chrome-devtools-frontend 1.0.927127 → 1.0.928589

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 (144) hide show
  1. package/AUTHORS +1 -0
  2. package/config/gni/all_devtools_files.gni +0 -1
  3. package/config/gni/devtools_grd_files.gni +30 -4
  4. package/config/gni/devtools_image_files.gni +1 -0
  5. package/front_end/Images/src/ic_preview_feature.svg +3 -0
  6. package/front_end/Tests.js +2 -3
  7. package/front_end/core/common/Settings.ts +26 -45
  8. package/front_end/core/host/UserMetrics.ts +2 -2
  9. package/front_end/core/i18n/locales/en-US.json +60 -15
  10. package/front_end/core/i18n/locales/en-XL.json +60 -15
  11. package/front_end/core/platform/keyboard-utilities.ts +1 -0
  12. package/front_end/core/root/Runtime.ts +62 -61
  13. package/front_end/core/sdk/AccessibilityModel.ts +73 -73
  14. package/front_end/core/sdk/CPUProfileDataModel.ts +14 -14
  15. package/front_end/core/sdk/CPUProfilerModel.ts +33 -33
  16. package/front_end/core/sdk/CPUThrottlingManager.ts +8 -8
  17. package/front_end/core/sdk/CSSFontFace.ts +10 -10
  18. package/front_end/core/sdk/CSSMatchedStyles.ts +114 -114
  19. package/front_end/core/sdk/CSSMedia.ts +22 -22
  20. package/front_end/core/sdk/CSSMetadata.ts +53 -49
  21. package/front_end/core/sdk/CSSModel.ts +139 -135
  22. package/front_end/core/sdk/CSSProperty.ts +18 -18
  23. package/front_end/core/sdk/CSSRule.ts +15 -15
  24. package/front_end/core/sdk/CSSStyleDeclaration.ts +49 -47
  25. package/front_end/core/sdk/CSSStyleSheetHeader.ts +12 -12
  26. package/front_end/core/sdk/ChildTargetManager.ts +41 -40
  27. package/front_end/core/sdk/CompilerSourceMappingContentProvider.ts +10 -10
  28. package/front_end/core/sdk/Connections.ts +81 -81
  29. package/front_end/core/sdk/ConsoleModel.ts +68 -68
  30. package/front_end/core/sdk/Cookie.ts +48 -48
  31. package/front_end/core/sdk/CookieModel.ts +13 -13
  32. package/front_end/core/sdk/CookieParser.ts +45 -45
  33. package/front_end/core/sdk/DOMDebuggerModel.ts +131 -131
  34. package/front_end/core/sdk/DOMModel.ts +264 -252
  35. package/front_end/core/sdk/DebuggerModel.ts +209 -205
  36. package/front_end/core/sdk/EmulationModel.ts +76 -76
  37. package/front_end/core/sdk/FilmStripModel.ts +29 -29
  38. package/front_end/core/sdk/FrameManager.ts +43 -42
  39. package/front_end/core/sdk/HeapProfilerModel.ts +36 -36
  40. package/front_end/core/sdk/IsolateManager.ts +82 -82
  41. package/front_end/core/sdk/IssuesModel.ts +6 -6
  42. package/front_end/core/sdk/LayerTreeBase.ts +37 -37
  43. package/front_end/core/sdk/LogModel.ts +5 -5
  44. package/front_end/core/sdk/NetworkManager.ts +229 -225
  45. package/front_end/core/sdk/NetworkRequest.ts +368 -360
  46. package/front_end/core/sdk/OverlayColorGenerator.ts +9 -9
  47. package/front_end/core/sdk/OverlayModel.ts +155 -153
  48. package/front_end/core/sdk/OverlayPersistentHighlighter.ts +100 -101
  49. package/front_end/core/sdk/PageResourceLoader.ts +30 -30
  50. package/front_end/core/sdk/PaintProfiler.ts +16 -16
  51. package/front_end/core/sdk/PerformanceMetricsModel.ts +12 -12
  52. package/front_end/core/sdk/ProfileTreeModel.ts +3 -3
  53. package/front_end/core/sdk/RemoteObject.ts +108 -104
  54. package/front_end/core/sdk/Resource.ts +85 -84
  55. package/front_end/core/sdk/ResourceTreeModel.ts +150 -145
  56. package/front_end/core/sdk/RuntimeModel.ts +38 -34
  57. package/front_end/core/sdk/SDKModel.ts +3 -3
  58. package/front_end/core/sdk/ScreenCaptureModel.ts +19 -19
  59. package/front_end/core/sdk/Script.ts +29 -29
  60. package/front_end/core/sdk/SecurityOriginManager.ts +19 -19
  61. package/front_end/core/sdk/ServerTiming.ts +2 -2
  62. package/front_end/core/sdk/ServiceWorkerCacheModel.ts +43 -43
  63. package/front_end/core/sdk/ServiceWorkerManager.ts +72 -68
  64. package/front_end/core/sdk/SourceMap.ts +40 -36
  65. package/front_end/core/sdk/SourceMapManager.ts +57 -57
  66. package/front_end/core/sdk/Target.ts +64 -63
  67. package/front_end/core/sdk/TargetManager.ts +60 -56
  68. package/front_end/core/sdk/TracingManager.ts +39 -39
  69. package/front_end/core/sdk/TracingModel.ts +125 -125
  70. package/front_end/core/sdk/WebAuthnModel.ts +9 -9
  71. package/front_end/entrypoints/lighthouse_worker/{LighthouseService.js → LighthouseService.ts} +20 -45
  72. package/front_end/entrypoints/lighthouse_worker/{lighthouse_worker.js → lighthouse_worker.ts} +0 -0
  73. package/front_end/entrypoints/main/MainImpl.ts +7 -2
  74. package/front_end/legacy_test_runner/elements_test_runner/ElementsTestRunner.js +4 -4
  75. package/front_end/legacy_test_runner/sdk_test_runner/sdk_test_runner.js +1 -1
  76. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +0 -6
  77. package/front_end/models/issues_manager/GenericIssue.ts +86 -0
  78. package/front_end/models/issues_manager/Issue.ts +24 -0
  79. package/front_end/models/issues_manager/IssuesManager.ts +18 -6
  80. package/front_end/models/issues_manager/descriptions/genericCrossOriginPortalPostMessageError.md +3 -0
  81. package/front_end/models/issues_manager/issues_manager.ts +2 -0
  82. package/front_end/models/javascript_metadata/NativeFunctions.js +5422 -1
  83. package/front_end/panels/console/ConsoleSidebar.ts +0 -3
  84. package/front_end/panels/elements/ElementsTreeElement.ts +53 -61
  85. package/front_end/panels/elements/ElementsTreeOutline.ts +0 -1
  86. package/front_end/panels/elements/components/LayoutPane.ts +5 -1
  87. package/front_end/panels/issues/GenericIssueDetailsView.ts +68 -0
  88. package/front_end/panels/issues/IssueAggregator.ts +16 -0
  89. package/front_end/panels/issues/IssueKindView.ts +95 -0
  90. package/front_end/panels/issues/IssueView.ts +6 -0
  91. package/front_end/panels/issues/IssuesPane.ts +81 -18
  92. package/front_end/panels/issues/issuesTree.css +8 -3
  93. package/front_end/panels/lighthouse/LighthouseController.ts +3 -1
  94. package/front_end/panels/network/NetworkItemView.ts +1 -1
  95. package/front_end/panels/network/networkLogView.css +5 -0
  96. package/front_end/panels/sensors/LocationsSettingsTab.ts +1 -1
  97. package/front_end/panels/settings/SettingsScreen.ts +1 -0
  98. package/front_end/panels/settings/settingsScreen.css +24 -0
  99. package/front_end/panels/snippets/SnippetsQuickOpen.ts +8 -3
  100. package/front_end/panels/sources/TabbedEditorContainer.ts +1 -1
  101. package/front_end/panels/sources/sources-meta.ts +22 -7
  102. package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
  103. package/front_end/third_party/codemirror.next/package.json +4 -4
  104. package/front_end/ui/components/code_highlighter/CodeHighlighter.ts +137 -0
  105. package/front_end/ui/components/code_highlighter/codeHighlighter.css +51 -0
  106. package/front_end/ui/components/code_highlighter/code_highlighter.ts +11 -0
  107. package/front_end/ui/components/docs/text_editor/basic.html +28 -0
  108. package/front_end/ui/components/docs/text_editor/basic.ts +14 -0
  109. package/front_end/ui/components/docs/text_prompt/basic.html +35 -0
  110. package/front_end/ui/components/docs/text_prompt/basic.ts +19 -0
  111. package/front_end/ui/components/issue_counter/IssueLinkIcon.ts +1 -0
  112. package/front_end/ui/components/render_coordinator/RenderCoordinator.ts +17 -0
  113. package/front_end/ui/components/request_link_icon/RequestLinkIcon.ts +1 -0
  114. package/front_end/ui/components/text_editor/TextEditor.ts +161 -0
  115. package/front_end/ui/components/text_editor/config.ts +264 -0
  116. package/front_end/{panels/console/components/components.ts → ui/components/text_editor/text_editor.ts} +2 -5
  117. package/front_end/ui/components/text_editor/theme.ts +113 -0
  118. package/front_end/ui/components/text_prompt/TextPrompt.ts +144 -0
  119. package/front_end/ui/components/text_prompt/textPrompt.css +33 -0
  120. package/front_end/ui/components/text_prompt/text_prompt.ts +9 -0
  121. package/front_end/ui/legacy/ARIAUtils.ts +14 -11
  122. package/front_end/ui/legacy/TabbedPane.ts +32 -3
  123. package/front_end/ui/legacy/UIUtils.ts +3 -1
  124. package/front_end/ui/legacy/View.ts +6 -0
  125. package/front_end/ui/legacy/ViewManager.ts +5 -1
  126. package/front_end/ui/legacy/ViewRegistration.ts +5 -0
  127. package/front_end/ui/legacy/XLink.ts +1 -1
  128. package/front_end/ui/legacy/closeButton.css +6 -0
  129. package/front_end/ui/legacy/components/quick_open/CommandMenu.ts +8 -3
  130. package/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts +38 -38
  131. package/front_end/ui/legacy/components/quick_open/HelpQuickOpen.ts +10 -4
  132. package/front_end/ui/legacy/components/quick_open/QuickOpen.ts +23 -6
  133. package/front_end/ui/legacy/components/quick_open/filteredListWidget.css +14 -16
  134. package/front_end/ui/legacy/filter.css +1 -0
  135. package/front_end/ui/legacy/tabbedPane.css +24 -0
  136. package/front_end/ui/legacy/toolbar.css +5 -0
  137. package/inspector_overlay/main.ts +2 -1
  138. package/inspector_overlay/tool_screenshot.ts +8 -1
  139. package/package.json +1 -1
  140. package/scripts/build/rollup.config.js +9 -0
  141. package/scripts/migration/class-fields/migrate.js +56 -0
  142. package/scripts/migration/class-fields/package.json +5 -0
  143. package/front_end/panels/console/components/SidebarDeprecation.ts +0 -58
  144. package/front_end/panels/console/components/sidebarDeprecation.css +0 -17
