Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1e0df6a4
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1e0df6a4
编写于
10月 24, 2020
作者:
C
Connor Peet
提交者:
GitHub
10月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notebooks: hide acquireVsCodeApi from renderers (#109273)
上级
b906da14
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
14 deletion
+27
-14
src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts
...ntrib/notebook/browser/view/renderers/backLayerWebView.ts
+0
-1
src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts
...ontrib/notebook/browser/view/renderers/webviewPreloads.ts
+26
-12
src/vs/workbench/contrib/webview/browser/pre/main.js
src/vs/workbench/contrib/webview/browser/pre/main.js
+1
-1
未找到文件。
src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts
浏览文件 @
1e0df6a4
...
...
@@ -322,7 +322,6 @@ export class BackLayerWebView extends Disposable {
self.require = {};
</script>
${
coreDependencies
}
<div id="__vscode_preloads"></div>
<div id='container' class="widgetarea" style="position: absolute;width:100%;top: 0px"></div>
<script>
${
preloadsScriptStr
(
outputNodePadding
)}
</script>
</body>
...
...
src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts
浏览文件 @
1e0df6a4
...
...
@@ -12,7 +12,13 @@ import { RenderOutputType } from 'vs/workbench/contrib/notebook/common/notebookC
// function. Imports are not allowed. This is stringifies and injected into
// the webview.
declare
const
acquireVsCodeApi
:
()
=>
({
getState
():
{
[
key
:
string
]:
unknown
;
},
setState
(
data
:
{
[
key
:
string
]:
unknown
;
}):
void
,
postMessage
:
(
msg
:
unknown
)
=>
void
;
});
declare
module
globalThis
{
const
acquireVsCodeApi
:
()
=>
({
getState
():
{
[
key
:
string
]:
unknown
;
};
setState
(
data
:
{
[
key
:
string
]:
unknown
;
}):
void
;
postMessage
:
(
msg
:
unknown
)
=>
void
;
});
}
declare
class
ResizeObserver
{
constructor
(
onChange
:
(
entries
:
{
target
:
HTMLElement
,
contentRect
?:
ClientRect
;
}[])
=>
void
);
...
...
@@ -30,7 +36,9 @@ interface EmitterLike<T> {
}
function
webviewPreloads
()
{
const
acquireVsCodeApi
=
globalThis
.
acquireVsCodeApi
;
const
vscode
=
acquireVsCodeApi
();
delete
(
globalThis
as
any
).
acquireVsCodeApi
;
const
handleInnerClick
=
(
event
:
MouseEvent
)
=>
{
if
(
!
event
||
!
event
.
view
||
!
event
.
view
.
document
)
{
...
...
@@ -93,6 +101,18 @@ function webviewPreloads() {
}
};
const
runScript
=
async
(
url
:
string
,
originalUri
:
string
,
globals
:
{
[
name
:
string
]:
unknown
}
=
{}):
Promise
<
string
|
undefined
>
=>
{
const
res
=
await
fetch
(
url
);
const
text
=
await
res
.
text
();
if
(
!
res
.
ok
)
{
throw
new
Error
(
`Unexpected
${
res
.
status
}
requesting
${
originalUri
}
:
${
text
||
res
.
statusText
}
`
);
}
const
args
=
Object
.
entries
(
globals
);
new
Function
(...
args
.
map
(([
k
])
=>
k
),
text
)(...
args
.
map
(([,
v
])
=>
v
));
return
undefined
;
};
const
outputObservers
=
new
Map
<
string
,
ResizeObserver
>
();
const
resizeObserve
=
(
container
:
Element
,
id
:
string
)
=>
{
...
...
@@ -477,17 +497,11 @@ function webviewPreloads() {
break
;
case
'
preload
'
:
const
resources
=
event
.
data
.
resources
;
const
preloadsContainer
=
document
.
getElementById
(
'
__vscode_preloads
'
)
!
;
for
(
let
i
=
0
;
i
<
resources
.
length
;
i
++
)
{
const
{
uri
,
originalUri
}
=
resources
[
i
];
const
scriptTag
=
document
.
createElement
(
'
script
'
);
scriptTag
.
setAttribute
(
'
src
'
,
uri
);
preloadsContainer
.
appendChild
(
scriptTag
);
preloadPromises
.
set
(
uri
,
new
Promise
<
string
|
undefined
>
(
resolve
=>
{
scriptTag
.
addEventListener
(
'
load
'
,
()
=>
resolve
(
undefined
));
scriptTag
.
addEventListener
(
'
error
'
,
()
=>
resolve
(
`Network error loading
${
originalUri
}
, does the path exist?`
)
);
const
globals
=
event
.
data
.
type
===
'
preload
'
?
{
acquireVsCodeApi
}
:
{};
for
(
const
{
uri
,
originalUri
}
of
resources
)
{
preloadPromises
.
set
(
uri
,
runScript
(
uri
,
originalUri
,
globals
).
catch
(
err
=>
{
console
.
error
(
err
);
return
err
.
message
||
String
(
err
);
}));
}
break
;
...
...
src/vs/workbench/contrib/webview/browser/pre/main.js
浏览文件 @
1e0df6a4
...
...
@@ -143,7 +143,7 @@
function
getVsCodeApiScript
(
allowMultipleAPIAcquire
,
state
)
{
const
encodedState
=
state
?
encodeURIComponent
(
state
)
:
undefined
;
return
`
const
acquireVsCodeApi = (function() {
globalThis.
acquireVsCodeApi = (function() {
const originalPostMessage = window.parent.postMessage.bind(window.parent);
const targetOrigin = '*';
let acquired = false;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录