Repository navigation
Expand file tree
/
Copy pathWireTableServiceProvider.php
More file actions
165 lines (152 loc) · 7.63 KB
/
Copy pathWireTableServiceProvider.php
File metadata and controls
165 lines (152 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
declare(strict_types=1);
namespace NyonCode\WireTable;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Livewire\LivewireManager;
use NyonCode\LaravelPackageToolkit\Commands\InstallCommand;
use NyonCode\LaravelPackageToolkit\Packager;
use NyonCode\LaravelPackageToolkit\PackageServiceProvider;
use NyonCode\WireCore\Actions\Action;
use NyonCode\WireCore\Foundation\Assets\Bundle;
use NyonCode\WireCore\Foundation\Icons\IconManager;
use NyonCode\WireTable\Columns\Console\MakeColumnCommand;
use NyonCode\WireTable\Filters\Console\MakeFilterCommand;
use NyonCode\WireTable\Livewire\TableStateSynthesizer;
use NyonCode\WireTable\Support\ClientViewport;
use NyonCode\WireTable\Support\Icons\TableIconSet;
use NyonCode\WireTable\Support\RecordAction;
use NyonCode\WireTable\Testing\TableTestingMacros;
class WireTableServiceProvider extends PackageServiceProvider
{
/** Absolute path to the pre-bundled, self-registering table assets. */
public const ASSETS_PATH = __DIR__.'/../dist';
/**
* Configure the package.
*
* @throws \Exception
*/
public function configure(Packager $packager): void
{
$packager
->name('WireTable')
->hasShortName('wire-table')
->bootedPackage(function ($packager) {
// The manager, not `app(HandleComponents::class)`: Livewire 4 moved
// the synthesizer registry out of that mechanism into
// `HandleSynths::registerSynth()`, and `registerPropertySynthesizer()`
// no longer exists there. `propertySynthesizer()` is the supported
// seam and forwards to the right owner in both 3.x and 4.x. Resolved
// from the container rather than through the `Livewire` facade
// because the facade's `@method` list does not carry it — same
// pattern as core's CurrentComponentDriver.
app(LivewireManager::class)->propertySynthesizer(TableStateSynthesizer::class);
$this->registerRecordActionMacros();
// Test helpers on Livewire::test() — a no-op where Livewire's
// testing layer is not loaded.
TableTestingMacros::register();
// The browser writes this one (wire-table-viewport.js), so it
// carries no signature to decrypt — encrypted, Laravel would
// read every value as null and no table would ever trim.
EncryptCookies::except(ClientViewport::COOKIE);
Bundle::serve('wire-table', self::ASSETS_PATH);
// The marks inside the hand-drawn selection checkbox, as
// `table:checkbox-check` and `table:checkbox-indeterminate`.
// Registering the set costs nothing until one is asked for —
// the bodies load on first use — and it is what keeps the
// selection cell free of inline <svg> (AI_CODING_STANDARD.md,
// Rendering § Icons).
app(IconManager::class)->registerIconSet(new TableIconSet, 'table');
})
->hasConfig()
->hasViews()
// The custom-component generators and their templates, publishable
// with `vendor:publish --tag=wire-table::stubs`; a published copy wins
// (Foundation\Console\Support\PublishedStubs says where it is looked for).
->hasCommand(MakeColumnCommand::class)
->hasCommand(MakeFilterCommand::class)
->hasStubs([
'../stubs/column.stub',
'../stubs/column-view.stub',
'../stubs/filter.stub',
'../stubs/filter-view.stub',
])
->hasAssets('dist', entries: [
Bundle::make('wire-table-records.js'),
Bundle::make('wire-table-selection.js'),
Bundle::make('wire-table-live.js'),
// The Excel-style fill handle. It lived in `wire-core-dropdown.js`
// until ADR 0025 § step 10: every wire-core consumer shipped 9 KB of
// a gesture only a table can trigger. It ships with the rest rather
// than on request — ADR 0024 forbids delivering an interaction
// registrar late, and `x-data="wireFillHandle()"` is in the rendered
// row region, not behind a click.
Bundle::make('wire-table-fill.js'),
// Writes the `wire_viewport` cookie a stacked table trims to.
Bundle::make('wire-table-viewport.js'),
// Moves a page-pinned `<thead>` with the page scroll.
Bundle::make('wire-table-sticky.js'),
// Column widths the user drags, and the offsets of pinned columns.
Bundle::make('wire-table-columns.js'),
])
->hasAssetFallback(Bundle::servedByRoute('wire-table'))
// No `hasMigrations()`: this package has no tables of its own any
// more. `table_preferences` was the only one, and it moved to
// wire-core as `wire_preferences` when the per-user store came down
// to where a dashboard could reach it too. Left declared, the tag
// survived over an empty directory and answered a publish with "No
// publishable resources" — which reads as a broken install rather
// than as a thing that moved.
->hasTranslations()
->hasAbout()
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfig()
// No migrations to publish; see `hasMigrations()` above.
// The per-user preference table is wire-core's now, and an
// install that offered to publish nothing would be offering
// the user a decision with no consequence.
->publishViews()
->publishTranslations();
});
}
/**
* Register the fluent record-action triggers on `Action` so a row action can
* be declared as `Action::make('edit')->onDoubleClick()`.
*
* The macros only promote the action into a table-owned {@see RecordAction};
* no trigger state lives on the shared `Action`, and `wire-core` need not know
* the table exists. Registered here — the package's cross-package extension
* seam — rather than in the core Action class.
*/
protected function registerRecordActionMacros(): void
{
foreach (['onClick', 'onDoubleClick', 'onContextMenu'] as $trigger) {
Action::macro($trigger, function () use ($trigger): RecordAction {
/** @var Action $this */
return RecordAction::make($this)->{$trigger}();
});
}
Action::macro('onKey', function (string $key): RecordAction {
/** @var Action $this */
return RecordAction::make($this)->onKey($key);
});
Action::macro('on', function (string $type): RecordAction {
/** @var Action $this */
return RecordAction::make($this)->on($type);
});
}
/**
* Extra rows for this package's `php artisan about` section (the toolkit
* already prepends "Version"). Values are closures so config resolves at
* boot, not at declaration time.
*
* @return array<string, string|\Closure>
*/
public function aboutData(): array
{
return [
'Per page' => fn (): string => (string) config('wire-table.defaults.per_page', 10),
'Preferences' => fn (): string => (string) config('wire-table.preferences.default', 'null'),
];
}
}