@@ -24,14 +24,14 @@
24
24
  "@codemirror/lang-xml": "0.19.2",
25
25
  "@codemirror/language": "0.19.3",
26
26
  "@codemirror/legacy-modes": "0.19.0",
27
- "@codemirror/matchbrackets": "0.19.1",
27
+ "@codemirror/matchbrackets": "0.19.3",
28
28
  "@codemirror/search": "0.19.2",
29
29
  "@codemirror/state": "0.19.2",
30
30
  "@codemirror/stream-parser": "0.19.2",
31
- "@codemirror/text": "0.19.3",
31
+ "@codemirror/text": "0.19.4",
32
32
  "@codemirror/tooltip": "0.19.2",
33
- "@codemirror/view": "0.19.8",
34
- "@lezer/common": "0.15.5",
33
+ "@codemirror/view": "0.19.9",
34
+ "@lezer/common": "0.15.6",
35
35
  "@rollup/plugin-node-resolve": "^13.0.4",
36
36
  "rollup-plugin-dts": "^4.0.0",
37
37
  "rollup-plugin-terser": "^7.0.2"
@@ -0,0 +1,137 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import type * as CodeMirror from '../../../third_party/codemirror.next/codemirror.next.js';
6
+
7
+ let highlightStyle: CodeMirror.HighlightStyle|null = null;
8
+
9
+ function importCM(): Promise<typeof CodeMirror> {
10
+ return import('../../../third_party/codemirror.next/codemirror.next.js');
11
+ }
12
+
13
+ export function getHighlightStyle(modCM: typeof CodeMirror): CodeMirror.HighlightStyle {
14
+ if (!highlightStyle) {
15
+ const t = modCM.tags;
16
+ highlightStyle = modCM.HighlightStyle.define([
17
+ {tag: t.variableName, class: 'token-variable'},
18
+ {tag: t.propertyName, class: 'token-property'},
19
+ {tag: [t.typeName, t.className, t.namespace, t.macroName], class: 'token-type'},
20
+ {tag: [t.special(t.name), t.constant(t.className)], class: 'token-variable-special'},
21
+ {tag: t.definition(t.name), class: 'token-definition'},
22
+ {tag: t.standard(t.variableName), class: 'token-builtin'},
23
+
24
+ {tag: [t.number, t.literal, t.unit], class: 'token-number'},
25
+ {tag: t.string, class: 'token-string'},
26
+ {tag: [t.special(t.string), t.regexp, t.escape], class: 'token-string-special'},
27
+ {tag: [t.atom, t.labelName, t.bool], class: 'token-atom'},
28
+
29
+ {tag: t.keyword, class: 'token-keyword'},
30
+ {tag: [t.comment, t.quote], class: 'token-comment'},
31
+ {tag: t.meta, class: 'token-meta'},
32
+ {tag: t.invalid, class: 'token-invalid'},
33
+
34
+ {tag: t.tagName, class: 'token-tag'},
35
+ {tag: t.attributeName, class: 'token-attribute'},
36
+ {tag: t.attributeValue, class: 'token-attribute-value'},
37
+
38
+ {tag: t.inserted, class: 'token-inserted'},
39
+ {tag: t.deleted, class: 'token-deleted'},
40
+ {tag: t.heading, class: 'token-variable-special'},
41
+ {tag: t.link, class: 'token-variable-special'},
42
+ {tag: t.strikethrough, class: 'token-strikethrough'},
43
+ {tag: t.strong, class: 'token-strong'},
44
+ {tag: t.emphasis, class: 'token-emphasis'},
45
+ ]);
46
+ }
47
+ return highlightStyle;
48
+ }
49
+
50
+ export async function create(code: string, mimeType: string): Promise<CodeHighlighter> {
51
+ const CM = await importCM();
52
+ const language = await languageFromMIME(mimeType);
53
+ const tree = language ? language.language.parser.parse(code) : new CM.Tree(CM.NodeType.none, [], [], code.length);
54
+ return new CodeHighlighter(code, tree, CM);
55
+ }
56
+
57
+ export async function languageFromMIME(mimeType: string): Promise<CodeMirror.LanguageSupport|null> {
58
+ const CM = await importCM();
59
+
60
+ switch (mimeType) {
61
+ case 'text/javascript':
62
+ return (await CM.javascript()).javascript();
63
+ case 'text/jsx':
64
+ return (await CM.javascript()).javascript({jsx: true});
65
+ case 'text/typescript':
66
+ return (await CM.javascript()).javascript({typescript: true});
67
+ case 'text/typescript-jsx':
68
+ return (await CM.javascript()).javascript({typescript: true, jsx: true});
69
+
70
+ case 'text/css':
71
+ case 'text/x-scss':
72
+ return (await CM.css()).css();
73
+
74
+ case 'text/html':
75
+ return (await CM.html()).html();
76
+
77
+ case 'application/xml':
78
+ return (await CM.xml()).xml();
79
+
80
+ case 'text/webassembly':
81
+ return (await CM.wast()).wast();
82
+
83
+ case 'text/x-c++src':
84
+ return (await CM.cpp()).cpp();
85
+
86
+ case 'text/x-java':
87
+ return (await CM.java()).java();
88
+
89
+ case 'application/json':
90
+ return (await CM.json()).json();
91
+
92
+ case 'application/x-httpd-php':
93
+ return (await CM.php()).php();
94
+
95
+ case 'text/x-python':
96
+ return (await CM.python()).python();
97
+
98
+ case 'text/markdown':
99
+ return (await CM.markdown()).markdown();
100
+
101
+ case 'text/x-sh':
102
+ return new CM.LanguageSupport(await CM.shell());
103
+
104
+ case 'text/x-coffeescript':
105
+ return new CM.LanguageSupport(await CM.coffeescript());
106
+
107
+ case 'text/x-clojure':
108
+ return new CM.LanguageSupport(await CM.clojure());
109
+
110
+ default:
111
+ return null;
112
+ }
113
+ }
114
+
115
+ export class CodeHighlighter {
116
+ constructor(readonly code: string, readonly tree: CodeMirror.Tree, private readonly modCM: typeof CodeMirror) {
117
+ }
118
+
119
+ highlight(token: (text: string, style: string) => void): void {
120
+ this.highlightRange(0, this.code.length, token);
121
+ }
122
+
123
+ highlightRange(from: number, to: number, token: (text: string, style: string) => void): void {
124
+ let pos = from;
125
+ const flush = (to: number, style: string): void => {
126
+ if (to > pos) {
127
+ token(this.code.slice(pos, to), style);
128
+ pos = to;
129
+ }
130
+ };
131
+ this.modCM.highlightTree(this.tree, getHighlightStyle(this.modCM).match, (from, to, style) => {
132
+ flush(from, '');
133
+ flush(to, style);
134
+ }, from, to);
135
+ flush(to, '');
136
+ }
137
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2021 The Chromium Authors. All rights reserved.
3
+ * Use of this source code is governed by a BSD-style license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ .token-variable { color: var(--color-token-variable); }
8
+ .token-property { color: var(--color-token-property); }
9
+ .token-type { color: var(--color-token-type); }
10
+ .token-variable-special { color: var(--color-token-variable-special); }
11
+ .token-definition { color: var(--color-token-definition); }
12
+ .token-builtin { color: var(--color-token-builtin); }
13
+
14
+ .token-number { color: var(--color-token-number); }
15
+ .token-string { color: var(--color-token-string); }
16
+ .token-string-special { color: var(--color-token-string-special); }
17
+ .token-atom { color: var(--color-token-atom); }
18
+
19
+ .token-keyword { color: var(--color-token-keyword); }
20
+ .token-comment { color: var(--color-token-comment); }
21
+ .token-meta { color: var(--color-token-meta); }
22
+ .token-invalid { color: var(--color-error-text); }
23
+
24
+ .token-tag { color: var(--color-token-tag); }
25
+ .token-attribute { color: var(--color-token-attribute); }
26
+ .token-attribute-value { color: var(--color-token-attribute-value); }
27
+
28
+ .token-inserted { color: var(--color-token-inserted); }
29
+ .token-deleted { color: var(--color-token-deleted); }
30
+
31
+ .token-heading {
32
+ color: var(--color-token-variable-special);
33
+ font-weight: bold;
34
+ }
35
+
36
+ .token-link {
37
+ color: var(--color-token-variable-special);
38
+ text-decoration: underline;
39
+ }
40
+
41
+ .token-strikethrough {
42
+ text-decoration: strike-through;
43
+ }
44
+
45
+ .token-strong {
46
+ font-weight: bold;
47
+ }
48
+
49
+ .token-emphasis {
50
+ font-style: italic;
51
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Style from './codeHighlighter.css.js';
6
+ import * as CodeHighlighter from './CodeHighlighter.js';
7
+
8
+ export {
9
+ CodeHighlighter,
10
+ Style,
11
+ };
@@ -0,0 +1,28 @@
1
+ <!--
2
+ Copyright 2020 The Chromium Authors. All rights reserved.
3
+ Use of this source code is governed by a BSD-style license that can be
4
+ found in the LICENSE file.
5
+ -->
6
+ <!DOCTYPE html>
7
+ <html>
8
+ <head>
9
+ <meta charset="UTF-8" />
10
+ <meta name="viewport" content="width=device-width" />
11
+ <title>Basic Data grid example</title>
12
+ <style>
13
+ #container {
14
+ width: 80%;
15
+ border: 1px solid black;
16
+ margin: 30px;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+
22
+ <div id="container">
23
+ </div>
24
+
25
+ <ul id="events"></ul>
26
+ <script type="module" src="./basic.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,14 @@
1
+ // Copyright 2020 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as FrontendHelpers from '../../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js';
6
+ import * as ComponentHelpers from '../../helpers/helpers.js';
7
+ import * as TextEditor from '../../text_editor/text_editor.js';
8
+
9
+ await ComponentHelpers.ComponentServerSetup.setup();
10
+ await FrontendHelpers.initializeGlobalVars();
11
+
12
+ const component = new TextEditor.TextEditor.TextEditor();
13
+
14
+ document.getElementById('container')?.appendChild(component);
@@ -0,0 +1,35 @@
1
+ <!--
2
+ Copyright 2021 The Chromium Authors. All rights reserved.
3
+ Use of this source code is governed by a BSD-style license that can be
4
+ found in the LICENSE file.
5
+ -->
6
+ <!DOCTYPE html>
7
+ <html>
8
+
9
+ <head>
10
+ <meta charset="UTF-8" />
11
+ <meta name="viewport" content="width=device-width" />
12
+ <title>Basic Text Prompt example</title>
13
+ <meta charset="UTF-8" />
14
+ <style>
15
+ #container {
16
+ width: 80%;
17
+ border: 1px solid black;
18
+ padding: 20px;
19
+ height: 300px;
20
+ }
21
+
22
+ #container > devtools-text-prompt {
23
+ vertical-align: middle;
24
+ font-size: 14px;
25
+ border: 1px solid #ccc;
26
+ }
27
+ </style>
28
+ </head>
29
+
30
+ <body>
31
+ <div id="container"></div>
32
+ <script type="module" src="./basic.js"></script>
33
+ </body>
34
+
35
+ </html>
@@ -0,0 +1,19 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as FrontendHelpers from '../../../../../test/unittests/front_end/helpers/EnvironmentHelpers.js';
6
+ import * as ComponentHelpers from '../../helpers/helpers.js';
7
+ import * as TextPrompt from '../../text_prompt/text_prompt.js';
8
+
9
+ await ComponentHelpers.ComponentServerSetup.setup();
10
+ await FrontendHelpers.initializeGlobalVars();
11
+
12
+ const textPrompt = new TextPrompt.TextPrompt.TextPrompt();
13
+ document.getElementById('container')?.appendChild(textPrompt);
14
+
15
+ textPrompt.data = {
16
+ ariaLabel: 'Quick open prompt',
17
+ prefix: 'Open',
18
+ suggestion: 'File',
19
+ };
@@ -163,6 +163,7 @@ export class IssueLinkIcon extends HTMLElement {
163
163
  // clang-format off
164
164
  return LitHtml.html`
165
165
  <span class=${LitHtml.Directives.classMap({'link': Boolean(this.issue)})}
166
+ tabindex="0"
166
167
  @click=${this.handleClick}>
167
168
  <${IconButton.Icon.Icon.litTagName} .data=${this.iconData() as IconButton.Icon.IconData}
168
169
  title=${this.getTooltip()}></${IconButton.Icon.Icon.litTagName}>
@@ -59,6 +59,11 @@ const UNNAMED_WRITE = 'Unnamed write';
59
59
  const UNNAMED_SCROLL = 'Unnamed scroll';
60
60
  const DEADLOCK_TIMEOUT = 1500;
61
61
 
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ (globalThis as any).__getRenderCoordinatorPendingFrames = function(): number {
64
+ return RenderCoordinator.pendingFramesCount();
65
+ };
66
+
62
67
  export class RenderCoordinator extends EventTarget {
63
68
  static instance({forceNew = false} = {}): RenderCoordinator {
64
69
  if (!renderCoordinatorInstance || forceNew) {
@@ -68,6 +73,14 @@ export class RenderCoordinator extends EventTarget {
68
73
  return renderCoordinatorInstance;
69
74
  }
70
75
 
76
+ static pendingFramesCount(): number {
77
+ if (!renderCoordinatorInstance) {
78
+ throw new Error('No render coordinator instance found.');
79
+ }
80
+
81
+ return renderCoordinatorInstance.pendingFramesCount();
82
+ }
83
+
71
84
  // Toggle on to start tracking. You must call takeRecords() to
72
85
  // obtain the records. Please note: records are limited by maxRecordSize below.
73
86
  observe = false;
@@ -85,6 +98,10 @@ export class RenderCoordinator extends EventTarget {
85
98
  private readonly labels = new WeakMap<CoordinatorCallback, string>();
86
99
  private scheduledWorkId = 0;
87
100
 
101
+ pendingFramesCount(): number {
102
+ return this.pendingWorkFrames.length;
103
+ }
104
+
88
105
  done(): Promise<void> {
89
106
  if (this.pendingWorkFrames.length === 0) {
90
107
  this.logIfEnabled('[Queue empty]');
@@ -197,6 +197,7 @@ export class RequestLinkIcon extends HTMLElement {
197
197
  // clang-format off
198
198
  return LitHtml.html`
199
199
  <span class=${LitHtml.Directives.classMap({'link': Boolean(this.request)})}
200
+ tabindex="0"
200
201
  @click=${this.handleClick}>
201
202
  <${IconButton.Icon.Icon.litTagName} .data=${this.iconData() as IconButton.Icon.IconData}
202
203
  title=${this.getTooltip()}></${IconButton.Icon.Icon.litTagName}>
@@ -0,0 +1,161 @@
1
+ // Copyright 2021 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Common from '../../../core/common/common.js';
6
+ import * as CodeMirror from '../../../third_party/codemirror.next/codemirror.next.js';
7
+ import * as LitHtml from '../../lit-html/lit-html.js';
8
+ import * as CodeHighlighter from '../code_highlighter/code_highlighter.js';
9
+ import * as ComponentHelpers from '../helpers/helpers.js';
10
+
11
+ import {baseConfiguration, dynamicSetting} from './config.js';
12
+
13
+ declare global {
14
+ interface HTMLElementTagNameMap {
15
+ 'devtools-text-editor': TextEditor;
16
+ }
17
+ }
18
+
19
+ export class TextEditor extends HTMLElement {
20
+ static readonly litTagName = LitHtml.literal`devtools-text-editor`;
21
+
22
+ private readonly shadow = this.attachShadow({mode: 'open'});
23
+ private activeEditor: CodeMirror.EditorView|undefined = undefined;
24
+ private activeSettingListeners: [Common.Settings.Setting<unknown>, (event: {data: unknown}) => void][] = [];
25
+ private pendingState: CodeMirror.EditorState|undefined;
26
+
27
+ constructor(pendingState?: CodeMirror.EditorState) {
28
+ super();
29
+ this.pendingState = pendingState;
30
+ this.shadow.adoptedStyleSheets = [CodeHighlighter.Style.default];
31
+ }
32
+
33
+ private createEditor(): CodeMirror.EditorView {
34
+ this.activeEditor = new CodeMirror.EditorView({
35
+ state: this.updateDynamicSettings(this.state),
36
+ parent: this.shadow,
37
+ root: this.shadow,
38
+ });
39
+ return this.activeEditor;
40
+ }
41
+
42
+ get editor(): CodeMirror.EditorView {
43
+ return this.activeEditor || this.createEditor();
44
+ }
45
+
46
+ get state(): CodeMirror.EditorState {
47
+ if (this.activeEditor) {
48
+ return this.activeEditor.state;
49
+ }
50
+ if (!this.pendingState) {
51
+ this.pendingState = CodeMirror.EditorState.create({extensions: baseConfiguration('')});
52
+ }
53
+ return this.pendingState;
54
+ }
55
+
56
+ set state(state: CodeMirror.EditorState) {
57
+ if (this.activeEditor) {
58
+ this.activeEditor.setState(state);
59
+ } else {
60
+ this.pendingState = state;
61
+ }
62
+ }
63
+
64
+ connectedCallback(): void {
65
+ if (!this.activeEditor) {
66
+ this.createEditor();
67
+ }
68
+ this.registerSettingHandlers();
69
+ }
70
+
71
+ disconnectedCallback(): void {
72
+ if (this.activeEditor) {
73
+ this.pendingState = this.activeEditor.state;
74
+ this.activeEditor.destroy();
75
+ this.activeEditor = undefined;
76
+ }
77
+ for (const [setting, listener] of this.activeSettingListeners) {
78
+ setting.removeChangeListener(listener);
79
+ }
80
+ this.activeSettingListeners = [];
81
+ }
82
+
83
+ private updateDynamicSettings(state: CodeMirror.EditorState): CodeMirror.EditorState {
84
+ const settings = Common.Settings.Settings.instance();
85
+ const changes = [];
86
+ for (const opt of state.facet(dynamicSetting)) {
87
+ const mustUpdate = opt.sync(state, settings.moduleSetting(opt.settingName).get());
88
+ if (mustUpdate) {
89
+ changes.push(mustUpdate);
90
+ }
91
+ }
92
+ return changes.length ? state.update({effects: changes}).state : state;
93
+ }
94
+
95
+ private registerSettingHandlers(): void {
96
+ const settings = Common.Settings.Settings.instance();
97
+ for (const opt of this.state.facet(dynamicSetting)) {
98
+ const handler = ({data}: {data: unknown}): void => {
99
+ const change = opt.sync(this.state, data);
100
+ if (change && this.activeEditor) {
101
+ this.activeEditor.dispatch({effects: change});
102
+ }
103
+ };
104
+ const setting = settings.moduleSetting(opt.settingName);
105
+ setting.addChangeListener(handler);
106
+ this.activeSettingListeners.push([setting, handler]);
107
+ }
108
+ }
109
+
110
+ revealPosition(position: number): void {
111
+ const view = this.activeEditor;
112
+ if (!view) {
113
+ return;
114
+ }
115
+
116
+ const line = view.state.doc.lineAt(position);
117
+ view.dispatch({
118
+ selection: CodeMirror.EditorSelection.cursor(position),
119
+ scrollIntoView: true,
120
+ effects:
121
+ [view.state.field(highlightState, false) ?
122
+ setHighlightLine.of(line.from) :
123
+ CodeMirror.StateEffect.appendConfig.of(highlightState.init(() => highlightDeco(line.from)))],
124
+ });
125
+ const {id} = view.state.field(highlightState);
126
+ // Reset the highlight state if, after 2 seconds (the animation
127
+ // duration) it is still showing this highlight.
128
+ setTimeout(() => {
129
+ if (view.state.field(highlightState).id === id) {
130
+ view.dispatch({effects: setHighlightLine.of(null)});
131
+ }
132
+ }, 2000);
133
+ }
134
+ }
135
+
136
+ ComponentHelpers.CustomElements.defineComponent('devtools-text-editor', TextEditor);
137
+
138
+ const setHighlightLine = CodeMirror.StateEffect.define<number|null>(
139
+ {map: (value, mapping) => value === null ? null : mapping.mapPos(value)});
140
+
141
+ function highlightDeco(position: number): {deco: CodeMirror.DecorationSet, id: number} {
142
+ const deco = CodeMirror.Decoration.set(
143
+ [CodeMirror.Decoration.line({attributes: {class: 'cm-highlightedLine'}}).range(position)]);
144
+ return {deco, id: Math.floor(Math.random() * 0xfffff)};
145
+ }
146
+
147
+ const highlightState = CodeMirror.StateField.define<{deco: CodeMirror.DecorationSet, id: number}>({
148
+ create: () => ({deco: CodeMirror.Decoration.none, id: 0}),
149
+ update(value, tr) {
150
+ if (!tr.changes.empty && value.deco.size) {
151
+ value = {deco: value.deco.map(tr.changes), id: value.id};
152
+ }
153
+ for (const effect of tr.effects) {
154
+ if (effect.is(setHighlightLine)) {
155
+ value = effect.value === null ? {deco: CodeMirror.Decoration.none, id: 0} : highlightDeco(effect.value);
156
+ }
157
+ }
158
+ return value;
159
+ },
160
+ provide: field => CodeMirror.EditorView.decorations.from(field, value => value.deco),
161
+ });