gonia 0.1.2 → 0.1.3
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/client/hydrate.js +40 -58
- package/dist/context-registry.d.ts +130 -0
- package/dist/context-registry.js +153 -0
- package/dist/directives/slot.d.ts +4 -2
- package/dist/directives/slot.js +11 -16
- package/dist/directives/template.d.ts +9 -2
- package/dist/directives/template.js +14 -13
- package/dist/dom.d.ts +29 -0
- package/dist/dom.js +39 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -2
- package/dist/inject.d.ts +47 -6
- package/dist/inject.js +66 -4
- package/dist/providers.js +9 -12
- package/dist/scope.js +13 -22
- package/dist/server/render.js +29 -40
- package/dist/types.d.ts +88 -11
- package/dist/types.js +41 -0
- package/dist/vite/plugin.d.ts +27 -0
- package/dist/vite/plugin.js +56 -3
- package/package.json +5 -1
package/dist/vite/plugin.js
CHANGED
|
@@ -113,15 +113,56 @@ function detectDirectives(code, id, isDev, attributePrefixes, elementPrefixes, c
|
|
|
113
113
|
}
|
|
114
114
|
return found;
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Get options for a directive from the directiveOptions config.
|
|
118
|
+
*/
|
|
119
|
+
function getDirectiveOptions(name, directiveOptions) {
|
|
120
|
+
if (!directiveOptions)
|
|
121
|
+
return undefined;
|
|
122
|
+
if (typeof directiveOptions === 'function') {
|
|
123
|
+
return directiveOptions(name);
|
|
124
|
+
}
|
|
125
|
+
return directiveOptions[name];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Serialize directive options to a string for code generation.
|
|
129
|
+
*/
|
|
130
|
+
function serializeOptions(options) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
if (options.scope !== undefined) {
|
|
133
|
+
parts.push(`scope: ${options.scope}`);
|
|
134
|
+
}
|
|
135
|
+
if (options.template !== undefined) {
|
|
136
|
+
if (typeof options.template === 'string') {
|
|
137
|
+
parts.push(`template: ${JSON.stringify(options.template)}`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Function templates can't be serialized - warn and skip
|
|
141
|
+
console.warn('[gonia] Function templates in directiveOptions are not supported. Use a string template.');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (options.provide !== undefined) {
|
|
145
|
+
// provide can contain functions which can't be serialized
|
|
146
|
+
console.warn('[gonia] "provide" in directiveOptions is not supported via plugin config.');
|
|
147
|
+
}
|
|
148
|
+
return `{ ${parts.join(', ')} }`;
|
|
149
|
+
}
|
|
116
150
|
/**
|
|
117
151
|
* Generate import statements for detected directives.
|
|
118
152
|
*/
|
|
119
|
-
function generateImports(directives, customDirectives, currentFile, rootDir) {
|
|
153
|
+
function generateImports(directives, customDirectives, currentFile, rootDir, directiveOptions) {
|
|
120
154
|
if (directives.size === 0)
|
|
121
155
|
return '';
|
|
122
156
|
// Group by module
|
|
123
157
|
const moduleImports = new Map();
|
|
158
|
+
// Track which directives need configuration
|
|
159
|
+
const directivesToConfigure = [];
|
|
124
160
|
for (const name of directives) {
|
|
161
|
+
// Check if this directive has options
|
|
162
|
+
const options = getDirectiveOptions(name, directiveOptions);
|
|
163
|
+
if (options) {
|
|
164
|
+
directivesToConfigure.push({ name, options });
|
|
165
|
+
}
|
|
125
166
|
// Check built-in first
|
|
126
167
|
const builtin = BUILTIN_DIRECTIVES[name];
|
|
127
168
|
if (builtin) {
|
|
@@ -152,6 +193,14 @@ function generateImports(directives, customDirectives, currentFile, rootDir) {
|
|
|
152
193
|
}
|
|
153
194
|
// Generate import statements
|
|
154
195
|
const statements = [];
|
|
196
|
+
// Add configureDirective import if we have options to apply
|
|
197
|
+
if (directivesToConfigure.length > 0) {
|
|
198
|
+
const goniaImports = moduleImports.get('gonia') ?? [];
|
|
199
|
+
if (!goniaImports.includes('configureDirective')) {
|
|
200
|
+
goniaImports.push('configureDirective');
|
|
201
|
+
}
|
|
202
|
+
moduleImports.set('gonia', goniaImports);
|
|
203
|
+
}
|
|
155
204
|
for (const [module, imports] of moduleImports) {
|
|
156
205
|
if (imports.length > 0) {
|
|
157
206
|
statements.push(`import { ${imports.join(', ')} } from '${module}';`);
|
|
@@ -161,6 +210,10 @@ function generateImports(directives, customDirectives, currentFile, rootDir) {
|
|
|
161
210
|
statements.push(`import '${module}';`);
|
|
162
211
|
}
|
|
163
212
|
}
|
|
213
|
+
// Add configureDirective calls
|
|
214
|
+
for (const { name, options } of directivesToConfigure) {
|
|
215
|
+
statements.push(`configureDirective('${name}', ${serializeOptions(options)});`);
|
|
216
|
+
}
|
|
164
217
|
return statements.length > 0 ? statements.join('\n') + '\n' : '';
|
|
165
218
|
}
|
|
166
219
|
/**
|
|
@@ -239,7 +292,7 @@ function transformInject(code) {
|
|
|
239
292
|
* ```
|
|
240
293
|
*/
|
|
241
294
|
export function gonia(options = {}) {
|
|
242
|
-
const { autoDirectives = true, includeDirectives = [], excludeDirectives = [], directiveSources = [], directiveAttributePrefixes = ['g-'], directiveElementPrefixes = options.directiveElementPrefixes ?? options.directiveAttributePrefixes ?? ['g-'], } = options;
|
|
295
|
+
const { autoDirectives = true, includeDirectives = [], excludeDirectives = [], directiveSources = [], directiveAttributePrefixes = ['g-'], directiveElementPrefixes = options.directiveElementPrefixes ?? options.directiveAttributePrefixes ?? ['g-'], directiveOptions, } = options;
|
|
243
296
|
let isDev = false;
|
|
244
297
|
let rootDir = process.cwd();
|
|
245
298
|
// Map of custom directive name -> DirectiveInfo
|
|
@@ -303,7 +356,7 @@ export function gonia(options = {}) {
|
|
|
303
356
|
const hasGoniaImport = code.includes("from 'gonia/directives'") ||
|
|
304
357
|
code.includes('from "gonia/directives"');
|
|
305
358
|
// For custom directives, check if already imported
|
|
306
|
-
const importStatement = generateImports(detected, customDirectives, id, rootDir);
|
|
359
|
+
const importStatement = generateImports(detected, customDirectives, id, rootDir, directiveOptions);
|
|
307
360
|
if (importStatement && !hasGoniaImport) {
|
|
308
361
|
result = importStatement + result;
|
|
309
362
|
modified = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gonia",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A lightweight, SSR-first reactive UI library with declarative directives",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"types": "./dist/server/index.d.ts",
|
|
37
37
|
"import": "./dist/server/index.js"
|
|
38
38
|
},
|
|
39
|
+
"./directives": {
|
|
40
|
+
"types": "./dist/directives/index.d.ts",
|
|
41
|
+
"import": "./dist/directives/index.js"
|
|
42
|
+
},
|
|
39
43
|
"./vite": {
|
|
40
44
|
"types": "./dist/vite/index.d.ts",
|
|
41
45
|
"import": "./dist/vite/index.js"
|