- First push to add as a composer module
This commit is contained in:
commit
b7cd369c12
2
asset/lean-live/app.js
Normal file
2
asset/lean-live/app.js
Normal file
@ -0,0 +1,2 @@
|
||||
import { UiLive } from "./ui-live.mjs";
|
||||
window.customElements.define("ui-live", UiLive);
|
||||
69
asset/lean-live/ui-live.mjs
Normal file
69
asset/lean-live/ui-live.mjs
Normal file
@ -0,0 +1,69 @@
|
||||
import { Webcomponent } from "../../webcomponent/module/webcomponent.js";
|
||||
import { Hourglass } from "../../webcomponent/hourglass.js";
|
||||
|
||||
const config = {
|
||||
url: window.location.href,
|
||||
template: {
|
||||
fetch : false
|
||||
}
|
||||
};
|
||||
|
||||
class UiLive extends Webcomponent {
|
||||
|
||||
constructor() {
|
||||
super(config);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.pool) {
|
||||
new Hourglass(this.fetchAndRender.bind(this), {
|
||||
timer: this.pool * 1000,
|
||||
start: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fetchAndRender() {
|
||||
this.classList.add("live-loading");
|
||||
|
||||
fetch(this.config.url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'X-Ui-Live': JSON.stringify([ { name: this.name } ])
|
||||
}
|
||||
}).then( response => response.text() )
|
||||
.then(html => {
|
||||
this.swapHtml(html);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
swapHtml(html) {
|
||||
this.innerHTML = ( new DOMParser() )
|
||||
.parseFromString(html, "text/html")
|
||||
.querySelector('ui-live[data-name="' + this.name + '"]')
|
||||
.innerHTML;
|
||||
|
||||
this.dispatchEvent(new CustomEvent("live:swap"));
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
get name() {
|
||||
return this.dataset["name"];
|
||||
}
|
||||
|
||||
/** @return int | undefined */
|
||||
get pool() {
|
||||
if (isNaN(this.dataset['pool'])) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.dataset["pool"];
|
||||
}
|
||||
}
|
||||
|
||||
export { UiLive };
|
||||
41
composer.json
Normal file
41
composer.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "mcnd/lean-live",
|
||||
"description": "Seamless operations between PHP and your users browsers actions.",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Dave Mc Nicoll",
|
||||
"email": "info@mcnd.ca"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.4",
|
||||
"php-di/php-di": "dev-master",
|
||||
"ext-json": "*",
|
||||
"mcnd/lean": "dev-master"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://git.mcnd.ca/mcndave/lean.git"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Lean\\Live\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra" : {
|
||||
"lean" : {
|
||||
"autoload": {
|
||||
"definitions" : [
|
||||
"meta/definitions/software.php"
|
||||
],
|
||||
"config": [
|
||||
"meta/config.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
meta/config.php
Normal file
11
meta/config.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$path = dirname(__DIR__, 1);
|
||||
|
||||
return [
|
||||
'lean' => [
|
||||
'autoload' => [
|
||||
'lean.live',
|
||||
]
|
||||
],
|
||||
];
|
||||
60
meta/definitions/software.php
Normal file
60
meta/definitions/software.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Ulmus\ConnectionAdapter;
|
||||
|
||||
putenv('LEAN_API_PROJECT_PATH=' . $path = dirname(__DIR__, 2));
|
||||
|
||||
return [
|
||||
'lean.api' => [
|
||||
'picea' => [
|
||||
'context' => Lean\Api\View::class,
|
||||
|
||||
'view' => [
|
||||
[
|
||||
'path' => implode(DIRECTORY_SEPARATOR, [ $path , "view", '' ]),
|
||||
'order' => 99,
|
||||
],
|
||||
],
|
||||
|
||||
'asset' => [
|
||||
[
|
||||
'path' => implode(DIRECTORY_SEPARATOR, [ $path, "asset", '' ]),
|
||||
'order' => 10
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'ulmus' => [
|
||||
'entities' => [ 'Lean\\Api\\Entity' => implode(DIRECTORY_SEPARATOR, [ $path, 'src', 'Entity', '' ]) ],
|
||||
'adapters' => [
|
||||
DI\get('lean.api:storage'),
|
||||
]
|
||||
],
|
||||
|
||||
'tell' => [
|
||||
'json' => [
|
||||
[
|
||||
'path' => implode(DIRECTORY_SEPARATOR, [ $path, "meta", "i18n", "" ]),
|
||||
'order' => 99,
|
||||
],
|
||||
]
|
||||
],
|
||||
|
||||
'routes' => [
|
||||
'Lean\\Api\\Controller' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Controller", "" ]),
|
||||
],
|
||||
],
|
||||
|
||||
'lean.api:storage' => function($c) {
|
||||
$adapter = new ConnectionAdapter('lean.api', $c->get('config')['ulmus'], false);
|
||||
$adapter->resolveConfiguration();
|
||||
|
||||
return $adapter;
|
||||
},
|
||||
|
||||
Lean\ApplicationStrategy\NotFoundDecoratorInterface::class => DI\autowire(Lean\Api\ApplicationStrategy\NotFoundDecorator::class),
|
||||
Lean\ApplicationStrategy\MethodNotAllowedInterface::class => DI\autowire(Lean\Api\ApplicationStrategy\MethodNotAllowedDecorator::class),
|
||||
Lean\Api\Factory\MessageFactoryInterface::class => DI\autowire(Lean\Api\Lib\Message::class),
|
||||
Lean\Api\Factory\DebugFormFactoryInterface::class => DI\autowire(Lean\Api\Factory\DebugFormFactory::class),
|
||||
# League\Route\Strategy\ApplicationStrategy::class => DI\autowire(Lean\Api\ApplicationStrategy::class),
|
||||
];
|
||||
Loading…
x
Reference in New Issue
Block a user