nexa-compiler 0.6.4 → 0.7.0

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.
@@ -81,8 +81,11 @@ function genSlot(node) {
81
81
  const propsCall = node.slotProps ? `{ ${node.slotProps} }` : '';
82
82
  const args = node.slotProps ? `(${propsCall})` : '()';
83
83
  const slotAccess = /^[\w$]+$/.test(node.name) ? `ctx.$slots.${node.name}` : `ctx.$slots[${node.name}]`;
84
+ const childrenCode = node.children && node.children.length > 0
85
+ ? `[${node.children.map(c => genNode(c)).join(', ')}]`
86
+ : 'null';
84
87
  if (node.name === 'default') {
85
- return `ctx.$slots.default ? ctx.$slots.default${args} : null`;
88
+ return `ctx.$slots.default ? ctx.$slots.default${args} : ${childrenCode}`;
86
89
  }
87
- return `${slotAccess} ? ${slotAccess}${args} : null`;
90
+ return `${slotAccess} ? ${slotAccess}${args} : ${childrenCode}`;
88
91
  }
@@ -31,6 +31,7 @@ export type SlotNode = {
31
31
  type: 'slot';
32
32
  name: string;
33
33
  attrs: Attr[];
34
+ children: TemplateNode[];
34
35
  };
35
36
  export type IfNode = {
36
37
  type: 'if';
@@ -42,14 +42,18 @@ export function parseTemplate(template) {
42
42
  type: 'slot',
43
43
  name: attrs.find(a => a.name === 'name')?.value || 'default',
44
44
  attrs,
45
+ children: []
45
46
  };
46
47
  stack[stack.length - 1].push(slotNode);
48
+ if (!isSelfClosing) {
49
+ stack.push(slotNode.children);
50
+ }
47
51
  }
48
52
  else {
49
53
  stack[stack.length - 1].push(node);
50
- }
51
- if (!isSelfClosing) {
52
- stack.push(node.children);
54
+ if (!isSelfClosing) {
55
+ stack.push(node.children);
56
+ }
53
57
  }
54
58
  lastIndex = tagRegex.lastIndex;
55
59
  }
@@ -25,6 +25,7 @@ export type TransformedNode = {
25
25
  type: 'slot';
26
26
  name: string;
27
27
  slotProps?: string;
28
+ children?: TransformedNode[];
28
29
  } | {
29
30
  type: 'comment';
30
31
  } | {
@@ -36,7 +36,7 @@ function transformNode(node, scopeId) {
36
36
  const slotProps = dynamicAttrs.length > 0
37
37
  ? dynamicAttrs.map(a => `${a.name}: ${a.value}`).join(', ')
38
38
  : undefined;
39
- return { type: 'slot', name: node.name, slotProps };
39
+ return { type: 'slot', name: node.name, slotProps, children: node.children?.map(c => transformNode(c)) };
40
40
  }
41
41
  case 'if': {
42
42
  const then = transformChildren(node.then, scopeId);
@@ -143,14 +143,26 @@ function genProps(attrs, tag) {
143
143
  let handler = typeof attr.value === 'string' && /^\w+$/.test(attr.value)
144
144
  ? attr.value
145
145
  : `($event) => { ${attr.value} }`;
146
- if (modifiers.includes('self')) {
147
- handler = `($event) => { if ($event.target === $event.currentTarget) { (${handler})($event) } }`;
148
- }
149
- if (modifiers.includes('prevent')) {
150
- handler = `($event) => { $event.preventDefault(); (${handler})($event) }`;
151
- }
152
- if (modifiers.includes('stop')) {
153
- handler = `($event) => { $event.stopPropagation(); (${handler})($event) }`;
146
+ const keyMap = {
147
+ enter: 'Enter', esc: 'Escape', tab: 'Tab',
148
+ space: ' ', up: 'ArrowUp', down: 'ArrowDown',
149
+ left: 'ArrowLeft', right: 'ArrowRight',
150
+ delete: 'Delete', backspace: 'Backspace',
151
+ };
152
+ const isKeyEvent = realName.startsWith('onKey');
153
+ for (const mod of modifiers) {
154
+ if (keyMap[mod] && isKeyEvent) {
155
+ handler = `($event) => { if ($event.key === '${keyMap[mod]}') { (${handler})($event) } }`;
156
+ }
157
+ else if (mod === 'self') {
158
+ handler = `($event) => { if ($event.target === $event.currentTarget) { (${handler})($event) } }`;
159
+ }
160
+ else if (mod === 'prevent') {
161
+ handler = `($event) => { $event.preventDefault(); (${handler})($event) }`;
162
+ }
163
+ else if (mod === 'stop') {
164
+ handler = `($event) => { $event.stopPropagation(); (${handler})($event) }`;
165
+ }
154
166
  }
155
167
  parts.push(`${realName}: ${handler}`);
156
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexa-compiler",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",