pinokiod 0.1.40 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -21,6 +21,8 @@ const http = require('isomorphic-git/http/node')
21
21
  const marked = require('marked')
22
22
  const multer = require('multer');
23
23
  const localtunnel = require('localtunnel');
24
+ const ejs = require('ejs');
25
+
24
26
 
25
27
 
26
28
 
@@ -960,7 +962,6 @@ class Server {
960
962
  // items
961
963
 
962
964
 
963
- console.log("ITEMS", items)
964
965
 
965
966
 
966
967
  // let U = `${_p}/${pathComponents.join("/")}`
@@ -1029,115 +1030,133 @@ class Server {
1029
1030
  }
1030
1031
  }
1031
1032
  async renderMenu(uri, name, config, pathComponents) {
1032
- for(let i=0; i<config.menu.length; i++) {
1033
- let menuitem = config.menu[i]
1033
+ if (config.menu) {
1034
+ for(let i=0; i<config.menu.length; i++) {
1035
+ let menuitem = config.menu[i]
1034
1036
 
1035
- if (menuitem.href && !menuitem.href.startsWith("http")) {
1037
+ if (menuitem.menu) {
1038
+ let m = await this.renderMenu(uri, name, { menu: menuitem.menu }, pathComponents)
1039
+ menuitem.menu = m.menu
1040
+ }
1036
1041
 
1037
- // href resolution
1038
- let absolute = path.resolve(__dirname, ...pathComponents, menuitem.href)
1039
- let seed = path.resolve(__dirname)
1040
- let p = absolute.replace(seed, "")
1041
- let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
1042
- config.menu[i].href = "/api/" + name + "/" + link
1043
- }
1044
1042
 
1043
+ if (menuitem.href && !menuitem.href.startsWith("http")) {
1045
1044
 
1046
- if (menuitem.href) {
1047
- let u
1048
- if (menuitem.href.startsWith("http")) {
1049
- menuitem.src = menuitem.href
1050
- } else if (menuitem.href.startsWith("/")) {
1051
- u = new URL("http://localhost" + menuitem.href)
1052
- u.search = ""
1053
- menuitem.src = u.pathname
1054
- } else {
1055
- u = new URL("http://localhost/" + menuitem.href)
1056
- u.search = ""
1057
- menuitem.src = u.pathname
1045
+ // href resolution
1046
+ let absolute = path.resolve(__dirname, ...pathComponents, menuitem.href)
1047
+ let seed = path.resolve(__dirname)
1048
+ let p = absolute.replace(seed, "")
1049
+ let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
1050
+ config.menu[i].href = "/api/" + name + "/" + link
1058
1051
  }
1059
1052
 
1060
-
1061
- // check running
1062
- let fullpath = this.kernel.path(menuitem.src.slice(1))
1063
- if (this.kernel.api.running[fullpath]) {
1064
- menuitem.running = true
1053
+ if (menuitem.href && menuitem.params) {
1054
+ menuitem.href = menuitem.href + "?" + new URLSearchParams(menuitem.params).toString();
1065
1055
  }
1066
1056
 
1067
- }
1057
+ if (menuitem.href) {
1058
+ let u
1059
+ if (menuitem.href.startsWith("http")) {
1060
+ menuitem.src = menuitem.href
1061
+ } else if (menuitem.href.startsWith("/")) {
1062
+ u = new URL("http://localhost" + menuitem.href)
1063
+ u.search = ""
1064
+ menuitem.src = u.pathname
1065
+ } else {
1066
+ u = new URL("http://localhost/" + menuitem.href)
1067
+ u.search = ""
1068
+ menuitem.src = u.pathname
1069
+ }
1068
1070
 
1069
1071
 
1072
+ // check running
1073
+ let fullpath = this.kernel.path(menuitem.src.slice(1))
1074
+ if (this.kernel.api.running[fullpath]) {
1075
+ menuitem.running = true
1076
+ }
1070
1077
 
1071
- if (menuitem.href && menuitem.params) {
1072
- menuitem.href = menuitem.href + "?" + new URLSearchParams(menuitem.params).toString();
1073
- }
1078
+ }
1074
1079
 
1075
1080
 
1076
1081
 
1077
- // check on/off: if on/off exists => assume that it's a script
1078
- // 1. check if the script is running
1079
- if (menuitem.when) {
1080
- let scriptPath = path.resolve(uri, name, menuitem.when)
1081
- let filepath = scriptPath.replace(/\?.+/, "")
1082
- let check = this.kernel.status(filepath)
1083
- if (check) {
1084
- // 2. if it's running, display the "on" HTML. If "on" doesn't exist, don't display anything
1085
- if (menuitem.on) {
1086
- if (menuitem.type === "label") {
1087
- config.menu[i].label = menuitem.on
1088
- } else {
1089
- config.menu[i].btn = menuitem.on
1082
+ // if (menuitem.href && menuitem.params) {
1083
+ // menuitem.href = menuitem.href + "?" + new URLSearchParams(menuitem.params).toString();
1084
+ // }
1085
+
1086
+
1087
+
1088
+ // check on/off: if on/off exists => assume that it's a script
1089
+ // 1. check if the script is running
1090
+ if (menuitem.when) {
1091
+ let scriptPath = path.resolve(uri, name, menuitem.when)
1092
+ let filepath = scriptPath.replace(/\?.+/, "")
1093
+ let check = this.kernel.status(filepath)
1094
+ if (check) {
1095
+ // 2. if it's running, display the "on" HTML. If "on" doesn't exist, don't display anything
1096
+ if (menuitem.on) {
1097
+ if (menuitem.type === "label") {
1098
+ config.menu[i].label = menuitem.on
1099
+ } else {
1100
+ config.menu[i].btn = menuitem.on
1101
+ }
1102
+ }
1103
+ } else {
1104
+ // 3. If it's NOT running, display the "off" HTML, If "off" doesn't exist, don't display anything
1105
+ if (menuitem.off) {
1106
+ if (menuitem.type === "label") {
1107
+ config.menu[i].label = menuitem.off
1108
+ } else {
1109
+ config.menu[i].btn = menuitem.off
1110
+ }
1090
1111
  }
1091
1112
  }
1092
- } else {
1093
- // 3. If it's NOT running, display the "off" HTML, If "off" doesn't exist, don't display anything
1094
- if (menuitem.off) {
1095
- if (menuitem.type === "label") {
1096
- config.menu[i].label = menuitem.off
1097
- } else {
1098
- config.menu[i].btn = menuitem.off
1113
+ } else if (menuitem.filter) {
1114
+ if (menuitem.filter()) {
1115
+ if (menuitem.hasOwnProperty("html")) {
1116
+ if (menuitem.type === "label") {
1117
+ config.menu[i].label = menuitem.html
1118
+ } else {
1119
+ config.menu[i].btn = menuitem.html
1120
+ }
1099
1121
  }
1100
1122
  }
1101
- }
1102
- } else if (menuitem.filter) {
1103
- if (menuitem.filter()) {
1123
+ } else {
1104
1124
  if (menuitem.hasOwnProperty("html")) {
1105
1125
  if (menuitem.type === "label") {
1106
1126
  config.menu[i].label = menuitem.html
1107
1127
  } else {
1108
1128
  config.menu[i].btn = menuitem.html
1109
1129
  }
1110
- }
1111
- }
1112
- } else {
1113
- if (menuitem.hasOwnProperty("html")) {
1114
- if (menuitem.type === "label") {
1115
- config.menu[i].label = menuitem.html
1116
- } else {
1117
- config.menu[i].btn = menuitem.html
1118
- }
1119
- } else if (menuitem.hasOwnProperty("text")) {
1130
+ } else if (menuitem.hasOwnProperty("text")) {
1120
1131
 
1121
- if (menuitem.hasOwnProperty("icon")) {
1122
- menuitem.html = `<i class="${menuitem.icon}"></i> ${menuitem.text}`
1123
- } else {
1124
- menuitem.html = `${menuitem.text}`
1125
- }
1132
+ console.log("processing", menuitem)
1126
1133
 
1127
- if (menuitem.href) {
1128
- // button
1129
- config.menu[i].btn = menuitem.html
1130
- } else {
1131
- // label
1132
- config.menu[i].label = menuitem.html
1134
+ if (menuitem.hasOwnProperty("icon")) {
1135
+ menuitem.html = `<i class="${menuitem.icon}"></i> ${menuitem.text}`
1136
+ } else {
1137
+ menuitem.html = `${menuitem.text}`
1138
+ }
1139
+
1140
+ if (menuitem.href) {
1141
+ // button
1142
+ config.menu[i].btn = menuitem.html
1143
+ } else if (menuitem.menu) {
1144
+ config.menu[i].btn = menuitem.html
1145
+ } else {
1146
+ // label
1147
+ config.menu[i].label = menuitem.html
1148
+ }
1133
1149
  }
1134
1150
  }
1135
1151
  }
1152
+ config.menu = config.menu.filter((item) => {
1153
+ return item.btn
1154
+ })
1155
+ console.log("config", JSON.stringify(config,null,2))
1156
+ return config
1157
+ } else {
1158
+ return config
1136
1159
  }
1137
- config.menu = config.menu.filter((item) => {
1138
- return item.btn
1139
- })
1140
- return config
1141
1160
  }
1142
1161
  relevant(r) {
1143
1162
  /*
@@ -1653,6 +1672,15 @@ class Server {
1653
1672
 
1654
1673
  console.log({ config })
1655
1674
  }
1675
+
1676
+
1677
+ ejs.renderFile(path.resolve(__dirname, "views/partials/menu.ejs"), { menu: config.menu }, (err, html) => {
1678
+ console.log("html", html)
1679
+ res.send(html)
1680
+ })
1681
+
1682
+
1683
+ /*
1656
1684
  res.json({
1657
1685
  config,
1658
1686
  home: req.originalUrl,
@@ -1661,6 +1689,7 @@ class Server {
1661
1689
  agent: this.agent,
1662
1690
  rawpath
1663
1691
  })
1692
+ */
1664
1693
 
1665
1694
  })
1666
1695
  this.app.get("/pinokio/memory", (req, res) => {
@@ -96,8 +96,16 @@ body.dark .header-item .btn2 {
96
96
  display: block;
97
97
  }
98
98
  .header-item img {
99
+ /*
99
100
  width: 60px;
101
+ */
102
+ width: 80px;
103
+ height: 80px;
104
+ border-radius: 40px;
105
+ object-fit: contain;
106
+ /*
100
107
  border-radius: 30px;
108
+ */
101
109
  }
102
110
  body.dark .header-item.btn {
103
111
  /*
@@ -187,16 +195,14 @@ body.dark .header-item.cursor {
187
195
  */
188
196
  }
189
197
  body .frame-link.selected {
190
- border-left: 10px solid gold;
191
- /*
192
- background: rgba(0,0,200,0.1) !important;
198
+ /*
199
+ border-right: 10px solid gold;
193
200
  */
201
+ background: rgba(0,0,200,0.1) !important;
194
202
  }
195
- /*
196
203
  body.dark .frame-link.selected {
197
204
  background: rgba(0,0,0,0.2) !important;
198
205
  }
199
- */
200
206
  .frame-link .tab {
201
207
  flex-grow: 1;
202
208
  width: 100%;
@@ -300,6 +306,10 @@ body.dark .header-item.cursor.header-top {
300
306
  body.dark #new-tab {
301
307
  border-top: 1px solid rgba(255,255,255,0.04);
302
308
  }
309
+ .submenu {
310
+ padding-left: 15px;
311
+ box-sizing: border-box;
312
+ }
303
313
  </style>
304
314
  </head>
305
315
  <body class='<%=theme%>'>
@@ -311,11 +321,14 @@ body.dark #new-tab {
311
321
  </div>
312
322
  </div>
313
323
  <div class='system'>
314
- <a data-index="0" target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>
324
+ <!--<a data-index="0" target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>-->
325
+ <a target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>
315
326
  <div class='tab'><i class="fa-regular fa-folder-open"></i> Files</div>
316
327
  </a>
317
328
  </div>
318
329
  <div class='menu'>
330
+ <%- include('./partials/menu', { menu: config.menu }) %>
331
+ <!--
319
332
  <% config.menu.forEach((item, index) => { %>
320
333
  <% if (item.btn) { %>
321
334
  <a data-index="<%=index+1%>" target="<%=item.src%>" href="<%=item.href%>" class='btn header-item frame-link'>
@@ -325,11 +338,10 @@ body.dark #new-tab {
325
338
  <% } %>
326
339
  </a>
327
340
  <% } else if (item.label) { %>
328
- <!--
329
341
  <label class='btn label header-item'><%-item.label%></label>
330
- -->
331
342
  <% } %>
332
343
  <% }) %>
344
+ -->
333
345
  </div>
334
346
  <div class='temp-menu'>
335
347
  <%tabs.forEach((tab) => { %>
@@ -376,12 +388,12 @@ body.dark #new-tab {
376
388
  <main class='browserview'>
377
389
  <!--
378
390
  <pre><%=JSON.stringify({ memory, running }, null, 2)%></pre>
379
- -->
380
391
  <% config.menu.forEach((item) => { %>
381
392
  <% if (item.btn && item.src) { %>
382
393
  <iframe name='<%=item.src%>' class='hidden'></iframe>
383
394
  <% } %>
384
395
  <% }) %>
396
+ -->
385
397
  </main>
386
398
  </div>
387
399
  <script>
@@ -414,23 +426,35 @@ const renderSelection = (e, force) => {
414
426
  if (location.hash && location.hash.length > 0) {
415
427
  document.querySelector(".bar").classList.remove("hidden")
416
428
  let id = getTarget(location.hash.slice(1))
417
- console.log("id", id)
418
- console.log("#3", loaded)
419
429
 
420
- document.querySelector("#location").innerHTML = id
430
+ //document.querySelector("#location").innerHTML = id
431
+ document.querySelector("#location").innerHTML = location.hash.slice(1)
421
432
 
422
433
  if (location.hash.slice(1).startsWith("/")) {
423
434
  document.querySelector("#open-browser").classList.add("hidden")
424
435
  } else {
425
436
  document.querySelector("#open-browser").classList.remove("hidden")
426
- document.querySelector("#open-browser").href = id
437
+ //document.querySelector("#open-browser").href = id
438
+ document.querySelector("#open-browser").href = location.hash.slice(1)
427
439
  }
428
440
 
429
441
  // select the selected link
430
- document.querySelectorAll(".frame-link").forEach((el) => {
431
- el.classList.remove("selected")
432
- })
433
- const target = document.querySelector(`[target='${id}']`)
442
+ // document.querySelectorAll(".frame-link").forEach((el) => {
443
+ // el.classList.remove("selected")
444
+ // })
445
+
446
+
447
+
448
+ // const target = document.querySelector(`[target='${id}']`)
449
+ let target
450
+ if (e) {
451
+ if (e.target.classList.contains("frame-link")) {
452
+ target = e.target
453
+ } else {
454
+ target = e.target.closest(".frame-link")
455
+ }
456
+ }
457
+
434
458
  if (target) {
435
459
  target.classList.add("selected")
436
460
 
@@ -439,50 +463,49 @@ const renderSelection = (e, force) => {
439
463
  el.classList.add("hidden")
440
464
  })
441
465
  let targetFrame = document.querySelector(`iframe[name='${target.target}']`)
442
- console.log("#4", loaded)
443
- console.log("targetFrame", targetFrame)
466
+ debugger
444
467
  if (targetFrame) {
445
- console.log("#5", loaded)
446
- console.log({ loaded })
447
468
  targetFrame.classList.remove("hidden")
448
469
 
449
470
  // if the iframe already exists, do not
450
471
  if (loaded[target.target]){
451
472
  if (e) {
452
- e.preventDefault()
453
- e.stopPropagation()
473
+ // triggered with a click
474
+ // do not reload iframe if the href and the src is the same
475
+ if (targetFrame.src === target.href) {
476
+ e.preventDefault()
477
+ e.stopPropagation()
478
+ }
454
479
  } else {
455
- console.log("REFRESH")
456
480
  if (force) {
457
- targetFrame.src = target.href
481
+ if (targetFrame.src !== target.href) {
482
+ targetFrame.src = target.href
483
+ }
458
484
  }
459
485
  }
460
486
  } else {
461
- console.log("load")
462
487
  //targetFrame.contentWindow.addEventListener("load", () => {
463
- console.log("#1")
464
488
  if (e) {
465
489
  // coming from a click => don't need to set the src
466
490
  } else {
467
491
  // load without click
468
- targetFrame.src = target.href
492
+ if (targetFrame.src !== target.href) {
493
+ targetFrame.src = target.href
494
+ }
469
495
  }
470
496
  loaded[target.target] = true
471
497
  //});
472
498
  }
473
499
  } else {
474
- console.log("#6", loaded)
475
500
  let frame = document.createElement("iframe")
476
501
  frame.name = target.target
477
502
  frame.src = target.href
478
503
  document.querySelector("main").appendChild(frame)
479
- console.log("#2")
480
504
  loaded[target.target] = true
481
505
  }
482
506
  }
483
507
  } else {
484
508
  document.querySelector(".bar").classList.add("hidden")
485
-
486
509
  }
487
510
  }
488
511
  console.log("loaded before", loaded)
@@ -552,6 +575,15 @@ const addTab = async (url) => {
552
575
  }
553
576
 
554
577
 
578
+
579
+
580
+ document.querySelector(".app-info").addEventListener("click", async (e) => {
581
+ e.preventDefault()
582
+ e.stopPropagation()
583
+ location.hash = ""
584
+ renderSelection()
585
+
586
+ })
555
587
  document.querySelector("aside").addEventListener("click", async (e) => {
556
588
  let target
557
589
 
@@ -592,12 +624,29 @@ document.querySelector("aside").addEventListener("click", async (e) => {
592
624
 
593
625
  if (target) {
594
626
 
595
- //location.hash = target.target
596
- let id = getTarget(target.getAttribute("href"))
597
- console.log("ID", id, target.href)
598
- location.hash = id
627
+ if (target.classList.contains("reveal")) {
628
+ // nested menu
629
+ target.closest(".nested-menu").querySelector(".submenu").classList.toggle("hidden")
630
+ e.preventDefault()
631
+ e.stopPropagation()
632
+ } else {
633
+ //location.hash = target.target
634
+
635
+
636
+ // let id = getTarget(target.getAttribute("href"))
637
+ // console.log("ID", id, target.href)
638
+ // location.hash = id
639
+
640
+ location.hash = target.getAttribute("href")
641
+
642
+ document.querySelectorAll(".frame-link").forEach((el) => {
643
+ el.classList.remove("selected")
644
+ })
645
+ target.classList.add("selected")
646
+
647
+ renderSelection(e)
648
+ }
599
649
 
600
- renderSelection(e)
601
650
 
602
651
  }
603
652
  }
@@ -606,6 +655,10 @@ document.querySelector("aside").addEventListener("click", async (e) => {
606
655
 
607
656
  })
608
657
  const refresh = async () => {
658
+ const html = await fetch("<%=sidebar%>").then((res) => {
659
+ return res.text()
660
+ })
661
+ /*
609
662
  const res = await fetch("<%=sidebar%>").then((res) => {
610
663
  return res.json()
611
664
  })
@@ -618,10 +671,10 @@ const refresh = async () => {
618
671
  </a>`
619
672
  } else if (item.label) {
620
673
  return ""
621
- // return `<label class='btn label header-item'>${item.label}</label>`
622
674
  }
623
675
  }).join("")
624
676
  console.log("refresh", html)
677
+ */
625
678
  document.querySelector(".menu").innerHTML = html
626
679
  renderSelection()
627
680
  // cursorIndex = 0
@@ -0,0 +1,21 @@
1
+ <% menu.forEach((item, index) => { %>
2
+ <% if (item.menu) { %>
3
+ <div class='nested-menu'>
4
+ <div class='btn header-item frame-link reveal'>
5
+ <div class='tab'><%-item.btn%></div>
6
+ </div>
7
+ <div class='submenu hidden'>
8
+ <%- include('./menu', { menu: item.menu }) %>
9
+ </div>
10
+ </div>
11
+ <% } else { %>
12
+ <% if (item.btn) { %>
13
+ <a data-index="<%=index%>" target="<%=item.src%>" href="<%=item.href%>" class='btn header-item frame-link'>
14
+ <div class='tab'><%-item.btn%></div>
15
+ <% if (item.running) { %>
16
+ <i class='fa-solid fa-spin fa-circle-notch'></i>
17
+ <% } %>
18
+ </a>
19
+ <% } %>
20
+ <% } %>
21
+ <% }) %>