editor-new.js 153 KB

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