@symbiote-native/vue 3.0.1 → 3.0.3

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
@@ -20,20 +20,79 @@ mutation-oriented framework driving the already-validated engine.
20
20
 
21
21
  ## Install
22
22
 
23
+ ```bash
24
+ npx @symbiote-native/cli new my-app --framework vue --vue-flavor sfc # or --vue-flavor tsx
25
+ ```
26
+
27
+ One command, nothing to wire by hand: scaffolds the Metro config (the SFC transformer, or the TSX
28
+ Babel plugin below), the entry seam below, and `@symbiote-native/vue`/`react-native`/`vue` as your
29
+ app's own dependencies.
30
+
31
+ <details>
32
+ <summary>Manual install (no generator — an existing app, or you want to wire it yourself)</summary>
33
+
23
34
  ```bash
24
35
  npm install @symbiote-native/vue react-native vue
25
36
  ```
26
37
 
27
38
  `react-native` and `vue` stay your app's own top-level dependencies — this package only replaces
28
- the JS renderer that drives them. **TSX** needs nothing beyond the install above; **SFC**
29
- additionally needs a Metro transformer for `.vue` files (see
30
- [`examples/vue-sfc`](../../examples/vue-sfc)'s `metro.config.js`) — `npx @symbiote-native/cli new`
31
- wires this for a new app; an existing app still needs it copied in by hand.
39
+ the JS renderer that drives them. **SFC** additionally needs a Metro transformer for `.vue` files
40
+ — see [`examples/vue-sfc`](../../examples/vue-sfc)'s `metro.config.js`.
41
+
42
+ **TSX** needs one more Babel plugin beyond the install above, or a dev-mode Vue warning can crash
43
+ the mount to a blank screen. RN's dev React-JSX transform tags every `JSXElement` with `__self`/
44
+ `__source` (inert under React); `@vue/babel-plugin-jsx` copies them verbatim into the vnode's
45
+ props, and at module scope `__self`'s `this` is the Hermes global `HostObject` — the first Vue dev
46
+ warning that formats that prop for a component trace throws reading `Symbol.toStringTag` off it,
47
+ unwinding the whole mount. Strip both attributes on `JSXOpeningElement` exit, after Babel's
48
+ `__self`/`__source` plugins add them but before `@vue/babel-plugin-jsx` reads them (see
49
+ [`examples/vue-tsx`](../../examples/vue-tsx)'s `babel.config.js`, `stripReactJsxDevAttrs`) — SFC
50
+ doesn't need this, since its compiler never sees RN's React-JSX transform at all.
51
+
52
+ </details>
32
53
 
33
54
  ---
34
55
 
35
56
  ## Use it
36
57
 
58
+ The app is ordinary Vue. The primitives are TAGS — `<view>`, `<text>`, `<pressable>` — so there is
59
+ nothing to import for them at all; both Vue compilers resolve them as elements and the renderer
60
+ maps each to its Fabric view. Styling is a CSS class (a plain `.css` file in TSX, an SFC's own
61
+ `<style>` block otherwise) — the convention every example app here follows. A tap→increment
62
+ counter, authored in TSX:
63
+
64
+ ```jsx
65
+ import { ref } from '@vue/runtime-core';
66
+ import './App.css';
67
+
68
+ export default {
69
+ setup() {
70
+ const count = ref(0);
71
+ return () => (
72
+ <safe-area-view class="screen">
73
+ <text>Taps: {count.value}</text>
74
+ <pressable onPress={() => count.value++}>
75
+ <text>Tap me</text>
76
+ </pressable>
77
+ </safe-area-view>
78
+ );
79
+ },
80
+ };
81
+ ```
82
+
83
+ ```css
84
+ /* App.css */
85
+ .screen {
86
+ flex: 1;
87
+ align-items: center;
88
+ justify-content: center;
89
+ padding: 24px;
90
+ }
91
+ ```
92
+
93
+ <details>
94
+ <summary>Native entry point (index.js) — already scaffolded by <code>npx @symbiote-native/cli new --framework vue</code></summary>
95
+
37
96
  The zero-config entry mirrors real Vue's own `createApp(App).mount(...)` idiom and wires the same
38
97
  RN-backed host seams React's `registerApp` does — this is what
39
98
  [`examples/vue-tsx`](../../examples/vue-tsx) and [`examples/vue-sfc`](../../examples/vue-sfc)
@@ -41,6 +100,11 @@ actually use:
41
100
 
42
101
  ```js
43
102
  // index.js
103
+
104
+ // Registers host behaviors (Image, Pressable, Switch, ...) that /bootstrap alone doesn't
105
+ // reach; deleting this breaks them silently (Metro's production inlineRequires makes a
106
+ // side-effect-only barrel import go lazy, see register.ts).
107
+ import '@symbiote-native/vue';
44
108
  import { createApp } from '@symbiote-native/vue/bootstrap';
45
109
  import App from './App';
46
110
  import { name as appName } from './app.json';
@@ -66,27 +130,7 @@ RNAppRegistry.registerRunnable(appName, ({ rootTag }) => {
66
130
  });
67
131
  ```
68
132
 
69
- The app is ordinary Vue. The primitives are TAGS — `<view>`, `<text>`, `<pressable>` — so there is
70
- nothing to import for them at all; both Vue compilers resolve them as elements and the renderer
71
- maps each to its Fabric view. A tap→increment counter, authored in TSX:
72
-
73
- ```jsx
74
- import { ref } from '@vue/runtime-core';
75
-
76
- export default {
77
- setup() {
78
- const count = ref(0);
79
- return () => (
80
- <view style={{ padding: 24 }}>
81
- <text>Taps: {count.value}</text>
82
- <pressable onPress={() => count.value++}>
83
- <text>Tap me</text>
84
- </pressable>
85
- </view>
86
- );
87
- },
88
- };
89
- ```
133
+ </details>
90
134
 
91
135
  ### Two example apps
92
136
 
@@ -101,9 +145,9 @@ the demo above is the first one running on the iOS simulator:
101
145
 
102
146
  ## Parity — and the one gap
103
147
 
104
- Both adapters reach the same primitives, runtime modules, `Animated` on both drivers, gestures,
105
- accessibility, and the `VirtualizedList` family, verified on-device on iOS and Android. That
106
- parity is **structural, not hand-copied**: the
148
+ Vue reaches the same primitives, runtime modules, `Animated` on both drivers, gestures,
149
+ accessibility, and the `VirtualizedList` family as React, Svelte, Solid, and Angular, verified
150
+ on-device on iOS and Android. That parity is **structural, not hand-copied**: the
107
151
  component logic (state machines + render functions) is written **once** in `@symbiote-native/components`,
108
152
  and each adapter supplies only its lifecycle (Vue's `ref`/`watch` + the descriptor→`h()` bridge).
109
153
 
@@ -10,8 +10,8 @@
10
10
  // $attrs onto the inner VirtualizedList. The inner list still GATES RefreshControl + viewability
11
11
  // on callback presence, so each emit bridge is wired ONLY when the consumer actually listens.
12
12
  import { defineComponent, getCurrentInstance, h, shallowRef, } from '@vue/runtime-core';
13
- import { SINGLE_COLUMN, chunkIntoRows, expandRowViewability, firstItemOfRow, lastItemOfRow, rowKeyExtractor, } from '@symbiote-native/components';
14
- import { dlog, resolveClassName, } from '@symbiote-native/engine';
13
+ import { SINGLE_COLUMN, chunkIntoRows, expandRowViewability, firstItemOfRow, lastItemOfRow, removeClippedSubviewsOrDefault, rowKeyExtractor, } from '@symbiote-native/components';
14
+ import { Platform, dlog, resolveClassName, } from '@symbiote-native/engine';
15
15
  import { VirtualizedList } from '../virtualized-list/index.js';
16
16
  import { normalizeVueAttrs } from '../../utils/normalize-attrs.js';
17
17
  // VirtualizedList's generic construct signature can't be resolved by h()'s overloads, so drive
@@ -81,7 +81,12 @@ export const FlatList = defineComponent((props, { attrs, expose, emit, slots, })
81
81
  footer: slots.footer,
82
82
  empty: slots.empty,
83
83
  };
84
- const forwarded = normalizeVueAttrs(attrs);
84
+ const normalizedAttrs = normalizeVueAttrs(attrs);
85
+ // FlatList.js always sends it, defaulted per platform.
86
+ const forwarded = {
87
+ ...normalizedAttrs,
88
+ removeClippedSubviews: removeClippedSubviewsOrDefault(normalizedAttrs.removeClippedSubviews, Platform.OS),
89
+ };
85
90
  dlog(`Vue FlatList over ${data.length} items, ${numColumns} column(s)`);
86
91
  const endReached = listens('onEndReached')
87
92
  ? (info) => emit('endReached', info)
@@ -11,8 +11,8 @@
11
11
  // events (onShow/onDismiss/onRequestClose/onOrientationChange) are real ViewConfig DirectEvents,
12
12
  // so, unlike Switch's pure-JS onValueChange, they forward to the host raw via passthrough.
13
13
  import { defineComponent, h, ref, watch } from '@vue/runtime-core';
14
- import { createInitialModalState, modalReducer, renderModal, resolveAccessibilityProps, shouldRenderModal, } from '@symbiote-native/components';
15
- import { dlog, } from '@symbiote-native/engine';
14
+ import { createInitialModalState, isModalVisible, modalReducer, modalVisibilityAction, renderModal, resolveAccessibilityProps, shouldRenderModal, } from '@symbiote-native/components';
15
+ import { dlog, Platform, } from '@symbiote-native/engine';
16
16
  import { normalizeVueAttrs } from '../../utils/normalize-attrs.js';
17
17
  function asBoolean(value) {
18
18
  return typeof value === 'boolean' ? value : undefined;
@@ -79,16 +79,23 @@ function forwardAttrs(attrs) {
79
79
  return result;
80
80
  }
81
81
  export const Modal = defineComponent((_props, { attrs: rawAttrs, slots, emit }) => {
82
- const state = ref(createInitialModalState(rawAttrs.visible === true));
83
- // POST-flush so the transition fires AFTER the render that used the OLD state: on visible→hidden
84
- // the node renders once more (state.isRendered still true → the keep-alive frame), then this
85
- // drops it and the next render unmounts. flush:'pre' would unmount immediately, killing the
86
- // keep-alive. The reducer is identity-stable, so a no-op transition triggers no extra render.
87
- watch(() => rawAttrs.visible === true, isVisible => {
88
- state.value = modalReducer(state.value, isVisible ? { type: 'show' } : { type: 'hide' });
82
+ const state = ref(createInitialModalState(isModalVisible(rawAttrs.visible)));
83
+ // Arms the iOS keep-alive on show; a hide is left to the native dismiss (state/modal.ts). The
84
+ // reducer is identity-stable, so a no-op transition triggers no extra render.
85
+ watch(() => isModalVisible(rawAttrs.visible), isVisible => {
86
+ const action = modalVisibilityAction(isVisible);
87
+ if (action !== undefined)
88
+ state.value = modalReducer(state.value, action);
89
89
  }, { flush: 'post' });
90
+ // Modal.js: onDismiss is iOS-only — it drops the keep-alive, then tells the app.
91
+ const handleDismiss = () => {
92
+ if (Platform.OS !== 'ios')
93
+ return;
94
+ state.value = modalReducer(state.value, { type: 'hide' });
95
+ emit('dismiss');
96
+ };
90
97
  return () => {
91
- const isVisible = rawAttrs.visible === true;
98
+ const isVisible = isModalVisible(rawAttrs.visible);
92
99
  if (!shouldRenderModal(isVisible, state.value)) {
93
100
  dlog('Modal hidden -> no node committed');
94
101
  return null;
@@ -118,7 +125,7 @@ export const Modal = defineComponent((_props, { attrs: rawAttrs, slots, emit })
118
125
  ...root.props,
119
126
  key: root.key,
120
127
  onShow: () => emit('show'),
121
- onDismiss: () => emit('dismiss'),
128
+ onDismiss: handleDismiss,
122
129
  onRequestClose: () => emit('requestClose'),
123
130
  onOrientationChange: (event) => emit('orientationChange', event),
124
131
  }, [
@@ -39,6 +39,8 @@ export interface IVirtualizedListProps<ItemT> {
39
39
  scrollEventThrottle?: number;
40
40
  keyboardShouldPersistTaps?: boolean | 'always' | 'never' | 'handled';
41
41
  keyboardDismissMode?: 'none' | 'on-drag' | 'interactive';
42
+ removeClippedSubviews?: boolean;
43
+ nestedScrollEnabled?: boolean;
42
44
  style?: IStyleProp<IViewStyle>;
43
45
  contentContainerStyle?: IStyleProp<IViewStyle>;
44
46
  [key: string]: unknown;
@@ -562,8 +562,9 @@ export const VirtualizedList = defineComponent((props, { attrs, expose, emit, sl
562
562
  const resolvedContentContainerStyle = p.horizontal
563
563
  ? [p.contentContainerStyle, { width: m.total }]
564
564
  : p.contentContainerStyle;
565
+ // VirtualizedList.js: `[inversionStyle, style]` — the app's style can override the flip.
565
566
  const resolvedStyle = p.inverted
566
- ? [p.style, p.horizontal ? INVERTED_X_STYLE : INVERTED_Y_STYLE]
567
+ ? [p.horizontal ? INVERTED_X_STYLE : INVERTED_Y_STYLE, p.style]
567
568
  : p.style;
568
569
  // `horizontal` is NOT in the bag: the axis is the TAG (`horizontal-scroll-view`), so passing
569
570
  // it would be redundant at best and a contradiction the behavior has to warn about at worst.
@@ -578,6 +579,9 @@ export const VirtualizedList = defineComponent((props, { attrs, expose, emit, sl
578
579
  // The raw scroll-lifecycle callbacks (onScrollBeginDrag/…) and scrollEventThrottle are NOT in
579
580
  // PROP_KEYS, so they already ride through via ...p.forwarded. The keyboard props come from
580
581
  // typed props (PROP_KEYS), so re-set them explicitly here (only when provided).
582
+ // VirtualizedList.js:1111 — Android moves the scrollbar back after the `scale: -1` flip.
583
+ if (p.inverted)
584
+ scrollProps.isInvertedVirtualizedList = true;
581
585
  if (p.keyboardShouldPersistTaps !== undefined) {
582
586
  scrollProps.keyboardShouldPersistTaps = p.keyboardShouldPersistTaps;
583
587
  }
@@ -35,6 +35,8 @@ export interface IVirtualizedSectionListProps<ItemT> {
35
35
  scrollEventThrottle?: number;
36
36
  keyboardShouldPersistTaps?: boolean | 'always' | 'never' | 'handled';
37
37
  keyboardDismissMode?: 'none' | 'on-drag' | 'interactive';
38
+ removeClippedSubviews?: boolean;
39
+ nestedScrollEnabled?: boolean;
38
40
  style?: IStyleProp<IViewStyle>;
39
41
  contentContainerStyle?: IStyleProp<IViewStyle>;
40
42
  [key: string]: unknown;
@@ -3,7 +3,7 @@
3
3
  // drives the exact same retained tree React does: the proof the core is framework-
4
4
  // agnostic.
5
5
  import { callWithErrorHandling, createRenderer, ErrorCodes, markRaw, } from '@vue/runtime-core';
6
- import { appendChild, createAnchor, createElement, createRawText, childrenOf, dlog, insertBefore, isRawTextNode, isTextContainer, nextSiblingOf, parentOf, removeChild, routeProp, setProp, setText, textOf, toPublicInstance, SymbioteSurface, } from '@symbiote-native/engine';
6
+ import { appendChild, createAnchor, createElement, createRawText, childrenOf, dlog, insertBefore, isRawTextNode, isTextContainer, nextSiblingOf, parentOf, removeChild, routeProp, setText, textOf, toPublicInstance, SymbioteSurface, } from '@symbiote-native/engine';
7
7
  import { descriptorFor } from '@symbiote-native/components';
8
8
  import { normalizeVueAttrKey } from '../utils/normalize-attrs.js';
9
9
  function isSurface(parent) {
@@ -16,8 +16,12 @@ const {
16
16
  parseCache,
17
17
  compileScript,
18
18
  registerTS,
19
+ babelParse,
19
20
  } = require('@vue/compiler-sfc');
20
- const { createCompoundExpression } = require('@vue/compiler-core');
21
+ const {
22
+ createCompoundExpression,
23
+ createSimpleExpression,
24
+ } = require('@vue/compiler-core');
21
25
 
22
26
  // A bare-specifier type import (`import type { X } from '@symbiote-native/navigation/vue'`) needs
23
27
  // real node_modules resolution to turn the specifier into a file path - compileScript's own `fs`
@@ -146,6 +150,51 @@ function trimReflowedTextNodeTransform(node) {
146
150
  // Shared with ./babel-jsx.cjs: Vue's two compilers must give one answer to element-vs-component.
147
151
  const INTRINSIC_TAGS = require('./intrinsic-tags.cjs');
148
152
 
153
+ const SYMBIOTE_SOURCE_PREFIX = '@symbiote-native/';
154
+
155
+ // Local names the file imports from any `@symbiote-native/*` package (`FlatList`, `Animated`).
156
+ function symbioteImportsOf(descriptor) {
157
+ const locals = new Set();
158
+ for (const block of [descriptor.script, descriptor.scriptSetup]) {
159
+ if (block == null) continue;
160
+ const plugins = block.lang === 'ts' || block.lang === 'tsx' ? ['typescript'] : [];
161
+ const program = babelParse(block.content, { sourceType: 'module', plugins }).program;
162
+ for (const statement of program.body) {
163
+ if (
164
+ statement.type !== 'ImportDeclaration' ||
165
+ !statement.source.value.startsWith(SYMBIOTE_SOURCE_PREFIX)
166
+ )
167
+ continue;
168
+ for (const specifier of statement.specifiers) locals.add(specifier.local.name);
169
+ }
170
+ }
171
+ return locals;
172
+ }
173
+
174
+ // Vue casts a bare attribute to `true` only for a prop declared Boolean. Our tags and components
175
+ // declare none, so `nested-scroll-enabled` reached Android as "" and the ViewManager threw
176
+ // `String cannot be cast to Boolean`. The app's own components keep Vue's semantics.
177
+ function createBareBooleanNodeTransform(symbioteLocals) {
178
+ const isOurs = tag =>
179
+ INTRINSIC_TAGS.has(tag) || symbioteLocals.has(tag.split('.')[0]);
180
+ return function bareBooleanNodeTransform(node) {
181
+ if (node.type !== 1 /* NodeTypes.ELEMENT */ || !isOurs(node.tag)) return;
182
+ node.props = node.props.map(prop =>
183
+ prop.type === 6 /* NodeTypes.ATTRIBUTE */ && prop.value === undefined
184
+ ? {
185
+ type: 7 /* NodeTypes.DIRECTIVE */,
186
+ name: 'bind',
187
+ rawName: `:${prop.name}`,
188
+ arg: createSimpleExpression(prop.name, true, prop.loc),
189
+ exp: createSimpleExpression('true', false, prop.loc, 3 /* CAN_STRINGIFY */),
190
+ modifiers: [],
191
+ loc: prop.loc,
192
+ }
193
+ : prop,
194
+ );
195
+ };
196
+ }
197
+
149
198
 
150
199
  // A short, stable id per file, used as the SFC scope id regardless of whether the file has
151
200
  // scoped styles - built on css-parser's shared hashFilePath so the algorithm isn't duplicated
@@ -307,7 +356,10 @@ async function compileSfc(src, filename) {
307
356
 
308
357
  // Scoped-class rewriting is skipped entirely (not even passed to the compiler) when nothing in
309
358
  // this file is scoped, so a .vue with only unscoped/no styles adds no runtime cost.
310
- const nodeTransforms = [trimReflowedTextNodeTransform];
359
+ const nodeTransforms = [
360
+ trimReflowedTextNodeTransform,
361
+ createBareBooleanNodeTransform(symbioteImportsOf(descriptor)),
362
+ ];
311
363
  if (scopedClassNames.size > 0)
312
364
  nodeTransforms.push(createScopeClassNodeTransform(scopedClassNames));
313
365
  // UNCONDITIONAL, and covering EVERY intrinsic rather than the ones this file happens to import.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbiote-native/vue",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "SymbioteNative's Vue adapter — a @vue/runtime-core createRenderer driving real native iOS/Android views through the same engine as the React adapter.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -70,18 +70,18 @@
70
70
  "@vue/compiler-sfc": "^3.5.13",
71
71
  "@vue/runtime-core": "^3.5.13",
72
72
  "typescript": "~6.0.0",
73
- "@symbiote-native/components": "3.0.1",
74
- "@symbiote-native/css-parser": "0.5.0"
73
+ "@symbiote-native/components": "3.1.1",
74
+ "@symbiote-native/css-parser": "0.5.1"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "vue": ">=3.5.0",
78
78
  "react-native": ">=0.86",
79
- "@symbiote-native/engine": "^1.2.0"
79
+ "@symbiote-native/engine": "^1.3.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@babel/core": "^7.25.2",
83
- "@symbiote-native/engine": "1.2.0",
84
- "@symbiote-native/test-utils": "0.4.1"
83
+ "@symbiote-native/engine": "1.3.0",
84
+ "@symbiote-native/test-utils": "0.4.3"
85
85
  },
86
86
  "scripts": {
87
87
  "typecheck": "tsc --build",