@ape-egg/vibe 1.3.0 → 1.3.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.1] - 2025-02-06
4
+
5
+ ### Fixed
6
+
7
+ - **Package exports**: Added missing `./component` export to package.json
8
+ - Enables proper import: `import component from '@ape-egg/vibe/component'`
9
+ - Previously `component.js` was included in package files but not exposed via exports field
10
+
11
+ ---
12
+
3
13
  ## [1.3.0] - 2025-02-06
4
14
 
5
15
  ### Added
package/component.js ADDED
@@ -0,0 +1,59 @@
1
+ // Component state entry point
2
+ // Usage:
3
+ // <component>
4
+ // <script type="module">
5
+ // import component from 'vibe/component.js';
6
+ // component({ count: 0 }, { debug: false }, 'body');
7
+ // </script>
8
+ // <div>@[this.count]</div>
9
+ // </component>
10
+ //
11
+ // Or with class:
12
+ // <div class="component">...</div>
13
+
14
+ import { generateComponentId } from './runtime/component-state.js';
15
+ import { ensureBoot } from './boot.js';
16
+
17
+ const component = (state = {}, config, targetSelector) => {
18
+ // Find the first unprocessed INLINE component wrapper
19
+ // Skip <component src=""> (fetched components) - they don't need state tagging
20
+ // Scripts execute in DOM order, so we claim wrappers in DOM order too
21
+ // Supports: <component> or <div class="component">
22
+ const allWrappers = Array.from(document.querySelectorAll('component:not([src]), div.component:not([src])'));
23
+ const wrapper = allWrappers.find(el => !el.hasAttribute('data-vibe-component-id'));
24
+
25
+ if (!wrapper) {
26
+ console.warn('[vibe] component() must be called inside <component> or <div class="component">');
27
+ return;
28
+ }
29
+
30
+ // Generate unique component ID
31
+ const componentId = generateComponentId();
32
+
33
+ // Tag only the wrapper element
34
+ // All descendants will find it via element.closest('[data-vibe-component-id]')
35
+ wrapper.setAttribute('data-vibe-component-id', componentId);
36
+
37
+ // Register component state in shared registry
38
+ if (!window.__vibeComponents) {
39
+ window.__vibeComponents = {};
40
+ }
41
+ window.__vibeComponents[componentId] = state;
42
+
43
+ // Store config (first caller wins)
44
+ if (config && !window.__vibeConfig) {
45
+ window.__vibeConfig = config;
46
+ }
47
+
48
+ // Store targetSelector (first caller wins)
49
+ if (targetSelector && !window.__vibeTargetSelector) {
50
+ window.__vibeTargetSelector = targetSelector;
51
+ }
52
+
53
+ // Ensure boot happens
54
+ ensureBoot();
55
+
56
+ return componentId;
57
+ };
58
+
59
+ export default component;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ape-egg/vibe",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "Runtime-first reactivity with optional compiler",
6
6
  "main": "index.js",
7
7
  "homepage": "https://vibe.korte.kim",
8
8
  "exports": {
9
9
  ".": "./index.js",
10
+ "./component": "./component.js",
10
11
  "./runtime": "./runtime/index.js",
11
12
  "./compiler": "./compiler/bin/vibe-compile.js"
12
13
  },
@@ -15,6 +16,7 @@
15
16
  },
16
17
  "files": [
17
18
  "index.js",
19
+ "component.js",
18
20
  "vibe.css",
19
21
  "runtime/",
20
22
  "compiler/bin/",