editor-new.js 159 KB

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