@lattice-php/lattice 0.40.0 → 0.42.0
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/provider-base.js +1 -1
- package/dist/provider-base.js.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/runtime.d.ts +11 -3
- package/dist/runtime.js +12 -3
- package/dist/types/core-augmentation.d.ts +2 -1
- package/dist/vite.d.ts +12 -7
- package/dist/vite.js +31 -10
- package/dist/vite.js.map +1 -1
- package/dist-standalone/chunks/chart-view-DghsYabe.js +59 -0
- package/dist-standalone/chunks/format-context-DCYPeoEM.js +1 -0
- package/dist-standalone/chunks/{rich-editor-field-n-mtzlT-.js → rich-editor-field-DnkT5hlA.js} +40 -40
- package/dist-standalone/chunks/runtime-zkYqbYk4.js +27 -0
- package/dist-standalone/chunks/{icon-button-COE_nq4v.js → toolbar-button-BmtWFTk1.js} +1 -1
- package/dist-standalone/lattice.css +1 -1
- package/dist-standalone/lattice.js +1 -1
- package/dist-standalone/manifest.json +1 -1
- package/dist-standalone/react-dom.js +1 -0
- package/dist-standalone/runtime.js +1 -1
- package/package.json +8 -16
- package/dist/_virtual/_rolldown/runtime.js +0 -27
- package/dist/action/components/action-form.d.ts +0 -1
- package/dist/action/components/action-form.js +0 -10
- package/dist/action/components/action-form.js.map +0 -1
- package/dist/action/components/action-group.d.ts +0 -3
- package/dist/action/components/action-group.js +0 -51
- package/dist/action/components/action-group.js.map +0 -1
- package/dist/action/components/action-trigger-provider.d.ts +0 -10
- package/dist/action/components/action-trigger-provider.js +0 -24
- package/dist/action/components/action-trigger-provider.js.map +0 -1
- package/dist/action/components/action.d.ts +0 -3
- package/dist/action/components/action.js +0 -36
- package/dist/action/components/action.js.map +0 -1
- package/dist/action/hooks/use-action.d.ts +0 -18
- package/dist/action/hooks/use-action.js +0 -100
- package/dist/action/hooks/use-action.js.map +0 -1
- package/dist/action/index.d.ts +0 -8
- package/dist/action/index.js +0 -11
- package/dist/action/lib/action-label.d.ts +0 -2
- package/dist/action/lib/action-label.js +0 -9
- package/dist/action/lib/action-label.js.map +0 -1
- package/dist/action/lib/run-action.d.ts +0 -1
- package/dist/action/lib/run-action.js +0 -10
- package/dist/action/lib/run-action.js.map +0 -1
- package/dist/action/plugin.d.ts +0 -2
- package/dist/action/plugin.js +0 -15
- package/dist/action/plugin.js.map +0 -1
- package/dist-standalone/chunks/chart-view-DFSCMDuw.js +0 -59
- package/dist-standalone/chunks/number-DjNO0Pxv.js +0 -1
- package/dist-standalone/chunks/runtime-Bh_GyTCD.js +0 -23
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,8 +20,8 @@ import { LATTICE_REF_HEADER, withRefHeader } from "@lattice-php/core/component-r
|
|
|
20
20
|
import { Icon, IconRenderer, IconRendererProvider, SpriteProvider } from "@lattice-php/ui/icons";
|
|
21
21
|
import { Renderer } from "@lattice-php/core/renderer";
|
|
22
22
|
import { LATTICE_EVENT } from "@lattice-php/core/event-names";
|
|
23
|
-
import { useEffectDispatcher } from "@lattice-php/ui/effects/use-effect-dispatcher";
|
|
24
23
|
import { dispatchActionError, dispatchEffects, getActionEffects, isActionEffect } from "@lattice-php/ui/effects/dispatch";
|
|
24
|
+
import { useEffectDispatcher } from "@lattice-php/ui/effects/use-effect-dispatcher";
|
|
25
25
|
import { builtinEffectHandlers, effectHandler, mergeEffectHandlers } from "@lattice-php/ui/effects/registry";
|
|
26
26
|
import { copyToClipboard } from "@lattice-php/ui/copyable-text";
|
|
27
27
|
import { columnCell } from "@lattice-php/table/registry";
|
package/dist/provider-base.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { updateAppearance } from "./appearance/index.js";
|
|
2
2
|
import { Toaster } from "./toast/toaster.js";
|
|
3
|
-
import { ActionInteractionProvider } from "./action/components/action-trigger-provider.js";
|
|
4
3
|
import { EventBridge } from "./event-bridge.js";
|
|
5
4
|
import { RegistryContext } from "@lattice-php/core/registry-context";
|
|
6
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { ActionInteractionProvider } from "@lattice-php/action/components/action-trigger-provider";
|
|
7
7
|
import { useFlashEffects } from "@lattice-php/ui/effects/use-flash-effects";
|
|
8
8
|
import { SpriteProvider } from "@lattice-php/ui/icons/sprite";
|
|
9
9
|
//#region resources/js/provider-base.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-base.js","names":[],"sources":["../resources/js/provider-base.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { ActionInteractionProvider } from \"
|
|
1
|
+
{"version":3,"file":"provider-base.js","names":[],"sources":["../resources/js/provider-base.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { ActionInteractionProvider } from \"@lattice-php/action/components/action-trigger-provider\";\nimport type { Registry } from \"@lattice-php/core/registry\";\nimport { RegistryContext } from \"@lattice-php/core/registry-context\";\nimport { useFlashEffects } from \"@lattice-php/ui/effects/use-flash-effects\";\nimport { EventBridge } from \"./event-bridge\";\nimport type { SpriteValue } from \"@lattice-php/ui/icons/sprite\";\nimport { SpriteProvider } from \"@lattice-php/ui/icons/sprite\";\nimport { Toaster } from \"./toast\";\nimport { updateAppearance } from \"./appearance\";\n\nconst defaultSprite: SpriteValue = { href: \"\" };\n\nexport type ProviderBaseProps = {\n children: ReactNode;\n registry: Registry;\n sprite?: SpriteValue;\n toaster?: boolean;\n};\n\nexport function ProviderBase({\n children,\n registry,\n sprite = defaultSprite,\n toaster = true,\n}: ProviderBaseProps) {\n useFlashEffects();\n\n return (\n <RegistryContext.Provider value={registry}>\n <ActionInteractionProvider>\n <SpriteProvider sprite={sprite}>\n {children}\n <EventBridge onAppearanceChange={updateAppearance} />\n {toaster ? <Toaster /> : null}\n </SpriteProvider>\n </ActionInteractionProvider>\n </RegistryContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,gBAA6B,EAAE,MAAM,GAAG;AAS9C,SAAgB,aAAa,EAC3B,UACA,UACA,SAAS,eACT,UAAU,QACU;CACpB,gBAAgB;CAEhB,OACE,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAC/B,UAAA,oBAAC,2BAAD,EAAA,UACE,qBAAC,gBAAD;GAAwB;GAAxB,UAAA;IACG;IACD,oBAAC,aAAD,EAAa,oBAAoB,iBAAmB,CAAA;IACnD,UAAU,oBAAC,SAAD,CAAU,CAAA,IAAI;GACX;EACS,CAAA,EAAA,CAAA;CACH,CAAA;AAE9B"}
|
package/dist/registry.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { layoutComponents } from "./layout/plugin.js";
|
|
2
|
-
import { actionComponents } from "./action/plugin.js";
|
|
3
2
|
import { chatComponents } from "./chat/plugin.js";
|
|
4
3
|
import { fragmentComponents } from "./fragments/plugin.js";
|
|
5
4
|
import { notificationsComponents } from "./notifications/plugin.js";
|
|
6
5
|
import { remoteComponents } from "./remote/plugin.js";
|
|
7
6
|
import { createRegistry } from "@lattice-php/core/registry";
|
|
7
|
+
import { actionComponents } from "@lattice-php/action/plugin";
|
|
8
8
|
import { formComponents } from "@lattice-php/form";
|
|
9
9
|
import { tableComponents } from "@lattice-php/table";
|
|
10
10
|
import { uiComponents } from "@lattice-php/ui";
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":[],"sources":["../resources/js/registry.ts"],"sourcesContent":["import { createRegistry } from \"@lattice-php/core/registry\";\nimport type {\n ActionNodeType,\n ChatNodeType,\n FormNodeType,\n FragmentNodeType,\n LayoutNodeType,\n NodeType,\n NotificationNodeType,\n RemoteNodeType,\n TableNodeType,\n UiNodeType,\n} from \"@lattice-php/lattice/types/generated\";\nimport { actionComponents } from \"
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../resources/js/registry.ts"],"sourcesContent":["import { createRegistry } from \"@lattice-php/core/registry\";\nimport type {\n ActionNodeType,\n ChatNodeType,\n FormNodeType,\n FragmentNodeType,\n LayoutNodeType,\n NodeType,\n NotificationNodeType,\n RemoteNodeType,\n TableNodeType,\n UiNodeType,\n} from \"@lattice-php/lattice/types/generated\";\nimport { actionComponents } from \"@lattice-php/action/plugin\";\nimport { chatComponents } from \"./chat/plugin\";\nimport { formComponents } from \"@lattice-php/form\";\nimport { fragmentComponents } from \"./fragments/plugin\";\nimport { layoutComponents } from \"./layout/plugin\";\nimport { notificationsComponents } from \"./notifications/plugin\";\nimport { remoteComponents } from \"./remote/plugin\";\nimport { tableComponents } from \"@lattice-php/table\";\nimport { uiComponents } from \"@lattice-php/ui\";\n\n// Compile-time totality: every generated NodeType must belong to a registered\n// plugin's union. A new PHP domain fails here until its plugin exists.\ntype RegisteredNodeType =\n | ActionNodeType\n | ChatNodeType\n | FormNodeType\n | FragmentNodeType\n | LayoutNodeType\n | NotificationNodeType\n | RemoteNodeType\n | TableNodeType\n | UiNodeType;\ntype Assert<T extends true> = T;\nexport type AllNodeTypesRegistered = Assert<\n Exclude<NodeType, RegisteredNodeType> extends never ? true : false\n>;\n\nexport const registry = createRegistry(\n uiComponents,\n fragmentComponents,\n actionComponents,\n formComponents,\n layoutComponents,\n tableComponents,\n chatComponents,\n notificationsComponents,\n remoteComponents,\n);\n"],"mappings":";;;;;;;;;;;AAwCA,IAAa,WAAW,eACtB,cACA,oBACA,kBACA,gBACA,kBACA,iBACA,gBACA,yBACA,gBACF"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export * from './index.js';
|
|
2
2
|
export { router } from '@inertiajs/react';
|
|
3
|
-
export {
|
|
3
|
+
export { runAction } from '@lattice-php/action';
|
|
4
|
+
export { apiFetch, apiJson, setRefRefreshEndpoint, xsrfToken } from '@lattice-php/core/api';
|
|
5
|
+
export { RenderNode } from '@lattice-php/core/renderer';
|
|
4
6
|
export { nodeIdentity } from '@lattice-php/core/test-id';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
+
export { requestSignedUpload, xhrTransfer } from '@lattice-php/core/upload';
|
|
8
|
+
export { SimpleField } from '@lattice-php/form/components/fields/simple-field';
|
|
9
|
+
export { RICH_EDITOR_EXTENSION, ToolbarIconButton } from '@lattice-php/form/rich-editor';
|
|
7
10
|
export * from '@lattice-php/form/toolkit';
|
|
11
|
+
export { useTable } from '@lattice-php/table/hooks/use-table';
|
|
12
|
+
export { useTableSelection } from '@lattice-php/table/hooks/use-table-selection';
|
|
13
|
+
export { getBulkActions } from '@lattice-php/table/lib/bulk';
|
|
14
|
+
export { Button, Checkbox, cn, ConfirmDialog, Dialog, DialogContent, DialogHeader, formatDateValue, IconButton, Input, Label, NativeSelect, PreviewableImage, useDebouncedCallback, useFormatContext, usePersistentState, } from '@lattice-php/ui';
|
|
8
15
|
export * from '@lattice-php/ui/i18n';
|
|
16
|
+
export { announce, attachTreeItemInstruction, combine, draggable, dropTargetForElements, extractTreeItemInstruction, } from './dnd/index.js';
|
|
9
17
|
export type { Variant } from './toast/index.js';
|
package/dist/runtime.js
CHANGED
|
@@ -15,10 +15,19 @@ import { registry } from "./registry.js";
|
|
|
15
15
|
import { createLatticeApp } from "./create-app.js";
|
|
16
16
|
import { Provider, useColumnRegistry, useComponentRegistry } from "./provider.js";
|
|
17
17
|
import { Icon, IconRenderer, IconRendererProvider, LATTICE_EVENT, LATTICE_REF_HEADER, Renderer, SpriteProvider, builtinEffectHandlers, columnCell, copyToClipboard, createRegistry, dispatchActionError, dispatchEffects, eagerComponent, effectHandler, extendRegistry, getActionEffects, isActionEffect, lazyComponent, loadPluginModules, mergeEffectHandlers, useEffectDispatcher, withHeaders, withRefHeader } from "./index.js";
|
|
18
|
+
import { announce, attachTreeItemInstruction, combine, draggable, dropTargetForElements, extractTreeItemInstruction } from "./dnd/index.js";
|
|
18
19
|
import { router } from "@inertiajs/react";
|
|
19
|
-
import { apiJson, setRefRefreshEndpoint } from "@lattice-php/core/api";
|
|
20
|
+
import { apiFetch, apiJson, setRefRefreshEndpoint, xsrfToken } from "@lattice-php/core/api";
|
|
21
|
+
import { RenderNode } from "@lattice-php/core/renderer";
|
|
20
22
|
import { nodeIdentity } from "@lattice-php/core/test-id";
|
|
21
|
-
import { cn, usePersistentState } from "@lattice-php/ui";
|
|
23
|
+
import { Button, Checkbox, ConfirmDialog, Dialog, DialogContent, DialogHeader, IconButton, Input, Label, NativeSelect, PreviewableImage, cn, formatDateValue, useDebouncedCallback, useFormatContext, usePersistentState } from "@lattice-php/ui";
|
|
24
|
+
import { runAction } from "@lattice-php/action";
|
|
25
|
+
import { requestSignedUpload, xhrTransfer } from "@lattice-php/core/upload";
|
|
26
|
+
import { SimpleField } from "@lattice-php/form/components/fields/simple-field";
|
|
27
|
+
import { RICH_EDITOR_EXTENSION, ToolbarIconButton } from "@lattice-php/form/rich-editor";
|
|
28
|
+
import { useTable } from "@lattice-php/table/hooks/use-table";
|
|
29
|
+
import { useTableSelection } from "@lattice-php/table/hooks/use-table-selection";
|
|
30
|
+
import { getBulkActions } from "@lattice-php/table/lib/bulk";
|
|
22
31
|
export * from "@lattice-php/ui/i18n";
|
|
23
32
|
export * from "@lattice-php/form/toolkit";
|
|
24
|
-
export { Callouts, EventBridge, Icon, IconRenderer, IconRendererProvider, LATTICE_EVENT, LATTICE_REF_HEADER, OutletContext, Provider, RealtimeListeners, Renderer, SchemaLayout, SidebarCollapsedContext, SpriteProvider, Toaster, apiJson, builtinEffectHandlers, chatComponents, cn, columnCell, copyToClipboard, createLatticeApp, createLayoutResolver, createPageResolver, createRegistry, dispatchActionError, dispatchEffects, eagerComponent, effectHandler, extendRegistry, getActionEffects, initializeAppearance, isActionEffect, layoutComponents, lazyComponent, loadPluginModules, mergeEffectHandlers, nodeIdentity, onCallout, onToast, pageComponentName, registry, router, setRefRefreshEndpoint, updateAppearance, useAppearance, useChat, useColumnRegistry, useComponentRegistry, useEffectDispatcher, usePersistentState, useSidebarCollapsed, withHeaders, withRefHeader, withVisitHeaders };
|
|
33
|
+
export { Button, Callouts, Checkbox, ConfirmDialog, Dialog, DialogContent, DialogHeader, EventBridge, Icon, IconButton, IconRenderer, IconRendererProvider, Input, LATTICE_EVENT, LATTICE_REF_HEADER, Label, NativeSelect, OutletContext, PreviewableImage, Provider, RICH_EDITOR_EXTENSION, RealtimeListeners, RenderNode, Renderer, SchemaLayout, SidebarCollapsedContext, SimpleField, SpriteProvider, Toaster, ToolbarIconButton, announce, apiFetch, apiJson, attachTreeItemInstruction, builtinEffectHandlers, chatComponents, cn, columnCell, combine, copyToClipboard, createLatticeApp, createLayoutResolver, createPageResolver, createRegistry, dispatchActionError, dispatchEffects, draggable, dropTargetForElements, eagerComponent, effectHandler, extendRegistry, extractTreeItemInstruction, formatDateValue, getActionEffects, getBulkActions, initializeAppearance, isActionEffect, layoutComponents, lazyComponent, loadPluginModules, mergeEffectHandlers, nodeIdentity, onCallout, onToast, pageComponentName, registry, requestSignedUpload, router, runAction, setRefRefreshEndpoint, updateAppearance, useAppearance, useChat, useColumnRegistry, useComponentRegistry, useDebouncedCallback, useEffectDispatcher, useFormatContext, usePersistentState, useSidebarCollapsed, useTable, useTableSelection, withHeaders, withRefHeader, withVisitHeaders, xhrTransfer, xsrfToken };
|
package/dist/vite.d.ts
CHANGED
|
@@ -30,22 +30,27 @@ export type LatticeComponentPackage = {
|
|
|
30
30
|
dir: string;
|
|
31
31
|
/** Absolute path to the package's JS plugin entry. */
|
|
32
32
|
plugin: string;
|
|
33
|
+
/** Absolute path to the package's stylesheet, when it declares one. */
|
|
34
|
+
css?: string;
|
|
35
|
+
/** Absolute path to the package's icon directory, when it declares one. */
|
|
36
|
+
icons?: string;
|
|
37
|
+
};
|
|
38
|
+
type LatticeManifest = {
|
|
39
|
+
plugin?: string;
|
|
40
|
+
css?: string;
|
|
41
|
+
icons?: string;
|
|
33
42
|
};
|
|
34
43
|
type InstalledPackage = {
|
|
35
44
|
name: string;
|
|
36
45
|
"install-path"?: string;
|
|
37
46
|
extra?: {
|
|
38
|
-
lattice?:
|
|
39
|
-
plugin?: string;
|
|
40
|
-
};
|
|
47
|
+
lattice?: LatticeManifest;
|
|
41
48
|
};
|
|
42
49
|
};
|
|
43
50
|
type RootPackageJson = {
|
|
44
51
|
name?: string;
|
|
45
52
|
extra?: {
|
|
46
|
-
lattice?:
|
|
47
|
-
plugin?: string;
|
|
48
|
-
};
|
|
53
|
+
lattice?: LatticeManifest;
|
|
49
54
|
};
|
|
50
55
|
};
|
|
51
56
|
/**
|
|
@@ -77,5 +82,5 @@ export declare function discoverComponentPackages(appRoot: string): LatticeCompo
|
|
|
77
82
|
*/
|
|
78
83
|
export declare function componentPackagesPlugin(packages: LatticeComponentPackage[]): Plugin;
|
|
79
84
|
export declare function latticeConfig(options?: LatticeViteOptions): ConfigWithTest;
|
|
80
|
-
export declare function resolveIconOptions(options: LatticeViteOptions): SvgSpriteOptions | null;
|
|
85
|
+
export declare function resolveIconOptions(options: LatticeViteOptions, packages?: LatticeComponentPackage[]): SvgSpriteOptions | null;
|
|
81
86
|
export {};
|
package/dist/vite.js
CHANGED
|
@@ -6,16 +6,23 @@ import { searchForWorkspaceRoot } from "vite";
|
|
|
6
6
|
//#region resources/js/vite.ts
|
|
7
7
|
function lattice(options = {}) {
|
|
8
8
|
const { appRoot } = resolveRoots(options);
|
|
9
|
+
const packages = discoverComponentPackages(appRoot);
|
|
9
10
|
const plugins = [
|
|
10
11
|
corePlugin(options),
|
|
11
12
|
optionalPeersPlugin(),
|
|
12
|
-
componentPackagesPlugin(
|
|
13
|
+
componentPackagesPlugin(packages),
|
|
13
14
|
typescriptPlugin(options)
|
|
14
15
|
];
|
|
15
|
-
const iconOptions = resolveIconOptions(options);
|
|
16
|
+
const iconOptions = resolveIconOptions(options, packages);
|
|
16
17
|
if (iconOptions) plugins.push(svgSprite(iconOptions));
|
|
17
18
|
return plugins;
|
|
18
19
|
}
|
|
20
|
+
function resolveManifestPaths(manifest, dir) {
|
|
21
|
+
return {
|
|
22
|
+
...typeof manifest.css === "string" ? { css: path.resolve(dir, manifest.css) } : {},
|
|
23
|
+
...typeof manifest.icons === "string" ? { icons: path.resolve(dir, manifest.icons) } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Resolve every Composer package that declares `extra.lattice.plugin` into an
|
|
21
28
|
* absolute plugin-entry path. `installPathsRelativeTo` is `vendor/composer` (the
|
|
@@ -23,13 +30,15 @@ function lattice(options = {}) {
|
|
|
23
30
|
*/
|
|
24
31
|
function collectComponentPackages(installed, installPathsRelativeTo) {
|
|
25
32
|
return (Array.isArray(installed) ? installed : installed.packages ?? []).flatMap((pkg) => {
|
|
26
|
-
const
|
|
33
|
+
const manifest = pkg.extra?.lattice ?? {};
|
|
34
|
+
const entry = manifest.plugin;
|
|
27
35
|
if (typeof entry !== "string") return [];
|
|
28
36
|
const dir = path.resolve(installPathsRelativeTo, pkg["install-path"] ?? `../${pkg.name}`);
|
|
29
37
|
return [{
|
|
30
38
|
name: pkg.name,
|
|
31
39
|
dir,
|
|
32
|
-
plugin: path.resolve(dir, entry)
|
|
40
|
+
plugin: path.resolve(dir, entry),
|
|
41
|
+
...resolveManifestPaths(manifest, dir)
|
|
33
42
|
}];
|
|
34
43
|
});
|
|
35
44
|
}
|
|
@@ -41,12 +50,13 @@ function collectComponentPackages(installed, installPathsRelativeTo) {
|
|
|
41
50
|
* the package itself is the app root).
|
|
42
51
|
*/
|
|
43
52
|
function collectRootComponentPackage(composerJson, appRoot) {
|
|
44
|
-
const
|
|
45
|
-
if (typeof
|
|
53
|
+
const manifest = composerJson.extra?.lattice ?? {};
|
|
54
|
+
if (typeof manifest.plugin !== "string" || typeof composerJson.name !== "string") return [];
|
|
46
55
|
return [{
|
|
47
56
|
name: composerJson.name,
|
|
48
57
|
dir: appRoot,
|
|
49
|
-
plugin: path.resolve(appRoot,
|
|
58
|
+
plugin: path.resolve(appRoot, manifest.plugin),
|
|
59
|
+
...resolveManifestPaths(manifest, appRoot)
|
|
50
60
|
}];
|
|
51
61
|
}
|
|
52
62
|
/**
|
|
@@ -84,7 +94,12 @@ function componentPackagesPlugin(packages) {
|
|
|
84
94
|
name: "lattice:component-packages",
|
|
85
95
|
config(config) {
|
|
86
96
|
if (packages.length === 0) return {};
|
|
87
|
-
|
|
97
|
+
const workspaceRoot = searchForWorkspaceRoot(config.root ?? process.cwd());
|
|
98
|
+
const alias = Object.fromEntries(packages.flatMap((pkg) => pkg.css ? [[`@${pkg.name}/css`, pkg.css]] : []));
|
|
99
|
+
return {
|
|
100
|
+
...Object.keys(alias).length > 0 ? { resolve: { alias } } : {},
|
|
101
|
+
server: { fs: { allow: [workspaceRoot, ...packages.map((pkg) => pkg.dir)] } }
|
|
102
|
+
};
|
|
88
103
|
},
|
|
89
104
|
resolveId(id) {
|
|
90
105
|
return id === VIRTUAL_PLUGINS_ID ? RESOLVED_VIRTUAL_PLUGINS_ID : null;
|
|
@@ -102,6 +117,7 @@ function latticeConfig(options = {}) {
|
|
|
102
117
|
...options.source ? { alias: {
|
|
103
118
|
"@lattice-php/lattice/css": path.resolve(root, "../ui/resources/css/lattice.css"),
|
|
104
119
|
"@lattice-php/lattice": path.resolve(root, "resources/js"),
|
|
120
|
+
"@lattice-php/action": path.resolve(root, "../action/resources/js"),
|
|
105
121
|
"@lattice-php/core": path.resolve(root, "../core/resources/js"),
|
|
106
122
|
"@lattice-php/form": path.resolve(root, "../form/resources/js"),
|
|
107
123
|
"@lattice-php/table": path.resolve(root, "../table/resources/js"),
|
|
@@ -117,6 +133,7 @@ function latticeConfig(options = {}) {
|
|
|
117
133
|
server: options.source ? { fs: { allow: [searchForWorkspaceRoot(appRoot), root] } } : void 0,
|
|
118
134
|
test: { server: { deps: { inline: [
|
|
119
135
|
"@lattice-php/lattice",
|
|
136
|
+
"@lattice-php/action",
|
|
120
137
|
"@lattice-php/core",
|
|
121
138
|
"@lattice-php/form",
|
|
122
139
|
"@lattice-php/table",
|
|
@@ -192,7 +209,7 @@ function typescriptPlugin(options) {
|
|
|
192
209
|
}
|
|
193
210
|
};
|
|
194
211
|
}
|
|
195
|
-
function resolveIconOptions(options) {
|
|
212
|
+
function resolveIconOptions(options, packages = []) {
|
|
196
213
|
const icons = options.icons ?? true;
|
|
197
214
|
if (icons === false) return null;
|
|
198
215
|
const { root } = resolveRoots(options);
|
|
@@ -204,7 +221,11 @@ function resolveIconOptions(options) {
|
|
|
204
221
|
};
|
|
205
222
|
return {
|
|
206
223
|
...spriteOptions,
|
|
207
|
-
iconDirs: [
|
|
224
|
+
iconDirs: [
|
|
225
|
+
path.resolve(root, "../ui/resources/icons"),
|
|
226
|
+
...packages.flatMap((pkg) => pkg.icons ? [pkg.icons] : []),
|
|
227
|
+
...dirs
|
|
228
|
+
],
|
|
208
229
|
...dts === false ? {} : { dts: {
|
|
209
230
|
...defaultTypes,
|
|
210
231
|
...dts
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../resources/js/vite.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { svgSprite } from \"@lattice-php/vite-svg-sprite\";\nimport type { IconTypesOptions, SvgSpriteOptions } from \"@lattice-php/vite-svg-sprite\";\nimport { searchForWorkspaceRoot } from \"vite\";\nimport type { Plugin, PluginOption, UserConfig } from \"vite\";\nimport { refreshTypeScriptTypes } from \"./vite-typescript-refresh.ts\";\n\ntype InlineDependency = string | RegExp;\n\ntype ConfigWithTest = UserConfig & {\n test?: {\n server?: {\n deps?: {\n inline?: InlineDependency[];\n };\n };\n };\n};\n\nexport type LatticeViteIconsOptions = Omit<SvgSpriteOptions, \"dts\" | \"iconDirs\"> & {\n dirs?: string[];\n dts?: Partial<IconTypesOptions> | false;\n};\n\nexport type LatticeViteOptions = {\n appRoot?: string;\n icons?: boolean | LatticeViteIconsOptions;\n root?: string;\n source?: boolean;\n /** Refresh generated TypeScript types via the dev server. Defaults to `true`. */\n typescript?: boolean;\n};\n\ntype Roots = {\n appRoot: string;\n root: string;\n};\n\nexport function lattice(options: LatticeViteOptions = {}): PluginOption[] {\n const { appRoot } = resolveRoots(options);\n const plugins: PluginOption[] = [\n corePlugin(options),\n optionalPeersPlugin(),\n componentPackagesPlugin(discoverComponentPackages(appRoot)),\n typescriptPlugin(options),\n ];\n const iconOptions = resolveIconOptions(options);\n\n if (iconOptions) {\n plugins.push(svgSprite(iconOptions));\n }\n\n return plugins;\n}\n\n/** A Composer package that contributes a Lattice component plugin. */\nexport type LatticeComponentPackage = {\n name: string;\n /** Absolute path to the package's installed directory. */\n dir: string;\n /** Absolute path to the package's JS plugin entry. */\n plugin: string;\n};\n\ntype InstalledPackage = {\n name: string;\n \"install-path\"?: string;\n extra?: { lattice?: { plugin?: string } };\n};\n\ntype RootPackageJson = {\n name?: string;\n extra?: { lattice?: { plugin?: string } };\n};\n\n/**\n * Resolve every Composer package that declares `extra.lattice.plugin` into an\n * absolute plugin-entry path. `installPathsRelativeTo` is `vendor/composer` (the\n * dir `installed.json` records its `install-path`s against).\n */\nexport function collectComponentPackages(\n installed: { packages?: InstalledPackage[] } | InstalledPackage[],\n installPathsRelativeTo: string,\n): LatticeComponentPackage[] {\n const packages = Array.isArray(installed) ? installed : (installed.packages ?? []);\n\n return packages.flatMap((pkg) => {\n const entry = pkg.extra?.lattice?.plugin;\n\n if (typeof entry !== \"string\") {\n return [];\n }\n\n const dir = path.resolve(installPathsRelativeTo, pkg[\"install-path\"] ?? `../${pkg.name}`);\n\n return [{ name: pkg.name, dir, plugin: path.resolve(dir, entry) }];\n });\n}\n\n/**\n * Resolve the composer ROOT project's own `extra.lattice.plugin` — Composer\n * never lists the root package in `installed.json`, so a component package\n * declaring the plugin entry in its own composer.json would otherwise be\n * invisible to its own dev server (e.g. inside a testbench workbench, where\n * the package itself is the app root).\n */\nexport function collectRootComponentPackage(\n composerJson: RootPackageJson,\n appRoot: string,\n): LatticeComponentPackage[] {\n const entry = composerJson.extra?.lattice?.plugin;\n\n if (typeof entry !== \"string\" || typeof composerJson.name !== \"string\") {\n return [];\n }\n\n return [{ name: composerJson.name, dir: appRoot, plugin: path.resolve(appRoot, entry) }];\n}\n\n/**\n * Read `<appRoot>/vendor/composer/installed.json` and `<appRoot>/composer.json`\n * and collect every component package they contribute.\n */\nexport function discoverComponentPackages(appRoot: string): LatticeComponentPackage[] {\n const composerDir = path.resolve(appRoot, \"vendor/composer\");\n\n let installed: LatticeComponentPackage[] = [];\n\n try {\n const raw = readFileSync(path.join(composerDir, \"installed.json\"), \"utf8\");\n installed = collectComponentPackages(JSON.parse(raw), composerDir);\n } catch {\n installed = [];\n }\n\n let root: LatticeComponentPackage[] = [];\n\n try {\n const raw = readFileSync(path.join(appRoot, \"composer.json\"), \"utf8\");\n root = collectRootComponentPackage(JSON.parse(raw), appRoot);\n } catch {\n root = [];\n }\n\n return [...installed, ...root];\n}\n\nconst VIRTUAL_PLUGINS_ID = \"virtual:lattice/plugins\";\nconst RESOLVED_VIRTUAL_PLUGINS_ID = `\\0${VIRTUAL_PLUGINS_ID}`;\n\n/**\n * Exposes the discovered component packages as `virtual:lattice/plugins` — a\n * module whose default export is the array of their plugin objects,\n * ready for `extendRegistry(registry, ...plugins)`. Also grants Vite filesystem\n * access to each package dir so its source compiles from `vendor/` (or a symlink).\n */\nexport function componentPackagesPlugin(packages: LatticeComponentPackage[]): Plugin {\n return {\n name: \"lattice:component-packages\",\n config(config) {\n if (packages.length === 0) {\n return {};\n }\n\n const workspaceRoot = searchForWorkspaceRoot(config.root ?? process.cwd());\n\n return { server: { fs: { allow: [workspaceRoot, ...packages.map((pkg) => pkg.dir)] } } };\n },\n resolveId(id) {\n return id === VIRTUAL_PLUGINS_ID ? RESOLVED_VIRTUAL_PLUGINS_ID : null;\n },\n load(id) {\n if (id !== RESOLVED_VIRTUAL_PLUGINS_ID) {\n return null;\n }\n\n const imports = packages\n .map((pkg, index) => `import p${index} from ${JSON.stringify(pkg.plugin)};`)\n .join(\"\\n\");\n const list = packages.map((_, index) => `p${index}`).join(\", \");\n\n return `${imports}\\nexport default [${list}];\\n`;\n },\n };\n}\n\nexport function latticeConfig(options: LatticeViteOptions = {}): ConfigWithTest {\n const { appRoot, root } = resolveRoots(options);\n\n return {\n resolve: {\n // A react alias would break SSR: Vite only externalizes bare specifiers,\n // so an absolute path inlines react's CJS into the SSR module runner.\n // `dedupe` alone keeps the app on a single React copy, symlinks included.\n ...(options.source\n ? {\n alias: {\n \"@lattice-php/lattice/css\": path.resolve(root, \"../ui/resources/css/lattice.css\"),\n \"@lattice-php/lattice\": path.resolve(root, \"resources/js\"),\n \"@lattice-php/core\": path.resolve(root, \"../core/resources/js\"),\n \"@lattice-php/form\": path.resolve(root, \"../form/resources/js\"),\n \"@lattice-php/table\": path.resolve(root, \"../table/resources/js\"),\n \"@lattice-php/ui/css\": path.resolve(root, \"../ui/resources/css/lattice.css\"),\n \"@lattice-php/ui\": path.resolve(root, \"../ui/resources/js\"),\n },\n }\n : {}),\n dedupe: [\"@inertiajs/react\", \"react\", \"react-dom\"],\n },\n server: options.source\n ? {\n fs: {\n allow: [searchForWorkspaceRoot(appRoot), root],\n },\n }\n : undefined,\n test: {\n server: {\n deps: {\n inline: [\n \"@lattice-php/lattice\",\n \"@lattice-php/core\",\n \"@lattice-php/form\",\n \"@lattice-php/table\",\n \"@lattice-php/ui\",\n /[/\\\\]lattice[/\\\\]dist[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]@radix-ui[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]@tiptap[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]react-i18next[/\\\\]/,\n ],\n },\n },\n },\n };\n}\n\nfunction corePlugin(options: LatticeViteOptions): Plugin {\n return {\n name: \"lattice\",\n config() {\n return latticeConfig(options);\n },\n };\n}\n\nconst OPTIONAL_PEER_STUB_PREFIX = \"\\0lattice-optional-peer/\";\n\n/**\n * Real-time listeners statically import their optional Echo peers. A consumer\n * that never uses real-time should still build, so stub a missing peer with\n * hooks that throw — the `RealtimeListeners` error boundary then degrades\n * gracefully and warns to install the peer, exactly as when it is absent.\n */\nconst OPTIONAL_PEER_STUBS: Record<string, string> = {\n \"@laravel/echo-react\": [\n \"const missing = () => {\",\n \" throw new Error(\",\n ' \"[lattice] Real-time listeners require @laravel/echo-react. Install it and call configureEcho().\",',\n \" );\",\n \"};\",\n \"export const useEcho = missing;\",\n \"export const useEchoPublic = missing;\",\n \"export const useEchoPresence = missing;\",\n \"export const useEchoNotification = missing;\",\n ].join(\"\\n\"),\n};\n\nfunction optionalPeersPlugin(): Plugin {\n return {\n name: \"lattice:optional-peers\",\n enforce: \"pre\",\n async resolveId(id) {\n if (!Object.prototype.hasOwnProperty.call(OPTIONAL_PEER_STUBS, id)) {\n return null;\n }\n\n const installed = await this.resolve(id, undefined, { skipSelf: true });\n\n return installed ? null : `${OPTIONAL_PEER_STUB_PREFIX}${id}`;\n },\n load(id) {\n if (!id.startsWith(OPTIONAL_PEER_STUB_PREFIX)) {\n return null;\n }\n\n return OPTIONAL_PEER_STUBS[id.slice(OPTIONAL_PEER_STUB_PREFIX.length)] ?? null;\n },\n };\n}\n\n/**\n * Refreshes `node.props` typings from the app's own `php artisan\n * lattice:typescript` whenever the dev server starts — installing or updating\n * a component package would otherwise leave its generated types stale until\n * someone remembers to run the command by hand. Dev-server only: a production\n * build machine may not have PHP installed, and the generated file is a dev\n * ergonomics artifact, not a build input.\n *\n * Module-private like its siblings `optionalPeersPlugin`/`corePlugin` — the\n * `refreshTypeScriptTypes` DI seam it defers to lives in\n * `./vite-typescript-refresh`, which isn't part of the published `vite`\n * subpath either (see that module for why).\n */\nfunction typescriptPlugin(options: LatticeViteOptions): Plugin {\n return {\n name: \"lattice:typescript\",\n apply: \"serve\",\n configureServer(server) {\n const typescript = options.typescript ?? true;\n\n if (typescript === false) {\n return;\n }\n\n const { appRoot } = resolveRoots(options);\n\n refreshTypeScriptTypes(appRoot, server.config.logger);\n },\n };\n}\n\nexport function resolveIconOptions(options: LatticeViteOptions): SvgSpriteOptions | null {\n const icons = options.icons ?? true;\n\n if (icons === false) {\n return null;\n }\n\n const { root } = resolveRoots(options);\n const iconOptions = icons === true ? {} : icons;\n const { dirs = [], dts, ...spriteOptions } = iconOptions;\n const defaultTypes = {\n file: \"resources/js/types/sprite-icons.ts\",\n augmentModule: \"@lattice-php/ui\",\n augmentInterface: \"KnownIcons\",\n };\n\n return {\n ...spriteOptions,\n iconDirs: [path.resolve(root, \"../ui/resources/icons\"), ...dirs],\n ...(dts === false ? {} : { dts: { ...defaultTypes, ...dts } }),\n };\n}\n\nfunction resolveRoots(options: LatticeViteOptions): Roots {\n const appRoot = options.appRoot ?? process.cwd();\n const root = options.root ?? path.resolve(appRoot, \"vendor/lattice-php/lattice\");\n\n return { appRoot, root };\n}\n"],"mappings":";;;;;;AAuCA,SAAgB,QAAQ,UAA8B,CAAC,GAAmB;CACxE,MAAM,EAAE,YAAY,aAAa,OAAO;CACxC,MAAM,UAA0B;EAC9B,WAAW,OAAO;EAClB,oBAAoB;EACpB,wBAAwB,0BAA0B,OAAO,CAAC;EAC1D,iBAAiB,OAAO;CAC1B;CACA,MAAM,cAAc,mBAAmB,OAAO;CAE9C,IAAI,aACF,QAAQ,KAAK,UAAU,WAAW,CAAC;CAGrC,OAAO;AACT;;;;;;AA2BA,SAAgB,yBACd,WACA,wBAC2B;CAG3B,QAFiB,MAAM,QAAQ,SAAS,IAAI,YAAa,UAAU,YAAY,CAAC,EAAA,CAEhE,SAAS,QAAQ;EAC/B,MAAM,QAAQ,IAAI,OAAO,SAAS;EAElC,IAAI,OAAO,UAAU,UACnB,OAAO,CAAC;EAGV,MAAM,MAAM,KAAK,QAAQ,wBAAwB,IAAI,mBAAmB,MAAM,IAAI,MAAM;EAExF,OAAO,CAAC;GAAE,MAAM,IAAI;GAAM;GAAK,QAAQ,KAAK,QAAQ,KAAK,KAAK;EAAE,CAA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ileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { svgSprite } from \"@lattice-php/vite-svg-sprite\";\nimport type { IconTypesOptions, SvgSpriteOptions } from \"@lattice-php/vite-svg-sprite\";\nimport { searchForWorkspaceRoot } from \"vite\";\nimport type { Plugin, PluginOption, UserConfig } from \"vite\";\nimport { refreshTypeScriptTypes } from \"./vite-typescript-refresh.ts\";\n\ntype InlineDependency = string | RegExp;\n\ntype ConfigWithTest = UserConfig & {\n test?: {\n server?: {\n deps?: {\n inline?: InlineDependency[];\n };\n };\n };\n};\n\nexport type LatticeViteIconsOptions = Omit<SvgSpriteOptions, \"dts\" | \"iconDirs\"> & {\n dirs?: string[];\n dts?: Partial<IconTypesOptions> | false;\n};\n\nexport type LatticeViteOptions = {\n appRoot?: string;\n icons?: boolean | LatticeViteIconsOptions;\n root?: string;\n source?: boolean;\n /** Refresh generated TypeScript types via the dev server. Defaults to `true`. */\n typescript?: boolean;\n};\n\ntype Roots = {\n appRoot: string;\n root: string;\n};\n\nexport function lattice(options: LatticeViteOptions = {}): PluginOption[] {\n const { appRoot } = resolveRoots(options);\n const packages = discoverComponentPackages(appRoot);\n const plugins: PluginOption[] = [\n corePlugin(options),\n optionalPeersPlugin(),\n componentPackagesPlugin(packages),\n typescriptPlugin(options),\n ];\n const iconOptions = resolveIconOptions(options, packages);\n\n if (iconOptions) {\n plugins.push(svgSprite(iconOptions));\n }\n\n return plugins;\n}\n\n/** A Composer package that contributes a Lattice component plugin. */\nexport type LatticeComponentPackage = {\n name: string;\n /** Absolute path to the package's installed directory. */\n dir: string;\n /** Absolute path to the package's JS plugin entry. */\n plugin: string;\n /** Absolute path to the package's stylesheet, when it declares one. */\n css?: string;\n /** Absolute path to the package's icon directory, when it declares one. */\n icons?: string;\n};\n\ntype LatticeManifest = { plugin?: string; css?: string; icons?: string };\n\ntype InstalledPackage = {\n name: string;\n \"install-path\"?: string;\n extra?: { lattice?: LatticeManifest };\n};\n\ntype RootPackageJson = {\n name?: string;\n extra?: { lattice?: LatticeManifest };\n};\n\nfunction resolveManifestPaths(\n manifest: LatticeManifest,\n dir: string,\n): Pick<LatticeComponentPackage, \"css\" | \"icons\"> {\n return {\n ...(typeof manifest.css === \"string\" ? { css: path.resolve(dir, manifest.css) } : {}),\n ...(typeof manifest.icons === \"string\" ? { icons: path.resolve(dir, manifest.icons) } : {}),\n };\n}\n\n/**\n * Resolve every Composer package that declares `extra.lattice.plugin` into an\n * absolute plugin-entry path. `installPathsRelativeTo` is `vendor/composer` (the\n * dir `installed.json` records its `install-path`s against).\n */\nexport function collectComponentPackages(\n installed: { packages?: InstalledPackage[] } | InstalledPackage[],\n installPathsRelativeTo: string,\n): LatticeComponentPackage[] {\n const packages = Array.isArray(installed) ? installed : (installed.packages ?? []);\n\n return packages.flatMap((pkg) => {\n const manifest = pkg.extra?.lattice ?? {};\n const entry = manifest.plugin;\n\n if (typeof entry !== \"string\") {\n return [];\n }\n\n const dir = path.resolve(installPathsRelativeTo, pkg[\"install-path\"] ?? `../${pkg.name}`);\n\n return [\n {\n name: pkg.name,\n dir,\n plugin: path.resolve(dir, entry),\n ...resolveManifestPaths(manifest, dir),\n },\n ];\n });\n}\n\n/**\n * Resolve the composer ROOT project's own `extra.lattice.plugin` — Composer\n * never lists the root package in `installed.json`, so a component package\n * declaring the plugin entry in its own composer.json would otherwise be\n * invisible to its own dev server (e.g. inside a testbench workbench, where\n * the package itself is the app root).\n */\nexport function collectRootComponentPackage(\n composerJson: RootPackageJson,\n appRoot: string,\n): LatticeComponentPackage[] {\n const manifest = composerJson.extra?.lattice ?? {};\n\n if (typeof manifest.plugin !== \"string\" || typeof composerJson.name !== \"string\") {\n return [];\n }\n\n return [\n {\n name: composerJson.name,\n dir: appRoot,\n plugin: path.resolve(appRoot, manifest.plugin),\n ...resolveManifestPaths(manifest, appRoot),\n },\n ];\n}\n\n/**\n * Read `<appRoot>/vendor/composer/installed.json` and `<appRoot>/composer.json`\n * and collect every component package they contribute.\n */\nexport function discoverComponentPackages(appRoot: string): LatticeComponentPackage[] {\n const composerDir = path.resolve(appRoot, \"vendor/composer\");\n\n let installed: LatticeComponentPackage[] = [];\n\n try {\n const raw = readFileSync(path.join(composerDir, \"installed.json\"), \"utf8\");\n installed = collectComponentPackages(JSON.parse(raw), composerDir);\n } catch {\n installed = [];\n }\n\n let root: LatticeComponentPackage[] = [];\n\n try {\n const raw = readFileSync(path.join(appRoot, \"composer.json\"), \"utf8\");\n root = collectRootComponentPackage(JSON.parse(raw), appRoot);\n } catch {\n root = [];\n }\n\n return [...installed, ...root];\n}\n\nconst VIRTUAL_PLUGINS_ID = \"virtual:lattice/plugins\";\nconst RESOLVED_VIRTUAL_PLUGINS_ID = `\\0${VIRTUAL_PLUGINS_ID}`;\n\n/**\n * Exposes the discovered component packages as `virtual:lattice/plugins` — a\n * module whose default export is the array of their plugin objects,\n * ready for `extendRegistry(registry, ...plugins)`. Also grants Vite filesystem\n * access to each package dir so its source compiles from `vendor/` (or a symlink).\n */\nexport function componentPackagesPlugin(packages: LatticeComponentPackage[]): Plugin {\n return {\n name: \"lattice:component-packages\",\n config(config) {\n if (packages.length === 0) {\n return {};\n }\n\n const workspaceRoot = searchForWorkspaceRoot(config.root ?? process.cwd());\n // Vite's mergeAlias puts plugin-config aliases in front of the user config's,\n // so this specific `/css` alias wins over a user's broader package-dir alias.\n const alias = Object.fromEntries(\n packages.flatMap((pkg) => (pkg.css ? [[`@${pkg.name}/css`, pkg.css]] : [])),\n );\n\n return {\n ...(Object.keys(alias).length > 0 ? { resolve: { alias } } : {}),\n server: { fs: { allow: [workspaceRoot, ...packages.map((pkg) => pkg.dir)] } },\n };\n },\n resolveId(id) {\n return id === VIRTUAL_PLUGINS_ID ? RESOLVED_VIRTUAL_PLUGINS_ID : null;\n },\n load(id) {\n if (id !== RESOLVED_VIRTUAL_PLUGINS_ID) {\n return null;\n }\n\n const imports = packages\n .map((pkg, index) => `import p${index} from ${JSON.stringify(pkg.plugin)};`)\n .join(\"\\n\");\n const list = packages.map((_, index) => `p${index}`).join(\", \");\n\n return `${imports}\\nexport default [${list}];\\n`;\n },\n };\n}\n\nexport function latticeConfig(options: LatticeViteOptions = {}): ConfigWithTest {\n const { appRoot, root } = resolveRoots(options);\n\n return {\n resolve: {\n // A react alias would break SSR: Vite only externalizes bare specifiers,\n // so an absolute path inlines react's CJS into the SSR module runner.\n // `dedupe` alone keeps the app on a single React copy, symlinks included.\n ...(options.source\n ? {\n alias: {\n \"@lattice-php/lattice/css\": path.resolve(root, \"../ui/resources/css/lattice.css\"),\n \"@lattice-php/lattice\": path.resolve(root, \"resources/js\"),\n \"@lattice-php/action\": path.resolve(root, \"../action/resources/js\"),\n \"@lattice-php/core\": path.resolve(root, \"../core/resources/js\"),\n \"@lattice-php/form\": path.resolve(root, \"../form/resources/js\"),\n \"@lattice-php/table\": path.resolve(root, \"../table/resources/js\"),\n \"@lattice-php/ui/css\": path.resolve(root, \"../ui/resources/css/lattice.css\"),\n \"@lattice-php/ui\": path.resolve(root, \"../ui/resources/js\"),\n },\n }\n : {}),\n dedupe: [\"@inertiajs/react\", \"react\", \"react-dom\"],\n },\n server: options.source\n ? {\n fs: {\n allow: [searchForWorkspaceRoot(appRoot), root],\n },\n }\n : undefined,\n test: {\n server: {\n deps: {\n inline: [\n \"@lattice-php/lattice\",\n \"@lattice-php/action\",\n \"@lattice-php/core\",\n \"@lattice-php/form\",\n \"@lattice-php/table\",\n \"@lattice-php/ui\",\n /[/\\\\]lattice[/\\\\]dist[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]@radix-ui[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]@tiptap[/\\\\]/,\n /[/\\\\]lattice[/\\\\]node_modules[/\\\\]react-i18next[/\\\\]/,\n ],\n },\n },\n },\n };\n}\n\nfunction corePlugin(options: LatticeViteOptions): Plugin {\n return {\n name: \"lattice\",\n config() {\n return latticeConfig(options);\n },\n };\n}\n\nconst OPTIONAL_PEER_STUB_PREFIX = \"\\0lattice-optional-peer/\";\n\n/**\n * Real-time listeners statically import their optional Echo peers. A consumer\n * that never uses real-time should still build, so stub a missing peer with\n * hooks that throw — the `RealtimeListeners` error boundary then degrades\n * gracefully and warns to install the peer, exactly as when it is absent.\n */\nconst OPTIONAL_PEER_STUBS: Record<string, string> = {\n \"@laravel/echo-react\": [\n \"const missing = () => {\",\n \" throw new Error(\",\n ' \"[lattice] Real-time listeners require @laravel/echo-react. Install it and call configureEcho().\",',\n \" );\",\n \"};\",\n \"export const useEcho = missing;\",\n \"export const useEchoPublic = missing;\",\n \"export const useEchoPresence = missing;\",\n \"export const useEchoNotification = missing;\",\n ].join(\"\\n\"),\n};\n\nfunction optionalPeersPlugin(): Plugin {\n return {\n name: \"lattice:optional-peers\",\n enforce: \"pre\",\n async resolveId(id) {\n if (!Object.prototype.hasOwnProperty.call(OPTIONAL_PEER_STUBS, id)) {\n return null;\n }\n\n const installed = await this.resolve(id, undefined, { skipSelf: true });\n\n return installed ? null : `${OPTIONAL_PEER_STUB_PREFIX}${id}`;\n },\n load(id) {\n if (!id.startsWith(OPTIONAL_PEER_STUB_PREFIX)) {\n return null;\n }\n\n return OPTIONAL_PEER_STUBS[id.slice(OPTIONAL_PEER_STUB_PREFIX.length)] ?? null;\n },\n };\n}\n\n/**\n * Refreshes `node.props` typings from the app's own `php artisan\n * lattice:typescript` whenever the dev server starts — installing or updating\n * a component package would otherwise leave its generated types stale until\n * someone remembers to run the command by hand. Dev-server only: a production\n * build machine may not have PHP installed, and the generated file is a dev\n * ergonomics artifact, not a build input.\n *\n * Module-private like its siblings `optionalPeersPlugin`/`corePlugin` — the\n * `refreshTypeScriptTypes` DI seam it defers to lives in\n * `./vite-typescript-refresh`, which isn't part of the published `vite`\n * subpath either (see that module for why).\n */\nfunction typescriptPlugin(options: LatticeViteOptions): Plugin {\n return {\n name: \"lattice:typescript\",\n apply: \"serve\",\n configureServer(server) {\n const typescript = options.typescript ?? true;\n\n if (typescript === false) {\n return;\n }\n\n const { appRoot } = resolveRoots(options);\n\n refreshTypeScriptTypes(appRoot, server.config.logger);\n },\n };\n}\n\nexport function resolveIconOptions(\n options: LatticeViteOptions,\n packages: LatticeComponentPackage[] = [],\n): SvgSpriteOptions | null {\n const icons = options.icons ?? true;\n\n if (icons === false) {\n return null;\n }\n\n const { root } = resolveRoots(options);\n const iconOptions = icons === true ? {} : icons;\n const { dirs = [], dts, ...spriteOptions } = iconOptions;\n const defaultTypes = {\n file: \"resources/js/types/sprite-icons.ts\",\n augmentModule: \"@lattice-php/ui\",\n augmentInterface: \"KnownIcons\",\n };\n\n return {\n ...spriteOptions,\n iconDirs: [\n path.resolve(root, \"../ui/resources/icons\"),\n ...packages.flatMap((pkg) => (pkg.icons ? [pkg.icons] : [])),\n ...dirs,\n ],\n ...(dts === false ? {} : { dts: { ...defaultTypes, ...dts } }),\n };\n}\n\nfunction resolveRoots(options: LatticeViteOptions): Roots {\n const appRoot = options.appRoot ?? process.cwd();\n const root = options.root ?? path.resolve(appRoot, \"vendor/lattice-php/lattice\");\n\n return { appRoot, root };\n}\n"],"mappings":";;;;;;AAuCA,SAAgB,QAAQ,UAA8B,CAAC,GAAmB;CACxE,MAAM,EAAE,YAAY,aAAa,OAAO;CACxC,MAAM,WAAW,0BAA0B,OAAO;CAClD,MAAM,UAA0B;EAC9B,WAAW,OAAO;EAClB,oBAAoB;EACpB,wBAAwB,QAAQ;EAChC,iBAAiB,OAAO;CAC1B;CACA,MAAM,cAAc,mBAAmB,SAAS,QAAQ;CAExD,IAAI,aACF,QAAQ,KAAK,UAAU,WAAW,CAAC;CAGrC,OAAO;AACT;AA4BA,SAAS,qBACP,UACA,KACgD;CAChD,OAAO;EACL,GAAI,OAAO,SAAS,QAAQ,WAAW,EAAE,KAAK,KAAK,QAAQ,KAAK,SAAS,GAAG,EAAE,IAAI,CAAC;EACnF,GAAI,OAAO,SAAS,UAAU,WAAW,EAAE,OAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,EAAE,IAAI,CAA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