Skip to content

Commit b5afa3b

Browse files
committed
Merge remote-tracking branch 'origin/develop' into wip/trigger-rewrite
2 parents 0107abb + 5198a5c commit b5afa3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+977
-523
lines changed

modules/backend/console/UserCreate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function handle(): int
5858
'first_name' => $this->option('fname') ?: $this->ask('First name', ''),
5959
'last_name' => $this->option('lname') ?: $this->ask('Last name', ''),
6060
'role_id' => (
61-
$role = UserRole::where(
61+
UserRole::where(
6262
'code',
6363
$this->option('role') ?: $this->choice(
6464
'Role',

modules/backend/formwidgets/Relation.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<?php namespace Backend\FormWidgets;
1+
<?php
2+
3+
namespace Backend\FormWidgets;
24

35
use Db;
6+
use Lang;
47
use Backend\Classes\FormField;
58
use Backend\Classes\FormWidgetBase;
6-
use Lang;
7-
use Winter\Storm\Database\Relations\Relation as RelationBase;
9+
use Illuminate\Database\Eloquent\Relations\Relation as RelationBase;
810
use Winter\Storm\Exception\SystemException;
911

1012
/**

modules/backend/formwidgets/TagList.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<?php namespace Backend\FormWidgets;
1+
<?php
2+
3+
namespace Backend\FormWidgets;
24

35
use Backend\Classes\FormWidgetBase;
4-
use Winter\Storm\Database\Relations\Relation as RelationBase;
6+
use Illuminate\Database\Eloquent\Relations\Relation as RelationBase;
57

68
/**
79
* Tag List Form Widget

modules/backend/formwidgets/fileupload/partials/_file_multi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class="field-fileupload style-file-multi is-sortable is-multi <?= count($fileLis
3636
class="upload-remove-button"
3737
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
3838
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
39-
data-request-data="file_id: <?= $file->id ?>"
39+
data-request-data="file_id: '<?= $file->id ?>'"
4040
><i class="icon-times"></i></a>
4141
</h4>
4242
<p class="size"><?= e($file->sizeToString()) ?></p>

modules/backend/formwidgets/fileupload/partials/_file_single.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class="field-fileupload style-file-single <?= $singleFile ? 'is-populated' : ''
3939
class="upload-remove-button"
4040
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
4141
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
42-
data-request-data="file_id: <?= $singleFile->id ?>"
42+
data-request-data="file_id: '<?= $singleFile->id ?>'"
4343
><i class="icon-times"></i></a>
4444
</div>
4545
</div>

modules/backend/formwidgets/fileupload/partials/_image_multi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class="field-fileupload style-image-multi is-sortable is-multi <?= count($fileLi
3636
class="upload-remove-button"
3737
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
3838
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
39-
data-request-data="file_id: <?= $file->id ?>"
39+
data-request-data="file_id: '<?= $file->id ?>'"
4040
><i class="icon-times"></i></a>
4141
</h4>
4242
<p class="size"><?= e($file->sizeToString()) ?></p>

modules/backend/formwidgets/fileupload/partials/_image_single.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class="upload-button">
4040
class="upload-remove-button"
4141
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
4242
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
43-
data-request-data="file_id: <?= $singleFile->id ?>"
43+
data-request-data="file_id: '<?= $singleFile->id ?>'"
4444
><i class="icon-times"></i></a>
4545
</h4>
4646
<p class="size"><?= e($singleFile->sizeToString()) ?></p>

modules/system/tests/classes/AutoDatasourceTest.php modules/cms/tests/classes/AutoDatasourceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace System\Tests\Classes;
3+
namespace Cms\Tests\Classes;
44

55
use System\Tests\Bootstrap\PluginTestCase;
66
use Cms\Classes\AutoDatasource;

modules/cms/twig/Extension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Block;
44
use Cms\Classes\Controller;
55
use Event;
6-
use System\Classes\Vite;
6+
use System\Classes\Asset\Vite;
77
use Twig\Extension\AbstractExtension as TwigExtension;
88
use Twig\TwigFilter as TwigSimpleFilter;
99
use Twig\TwigFunction as TwigSimpleFunction;

modules/system/ServiceProvider.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Config;
99
use DateInterval;
1010
use Event;
11-
use Illuminate\Foundation\Vite;
11+
use Illuminate\Foundation\Vite as LaravelVite;
1212
use Illuminate\Pagination\Paginator;
1313
use Illuminate\Support\Facades\Schema;
1414
use Markdown;
@@ -145,7 +145,7 @@ protected function registerSingletons()
145145
});
146146

147147
// Register the Laravel Vite singleton
148-
$this->app->singleton(Vite::class, \System\Classes\Vite::class);
148+
$this->app->singleton(LaravelVite::class, \System\Classes\Asset\Vite::class);
149149
}
150150

151151
/**
@@ -321,19 +321,19 @@ protected function registerConsole()
321321
$this->registerConsoleCommand('plugin.list', \System\Console\PluginList::class);
322322

323323
$this->registerConsoleCommand('mix.compile', Console\Asset\Mix\MixCompile::class);
324-
$this->registerConsoleCommand('mix.config', Console\Asset\Mix\MixConfig::class);
324+
$this->registerConsoleCommand('mix.config', Console\Asset\Mix\MixCreate::class);
325325
$this->registerConsoleCommand('mix.install', Console\Asset\Mix\MixInstall::class);
326326
$this->registerConsoleCommand('mix.list', Console\Asset\Mix\MixList::class);
327327
$this->registerConsoleCommand('mix.watch', Console\Asset\Mix\MixWatch::class);
328328

329329
$this->registerConsoleCommand('vite.compile', Console\Asset\Vite\ViteCompile::class);
330-
$this->registerConsoleCommand('vite.config', Console\Asset\Vite\ViteConfig::class);
330+
$this->registerConsoleCommand('vite.config', Console\Asset\Vite\ViteCreate::class);
331331
$this->registerConsoleCommand('vite.install', Console\Asset\Vite\ViteInstall::class);
332332
$this->registerConsoleCommand('vite.list', Console\Asset\Vite\ViteList::class);
333333
$this->registerConsoleCommand('vite.watch', Console\Asset\Vite\ViteWatch::class);
334334

335-
$this->registerConsoleCommand('npm.run', Console\NpmRun::class);
336-
$this->registerConsoleCommand('npm.update', Console\NpmUpdate::class);
335+
$this->registerConsoleCommand('npm.run', Console\Asset\NpmRun::class);
336+
$this->registerConsoleCommand('npm.update', Console\Asset\NpmUpdate::class);
337337
}
338338

339339
/*

modules/system/classes/MailManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function listRegisteredLayouts()
344344
/**
345345
* Registers a callback function that defines mail templates.
346346
* The callback function should register templates by calling the manager's
347-
* registerMailTemplates() function. Thi instance is passed to the
347+
* registerMailTemplates() function. This instance is passed to the
348348
* callback function as an argument. Usage:
349349
*
350350
* MailManager::registerCallback(function ($manager) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
<?php
2+
3+
namespace System\Classes\Asset;
4+
5+
use Closure;
6+
use Winter\Storm\Support\Traits\Singleton;
7+
8+
/**
9+
* Asset Bundle manager.
10+
*
11+
* This class manages "asset bundles" registered by the core and plugins that are used by the
12+
* [mix|vite]:create commands to generate & populate the required files for a given bundle.
13+
* Bundles include information on the specific packages & versions required for the bundle
14+
* to function in the context of the Winter package (plugin or theme) it is being used in,
15+
* as well as dependencies specific to the desired compiler (e.g. mix or vite).
16+
*
17+
* @package winter\wn-system-module
18+
* @author Jack Wilkinson <[email protected]>
19+
* @copyright Winter CMS Maintainers
20+
*/
21+
class BundleManager
22+
{
23+
use Singleton;
24+
25+
protected const HANDLER_SETUP = '_setup';
26+
protected const HANDLER_SCAFFOLD = '_scaffold';
27+
28+
/**
29+
* List of packages available to install. Allows for `$compilerName` => [`CompilerSpecificPackage`]
30+
*/
31+
protected array $defaultPackages = [
32+
'tailwind' => [
33+
'tailwindcss' => '^3.4.0',
34+
'@tailwindcss/forms' => '^0.5.3',
35+
'@tailwindcss/typography' => '^0.5.2',
36+
],
37+
'vue' => [
38+
'vue' => '^3.4.0',
39+
'vite' => [
40+
'@vitejs/plugin-vue' => '^5.0.5'
41+
],
42+
],
43+
];
44+
45+
/**
46+
* List of registered asset bundles in the system
47+
*/
48+
protected array $registeredBundles = [];
49+
50+
/**
51+
* Initialize the singleton
52+
*/
53+
public function init(): void
54+
{
55+
// Register the default bundles
56+
$this->registerCallback(function (self $manager) {
57+
$manager->registerBundles($this->defaultPackages);
58+
59+
$manager->registerSetupHandler('tailwind', function (string $packagePath, string $packageType) {
60+
$this->writeFile(
61+
$packagePath . '/tailwind.config.js',
62+
$this->getFixture('tailwind/tailwind.' . $packageType . '.config.js.fixture')
63+
);
64+
65+
$this->writeFile(
66+
$packagePath . '/postcss.config.mjs',
67+
$this->getFixture('tailwind/postcss.config.js.fixture')
68+
);
69+
});
70+
71+
$manager->registerScaffoldHandler('tailwind', function (string $contents, string $contentType) {
72+
return match ($contentType) {
73+
'mix' => $contents . PHP_EOL . <<<JAVASCRIPT
74+
mix.postCss('assets/src/css/{{packageName}}.css', 'assets/dist/css/{{packageName}}.css', [
75+
require('postcss-import'),
76+
require('tailwindcss'),
77+
require('autoprefixer'),
78+
]);
79+
JAVASCRIPT,
80+
'css' => $this->getFixture('css/tailwind.css.fixture'),
81+
default => $contents
82+
};
83+
});
84+
85+
$manager->registerScaffoldHandler('vue', function (string $contents, string $contentType) {
86+
return match ($contentType) {
87+
'vite' => str_replace(
88+
'}),',
89+
<<<JAVASCRIPT
90+
}),
91+
vue({
92+
template: {
93+
transformAssetUrls: {
94+
// The Vue plugin will re-write asset URLs, when referenced
95+
// in Single File Components, to point to the Laravel web
96+
// server. Setting this to `null` allows the Laravel plugin
97+
// to instead re-write asset URLs to point to the Vite
98+
// server instead.
99+
base: null,
100+
101+
// The Vue plugin will parse absolute URLs and treat them
102+
// as absolute paths to files on disk. Setting this to
103+
// `false` will leave absolute URLs un-touched so they can
104+
// reference assets in the public directory as expected.
105+
includeAbsolute: false,
106+
},
107+
},
108+
}),
109+
JAVASCRIPT,
110+
str_replace(
111+
'import laravel from \'laravel-vite-plugin\';',
112+
'import laravel from \'laravel-vite-plugin\';' . PHP_EOL . 'import vue from \'@vitejs/plugin-vue\';',
113+
$contents
114+
)
115+
),
116+
'mix' => str_replace(
117+
'mix.js(\'assets/src/js/{{packageName}}.js\', \'assets/dist/js/{{packageName}}.js\');',
118+
'mix.js(\'assets/src/js/{{packageName}}.js\', \'assets/dist/js/{{packageName}}.js\').vue({ version: 3 });',
119+
$contents
120+
),
121+
'js' => $this->getFixture('js/vue.js.fixture'),
122+
default => $contents
123+
};
124+
});
125+
});
126+
}
127+
128+
/**
129+
* Returns a list of the registered asset bundles.
130+
*/
131+
public function listRegisteredBundles(): array
132+
{
133+
return $this->registeredBundles;
134+
}
135+
136+
/**
137+
* Get all bundles configured
138+
*/
139+
public function getBundles(): array
140+
{
141+
return array_keys($this->listRegisteredBundles());
142+
}
143+
144+
/**
145+
* Get the packages for a bundle, with compiler specific packages
146+
*/
147+
public function getBundlePackages(string $name, string $assetType): array
148+
{
149+
$config = $this->listRegisteredBundles()[$name] ?? [];
150+
151+
$packages = [];
152+
foreach ($config as $key => $value) {
153+
// Skip handlers
154+
if (in_array($key, [static::HANDLER_SETUP, static::HANDLER_SCAFFOLD])) {
155+
continue;
156+
}
157+
158+
// Merge in any compiler specific packages for the current compiler
159+
if (is_array($value)) {
160+
if ($key === $assetType) {
161+
$packages = array_merge($packages, $value);
162+
}
163+
continue;
164+
}
165+
166+
$packages[$key] = $value;
167+
}
168+
169+
return $packages;
170+
}
171+
172+
/**
173+
* Registers a callback function that defines asset bundles. The callback function
174+
* should register bundles by calling the manager's registerBundles() function.
175+
* This instance is passed to the callback function as an argument. Usage:
176+
*
177+
* BundleManager::registerCallback(function ($manager) {
178+
* $manager->registerAssetBundles([...]);
179+
* });
180+
*
181+
*/
182+
public function registerCallback(callable $callback): static
183+
{
184+
$callback($this);
185+
186+
return $this;
187+
}
188+
189+
/**
190+
* Registers asset bundles.
191+
*/
192+
public function registerBundles(array $definitions): static
193+
{
194+
foreach ($definitions as $name => $definition) {
195+
$this->registerBundle($name, $definition);
196+
}
197+
198+
return $this;
199+
}
200+
201+
/**
202+
* Registers a single asset bundle.
203+
*/
204+
public function registerBundle(string $name, array $definition): static
205+
{
206+
$this->registeredBundles[$name] = $definition;
207+
208+
return $this;
209+
}
210+
211+
/**
212+
* Registers a single bundle setup handler.
213+
*/
214+
public function registerSetupHandler(string $name, Closure $closure): static
215+
{
216+
$this->registeredBundles[$name][static::HANDLER_SETUP] = $closure;
217+
218+
return $this;
219+
}
220+
221+
/**
222+
* Registers a single bundle scaffold handler.
223+
*/
224+
public function registerScaffoldHandler(string $name, Closure $closure): static
225+
{
226+
$this->registeredBundles[$name][static::HANDLER_SCAFFOLD] = $closure;
227+
228+
return $this;
229+
}
230+
231+
/**
232+
* Gets the setup handler for a bundle.
233+
*/
234+
public function getSetupHandler(string $name): ?Closure
235+
{
236+
return $this->listRegisteredBundles()[$name][static::HANDLER_SETUP] ?? null;
237+
}
238+
239+
/**
240+
* Gets the scaffold handler for a bundle.
241+
*/
242+
public function getScaffoldHandler(string $name): ?Closure
243+
{
244+
return $this->listRegisteredBundles()[$name][static::HANDLER_SCAFFOLD] ?? null;
245+
}
246+
}

0 commit comments

Comments
 (0)