PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / trunk
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution vtrunk
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Vite.php

Vite.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution trunk, at app/Vite.php

292 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App;
4
5 use FluentBooking\App\Services\Helper;
6
7 class Vite
8 {
9 protected static $entries = [
10 'admin_app' => [
11 'src' => 'resources/admin/app.js',
12 'build' => 'admin/app.js',
13 'module' => false,
14 ],
15 'global_admin' => [
16 'src' => 'resources/admin/global_admin.js',
17 'build' => 'admin/global_admin.js',
18 'module' => false,
19 ],
20 'fb_index' => [
21 'src' => 'resources/Blocks/fluent-booking-index.js',
22 'build' => 'admin/fluent-booking-index.js',
23 'module' => false,
24 ],
25 'fb_team' => [
26 'src' => 'resources/Blocks/TeamManagement/fluent-booking-team-management-index.jsx',
27 'build' => 'admin/fluent-booking-team-management-index.js',
28 'module' => false,
29 ],
30 'fb_calendar' => [
31 'src' => 'resources/Blocks/CalendarManagement/fluent-booking-calendar-management-index.jsx',
32 'build' => 'admin/fluent-booking-calendar-management-index.js',
33 'module' => false,
34 ],
35 'fb_booking' => [
36 'src' => 'resources/Blocks/BookingManagement/fluent-booking-booking-management-index.jsx',
37 'build' => 'admin/fluent-booking-booking-management-index.js',
38 'module' => false,
39 ],
40 'public_app' => [
41 'src' => 'resources/public/app.js',
42 'build' => 'public/js/app.js',
43 'module' => false,
44 ],
45 'widget' => [
46 'src' => 'resources/public/widget.js',
47 'build' => 'public/js/widget.js',
48 'module' => false,
49 ],
50 'ff_public' => [
51 'src' => 'resources/public/fluentform.js',
52 'build' => 'public/js/fluentform.js',
53 'module' => false,
54 ],
55 'ff_conversational' => [
56 'src' => 'resources/public/fluentform-conversational.js',
57 'build' => 'public/js/fluentform-conversational.js',
58 'module' => false,
59 ],
60 'phone_field' => [
61 'src' => 'resources/public/ExtendedPhone/phone-field.js',
62 'build' => 'public/js/phone-field.js',
63 'module' => false,
64 ],
65 'manage_meeting' => [
66 'src' => 'resources/public/public-manage-meeting.js',
67 'build' => 'public/js/public-manage-meeting.js',
68 'module' => false,
69 ],
70 'team_app' => [
71 'src' => 'resources/public/Team/team_app.js',
72 'build' => 'public/js/team_app.js',
73 'module' => false,
74 ],
75 'calendar_app' => [
76 'src' => 'resources/public/Team/calendar_app.js',
77 'build' => 'public/js/calendar_app.js',
78 'module' => false,
79 ],
80 'bookings' => [
81 'src' => 'resources/public/Booking/bookings.js',
82 'build' => 'public/js/bookings.js',
83 'module' => false,
84 ],
85 ];
86
87 protected static $styles = [
88 'fb_index_css' => [
89 'src' => 'resources/Blocks/fluent-booking-block.scss',
90 'build' => 'admin/fluent-booking-index.css',
91 'rtl' => false,
92 ],
93 'fb_team_css' => [
94 'src' => 'resources/Blocks/TeamManagement/fcal-team-management-block.scss',
95 'build' => 'admin/fluent-booking-team-management-index.css',
96 'rtl' => false,
97 ],
98 'fb_calendar_css' => [
99 'src' => 'resources/Blocks/CalendarManagement/fcal-calendar-management-block.scss',
100 'build' => 'admin/fluent-booking-calendar-management-index.css',
101 'rtl' => false,
102 ],
103 'fb_booking_css' => [
104 'src' => 'resources/Blocks/BookingManagement/fcal-booking-management-block.scss',
105 'build' => 'admin/fluent-booking-booking-management-index.css',
106 'rtl' => false,
107 ],
108 'admin_css' => [
109 'src' => 'resources/scss/admin.scss',
110 'build' => 'admin/admin.css',
111 'rtl' => true,
112 ],
113 'admin_rtl_css' => [
114 'src' => 'resources/scss/fluentbooking_admin_rtl.scss',
115 'build' => 'admin/fluentbooking_admin_rtl.css',
116 'rtl' => false,
117 ],
118 'saas_css' => [
119 'src' => 'resources/scss/saas.scss',
120 'build' => 'public/saas.css',
121 'rtl' => true,
122 ],
123 'saas_public_css' => [
124 'src' => 'resources/scss/saas_public.scss',
125 'build' => 'public/saas_public.css',
126 'rtl' => true,
127 ],
128 'saas_admin_css' => [
129 'src' => 'resources/scss/saas_admin.scss',
130 'build' => 'public/saas_admin.css',
131 'rtl' => false,
132 ],
133 ];
134
135 protected static $moduleHandles = [];
136
137 protected static $clientEnqueued = false;
138
139 protected static function devServer()
140 {
141 static $origin = null;
142
143 if ($origin !== null) {
144 return $origin;
145 }
146
147 $origin = '';
148
149 if (defined('FLUENT_BOOKING_DISABLE_VITE_DEV') && FLUENT_BOOKING_DISABLE_VITE_DEV) {
150 return $origin;
151 }
152
153 $hotFile = FLUENT_BOOKING_DIR . '.vite-hot';
154
155 if (!is_readable($hotFile)) {
156 return $origin;
157 }
158
159 $contents = trim((string) file_get_contents($hotFile));
160
161 if (preg_match('#^https?://(localhost|127\.0\.0\.1)(:\d+)?$#', $contents)) {
162 $origin = $contents;
163 }
164
165 return $origin;
166 }
167
168 public static function isDev()
169 {
170 return static::devServer() !== '';
171 }
172
173 public static function scriptUrl($entry)
174 {
175 if (!isset(static::$entries[$entry])) {
176 return '';
177 }
178
179 if (static::isDev()) {
180 return static::devServer() . '/' . static::$entries[$entry]['src'];
181 }
182
183 return App::getInstance()['url.assets'] . static::$entries[$entry]['build'];
184 }
185
186 public static function styleUrl($entry)
187 {
188 if (!isset(static::$styles[$entry])) {
189 return '';
190 }
191
192 $style = static::$styles[$entry];
193
194 if (static::isDev()) {
195 return static::devServer() . '/' . $style['src'];
196 }
197
198 $file = $style['build'];
199
200 if ($style['rtl'] && Helper::fluentbooking_is_rtl()) {
201 $file = preg_replace('/\.css$/', '-rtl.css', $file);
202 }
203
204 return App::getInstance()['url.assets'] . $file;
205 }
206
207 public static function styleIsModule()
208 {
209 return static::isDev();
210 }
211
212 public static function enqueueScript($handle, $entry, $deps = [], $version = false, $inFooter = true)
213 {
214 if (!isset(static::$entries[$entry])) {
215 return;
216 }
217
218 $src = static::scriptUrl($entry);
219
220 if (!$src) {
221 return;
222 }
223
224 static::bootDevClient();
225
226 wp_enqueue_script($handle, $src, $deps, $version, $inFooter);
227
228 if (static::isDev() || static::$entries[$entry]['module']) {
229 static::markAsModule($handle);
230 }
231 }
232
233 public static function enqueueStyle($handle, $entry, $deps = [], $version = false, $media = 'all')
234 {
235 if (!isset(static::$styles[$entry])) {
236 return;
237 }
238
239 $src = static::styleUrl($entry);
240
241 if (static::isDev()) {
242 if (!static::$styles[$entry]['src']) {
243 return;
244 }
245
246 static::bootDevClient();
247
248 $devHandle = $handle . '-vite-style';
249
250 wp_enqueue_script($devHandle, $src, [], $version, true);
251 static::markAsModule($devHandle);
252
253 return;
254 }
255
256 wp_enqueue_style($handle, $src, $deps, $version, $media);
257 }
258
259 protected static function bootDevClient()
260 {
261 if (!static::isDev() || static::$clientEnqueued) {
262 return;
263 }
264
265 static::$clientEnqueued = true;
266
267 wp_enqueue_script('fluent-booking-vite-client', static::devServer() . '/@vite/client', [], null, false);
268 static::markAsModule('fluent-booking-vite-client');
269 }
270
271 protected static function markAsModule($handle)
272 {
273 if (in_array($handle, static::$moduleHandles, true)) {
274 return;
275 }
276
277 if (!static::$moduleHandles) {
278 add_filter('script_loader_tag', function ($tag, $handle) {
279 if (!in_array($handle, self::$moduleHandles, true)) {
280 return $tag;
281 }
282
283 $tag = preg_replace('/\stype=([\'"])[^\'"]*\1/', '', $tag);
284
285 return str_replace('<script ', '<script type="module" ', $tag);
286 }, 10, 2);
287 }
288
289 static::$moduleHandles[] = $handle;
290 }
291 }
292