Skip to content

Commit 0d9cae6

Browse files
authored
Complete the package:web migration of pkg/web_app (dart-lang#9387)
1 parent 423738d commit 0d9cae6

10 files changed

Lines changed: 233 additions & 306 deletions

File tree

.github/workflows/all-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ jobs:
149149
run: |
150150
if [[ "${{ matrix.package }}" == "pub_integration" ]]; then
151151
dart tool/trigger_puppeteer_download.dart
152+
dart test --run-skipped -j 1
153+
else
154+
dart test --run-skipped
152155
fi
153-
dart test --run-skipped
154156
working-directory: pkg/${{matrix.package}}
155157
env:
156158
PUB_POSTGRES_URL: postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable

app/test/frontend/static_files_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void main() {
235235
test('script.dart.js and parts size check', () {
236236
final file = cache.getFile('/static/js/script.dart.js');
237237
expect(file, isNotNull);
238-
expect((file!.bytes.length / 1024).round(), closeTo(366, 20));
238+
expect((file!.bytes.length / 1024).round(), closeTo(275, 20));
239239

240240
final parts = cache.paths
241241
.where(

pkg/web_app/lib/src/_dart_html_focusability.dart

Lines changed: 0 additions & 89 deletions
This file was deleted.

pkg/web_app/lib/src/_dom_helper.dart

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6-
// TODO: migrate to package:web
7-
// ignore: deprecated_member_use
8-
import 'dart:html';
96

10-
import '_dart_html_focusability.dart';
7+
import 'package:web/web.dart';
8+
9+
import '_focusability.dart';
1110
import 'deferred/markdown.dart' deferred as md;
1211
import 'mdc/mdc_dialog.dart';
12+
import 'web_util.dart';
1313

1414
/// Displays a message via the modal window.
1515
Future<void> modalMessage(String title, String message) async {
@@ -75,7 +75,7 @@ Future<bool> modalWindow({
7575
dialog.destroy();
7676
root.remove();
7777
// Note: This seems to be a bug in the JS library
78-
document.body!.classes.remove('mdc-dialog-scroll-lock');
78+
document.body!.classList.remove('mdc-dialog-scroll-lock');
7979
}
8080
return await c.future;
8181
}
@@ -90,70 +90,79 @@ Element _buildDialog({
9090
/// The callback will be called with `true` when "OK" was clicked, and `false`
9191
/// when "Cancel" was clicked.
9292
required void Function(bool) closing,
93-
}) => document.createElement('div')
94-
..classes.add('mdc-dialog')
95-
..attributes.addAll({
96-
'role': 'alertdialog',
97-
'aria-model': 'true',
98-
'aria-labelledby': 'pub-dialog-title',
99-
'aria-describedby': 'pub-dialog-content',
100-
})
101-
..children = [
102-
document.createElement('div')
103-
..classes.add('mdc-dialog__container')
104-
..children = [
105-
document.createElement('div')
106-
..classes.add('mdc-dialog__surface')
107-
..children = [
108-
document.createElement('h2')
109-
..classes.add('mdc-dialog__title')
110-
..id = 'pub-dialog-title'
111-
..innerText = titleText,
112-
document.createElement('div')
113-
..classes.add('mdc-dialog__content')
114-
..id = 'pub-dialog-content'
115-
..children = [content],
116-
document.createElement('footer')
117-
..classes.add('mdc-dialog__actions')
118-
..children = [
119-
if (isQuestion)
120-
document.createElement('button')
121-
..classes.addAll([
122-
'mdc-button',
123-
'mdc-dialog__button',
124-
'-pub-dom-dialog-cancel-button',
125-
])
126-
..tabIndex = 2
127-
..onClick.listen((e) {
128-
e.preventDefault();
129-
closing(false);
130-
})
131-
..children = [
132-
document.createElement('span')
133-
..classes.add('mdc-button__label')
134-
..innerText = cancelButtonText ?? 'Cancel',
135-
],
136-
document.createElement('button')
137-
..classes.addAll([
138-
'mdc-button',
139-
'mdc-dialog__button',
140-
'-pub-dom-dialog-ok-button',
141-
])
142-
..tabIndex = 1
143-
..onClick.listen((e) {
144-
e.preventDefault();
145-
closing(true);
146-
})
147-
..children = [
148-
document.createElement('span')
149-
..classes.add('mdc-button__label')
150-
..innerText = okButtonText ?? 'Ok',
151-
],
152-
],
153-
],
154-
],
155-
document.createElement('div')..classes.add('mdc-dialog__scrim'),
156-
];
93+
}) {
94+
final title = document.createElement('h2') as HTMLElement
95+
..classList.add('mdc-dialog__title')
96+
..id = 'pub-dialog-title'
97+
..innerText = titleText;
98+
99+
final contentDiv = HTMLDivElement()
100+
..classList.add('mdc-dialog__content')
101+
..id = 'pub-dialog-content'
102+
..append(content);
103+
104+
final footer = document.createElement('footer');
105+
footer.classList.add('mdc-dialog__actions');
106+
107+
if (isQuestion) {
108+
final cancelBtn = HTMLButtonElement()
109+
..classList.addAll([
110+
'mdc-button',
111+
'mdc-dialog__button',
112+
'-pub-dom-dialog-cancel-button',
113+
])
114+
..tabIndex = 2;
115+
cancelBtn.onClick.listen((e) {
116+
e.preventDefault();
117+
closing(false);
118+
});
119+
cancelBtn.append(
120+
HTMLSpanElement()
121+
..classList.add('mdc-button__label')
122+
..innerText = cancelButtonText ?? 'Cancel',
123+
);
124+
footer.append(cancelBtn);
125+
}
126+
127+
final okBtn = HTMLButtonElement()
128+
..classList.addAll([
129+
'mdc-button',
130+
'mdc-dialog__button',
131+
'-pub-dom-dialog-ok-button',
132+
])
133+
..tabIndex = 1;
134+
okBtn.onClick.listen((e) {
135+
e.preventDefault();
136+
closing(true);
137+
});
138+
okBtn.append(
139+
HTMLSpanElement()
140+
..classList.add('mdc-button__label')
141+
..innerText = okButtonText ?? 'Ok',
142+
);
143+
footer.append(okBtn);
144+
145+
final surface = HTMLDivElement()
146+
..classList.add('mdc-dialog__surface')
147+
..append(title)
148+
..append(contentDiv)
149+
..append(footer);
150+
151+
final container = HTMLDivElement()
152+
..classList.add('mdc-dialog__container')
153+
..append(surface);
154+
155+
final root = HTMLDivElement()
156+
..classList.add('mdc-dialog')
157+
..setAttribute('role', 'alertdialog')
158+
..setAttribute('aria-model', 'true')
159+
..setAttribute('aria-labelledby', 'pub-dialog-title')
160+
..setAttribute('aria-describedby', 'pub-dialog-content')
161+
..append(container)
162+
..append(HTMLDivElement()..classList.add('mdc-dialog__scrim'));
163+
164+
return root;
165+
}
157166

158167
/// Creates an [Element] with Markdown-formatted content.
159168
Future<Element> markdown(String text) async {

0 commit comments

Comments
 (0)