@nckrtl/launch-ui 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{i18n-plugin-D--fPPUj.mjs → i18n-plugin-6AdekIa0.mjs} +7 -7
- package/dist/index.d.mts +24 -14
- package/dist/index.mjs +134 -37
- package/package.json +6 -8
- package/dist/agentation-plugin.d.mts +0 -18
- package/dist/agentation-plugin.mjs +0 -125
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @nckrtl/launch-ui
|
|
2
2
|
|
|
3
|
-
React component library and Vite toolchain for building Laravel + React + Inertia applications. Built on Base UI and shadcn
|
|
3
|
+
React component library and Vite toolchain for building Laravel + React + Inertia applications. Built on Base UI and shadcn.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -20,6 +20,6 @@ export default defineLaunchConfig();
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- **Vite Integration**: Zero-config Vite setups for Laravel + React + Inertia projects via `defineLaunchConfig()`.
|
|
23
|
+
- **PHP Reload**: On the dev server, PHP changes refresh Inertia props with `router.reload()` instead of reloading the page. Blade views still reload. Turn it off with `phpReload: false`.
|
|
23
24
|
- **i18n Support**: Simple translation helpers available via `@nckrtl/launch-ui/i18n`.
|
|
24
|
-
- **Agentation**: Integrated UI feedback toolbar integration via `@nckrtl/launch-ui/agentation`.
|
|
25
25
|
- **Legacy Fallback**: Backwards-compatible aliases for `@nckrtl/craft-ui-react/*` and `defineCraftConfig`.
|
|
@@ -25,7 +25,7 @@ export function initI18n(options) {
|
|
|
25
25
|
locale = options.locale ?? "en";
|
|
26
26
|
fallbackLocale = options.fallbackLocale ?? "en";
|
|
27
27
|
for (const [path, mod] of Object.entries(options.files)) {
|
|
28
|
-
const match = path.match(/\\/([a-z]{2}(?:[-_][a-zA-Z]+)?)
|
|
28
|
+
const match = path.match(/\\/([a-z]{2}(?:[-_][a-zA-Z]+)?)\\.json$/);
|
|
29
29
|
if (!match) continue;
|
|
30
30
|
const lang = match[1].replace("-", "_");
|
|
31
31
|
const translations = "default" in mod ? mod.default : mod;
|
|
@@ -73,15 +73,15 @@ export function __(key, replacements) {
|
|
|
73
73
|
*/
|
|
74
74
|
function launchI18nPlugin(i18n) {
|
|
75
75
|
const opts = typeof i18n === "object" ? i18n : {};
|
|
76
|
-
opts.locale;
|
|
77
|
-
opts.fallbackLocale;
|
|
78
|
-
opts.langPath;
|
|
76
|
+
const locale = opts.locale ?? "en";
|
|
77
|
+
const fallbackLocale = opts.fallbackLocale ?? "en";
|
|
78
|
+
const langPath = opts.langPath ?? "/lang/*.json";
|
|
79
79
|
const initCode = `
|
|
80
80
|
import { initI18n } from "virtual:launch-i18n";
|
|
81
81
|
initI18n({
|
|
82
|
-
locale:
|
|
83
|
-
fallbackLocale:
|
|
84
|
-
files: import.meta.glob(
|
|
82
|
+
locale: ${JSON.stringify(locale)},
|
|
83
|
+
fallbackLocale: ${JSON.stringify(fallbackLocale)},
|
|
84
|
+
files: import.meta.glob(${JSON.stringify(langPath)}, { eager: true }),
|
|
85
85
|
});
|
|
86
86
|
`;
|
|
87
87
|
return {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PluginOption, UserConfig } from "vite-plus";
|
|
2
|
-
|
|
3
2
|
//#region src/vite/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Options for defineLaunchConfig
|
|
@@ -11,8 +10,10 @@ interface LaunchConfigOptions {
|
|
|
11
10
|
/** Laravel Vite plugin options */
|
|
12
11
|
laravel?: {
|
|
13
12
|
input?: string[];
|
|
14
|
-
|
|
13
|
+
/** Files that reload the page. Defaults to `resources/views/**` when `phpReload` is on. */
|
|
14
|
+
refresh?: boolean | string | string[];
|
|
15
15
|
ssr?: string;
|
|
16
|
+
detectTls?: string | boolean;
|
|
16
17
|
};
|
|
17
18
|
/** @inertiajs/vite plugin options, or `false` to disable */
|
|
18
19
|
inertia?: false | {
|
|
@@ -31,22 +32,24 @@ interface LaunchConfigOptions {
|
|
|
31
32
|
wayfinder?: false | {
|
|
32
33
|
formVariants?: boolean;
|
|
33
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Refresh Inertia props when a PHP file changes, instead of reloading the page.
|
|
37
|
+
* Applies to the dev server when Inertia is enabled. Blade files still reload the page.
|
|
38
|
+
* Default: true.
|
|
39
|
+
*/
|
|
40
|
+
phpReload?: boolean;
|
|
34
41
|
/**
|
|
35
42
|
* Enable i18n support. When true, injects initI18n() into app entry.
|
|
36
43
|
* The __ function becomes available via: import { __ } from '@nckrtl/launch-ui/i18n'
|
|
37
44
|
*/
|
|
38
45
|
i18n?: boolean | {
|
|
39
|
-
/** Active locale (default: "en") */
|
|
40
|
-
|
|
46
|
+
/** Active locale (default: "en") */
|
|
47
|
+
locale?: string;
|
|
48
|
+
/** Fallback locale (default: "en") */
|
|
49
|
+
fallbackLocale?: string;
|
|
50
|
+
/** Glob pattern for lang files (default: "/lang/*.json") */
|
|
41
51
|
langPath?: string;
|
|
42
52
|
};
|
|
43
|
-
/**
|
|
44
|
-
* Agentation integration (enabled by default). Auto-mounts the Agentation
|
|
45
|
-
* component in dev mode with annotation count tracking for the toolbar.
|
|
46
|
-
* Requires `agentation` npm package as a dev dependency.
|
|
47
|
-
* Set to `false` to disable.
|
|
48
|
-
*/
|
|
49
|
-
agentation?: boolean;
|
|
50
53
|
/** Additional Vite plugins to include */
|
|
51
54
|
plugins?: PluginOption[];
|
|
52
55
|
/** VitePlus lint options — passed through to defineConfig */
|
|
@@ -56,10 +59,14 @@ interface LaunchConfigOptions {
|
|
|
56
59
|
typeCheck?: boolean;
|
|
57
60
|
};
|
|
58
61
|
};
|
|
62
|
+
/** Formatting options, including an override for the default .agents exclusion. */
|
|
63
|
+
fmt?: {
|
|
64
|
+
ignorePatterns?: string[];
|
|
65
|
+
};
|
|
59
66
|
/**
|
|
60
67
|
* VitePlus staged command map for pre-commit hooks. Keys are glob patterns,
|
|
61
68
|
* values are the shell command to run on matching staged files. Defaults
|
|
62
|
-
* to
|
|
69
|
+
* to VitePlus formatting plus Pint for PHP files — override to customize.
|
|
63
70
|
*/
|
|
64
71
|
staged?: Record<string, string>;
|
|
65
72
|
}
|
|
@@ -68,11 +75,14 @@ interface LaunchConfigOptions {
|
|
|
68
75
|
*/
|
|
69
76
|
type CraftConfigOptions = LaunchConfigOptions;
|
|
70
77
|
//#endregion
|
|
78
|
+
//#region src/vite/environment.d.ts
|
|
79
|
+
type Environment = Record<string, string | undefined>;
|
|
80
|
+
//#endregion
|
|
71
81
|
//#region src/vite/plugins.d.ts
|
|
72
82
|
/**
|
|
73
83
|
* Assemble all Vite plugins for the Launch React stack
|
|
74
84
|
*/
|
|
75
|
-
declare function getPlugins(options: LaunchConfigOptions): Promise<PluginOption[]>;
|
|
85
|
+
declare function getPlugins(options: LaunchConfigOptions, env?: Environment): Promise<PluginOption[]>;
|
|
76
86
|
//#endregion
|
|
77
87
|
//#region src/vite/index.d.ts
|
|
78
88
|
/**
|
|
@@ -85,7 +95,7 @@ declare function getPlugins(options: LaunchConfigOptions): Promise<PluginOption[
|
|
|
85
95
|
* import { defineLaunchConfig } from '@nckrtl/launch-ui/vite';
|
|
86
96
|
* export default defineLaunchConfig();
|
|
87
97
|
*/
|
|
88
|
-
declare function defineLaunchConfig(options?: LaunchConfigOptions): Promise<(env: import("vite").ConfigEnv) => UserConfig
|
|
98
|
+
declare function defineLaunchConfig(options?: LaunchConfigOptions): Promise<(env: import("vite").ConfigEnv) => Promise<UserConfig>>;
|
|
89
99
|
/**
|
|
90
100
|
* @deprecated Use `defineLaunchConfig` instead.
|
|
91
101
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,76 @@
|
|
|
1
|
-
import { defineConfig } from "vite-plus";
|
|
1
|
+
import { defineConfig, isCSSRequest, loadEnv } from "vite-plus";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
//#region src/vite/environment.ts
|
|
6
|
+
function orbitDevServerUrl(env) {
|
|
7
|
+
const origin = env.ORBIT_DEV_SERVER_ORIGIN;
|
|
8
|
+
if (!origin) return null;
|
|
9
|
+
const url = new URL(origin);
|
|
10
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("ORBIT_DEV_SERVER_ORIGIN must be an HTTP or HTTPS URL.");
|
|
11
|
+
return url;
|
|
12
|
+
}
|
|
13
|
+
function inertiaOptions(options, env) {
|
|
14
|
+
if (options === false || options?.ssr === false) return options === false ? void 0 : options;
|
|
15
|
+
if (options?.ssr?.port !== void 0 || !env.INERTIA_SSR_PORT) return options;
|
|
16
|
+
const port = Number(env.INERTIA_SSR_PORT);
|
|
17
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("INERTIA_SSR_PORT must be an integer between 1 and 65535.");
|
|
18
|
+
return {
|
|
19
|
+
...options,
|
|
20
|
+
ssr: {
|
|
21
|
+
...options?.ssr,
|
|
22
|
+
port
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/vite/php-reload-plugin.ts
|
|
28
|
+
const EVENT = "launch:php-update";
|
|
29
|
+
const CLIENT_CODE = `
|
|
30
|
+
import { router as __launchRouter } from "@inertiajs/react";
|
|
31
|
+
|
|
32
|
+
if (import.meta.hot) {
|
|
33
|
+
let __launchReloadTimer;
|
|
34
|
+
import.meta.hot.on(${JSON.stringify(EVENT)}, () => {
|
|
35
|
+
clearTimeout(__launchReloadTimer);
|
|
36
|
+
__launchReloadTimer = setTimeout(() => __launchRouter.reload(), 50);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
/**
|
|
41
|
+
* Vite plugin that refreshes Inertia props when PHP changes, instead of reloading the page.
|
|
42
|
+
*
|
|
43
|
+
* Tailwind scans PHP files for classes and sends a full reload when one changes. This plugin
|
|
44
|
+
* runs first: it keeps the Tailwind CSS update, drops the full reload, and tells the browser
|
|
45
|
+
* to call `router.reload()`, which keeps scroll position and component state.
|
|
46
|
+
*
|
|
47
|
+
* Blade files still reload the page, because the root view is outside Inertia's props.
|
|
48
|
+
*/
|
|
49
|
+
function launchPhpReloadPlugin(entries) {
|
|
50
|
+
const entryPaths = entries.map((entry) => `/${entry.replace(/^\.?\//, "")}`);
|
|
51
|
+
return {
|
|
52
|
+
name: "launch:php-reload",
|
|
53
|
+
apply: "serve",
|
|
54
|
+
enforce: "pre",
|
|
55
|
+
transform(code, id) {
|
|
56
|
+
if (!entryPaths.some((entry) => id.endsWith(entry)) || isCSSRequest(id)) return null;
|
|
57
|
+
return {
|
|
58
|
+
code: code + CLIENT_CODE,
|
|
59
|
+
map: null
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
hotUpdate({ file, modules }) {
|
|
63
|
+
if (!file.endsWith(".php") || file.endsWith(".blade.php")) return;
|
|
64
|
+
if (this.environment.name === "client") this.environment.hot.send({
|
|
65
|
+
type: "custom",
|
|
66
|
+
event: EVENT,
|
|
67
|
+
data: { file }
|
|
68
|
+
});
|
|
69
|
+
return modules.flatMap((module) => [...module.importers].filter((importer) => importer.id && isCSSRequest(importer.id)));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
5
74
|
//#region src/vite/plugins.ts
|
|
6
75
|
/**
|
|
7
76
|
* Import a package from the consumer project's node_modules.
|
|
@@ -15,37 +84,42 @@ async function importFromConsumer(pkg) {
|
|
|
15
84
|
const subpath = parts.slice(1).join("/");
|
|
16
85
|
if (subpath) {
|
|
17
86
|
const filePath = join(nodeModules, pkgName, subpath);
|
|
18
|
-
|
|
87
|
+
const resolved = existsSync(filePath) ? filePath : `${filePath}.js`;
|
|
88
|
+
return import(pathToFileURL(resolved).href);
|
|
19
89
|
}
|
|
20
90
|
const pkgDir = join(nodeModules, pkgName);
|
|
21
91
|
const pkgJson = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8"));
|
|
22
92
|
const exports = pkgJson.exports?.["."];
|
|
23
|
-
|
|
93
|
+
const entry = (typeof exports === "string" ? exports : exports?.import ?? exports?.default) ?? pkgJson.module ?? pkgJson.main ?? "index.js";
|
|
94
|
+
return import(pathToFileURL(join(pkgDir, entry)).href);
|
|
24
95
|
}
|
|
25
96
|
/**
|
|
26
97
|
* Assemble all Vite plugins for the Launch React stack
|
|
27
98
|
*/
|
|
28
|
-
async function getPlugins(options) {
|
|
99
|
+
async function getPlugins(options, env = process.env) {
|
|
29
100
|
const [{ default: laravel }, { default: react }, { default: tailwindcss }] = await Promise.all([
|
|
30
101
|
importFromConsumer("laravel-vite-plugin"),
|
|
31
102
|
importFromConsumer("@vitejs/plugin-react"),
|
|
32
103
|
importFromConsumer("@tailwindcss/vite")
|
|
33
104
|
]);
|
|
34
|
-
const
|
|
105
|
+
const orbitUrl = orbitDevServerUrl(env);
|
|
106
|
+
const input = options.laravel?.input ?? ["resources/js/app.tsx"];
|
|
107
|
+
const phpReload = options.inertia !== false && options.phpReload !== false;
|
|
35
108
|
const plugins = [
|
|
36
109
|
launchAliasPlugin(),
|
|
110
|
+
...phpReload ? [launchPhpReloadPlugin(input)] : [],
|
|
37
111
|
laravel({
|
|
38
|
-
input
|
|
112
|
+
input,
|
|
39
113
|
ssr: options.laravel?.ssr,
|
|
40
|
-
refresh: options.laravel?.refresh ?? true,
|
|
41
|
-
|
|
114
|
+
refresh: options.laravel?.refresh ?? (phpReload ? ["resources/views/**"] : true),
|
|
115
|
+
detectTls: options.laravel?.detectTls ?? (orbitUrl ? false : void 0)
|
|
42
116
|
}),
|
|
43
117
|
react(options.react),
|
|
44
118
|
tailwindcss()
|
|
45
119
|
];
|
|
46
120
|
if (options.inertia !== false) {
|
|
47
121
|
const { default: inertia } = await importFromConsumer("@inertiajs/vite");
|
|
48
|
-
plugins.push(inertia(
|
|
122
|
+
plugins.push(inertia(inertiaOptions(options.inertia, env)));
|
|
49
123
|
}
|
|
50
124
|
if (options.wayfinder !== false) {
|
|
51
125
|
const { wayfinder } = await importFromConsumer("@laravel/vite-plugin-wayfinder");
|
|
@@ -56,14 +130,10 @@ async function getPlugins(options) {
|
|
|
56
130
|
}));
|
|
57
131
|
}
|
|
58
132
|
if (options.i18n) {
|
|
59
|
-
const { launchI18nPlugin } = await import("./i18n-plugin-
|
|
133
|
+
const { launchI18nPlugin } = await import("./i18n-plugin-6AdekIa0.mjs");
|
|
60
134
|
plugins.push(launchI18nPlugin(options.i18n));
|
|
61
135
|
}
|
|
62
|
-
|
|
63
|
-
const { launchAgentationPlugin } = await import("./agentation-plugin.mjs");
|
|
64
|
-
plugins.push(launchAgentationPlugin());
|
|
65
|
-
}
|
|
66
|
-
plugins.push(launchPublicDevServerUrlPlugin());
|
|
136
|
+
plugins.push(launchPublicDevServerUrlPlugin(env));
|
|
67
137
|
const runners = await getArtisanRunners();
|
|
68
138
|
if (runners) plugins.push(runners);
|
|
69
139
|
if (options.plugins) plugins.push(...options.plugins);
|
|
@@ -82,10 +152,6 @@ function launchAliasPlugin() {
|
|
|
82
152
|
find: /^@nckrtl\/craft-ui-react\/i18n$/,
|
|
83
153
|
replacement: "@nckrtl/launch-ui/i18n"
|
|
84
154
|
},
|
|
85
|
-
{
|
|
86
|
-
find: /^@nckrtl\/craft-ui-react\/agentation$/,
|
|
87
|
-
replacement: "@nckrtl/launch-ui/agentation"
|
|
88
|
-
},
|
|
89
155
|
{
|
|
90
156
|
find: /^@nckrtl\/craft-ui-react\/(.*)$/,
|
|
91
157
|
replacement: "@nckrtl/launch-ui/$1"
|
|
@@ -94,13 +160,33 @@ function launchAliasPlugin() {
|
|
|
94
160
|
}
|
|
95
161
|
};
|
|
96
162
|
}
|
|
97
|
-
function launchPublicDevServerUrlPlugin() {
|
|
163
|
+
function launchPublicDevServerUrlPlugin(env) {
|
|
164
|
+
const orbitUrl = orbitDevServerUrl(env);
|
|
98
165
|
return {
|
|
99
166
|
name: "launch:public-dev-server-url",
|
|
100
167
|
apply: "serve",
|
|
168
|
+
config(config) {
|
|
169
|
+
const publicUrl = orbitUrl ?? getPublicDevServerOrigin(env);
|
|
170
|
+
if (!publicUrl) return;
|
|
171
|
+
return {
|
|
172
|
+
...orbitUrl ? { base: config.base ?? `${orbitUrl.pathname.replace(/\/$/, "")}/` } : {},
|
|
173
|
+
server: {
|
|
174
|
+
...orbitUrl ? { origin: config.server?.origin ?? orbitUrl.origin } : {},
|
|
175
|
+
ws: config.server?.ws === false || config.server?.hmr === false ? false : {
|
|
176
|
+
host: publicUrl.hostname,
|
|
177
|
+
...orbitUrl ? {
|
|
178
|
+
protocol: orbitUrl.protocol === "https:" ? "wss" : "ws",
|
|
179
|
+
clientPort: Number(orbitUrl.port || (orbitUrl.protocol === "https:" ? 443 : 80)),
|
|
180
|
+
path: "hmr"
|
|
181
|
+
} : {},
|
|
182
|
+
...typeof config.server?.ws === "object" ? config.server.ws : {}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
},
|
|
101
187
|
configureServer(server) {
|
|
102
188
|
server.httpServer?.once("listening", () => {
|
|
103
|
-
const preferredUrl = getPublicDevServerUrl(server);
|
|
189
|
+
const preferredUrl = orbitUrl ? `${server.config.server.origin}${server.config.base}` : getPublicDevServerUrl(server);
|
|
104
190
|
if (!preferredUrl || !server.resolvedUrls) return;
|
|
105
191
|
server.resolvedUrls.local = preferUrl(server.resolvedUrls.local, preferredUrl);
|
|
106
192
|
});
|
|
@@ -108,18 +194,22 @@ function launchPublicDevServerUrlPlugin() {
|
|
|
108
194
|
};
|
|
109
195
|
}
|
|
110
196
|
function getPublicDevServerUrl(server) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
197
|
+
const url = getPublicDevServerOrigin(server.config.env);
|
|
198
|
+
if (!url) return null;
|
|
199
|
+
const address = server.httpServer?.address();
|
|
200
|
+
const port = address && typeof address !== "string" ? address.port : server.config.server.port;
|
|
201
|
+
if (port) url.port = String(port);
|
|
202
|
+
url.pathname = "/";
|
|
203
|
+
url.search = "";
|
|
204
|
+
url.hash = "";
|
|
205
|
+
return url.toString();
|
|
206
|
+
}
|
|
207
|
+
function getPublicDevServerOrigin(env) {
|
|
208
|
+
const rawOrigin = env.VITE_DEV_SERVER_ORIGIN ?? env.VITE_APP_URL ?? env.APP_URL;
|
|
209
|
+
if (!rawOrigin) return null;
|
|
113
210
|
try {
|
|
114
211
|
const url = new URL(rawOrigin);
|
|
115
|
-
|
|
116
|
-
const address = server.httpServer?.address();
|
|
117
|
-
const port = address && typeof address !== "string" ? address.port : server.config.server.port;
|
|
118
|
-
if (port) url.port = String(port);
|
|
119
|
-
url.pathname = "/";
|
|
120
|
-
url.search = "";
|
|
121
|
-
url.hash = "";
|
|
122
|
-
return url.toString();
|
|
212
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url : null;
|
|
123
213
|
} catch {
|
|
124
214
|
return null;
|
|
125
215
|
}
|
|
@@ -172,13 +262,20 @@ async function getArtisanRunners() {
|
|
|
172
262
|
* export default defineLaunchConfig();
|
|
173
263
|
*/
|
|
174
264
|
async function defineLaunchConfig(options = {}) {
|
|
175
|
-
const { lint, staged, ...launchOptions } = options;
|
|
176
|
-
|
|
177
|
-
return defineConfig(() => ({
|
|
265
|
+
const { lint, fmt, staged, ...launchOptions } = options;
|
|
266
|
+
return defineConfig(async ({ mode }) => ({
|
|
178
267
|
...lint ? { lint } : {},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
268
|
+
fmt: fmt ?? { ignorePatterns: [".agents/**"] },
|
|
269
|
+
staged: staged ?? {
|
|
270
|
+
"*": "vp check --fix",
|
|
271
|
+
"*.php": "vendor/bin/pint"
|
|
272
|
+
},
|
|
273
|
+
plugins: await getPlugins(launchOptions, loadEnv(mode, process.cwd(), "")),
|
|
274
|
+
server: { watch: { ignored: [
|
|
275
|
+
"**/vendor/**",
|
|
276
|
+
"**/storage/**",
|
|
277
|
+
"**/bootstrap/cache/**"
|
|
278
|
+
] } }
|
|
182
279
|
}));
|
|
183
280
|
}
|
|
184
281
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nckrtl/launch-ui",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A React component library and Vite toolchain for building Laravel + React + Inertia apps. Built on Base UI and shadcn
|
|
3
|
+
"version": "0.0.28",
|
|
4
|
+
"description": "A React component library and Vite toolchain for building Laravel + React + Inertia apps. Built on Base UI and shadcn.",
|
|
5
5
|
"author": "nckrtl <nick.retel@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/nckrtl/launch-ui#readme",
|
|
@@ -24,16 +24,13 @@
|
|
|
24
24
|
"./vite": {
|
|
25
25
|
"types": "./dist/index.d.mts",
|
|
26
26
|
"default": "./dist/index.mjs"
|
|
27
|
-
},
|
|
28
|
-
"./agentation": {
|
|
29
|
-
"types": "./dist/agentation-plugin.d.mts",
|
|
30
|
-
"default": "./dist/agentation-plugin.mjs"
|
|
31
27
|
}
|
|
32
28
|
},
|
|
33
29
|
"scripts": {
|
|
30
|
+
"test": "node --test tests/*.test.ts && vp test src/vite/config.test.ts",
|
|
34
31
|
"dev": "storybook dev -p 6006",
|
|
35
32
|
"build": "shadcn build",
|
|
36
|
-
"build:lib": "vp pack src/vite/index.ts
|
|
33
|
+
"build:lib": "vp pack src/vite/index.ts --dts --format esm --out-dir dist",
|
|
37
34
|
"build:storybook": "storybook build && rsync -a storybook-static/ public/",
|
|
38
35
|
"serve": "npx http-server public -p 4100 -c-1 --cors"
|
|
39
36
|
},
|
|
@@ -44,6 +41,7 @@
|
|
|
44
41
|
"@storybook/addon-themes": "10.5.6",
|
|
45
42
|
"@storybook/react-vite": "10.5.6",
|
|
46
43
|
"@tailwindcss/vite": "^4.2.1",
|
|
44
|
+
"@types/node": "^24.13.5",
|
|
47
45
|
"@types/react": "^19.1.0",
|
|
48
46
|
"@types/react-dom": "^19.1.0",
|
|
49
47
|
"class-variance-authority": "^0.7.1",
|
|
@@ -86,7 +84,7 @@
|
|
|
86
84
|
"tw-animate-css": "^1.4.0",
|
|
87
85
|
"vaul": "^1.1.2",
|
|
88
86
|
"vite": "^8.0.2",
|
|
89
|
-
"vite-plus": "^0.2.
|
|
87
|
+
"vite-plus": "^0.2.9"
|
|
90
88
|
},
|
|
91
89
|
"packageManager": "npm@11.12.1"
|
|
92
90
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "vite-plus";
|
|
2
|
-
|
|
3
|
-
//#region src/vite/agentation-plugin.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Vite plugin that provides Agentation integration:
|
|
6
|
-
* 1. A virtual module with mountAgentation()
|
|
7
|
-
* 2. An alias so "@nckrtl/launch-ui/agentation" (and legacy "@nckrtl/craft-ui-react/agentation") resolves to it
|
|
8
|
-
* 3. Auto-injection of mountAgentation() into the app entry point. The
|
|
9
|
-
* injected code is a lightweight listener; the agentation runtime itself
|
|
10
|
-
* is only downloaded when the laravel-toolbar is present on the page.
|
|
11
|
-
*/
|
|
12
|
-
declare function launchAgentationPlugin(): Plugin;
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Use `launchAgentationPlugin` instead.
|
|
15
|
-
*/
|
|
16
|
-
declare const craftAgentationPlugin: typeof launchAgentationPlugin;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { craftAgentationPlugin, launchAgentationPlugin };
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//#region src/vite/agentation-plugin.ts
|
|
2
|
-
const VIRTUAL_MODULE_ID = "virtual:launch-agentation";
|
|
3
|
-
const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:launch-agentation";
|
|
4
|
-
const AGENTATION_RUNTIME = `
|
|
5
|
-
function injectStyles() {
|
|
6
|
-
if (document.getElementById("launch-agentation-styles") || document.getElementById("craft-agentation-styles")) return;
|
|
7
|
-
const style = document.createElement("style");
|
|
8
|
-
style.id = "launch-agentation-styles";
|
|
9
|
-
style.textContent = \`
|
|
10
|
-
[data-agentation-toolbar] { display: none !important; }
|
|
11
|
-
[data-agentation-toolbar].agentation-visible { display: block !important; }
|
|
12
|
-
#laravel-toolbar-shadow-host.toolbar-external-active {
|
|
13
|
-
opacity: 0 !important;
|
|
14
|
-
pointer-events: none !important;
|
|
15
|
-
transition: opacity 0.15s ease;
|
|
16
|
-
}
|
|
17
|
-
\`;
|
|
18
|
-
document.head.appendChild(style);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function syncCount(count) {
|
|
22
|
-
window.dispatchEvent(
|
|
23
|
-
new CustomEvent("toolbar:agentation:state", {
|
|
24
|
-
detail: { annotationCount: count },
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function readAnnotationCount() {
|
|
30
|
-
try {
|
|
31
|
-
const key = "feedback-annotations-" + window.location.pathname;
|
|
32
|
-
const stored = JSON.parse(localStorage.getItem(key) ?? "[]");
|
|
33
|
-
return Array.isArray(stored) ? stored.length : 0;
|
|
34
|
-
} catch {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function mountAgentation() {
|
|
40
|
-
injectStyles();
|
|
41
|
-
|
|
42
|
-
let count = readAnnotationCount();
|
|
43
|
-
let loaded = false;
|
|
44
|
-
|
|
45
|
-
// The runtime is heavy (agentation + a second react-dom root), so it only
|
|
46
|
-
// loads once the toolbar proves it is on the page — via its request-state
|
|
47
|
-
// event, or via its host element when the toolbar mounted first. Pages
|
|
48
|
-
// without the toolbar (production visitors) never download it.
|
|
49
|
-
function loadAgentation() {
|
|
50
|
-
if (loaded) return;
|
|
51
|
-
loaded = true;
|
|
52
|
-
|
|
53
|
-
import(/* @vite-ignore */ "agentation").then(({ Agentation }) => {
|
|
54
|
-
import("react-dom/client").then(({ createRoot }) => {
|
|
55
|
-
import("react/jsx-runtime").then(({ jsx }) => {
|
|
56
|
-
const container = document.createElement("div");
|
|
57
|
-
container.id = "agentation-root";
|
|
58
|
-
document.body.appendChild(container);
|
|
59
|
-
createRoot(container).render(
|
|
60
|
-
jsx(Agentation, {
|
|
61
|
-
onAnnotationAdd: () => syncCount(++count),
|
|
62
|
-
onAnnotationDelete: () => syncCount(--count),
|
|
63
|
-
onAnnotationsClear: () => { count = 0; syncCount(0); },
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
window.addEventListener("toolbar:agentation:request-state", () => {
|
|
72
|
-
syncCount(count);
|
|
73
|
-
loadAgentation();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (document.getElementById("laravel-toolbar-shadow-host")) {
|
|
77
|
-
loadAgentation();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
const INIT_CODE = `
|
|
82
|
-
import { mountAgentation } from "virtual:launch-agentation";
|
|
83
|
-
if (typeof window !== "undefined") {
|
|
84
|
-
mountAgentation();
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
/**
|
|
88
|
-
* Vite plugin that provides Agentation integration:
|
|
89
|
-
* 1. A virtual module with mountAgentation()
|
|
90
|
-
* 2. An alias so "@nckrtl/launch-ui/agentation" (and legacy "@nckrtl/craft-ui-react/agentation") resolves to it
|
|
91
|
-
* 3. Auto-injection of mountAgentation() into the app entry point. The
|
|
92
|
-
* injected code is a lightweight listener; the agentation runtime itself
|
|
93
|
-
* is only downloaded when the laravel-toolbar is present on the page.
|
|
94
|
-
*/
|
|
95
|
-
function launchAgentationPlugin() {
|
|
96
|
-
return {
|
|
97
|
-
name: "launch-agentation",
|
|
98
|
-
enforce: "pre",
|
|
99
|
-
config() {
|
|
100
|
-
return { resolve: { alias: {
|
|
101
|
-
"@nckrtl/launch-ui/agentation": VIRTUAL_MODULE_ID,
|
|
102
|
-
"@nckrtl/craft-ui-react/agentation": VIRTUAL_MODULE_ID
|
|
103
|
-
} } };
|
|
104
|
-
},
|
|
105
|
-
resolveId(id) {
|
|
106
|
-
if (id === VIRTUAL_MODULE_ID || id === "virtual:craft-agentation" || id === "@nckrtl/launch-ui/agentation" || id === "@nckrtl/craft-ui-react/agentation") return RESOLVED_VIRTUAL_MODULE_ID;
|
|
107
|
-
},
|
|
108
|
-
load(id) {
|
|
109
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) return AGENTATION_RUNTIME;
|
|
110
|
-
},
|
|
111
|
-
transform(code, id) {
|
|
112
|
-
if (!id.match(/resources\/js\/app\.(tsx|ts|jsx|js)$/)) return null;
|
|
113
|
-
return {
|
|
114
|
-
code: INIT_CODE + code,
|
|
115
|
-
map: null
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated Use `launchAgentationPlugin` instead.
|
|
122
|
-
*/
|
|
123
|
-
const craftAgentationPlugin = launchAgentationPlugin;
|
|
124
|
-
//#endregion
|
|
125
|
-
export { craftAgentationPlugin, launchAgentationPlugin };
|