2023-10-02 23:10:49 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Lucent\Svelte;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
2023-10-17 22:57:25 +03:00
|
|
|
use Lucent\Account\AccountService;
|
2023-10-02 23:10:49 +03:00
|
|
|
use Lucent\Channel\ChannelService;
|
|
|
|
|
|
|
|
|
|
class Svelte
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2023-10-17 22:57:25 +03:00
|
|
|
public ChannelService $channelService,
|
|
|
|
|
public AccountService $accountService
|
2023-10-02 23:10:49 +03:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function render(string $layout, string $view, string $title = "", mixed $data = []): View|Factory
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$context = [];
|
|
|
|
|
$context["user"] = session('user');
|
|
|
|
|
$context["view"] = $view;
|
|
|
|
|
$context["layout"] = $layout;
|
|
|
|
|
$context["title"] = $title;
|
|
|
|
|
$context["data"] = $data;
|
|
|
|
|
$context["channel"] = $this->channelService->channel;
|
2023-10-17 22:57:25 +03:00
|
|
|
$context["readableSchemas"] = $this->accountService->currentReadableSchemas();
|
2023-10-02 23:10:49 +03:00
|
|
|
$json = json_encode($context);
|
|
|
|
|
|
|
|
|
|
$divTag = sprintf('<div class="lucent-component" data-layout="%s"></div>', $layout);
|
|
|
|
|
$jsonTag = sprintf('<script type="application/json" id="json-%s">%s</script>', $layout, $json);
|
|
|
|
|
|
|
|
|
|
$svelte = $divTag . $jsonTag;
|
|
|
|
|
|
|
|
|
|
return view('lucent::svelte', [
|
|
|
|
|
'svelte' => $svelte,
|
|
|
|
|
'view' => $view,
|
|
|
|
|
'data' => $data,
|
|
|
|
|
'title' => $title,
|
|
|
|
|
'layout' => $layout,
|
|
|
|
|
'channel' => $this->channelService->channel,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|