style body min height 500px style button onclick clearAll Clear button button onclick addItem Add button button onclick savefile Save button button onclick loadfile Load button button onclick horizontal 1 Left button button onclick horizontal 1 Right button button onclick vertical 1 Up button button onclick vertical 1 Down button button onclick collapserow toggle Toggle Collapse Row button button onclick collapserow all Collapse All button button onclick collapserow none Expand All button button onclick trimnewlines Trim New Lines button button onclick addcontentversion Add Version button button onclick addparaphraseversion Add Paraphrase Version button button onclick styleview 0 Outline View button button onclick styleview 1 Writer View button div id container div script let style0 box sizing content box padding 0 margin 0 container width 100 border 1px solid blue item border 1px solid gray display flex item hover background color rgba 100 100 100 0 1 item active background color rgba 100 10 10 0 3 item selected background color rgba 10 100 10 0 3 item collapse max height 23px item header background color rgba 90 90 90 0 3 group display inline block width 100px border 1px solid red vertical align top overflow clip white space nowrap group number width 60px group title width 100px group status width 50px group words width 50px group complete width 40px group type width 60px group version width 60px group content flex grow 1 group input background color transparent outline none border none group select background color transparent outline none border none group status select width 100 group type select width 100 contenttextarea background color transparent outline none resize none border 0 margin 0 padding 0 font family Times New Roman font size 16px line height 16px padding 1px 0px 0px 0px width 100 height 16px overflow hidden let style1 box sizing content box padding 0 margin 0 container width 100 border 1px solid blue item border 1px solid gray display flex display block item hover background color rgba 100 100 100 0 1 item active background color rgba 100 10 10 0 3 item selected background color rgba 10 100 10 0 3 item collapse max height 23px item header display none background color rgba 90 90 90 0 3 group display inline block width 100px border 1px solid red vertical align top overflow clip white space nowrap group number display none width 60px group title display block width 100 group status display none width 50px group words display none width 50px group complete display none width 40px group type display none width 60px group version display none width 60px group content display block width 100 group input background color transparent outline none border none group select background color transparent outline none border none group status select width 100 group type select width 100 contenttextarea background color transparent outline none resize none border 0 margin 0 padding 0 font family Times New Roman font size 16px line height 16px padding 1px 0px 0px 0px width 100 height 16px overflow hidden let styleElement 0 function styleview v let stylecontents style0 if v 1 stylecontents style1 if styleElement document getElementsByTagName head 0 removeChild styleElement styleElement document createElement style styleElement type text css if styleElement styleSheet styleElement styleSheet cssText stylecontents else styleElement appendChild document createTextNode stylecontents document getElementsByTagName head 0 appendChild styleElement styleview 0 let container document getElementById container let testitem div class item header span class group number No span span class group title Title span span class group status Status span span class group words Size span span class group complete span span class group type Type span span class group version Version span span class group content textarea class contenttextarea oninput this style height 0px this style height this scrollHeight px Content textarea Content span div let levels function updateOrder let levels let items document getElementsByClassName item items items items forEach el i if i 0 return header let level el getAttribute level level parseInt level if level 1 el children 0 innerHTML no number el children 1 children 0 innerHTML span span no indent return item has no level for let n 0 n level 1 n if levels n levels n 0 levels level 1 for let n level 1 n 10 n delete levels n let indent span style min width 15px display inline block span repeat level el children 1 children 0 innerHTML indent let no Object values levels join el children 0 innerHTML no const genRanHex size Array size map Math floor Math random 16 toString 16 join function addItem level title uid contents if typeof level undefined level 0 if typeof title undefined title title if typeof uid undefined uid genRanHex 16 if typeof contents undefined contents level parseInt level for let n 0 n level 1 n if levels n levels n 0 levels level 1 for let n level 1 n 10 n delete levels n let versions contents forEach v i a let selected i a length 1 selected versions option value selected i option let textareas contents forEach v i a let display i a length 1 inline none console log i i a length a length console log display display textareas textarea class contenttextarea style display display oninput this style height 0px this style height this scrollHeight px textareainput this placeholder Type content v textarea let no Object values levels join let indent span style min width 15px display inline block span repeat level let item document createElement div container appendChild item item className item item onclick selectitem item item setAttribute level level item setAttribute uid uid item innerHTML span class group number span span class group title span span input type text value title span span class group status select name status option value unknown option option value draft Draft option option value temp Temp option option value work Work option option value final Final option select span span class group words Words span span class group complete select name option value 0 0 option option value 20 20 option option value 40 40 option option value 60 60 option option value 80 80 option option value 100 100 option select span span class group type select name type option value text Text option option value note Note option option value title Title option option value section Section option option value paragraph Paragraph option option value listing Listing option option value figure Figure option option value equation Equation option option value table Table option select span span class group version select name vesion onchange selectversion this versions select span span class group content textareas span updateOrder function selectitem item let items document getElementsByClassName item items forEach el el classList remove selected item classList add selected let data items level 0 title Introduction level 1 title Motivation level 2 title Problem level 2 title Other level 1 title Tasks level 0 title Background level 2 title Timeline level 2 title Cats function addcontentarea sel value sel children 7 innerHTML textarea class contenttextarea oninput this style height 0px this style height this scrollHeight px placeholder Type content value textarea function clearAll container innerHTML testitem header function loaddata d clearAll levels let innerHTML innerHTML testitem HEADER let items d items items forEach item nn let contents item contents if contents contents length 0 contents if item uid item uid genRanHex 16 addItem item level item title item uid contents for let g 0 g contents length g don t include header hence 1 addcontentversion container children nn contents g let textareas document getElementsByTagName textarea textareas textareas textareas forEach el el style height auto el style height 0px el style height el scrollHeight px let divitems document getElementsByClassName item divitems divitems divitems forEach el i if i 0 return updatesize el textareas 0 oninput textareas textareainput textareas forEach el el dispatchEvent new Event input bubbles true textareas forEach el el value el value function textareainput ta ta style height 0px ta style height ta scrollHeight px function savedata let savedata savedata sig grid savedata items let items document getElementsByClassName item items items items forEach el i if i 0 return let item level el getAttribute level title el children 1 children 1 value uid el getAttribute uid contents let content el children 7 children content content content forEach c item contents push c value savedata items push item return savedata test loaddata data let res savedata console log data res loaddata res function savefile let curdata savedata let jsonTXT JSON stringify curdata let a document createElement a let file new Blob jsonTXT type text plain a href URL createObjectURL file a download mygriddata json a click URL revokeObjectURL a href function loadfile let inputdiv document createElement input inputdiv type file inputdiv accept json json inputdiv onchange function const fileList this files let reader new FileReader no arguments reader readAsText this files 0 reader onload function let indata JSON parse reader result loaddata indata inputdiv click function horizontal dir let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let level parseInt sel getAttribute level level dir if level 1 level 1 sel setAttribute level level 1 means no level updateOrder function vertical dir let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let selParent sel parentElement if dir 0 sel previousElementSibling if dir 0 selParent children indexOf sel 1 selParent insertBefore sel sel previousElementSibling else if dir 0 sel nextElementSibling selParent insertBefore sel nextElementSibling sel updateOrder function collapserow arg toggle all none let items document getElementsByClassName item items items if arg all items forEach el el classList add collapse if arg none items forEach el el classList remove collapse let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 if arg toggle sel classList toggle collapse function trimnewlines let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let value sel children 7 children 0 value value value replaceAll r value value replaceAll n value value replaceAll sel children 7 children 0 value value function addcontentversion sel value if typeof value undefined value if typeof sel undefined console log sel sel sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 console log sel sel children 7 let numversions sel children 7 children length console log sel version sel children 6 children 0 selectedIndex console log num version sel children 6 children 0 length sel children 6 children 0 innerHTML option value selected numversions option console log textareas sel children 7 children for let i 0 i sel children 7 children length i sel children 7 children i style display none let newtextarea document createElement textarea sel children 7 appendChild newtextarea newtextarea className contenttextarea newtextarea addEventListener input function event event target style height 0px event target style height event target scrollHeight px textareainput newtextarea newtextarea value value newtextarea placeholder Type content newtextarea dispatchEvent new Event input select the latest version sel children 6 children 0 selectedIndex numversions selected word on last element console log newtextarea newtextarea parentElement parentElement selectversion sel children 6 children 0 function selectversion el sel el parentElement parentElement console log select version var value el options el selectedIndex value var text el options el selectedIndex text console log selected version el selectedIndex let numversions sel children 7 children length let contents sel children 7 children contents contents contents forEach c c style display none sel children 7 children el selectedIndex style display inline block console log sel value sel children 7 children el selectedIndex value sel children 7 children el selectedIndex dispatchEvent new Event input bubbles true updatesize sel async function addparaphraseversion let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 get current selected version let version sel children 6 children 0 selectedIndex get content let value sel children 7 children version value json sin sout http localhost 105 hello sin let url http localhost 105 hello sin encodeURIComponent value fetch url then response response text then text console log recv text let json JSON parse text addcontentversion sel json sout function textareainput ta let item ta parentElement parentElement updatesize item function updatesize item console log item item children let selectType item children 5 children 0 var value selectType options selectType selectedIndex value var text selectType options selectType selectedIndex text let selectVersion item children 6 children 0 selectedIndex let contentValue item children 7 children selectVersion value let sizeSpan item children 3 sizeSpan innerHTML contentValue split length 1 console log ready script br br
option value table Table option select span span class group version select name vesion onchange selectversion this versions select span span class group content textareas span updateOrder function selectitem item let items document getElementsByClassName item items forEach el el classList remove selected item classList add selected let data items level 0 title Introduction level 1 title Motivation level 2 title Problem level 2 title Other level 1 title Tasks level 0 title Background level 2 title Timeline level 2 title Cats function addcontentarea sel value sel children 7 innerHTML textarea class contenttextarea oninput this style height 0px this style height this scrollHeight px placeholder Type content value textarea function clearAll container innerHTML testitem header function loaddata d clearAll levels let innerHTML innerHTML testitem HEADER let items d items items forEach item nn let contents item contents if contents contents length 0 contents if item uid item uid genRanHex 16 addItem item level item title item uid contents for let g 0 g contents length g don t include header hence 1 addcontentversion container children nn contents g let textareas document getElementsByTagName textarea textareas textareas textareas forEach el el style height auto el style height 0px el style height el scrollHeight px let divitems document getElementsByClassName item divitems divitems divitems forEach el i if i 0 return updatesize el textareas 0 oninput textareas textareainput textareas forEach el el dispatchEvent new Event input bubbles true textareas forEach el el value el value function textareainput ta ta style height 0px ta style height ta scrollHeight px function savedata let savedata savedata sig grid savedata items let items document getElementsByClassName item items items items forEach el i if i 0 return let item level el getAttribute level title el children 1 children 1 value uid el getAttribute uid contents let content el children 7 children content content content forEach c item contents push c value savedata items push item return savedata test loaddata data let res savedata console log data res loaddata res function savefile let curdata savedata let jsonTXT JSON stringify curdata let a document createElement a let file new Blob jsonTXT type text plain a href URL createObjectURL file a download mygriddata json a click URL revokeObjectURL a href function loadfile let inputdiv document createElement input inputdiv type file inputdiv accept json json inputdiv onchange function const fileList this files let reader new FileReader no arguments reader readAsText this files 0 reader onload function let indata JSON parse reader result loaddata indata inputdiv click function horizontal dir let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let level parseInt sel getAttribute level level dir if level 1 level 1 sel setAttribute level level 1 means no level updateOrder function vertical dir let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let selParent sel parentElement if dir 0 sel previousElementSibling if dir 0 selParent children indexOf sel 1 selParent insertBefore sel sel previousElementSibling else if dir 0 sel nextElementSibling selParent insertBefore sel nextElementSibling sel updateOrder function collapserow arg toggle all none let items document getElementsByClassName item items items if arg all items forEach el el classList add collapse if arg none items forEach el el classList remove collapse let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 if arg toggle sel classList toggle collapse function trimnewlines let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 let value sel children 7 children 0 value value value replaceAll r value value replaceAll n value value replaceAll sel children 7 children 0 value value function addcontentversion sel value if typeof value undefined value if typeof sel undefined console log sel sel sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 console log sel sel children 7 let numversions sel children 7 children length console log sel version sel children 6 children 0 selectedIndex console log num version sel children 6 children 0 length sel children 6 children 0 innerHTML option value selected numversions option console log textareas sel children 7 children for let i 0 i sel children 7 children length i sel children 7 children i style display none let newtextarea document createElement textarea sel children 7 appendChild newtextarea newtextarea className contenttextarea newtextarea addEventListener input function event event target style height 0px event target style height event target scrollHeight px textareainput newtextarea newtextarea value value newtextarea placeholder Type content newtextarea dispatchEvent new Event input select the latest version sel children 6 children 0 selectedIndex numversions selected word on last element console log newtextarea newtextarea parentElement parentElement selectversion sel children 6 children 0 function selectversion el sel el parentElement parentElement console log select version var value el options el selectedIndex value var text el options el selectedIndex text console log selected version el selectedIndex let numversions sel children 7 children length let contents sel children 7 children contents contents contents forEach c c style display none sel children 7 children el selectedIndex style display inline block console log sel value sel children 7 children el selectedIndex value sel children 7 children el selectedIndex dispatchEvent new Event input bubbles true updatesize sel async function addparaphraseversion let sel document getElementsByClassName selected if sel length 0 alert no row selected return sel sel 0 get current selected version let version sel children 6 children 0 selectedIndex get content let value sel children 7 children version value json sin sout http localhost 105 hello sin let url http localhost 105 hello sin encodeURIComponent value fetch url then response response text then text console log recv text let json JSON parse text addcontentversion sel json sout function textareainput ta let item ta parentElement parentElement updatesize item function updatesize item console log item item children let selectType item children 5 children 0 var value selectType options selectType selectedIndex value var text selectType options selectType selectedIndex text let selectVersion item children 6 children 0 selectedIndex let contentValue item children 7 children selectVersion value let sizeSpan item children 3 sizeSpan innerHTML contentValue split length 1 console log ready script br br