@sprlab/wccompiler 0.8.3 → 0.8.5

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/adapters/vue.js CHANGED
@@ -32,15 +32,21 @@
32
32
  // This enables Vue's native v-model on WCC custom elements.
33
33
  // Vue v-model on custom elements listens for `update:modelValue` by default.
34
34
  // The nodeTransform in wccVuePlugin makes v-model:propName listen for `update:propName`.
35
+ //
36
+ // IMPORTANT: We listen in CAPTURE phase so the update:propName event is dispatched
37
+ // BEFORE Vue's own bubble-phase listeners process the element. This ensures Vue
38
+ // picks up the translated event synchronously.
35
39
 
36
40
  if (typeof document !== 'undefined') {
37
41
  document.addEventListener('wcc:model', (e) => {
38
42
  const { prop, value } = e.detail;
43
+ // Dispatch update:propName synchronously on the target element.
44
+ // bubbles:false because Vue listens directly on the element via addEventListener.
39
45
  e.target.dispatchEvent(new CustomEvent(`update:${prop}`, {
40
46
  detail: value,
41
- bubbles: true
47
+ bubbles: false
42
48
  }));
43
- });
49
+ }, true); // ← capture phase
44
50
  }
45
51
 
46
52
  // ── Vue directive: v-wcc-model ──────────────────────────────────────
@@ -60,13 +60,13 @@ function wccVModelTransform(node, context) {
60
60
  let modified = false;
61
61
 
62
62
  for (const prop of node.props) {
63
- // Check if this is a v-model directive with an argument
63
+ // Check if this is a v-model directive (with or without argument)
64
64
  if (
65
65
  prop.type === 7 && // DIRECTIVE
66
- prop.name === 'model' &&
67
- prop.arg // has argument (v-model:name)
66
+ prop.name === 'model'
68
67
  ) {
69
- const propName = prop.arg.content;
68
+ // Determine prop name: explicit arg or default 'modelValue'
69
+ const propName = prop.arg ? prop.arg.content : 'modelValue';
70
70
  const expr = prop.exp;
71
71
 
72
72
  if (!expr) {
@@ -74,12 +74,21 @@ function wccVModelTransform(node, context) {
74
74
  continue;
75
75
  }
76
76
 
77
+ // Create the arg node (use existing or create for modelValue)
78
+ const argNode = prop.arg || {
79
+ type: 4, // SIMPLE_EXPRESSION
80
+ content: 'modelValue',
81
+ isStatic: true,
82
+ constType: 3,
83
+ loc: prop.loc
84
+ };
85
+
77
86
  // Replace v-model:propName="expr" with:
78
87
  // :propName="expr" (bind directive)
79
88
  newProps.push({
80
89
  type: 7, // DIRECTIVE
81
90
  name: 'bind',
82
- arg: prop.arg,
91
+ arg: argNode,
83
92
  exp: expr,
84
93
  modifiers: [],
85
94
  loc: prop.loc
@@ -98,7 +107,7 @@ function wccVModelTransform(node, context) {
98
107
  },
99
108
  exp: {
100
109
  type: 4, // SIMPLE_EXPRESSION
101
- content: `$event => { ${expr.content} = $event }`,
110
+ content: `$event => { ${expr.content} = $event.detail ?? $event }`,
102
111
  isStatic: false,
103
112
  constType: 0,
104
113
  loc: prop.loc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
5
  "type": "module",
6
6
  "exports": {