Update Kirby and dependencies
This commit is contained in:
parent
07150a0011
commit
c7c5d615a4
451 changed files with 67540 additions and 63740 deletions
|
@ -3,7 +3,9 @@
|
|||
namespace Kirby\Panel;
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Data\Json;
|
||||
use Kirby\Filesystem\F;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
|
@ -19,91 +21,131 @@ use Kirby\Toolkit\Str;
|
|||
*/
|
||||
class Plugins
|
||||
{
|
||||
/**
|
||||
* Cache of all collected plugin files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $files;
|
||||
/**
|
||||
* Cache of all collected plugin files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $files;
|
||||
|
||||
/**
|
||||
* Collects and returns the plugin files for all plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function files(): array
|
||||
{
|
||||
if ($this->files !== null) {
|
||||
return $this->files;
|
||||
}
|
||||
/**
|
||||
* Collects and returns the plugin files for all plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function files(): array
|
||||
{
|
||||
if ($this->files !== null) {
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
$this->files = [];
|
||||
$this->files = [];
|
||||
|
||||
foreach (App::instance()->plugins() as $plugin) {
|
||||
$this->files[] = $plugin->root() . '/index.css';
|
||||
$this->files[] = $plugin->root() . '/index.js';
|
||||
}
|
||||
foreach (App::instance()->plugins() as $plugin) {
|
||||
$this->files[] = $plugin->root() . '/index.css';
|
||||
$this->files[] = $plugin->root() . '/index.js';
|
||||
// During plugin development, kirbyup adds an index.dev.mjs as entry point, which
|
||||
// Kirby will load instead of the regular index.js. Since kirbyup is based on Vite,
|
||||
// it can't use the standard index.js as entry for its development server:
|
||||
// Vite requires an entry of type module so it can use JavaScript imports,
|
||||
// but Kirbyup needs index.js to load as a regular script, synchronously.
|
||||
$this->files[] = $plugin->root() . '/index.dev.mjs';
|
||||
}
|
||||
|
||||
return $this->files;
|
||||
}
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last modification
|
||||
* of the collected plugin files
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function modified(): int
|
||||
{
|
||||
$files = $this->files();
|
||||
$modified = [0];
|
||||
/**
|
||||
* Returns the last modification
|
||||
* of the collected plugin files
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function modified(): int
|
||||
{
|
||||
$files = $this->files();
|
||||
$modified = [0];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$modified[] = F::modified($file);
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$modified[] = F::modified($file);
|
||||
}
|
||||
|
||||
return max($modified);
|
||||
}
|
||||
return max($modified);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the files from all plugins and concatenate them
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function read(string $type): string
|
||||
{
|
||||
$dist = [];
|
||||
/**
|
||||
* Read the files from all plugins and concatenate them
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function read(string $type): string
|
||||
{
|
||||
$dist = [];
|
||||
|
||||
foreach ($this->files() as $file) {
|
||||
if (F::extension($file) === $type) {
|
||||
if ($content = F::read($file)) {
|
||||
if ($type === 'js') {
|
||||
$content = trim($content);
|
||||
foreach ($this->files() as $file) {
|
||||
// filter out files with a different type
|
||||
if (F::extension($file) !== $type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure that each plugin is ended correctly
|
||||
if (Str::endsWith($content, ';') === false) {
|
||||
$content .= ';';
|
||||
}
|
||||
}
|
||||
// filter out empty files and files that don't exist
|
||||
$content = F::read($file);
|
||||
if (!$content) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$dist[] = $content;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($type === 'mjs') {
|
||||
// index.dev.mjs files are turned into data URIs so they
|
||||
// can be imported without having to copy them to /media
|
||||
// (avoids having to clean the files from /media again)
|
||||
$content = F::uri($file);
|
||||
}
|
||||
|
||||
return implode(PHP_EOL . PHP_EOL, $dist);
|
||||
}
|
||||
if ($type === 'js') {
|
||||
// filter out all index.js files that shouldn't be loaded
|
||||
// because an index.dev.mjs exists
|
||||
if (F::exists(preg_replace('/\.js$/', '.dev.mjs', $file)) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute url to the cache file
|
||||
* This is used by the panel to link the plugins
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function url(string $type): string
|
||||
{
|
||||
return App::instance()->url('media') . '/plugins/index.' . $type . '?' . $this->modified();
|
||||
}
|
||||
$content = trim($content);
|
||||
|
||||
// make sure that each plugin is ended correctly
|
||||
if (Str::endsWith($content, ';') === false) {
|
||||
$content .= ';';
|
||||
}
|
||||
}
|
||||
|
||||
$dist[] = $content;
|
||||
}
|
||||
|
||||
if ($type === 'mjs') {
|
||||
// if no index.dev.mjs modules exist, we MUST return an empty string instead
|
||||
// of loading an empty array; this is because the module loader code uses
|
||||
// top level await, which is not compatible with Kirby's minimum browser
|
||||
// version requirements and therefore must not appear in a default setup
|
||||
if (empty($dist)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$modules = Json::encode($dist);
|
||||
$modulePromise = "Promise.all($modules.map(url => import(url)))";
|
||||
return "try { await $modulePromise } catch (e) { console.error(e) }" . PHP_EOL;
|
||||
}
|
||||
|
||||
return implode(PHP_EOL . PHP_EOL, $dist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute url to the cache file
|
||||
* This is used by the panel to link the plugins
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function url(string $type): string
|
||||
{
|
||||
return App::instance()->url('media') . '/plugins/index.' . $type . '?' . $this->modified();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue