@ynor/ynor 1.0.5 → 1.0.6

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 CHANGED
@@ -16,7 +16,8 @@ A lightweight, next-generation JavaScript extension framework inspired by Svelte
16
16
  ## Project Structure
17
17
 
18
18
 
19
- `📁 ynor/
19
+ ```
20
+ 📁 ynor/
20
21
  ├── 📁 .svelte-kit/
21
22
  │ ├── 📁 generated/
22
23
  │ │ ├── 📁 client/
@@ -108,4 +109,4 @@ no extension: 2 files
108
109
  .txt: 1 file
109
110
 
110
111
  Generated: 29/06/2026, 11:57:18 am
111
- `
112
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynor/ynor",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "⚡ Lightweight next-gen JS extension framework like Svelte",
5
5
  "type": "module",
6
6
  "main": "./src/lib/core/index.js",
@@ -186,17 +186,40 @@ export default class ${className} extends YnorComponent {
186
186
  return this._element;
187
187
  }
188
188
 
189
- _renderComponent(componentName) {
190
- const Component = runtime.components.get(componentName);
191
- if (!Component) {
192
- console.warn(\`Component "\${componentName}" not found\`);
193
- return '';
189
+ // In generateComponent, update _renderComponent
190
+
191
+ _renderComponent(componentName, attributes = '') {
192
+ const Component = runtime.components.get(componentName);
193
+ if (!Component) {
194
+ console.warn(\`Component "\${componentName}" not found\`);
195
+ return '';
196
+ }
197
+
198
+ // Parse attributes into props
199
+ const props = {};
200
+ if (attributes) {
201
+ // Parse on:click_menu={toggleSidebar} -> props.on_click_menu = this.toggleSidebar
202
+ const attrRegex = /([a-zA-Z_:][a-zA-Z0-9_:]*)=["{]([^"}]+)["}]/g;
203
+ let match;
204
+ while ((match = attrRegex.exec(attributes)) !== null) {
205
+ const key = match[1].replace(/:/g, '_');
206
+ const value = match[2].trim();
207
+ // Check if it's a function reference on this
208
+ if (this[value] && typeof this[value] === 'function') {
209
+ props[key] = this[value].bind(this);
210
+ } else {
211
+ props[key] = value;
212
+ }
194
213
  }
195
- const tempDiv = document.createElement('div');
196
- const instance = new Component({ target: tempDiv });
197
- instance.$mount();
198
- return tempDiv.innerHTML;
199
214
  }
215
+
216
+ console.log(\`🔧 Rendering component "\${componentName}" with props:\`, props);
217
+
218
+ const tempDiv = document.createElement('div');
219
+ const instance = new Component({ target: tempDiv, props });
220
+ instance.$mount();
221
+ return tempDiv.innerHTML;
222
+ }
200
223
 
201
224
  _bindEvents(container) {
202
225
  const clickElements = container.querySelectorAll('[data-on-click]');
@@ -316,6 +339,8 @@ transformScript(script) {
316
339
 
317
340
  // src/lib/core/compiler.js - Fix processTemplate
318
341
 
342
+ // src/lib/core/compiler.js - Replace processTemplate with this version
343
+
319
344
  processTemplate(template) {
320
345
  if (!template) {
321
346
  return '';
@@ -323,22 +348,28 @@ processTemplate(template) {
323
348
 
324
349
  let processed = template;
325
350
 
326
- // Handle component tags
351
+ // FIRST: Handle component tags with attributes - This must come before simple tags
352
+ // Matches <ComponentName attr1={value1} attr2={value2} ... />
353
+ processed = processed.replace(/<([A-Z][a-zA-Z0-9]*)\s+([^>]*?)\s*\/>/g, (match, componentName, attributes) => {
354
+ console.log('🔧 Processing component with attributes:', componentName, attributes);
355
+ // Pass attributes as props
356
+ return '${this._renderComponent("' + componentName + '", "' + attributes.trim() + '")}';
357
+ });
358
+
359
+ // Handle simple component tags without attributes
327
360
  processed = processed.replace(/<([A-Z][a-zA-Z0-9]*)\s*\/>/g, (match, componentName) => {
328
361
  return '${this._renderComponent("' + componentName + '")}';
329
362
  });
330
363
 
331
- // Handle on:click={handler} - FIX THIS
364
+ // Handle on:click={handler}
332
365
  processed = processed.replace(/on:([a-zA-Z]+)=\{([^}]+)\}/g, (match, event, handler) => {
333
- // Store the handler name as a data attribute
334
366
  return `data-on-${event}="${handler.trim()}"`;
335
367
  });
336
368
 
337
369
  // Handle expressions {variable}
338
370
  processed = processed.replace(/\{([^}]+)\}/g, (match, expr) => {
339
371
  const trimmed = expr.trim();
340
- // For simple variables, access from this
341
- return '${this.' + trimmed + ' !== undefined ? this.' + trimmed + ' : 0}';
372
+ return '${this.' + trimmed + '}';
342
373
  });
343
374
 
344
375
  // Handle class:active={condition}