@sprlab/wccompiler 0.10.4 → 0.10.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/integrations/vue.js +9 -5
- package/lib/codegen.js +7 -6
- package/package.json +1 -1
package/integrations/vue.js
CHANGED
|
@@ -65,11 +65,15 @@ export function wccVuePlugin(options = {}) {
|
|
|
65
65
|
|
|
66
66
|
let result = code
|
|
67
67
|
|
|
68
|
-
// NOTE: As of WCC 0.10.3+,
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
68
|
+
// NOTE: As of WCC 0.10.3+, basic events work WITHOUT this plugin because
|
|
69
|
+
// the compiled component emits events in multiple formats (kebab, camelCase, lowercase).
|
|
70
|
+
// However, v-model:propName STILL REQUIRES this plugin because Vue assigns the raw
|
|
71
|
+
// Event object to the ref — it doesn't extract .detail automatically.
|
|
72
|
+
// This transform rewrites v-model:prop to @prop-changed="ref = $event.detail".
|
|
73
|
+
//
|
|
74
|
+
// This plugin is needed for:
|
|
75
|
+
// 1. v-model:propName (Vue can't unwrap CustomEvent.detail natively)
|
|
76
|
+
// 2. v-model modifiers (.trim, .number)
|
|
73
77
|
// 3. Scoped slot syntax transformation ({{prop}} → {%prop%})
|
|
74
78
|
|
|
75
79
|
// Transform v-model:propName="expr" on custom elements (tags with hyphens)
|
package/lib/codegen.js
CHANGED
|
@@ -1799,11 +1799,14 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1799
1799
|
// _modelSet methods (one per defineModel prop — emits events on internal write)
|
|
1800
1800
|
// Emits:
|
|
1801
1801
|
// 1. wcc:model — generic event for vanilla JS and WCC-to-WCC binding
|
|
1802
|
-
// 2. propName-changed — kebab-case for direct addEventListener
|
|
1802
|
+
// 2. propName-changed — kebab-case for direct addEventListener and Vue plugin
|
|
1803
1803
|
// 3. propNameChanged — camelCase for Angular WccEvents / direct binding
|
|
1804
1804
|
// 4. propnamechanged — lowercase for React 19 (onPropnameChanged → 'propnamechanged')
|
|
1805
1805
|
// 5. propNameChange — for Angular [(prop)] banana-box syntax
|
|
1806
|
-
//
|
|
1806
|
+
//
|
|
1807
|
+
// NOTE: Vue v-model:prop requires the wccVuePlugin because Vue assigns the raw
|
|
1808
|
+
// Event object to the ref (not event.detail). The plugin transforms v-model:prop
|
|
1809
|
+
// to @prop-changed="ref = $event.detail" which correctly extracts the value.
|
|
1807
1810
|
for (const md of modelDefs) {
|
|
1808
1811
|
const kebabName = camelToKebab(md.name);
|
|
1809
1812
|
const camelChanged = `${md.name}Changed`;
|
|
@@ -1815,16 +1818,14 @@ export function generateComponent(parseResult, options = {}) {
|
|
|
1815
1818
|
lines.push(` bubbles: true,`);
|
|
1816
1819
|
lines.push(` composed: true`);
|
|
1817
1820
|
lines.push(` }));`);
|
|
1818
|
-
// Kebab-case: prop-name-changed
|
|
1821
|
+
// Kebab-case: prop-name-changed (Vue plugin, addEventListener)
|
|
1819
1822
|
lines.push(` this.dispatchEvent(new CustomEvent('${kebabName}-changed', { detail: newVal, bubbles: true }));`);
|
|
1820
|
-
// camelCase: propNameChanged
|
|
1823
|
+
// camelCase: propNameChanged (Angular, addEventListener)
|
|
1821
1824
|
lines.push(` this.dispatchEvent(new CustomEvent('${camelChanged}', { detail: newVal, bubbles: true }));`);
|
|
1822
1825
|
// lowercase: propnamechanged (React 19)
|
|
1823
1826
|
lines.push(` this.dispatchEvent(new CustomEvent('${camelChanged.toLowerCase()}', { detail: newVal, bubbles: true }));`);
|
|
1824
1827
|
// Angular banana-box: propNameChange
|
|
1825
1828
|
lines.push(` this.dispatchEvent(new CustomEvent('${md.name}Change', { detail: newVal, bubbles: true }));`);
|
|
1826
|
-
// Vue v-model: update:propName
|
|
1827
|
-
lines.push(` this.dispatchEvent(new CustomEvent('update:${md.name}', { detail: newVal, bubbles: true }));`);
|
|
1828
1829
|
lines.push(' }');
|
|
1829
1830
|
lines.push('');
|
|
1830
1831
|
}
|
package/package.json
CHANGED