@benqoder/beam 0.1.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/LICENSE +21 -0
- package/README.md +1574 -0
- package/dist/DrawerFrame.d.ts +16 -0
- package/dist/DrawerFrame.d.ts.map +1 -0
- package/dist/DrawerFrame.js +12 -0
- package/dist/ModalFrame.d.ts +12 -0
- package/dist/ModalFrame.d.ts.map +1 -0
- package/dist/ModalFrame.js +8 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1847 -0
- package/dist/collect.d.ts +68 -0
- package/dist/collect.d.ts.map +1 -0
- package/dist/collect.js +90 -0
- package/dist/createBeam.d.ts +104 -0
- package/dist/createBeam.d.ts.map +1 -0
- package/dist/createBeam.js +421 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/render.d.ts +7 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +7 -0
- package/dist/types.d.ts +151 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/vite.d.ts +72 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +79 -0
- package/package.json +62 -0
- package/src/beam.css +288 -0
- package/src/virtual-beam.d.ts +4 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createBeam, KVSession, CookieSession } from './createBeam';
|
|
2
|
+
export { render } from './render';
|
|
3
|
+
export { ModalFrame } from './ModalFrame';
|
|
4
|
+
export { DrawerFrame } from './DrawerFrame';
|
|
5
|
+
export { collectActions, collectModals, collectDrawers, collectHandlers, } from './collect';
|
|
6
|
+
export type { ActionHandler, ModalHandler, DrawerHandler, BeamConfig, BeamInstance, BeamInitOptions, BeamUser, BeamContext, BeamVariables, AuthResolver, BeamSession, SessionConfig, SessionStorageFactory, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,OAAO,EACL,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,GAChB,MAAM,WAAW,CAAA;AAGlB,YAAY,EACV,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,aAAa,EACb,qBAAqB,GACtB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Main server-side exports for @benqoder/beam
|
|
2
|
+
export { createBeam, KVSession, CookieSession } from './createBeam';
|
|
3
|
+
export { render } from './render';
|
|
4
|
+
export { ModalFrame } from './ModalFrame';
|
|
5
|
+
export { DrawerFrame } from './DrawerFrame';
|
|
6
|
+
// Auto-discovery utilities
|
|
7
|
+
export { collectActions, collectModals, collectDrawers, collectHandlers, } from './collect';
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HtmlEscapedString } from 'hono/utils/html';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a Hono JSX node to a string.
|
|
4
|
+
* Handles both sync and async JSX nodes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function render(node: HtmlEscapedString | Promise<HtmlEscapedString>): Promise<string>;
|
|
7
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD;;;GAGG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GACnD,OAAO,CAAC,MAAM,CAAC,CAEjB"}
|
package/dist/render.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Hono, MiddlewareHandler } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* User type - customize per app via module augmentation
|
|
4
|
+
*/
|
|
5
|
+
export interface BeamUser {
|
|
6
|
+
id: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Session interface - abstracts away session ID management
|
|
11
|
+
* Uses KV storage under the hood
|
|
12
|
+
*/
|
|
13
|
+
export interface BeamSession {
|
|
14
|
+
/** Get value from session */
|
|
15
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
16
|
+
/** Set value in session */
|
|
17
|
+
set<T = unknown>(key: string, value: T): Promise<void>;
|
|
18
|
+
/** Delete value from session */
|
|
19
|
+
delete(key: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Render options for ctx.render()
|
|
23
|
+
*/
|
|
24
|
+
export interface RenderOptions {
|
|
25
|
+
/** JavaScript to execute on client after rendering */
|
|
26
|
+
script?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Context passed to all handlers
|
|
30
|
+
*/
|
|
31
|
+
export interface BeamContext<TEnv = object> {
|
|
32
|
+
env: TEnv;
|
|
33
|
+
user: BeamUser | null;
|
|
34
|
+
request: Request;
|
|
35
|
+
session: BeamSession;
|
|
36
|
+
/**
|
|
37
|
+
* Return JavaScript to execute on the client (no DOM update)
|
|
38
|
+
* @example ctx.script('showToast("Success!")')
|
|
39
|
+
*/
|
|
40
|
+
script(code: string): ActionResponse;
|
|
41
|
+
/**
|
|
42
|
+
* Return HTML with optional script to execute
|
|
43
|
+
* @example ctx.render(<ProductList />, { script: 'playSound("ding")' })
|
|
44
|
+
*/
|
|
45
|
+
render(html: string | Promise<string>, options?: RenderOptions): ActionResponse | Promise<ActionResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Redirect the client to a new URL
|
|
48
|
+
* @example ctx.redirect('/dashboard')
|
|
49
|
+
* @example ctx.redirect('https://example.com')
|
|
50
|
+
*/
|
|
51
|
+
redirect(url: string): ActionResponse;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Auth resolver function - user provides this to extract user from request
|
|
55
|
+
*/
|
|
56
|
+
export type AuthResolver<TEnv = object> = (request: Request, env: TEnv) => Promise<BeamUser | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Response type for actions - can include HTML and/or script to execute
|
|
59
|
+
*/
|
|
60
|
+
export interface ActionResponse {
|
|
61
|
+
/** HTML to render (optional) */
|
|
62
|
+
html?: string;
|
|
63
|
+
/** JavaScript to execute on client (optional) */
|
|
64
|
+
script?: string;
|
|
65
|
+
/** URL to redirect to (optional) */
|
|
66
|
+
redirect?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Type for action handlers - receives context and data, returns ActionResponse
|
|
70
|
+
*/
|
|
71
|
+
export type ActionHandler<TEnv = object> = (ctx: BeamContext<TEnv>, data: Record<string, unknown>) => Promise<ActionResponse> | ActionResponse;
|
|
72
|
+
/**
|
|
73
|
+
* Type for modal handlers - receives context and params, returns HTML string
|
|
74
|
+
*/
|
|
75
|
+
export type ModalHandler<TEnv = object> = (ctx: BeamContext<TEnv>, params: Record<string, unknown>) => Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Type for drawer handlers - receives context and params, returns HTML string
|
|
78
|
+
*/
|
|
79
|
+
export type DrawerHandler<TEnv = object> = (ctx: BeamContext<TEnv>, params: Record<string, unknown>) => Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Factory function to create a session storage adapter.
|
|
82
|
+
* Called with the session ID and environment, returns a BeamSession implementation.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Custom KV storage
|
|
87
|
+
* const kvStorage: SessionStorageFactory<Env> = (sessionId, env) =>
|
|
88
|
+
* new KVSession(sessionId, env.KV)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export type SessionStorageFactory<TEnv = object> = (sessionId: string, env: TEnv) => BeamSession;
|
|
92
|
+
/**
|
|
93
|
+
* Session configuration
|
|
94
|
+
*/
|
|
95
|
+
export interface SessionConfig<TEnv = object> {
|
|
96
|
+
/** Secret key for signing session cookies (can be empty if secretEnvKey is provided) */
|
|
97
|
+
secret: string;
|
|
98
|
+
/** Environment variable name containing the secret (used at runtime) */
|
|
99
|
+
secretEnvKey?: string;
|
|
100
|
+
/** Cookie name (default: 'beam_sid') */
|
|
101
|
+
cookieName?: string;
|
|
102
|
+
/** Cookie max age in seconds (default: 1 year) */
|
|
103
|
+
maxAge?: number;
|
|
104
|
+
/** Custom storage factory (default: cookie storage) */
|
|
105
|
+
storageFactory?: SessionStorageFactory<TEnv>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Configuration for createBeam
|
|
109
|
+
*/
|
|
110
|
+
export interface BeamConfig<TEnv = object> {
|
|
111
|
+
actions: Record<string, ActionHandler<TEnv>>;
|
|
112
|
+
modals: Record<string, ModalHandler<TEnv>>;
|
|
113
|
+
drawers?: Record<string, DrawerHandler<TEnv>>;
|
|
114
|
+
auth?: AuthResolver<TEnv>;
|
|
115
|
+
/** Session config - default uses cookie storage, or provide storageFactory for custom storage */
|
|
116
|
+
session?: SessionConfig<TEnv>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Options for beam.init()
|
|
120
|
+
*/
|
|
121
|
+
export interface BeamInitOptions {
|
|
122
|
+
/** WebSocket endpoint path (default: '/beam') */
|
|
123
|
+
endpoint?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Hono context variables set by beam.authMiddleware()
|
|
127
|
+
* Use with: c.get('beam').user, c.get('beam').env, c.get('beam').request
|
|
128
|
+
*/
|
|
129
|
+
export interface BeamVariables<TEnv = object> {
|
|
130
|
+
beam: BeamContext<TEnv>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The Beam instance returned by createBeam
|
|
134
|
+
*/
|
|
135
|
+
export interface BeamInstance<TEnv extends object = object> {
|
|
136
|
+
actions: Record<string, ActionHandler<TEnv>>;
|
|
137
|
+
modals: Record<string, ModalHandler<TEnv>>;
|
|
138
|
+
drawers: Record<string, DrawerHandler<TEnv>>;
|
|
139
|
+
/** Auth resolver (if provided) */
|
|
140
|
+
auth: AuthResolver<TEnv> | undefined;
|
|
141
|
+
/** Init function for HonoX createApp({ init(app) { beam.init(app, options) } }) */
|
|
142
|
+
init: (app: Hono<{
|
|
143
|
+
Bindings: TEnv;
|
|
144
|
+
}>, options?: BeamInitOptions) => void;
|
|
145
|
+
/** Middleware that resolves auth and sets beamUser/beamContext in Hono context */
|
|
146
|
+
authMiddleware: () => MiddlewareHandler<{
|
|
147
|
+
Bindings: TEnv;
|
|
148
|
+
Variables: BeamVariables<TEnv>;
|
|
149
|
+
}>;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAEnD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,6BAA6B;IAC7B,GAAG,CAAC,CAAC,GAAG,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ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface BeamPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Glob pattern for action handlers (must start with '/' for virtual modules)
|
|
5
|
+
* @default '/app/actions/*.tsx'
|
|
6
|
+
*/
|
|
7
|
+
actions?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Glob pattern for modal handlers (must start with '/' for virtual modules)
|
|
10
|
+
* @default '/app/modals/*.tsx'
|
|
11
|
+
*/
|
|
12
|
+
modals?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Glob pattern for drawer handlers (must start with '/' for virtual modules)
|
|
15
|
+
* @default '/app/drawers/*.tsx'
|
|
16
|
+
*/
|
|
17
|
+
drawers?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Path to auth resolver module (must export default AuthResolver function)
|
|
20
|
+
* @example '/app/auth.ts'
|
|
21
|
+
*/
|
|
22
|
+
auth?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Session configuration.
|
|
25
|
+
* - `secretEnvKey`: Environment variable name containing the session secret (default: 'SESSION_SECRET')
|
|
26
|
+
* - `cookieName`: Cookie name (default: 'beam_sid')
|
|
27
|
+
* - `maxAge`: Cookie max age in seconds (default: 1 year)
|
|
28
|
+
* - `storage`: Path to custom storage factory module (default: cookie storage)
|
|
29
|
+
*
|
|
30
|
+
* Set to `true` for defaults (cookie storage), or provide partial config.
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* session: true // uses cookie storage with env.SESSION_SECRET
|
|
34
|
+
* session: { secretEnvKey: 'MY_SECRET', cookieName: 'my_sid' }
|
|
35
|
+
* session: { storage: '/app/session-storage.ts' } // custom KV storage
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
session?: boolean | {
|
|
39
|
+
secretEnvKey?: string;
|
|
40
|
+
cookieName?: string;
|
|
41
|
+
maxAge?: number;
|
|
42
|
+
/** Path to custom storage factory module (must export default SessionStorageFactory) */
|
|
43
|
+
storage?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Vite plugin that auto-generates the beam instance from handler files.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // vite.config.ts
|
|
52
|
+
* import { beamPlugin } from '@benqoder/beam/vite'
|
|
53
|
+
*
|
|
54
|
+
* export default defineConfig({
|
|
55
|
+
* plugins: [
|
|
56
|
+
* beamPlugin({
|
|
57
|
+
* actions: '/app/actions/*.tsx',
|
|
58
|
+
* modals: '/app/modals/*.tsx',
|
|
59
|
+
* drawers: '/app/drawers/*.tsx',
|
|
60
|
+
* })
|
|
61
|
+
* ]
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Then import the beam instance:
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { beam } from 'virtual:beam'
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function beamPlugin(options?: BeamPluginOptions): Plugin;
|
|
71
|
+
export default beamPlugin;
|
|
72
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG;QAClB,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,wFAAwF;QACxF,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;CACF;AAKD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAgElE;AAED,eAAe,UAAU,CAAA"}
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const VIRTUAL_MODULE_ID = 'virtual:beam';
|
|
2
|
+
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin that auto-generates the beam instance from handler files.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // vite.config.ts
|
|
9
|
+
* import { beamPlugin } from '@benqoder/beam/vite'
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* plugins: [
|
|
13
|
+
* beamPlugin({
|
|
14
|
+
* actions: '/app/actions/*.tsx',
|
|
15
|
+
* modals: '/app/modals/*.tsx',
|
|
16
|
+
* drawers: '/app/drawers/*.tsx',
|
|
17
|
+
* })
|
|
18
|
+
* ]
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Then import the beam instance:
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { beam } from 'virtual:beam'
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function beamPlugin(options = {}) {
|
|
28
|
+
const { actions = '/app/actions/*.tsx', modals = '/app/modals/*.tsx', drawers = '/app/drawers/*.tsx', auth, session, } = options;
|
|
29
|
+
return {
|
|
30
|
+
name: 'beam-plugin',
|
|
31
|
+
resolveId(id) {
|
|
32
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
33
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
load(id) {
|
|
37
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
38
|
+
const authImport = auth ? `import auth from '${auth}'` : '';
|
|
39
|
+
const authConfig = auth ? ', auth' : '';
|
|
40
|
+
// Generate session config code
|
|
41
|
+
let sessionConfig = '';
|
|
42
|
+
let storageImport = '';
|
|
43
|
+
if (session) {
|
|
44
|
+
const sessionOpts = typeof session === 'object' ? session : {};
|
|
45
|
+
const secretEnvKey = sessionOpts.secretEnvKey || 'SESSION_SECRET';
|
|
46
|
+
const cookieName = sessionOpts.cookieName || 'beam_sid';
|
|
47
|
+
const maxAge = sessionOpts.maxAge || 365 * 24 * 60 * 60;
|
|
48
|
+
const storagePath = sessionOpts.storage;
|
|
49
|
+
// Import custom storage factory if provided
|
|
50
|
+
if (storagePath) {
|
|
51
|
+
storageImport = `import storageFactory from '${storagePath}'`;
|
|
52
|
+
}
|
|
53
|
+
// Session secret is resolved at runtime from env
|
|
54
|
+
sessionConfig = `, session: {
|
|
55
|
+
secret: '', // Will be resolved from env.${secretEnvKey} at runtime
|
|
56
|
+
secretEnvKey: '${secretEnvKey}',
|
|
57
|
+
cookieName: '${cookieName}',
|
|
58
|
+
maxAge: ${maxAge}${storagePath ? ',\n storageFactory' : ''}
|
|
59
|
+
}`;
|
|
60
|
+
}
|
|
61
|
+
// Generate plain JavaScript - TypeScript types are handled via virtual-beam.d.ts
|
|
62
|
+
return `
|
|
63
|
+
import { createBeam, collectHandlers } from '@benqoder/beam'
|
|
64
|
+
${authImport}
|
|
65
|
+
${storageImport}
|
|
66
|
+
|
|
67
|
+
const { actions, modals, drawers } = collectHandlers({
|
|
68
|
+
actions: import.meta.glob('${actions}', { eager: true }),
|
|
69
|
+
modals: import.meta.glob('${modals}', { eager: true }),
|
|
70
|
+
drawers: import.meta.glob('${drawers}', { eager: true }),
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export const beam = createBeam({ actions, modals, drawers${authConfig}${sessionConfig} })
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export default beamPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@benqoder/beam",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org",
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/benqoder/beam.git"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./client": {
|
|
19
|
+
"types": "./dist/client.d.ts",
|
|
20
|
+
"import": "./dist/client.js"
|
|
21
|
+
},
|
|
22
|
+
"./vite": {
|
|
23
|
+
"types": "./dist/vite.d.ts",
|
|
24
|
+
"import": "./dist/vite.js"
|
|
25
|
+
},
|
|
26
|
+
"./virtual": {
|
|
27
|
+
"types": "./src/virtual-beam.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./styles": "./src/beam.css",
|
|
30
|
+
"./beam.css": "./src/beam.css"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"src/beam.css",
|
|
35
|
+
"src/virtual-beam.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc",
|
|
39
|
+
"dev": "tsc --watch"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"capnweb": "^0.4.0",
|
|
43
|
+
"hono": "^4.0.0",
|
|
44
|
+
"honox": "^0.1.0",
|
|
45
|
+
"idiomorph": "^0.3.0",
|
|
46
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"vite": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@cloudflare/workers-types": "^4.20241127.0",
|
|
55
|
+
"capnweb": "^0.4.0",
|
|
56
|
+
"hono": "^4.6.0",
|
|
57
|
+
"honox": "^0.1.0",
|
|
58
|
+
"idiomorph": "^0.3.0",
|
|
59
|
+
"typescript": "^5.0.0",
|
|
60
|
+
"vite": "^6.0.0"
|
|
61
|
+
}
|
|
62
|
+
}
|