pinokiod 0.1.40 → 0.1.42

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.42",
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,17 @@ body.dark .header-item .btn2 {
96
96
  display: block;
97
97
  }
98
98
  .header-item img {
99
+ /*
99
100
  width: 60px;
101
+ */
102
+ height: 80px;
103
+ width: 80px;
104
+ border-radius: 10px;
105
+ object-fit: contain;
106
+ display: inline-block;
107
+ /*
100
108
  border-radius: 30px;
109
+ */
101
110
  }
102
111
  body.dark .header-item.btn {
103
112
  /*
@@ -187,16 +196,14 @@ body.dark .header-item.cursor {
187
196
  */
188
197
  }
189
198
  body .frame-link.selected {
190
- border-left: 10px solid gold;
191
- /*
192
- background: rgba(0,0,200,0.1) !important;
199
+ /*
200
+ border-right: 10px solid gold;
193
201
  */
202
+ background: rgba(0,0,200,0.1) !important;
194
203
  }
195
- /*
196
204
  body.dark .frame-link.selected {
197
205
  background: rgba(0,0,0,0.2) !important;
198
206
  }
199
- */
200
207
  .frame-link .tab {
201
208
  flex-grow: 1;
202
209
  width: 100%;
@@ -300,6 +307,10 @@ body.dark .header-item.cursor.header-top {
300
307
  body.dark #new-tab {
301
308
  border-top: 1px solid rgba(255,255,255,0.04);
302
309
  }
310
+ .submenu {
311
+ padding-left: 15px;
312
+ box-sizing: border-box;
313
+ }
303
314
  </style>
304
315
  </head>
305
316
  <body class='<%=theme%>'>
@@ -311,11 +322,14 @@ body.dark #new-tab {
311
322
  </div>
312
323
  </div>
313
324
  <div class='system'>
314
- <a data-index="0" target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>
325
+ <!--<a data-index="0" target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>-->
326
+ <a target="<%=src%>" href="<%=src%>" class='btn header-item frame-link'>
315
327
  <div class='tab'><i class="fa-regular fa-folder-open"></i> Files</div>
316
328
  </a>
317
329
  </div>
318
330
  <div class='menu'>
331
+ <%- include('./partials/menu', { menu: config.menu }) %>
332
+ <!--
319
333
  <% config.menu.forEach((item, index) => { %>
320
334
  <% if (item.btn) { %>
321
335
  <a data-index="<%=index+1%>" target="<%=item.src%>" href="<%=item.href%>" class='btn header-item frame-link'>
@@ -325,11 +339,10 @@ body.dark #new-tab {
325
339
  <% } %>
326
340
  </a>
327
341
  <% } else if (item.label) { %>
328
- <!--
329
342
  <label class='btn label header-item'><%-item.label%></label>
330
- -->
331
343
  <% } %>
332
344
  <% }) %>
345
+ -->
333
346
  </div>
334
347
  <div class='temp-menu'>
335
348
  <%tabs.forEach((tab) => { %>
@@ -376,12 +389,12 @@ body.dark #new-tab {
376
389
  <main class='browserview'>
377
390
  <!--
378
391
  <pre><%=JSON.stringify({ memory, running }, null, 2)%></pre>
379
- -->
380
392
  <% config.menu.forEach((item) => { %>
381
393
  <% if (item.btn && item.src) { %>
382
394
  <iframe name='<%=item.src%>' class='hidden'></iframe>
383
395
  <% } %>
384
396
  <% }) %>
397
+ -->
385
398
  </main>
386
399
  </div>
387
400
  <script>
@@ -414,23 +427,35 @@ const renderSelection = (e, force) => {
414
427
  if (location.hash && location.hash.length > 0) {
415
428
  document.querySelector(".bar").classList.remove("hidden")
416
429
  let id = getTarget(location.hash.slice(1))
417
- console.log("id", id)
418
- console.log("#3", loaded)
419
430
 
420
- document.querySelector("#location").innerHTML = id
431
+ //document.querySelector("#location").innerHTML = id
432
+ document.querySelector("#location").innerHTML = location.hash.slice(1)
421
433
 
422
434
  if (location.hash.slice(1).startsWith("/")) {
423
435
  document.querySelector("#open-browser").classList.add("hidden")
424
436
  } else {
425
437
  document.querySelector("#open-browser").classList.remove("hidden")
426
- document.querySelector("#open-browser").href = id
438
+ //document.querySelector("#open-browser").href = id
439
+ document.querySelector("#open-browser").href = location.hash.slice(1)
427
440
  }
428
441
 
429
442
  // select the selected link
430
- document.querySelectorAll(".frame-link").forEach((el) => {
431
- el.classList.remove("selected")
432
- })
433
- const target = document.querySelector(`[target='${id}']`)
443
+ // document.querySelectorAll(".frame-link").forEach((el) => {
444
+ // el.classList.remove("selected")
445
+ // })
446
+
447
+
448
+
449
+ // const target = document.querySelector(`[target='${id}']`)
450
+ let target
451
+ if (e) {
452
+ if (e.target.classList.contains("frame-link")) {
453
+ target = e.target
454
+ } else {
455
+ target = e.target.closest(".frame-link")
456
+ }
457
+ }
458
+
434
459
  if (target) {
435
460
  target.classList.add("selected")
436
461
 
@@ -439,50 +464,49 @@ const renderSelection = (e, force) => {
439
464
  el.classList.add("hidden")
440
465
  })
441
466
  let targetFrame = document.querySelector(`iframe[name='${target.target}']`)
442
- console.log("#4", loaded)
443
- console.log("targetFrame", targetFrame)
467
+ debugger
444
468
  if (targetFrame) {
445
- console.log("#5", loaded)
446
- console.log({ loaded })
447
469
  targetFrame.classList.remove("hidden")
448
470
 
449
471
  // if the iframe already exists, do not
450
472
  if (loaded[target.target]){
451
473
  if (e) {
452
- e.preventDefault()
453
- e.stopPropagation()
474
+ // triggered with a click
475
+ // do not reload iframe if the href and the src is the same
476
+ if (targetFrame.src === target.href) {
477
+ e.preventDefault()
478
+ e.stopPropagation()
479
+ }
454
480
  } else {
455
- console.log("REFRESH")
456
481
  if (force) {
457
- targetFrame.src = target.href
482
+ if (targetFrame.src !== target.href) {
483
+ targetFrame.src = target.href
484
+ }
458
485
  }
459
486
  }
460
487
  } else {
461
- console.log("load")
462
488
  //targetFrame.contentWindow.addEventListener("load", () => {
463
- console.log("#1")
464
489
  if (e) {
465
490
  // coming from a click => don't need to set the src
466
491
  } else {
467
492
  // load without click
468
- targetFrame.src = target.href
493
+ if (targetFrame.src !== target.href) {
494
+ targetFrame.src = target.href
495
+ }
469
496
  }
470
497
  loaded[target.target] = true
471
498
  //});
472
499
  }
473
500
  } else {
474
- console.log("#6", loaded)
475
501
  let frame = document.createElement("iframe")
476
502
  frame.name = target.target
477
503
  frame.src = target.href
478
504
  document.querySelector("main").appendChild(frame)
479
- console.log("#2")
480
505
  loaded[target.target] = true
481
506
  }
482
507
  }
483
508
  } else {
484
509
  document.querySelector(".bar").classList.add("hidden")
485
-
486
510
  }
487
511
  }
488
512
  console.log("loaded before", loaded)
@@ -552,6 +576,15 @@ const addTab = async (url) => {
552
576
  }
553
577
 
554
578
 
579
+
580
+
581
+ document.querySelector(".app-info").addEventListener("click", async (e) => {
582
+ e.preventDefault()
583
+ e.stopPropagation()
584
+ location.hash = ""
585
+ renderSelection()
586
+
587
+ })
555
588
  document.querySelector("aside").addEventListener("click", async (e) => {
556
589
  let target
557
590
 
@@ -592,12 +625,29 @@ document.querySelector("aside").addEventListener("click", async (e) => {
592
625
 
593
626
  if (target) {
594
627
 
595
- //location.hash = target.target
596
- let id = getTarget(target.getAttribute("href"))
597
- console.log("ID", id, target.href)
598
- location.hash = id
628
+ if (target.classList.contains("reveal")) {
629
+ // nested menu
630
+ target.closest(".nested-menu").querySelector(".submenu").classList.toggle("hidden")
631
+ e.preventDefault()
632
+ e.stopPropagation()
633
+ } else {
634
+ //location.hash = target.target
635
+
636
+
637
+ // let id = getTarget(target.getAttribute("href"))
638
+ // console.log("ID", id, target.href)
639
+ // location.hash = id
640
+
641
+ location.hash = target.getAttribute("href")
642
+
643
+ document.querySelectorAll(".frame-link").forEach((el) => {
644
+ el.classList.remove("selected")
645
+ })
646
+ target.classList.add("selected")
647
+
648
+ renderSelection(e)
649
+ }
599
650
 
600
- renderSelection(e)
601
651
 
602
652
  }
603
653
  }
@@ -606,6 +656,10 @@ document.querySelector("aside").addEventListener("click", async (e) => {
606
656
 
607
657
  })
608
658
  const refresh = async () => {
659
+ const html = await fetch("<%=sidebar%>").then((res) => {
660
+ return res.text()
661
+ })
662
+ /*
609
663
  const res = await fetch("<%=sidebar%>").then((res) => {
610
664
  return res.json()
611
665
  })
@@ -618,10 +672,10 @@ const refresh = async () => {
618
672
  </a>`
619
673
  } else if (item.label) {
620
674
  return ""
621
- // return `<label class='btn label header-item'>${item.label}</label>`
622
675
  }
623
676
  }).join("")
624
677
  console.log("refresh", html)
678
+ */
625
679
  document.querySelector(".menu").innerHTML = html
626
680
  renderSelection()
627
681
  // 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
+ <% }) %>