33// BSD-style license that can be found in the LICENSE file.
44
55import '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' ;
1110import 'deferred/markdown.dart' deferred as md;
1211import 'mdc/mdc_dialog.dart' ;
12+ import 'web_util.dart' ;
1313
1414/// Displays a message via the modal window.
1515Future <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.
159168Future <Element > markdown (String text) async {
0 commit comments