Skip to content

Commit

Permalink
optimized view auto includes in backend views
Browse files Browse the repository at this point in the history
minor style fixes
  • Loading branch information
brainfoolong committed Apr 9, 2024
1 parent 4ec2061 commit 61d5a60
Show file tree
Hide file tree
Showing 27 changed files with 295 additions and 244 deletions.
10 changes: 3 additions & 7 deletions appdata/modules/Framelix/public/dist/css/backend.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
html body {
overflow: hidden;
background: var(--color-page-bg);
color: var(--color-page-text);
padding: 0;
margin: 0;
}

html[data-layout="2"] .framelix-page {
Expand Down Expand Up @@ -77,13 +80,6 @@ html[data-screen-size=s] .hide-if-small {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

body {
background: var(--color-page-bg);
color: var(--color-page-text);
padding: 0;
margin: 0;
}

body, button, input, select, textarea {
font-family: var(--font);
font-size: var(--font-size);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79d64af45406d13eb8fcb55912ae86cf
1492af3ba9d2282ee1fe18783023f912
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0878b3aec01599c61b3a335a5964d05
18727f5c82e393e82d0c0777a94f80c8
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3ccc813507678721ee1030a2b5a80581
ae285f0706a71cc171f5f54687bad536
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9171660cc776a30b6104d96e71296d26
14e15c66ceb92ce3abc3c70242470bff
Original file line number Diff line number Diff line change
@@ -1 +1 @@
622c576092625f4df8a92fbdca07fae0
d045cc643c3ea2e5a4456a290c60fea7
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aa4783884f90c84ba9e46bab22272171
5f38e8864afdc6167b8ef707eb3e4492
Original file line number Diff line number Diff line change
@@ -1 +1 @@
814ac77440676797db59d60de2e09c0c
8a2e5aadd79789ece639b48365aad21e
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e562ce162e2ee971b7205894889c8f96
4862de1a6358f7d0fe59bfc8bae1bd1b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b92b3fc8650c529f7129404a1d301317
f12490b241a263994a54f2b130d20e14
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8de3c12e285c5268407b37a7143d12e4
868888d32b71fef47873d2316153e444
Original file line number Diff line number Diff line change
@@ -1 +1 @@
017754582110afccc63973ac8eb98239
ec4b5f68ad9fdb7eefd9a9efbe5dfe9f
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19c82e4ce9ff945fd8c2838e26b19b36
25307b36da19bf44ec72df08537b5ace
11 changes: 3 additions & 8 deletions appdata/modules/Framelix/scss/backend/framelix-backend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
html body {
overflow: hidden;
background: var(--color-page-bg);
color: var(--color-page-text);
padding: 0;
margin: 0;
}

html[data-layout='2'] .framelix-page {
Expand Down Expand Up @@ -58,13 +61,6 @@ html[data-screen-size='s'] {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

body {
background: var(--color-page-bg);
color: var(--color-page-text);
padding: 0;
margin: 0;
}

body, button, input, select, textarea {
font-family: var(--font);
font-size: var(--font-size);
Expand Down Expand Up @@ -289,7 +285,6 @@ html.dragging [data-tooltip] {
}



h1, h2, h3, h4, h5, h6 {
padding: 0;
margin: 0 0 10px;
Expand Down
1 change: 0 additions & 1 deletion appdata/modules/Framelix/scss/general/framelix-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
.framelix-modal-body {
flex: 1 1 auto;
overflow: auto;
// a little padding top and bottom to fix hidden styles that has outline
padding: 5px;
}

Expand Down
49 changes: 42 additions & 7 deletions appdata/modules/Framelix/src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use JetBrains\PhpStorm\ExpectedValues;
use SensitiveParameter;

use function call_user_func_array;
use function file_exists;
use function is_file;
use function set_time_limit;

use const FRAMELIX_MODULE;
Expand Down Expand Up @@ -306,6 +308,15 @@ class Config
*/
public static function onRegister(): void
{
$matchFilterEarly = function (View $view, string $position) {
return $view instanceof \Framelix\Framelix\View\Backend\View && $position === 'early';
};
$matchFilterDefault = function (View $view, string $position) {
return $view instanceof \Framelix\Framelix\View\Backend\View && $position === 'default';
};
$matchFilterLate = function (View $view, string $position) {
return $view instanceof \Framelix\Framelix\View\Backend\View && $position === 'late';
};
// add a default salt, after application is set up, this default salt must be replaced
// app requires any salt to be functional, even during setup
self::addSalt('none');
Expand All @@ -318,7 +329,7 @@ public static function onRegister(): void
self::addAvailableUserRole('usermanagement', '__framelix_edituser_sidebar_title__');

$bundle = self::createCompilerFileBundle("Framelix", "js", "general-vendor-native");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->compile = false;
$bundle->addFile('node_modules/cash-dom/dist/cash.min.js');
$bundle->addFile('js/cashjs/cash-improvements.js');
Expand All @@ -331,7 +342,7 @@ public static function onRegister(): void
$bundle->addFile('node_modules/swiped-events/dist/swiped-events.min.js');

$bundle = self::createCompilerFileBundle("Framelix", "js", "form");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFile('js/form/framelix-form.js');
$bundle->addFile('js/form/framelix-form-field.js');
$bundle->addFile('js/form/framelix-form-field-text.js');
Expand All @@ -348,37 +359,39 @@ public static function onRegister(): void
$bundle->addFolder('vendor/qrcodejs', true);

$bundle = self::createCompilerFileBundle("Framelix", "js", "general-early");
$bundle->matchFilter = $matchFilterEarly;
$bundle->addFile('js/framelix-local-storage.js');
$bundle->addFile('js/framelix-session-storage.js');
$bundle->addFile('js/framelix-device-detection.js');

$bundle = self::createCompilerFileBundle("Framelix", "js", "general-late");
$bundle->matchFilter = $matchFilterLate;
$bundle->addFile('custom-elements/framelix-custom-element.js');
$bundle->addFolder('custom-elements', true);

$bundle = self::createCompilerFileBundle("Framelix", "js", "general");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFolder('js', false, Config::$compilerFileBundles);
$bundle->addFolder('public/dist/typedefs', false);

$bundle = self::createCompilerFileBundle("Framelix", "js", "table-sorter-serviceworker");
$bundle->addFile('js/framelix-table-sort-serviceworker.js');

$bundle = self::createCompilerFileBundle("Framelix", "js", "backend");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFolder('js/backend', true);

$bundle = self::createCompilerFileBundle("Framelix", "scss", "general");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFolder('scss/general', false);
$bundle->addFolder('custom-elements', true);

$bundle = self::createCompilerFileBundle("Framelix", "scss", "form");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFolder('scss/form', true);

$bundle = self::createCompilerFileBundle("Framelix", "scss", "backend");
$bundle->includeInBackendView = \Framelix\Framelix\View\Backend\View::class;
$bundle->matchFilter = $matchFilterDefault;
$bundle->addFolder('scss/backend', true);

// register the other module
Expand Down Expand Up @@ -545,6 +558,28 @@ public static function createCompilerFileBundle(
return $bundle;
}

/**
* @param View $view
* @param string $position
* @return array
*/
public static function getMatchingCompilerFileBundles(
View $view,
#[ExpectedValues(values: ['early', 'default', 'late'])] string $position
): array {
$arr = [];
foreach (Config::$compilerFileBundles as $bundle) {
$file = $bundle->getGeneratedBundleFilePath();
if (!is_file($file) || !$bundle->matchFilter) {
continue;
}
if (call_user_func_array($bundle->matchFilter, [$view, $position]) === true) {
$arr[] = $bundle;
}
}
return $arr;
}

/**
* Get existing (previously created) compiler file bundle
* @param string $module Framelix module name
Expand Down
17 changes: 9 additions & 8 deletions appdata/modules/Framelix/src/Html/CompilerFileBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Framelix\Framelix\Html;

use Closure;
use Framelix\Framelix\Exception\FatalError;
use Framelix\Framelix\Url;
use Framelix\Framelix\Utils\FileUtils;
Expand All @@ -12,13 +13,12 @@

class CompilerFileBundle
{

/**
* Automatically include into backend views that inherit from given view class
* If null you need to add it by hand with HtmlUtils::getIncludeTagForBundle
* @var string|null
* If this isset, Config::getMatchingCompilerFileBundles will return only if this match filter returns true
* If not set, it will never be returned
* @var Closure|null
*/
public ?string $includeInBackendView = null;
public ?Closure $matchFilter = null;

/**
* Compile the bundle with babel/sass
Expand All @@ -43,7 +43,8 @@ public function __construct(
public string $module,
#[ExpectedValues(['js', 'scss'])] public string $type,
public string $bundleId
) {}
) {
}

public function getGeneratedBundleFilePath(): string
{
Expand All @@ -64,7 +65,7 @@ public function getGeneratedBundleUrl(): Url
* Add a folder with all files in it, relative from the bundles module folder
* @param string $relativeFolderPath
* @param bool $recursive
* @param \Framelix\Framelix\Html\CompilerFileBundle[]|\Framelix\Framelix\Html\CompilerFileBundle|null $ignoreFilesFromBundles Ignores
* @param CompilerFileBundle[]|CompilerFileBundle|null $ignoreFilesFromBundles Ignores
* all files from given bundles
* @return void
*/
Expand All @@ -75,7 +76,7 @@ public function addFolder(
): void {
$ignoredFiles = [];
if ($ignoreFilesFromBundles) {
/** @var \Framelix\Framelix\Html\CompilerFileBundle[] $arr */
/** @var CompilerFileBundle[] $arr */
$arr = !is_array($ignoreFilesFromBundles) ? [$ignoreFilesFromBundles] : $ignoreFilesFromBundles;
foreach ($arr as $ignoredBundle) {
if ($ignoredBundle !== $this && $ignoredBundle instanceof CompilerFileBundle) {
Expand Down
Loading

0 comments on commit 61d5a60

Please sign in to comment.