@@ -63,6 +63,13 @@ public function hooks() : void {
6363 10 ,
6464 0
6565 );
66+
67+ add_filter (
68+ 'script_loader_tag ' ,
69+ \Closure::fromCallable ( [ $ this , 'add_script_attributes ' ] ),
70+ 10 ,
71+ 2
72+ );
6673 }
6774
6875 /**
@@ -158,6 +165,43 @@ private function enqueue_assets() : void {
158165 ] );
159166
160167 \wp_dequeue_style ( 'wp-block-library ' );
168+
169+ \wp_enqueue_script ( // phpcs:ignore
170+ 'duet-date-picker-module ' ,
171+ 'https://cdn.jsdelivr.net/npm/@duetds/date-picker@1.4.0/dist/duet/duet.esm.js ' ,
172+ [ 'jquery ' ],
173+ null ,
174+ false
175+ );
176+
177+ \wp_enqueue_script ( // phpcs:ignore
178+ 'duet-date-picker-nomodule ' ,
179+ 'https://cdn.jsdelivr.net/npm/@duetds/date-picker@1.4.0/dist/duet/duet.js ' ,
180+ [ 'jquery ' ],
181+ null ,
182+ false
183+ );
184+ }
185+
186+ /**
187+ * Add attributes to enqueued script tags
188+ *
189+ * @param string $tag Script tag.
190+ * @param string $handle Script handle name.
191+ * @return string The script tag.
192+ */
193+ private function add_script_attributes ( $ tag , $ handle ) : string {
194+
195+ if ( $ handle === 'duet-date-picker-module ' ) {
196+ $ tag = str_replace ( '<script ' , ' <script type="module" ' , $ tag );
197+ return $ tag ;
198+ }
199+
200+ if ( $ handle === 'duet-date-picker-nomodule ' ) {
201+ $ tag = str_replace ( '<script ' , ' <script nomodule ' , $ tag );
202+ return $ tag ;
203+ }
204+ return $ tag ;
161205 }
162206
163207 /**
0 commit comments