editor-new.js 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/view/editor creates a view interface for editor functions.
  15. ///
  16. /// @module vwf/view/editor
  17. /// @requires version
  18. /// @requires vwf/view
  19. /// @requires vwf/utility
  20. define([
  21. "module",
  22. "version",
  23. "vwf/view",
  24. "vwf/utility",
  25. "vwf/view/lib/ace/ace",
  26. "vwf/view/lib/colorpicker/colorpicker.min"
  27. ], function (module, version, view, utility, ace, colorpicker) {
  28. var self;
  29. return view.load(module, {
  30. // == Module Definition ====================================================================
  31. initialize: function () {
  32. self = this;
  33. this.ace = window.ace;
  34. this.nodes = {};
  35. this.scenes = {};
  36. this.allScripts = {};
  37. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  38. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  39. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  40. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  41. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  42. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  43. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  44. // $('body').append('<script>mdc.autoInit()</script>');
  45. this.removeProps = (obj) => {
  46. Object.keys(obj).forEach(key =>
  47. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  48. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  49. );
  50. return obj;
  51. };
  52. this.getNodeDef = function (nodeID) {
  53. let node = vwf.getNode(nodeID, true);
  54. let nodeDef = self.removeProps(node);
  55. return nodeDef
  56. }
  57. this.GUID = function () {
  58. var S4 = function () {
  59. return Math.floor(
  60. Math.random() * 0x10000 /* 65536 */
  61. ).toString(16);
  62. };
  63. return (
  64. S4() + S4() + "-" +
  65. S4() + "-" +
  66. S4() + "-" +
  67. S4() + "-" +
  68. S4() + S4() + S4()
  69. );
  70. }
  71. this.getRoot = function () {
  72. var app = window.location.pathname;
  73. var pathSplit = app.split('/');
  74. if (pathSplit[0] == "") {
  75. pathSplit.shift();
  76. }
  77. if (pathSplit[pathSplit.length - 1] == "") {
  78. pathSplit.pop();
  79. }
  80. var instIndex = pathSplit.length - 1;
  81. if (pathSplit.length > 2) {
  82. if (pathSplit[pathSplit.length - 2] == "load") {
  83. instIndex = pathSplit.length - 3;
  84. }
  85. }
  86. if (pathSplit.length > 3) {
  87. if (pathSplit[pathSplit.length - 3] == "load") {
  88. instIndex = pathSplit.length - 4;
  89. }
  90. }
  91. var root = "";
  92. for (var i = 0; i < instIndex; i++) {
  93. if (root != "") {
  94. root = root + "/";
  95. }
  96. root = root + pathSplit[i];
  97. }
  98. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  99. return root
  100. };
  101. this.getRandomInt = function (min, max) {
  102. min = Math.ceil(min);
  103. max = Math.floor(max);
  104. return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  105. };
  106. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  107. let el = document.createElement("div");
  108. el.setAttribute("id", item);
  109. document.body.appendChild(el);
  110. }
  111. );
  112. this.avatarCardDef = function (src, desc, onclickfunc) {
  113. return {
  114. $cell: true,
  115. $type: "div",
  116. class: "mdc-card avatar-card",
  117. $init: function () {
  118. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  119. },
  120. onclick: onclickfunc,
  121. $components: [
  122. {
  123. $type: "section",
  124. class: "mdc-card__primary",
  125. $components: [
  126. {
  127. $type: "h1",
  128. class: "mdc-card__title mdc-card__title--large",
  129. $text: desc.subtitle
  130. },
  131. {
  132. $type: "h2",
  133. class: "mdc-card__subtitle",
  134. $text: desc.title
  135. }
  136. ]
  137. },
  138. {
  139. $type: "section",
  140. class: "mdc-card__actions",
  141. $components: [
  142. {
  143. $type: "button",
  144. class: "mdc-button mdc-button--compact mdc-card__action",
  145. //$text: "Use it",
  146. onclick: onclickfunc
  147. }
  148. ]
  149. }
  150. ]
  151. }
  152. }
  153. let avatarSettings =
  154. {
  155. $cell: true,
  156. $type: "div",
  157. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  158. $components: [
  159. {
  160. $cell: true,
  161. $type: "div",
  162. class: "mdc-layout-grid__inner",
  163. $components: [
  164. {
  165. $cell: true,
  166. $type: "div",
  167. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  168. $components: [
  169. {
  170. $cell: true,
  171. $type: "button",
  172. class: "mdc-button mdc-button--raised",
  173. $text: "Go forward",
  174. onclick: function (e) {
  175. function getMovementVector(el) {
  176. var directionVector = new THREE.Vector3(0, 0, 0);
  177. var rotationEuler = new THREE.Euler(0, 0, 0, 'YXZ');
  178. var rotation = el.getAttribute('rotation');
  179. var velocity = new THREE.Vector3(0, 0, -0.5);
  180. var xRotation;
  181. directionVector.copy(velocity);
  182. directionVector.multiplyScalar(1.0);
  183. // Absolute.
  184. if (!rotation) { return directionVector; }
  185. xRotation = 0;
  186. // Transform direction relative to heading.
  187. rotationEuler.set(THREE.Math.degToRad(xRotation), THREE.Math.degToRad(rotation.y), 0);
  188. directionVector.applyEuler(rotationEuler);
  189. return directionVector;
  190. }
  191. let el = document.querySelector('#avatarControl');
  192. let currentPosition = el.getAttribute('position');
  193. let movementVector = getMovementVector(el);
  194. let position = {};
  195. position.x = currentPosition.x + movementVector.x;
  196. position.y = currentPosition.y + movementVector.y;
  197. position.z = currentPosition.z + movementVector.z;
  198. el.setAttribute('position', position);
  199. }
  200. },
  201. ]
  202. },
  203. {
  204. $cell: true,
  205. $type: "div",
  206. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  207. $components: [
  208. {
  209. $cell: true,
  210. $type: "button",
  211. class: "mdc-button mdc-button--raised",
  212. $text: "Reset camera view",
  213. onclick: function (e) {
  214. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  215. let controlEl = document.querySelector('#avatarControl');
  216. controlEl.setAttribute('camera', 'active', true);
  217. }
  218. },
  219. {
  220. $cell: true,
  221. $type: "button",
  222. class: "mdc-button mdc-button--raised",
  223. $text: "Hide cursor",
  224. onclick: function (e) {
  225. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  226. let avatarID = 'avatar-' + self.kernel.moniker();
  227. let cursorID = 'myCursor-' + avatarID;
  228. let controlEl = document.querySelector("[id='" + cursorID + "']");
  229. let vis = controlEl.getAttribute('visible');
  230. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  231. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  232. //controlEl.setAttribute('visible', !vis);
  233. }
  234. }
  235. ]
  236. },
  237. {
  238. $cell: true,
  239. $type: "div",
  240. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  241. $components: [
  242. {
  243. $type: "div",
  244. class: "mdc-layout-grid",
  245. $components: [
  246. {
  247. $type: "div",
  248. class: "mdc-layout-grid__inner",
  249. $components: [
  250. {
  251. $cell: true,
  252. $type: "div",
  253. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  254. $components: [
  255. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  256. function (e) {
  257. let avatarID = 'avatar-' + self.kernel.moniker();
  258. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  259. }
  260. )
  261. ]
  262. },
  263. {
  264. $cell: true,
  265. $type: "div",
  266. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  267. $components: [
  268. self.avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  269. function (e) {
  270. let avatarID = 'avatar-' + self.kernel.moniker();
  271. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  272. }
  273. )]
  274. },
  275. {
  276. $cell: true,
  277. $type: "div",
  278. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  279. $components: [
  280. self.avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  281. function (e) {
  282. let avatarID = 'avatar-' + self.kernel.moniker();
  283. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  284. }
  285. )]
  286. }
  287. ]
  288. }
  289. ]
  290. }
  291. ]
  292. }
  293. ]
  294. }
  295. ]
  296. }
  297. let viewSettings =
  298. {
  299. $cell: true,
  300. $type: "div",
  301. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  302. $components: [
  303. {
  304. $cell: true,
  305. $type: "div",
  306. class: "mdc-layout-grid__inner",
  307. $components: [
  308. {
  309. $cell: true,
  310. $type: "div",
  311. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  312. $components: [
  313. {
  314. $cell: true,
  315. $type: "button",
  316. class: "mdc-button mdc-button--raised",
  317. $text: "OSC Settings",
  318. onclick: function (e) {
  319. let sideBar = document.querySelector('#sideBar');
  320. sideBar._sideBarComponent = oscSettings;
  321. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  322. }
  323. }
  324. ]
  325. }
  326. ]
  327. }
  328. ]
  329. }
  330. let savedStateEl = function (item) {
  331. return {
  332. $type: "li",
  333. class: "mdc-list-item",
  334. role: "option",
  335. $components: [
  336. {
  337. $text: "Saved world"
  338. }
  339. ]
  340. }
  341. }
  342. let stateListElement = function (item) {
  343. let liEl = {
  344. $type: "li",
  345. class: "mdc-list-item",
  346. role: "option",
  347. id: "",
  348. applicationpath: "",
  349. $components: [
  350. {
  351. $text: "no saves"
  352. }
  353. ]
  354. }
  355. let applicationName = item.applicationpath.split("/");
  356. if (applicationName == "") {
  357. return liEl
  358. }
  359. if (applicationName.length > 0) {
  360. applicationName = applicationName[applicationName.length - 1];
  361. }
  362. if (applicationName.length > 0) {
  363. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  364. }
  365. if (item.latestsave) {
  366. liEl = {
  367. $type: "li",
  368. class: "mdc-list-item",
  369. role: "option",
  370. id: item.savename,
  371. applicationpath: item.applicationpath,
  372. $components: [
  373. {
  374. $text: applicationName + ": " + item.savename
  375. }
  376. ]
  377. }
  378. }
  379. else {
  380. liEl = {
  381. $type: "li",
  382. class: "mdc-list-item",
  383. role: "option",
  384. id: item.savename,
  385. revision: item.revision,
  386. applicationpath: item.applicationpath,
  387. $components: [
  388. {
  389. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  390. }
  391. ]
  392. }
  393. }
  394. return liEl
  395. }
  396. let oscSettings =
  397. {
  398. $cell: true,
  399. $type: "div",
  400. id: "oscSettings",
  401. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  402. _oscHost: '',
  403. _oscPort: '',
  404. _oscStatus: '',
  405. _updateStatus: function () {
  406. this._oscStatus = window._OSCManager.getStatus()
  407. },
  408. $init: function () {
  409. if (window._OSCManager) {
  410. this._oscHost = window._OSCManager.hostValue;
  411. this._oscPort = window._OSCManager.portValue;
  412. this._oscStatus = window._OSCManager.getStatus();
  413. // var t = this;
  414. // setInterval(function () {
  415. // t._updateStatus();
  416. // }, 1000);
  417. }
  418. },
  419. $update: function () {
  420. let that = this
  421. var buttonText = "Connect";
  422. var buttonFunc = function (e) {
  423. }
  424. if (this._oscStatus == 1) {
  425. buttonText = "Disconnect";
  426. buttonFunc = function (e) {
  427. window._OSCManager.disconnect();
  428. }
  429. } else {
  430. var buttonFunc = function (e) {
  431. window._OSCManager.connect();
  432. window._OSCManager.port.on("open", function () {
  433. that._oscStatus = window._OSCManager.getStatus();
  434. console.log("connected");
  435. });
  436. window._OSCManager.port.on("close", function () {
  437. that._oscStatus = window._OSCManager.getStatus();
  438. console.log("disconnected");
  439. });
  440. }
  441. }
  442. this.$components = [
  443. {
  444. $cell: true,
  445. $type: "div",
  446. class: "mdc-layout-grid__inner",
  447. $components: [
  448. {
  449. $cell: true,
  450. $type: "div",
  451. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  452. $components: [
  453. {
  454. $type: "span",
  455. $text: "Host: "
  456. },
  457. {
  458. class: "mdc-textfield",
  459. $cell: true,
  460. $type: "span",
  461. $components: [
  462. {
  463. class: "mdc-textfield__input",
  464. id: "oscHost",
  465. $cell: true,
  466. $type: "input",
  467. type: "text",
  468. value: this._oscHost,
  469. onchange: function (e) {
  470. this._oscHost = this.value;
  471. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  472. }
  473. }
  474. ]
  475. }
  476. ]
  477. },
  478. {
  479. $cell: true,
  480. $type: "div",
  481. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  482. $components: [
  483. {
  484. $type: "span",
  485. $text: "Port: "
  486. },
  487. {
  488. class: "mdc-textfield",
  489. $cell: true,
  490. $type: "span",
  491. $components: [
  492. {
  493. class: "mdc-textfield__input",
  494. id: "oscPort",
  495. $cell: true,
  496. $type: "input",
  497. type: "text",
  498. value: this._oscPort,
  499. onchange: function (e) {
  500. this._oscPort = this.value;
  501. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  502. }
  503. }
  504. ]
  505. }
  506. ]
  507. },
  508. {
  509. $cell: true,
  510. $type: "div",
  511. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  512. $components: [
  513. {
  514. $cell: true,
  515. $type: "button",
  516. class: "mdc-button mdc-button--raised",
  517. $text: buttonText,
  518. onclick: buttonFunc
  519. }
  520. ]
  521. }
  522. ]
  523. }
  524. ]
  525. }
  526. }
  527. let loadSaveSettings =
  528. {
  529. $cell: true,
  530. $type: "div",
  531. id: "loadSaveSettings",
  532. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  533. _saveStates: [],
  534. _getStates: async function () {
  535. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  536. let data = await response.json();
  537. //this._saveStates = data;
  538. //let appName = self.getRoot();
  539. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  540. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  541. if (filterData.length !== 0) {
  542. this._saveStates = filterData
  543. //return filterData
  544. } else {
  545. this._saveStates = [{
  546. savename: "",
  547. latestsave: "",
  548. revision: "",
  549. applicationpath: "",
  550. url: ""
  551. }]
  552. }
  553. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  554. //return data
  555. //console.log(data);
  556. return this._saveStates
  557. },
  558. $init: function () {
  559. this._getStates();
  560. },
  561. $update: function () {
  562. this.$components =
  563. [
  564. {
  565. $cell: true,
  566. $type: "div",
  567. class: "mdc-layout-grid__inner",
  568. $components: [
  569. {
  570. $cell: true,
  571. $type: "div",
  572. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  573. $components: [
  574. {
  575. class: "mdc-textfield",
  576. $cell: true,
  577. $type: "span",
  578. $components: [
  579. {
  580. class: "mdc-textfield__input",
  581. id: "fileName",
  582. $cell: true,
  583. $type: "input",
  584. type: "text",
  585. value: self.getRoot()
  586. }]
  587. }
  588. ]
  589. },
  590. {
  591. $cell: true,
  592. $type: "div",
  593. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  594. $components: [
  595. {
  596. $cell: true,
  597. $type: "button",
  598. class: "mdc-button mdc-button--raised",
  599. $text: "Save",
  600. onclick: function (e) {
  601. let fileName = document.querySelector('#fileName')
  602. saveStateAsFile.call(self, fileName.value);
  603. document.querySelector("#fileName").value = '';
  604. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  605. }
  606. }
  607. ]
  608. },
  609. {
  610. $cell: true,
  611. $type: "div",
  612. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  613. $components: [
  614. {
  615. $cell: true,
  616. $type: "div",
  617. class: "mdc-select",
  618. $init: function () {
  619. var MDCSelect = mdc.select.MDCSelect;
  620. const select = new MDCSelect(document.querySelector('.mdc-select'));
  621. select.listen('MDCSelect:change', () => {
  622. //this._selectedState = select.value;
  623. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  624. //console.log(select.value);
  625. //.selectedOptions[0]
  626. });
  627. },
  628. role: "listbox",
  629. $components: [
  630. {
  631. $type: "span",
  632. class: "mdc-select__selected-text",
  633. $text: "Select saved state"
  634. },
  635. {
  636. $type: "div",
  637. class: "mdc-simple-menu mdc-select__menu",
  638. $components: [
  639. {
  640. $type: "ul",
  641. class: "mdc-list mdc-simple-menu__items",
  642. $components: this._saveStates.map(stateListElement)
  643. }
  644. ]
  645. }
  646. ]
  647. }
  648. ]
  649. },
  650. {
  651. $cell: true,
  652. $type: "div",
  653. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  654. $components: [
  655. {
  656. $cell: true,
  657. $type: "button",
  658. _selectedState: {},
  659. id: "loadStateButton",
  660. class: "mdc-button mdc-button--raised",
  661. $text: "Load",
  662. onclick: function (e) {
  663. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  664. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  665. }
  666. }
  667. ]
  668. }
  669. ]
  670. }
  671. ]
  672. }
  673. }
  674. let protoPropertiesCell = function (m) {
  675. return {
  676. $type: "div",
  677. class: "mdc-layout-grid__inner",
  678. _prop: {},
  679. $init: function () {
  680. let prop = m[1].prop;
  681. if (prop.value == undefined && this._currentNode !== undefined) {
  682. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  683. }
  684. this._prop = prop
  685. },
  686. $update: function () {
  687. this.$components = [
  688. {
  689. $type: "div",
  690. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  691. $components: [
  692. { $text: this._prop.name }
  693. ]
  694. },
  695. {
  696. $type: "div",
  697. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  698. },
  699. {
  700. $type: "div",
  701. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  702. $components: [
  703. {
  704. class: "mdc-textfield",
  705. $cell: true,
  706. $type: "div",
  707. $components: [{
  708. class: "mdc-textfield__input",
  709. $cell: true,
  710. $type: "input",
  711. type: "text",
  712. value: this._prop.value,
  713. onchange: function (e) {
  714. let propValue = this.value;
  715. try {
  716. propValue = JSON.parse(propValue);
  717. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  718. } catch (e) {
  719. // restore the original value on error
  720. this.value = propValue;
  721. }
  722. }
  723. }]
  724. }
  725. ]
  726. }
  727. ]
  728. }
  729. }
  730. }
  731. let propertiesCell = function (m) {
  732. var editComponents = [{}, {}]
  733. if (m.name.indexOf("semantics") > -1) { }
  734. else if (m.name.indexOf("grammar") > -1) { }
  735. else if (m.name.indexOf("ohm") > -1) {
  736. editComponents = [
  737. {
  738. $type: "div",
  739. $cell: true,
  740. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  741. $components: [
  742. {
  743. $cell: true,
  744. $type: "button",
  745. class: "mdc-button",
  746. $text: "Edit", //edit grammar
  747. onclick: function (e) {
  748. var currentNode = document.querySelector('#currentNode')._currentNode;
  749. if (currentNode == '') {
  750. currentNode = vwf_view.kernel.find("", "/")[0];
  751. }
  752. let editor = document.querySelector('#livePropEditor');
  753. editor._setNode(currentNode);
  754. editor._propName = m.name;
  755. editor._prop = { body: m.rawValue, type: 'complex' }
  756. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  757. }
  758. }
  759. ]
  760. },
  761. {
  762. $type: "div",
  763. $cell: true,
  764. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  765. $components: []
  766. }
  767. ]
  768. } else {
  769. editComponents = [
  770. {
  771. $type: "div",
  772. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  773. $components: [
  774. {
  775. class: "mdc-textfield",
  776. $cell: true,
  777. $type: "span",
  778. $components: [
  779. {
  780. class: "mdc-textfield__input",
  781. id: "prop-" + m.name,
  782. $cell: true,
  783. $type: "input",
  784. type: "text",
  785. value: m.getValue(),
  786. onchange: function (e) {
  787. let propValue = this.value;
  788. try {
  789. propValue = JSON.parse(propValue);
  790. self.kernel.setProperty(this._currentNode, m.name, propValue);
  791. } catch (e) {
  792. // restore the original value on error
  793. this.value = propValue;
  794. }
  795. }
  796. }
  797. ]
  798. }
  799. ]
  800. },
  801. {
  802. $type: "div",
  803. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  804. $components: [
  805. {
  806. $cell: true,
  807. $type: "button",
  808. class: "mdc-button",
  809. $text: "^", //edit grammar
  810. onclick: function (e) {
  811. var currentNode = document.querySelector('#currentNode')._currentNode;
  812. if (currentNode == '') {
  813. currentNode = vwf_view.kernel.find("", "/")[0];
  814. }
  815. let editor = document.querySelector('#livePropEditor');
  816. editor._setNode(currentNode);
  817. editor._propName = m.name;
  818. editor._prop = { body: m.getValue(), type: 'simple' }
  819. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  820. }
  821. }
  822. ]
  823. }
  824. ];
  825. }
  826. return {
  827. $type: "div",
  828. class: "mdc-layout-grid__inner",
  829. $components: [
  830. {
  831. $type: "div",
  832. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  833. $components: [
  834. { $text: m.name }
  835. ]
  836. },
  837. {
  838. $type: "div",
  839. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  840. },
  841. editComponents[0],
  842. editComponents[1]
  843. ]
  844. }
  845. }
  846. let nodeLink = function (m) {
  847. var myClass = "nodeItem";
  848. let myAvatarName = 'avatar-' + self.kernel.moniker();
  849. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  850. myClass = "nodeItem"
  851. return {
  852. $type: "li",
  853. class: "mdc-list-item",
  854. $components: [{
  855. $type: "a",
  856. class: "mdc-list-item",
  857. $href: "#",
  858. $components: [{
  859. $type: 'span',
  860. class: myClass,
  861. $text: m.name
  862. }
  863. ],
  864. onclick: function (e) {
  865. //self.currentNodeID = m.ID;
  866. document.querySelector('#currentNode')._setNode(m.ID);
  867. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  868. // createAceEditor(self, m.ID);
  869. }
  870. }]
  871. }
  872. };
  873. let listDivider = {
  874. $cell: true,
  875. $type: "hr",
  876. class: "mdc-list-divider",
  877. }
  878. let gizmoEdit = {
  879. $type: "div",
  880. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  881. $components: [
  882. {
  883. $type: "div",
  884. class: "mdc-layout-grid__inner",
  885. $components: [
  886. {
  887. $type: "div",
  888. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  889. $components: [
  890. {
  891. $cell: true,
  892. $type: "span",
  893. $text: "Edit: ",
  894. }
  895. ]
  896. },
  897. {
  898. $type: "div",
  899. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  900. $components: [
  901. {
  902. $cell: true,
  903. $type: "div",
  904. class: "mdc-switch",
  905. $components: [
  906. {
  907. $type: "input",
  908. type: "checkbox",
  909. class: "mdc-switch__native-control",
  910. id: 'editnode',
  911. $init: function () {
  912. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  913. },
  914. //id: "basic-switch",
  915. onchange: function (e) {
  916. var nodeID = document.querySelector('#currentNode')._currentNode;
  917. let chkAttr = this.getAttribute('checked');
  918. if (chkAttr == "") {
  919. self.kernel.setProperty(this._currentNode, 'edit', false);
  920. } else {
  921. self.kernel.setProperty(this._currentNode, 'edit', true);
  922. }
  923. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  924. }
  925. },
  926. {
  927. $type: "div",
  928. class: "mdc-switch__background",
  929. $components: [
  930. {
  931. $type: "div",
  932. class: "mdc-switch__knob"
  933. }
  934. ]
  935. }
  936. ]
  937. }
  938. ]
  939. },
  940. {
  941. $type: "div",
  942. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  943. $components: [
  944. {
  945. $cell: true,
  946. $type: "a",
  947. class: "gizmomode",
  948. $text: "T",
  949. onclick: function (e) {
  950. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  951. }
  952. }
  953. ]
  954. },
  955. {
  956. $type: "div",
  957. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  958. $components: [
  959. {
  960. $cell: true,
  961. $type: "a",
  962. class: "gizmomode",
  963. $text: "R",
  964. onclick: function (e) {
  965. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  966. }
  967. }
  968. ]
  969. },
  970. {
  971. $type: "div",
  972. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  973. $components: [
  974. {
  975. $cell: true,
  976. $type: "a",
  977. class: "gizmomode",
  978. $text: "S",
  979. onclick: function (e) {
  980. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  981. }
  982. }
  983. ]
  984. }
  985. ]
  986. }
  987. ]
  988. }
  989. let nodesCell = {
  990. $cell: true,
  991. $type: "div",
  992. id: "currentNode",
  993. _childNodes: [],
  994. _currentNode: '',
  995. _displayedProperties: {},
  996. _setNode: function (aNode) {
  997. this._currentNode = aNode;
  998. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  999. },
  1000. $init: function () {
  1001. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  1002. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  1003. //this._currentNode = '3333';
  1004. },
  1005. _getChildNodes: function () {
  1006. this._childNodes = self.nodes[this._currentNode];
  1007. if (this._childNodes !== undefined) {
  1008. return this._childNodes.children
  1009. } else {
  1010. return []
  1011. }
  1012. //let nodeIDAlpha = he.encode(this._currentNode);
  1013. },
  1014. // _getNodeComplexProperties: function () {
  1015. // let node = self.nodes[this._currentNode];
  1016. // let props = this._getNodeProperties();
  1017. // let filterFunction = function (prop) {
  1018. // return (prop.name == 'ohmLang')
  1019. // };
  1020. // let complexProps = props.filter(filterFunction.bind(this));
  1021. // return complexProps
  1022. // },
  1023. _getNodeProperties: function () {
  1024. let node = self.nodes[this._currentNode];
  1025. this._displayedProperties = {};
  1026. let filterFunction = function (prop) {
  1027. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  1028. };
  1029. let props = node.properties.filter(filterFunction.bind(this));
  1030. return props
  1031. },
  1032. _getNodeProtoProperties: function () {
  1033. let node = self.nodes[this._currentNode];
  1034. let filterFunction = function (prop) {
  1035. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  1036. };
  1037. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  1038. return props
  1039. },
  1040. $update: function () {
  1041. //this.$text = this._currentNode;
  1042. let node = self.nodes[this._currentNode];
  1043. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1044. var viewerProps = {};
  1045. var viewerPropsCell = {};
  1046. var gizmoCell = {};
  1047. if (this._currentNode !== self.kernel.application()) {
  1048. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1049. //gizmoCell = {};
  1050. } else {
  1051. gizmoCell = gizmoEdit
  1052. }
  1053. }
  1054. if (node !== undefined) {
  1055. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1056. viewerProps = {
  1057. $type: "li",
  1058. class: "mdc-list-item",
  1059. $components: [
  1060. {
  1061. $text: "Viewer properties",
  1062. $type: "span",
  1063. class: "mdc-list-item__text mdc-typography--button"
  1064. }
  1065. ]
  1066. }
  1067. viewerPropsCell = {
  1068. $cell: true,
  1069. $type: "div",
  1070. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1071. $components: [
  1072. {
  1073. $cell: true,
  1074. $type: "div",
  1075. class: "mdc-layout-grid__inner",
  1076. $components: [
  1077. {
  1078. $cell: true,
  1079. $type: "div",
  1080. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1081. $components: [
  1082. {
  1083. $cell: true,
  1084. $type: "button",
  1085. class: "mdc-button mdc-button--raised",
  1086. $text: "Active",
  1087. onclick: function (e) {
  1088. let camera = document.querySelector('#' + this._currentNode);
  1089. camera.setAttribute('active', true);
  1090. }
  1091. }
  1092. ]
  1093. }
  1094. ]
  1095. }
  1096. ]
  1097. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1098. }
  1099. } else {
  1100. viewerProps = {};
  1101. viewerPropsCell = {};
  1102. }
  1103. }
  1104. this.$components = [
  1105. {
  1106. $cell: true,
  1107. $type: "ul",
  1108. class: "mdc-list",
  1109. $components: [
  1110. {
  1111. $cell: true,
  1112. $type: "button",
  1113. class: "mdc-list-item mdc-button mdc-button--raised",
  1114. $text: "<--",
  1115. onclick: function (e) {
  1116. let node = self.nodes[this._currentNode];
  1117. if (node.parentID !== 0) {
  1118. //self.currentNodeID = node.parentID,
  1119. document.querySelector('#currentNode')._setNode(node.parentID)
  1120. }
  1121. }
  1122. },
  1123. {
  1124. $type: "li",
  1125. class: "mdc-list-item",
  1126. $components: [
  1127. {
  1128. $text: "name",
  1129. $type: "span",
  1130. $init: function () {
  1131. let node = self.nodes[this._currentNode];
  1132. if (node) this.$text = node.name
  1133. },
  1134. class: "mdc-list-item__text mdc-typography--headline"
  1135. //<h1 class="mdc-typography--display4">Big header</h1>
  1136. }]
  1137. }, listDivider,
  1138. {
  1139. // $cell: true,
  1140. // $type: "ul",
  1141. // class: "mdc-list",
  1142. $type: "div",
  1143. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1144. $components: [
  1145. {
  1146. $type: "div",
  1147. class: "mdc-layout-grid__inner",
  1148. $components: [
  1149. {
  1150. $type: "div",
  1151. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1152. $components: [
  1153. {
  1154. $cell: true,
  1155. $type: "button",
  1156. class: "mdc-button mdc-button--raised",
  1157. $text: "Methods browser",
  1158. onclick: function (e) {
  1159. var currentNode = document.querySelector('#currentNode')._currentNode;
  1160. if (currentNode == '') {
  1161. currentNode = vwf_view.kernel.find("", "/")[0];
  1162. }
  1163. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1164. //createAceEditor(self, currentNode);
  1165. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1166. }
  1167. }
  1168. ]
  1169. }
  1170. ]
  1171. }
  1172. ]
  1173. },
  1174. gizmoCell,
  1175. listDivider,
  1176. {
  1177. $type: "li",
  1178. class: "mdc-list-item",
  1179. $components: [
  1180. {
  1181. $text: "Children",
  1182. $type: "span",
  1183. class: "mdc-list-item__text mdc-typography--button"
  1184. }]
  1185. },
  1186. {
  1187. $cell: true,
  1188. $type: "ul",
  1189. class: "mdc-list",
  1190. $components: this._getChildNodes().map(nodeLink)
  1191. }, listDivider, {
  1192. $type: "li",
  1193. class: "mdc-list-item",
  1194. $components: [
  1195. {
  1196. $text: "Properties",
  1197. $type: "span",
  1198. class: "mdc-list-item__text mdc-typography--button"
  1199. //<h1 class="mdc-typography--display4">Big header</h1>
  1200. }]
  1201. },
  1202. {
  1203. // $cell: true,
  1204. // $type: "ul",
  1205. // class: "mdc-list",
  1206. $type: "div",
  1207. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1208. $components: this._getNodeProperties().map(propertiesCell)
  1209. },
  1210. listDivider,
  1211. {
  1212. $type: "li",
  1213. class: "mdc-list-item",
  1214. $components: [
  1215. {
  1216. $text: "Proto properties",
  1217. $type: "span",
  1218. class: "mdc-list-item__text mdc-typography--button"
  1219. }]
  1220. },
  1221. {
  1222. $cell: true,
  1223. $type: "div",
  1224. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1225. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1226. }, listDivider,
  1227. viewerProps,
  1228. viewerPropsCell
  1229. ]
  1230. }
  1231. ]
  1232. }
  1233. }
  1234. let colorPickerComponent = {
  1235. $cell: true,
  1236. $type: "div",
  1237. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1238. $init: function () {
  1239. let myEl = this;
  1240. let cp = ColorPicker(
  1241. document.getElementById('slide'),
  1242. document.getElementById('picker'),
  1243. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1244. ColorPicker.positionIndicators(
  1245. document.getElementById('slide-indicator'),
  1246. document.getElementById('picker-indicator'),
  1247. mouseSlide, mousePicker
  1248. );
  1249. if (myEl._propName == 'color') {
  1250. // console.log(hex);
  1251. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1252. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1253. }
  1254. });
  1255. if (myEl._propName == 'color') {
  1256. cp.setHex(JSON.parse(myEl._prop.body));
  1257. }
  1258. },
  1259. $components: [
  1260. {
  1261. $cell: true,
  1262. $type: "div",
  1263. id: "color-picker",
  1264. class: "cp-default",
  1265. $components: [
  1266. {
  1267. $cell: true,
  1268. $type: "div",
  1269. class: "picker-wrapper",
  1270. $components: [
  1271. {
  1272. $cell: true,
  1273. $type: "div",
  1274. id: "picker",
  1275. class: "picker",
  1276. style: "width: 130px; height: 130px"
  1277. },
  1278. {
  1279. $cell: true,
  1280. $type: "div",
  1281. id: "picker-indicator",
  1282. class: "picker-indicator"
  1283. }
  1284. ]
  1285. },
  1286. {
  1287. $cell: true,
  1288. $type: "div",
  1289. class: "slide-wrapper",
  1290. $components: [
  1291. {
  1292. $cell: true,
  1293. $type: "div",
  1294. id: "slide",
  1295. class: "slide",
  1296. style: "width: 30px; height: 130px"
  1297. },
  1298. {
  1299. $cell: true,
  1300. $type: "div",
  1301. id: "slide-indicator",
  1302. class: "slide-indicator"
  1303. }
  1304. ]
  1305. }
  1306. ]
  1307. }
  1308. // {
  1309. // $cell: true,
  1310. // $type: "div",
  1311. // id: "color-picker",
  1312. // $init: function () {
  1313. // }
  1314. // }
  1315. ]
  1316. }
  1317. let propEditorWindow = {
  1318. $cell: true,
  1319. $type: "div",
  1320. _editorNode: '',
  1321. _prop: { body: '', type: 'simple' },
  1322. _propName: '',
  1323. id: "livePropEditor",
  1324. _setNode: function (node) {
  1325. this._editorNode = node;
  1326. this._prop.body = ''
  1327. },
  1328. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1329. $update: function () {
  1330. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  1331. var livePropertyComponent = {}
  1332. if (this._prop.type == 'simple') {
  1333. if (this._propName == 'color') {
  1334. livePropertyComponent = colorPickerComponent
  1335. }
  1336. } else {
  1337. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  1338. }
  1339. this.$components = [
  1340. {
  1341. $cell: true,
  1342. $type: "div",
  1343. class: "mdc-layout-grid__inner",
  1344. $components: [
  1345. {
  1346. $cell: true,
  1347. $type: "div",
  1348. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1349. $components: [
  1350. {
  1351. $cell: true,
  1352. $type: "button",
  1353. class: "mdc-button mdc-button--raised",
  1354. $text: "Update",
  1355. onclick: function (e) {
  1356. let editor = document.querySelector("#propAceEditor").env.editor;
  1357. let value = editor.getValue();
  1358. try {
  1359. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1360. //propValue = JSON.parse(value);
  1361. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1362. } catch (e) {
  1363. // restore the original value on error
  1364. this.value = propValue;
  1365. }
  1366. }
  1367. }]
  1368. },
  1369. {
  1370. $cell: true,
  1371. $type: "div",
  1372. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1373. $components: [
  1374. {
  1375. $type: "h3",
  1376. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1377. $text: this._editorNode
  1378. }
  1379. ]
  1380. },
  1381. {
  1382. $cell: true,
  1383. $type: "div",
  1384. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1385. $components: [
  1386. {
  1387. $type: "h3",
  1388. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1389. $text: this._propName
  1390. }
  1391. ]
  1392. }
  1393. ]
  1394. },
  1395. {
  1396. $cell: true,
  1397. $type: "div",
  1398. class: "mdc-layout-grid__inner",
  1399. $components: [
  1400. {
  1401. $cell: true,
  1402. $type: "div",
  1403. class: editorClass,
  1404. $components: [
  1405. {
  1406. $cell: true,
  1407. class: "aceEditor",
  1408. id: "propAceEditor",
  1409. $type: "div",
  1410. $text: this._prop.body,
  1411. $init: function () {
  1412. createAceEditor(self, this._editorNode, "propAceEditor");
  1413. this.env.editor.$blockScrolling = Infinity
  1414. }
  1415. }
  1416. ]
  1417. }, livePropertyComponent
  1418. // {
  1419. // $cell: true,
  1420. // $type: "div",
  1421. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1422. // $components: []
  1423. // },
  1424. ]
  1425. }
  1426. ]
  1427. //$components:
  1428. }
  1429. }
  1430. let codeEditorWindow = {
  1431. $cell: true,
  1432. $type: "div",
  1433. _editorNode: '',
  1434. _method: { body: '' },
  1435. _methodName: '',
  1436. _getNodeMethods: function () {
  1437. let node = self.nodes[this._editorNode];
  1438. return node.methods
  1439. },
  1440. _getProtoNodeMethods: function () {
  1441. let node = self.nodes[this._editorNode];
  1442. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1443. return prototypeMethods
  1444. },
  1445. id: "liveCodeEditor",
  1446. _setNode: function (node) {
  1447. this._editorNode = node;
  1448. this._method.body = ''
  1449. },
  1450. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1451. // _getComplexProps: function(){
  1452. // let node = self.nodes[this._editorNode];
  1453. // let currentNode = document.querySelector('#currentNode');
  1454. // var props = {}
  1455. // if (currentNode !== null) {
  1456. // props = currentNode._getNodeComplexProperties();
  1457. // }
  1458. // return props
  1459. // },
  1460. // _listPropertyElement: function (m) {
  1461. // return {
  1462. // $type: "li",
  1463. // class: "mdc-list-item",
  1464. // $components: [{
  1465. // $type: "a",
  1466. // class: "mdc-list-item",
  1467. // $href: "#",
  1468. // $text: m[1].name,
  1469. // onclick: function (e) {
  1470. // this._method = {};
  1471. // this._methodName = m[1].name;
  1472. // this._method.body = m[1].rawValue
  1473. // this._method.type = "complexProperty"
  1474. // }
  1475. // }]
  1476. // }
  1477. // },
  1478. _listElement: function (m) {
  1479. return {
  1480. $type: "li",
  1481. class: "mdc-list-item",
  1482. $components: [{
  1483. $type: "a",
  1484. class: "mdc-list-item",
  1485. $href: "#",
  1486. $text: m[0],
  1487. onclick: function (e) {
  1488. let method = vwf.getMethod(this._editorNode, m[0]);
  1489. //document.querySelector('#aceEditor').
  1490. this._method = method;
  1491. this._methodName = m[0];
  1492. //self.currentNodeID = m.ID;
  1493. //document.querySelector('#currentNode')._setNode(m.ID);
  1494. }
  1495. }]
  1496. }
  1497. },
  1498. $update: function () {
  1499. this.$components = [
  1500. {
  1501. $cell: true,
  1502. $type: "div",
  1503. class: "mdc-layout-grid__inner",
  1504. $components: [
  1505. {
  1506. $cell: true,
  1507. $type: "div",
  1508. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1509. $components: [
  1510. {
  1511. $type: "h3",
  1512. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1513. $text: this._editorNode
  1514. }
  1515. ]
  1516. },
  1517. {
  1518. $cell: true,
  1519. $type: "div",
  1520. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1521. $components: [
  1522. {
  1523. $cell: true,
  1524. $type: "button",
  1525. class: "mdc-button mdc-button--raised",
  1526. $text: "Update",
  1527. onclick: function (e) {
  1528. let editor = document.querySelector("#aceEditor").env.editor;
  1529. let evalText = editor.getValue();
  1530. // if (this._method.type == 'complexProperty') {
  1531. // let propValue = evalText;
  1532. // try {
  1533. // //propValue = JSON.parse(propValue);
  1534. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1535. // } catch (e) {
  1536. // // restore the original value on error
  1537. // this.value = propValue;
  1538. // }
  1539. // } else {
  1540. // }
  1541. self.kernel.setMethod(this._editorNode, this._methodName,
  1542. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1543. }
  1544. }]
  1545. },
  1546. {
  1547. $cell: true,
  1548. $type: "div",
  1549. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1550. $components: [
  1551. {
  1552. $cell: true,
  1553. $type: "button",
  1554. class: "mdc-button mdc-button--raised",
  1555. $text: "Call",
  1556. onclick: function (e) {
  1557. var params = [];
  1558. if (this._method.parameters) {
  1559. let paramsLength = this._method.parameters.length
  1560. if (paramsLength >= 1) {
  1561. let paramsVal = document.querySelector("#methodParams").value;
  1562. try {
  1563. params = JSON.parse(paramsVal);
  1564. //params.push(prmtr);
  1565. } catch (e) {
  1566. self.logger.error('Invalid Value');
  1567. }
  1568. }
  1569. };
  1570. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1571. }
  1572. }]
  1573. },
  1574. {
  1575. $cell: true,
  1576. $type: "div",
  1577. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1578. $components: [
  1579. {
  1580. $cell: true,
  1581. $type: "button",
  1582. class: "mdc-button mdc-button--raised",
  1583. $text: "Do It",
  1584. onclick: function (e) {
  1585. let editor = document.querySelector("#aceEditor").env.editor;
  1586. codeEditorDoit.call(self, editor, this._editorNode);
  1587. }
  1588. }]
  1589. },
  1590. {
  1591. $cell: true,
  1592. $type: "div",
  1593. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1594. $components: [
  1595. {
  1596. $cell: true,
  1597. $type: "button",
  1598. class: "mdc-button mdc-button--raised",
  1599. $text: "Print It",
  1600. onclick: function (e) {
  1601. let editor = document.querySelector("#aceEditor").env.editor;
  1602. codeEditorPrintit.call(self, editor, this._editorNode);
  1603. }
  1604. }]
  1605. }
  1606. ]
  1607. },
  1608. {
  1609. $cell: true,
  1610. $type: "div",
  1611. class: "mdc-layout-grid__inner",
  1612. $components: [
  1613. {
  1614. $cell: true,
  1615. $type: "div",
  1616. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1617. style: "overflow-y: scroll; max-height: 400px;",
  1618. $components: [
  1619. {
  1620. $cell: true,
  1621. $type: "div",
  1622. class: "mdc-list-group",
  1623. $components: [
  1624. {
  1625. $type: "h3",
  1626. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1627. $text: "Node methods"
  1628. },
  1629. {
  1630. $cell: true,
  1631. $type: "ul",
  1632. class: "mdc-list",
  1633. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1634. }, listDivider,
  1635. {
  1636. $type: "h3",
  1637. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1638. $text: "Proto methods"
  1639. },
  1640. {
  1641. $cell: true,
  1642. $type: "ul",
  1643. class: "mdc-list",
  1644. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1645. }, listDivider,
  1646. {
  1647. $type: "h3",
  1648. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1649. $text: "Events"
  1650. }
  1651. // {
  1652. // $cell: true,
  1653. // $type: "ul",
  1654. // class: "mdc-list",
  1655. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1656. // }
  1657. ]
  1658. }
  1659. ]
  1660. },
  1661. {
  1662. $cell: true,
  1663. $type: "div",
  1664. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1665. $components: [
  1666. {
  1667. $cell: true,
  1668. class: "aceEditor",
  1669. id: "aceEditor",
  1670. $type: "div",
  1671. $text: this._method.body,
  1672. $init: function () {
  1673. createAceEditor(self, this._editorNode, "aceEditor");
  1674. }
  1675. }
  1676. ]
  1677. }
  1678. ]
  1679. },
  1680. {
  1681. $cell: true,
  1682. $type: "div",
  1683. class: "mdc-layout-grid__inner",
  1684. $components: [
  1685. {
  1686. $cell: true,
  1687. $type: "div",
  1688. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1689. $components: [
  1690. {
  1691. $type: "span",
  1692. $text: "*"
  1693. }
  1694. ]
  1695. }
  1696. ]
  1697. },
  1698. { //params input
  1699. $cell: true,
  1700. $type: "div",
  1701. class: "mdc-layout-grid__inner",
  1702. $components: [
  1703. {
  1704. $cell: true,
  1705. $type: "div",
  1706. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1707. $components: [
  1708. {
  1709. class: "mdc-textfield",
  1710. $cell: true,
  1711. $type: "div",
  1712. $components: [{
  1713. class: "mdc-textfield__input",
  1714. id: "methodName",
  1715. $cell: true,
  1716. $type: "input",
  1717. type: "text",
  1718. value: "newMethodName",
  1719. onchange: function (e) {
  1720. let propValue = this.value;
  1721. try {
  1722. } catch (e) {
  1723. // restore the original value on error
  1724. }
  1725. }
  1726. }]
  1727. }
  1728. ]
  1729. },
  1730. {
  1731. $cell: true,
  1732. $type: "div",
  1733. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1734. $components: [
  1735. {
  1736. class: "mdc-textfield params-textfield-input",
  1737. $cell: true,
  1738. $type: "div",
  1739. $components: [{
  1740. class: "mdc-textfield__input",
  1741. id: "methodParams",
  1742. $cell: true,
  1743. $type: "input",
  1744. type: "text",
  1745. value: JSON.stringify(this._method.parameters),
  1746. onchange: function (e) {
  1747. let propValue = this.value;
  1748. try {
  1749. } catch (e) {
  1750. // restore the original value on error
  1751. }
  1752. }
  1753. }]
  1754. }
  1755. ]
  1756. },
  1757. {
  1758. $cell: true,
  1759. $type: "div",
  1760. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1761. $components: [
  1762. {
  1763. $cell: true,
  1764. $type: "button",
  1765. class: "mdc-button mdc-button--raised",
  1766. $text: "Create",
  1767. onclick: function (e) {
  1768. let methodName = document.querySelector('#methodName').value;
  1769. //let methodParams = document.querySelector('#methodParams');
  1770. var params = [];
  1771. let body = '';
  1772. let paramsVal = document.querySelector("#methodParams").value;
  1773. if (paramsVal !== '') {
  1774. try {
  1775. params = JSON.parse(paramsVal);
  1776. //params.push(prmtr);
  1777. } catch (e) {
  1778. self.logger.error('Invalid Value');
  1779. }
  1780. }
  1781. self.kernel.createMethod(this._editorNode, methodName, params, body);
  1782. this._setNode(this._editorNode);
  1783. // let editor = document.querySelector("#aceEditor").env.editor;
  1784. // codeEditorDoit.call(self, editor, this._editorNode);
  1785. }
  1786. }
  1787. ]
  1788. }
  1789. ]
  1790. }
  1791. ]
  1792. //$components:
  1793. }
  1794. }
  1795. let propWindow = {
  1796. $cell: true,
  1797. $type: "div",
  1798. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1799. style: "overflow-y: scroll; max-height: 800px;",
  1800. $components: [
  1801. {
  1802. $type: "div",
  1803. class: "mdc-layout-grid__inner",
  1804. $components: [
  1805. {
  1806. $cell: true,
  1807. $type: "div",
  1808. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1809. $components: [
  1810. nodesCell
  1811. ]
  1812. }
  1813. ]
  1814. }
  1815. // <button class="mdc-button">
  1816. // Flat button
  1817. // </button>
  1818. ]
  1819. }
  1820. let clientListCell = {
  1821. $cell: true,
  1822. $type: "div",
  1823. class: "mdc-list",
  1824. id: "clientsList",
  1825. _watchNodes: [],
  1826. _listElement: function (m) {
  1827. return {
  1828. $type: "a",
  1829. class: "mdc-list-item",
  1830. $href: "#",
  1831. $text: m.name,
  1832. onclick: function (e) {
  1833. //self.currentNodeID = m.ID;
  1834. //document.querySelector('#currentNode')._setNode(m.ID);
  1835. }
  1836. }
  1837. },
  1838. $init: function () {
  1839. var t = this;
  1840. setInterval(function () {
  1841. t._updateMe();
  1842. }, 1000);
  1843. },
  1844. _updateMe: function () {
  1845. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1846. },
  1847. $update: function () {
  1848. //this._clientNodes
  1849. this.$components = this._watchNodes.map(this._listElement)
  1850. }
  1851. }
  1852. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1853. //createCellWindow("propWindow", propWindow, "Scene");
  1854. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1855. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1856. let viewSceneProps = {
  1857. $cell: true,
  1858. $type: "div",
  1859. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1860. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1861. $components: [
  1862. {
  1863. $type: "div",
  1864. class: "mdc-layout-grid__inner",
  1865. $components: [
  1866. {
  1867. $cell: true,
  1868. $type: "div",
  1869. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1870. $components: [
  1871. nodesCell
  1872. ]
  1873. }
  1874. ]
  1875. }
  1876. ]
  1877. }
  1878. let sideBar = {
  1879. $cell: true,
  1880. $type: "div",
  1881. id: 'sideBar',
  1882. class: "sideBar mdc-toolbar-fixed-adjust",
  1883. _sideBarComponent: {},
  1884. _sideCurrentNode: '',
  1885. $init: function () {
  1886. this.style.visibility = 'hidden';
  1887. this._importScript("/" + self.getRoot() + "/appui.js");
  1888. },
  1889. _importScript: function (sSrc, fOnload) {
  1890. var oScript = document.createElement("script");
  1891. oScript.type = "text\/javascript";
  1892. oScript.async = false;
  1893. //oScript.onerror = loadError;
  1894. if (fOnload) { oScript.onload = fOnload; }
  1895. oScript.src = sSrc;
  1896. //let sideBar = document.querySelector('#sideBar');
  1897. this.appendChild(oScript);
  1898. },
  1899. _getAppDef: async function () {
  1900. let response = await fetch("/" + self.getRoot() + "/appui.js");
  1901. let data = await response.text();
  1902. //console.log(data)
  1903. return data
  1904. },
  1905. $update: function () {
  1906. this.$components = [
  1907. {
  1908. $cell: true,
  1909. $type: "button",
  1910. class: "mdc-button mdc-button--compact",
  1911. $text: "X",
  1912. onclick: function (e) {
  1913. document.querySelector('#sideBar').style.visibility = 'hidden';
  1914. }
  1915. },
  1916. this._sideBarComponent
  1917. ]
  1918. }
  1919. //$components: [this._sideComponents]
  1920. }
  1921. document.querySelector('#' + 'sideBar').$cell(sideBar)
  1922. let defaultApp = function () {
  1923. return {
  1924. $cell: true,
  1925. $type: "div",
  1926. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  1927. $components: [
  1928. {
  1929. $cell: true,
  1930. $type: "div",
  1931. class: "mdc-layout-grid__inner",
  1932. $components: [
  1933. {
  1934. $cell: true,
  1935. $type: "div",
  1936. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1937. $components: [
  1938. {
  1939. $cell: true,
  1940. $type: "h3",
  1941. class: "mdc-typography--headline",
  1942. $text: "Application",
  1943. }
  1944. ]
  1945. }
  1946. ]
  1947. }
  1948. ]
  1949. }
  1950. }
  1951. let drawerCell = {
  1952. $cell: true,
  1953. $type: "nav",
  1954. class: "mdc-temporary-drawer__drawer",
  1955. $components: [
  1956. {
  1957. $cell: true,
  1958. $type: "header",
  1959. class: "mdc-temporary-drawer__header",
  1960. $components: [
  1961. {
  1962. $cell: true,
  1963. $type: "div",
  1964. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  1965. $text: "Home"
  1966. }
  1967. ]
  1968. },
  1969. {
  1970. $cell: true,
  1971. $type: "nav",
  1972. class: "mdc-temporary-drawer__content mdc-list-group",
  1973. $components: [
  1974. {
  1975. $cell: true,
  1976. $type: "div",
  1977. class: "mdc-list",
  1978. $components: [
  1979. {
  1980. $cell: true,
  1981. $type: "a",
  1982. class: "mdc-list-item",
  1983. $href: "#",
  1984. onclick: function (e) {
  1985. let sideBar = document.querySelector('#sideBar');
  1986. try {
  1987. sideBar._sideBarComponent = createApp.call(self);
  1988. } catch (e) {
  1989. sideBar._sideBarComponent = defaultApp();
  1990. }
  1991. drawer.open = !drawer.open
  1992. document.querySelector('#sideBar').style.visibility = 'visible';
  1993. },
  1994. $components: [{
  1995. $type: "i",
  1996. class: "material-icons mdc-list-item__start-detail",
  1997. 'aria-hidden': "true",
  1998. $text: "play_arrow"
  1999. },
  2000. {
  2001. $text: "App"
  2002. }]
  2003. },
  2004. {
  2005. $cell: true,
  2006. $type: "a",
  2007. class: "mdc-list-item",
  2008. $href: "#",
  2009. onclick: function (e) {
  2010. let sideBar = document.querySelector('#sideBar');
  2011. sideBar._sideBarComponent = viewSceneProps;
  2012. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  2013. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  2014. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  2015. document.querySelector('#sideBar').style.visibility = 'visible';
  2016. drawer.open = !drawer.open
  2017. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2018. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2019. // document.querySelector('#currentNode')._setNode(currentNode);
  2020. },
  2021. $components: [{
  2022. $cell: true,
  2023. $type: "i",
  2024. class: "material-icons mdc-list-item__start-detail",
  2025. $text: "description"
  2026. },
  2027. {
  2028. $text: "Scene"
  2029. }
  2030. ]
  2031. },
  2032. {
  2033. $cell: true,
  2034. $type: "a",
  2035. class: "mdc-list-item",
  2036. $href: "#",
  2037. onclick: function (e) {
  2038. // var currentNode = document.querySelector('#currentNode')._currentNode;
  2039. // if (currentNode == '') {
  2040. // currentNode = vwf_view.kernel.find("", "/")[0];
  2041. // }
  2042. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  2043. //createAceEditor(self, currentNode);
  2044. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2045. },
  2046. $components: [{
  2047. $type: "i",
  2048. class: "material-icons mdc-list-item__start-detail",
  2049. 'aria-hidden': "true",
  2050. $text: "code"
  2051. },
  2052. {
  2053. $text: "Code editor"
  2054. }]
  2055. },
  2056. {
  2057. $cell: true,
  2058. $type: "a",
  2059. class: "mdc-list-item",
  2060. $href: "#",
  2061. onclick: function (e) {
  2062. //self.currentNodeID = m.ID;
  2063. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2064. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2065. let sideBar = document.querySelector('#sideBar');
  2066. sideBar._sideBarComponent = avatarSettings;
  2067. drawer.open = !drawer.open
  2068. document.querySelector('#sideBar').style.visibility = 'visible';
  2069. },
  2070. $components: [{
  2071. $type: "i",
  2072. class: "material-icons mdc-list-item__start-detail",
  2073. 'aria-hidden': "true",
  2074. $text: "account_circle"
  2075. },
  2076. {
  2077. $text: "My Avatar"
  2078. }]
  2079. },
  2080. {
  2081. $cell: true,
  2082. $type: "a",
  2083. class: "mdc-list-item",
  2084. $href: "#",
  2085. onclick: function (e) {
  2086. //self.currentNodeID = m.ID;
  2087. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2088. let sideBar = document.querySelector('#sideBar');
  2089. sideBar._sideBarComponent = viewSettings;
  2090. drawer.open = !drawer.open
  2091. document.querySelector('#sideBar').style.visibility = 'visible';
  2092. },
  2093. $components: [{
  2094. $type: "i",
  2095. class: "material-icons mdc-list-item__start-detail",
  2096. 'aria-hidden': "true",
  2097. $text: "settings"
  2098. },
  2099. {
  2100. $text: "Settings"
  2101. }]
  2102. },
  2103. {
  2104. $cell: true,
  2105. $type: "a",
  2106. class: "mdc-list-item",
  2107. $href: "#",
  2108. onclick: function (e) {
  2109. //self.currentNodeID = m.ID;
  2110. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2111. let sideBar = document.querySelector('#sideBar');
  2112. sideBar._sideBarComponent = loadSaveSettings;
  2113. if (document.querySelector('#loadSaveSettings')) {
  2114. document.querySelector('#loadSaveSettings')._getStates();
  2115. }
  2116. //sideBar._sideBarComponent._getStates();
  2117. drawer.open = !drawer.open
  2118. document.querySelector('#sideBar').style.visibility = 'visible';
  2119. },
  2120. $components: [{
  2121. $type: "i",
  2122. class: "material-icons mdc-list-item__start-detail",
  2123. 'aria-hidden': "true",
  2124. $text: "save"
  2125. },
  2126. {
  2127. $text: "Load/Save"
  2128. }]
  2129. }
  2130. ]
  2131. },
  2132. {
  2133. $cell: true,
  2134. $type: "hr",
  2135. class: "mdc-list-divider",
  2136. },
  2137. {
  2138. $cell: true,
  2139. $type: "h3",
  2140. class: "userList mdc-list-group__subheader",
  2141. $text: "Users online"
  2142. },
  2143. clientListCell
  2144. ]
  2145. }
  2146. // {
  2147. // $cell: true,
  2148. // $type: "div",
  2149. // class: "mdc-persistent-drawer__toolbar-spacer",
  2150. // },
  2151. // {
  2152. // $cell: true,
  2153. // $type: "div",
  2154. // class: "mdc-list-group",
  2155. // $components: [{
  2156. // $cell: true,
  2157. // $type: "nav",
  2158. // class: "mdc-list",
  2159. // $components: [
  2160. // ]
  2161. // }]
  2162. // }
  2163. ]
  2164. };
  2165. // <div class="mdc-form-field">
  2166. // <input type="checkbox" id="input">
  2167. // <label for="input">Input Label</label>
  2168. // </div>
  2169. document.querySelector("#drawer").$cell({
  2170. $cell: true,
  2171. $type: "aside",
  2172. class: "mdc-temporary-drawer",
  2173. $components: [drawerCell]
  2174. }
  2175. );
  2176. let toolbar = {
  2177. $cell: true,
  2178. $type: "div",
  2179. class: "mdc-toolbar__row",
  2180. $components: [{
  2181. $type: "section",
  2182. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2183. $components: [
  2184. {
  2185. $type: "button",
  2186. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  2187. $text: "menu"
  2188. },
  2189. {
  2190. $type: "span",
  2191. class: "mdc-toolbar__title catalog-title",
  2192. $text: "LiveCoding.space"
  2193. }
  2194. ]
  2195. }]
  2196. };
  2197. document.querySelector("#toolbar").$cell({
  2198. $cell: true,
  2199. $type: "div",
  2200. class: "mdc-toolbar mdc-toolbar--fixed",
  2201. $components: [toolbar]
  2202. }
  2203. );
  2204. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  2205. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  2206. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  2207. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  2208. var drawer = new MDCTemporaryDrawer(drawerEl);
  2209. document.querySelector('.demo-menu').addEventListener('click', function () {
  2210. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  2211. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2212. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2213. // document.querySelector('#currentNode')._setNode(currentNode);
  2214. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  2215. drawer.open = !drawer.open;
  2216. });
  2217. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  2218. //console.log('Received MDCPersistentDrawer:open');
  2219. });
  2220. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  2221. //console.log('Received MDCPersistentDrawer:close');
  2222. });
  2223. //==============
  2224. },
  2225. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2226. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2227. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2228. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2229. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2230. var kernel = this.kernel;
  2231. var self = this;
  2232. var parent = this.nodes[nodeID];
  2233. var node = this.nodes[childID] = {
  2234. children: [],
  2235. properties: [],
  2236. events: {},
  2237. methods: {},
  2238. parent: parent,
  2239. parentID: nodeID,
  2240. ID: childID,
  2241. extendsID: childExtendsID,
  2242. implementsIDs: childImplementsIDs,
  2243. source: childSource,
  2244. name: childName,
  2245. };
  2246. if (parent) {
  2247. parent.children.push(node);
  2248. }
  2249. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2250. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2251. this.scenes[childID] = node;
  2252. }
  2253. let nodeCell = document.querySelector("#currentNode");
  2254. if (nodeCell !== null) {
  2255. if (nodeCell._currentNode === nodeID) {
  2256. nodeCell._getChildNodes();
  2257. }
  2258. }
  2259. if (nodeID === this.kernel.application()) {
  2260. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2261. document.querySelector('body').classList.add("editor-body");
  2262. }
  2263. },
  2264. createdProperty: function (nodeID, propertyName, propertyValue) {
  2265. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2266. },
  2267. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2268. var node = this.nodes[nodeID];
  2269. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2270. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2271. node.properties.push(property);
  2272. },
  2273. deletedNode: function (nodeID) {
  2274. var node = this.nodes[nodeID];
  2275. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2276. delete this.nodes[nodeID];
  2277. let nodeCell = document.querySelector("#currentNode");
  2278. if (nodeCell) {
  2279. if (nodeCell._currentNode !== "") {
  2280. if (nodeCell._currentNode !== nodeID) {
  2281. //&& (this.nodes[nodeID] !== undefined)
  2282. nodeCell._getChildNodes();
  2283. } else {
  2284. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2285. nodeCell._getChildNodes();
  2286. }
  2287. }
  2288. }
  2289. },
  2290. //addedChild: [ /* nodeID, childID, childName */ ],
  2291. //removedChild: [ /* nodeID, childID */ ],
  2292. satProperty: function (nodeID, propertyName, propertyValue) {
  2293. var node = this.nodes[nodeID];
  2294. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2295. // It is possible for a property to have satProperty called for it without ever getting an
  2296. // initializedProperty (if that property delegated to itself or another on replication)
  2297. // Catch that case here and create the property
  2298. if (!node.properties[propertyName]) {
  2299. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2300. node.properties.push(property);
  2301. }
  2302. try {
  2303. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2304. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2305. node.properties[propertyName].rawValue = propertyValue;
  2306. } catch (e) {
  2307. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2308. "stringify error:", e.message);
  2309. node.properties[propertyName].value = propertyValue;
  2310. }
  2311. let nodeCell = document.querySelector('#currentNode');
  2312. if (nodeCell !== null) {
  2313. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2314. console.log('EDIT !!!')
  2315. }
  2316. }
  2317. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2318. if (propCell !== null) {
  2319. if (propCell._currentNode == nodeID) {
  2320. propCell.value = node.properties[propertyName].getValue();
  2321. }
  2322. }
  2323. },
  2324. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2325. gotProperty: function (nodeID, propertyName, propertyValue) {
  2326. var node = this.nodes[nodeID];
  2327. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2328. let nodeCell = document.querySelector('#currentNode');
  2329. if (nodeCell !== null) {
  2330. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2331. let editCheckBox = document.querySelector("#currentNode #editnode");
  2332. if (editCheckBox) {
  2333. if (propertyValue) {
  2334. editCheckBox.setAttribute('checked', '');
  2335. } else {
  2336. let checkAttr = editCheckBox.getAttribute('checked');
  2337. if (checkAttr) editCheckBox.removeAttribute('checked');
  2338. }
  2339. }
  2340. console.log('EDIT !!! is ' + propertyValue)
  2341. }
  2342. }
  2343. },
  2344. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2345. var node = this.nodes[nodeID];
  2346. if (node) {
  2347. node.methods[methodName] = methodParameters;
  2348. }
  2349. },
  2350. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2351. //},
  2352. createdEvent: function (nodeID, eventName, eventParameters) {
  2353. var node = this.nodes[nodeID];
  2354. if (node) {
  2355. node.events[eventName] = eventParameters;
  2356. }
  2357. },
  2358. firedEvent: function (nodeID, eventName, eventParameters) {
  2359. },
  2360. executed: function (nodeID, scriptText, scriptType) {
  2361. // var nodeScript = {
  2362. // text: scriptText,
  2363. // type: scriptType,
  2364. // };
  2365. // if ( !this.allScripts[ nodeID ] ) {
  2366. // var nodeScripts = new Array();
  2367. // nodeScripts.push(nodeScript);
  2368. // this.allScripts[ nodeID ] = nodeScripts;
  2369. // }
  2370. // else {
  2371. // this.allScripts[ nodeID ].push(nodeScript);
  2372. // }
  2373. },
  2374. //ticked: [ /* time */ ],
  2375. });
  2376. function createCellWindow(elementID, cellNode, title) {
  2377. document.querySelector('#' + elementID).$cell({
  2378. $cell: true,
  2379. $type: "div",
  2380. id: elementID,
  2381. class: 'draggable',
  2382. $init: function () {
  2383. // let draggie = new Draggabilly('.draggable', {
  2384. // handle: '.handle',
  2385. // containment: true
  2386. // });
  2387. // get all draggie elements
  2388. var draggableElems = document.querySelectorAll('.draggable');
  2389. // array of Draggabillies
  2390. var draggies = []
  2391. // init Draggabillies
  2392. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2393. var draggableElem = draggableElems[i];
  2394. var draggie = new Draggabilly(draggableElem, {
  2395. handle: '.handle',
  2396. containment: true
  2397. });
  2398. draggies.push(draggie);
  2399. }
  2400. this.style.visibility = 'hidden';
  2401. },
  2402. $components: [
  2403. {
  2404. $cell: true,
  2405. $type: "div",
  2406. class: "handle",
  2407. $components: [
  2408. {
  2409. $cell: true,
  2410. $type: "button",
  2411. class: "mdc-button mdc-button--compact",
  2412. $text: "X",
  2413. onclick: function (e) {
  2414. //self.currentNodeID = m.ID;
  2415. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2416. }
  2417. },
  2418. {
  2419. $cell: true,
  2420. $type: "span",
  2421. class: "mdc-typography--button",
  2422. $text: title
  2423. }
  2424. ]
  2425. },
  2426. cellNode,
  2427. {
  2428. $cell: true,
  2429. $type: "div",
  2430. class: "handle",
  2431. style: "height: 10px; width: inherit;",
  2432. //$text: "sdfsdf"
  2433. }
  2434. // { $text: "23423"}
  2435. ]
  2436. }
  2437. );
  2438. }
  2439. // -- getChildByName --------------------------------------------------------------------
  2440. function getChildByName(node, childName) {
  2441. var childNode = undefined;
  2442. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2443. if (node.children[i].name == childName) {
  2444. childNode = node.children[i];
  2445. }
  2446. }
  2447. return childNode;
  2448. };
  2449. // -- viewScript ------------------------------------------------------------------------
  2450. function createAceEditor(view, nodeID, elID) {
  2451. var editor = view.ace.edit(elID);
  2452. editor.setTheme("ace/theme/monokai");
  2453. editor.setFontSize(16);
  2454. editor.getSession().setMode("ace/mode/javascript");
  2455. editor.commands.addCommand({
  2456. name: "doit",
  2457. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2458. exec: function () {
  2459. codeEditorDoit(editor, nodeID);
  2460. }
  2461. });
  2462. editor.commands.addCommand({
  2463. name: "printit",
  2464. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2465. exec: function () {
  2466. codeEditorPrintit(editor, nodeID);
  2467. }
  2468. });
  2469. return editor;
  2470. }
  2471. function getPrototypes(kernel, extendsID) {
  2472. var prototypes = [];
  2473. var id = extendsID;
  2474. while (id !== undefined) {
  2475. prototypes.push(id);
  2476. id = kernel.prototype(id);
  2477. }
  2478. return prototypes;
  2479. }
  2480. function getPrototypes(kernel, extendsID) {
  2481. var prototypes = [];
  2482. var id = extendsID;
  2483. while (id !== undefined) {
  2484. prototypes.push(id);
  2485. id = kernel.prototype(id);
  2486. }
  2487. return prototypes;
  2488. }
  2489. function createProperty(node, propertyName, propertyValue) {
  2490. var property = {
  2491. name: propertyName,
  2492. rawValue: propertyValue,
  2493. value: undefined,
  2494. getValue: function () {
  2495. var propertyValue;
  2496. if (this.value == undefined) {
  2497. try {
  2498. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  2499. this.value = JSON.stringify(propertyValue);
  2500. } catch (e) {
  2501. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  2502. "stringify error:", e.message);
  2503. this.value = this.rawValue;
  2504. }
  2505. }
  2506. return this.value;
  2507. }
  2508. };
  2509. return property;
  2510. }
  2511. function getProperties(kernel, extendsID) {
  2512. var pTypes = getPrototypes(kernel, extendsID);
  2513. var pProperties = {};
  2514. if (pTypes) {
  2515. for (var i = 0; i < pTypes.length; i++) {
  2516. var nd = this.nodes[pTypes[i]];
  2517. if (nd && nd.properties) {
  2518. for (var key in nd.properties) {
  2519. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  2520. }
  2521. }
  2522. }
  2523. }
  2524. return pProperties;
  2525. }
  2526. function getChildren(kernel, extendsID) {
  2527. var pTypes = getPrototypes(kernel, extendsID);
  2528. var pChildren = {};
  2529. if (pTypes) {
  2530. for (var i = 0; i < pTypes.length; i++) {
  2531. var nd = this.nodes[pTypes[i]];
  2532. if (nd && nd.children) {
  2533. for (var key in nd.children) {
  2534. pChildren[key] = nd.children[key];
  2535. }
  2536. }
  2537. }
  2538. }
  2539. return pChildren;
  2540. }
  2541. function getEvents(kernel, extendsID) {
  2542. var pTypes = getPrototypes(kernel, extendsID);
  2543. var events = {};
  2544. if (pTypes) {
  2545. for (var i = 0; i < pTypes.length; i++) {
  2546. var nd = this.nodes[pTypes[i]];
  2547. if (nd && nd.events) {
  2548. for (var key in nd.events) {
  2549. events[key] = nd.events[key];
  2550. }
  2551. }
  2552. }
  2553. }
  2554. return events;
  2555. }
  2556. function getMethods(kernel, extendsID) {
  2557. var pTypes = getPrototypes(kernel, extendsID);
  2558. var methods = {};
  2559. if (pTypes) {
  2560. for (var i = 0; i < pTypes.length; i++) {
  2561. var nd = this.nodes[pTypes[i]];
  2562. if (nd && nd.methods) {
  2563. for (var key in nd.methods) {
  2564. methods[key] = nd.methods[key];
  2565. }
  2566. }
  2567. }
  2568. }
  2569. return methods;
  2570. }
  2571. // -- Show Code Editor tab
  2572. function codeEditorDoit(editor, nodeID) {
  2573. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2574. if (selectedText == "") {
  2575. var currline = editor.getSelectionRange().start.row;
  2576. var selectedText = editor.session.getLine(currline);
  2577. }
  2578. //console.log(selectedText);
  2579. //var sceneID = self.kernel.application();
  2580. vwf_view.kernel.execute(nodeID, selectedText);
  2581. }
  2582. function codeEditorPrintit(editor, nodeID) {
  2583. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2584. if (selectedText == "") {
  2585. var currline = editor.getSelectionRange().start.row;
  2586. var selectedText = editor.session.getLine(currline);
  2587. }
  2588. //console.log(selectedText);
  2589. //var sceneID = self.kernel.application();
  2590. let scriptText = 'console.log(' + selectedText + ');'
  2591. self.kernel.execute(nodeID, scriptText);
  2592. }
  2593. function saveStateAsFile(filename) // invoke with the view as "this"
  2594. {
  2595. this.logger.info("Saving: " + filename);
  2596. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  2597. if (supportAjaxUploadWithProgress.call(this)) {
  2598. var xhr = new XMLHttpRequest();
  2599. // Save State Information
  2600. var state = vwf.getState();
  2601. state.nodes[0].children = {};
  2602. var timestamp = state["queue"].time;
  2603. timestamp = Math.round(timestamp * 1000);
  2604. var objectIsTypedArray = function (candidate) {
  2605. var typedArrayTypes = [
  2606. Int8Array,
  2607. Uint8Array,
  2608. // Uint8ClampedArray,
  2609. Int16Array,
  2610. Uint16Array,
  2611. Int32Array,
  2612. Uint32Array,
  2613. Float32Array,
  2614. Float64Array
  2615. ];
  2616. var isTypedArray = false;
  2617. if (typeof candidate == "object" && candidate != null) {
  2618. typedArrayTypes.forEach(function (typedArrayType) {
  2619. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  2620. });
  2621. }
  2622. return isTypedArray;
  2623. };
  2624. var transitTransformation = function (object) {
  2625. return objectIsTypedArray(object) ?
  2626. Array.prototype.slice.call(object) : object;
  2627. };
  2628. var json = JSON.stringify(
  2629. require("vwf/utility").transform(
  2630. state, transitTransformation
  2631. )
  2632. );
  2633. json = $.encoder.encodeForURL(json);
  2634. var path = window.location.pathname;
  2635. var pathSplit = path.split('/');
  2636. if (pathSplit[0] == "") {
  2637. pathSplit.shift();
  2638. }
  2639. if (pathSplit[pathSplit.length - 1] == "") {
  2640. pathSplit.pop();
  2641. }
  2642. var inst = undefined;
  2643. var instIndex = pathSplit.length - 1;
  2644. if (pathSplit.length > 2) {
  2645. if (pathSplit[pathSplit.length - 2] == "load") {
  2646. instIndex = pathSplit.length - 3;
  2647. }
  2648. }
  2649. if (pathSplit.length > 3) {
  2650. if (pathSplit[pathSplit.length - 3] == "load") {
  2651. instIndex = pathSplit.length - 4;
  2652. }
  2653. }
  2654. inst = pathSplit[instIndex];
  2655. var root = "";
  2656. for (var i = 0; i < instIndex; i++) {
  2657. if (root != "") {
  2658. root = root + "/";
  2659. }
  2660. root = root + pathSplit[i];
  2661. }
  2662. if (filename == '') filename = inst;
  2663. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2664. xhr.open("POST", "/" + root + "/save/" + filename, true);
  2665. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2666. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  2667. // Save Config Information
  2668. var config = { "info": {}, "model": {}, "view": {} };
  2669. // Save browser title
  2670. config["info"]["title"] = document.title//$('title').html();
  2671. // Save model drivers
  2672. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  2673. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  2674. });
  2675. // If neither glge or threejs model drivers are defined, specify nodriver
  2676. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  2677. // Save view drivers and associated parameters, if any
  2678. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  2679. if (viewDriver.indexOf('vwf/view/') != -1) {
  2680. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  2681. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  2682. }
  2683. else config["view"][viewDriver] = "";
  2684. }
  2685. });
  2686. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  2687. // Save config file to server
  2688. var xhrConfig = new XMLHttpRequest();
  2689. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  2690. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2691. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  2692. }
  2693. else {
  2694. console.error("Unable to save state.");
  2695. }
  2696. }
  2697. // -- LoadSavedState --------------------------------------------------------------------------
  2698. function loadSavedState(filename, applicationpath, revision) {
  2699. this.logger.info("Loading: " + filename);
  2700. // Redirect until setState ID conflict is resolved
  2701. var path = window.location.pathname;
  2702. var inst = path.substring(path.length - 17, path.length - 1);
  2703. var pathSplit = path.split('/');
  2704. if (pathSplit[0] == "") {
  2705. pathSplit.shift();
  2706. }
  2707. if (pathSplit[pathSplit.length - 1] == "") {
  2708. pathSplit.pop();
  2709. }
  2710. var inst = undefined;
  2711. var instIndex = pathSplit.length - 1;
  2712. if (pathSplit.length > 2) {
  2713. if (pathSplit[pathSplit.length - 2] == "load") {
  2714. instIndex = pathSplit.length - 3;
  2715. }
  2716. }
  2717. if (pathSplit.length > 3) {
  2718. if (pathSplit[pathSplit.length - 3] == "load") {
  2719. instIndex = pathSplit.length - 4;
  2720. }
  2721. }
  2722. inst = pathSplit[instIndex];
  2723. if (revision) {
  2724. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  2725. }
  2726. else {
  2727. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  2728. }
  2729. // $.get(filename,function(data,status){
  2730. // vwf.setState(data);
  2731. // });
  2732. }
  2733. // -- SupportAjax -----------------------------------------------------------------------------
  2734. function supportAjaxUploadWithProgress() {
  2735. return supportAjaxUploadProgressEvents();
  2736. function supportAjaxUploadProgressEvents() {
  2737. var xhr = new XMLHttpRequest();
  2738. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  2739. }
  2740. }
  2741. });