@nckrtl/launch-ui 0.0.24
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 +25 -0
- package/dist/agentation-plugin.d.mts +18 -0
- package/dist/agentation-plugin.mjs +125 -0
- package/dist/i18n-plugin-D--fPPUj.mjs +112 -0
- package/dist/index.d.mts +94 -0
- package/dist/index.mjs +189 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @nckrtl/launch-ui
|
|
2
|
+
|
|
3
|
+
React component library and Vite toolchain for building Laravel + React + Inertia applications. Built on Base UI and shadcn with Agentation integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nckrtl/launch-ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage in Vite
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { defineLaunchConfig } from '@nckrtl/launch-ui/vite';
|
|
16
|
+
|
|
17
|
+
export default defineLaunchConfig();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Vite Integration**: Zero-config Vite setups for Laravel + React + Inertia projects via `defineLaunchConfig()`.
|
|
23
|
+
- **i18n Support**: Simple translation helpers available via `@nckrtl/launch-ui/i18n`.
|
|
24
|
+
- **Agentation**: Integrated UI feedback toolbar integration via `@nckrtl/launch-ui/agentation`.
|
|
25
|
+
- **Legacy Fallback**: Backwards-compatible aliases for `@nckrtl/craft-ui-react/*` and `defineCraftConfig`.
|
|
@@ -0,0 +1,18 @@
|
|
|
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 };
|
|
@@ -0,0 +1,125 @@
|
|
|
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("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 };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//#region src/vite/i18n-plugin.ts
|
|
2
|
+
const VIRTUAL_MODULE_ID = "virtual:launch-i18n";
|
|
3
|
+
const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:launch-i18n";
|
|
4
|
+
/**
|
|
5
|
+
* The i18n runtime — a self-contained module.
|
|
6
|
+
*
|
|
7
|
+
* Exports:
|
|
8
|
+
* - __() — translate a key (plain function, works anywhere)
|
|
9
|
+
* - setLocale() — switch language + notify subscribers + persist
|
|
10
|
+
* - getLocale() — get current locale
|
|
11
|
+
* - useLocale() — React hook that re-renders on locale change
|
|
12
|
+
* - initI18n() — load translations (called automatically by the Vite plugin)
|
|
13
|
+
*/
|
|
14
|
+
const I18N_RUNTIME = `
|
|
15
|
+
import { useSyncExternalStore } from "react";
|
|
16
|
+
|
|
17
|
+
let locale = "en";
|
|
18
|
+
let fallbackLocale = "en";
|
|
19
|
+
const messages = {};
|
|
20
|
+
const listeners = new Set();
|
|
21
|
+
|
|
22
|
+
function notify() { listeners.forEach(fn => fn()); }
|
|
23
|
+
|
|
24
|
+
export function initI18n(options) {
|
|
25
|
+
locale = options.locale ?? "en";
|
|
26
|
+
fallbackLocale = options.fallbackLocale ?? "en";
|
|
27
|
+
for (const [path, mod] of Object.entries(options.files)) {
|
|
28
|
+
const match = path.match(/\\/([a-z]{2}(?:[-_][a-zA-Z]+)?)\\json$/);
|
|
29
|
+
if (!match) continue;
|
|
30
|
+
const lang = match[1].replace("-", "_");
|
|
31
|
+
const translations = "default" in mod ? mod.default : mod;
|
|
32
|
+
messages[lang] = { ...(messages[lang] || {}), ...translations };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function setLocale(lang) {
|
|
37
|
+
locale = lang;
|
|
38
|
+
if (typeof localStorage !== "undefined") localStorage.setItem("locale", lang);
|
|
39
|
+
if (typeof document !== "undefined") {
|
|
40
|
+
document.cookie = "locale=" + lang + ";path=/;SameSite=Lax;max-age=31536000";
|
|
41
|
+
document.documentElement.setAttribute("lang", lang.replace("_", "-"));
|
|
42
|
+
}
|
|
43
|
+
notify();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getLocale() { return locale; }
|
|
47
|
+
|
|
48
|
+
export function useLocale() {
|
|
49
|
+
return useSyncExternalStore(
|
|
50
|
+
(cb) => { listeners.add(cb); return () => listeners.delete(cb); },
|
|
51
|
+
() => locale,
|
|
52
|
+
() => locale,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function __(key, replacements) {
|
|
57
|
+
const msg = messages[locale]?.[key] ?? messages[fallbackLocale]?.[key] ?? key;
|
|
58
|
+
if (!replacements) return msg;
|
|
59
|
+
return Object.entries(replacements).reduce((result, [param, value]) => {
|
|
60
|
+
const str = String(value);
|
|
61
|
+
return result
|
|
62
|
+
.replace(new RegExp(":" + param, "g"), str)
|
|
63
|
+
.replace(new RegExp(":" + param.charAt(0).toUpperCase() + param.slice(1), "g"), str.charAt(0).toUpperCase() + str.slice(1))
|
|
64
|
+
.replace(new RegExp(":" + param.toUpperCase(), "g"), str.toUpperCase());
|
|
65
|
+
}, msg);
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
/**
|
|
69
|
+
* Vite plugin that provides launch i18n:
|
|
70
|
+
* 1. A virtual module "virtual:launch-i18n" with __, setLocale, getLocale, useLocale, initI18n
|
|
71
|
+
* 2. An alias so "@nckrtl/launch-ui/i18n" (and legacy "@nckrtl/craft-ui-react/i18n") resolves to the virtual module
|
|
72
|
+
* 3. Auto-injection of initI18n() into the app entry point
|
|
73
|
+
*/
|
|
74
|
+
function launchI18nPlugin(i18n) {
|
|
75
|
+
const opts = typeof i18n === "object" ? i18n : {};
|
|
76
|
+
opts.locale;
|
|
77
|
+
opts.fallbackLocale;
|
|
78
|
+
opts.langPath;
|
|
79
|
+
const initCode = `
|
|
80
|
+
import { initI18n } from "virtual:launch-i18n";
|
|
81
|
+
initI18n({
|
|
82
|
+
locale: "",
|
|
83
|
+
fallbackLocale: "",
|
|
84
|
+
files: import.meta.glob("", { eager: true }),
|
|
85
|
+
});
|
|
86
|
+
`;
|
|
87
|
+
return {
|
|
88
|
+
name: "launch-i18n",
|
|
89
|
+
enforce: "pre",
|
|
90
|
+
config() {
|
|
91
|
+
return { resolve: { alias: {
|
|
92
|
+
"@nckrtl/launch-ui/i18n": VIRTUAL_MODULE_ID,
|
|
93
|
+
"@nckrtl/craft-ui-react/i18n": VIRTUAL_MODULE_ID
|
|
94
|
+
} } };
|
|
95
|
+
},
|
|
96
|
+
resolveId(id) {
|
|
97
|
+
if (id === VIRTUAL_MODULE_ID || id === "virtual:craft-i18n" || id === "@nckrtl/launch-ui/i18n" || id === "@nckrtl/craft-ui-react/i18n") return RESOLVED_VIRTUAL_MODULE_ID;
|
|
98
|
+
},
|
|
99
|
+
load(id) {
|
|
100
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) return I18N_RUNTIME;
|
|
101
|
+
},
|
|
102
|
+
transform(code, id) {
|
|
103
|
+
if (!id.match(/resources\/js\/app\.(tsx|ts|jsx|js)$/)) return null;
|
|
104
|
+
return {
|
|
105
|
+
code: initCode + code,
|
|
106
|
+
map: null
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { launchI18nPlugin };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { PluginOption, UserConfig } from "vite-plus";
|
|
2
|
+
|
|
3
|
+
//#region src/vite/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options for defineLaunchConfig
|
|
6
|
+
*
|
|
7
|
+
* Each inner plugin's options are exposed as a top-level key.
|
|
8
|
+
* Pass `false` to disable a plugin entirely.
|
|
9
|
+
*/
|
|
10
|
+
interface LaunchConfigOptions {
|
|
11
|
+
/** Laravel Vite plugin options */
|
|
12
|
+
laravel?: {
|
|
13
|
+
input?: string[];
|
|
14
|
+
refresh?: boolean;
|
|
15
|
+
ssr?: string;
|
|
16
|
+
};
|
|
17
|
+
/** @inertiajs/vite plugin options, or `false` to disable */
|
|
18
|
+
inertia?: false | {
|
|
19
|
+
ssr?: false | {
|
|
20
|
+
entry?: string;
|
|
21
|
+
port?: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** @vitejs/plugin-react options */
|
|
25
|
+
react?: {
|
|
26
|
+
babel?: {
|
|
27
|
+
plugins?: string[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** @laravel/vite-plugin-wayfinder options, or `false` to disable */
|
|
31
|
+
wayfinder?: false | {
|
|
32
|
+
formVariants?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Enable i18n support. When true, injects initI18n() into app entry.
|
|
36
|
+
* The __ function becomes available via: import { __ } from '@nckrtl/launch-ui/i18n'
|
|
37
|
+
*/
|
|
38
|
+
i18n?: boolean | {
|
|
39
|
+
/** Active locale (default: "en") */locale?: string; /** Fallback locale (default: "en") */
|
|
40
|
+
fallbackLocale?: string; /** Glob pattern for lang files (default: "/lang/*.json") */
|
|
41
|
+
langPath?: string;
|
|
42
|
+
};
|
|
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
|
+
/** Additional Vite plugins to include */
|
|
51
|
+
plugins?: PluginOption[];
|
|
52
|
+
/** VitePlus lint options — passed through to defineConfig */
|
|
53
|
+
lint?: {
|
|
54
|
+
options?: {
|
|
55
|
+
typeAware?: boolean;
|
|
56
|
+
typeCheck?: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* VitePlus staged command map for pre-commit hooks. Keys are glob patterns,
|
|
61
|
+
* values are the shell command to run on matching staged files. Defaults
|
|
62
|
+
* to `{ "*": "vp check --fix" }` — override to customize.
|
|
63
|
+
*/
|
|
64
|
+
staged?: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated Use `LaunchConfigOptions` instead.
|
|
68
|
+
*/
|
|
69
|
+
type CraftConfigOptions = LaunchConfigOptions;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/vite/plugins.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* Assemble all Vite plugins for the Launch React stack
|
|
74
|
+
*/
|
|
75
|
+
declare function getPlugins(options: LaunchConfigOptions): Promise<PluginOption[]>;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/vite/index.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Create a complete Vite config for a Launch React app.
|
|
80
|
+
*
|
|
81
|
+
* Returns a Promise<UserConfig> — Vite's defineConfig supports async functions.
|
|
82
|
+
* The async is needed because plugin imports resolve from the consumer's node_modules.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* import { defineLaunchConfig } from '@nckrtl/launch-ui/vite';
|
|
86
|
+
* export default defineLaunchConfig();
|
|
87
|
+
*/
|
|
88
|
+
declare function defineLaunchConfig(options?: LaunchConfigOptions): Promise<(env: import("vite").ConfigEnv) => UserConfig>;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated Use `defineLaunchConfig` instead.
|
|
91
|
+
*/
|
|
92
|
+
declare const defineCraftConfig: typeof defineLaunchConfig;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { type CraftConfigOptions, type LaunchConfigOptions, defineCraftConfig, defineLaunchConfig, getPlugins };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { defineConfig } from "vite-plus";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
//#region src/vite/plugins.ts
|
|
6
|
+
/**
|
|
7
|
+
* Import a package from the consumer project's node_modules.
|
|
8
|
+
* Reads the package's entry point from its package.json exports/main field,
|
|
9
|
+
* then imports it via file:// URL for ESM compatibility.
|
|
10
|
+
*/
|
|
11
|
+
async function importFromConsumer(pkg) {
|
|
12
|
+
const nodeModules = join(process.cwd(), "node_modules");
|
|
13
|
+
const parts = pkg.startsWith("@") ? [pkg.split("/").slice(0, 2).join("/"), ...pkg.split("/").slice(2)] : pkg.split("/");
|
|
14
|
+
const pkgName = parts[0];
|
|
15
|
+
const subpath = parts.slice(1).join("/");
|
|
16
|
+
if (subpath) {
|
|
17
|
+
const filePath = join(nodeModules, pkgName, subpath);
|
|
18
|
+
return import(pathToFileURL(existsSync(filePath) ? filePath : `${filePath}.js`).href);
|
|
19
|
+
}
|
|
20
|
+
const pkgDir = join(nodeModules, pkgName);
|
|
21
|
+
const pkgJson = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8"));
|
|
22
|
+
const exports = pkgJson.exports?.["."];
|
|
23
|
+
return import(pathToFileURL(join(pkgDir, (typeof exports === "string" ? exports : exports?.import ?? exports?.default) ?? pkgJson.module ?? pkgJson.main ?? "index.js")).href);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Assemble all Vite plugins for the Launch React stack
|
|
27
|
+
*/
|
|
28
|
+
async function getPlugins(options) {
|
|
29
|
+
const [{ default: laravel }, { default: react }, { default: tailwindcss }] = await Promise.all([
|
|
30
|
+
importFromConsumer("laravel-vite-plugin"),
|
|
31
|
+
importFromConsumer("@vitejs/plugin-react"),
|
|
32
|
+
importFromConsumer("@tailwindcss/vite")
|
|
33
|
+
]);
|
|
34
|
+
const runningBehindProxy = typeof process.env.VITE_APP_URL === "string" && process.env.VITE_APP_URL !== "";
|
|
35
|
+
const plugins = [
|
|
36
|
+
launchAliasPlugin(),
|
|
37
|
+
laravel({
|
|
38
|
+
input: options.laravel?.input ?? ["resources/js/app.tsx"],
|
|
39
|
+
ssr: options.laravel?.ssr,
|
|
40
|
+
refresh: options.laravel?.refresh ?? true,
|
|
41
|
+
...runningBehindProxy ? { detectTls: false } : {}
|
|
42
|
+
}),
|
|
43
|
+
react(options.react),
|
|
44
|
+
tailwindcss()
|
|
45
|
+
];
|
|
46
|
+
if (options.inertia !== false) {
|
|
47
|
+
const { default: inertia } = await importFromConsumer("@inertiajs/vite");
|
|
48
|
+
plugins.push(inertia(typeof options.inertia === "object" ? options.inertia : void 0));
|
|
49
|
+
}
|
|
50
|
+
if (options.wayfinder !== false) {
|
|
51
|
+
const { wayfinder } = await importFromConsumer("@laravel/vite-plugin-wayfinder");
|
|
52
|
+
const wayfinderOptions = typeof options.wayfinder === "object" ? options.wayfinder : {};
|
|
53
|
+
plugins.push(wayfinder({
|
|
54
|
+
formVariants: true,
|
|
55
|
+
...wayfinderOptions
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
if (options.i18n) {
|
|
59
|
+
const { launchI18nPlugin } = await import("./i18n-plugin-D--fPPUj.mjs");
|
|
60
|
+
plugins.push(launchI18nPlugin(options.i18n));
|
|
61
|
+
}
|
|
62
|
+
if (options.agentation !== false) {
|
|
63
|
+
const { launchAgentationPlugin } = await import("./agentation-plugin.mjs");
|
|
64
|
+
plugins.push(launchAgentationPlugin());
|
|
65
|
+
}
|
|
66
|
+
plugins.push(launchPublicDevServerUrlPlugin());
|
|
67
|
+
const runners = await getArtisanRunners();
|
|
68
|
+
if (runners) plugins.push(runners);
|
|
69
|
+
if (options.plugins) plugins.push(...options.plugins);
|
|
70
|
+
return plugins;
|
|
71
|
+
}
|
|
72
|
+
function launchAliasPlugin() {
|
|
73
|
+
return {
|
|
74
|
+
name: "launch:alias-fallback",
|
|
75
|
+
config() {
|
|
76
|
+
return { resolve: { alias: [
|
|
77
|
+
{
|
|
78
|
+
find: /^@nckrtl\/craft-ui-react\/vite$/,
|
|
79
|
+
replacement: "@nckrtl/launch-ui/vite"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
find: /^@nckrtl\/craft-ui-react\/i18n$/,
|
|
83
|
+
replacement: "@nckrtl/launch-ui/i18n"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
find: /^@nckrtl\/craft-ui-react\/agentation$/,
|
|
87
|
+
replacement: "@nckrtl/launch-ui/agentation"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
find: /^@nckrtl\/craft-ui-react\/(.*)$/,
|
|
91
|
+
replacement: "@nckrtl/launch-ui/$1"
|
|
92
|
+
}
|
|
93
|
+
] } };
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function launchPublicDevServerUrlPlugin() {
|
|
98
|
+
return {
|
|
99
|
+
name: "launch:public-dev-server-url",
|
|
100
|
+
apply: "serve",
|
|
101
|
+
configureServer(server) {
|
|
102
|
+
server.httpServer?.once("listening", () => {
|
|
103
|
+
const preferredUrl = getPublicDevServerUrl(server);
|
|
104
|
+
if (!preferredUrl || !server.resolvedUrls) return;
|
|
105
|
+
server.resolvedUrls.local = preferUrl(server.resolvedUrls.local, preferredUrl);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function getPublicDevServerUrl(server) {
|
|
111
|
+
const rawOrigin = server.config.env.VITE_DEV_SERVER_ORIGIN ?? server.config.env.VITE_APP_URL ?? server.config.env.APP_URL;
|
|
112
|
+
if (typeof rawOrigin !== "string" || rawOrigin === "") return null;
|
|
113
|
+
try {
|
|
114
|
+
const url = new URL(rawOrigin);
|
|
115
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
|
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();
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function preferUrl(urls, preferredUrl) {
|
|
128
|
+
const preferredOrigin = new URL(preferredUrl).origin;
|
|
129
|
+
return [preferredUrl, ...urls.filter((url) => {
|
|
130
|
+
try {
|
|
131
|
+
return new URL(url).origin !== preferredOrigin;
|
|
132
|
+
} catch {
|
|
133
|
+
return url !== preferredUrl;
|
|
134
|
+
}
|
|
135
|
+
})];
|
|
136
|
+
}
|
|
137
|
+
async function getArtisanRunners() {
|
|
138
|
+
if (process.env.NODE_ENV !== "development") return null;
|
|
139
|
+
try {
|
|
140
|
+
const { run } = await importFromConsumer("vite-plugin-run");
|
|
141
|
+
return run([{
|
|
142
|
+
name: "waymaker",
|
|
143
|
+
run: [
|
|
144
|
+
"php",
|
|
145
|
+
"artisan",
|
|
146
|
+
"waymaker:generate"
|
|
147
|
+
],
|
|
148
|
+
pattern: ["app/**/Http/**/*.php"]
|
|
149
|
+
}, {
|
|
150
|
+
name: "typescript",
|
|
151
|
+
run: [
|
|
152
|
+
"php",
|
|
153
|
+
"artisan",
|
|
154
|
+
"typescript:transform"
|
|
155
|
+
],
|
|
156
|
+
pattern: ["app/{Data,Enums}/**/*.php"]
|
|
157
|
+
}]);
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/vite/index.ts
|
|
164
|
+
/**
|
|
165
|
+
* Create a complete Vite config for a Launch React app.
|
|
166
|
+
*
|
|
167
|
+
* Returns a Promise<UserConfig> — Vite's defineConfig supports async functions.
|
|
168
|
+
* The async is needed because plugin imports resolve from the consumer's node_modules.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* import { defineLaunchConfig } from '@nckrtl/launch-ui/vite';
|
|
172
|
+
* export default defineLaunchConfig();
|
|
173
|
+
*/
|
|
174
|
+
async function defineLaunchConfig(options = {}) {
|
|
175
|
+
const { lint, staged, ...launchOptions } = options;
|
|
176
|
+
const plugins = await getPlugins(launchOptions);
|
|
177
|
+
return defineConfig(() => ({
|
|
178
|
+
...lint ? { lint } : {},
|
|
179
|
+
staged: staged ?? { "*": "vp check --fix" },
|
|
180
|
+
plugins,
|
|
181
|
+
server: { watch: { ignored: ["**/vendor/**"] } }
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Use `defineLaunchConfig` instead.
|
|
186
|
+
*/
|
|
187
|
+
const defineCraftConfig = defineLaunchConfig;
|
|
188
|
+
//#endregion
|
|
189
|
+
export { defineCraftConfig, defineLaunchConfig, getPlugins };
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nckrtl/launch-ui",
|
|
3
|
+
"version": "0.0.24",
|
|
4
|
+
"description": "A React component library and Vite toolchain for building Laravel + React + Inertia apps. Built on Base UI and shadcn with Agentation integration.",
|
|
5
|
+
"author": "nckrtl <nick.retel@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/nckrtl/launch-ui#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/nckrtl/launch-ui/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/nckrtl/launch-ui.git"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
"./vite": {
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./agentation": {
|
|
29
|
+
"types": "./dist/agentation-plugin.d.mts",
|
|
30
|
+
"default": "./dist/agentation-plugin.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "storybook dev -p 6006",
|
|
35
|
+
"build": "shadcn build",
|
|
36
|
+
"build:lib": "vp pack src/vite/index.ts src/vite/agentation-plugin.ts --dts --format esm --out-dir dist",
|
|
37
|
+
"build:storybook": "storybook build && rsync -a storybook-static/ public/",
|
|
38
|
+
"serve": "npx http-server public -p 4100 -c-1 --cors"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@chromatic-com/storybook": "^5.3.0",
|
|
42
|
+
"@inertiajs/react": "^3.0.0",
|
|
43
|
+
"@storybook/addon-docs": "10.5.6",
|
|
44
|
+
"@storybook/addon-themes": "10.5.6",
|
|
45
|
+
"@storybook/react-vite": "10.5.6",
|
|
46
|
+
"@tailwindcss/vite": "^4.2.1",
|
|
47
|
+
"@types/react": "^19.1.0",
|
|
48
|
+
"@types/react-dom": "^19.1.0",
|
|
49
|
+
"class-variance-authority": "^0.7.1",
|
|
50
|
+
"clsx": "^2.1.1",
|
|
51
|
+
"lucide-react": "^0.577.0",
|
|
52
|
+
"react": "^19.1.0",
|
|
53
|
+
"react-dom": "^19.1.0",
|
|
54
|
+
"reselect": "^5.2.0",
|
|
55
|
+
"shadcn": "^4.1.0",
|
|
56
|
+
"storybook": "10.5.6",
|
|
57
|
+
"tailwind-merge": "^3.5.0",
|
|
58
|
+
"tailwindcss": "^4.2.1",
|
|
59
|
+
"typescript": "^5.9.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@inertiajs/vite": "^3.0.0",
|
|
63
|
+
"@laravel/vite-plugin-wayfinder": "^0.1.0",
|
|
64
|
+
"@tailwindcss/vite": "^4.2.0",
|
|
65
|
+
"@vitejs/plugin-react": "^6.0.0",
|
|
66
|
+
"laravel-vite-plugin": "^3.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"vite-plugin-run": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"@base-ui/react": "^1.3.0",
|
|
75
|
+
"@storybook/addon-mcp": "^0.4.2",
|
|
76
|
+
"cmdk": "^1.1.1",
|
|
77
|
+
"date-fns": "^4.1.0",
|
|
78
|
+
"embla-carousel-react": "^8.6.0",
|
|
79
|
+
"input-otp": "^1.4.2",
|
|
80
|
+
"next-themes": "^0.4.6",
|
|
81
|
+
"react-day-picker": "^9.14.0",
|
|
82
|
+
"react-is": "^19.2.4",
|
|
83
|
+
"react-resizable-panels": "^4.7.5",
|
|
84
|
+
"recharts": "^3.8.0",
|
|
85
|
+
"sonner": "^2.0.7",
|
|
86
|
+
"tw-animate-css": "^1.4.0",
|
|
87
|
+
"vaul": "^1.1.2",
|
|
88
|
+
"vite": "^8.0.2",
|
|
89
|
+
"vite-plus": "^0.2.1"
|
|
90
|
+
},
|
|
91
|
+
"packageManager": "npm@11.12.1"
|
|
92
|
+
}
|