|
| 1 | + |
| 2 | + |
| 3 | +<webcontainer-ports> |
| 4 | + |
| 5 | + <template shadowrootmode=open> |
| 6 | + |
| 7 | + <style> |
| 8 | + |
| 9 | + #root |
| 10 | + {} |
| 11 | + |
| 12 | + #list |
| 13 | + {display:flex;flex-direction:column;gap:5px} |
| 14 | + |
| 15 | + .item |
| 16 | + {display:flex;align-items:center;gap:10px} |
| 17 | + |
| 18 | + .port |
| 19 | + {} |
| 20 | + .url |
| 21 | + {} |
| 22 | + .copy |
| 23 | + {} |
| 24 | + |
| 25 | + </style> |
| 26 | + |
| 27 | + <div id=root style='display:none'> |
| 28 | + |
| 29 | + <div id=list> |
| 30 | + |
| 31 | + <div class=item> |
| 32 | + <div class=port> |
| 33 | + </div> |
| 34 | + <div class=url> |
| 35 | + </div> |
| 36 | + <img class=copy> |
| 37 | + </div> |
| 38 | + |
| 39 | + </div> |
| 40 | + |
| 41 | + </div> |
| 42 | + |
| 43 | + </template> |
| 44 | + |
| 45 | + |
| 46 | + <script> |
| 47 | + |
| 48 | +(function({mod,dom}){ |
| 49 | + |
| 50 | + var obj = { |
| 51 | + version : 'v1.0.0', |
| 52 | + }; |
| 53 | + var df=true,did='webcontainer-ports'; |
| 54 | + |
| 55 | + |
| 56 | + var vm |
| 57 | + ; |
| 58 | + |
| 59 | + obj.initmod = function(params){ |
| 60 | + |
| 61 | + vm = mod.rd(params,'vm',vm); |
| 62 | + |
| 63 | + }//intimod |
| 64 | + |
| 65 | + |
| 66 | + //: |
| 67 | + |
| 68 | + |
| 69 | + var shadow; |
| 70 | + |
| 71 | + var viewport; |
| 72 | + |
| 73 | + |
| 74 | + //: |
| 75 | + |
| 76 | + |
| 77 | + obj.init = async function(){ |
| 78 | + }//init |
| 79 | + |
| 80 | + |
| 81 | + //: |
| 82 | + |
| 83 | + |
| 84 | + obj.initdom = async function(){ |
| 85 | + |
| 86 | + shadow = host.shadowRoot; |
| 87 | + |
| 88 | + viewport = await vm.new(); |
| 89 | + viewport.pos({x:200,y:200,w:400,h:200}); |
| 90 | + |
| 91 | + root = $(shadow,'#root'); |
| 92 | + viewport.body.append(root); |
| 93 | + root.style.display = ''; |
| 94 | + |
| 95 | + list = $(root,'#list'); |
| 96 | + item = $(list,'.item'); |
| 97 | + item.remove(); |
| 98 | + |
| 99 | + }//initdom |
| 100 | + |
| 101 | + |
| 102 | + //: |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + obj.add = function(port,url){ |
| 107 | + |
| 108 | + var nitem = item.cloneNode(true); |
| 109 | + $(nitem,'.port').textContent = port; |
| 110 | + $(nitem,'.url').textContent = url; |
| 111 | + $(nitem,'.copy').onclick = e=>{ |
| 112 | + |
| 113 | + await navigator.clipboard.writeText(url); |
| 114 | + |
| 115 | + }//copy |
| 116 | + list.append(nitem); |
| 117 | + |
| 118 | + }//add |
| 119 | + |
| 120 | + |
| 121 | + obj.remove = function(port){ |
| 122 | + |
| 123 | + port += ''; |
| 124 | + var item = $.all(list,'.item').find(item=>$(item,'.port').textContent.trim()===port); |
| 125 | + if(!item){ |
| 126 | + return; |
| 127 | + } |
| 128 | + item.remove(); |
| 129 | + |
| 130 | + }//remove |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + //: |
| 136 | + |
| 137 | + return obj; |
| 138 | + |
| 139 | + //webcontainer-ports |
| 140 | +}) |
| 141 | + |
| 142 | + </script> |
| 143 | + |
| 144 | +</webcontainer-ports> |
| 145 | + |
| 146 | + |
| 147 | + |
0 commit comments