pinokiod 3.161.0 → 3.163.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/views/app.ejs +141 -72
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.161.0",
3
+ "version": "3.163.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4979,6 +4979,28 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
4979
4979
  }
4980
4980
  return null
4981
4981
  }
4982
+ const forwardEventToParent = (payload) => {
4983
+ if (!payload || typeof payload !== 'object' || payload === null) {
4984
+ return
4985
+ }
4986
+ if (window.parent === window) {
4987
+ return
4988
+ }
4989
+ const forwardingPayload = Object.assign({}, payload, { __pinokioForwarded: true })
4990
+ let forwarded = false
4991
+ if (typeof window.PinokioBroadcastMessage === 'function') {
4992
+ try {
4993
+ forwarded = window.PinokioBroadcastMessage(forwardingPayload, '*', window)
4994
+ } catch (_) {
4995
+ forwarded = false
4996
+ }
4997
+ }
4998
+ if (!forwarded) {
4999
+ try {
5000
+ window.parent.postMessage(forwardingPayload, '*')
5001
+ } catch (_) {}
5002
+ }
5003
+ }
4982
5004
  const getTarget = (href) => {
4983
5005
  let u
4984
5006
  if (href.startsWith("http")) {
@@ -5135,10 +5157,17 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
5135
5157
  }
5136
5158
  }
5137
5159
 
5138
- console.log({ target, skipPersistedSelection })
5160
+ console.log('[renderSelection] init', {
5161
+ triggeredByUser,
5162
+ resolvedByGlobalSelector,
5163
+ skipPersistedSelection,
5164
+ hasPersistedSelection,
5165
+ explicitTarget: Boolean(explicitTarget),
5166
+ targetInitial: target ? target.outerHTML : null
5167
+ })
5139
5168
  if (!target && !skipPersistedSelection) {
5140
5169
  preselected = document.querySelector('#devtab.frame-link.selected') || document.querySelector('.frame-link.selected')
5141
- console.log({ preselected })
5170
+ console.log('[renderSelection] preselected candidate', preselected ? preselected.outerHTML : null)
5142
5171
  }
5143
5172
 
5144
5173
  if (!target && persistedSelectionPayload) {
@@ -5214,7 +5243,7 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
5214
5243
  target = preselected
5215
5244
  }
5216
5245
 
5217
- console.log({ targetAfter: target })
5246
+ console.log('[renderSelection] target after resolution', target ? target.outerHTML : null)
5218
5247
 
5219
5248
  if (!target) {
5220
5249
  target = document.querySelector(".frame-link")
@@ -6192,7 +6221,16 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6192
6221
  const navContainers = [document.querySelector("aside"), document.querySelector("#fs-status")]
6193
6222
  navContainers.forEach((container) => {
6194
6223
  if (container) {
6195
- container.addEventListener("click", handleMenuClick)
6224
+ container.addEventListener("click", (event) => {
6225
+ const frameLink = event.target?.closest && event.target.closest('.frame-link')
6226
+ if (frameLink) {
6227
+ console.log('[handleMenuClick] triggered', {
6228
+ origin: event.target && event.target.className,
6229
+ frameLink: frameLink.outerHTML
6230
+ })
6231
+ }
6232
+ handleMenuClick(event)
6233
+ })
6196
6234
  }
6197
6235
  })
6198
6236
  setupTabLinkHover()
@@ -6271,6 +6309,7 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6271
6309
  status = res.status
6272
6310
  return res.text()
6273
6311
  })
