pinokiod 3.163.0 → 3.164.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.163.0",
3
+ "version": "3.164.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@ function collectPostMessageTargets(contextWindow) {
28
28
  return targets;
29
29
  }
30
30
 
31
- function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = null, includeCurrent = false) {
31
+ function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = null) {
32
32
  const ctx = (contextWindow && typeof contextWindow === 'object') ? contextWindow : window;
33
33
  let dispatched = false;
34
34
  let targets;
@@ -37,11 +37,6 @@ function pinokioBroadcastMessage(payload, targetOrigin = '*', contextWindow = nu
37
37
  } catch (_) {
38
38
  targets = new Set();
39
39
  }
40
- if (includeCurrent) {
41
- try {
42
- targets.add(ctx);
43
- } catch (_) {}
44
- }
45
40
  if (targets.size === 0) {
46
41
  return dispatched;
47
42
  }
@@ -4979,28 +4979,6 @@ 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
- }
5004
4982
  const getTarget = (href) => {
5005
4983
  let u
5006
4984
  if (href.startsWith("http")) {
@@ -5157,17 +5135,10 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
5157
5135
  }
5158
5136
  }
5159
5137
 
5160
- console.log('[renderSelection] init', {
5161
- triggeredByUser,
5162
- resolvedByGlobalSelector,
5163
- skipPersistedSelection,
5164
- hasPersistedSelection,
5165
- explicitTarget: Boolean(explicitTarget),
5166
- targetInitial: target ? target.outerHTML : null
5167
- })
5138
+ console.log({ target, skipPersistedSelection })
5168
5139
  if (!target && !skipPersistedSelection) {
5169
5140
  preselected = document.querySelector('#devtab.frame-link.selected') || document.querySelector('.frame-link.selected')
5170
- console.log('[renderSelection] preselected candidate', preselected ? preselected.outerHTML : null)
5141
+ console.log({ preselected })
5171
5142
  }
5172
5143
 
5173
5144
  if (!target && persistedSelectionPayload) {
@@ -5243,7 +5214,7 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
5243
5214
  target = preselected
5244
5215
  }
5245
5216
 
5246
- console.log('[renderSelection] target after resolution', target ? target.outerHTML : null)
5217
+ console.log({ targetAfter: target })
5247
5218
 
5248
5219
  if (!target) {
5249
5220
  target = document.querySelector(".frame-link")
@@ -6221,16 +6192,7 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6221
6192
  const navContainers = [document.querySelector("aside"), document.querySelector("#fs-status")]
6222
6193
  navContainers.forEach((container) => {
6223
6194
  if (container) {
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
- })
6195
+ container.addEventListener("click", handleMenuClick)
6234
6196
  }
6235
6197
  })
6236
6198
  setupTabLinkHover()
@@ -6309,7 +6271,6 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6309
6271
  status = res.status
6310
6272
  return res.text()
6311
6273
  })
6312
- console.log('[try_dynamic] fetched', { status, length: dynamic ? dynamic.length : 0 })
6313
6274
  if (status == 500) {
6314
6275
  ModalInput({
6315
6276
  description: dynamic,
@@ -6329,10 +6290,8 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6329
6290
  }
6330
6291
  let default_selection = document.querySelector(".dynamic .submenu [data-default]")
6331
6292
  if (default_selection) {
6332
- console.log('[try_dynamic] clicking default', default_selection.outerHTML)
6293
+ console.log("CLICK default")
6333
6294
  default_selection.click()
6334
- } else {
6335
- console.log('[try_dynamic] no default selection found after update')
6336
6295
  }
6337
6296
  rendered = true
6338
6297
  } else {
@@ -6429,105 +6388,80 @@ body.dark .pinokio-fork-dropdown-remote, body.dark .pinokio-publish-dropdown-rem
6429
6388
  window.addEventListener('message', (event) => {
6430
6389
  console.log("EVENT", event)
6431
6390
 
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
6454
- }
6455
- } catch (_) {}
6456
- if (!allowEvent && /https:\/\/.*pinokio\..*(localhost|co)/.test(origin)) {
6457
- allowEvent = true
6458
- }
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
- }
6472
-
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)
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
+ if (event.data.type === 'start') {
6453
+ ignorePersistedSelection = true
6454
+ }
6455
+ refresh()
6456
+ }
6457
+ }
6482
6458
  } 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
6459
+ refresh()
6508
6460
  }
6509
6461
  }
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
  }
6463
+
6464
+
6531
6465
  });
6532
6466
  refresh_du()
6533
6467
  refresh_du("logs")
@@ -593,32 +593,12 @@ const launchTab = (tab) => {
593
593
  const href = appendSessionParam(baseHref, session)
594
594
  const target = appendSessionParam(baseTarget, session)
595
595
 
596
- const payload = {
596
+ window.parent.postMessage({
597
597
  launch: {
598
598
  name: target,
599
599
  href
600
600
  }
601
- }
602
-
603
- let posted = false
604
- if (typeof window !== 'undefined' && typeof window.PinokioBroadcastMessage === 'function') {
605
- try {
606
- posted = window.PinokioBroadcastMessage(payload, '*', window, true)
607
- } catch (_) {
608
- posted = false
609
- }
610
- }
611
-
612
- if (!posted) {
613
- try {
614
- window.parent.postMessage(payload, '*')
615
- } catch (_) {}
616
- if (window.parent && window.parent !== window && typeof window.postMessage === 'function') {
617
- try {
618
- window.postMessage(payload, '*')
619
- } catch (_) {}
620
- }
621
- }
601
+ }, "*")
622
602
 
623
603
  return true
624
604
  }