6312
+ console.log('[try_dynamic] fetched', { status, length: dynamic ? dynamic.length : 0 })
6274
6313
  if (status == 500) {
6275
6314
  ModalInput({
6276
6315
  description: dynamic,
@@ -6290,8 +6329,10 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6290
6329
  }
6291
6330
  let default_selection = document.querySelector(".dynamic .submenu [data-default]")
6292
6331
  if (default_selection) {
6293
- console.log("CLICK default")
6332
+ console.log('[try_dynamic] clicking default', default_selection.outerHTML)
6294
6333
  default_selection.click()
6334
+ } else {
6335
+ console.log('[try_dynamic] no default selection found after update')
6295
6336
  }
6296
6337
  rendered = true
6297
6338
  } else {
@@ -6388,77 +6429,105 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6388
6429
  window.addEventListener('message', (event) => {
6389
6430
  console.log("EVENT", event)
6390
6431
 
6391
- // only process the event it's coming from pinokio
6392
- let origin = event.origin
6393
- if (origin) {
6394
- let port = new URL(origin).port || 80
6395
- if (String(port) === String(location.port) || /https:\/\/.*pinokio\..*(localhost|co)/.test(origin)) {
6396
- //if (String(port) === "<%=port%>" || /https:\/\/pinokio\..*localhost/.test(origin)) {
6397
- //if (String(port) === "<%=port%>") {
6398
- if (event.data) {
6399
- if (event.data.action) {
6400
- if (event.data.action.type === "newtab") {
6401
- addTab(event.data.action.url)
6402
- } else if (event.data.action.type === "title") {
6403
- } else if (event.data.action.type === "location") {
6404
- let url = event.data.action.url
6405
- //document.querySelector("#location").value = url
6406
- let pathname = new URL(url).pathname
6407
- if (pathname.startsWith("/run")) {
6408
- document.querySelector("#location").value = pathname.slice(4)
6409
- } else {
6410
- document.querySelector("#location").value = pathname
6411
- }
6412
- }
6413
- } else if (event.data.launch) {
6414
- const rawName = event.data.launch.name
6415
- const escapedSelector = escapeTargetSelector(rawName)
6416
- if (escapedSelector) {
6417
- global_selector = `.frame-link[target="${escapedSelector}"]`
6418
- } else {
6419
- global_selector = null
6420
- }
6421
- const frameExists = Array.from(document.querySelectorAll("main.browserview iframe")).some((frame) => {
6422
- return frame.name === rawName
6423
- })
6424
- if (!frameExists) {
6425
- create_iframe(rawName, event.data.launch.href)
6426
- }
6427
- refresh()
6428
- } else if (event.data.type === "shell-session-id") {
6429
- const frameName = resolveFrameName(event.data.frame, event.source)
6430
- if (frameName && event.data.shellId) {
6431
- const link = getTabLink(frameName)
6432
- if (link) {
6433
- link.setAttribute("data-shell", event.data.shellId)
6434
- link.dataset.shell = event.data.shellId
6435
- }
6436
- }
6437
- return
6438
- } else if (event.data.type === "terminal-input") {
6439
- const frameName = resolveFrameName(event.data.frame, event.source)
6440
- const hasContent = typeof event.data.hasContent === "boolean" ? event.data.hasContent : Boolean(event.data.line && event.data.line.length > 0)
6441
- updateTabPreview(frameName, event.data.line || "", hasContent, Date.now())
6442
- return
6443
- } else if (event.data.type) {
6444
- if (event.data.type === 'stream') {
6445
- const frameName = resolveFrameName(null, event.source)
6446
- updateTabTimestamp(frameName, Date.now())
6447
- } else if (event.data.type === 'result') {
6448
- refresh()
6449
- refresh_du()
6450
- refresh_du("logs")
6451
- } else {
6452
- refresh()
6453
- }
6454
- }
6455
- } else {
6456
- refresh()
6432
+ const data = event.data
6433
+ const dataIsObject = data && typeof data === 'object' && data !== null
6434
+ const frameHint = dataIsObject && typeof data.frame === 'string' ? data.frame : null
6435
+
6436
+ let matchedFrameName = null
6437
+ if (frameHint) {
6438
+ matchedFrameName = resolveFrameName(frameHint, event.source)
6439
+ }
6440
+ if (!matchedFrameName) {
6441
+ matchedFrameName = resolveFrameName(null, event.source)
6442
+ }
6443
+
6444
+ let allowEvent = false
6445
+ const origin = event.origin
6446
+ if (!origin) {
6447
+ allowEvent = true
6448
+ } else {
6449
+ try {
6450
+ const originUrl = new URL(origin)
6451
+ const originPort = originUrl.port || (originUrl.protocol === 'https:' ? '443' : '80')
6452
+ if (String(originPort) === String(location.port)) {
6453
+ allowEvent = true
6457
6454
  }
6455
+ } catch (_) {}
6456
+ if (!allowEvent && /https:\/\/.*pinokio\..*(localhost|co)/.test(origin)) {
6457
+ allowEvent = true
6458
6458
  }
6459
6459
  }
6460
+ if (!allowEvent && matchedFrameName) {
6461
+ allowEvent = true
6462
+ }
6463
+ if (!allowEvent) {
6464
+ return
6465
+ }
6466
+ if (!dataIsObject) {
6467
+ return
6468
+ }
6469
+ if (!data.__pinokioForwarded) {
6470
+ forwardEventToParent(data)
6471
+ }
6460
6472
 
6461
-
6473
+ if (data.action) {
6474
+ if (data.action.type === "newtab") {
6475
+ addTab(data.action.url)
6476
+ } else if (data.action.type === "title") {
6477
+ } else if (data.action.type === "location") {
6478
+ let url = data.action.url
6479
+ let pathname = new URL(url).pathname
6480
+ if (pathname.startsWith("/run")) {
6481
+ document.querySelector("#location").value = pathname.slice(4)
6482
+ } else {
6483
+ document.querySelector("#location").value = pathname
6484
+ }
6485
+ }
6486
+ } else if (data.launch) {
6487
+ const rawName = data.launch.name
6488
+ const escapedSelector = escapeTargetSelector(rawName)
6489
+ if (escapedSelector) {
6490
+ global_selector = `.frame-link[target="${escapedSelector}"]`
6491
+ } else {
6492
+ global_selector = null
6493
+ }
6494
+ const frameExists = Array.from(document.querySelectorAll("main.browserview iframe")).some((frame) => {
6495
+ return frame.name === rawName
6496
+ })
6497
+ if (!frameExists) {
6498
+ create_iframe(rawName, data.launch.href)
6499
+ }
6500
+ refresh()
6501
+ } else if (data.type === "shell-session-id") {
6502
+ const frameName = matchedFrameName || (typeof data.frame === 'string' ? data.frame : null)
6503
+ if (frameName && data.shellId) {
6504
+ const link = getTabLink(frameName)
6505
+ if (link) {
6506
+ link.setAttribute("data-shell", data.shellId)
6507
+ link.dataset.shell = data.shellId
6508
+ }
6509
+ }
6510
+ return
6511
+ } else if (data.type === "terminal-input") {
6512
+ const frameName = matchedFrameName || (typeof data.frame === 'string' ? data.frame : null)
6513
+ const hasContent = typeof data.hasContent === "boolean" ? data.hasContent : Boolean(data.line && data.line.length > 0)
6514
+ updateTabPreview(frameName, data.line || "", hasContent, Date.now())
6515
+ return
6516
+ } else if (data.type) {
6517
+ if (data.type === 'stream') {
6518
+ if (matchedFrameName) {
6519
+ updateTabTimestamp(matchedFrameName, Date.now())
6520
+ }
6521
+ } else if (data.type === 'result') {
6522
+ refresh()
6523
+ refresh_du()
6524
+ refresh_du("logs")
6525
+ } else {
6526
+ refresh()
6527
+ }
6528
+ } else {
6529
+ refresh()
6530
+ }
6462
6531
  });
6463
6532
  refresh_du()
6464
6533
  refresh_du("logs")