nativescript-vue 3.0.3 → 3.1.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.
Files changed (68) hide show
  1. package/README.md +37 -2
  2. package/devtools.js +100 -24
  3. package/dist/components/ActionBar.js +1 -1
  4. package/dist/components/ActionBar.js.map +1 -1
  5. package/dist/components/ListView.d.ts +9 -3
  6. package/dist/components/ListView.js +46 -14
  7. package/dist/components/ListView.js.map +1 -1
  8. package/dist/components/Platform.d.ts +8 -0
  9. package/dist/components/Platform.js +15 -0
  10. package/dist/components/Platform.js.map +1 -0
  11. package/dist/components/index.d.ts +16 -5
  12. package/dist/components/index.js +4 -1
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/directives/vShow.js.map +1 -1
  15. package/dist/dom/index.d.ts +14 -1
  16. package/dist/dom/index.js +58 -19
  17. package/dist/dom/index.js.map +1 -1
  18. package/dist/index.d.ts +6 -2
  19. package/dist/index.js +52 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/nativescript/elements.js +61 -43
  22. package/dist/nativescript/elements.js.map +1 -1
  23. package/dist/nativescript/index.js.map +1 -1
  24. package/dist/plugins/modals.d.ts +4 -1
  25. package/dist/plugins/modals.js +85 -15
  26. package/dist/plugins/modals.js.map +1 -1
  27. package/dist/plugins/navigation.d.ts +7 -2
  28. package/dist/plugins/navigation.js +45 -7
  29. package/dist/plugins/navigation.js.map +1 -1
  30. package/dist/registry/index.js.map +1 -1
  31. package/dist/renderer/index.js.map +1 -1
  32. package/dist/renderer/modules/attrs.js +27 -8
  33. package/dist/renderer/modules/attrs.js.map +1 -1
  34. package/dist/renderer/modules/class.js.map +1 -1
  35. package/dist/renderer/modules/events.js +0 -1
  36. package/dist/renderer/modules/events.js.map +1 -1
  37. package/dist/renderer/modules/style.js +13 -16
  38. package/dist/renderer/modules/style.js.map +1 -1
  39. package/dist/renderer/nodeOps.js.map +1 -1
  40. package/dist/renderer/patchProp.js +38 -16
  41. package/dist/renderer/patchProp.js.map +1 -1
  42. package/dist/renderer/runtimeDomOverrides.d.ts +11 -0
  43. package/dist/renderer/runtimeDomOverrides.js +23 -0
  44. package/dist/renderer/runtimeDomOverrides.js.map +1 -1
  45. package/dist/runtimeHelpers.d.ts +12 -1
  46. package/dist/runtimeHelpers.js +27 -3
  47. package/dist/runtimeHelpers.js.map +1 -1
  48. package/dist/util/logger.js.map +1 -1
  49. package/nativescript.webpack.js +199 -54
  50. package/package.json +49 -19
  51. package/dist/compiler-sfc/index.d.ts +0 -1
  52. package/dist/compiler-sfc/index.js +0 -2
  53. package/dist/compiler-sfc/index.js.map +0 -1
  54. package/dist/compiler.d.ts +0 -4
  55. package/dist/compiler.js +0 -32
  56. package/dist/compiler.js.map +0 -1
  57. package/dist/directives/vModel.d.ts +0 -8
  58. package/dist/directives/vModel.js +0 -38
  59. package/dist/directives/vModel.js.map +0 -1
  60. package/dist/plugins/templates.d.ts +0 -10
  61. package/dist/plugins/templates.js +0 -12
  62. package/dist/plugins/templates.js.map +0 -1
  63. package/dist/types.d.ts +0 -15
  64. package/dist/types.js +0 -2
  65. package/dist/types.js.map +0 -1
  66. package/dist/withCompiler.d.ts +0 -3
  67. package/dist/withCompiler.js +0 -6
  68. package/dist/withCompiler.js.map +0 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <a href="https://www.npmjs.com/package/nativescript-vue">
9
9
  <img src="https://img.shields.io/npm/v/nativescript-vue/latest.svg" alt="npm"/>
10
10
  </a>
11
- <a href="https://github.com/nativescript-vue/nativescript-vue/blob/master/LICENSE">
11
+ <a href="https://github.com/nativescript-vue/nativescript-vue/blob/main/LICENSE">
12
12
  <img src="https://img.shields.io/github/license/nativescript-vue/nativescript-vue.svg" alt="license"/>
13
13
  </a>
14
14
  </p>
@@ -34,12 +34,26 @@ Please refer to our [Upgrade Guide](https://nativescript-vue.org/docs/essentials
34
34
 
35
35
  ## Using Vue Devtools
36
36
 
37
- To enable Vue Devtools, run:
37
+ Install the standalone devtools in your app (it is not pulled in by
38
+ nativescript-vue because it depends on Electron):
39
+
40
+ ```sh
41
+ npm i -D @vue/devtools@^8
42
+ ```
43
+
44
+ Then run with the `vueDevtools` flag. The devtools window opens on the host
45
+ machine and the app connects to it:
38
46
 
39
47
  ```sh
40
48
  ns run ios|android --env.vueDevtools
41
49
  ```
42
50
 
51
+ A free port from 8098 up is picked automatically; pass `--env.vueDevtoolsPort=9000`
52
+ to pin one, or `--env.vueDevtoolsHost=http://192.168.1.10` to reach the
53
+ devtools from a physical device. `--env.vueDevtoolsSpawn=false` skips
54
+ launching the devtools app, for when one is already running, and
55
+ `--env.vueDevtoolsDebug` logs the socket traffic between app and devtools.
56
+
43
57
  🛠️ **Android Users:**
44
58
  To allow Vue Devtools to connect, enable **cleartext HTTP traffic** in your `AndroidManifest.xml`:
45
59
 
@@ -49,6 +63,27 @@ To allow Vue Devtools to connect, enable **cleartext HTTP traffic** in your `And
49
63
  .../>
50
64
  ```
51
65
 
66
+ ## TypeScript
67
+
68
+ Types for every core element, `$navigateTo`, `$showModal` and friends ship
69
+ with the package. Third-party libraries such as Pinia or vue-i18n augment the
70
+ `vue` module, and code often imports from `vue`. The templates map `vue` to
71
+ `nativescript-vue` in `tsconfig.json` so both resolve; add this to existing
72
+ projects:
73
+
74
+ ```json
75
+ {
76
+ "compilerOptions": {
77
+ "paths": {
78
+ "vue": ["./node_modules/nativescript-vue"]
79
+ }
80
+ },
81
+ "vueCompilerOptions": {
82
+ "lib": "nativescript-vue"
83
+ }
84
+ }
85
+ ```
86
+
52
87
  ## Issues
53
88
 
54
89
  If you encounter any issues, please open a new issue with as much detail as possible.
package/devtools.js CHANGED
@@ -1,33 +1,109 @@
1
+ // Bundled into the app ahead of its entry point by nativescript.webpack.js
2
+ // when running with --env.vueDevtools. Connects to the standalone Vue
3
+ // Devtools app over socket.io, mirroring @vue/devtools-electron's user-app
4
+ // client but without the DOM inspector code that expects a browser.
1
5
  if (__DEV__) {
2
6
  try {
3
- const _global = globalThis.global;
7
+ const target = globalThis;
8
+ const host = (target.__VUE_DEVTOOLS_HOST__ ??= __NS_VUE_DEVTOOLS_HOST__);
9
+ const port = (target.__VUE_DEVTOOLS_PORT__ ??= __NS_VUE_DEVTOOLS_PORT__);
10
+ const url = `${host}:${port}`;
4
11
 
5
- const host = (_global.__VUE_DEVTOOLS_HOST__ ??= __NS_VUE_DEVTOOLS_HOST__);
6
- const port = (_global.__VUE_DEVTOOLS_PORT__ ??= __NS_VUE_DEVTOOLS_PORT__);
7
- _global.__VUE_DEVTOOLS_TOAST__ ??= (message) => {
8
- console.warn('[VueDevtools]', message);
9
- };
12
+ const {
13
+ devtools,
14
+ setElectronServerContext,
15
+ createRpcServer,
16
+ } = require('@vue/devtools-kit');
17
+
18
+ // The hook must exist before anything evaluates nativescript-vue: its
19
+ // renderer reads the hook once at import and, without a window to
20
+ // replay into, treats a missing hook as "devtools not installed" for
21
+ // the rest of the session. @vue/devtools-core imports 'vue', which the
22
+ // webpack alias resolves to nativescript-vue, so it has to come after.
23
+ devtools.init();
24
+
25
+ const { io } = require('socket.io-client');
26
+ const { functions } = require('@vue/devtools-core');
10
27
 
11
28
  const platform = global.isAndroid ? 'Android' : 'iOS';
29
+ console.log(`[VueDevtools] Connecting to ${url} (${platform})...`);
30
+
31
+ const socket = io(url, {
32
+ // NativeScript exposes XMLHttpRequest but no global WebSocket
33
+ transports: ['polling'],
34
+ reconnectionDelayMax: 5000,
35
+ });
36
+
37
+ if (__NS_VUE_DEVTOOLS_DEBUG__) {
38
+ const preview = (args) =>
39
+ args.map((a) => String(a).slice(0, 160)).join(' ');
40
+ socket.onAny((event, ...args) =>
41
+ console.log(`[VueDevtools] <- ${event} ${preview(args)}`),
42
+ );
43
+ socket.onAnyOutgoing((event, ...args) =>
44
+ console.log(`[VueDevtools] -> ${event} ${preview(args)}`),
45
+ );
46
+ socket.on('disconnect', (reason) =>
47
+ console.log(`[VueDevtools] disconnected: ${reason}`),
48
+ );
49
+ socket.io.on('reconnect_attempt', (n) =>
50
+ console.log(`[VueDevtools] reconnect attempt ${n}`),
51
+ );
52
+ socket.io.on('error', (err) =>
53
+ console.log(`[VueDevtools] transport error: ${err.message}`),
54
+ );
55
+ }
56
+
57
+ let serverReady = false;
58
+ socket.on('connect', () => {
59
+ // the Socket instance survives reconnects, so the RPC server only
60
+ // needs wiring once; the devtools window needs init after every
61
+ // (re)connect because it is what evicted us in the first place
62
+ if (!serverReady) {
63
+ setElectronServerContext(socket);
64
+ createRpcServer(functions, { preset: 'electron' });
65
+ serverReady = true;
66
+ }
67
+ socket.emit('vue-devtools:init');
68
+ console.log(`[VueDevtools] Connected to ${url}`);
69
+
70
+ if (__NS_VUE_DEVTOOLS_DEBUG__) {
71
+ setTimeout(() => {
72
+ const { devtoolsState } = require('@vue/devtools-kit');
73
+ console.log(
74
+ `[VueDevtools] state: apps=${devtoolsState.appRecords.length} ` +
75
+ `connected=${devtoolsState.connected} ` +
76
+ `clientConnected=${devtoolsState.clientConnected} ` +
77
+ `vue=${devtoolsState.vueVersion}`,
78
+ );
79
+ }, 2000);
80
+ }
81
+ });
82
+
83
+ // the devtools app tells every other client to leave whenever a new
84
+ // socket connects, including when its own window opens after the app;
85
+ // reconnecting shortly after makes the start order irrelevant
86
+ socket.on('vue-devtools:disconnect-user-app', () => {
87
+ socket.disconnect();
88
+ setTimeout(() => socket.connect(), 1000);
89
+ });
12
90
 
13
- const documentShim = {
14
- // this shows as the title in VueDevtools
15
- title: `${platform} :: ${host}:${port} :: NativeScript`,
16
- querySelector: () => null,
17
- querySelectorAll: () => [],
18
- };
19
-
20
- _global.document = Object.assign({}, documentShim, _global.document);
21
- _global.addEventListener ??= () => {};
22
- _global.removeEventListener ??= () => {};
23
- _global.window ??= _global;
24
-
25
- console.warn(
26
- `[VueDevtools] Connecting to ${global.__VUE_DEVTOOLS_HOST__}:${global.__VUE_DEVTOOLS_PORT__}...`,
27
- );
28
- require('@vue/devtools/build/hook.js');
29
- require('@vue/devtools/build/backend.js');
91
+ let reportedError = false;
92
+ socket.on('connect_error', (err) => {
93
+ if (reportedError) return;
94
+ reportedError = true;
95
+ console.warn(
96
+ `[VueDevtools] Could not reach ${url}: ${err.message}. ` +
97
+ `Is the devtools app running?` +
98
+ (global.isAndroid
99
+ ? ` On Android, cleartext HTTP must be allowed (android:usesCleartextTraffic="true").`
100
+ : ''),
101
+ );
102
+ });
103
+ socket.on('connect', () => {
104
+ reportedError = false;
105
+ });
30
106
  } catch (e) {
31
- console.warn('[VueDevtools] Failed to init:', e);
107
+ console.warn('[VueDevtools] Failed to start:', e);
32
108
  }
33
109
  }
@@ -12,7 +12,7 @@ registerElement('NSCActionBar', () => NSCActionBar, {
12
12
  actionBar.navigationButton = childView;
13
13
  }
14
14
  else if (childView instanceof NSCActionItem) {
15
- if (atIndex) {
15
+ if (typeof atIndex === 'number') {
16
16
  const ai = actionBar.actionItems.getItems();
17
17
  ai.splice(atIndex, 0, childView);
18
18
  actionBar.actionItems.setItems(ai);
@@ -1 +1 @@
1
- {"version":3,"file":"ActionBar.js","sourceRoot":"","sources":["../../src/components/ActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,YAAY,EACzB,UAAU,IAAI,aAAa,EAC3B,gBAAgB,IAAI,mBAAmB,EACvC,IAAI,IAAI,OAAO,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,eAAe,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE;IAClD,SAAS,sCAA8B;IACvC,OAAO,EAAE;QACP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO;YAC3B,MAAM,SAAS,GAAG,MAAM,CAAC,UAA0B,CAAC;YACpD,MAAM,SAAS,GAAG,KAAK,CAAC,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AC,CAAC;YAC9C,CAAC;iBAAM,CAAC;gBACN,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;oBACtC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;gBAC7B,CAAC;YACH,CAAC;QACH,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,eAAe,CAAC;IACrD,IAAI,EAAE,WAAW;IACjB,KAAK,CAAC,KAAK,EAAE,GAAG;QACd,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,CACN,cAAc,EACd;gBACE,GAAG,GAAG,CAAC,KAAK;gBACZ,cAAc,CAAC,KAAK;oBAClB,MAAM,EAAE,GAAG,KAAK,CAAC,EAAgB,CAAC;oBAClC,MAAM,SAAS,GAAG,EAAE,CAAC,UAA0B,CAAC;oBAChD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAwB,CAAC;oBAE3C,IAAI,MAAM,CAAC,UAAU,YAAY,OAAO,EAAE,CAAC;wBACzC,MAAM,CAAC,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;oBAC1C,CAAC;yBAAM,CAAC;wBACN,IAAI,OAAO,EAAE,CAAC;4BACZ,MAAM,CAAC,IAAI,CACT,2DAA2D;gCACzD,QAAQ,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,YAAY,CACzD,CAAC;wBACJ,CAAC;oBACH,CAAC;gBACH,CAAC;aACF,EACD,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CACpD,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {\n ActionBar as NSCActionBar,\n ActionItem as NSCActionItem,\n NavigationButton as NSCNavigationButton,\n Page as NSCPage,\n} from '@nativescript/core';\nimport { defineComponent, h } from '@vue/runtime-core';\nimport { NSVElement, NSVViewFlags } from '../dom';\nimport { registerElement } from '../registry';\nimport { logger } from '../util/logger';\n\nregisterElement('NSCActionBar', () => NSCActionBar, {\n viewFlags: NSVViewFlags.SKIP_ADD_TO_DOM,\n nodeOps: {\n insert(child, parent, atIndex) {\n const actionBar = parent.nativeView as NSCActionBar;\n const childView = child.nativeView;\n\n if (childView instanceof NSCNavigationButton) {\n actionBar.navigationButton = childView;\n } else if (childView instanceof NSCActionItem) {\n if (typeof atIndex === 'number') {\n const ai: NSCActionItem[] = actionBar.actionItems.getItems();\n ai.splice(atIndex, 0, childView);\n (actionBar.actionItems as any).setItems(ai);\n } else {\n actionBar.actionItems.addItem(childView);\n }\n } else {\n actionBar.titleView = childView;\n }\n },\n remove(child, parent) {\n const actionBar = parent.nativeView as NSCActionBar;\n const childView = child.nativeView;\n\n if (childView instanceof NSCNavigationButton) {\n if (actionBar.navigationButton === childView) {\n actionBar.navigationButton = null;\n }\n } else if (childView instanceof NSCActionItem) {\n actionBar.actionItems.removeItem(childView);\n } else {\n if (actionBar.titleView === childView) {\n actionBar.titleView = null;\n }\n }\n },\n },\n});\n\nexport const ActionBar = /*#__PURE__*/ defineComponent({\n name: 'ActionBar',\n setup(props, ctx) {\n return () => {\n return h(\n 'NSCActionBar',\n {\n ...ctx.attrs,\n onVnodeMounted(vnode) {\n const el = vnode.el as NSVElement;\n const actionBar = el.nativeView as NSCActionBar;\n const parent = el.parentNode as NSVElement;\n\n if (parent.nativeView instanceof NSCPage) {\n parent.nativeView.actionBar = actionBar;\n } else {\n if (__DEV__) {\n logger.warn(\n `<ActionBar> must be a direct child of a <Page> element - ` +\n `got <${parent.nativeView.constructor.name}> instead.`,\n );\n }\n }\n },\n },\n ctx.slots.default ? ctx.slots.default() : undefined,\n );\n };\n },\n});\n"]}
@@ -1,11 +1,13 @@
1
1
  import { VNode } from '@vue/runtime-core';
2
- import { ObservableArray } from '@nativescript/core';
2
+ import { ItemEventData, ObservableArray } from '@nativescript/core';
3
3
  export interface ListItem<T = any> {
4
4
  item: T;
5
5
  index: number;
6
6
  even: boolean;
7
7
  odd: boolean;
8
8
  }
9
+ /** Payload of the ListView `itemTap` event. */
10
+ export type ListViewItemTapEvent<T = any> = ItemEventData & ListItem<T>;
9
11
  export declare const ListView: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
10
12
  items: {
11
13
  validator(value: unknown): value is any[] | ObservableArray<any>;
@@ -13,9 +15,13 @@ export declare const ListView: import("@vue/runtime-core").DefineComponent<impor
13
15
  itemTemplateSelector: FunctionConstructor;
14
16
  }>, () => VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
15
17
  [key: string]: any;
16
- }>, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
18
+ }>, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
19
+ itemTap: (event: ListViewItemTapEvent) => boolean;
20
+ }, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
17
21
  items: {
18
22
  validator(value: unknown): value is any[] | ObservableArray<any>;
19
23
  };
20
24
  itemTemplateSelector: FunctionConstructor;
21
- }>> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
25
+ }>> & Readonly<{
26
+ onItemTap?: (event: ListViewItemTapEvent<any>) => any;
27
+ }>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
@@ -1,4 +1,4 @@
1
- import { Comment, defineComponent, getCurrentInstance, h, ref, watch, } from '@vue/runtime-core';
1
+ import { Comment, defineComponent, Fragment, getCurrentInstance, h, ref, watch, } from '@vue/runtime-core';
2
2
  import { ListView as NSCListView, ObservableArray, } from '@nativescript/core';
3
3
  import { registerElement } from '../registry';
4
4
  import { ELEMENT_REF } from '../runtimeHelpers';
@@ -15,6 +15,22 @@ function getListItem(item, index) {
15
15
  };
16
16
  }
17
17
  const LIST_CELL_ID = Symbol('list_cell_id');
18
+ /**
19
+ * The element vnodes a template renders. Fragments are unwrapped because a
20
+ * forwarded `<slot>` renders as one, and a cell needs an element to hand to
21
+ * the native ListView.
22
+ */
23
+ function templateRoots(vnodes) {
24
+ return vnodes.flatMap((vnode) => {
25
+ if (vnode.type === Comment) {
26
+ return [];
27
+ }
28
+ if (vnode.type === Fragment) {
29
+ return templateRoots(vnode.children);
30
+ }
31
+ return [vnode];
32
+ });
33
+ }
18
34
  export const ListView = /*#__PURE__*/ defineComponent({
19
35
  name: 'ListView',
20
36
  props: {
@@ -25,6 +41,9 @@ export const ListView = /*#__PURE__*/ defineComponent({
25
41
  },
26
42
  itemTemplateSelector: Function,
27
43
  },
44
+ emits: {
45
+ itemTap: (event) => !!event,
46
+ },
28
47
  setup(props, ctx) {
29
48
  const itemTemplates = Object.keys(ctx.slots).map((slotName) => {
30
49
  return {
@@ -37,8 +56,9 @@ export const ListView = /*#__PURE__*/ defineComponent({
37
56
  const getSlotName = (itemCtx) => props.itemTemplateSelector?.(itemCtx) ?? 'default';
38
57
  const listView = ref(null);
39
58
  const vm = getCurrentInstance();
40
- watch(props, () => {
59
+ function refresh() {
41
60
  try {
61
+ // ObservableArray notifies the native ListView of changes itself
42
62
  if (props.items instanceof ObservableArray) {
43
63
  return;
44
64
  }
@@ -48,15 +68,27 @@ export const ListView = /*#__PURE__*/ defineComponent({
48
68
  catch (err) {
49
69
  console.error('Error while refreshing ListView', err);
50
70
  }
51
- });
71
+ }
72
+ // depth 1 tracks the array's length and slots without walking into the
73
+ // items themselves; cells re-render on their own when item fields change
74
+ watch(() => props.items, refresh, { deep: 1 });
75
+ watch(() => props.itemTemplateSelector, refresh);
76
+ function listItemAt(index) {
77
+ return getListItem(props.items instanceof ObservableArray
78
+ ? props.items.getItem(index)
79
+ : props.items[index], index);
80
+ }
81
+ // the native event carries only the index; the template's item context
82
+ // is what handlers want
83
+ function onItemTap(event) {
84
+ ctx.emit('itemTap', Object.assign(event, listItemAt(event.index)));
85
+ }
52
86
  let cellId = 0;
53
87
  const cells = ref({});
54
- function onitemLoading(event) {
88
+ function onItemLoading(event) {
55
89
  const el = event.view?.[ELEMENT_REF];
56
90
  const id = el?.nativeView[LIST_CELL_ID] ?? `LIST_CELL_${cellId++}`;
57
- const itemCtx = getListItem(props.items instanceof ObservableArray
58
- ? props.items.getItem(event.index)
59
- : props.items[event.index], event.index);
91
+ const itemCtx = listItemAt(event.index);
60
92
  // update the cell data with the current row
61
93
  cells.value[id] = {
62
94
  itemCtx,
@@ -80,15 +112,14 @@ export const ListView = /*#__PURE__*/ defineComponent({
80
112
  }
81
113
  // render all realized templates as children
82
114
  const cellVNODES = () => Object.entries(cells.value).map(([id, entry]) => {
83
- const vnodes = ctx.slots[entry.slotName]?.(entry.itemCtx) ?? [];
84
- const nonCommentVnodes = vnodes.filter((vnode) => vnode.type !== Comment);
85
- if (nonCommentVnodes.length === 0) {
115
+ const roots = templateRoots(ctx.slots[entry.slotName]?.(entry.itemCtx) ?? []);
116
+ if (roots.length === 0) {
86
117
  logger.warn(`ListView template must contain at least one element.`);
87
118
  }
88
- else if (nonCommentVnodes.length > 1) {
89
- logger.warn(`ListView template must contain a single root element. Found: ${vnodes.length}. Only the first one will be used.`);
119
+ else if (roots.length > 1) {
120
+ logger.warn(`ListView template must contain a single root element. Found: ${roots.length}. Only the first one will be used.`);
90
121
  }
91
- const vnode = nonCommentVnodes.at(0) ??
122
+ const vnode = roots.at(0) ??
92
123
  // default template is just a label
93
124
  h('Label', {
94
125
  text: entry.itemCtx.item,
@@ -103,7 +134,8 @@ export const ListView = /*#__PURE__*/ defineComponent({
103
134
  items: props.items,
104
135
  itemTemplates,
105
136
  itemTemplateSelector,
106
- onitemLoading,
137
+ onItemLoading,
138
+ onItemTap,
107
139
  }, cellVNODES());
108
140
  };
109
141
  },
@@ -1 +1 @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9C,MAAM,KAAK,GAAG,aAAa,CACzB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CACjD,CAAC;YAEF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;YACtE,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,CAAC,IAAI,CACT,gEAAgE,KAAK,CAAC,MAAM,oCAAoC,CACjH,CAAC;YACJ,CAAC;YAED,MAAM,KAAK,GACT,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBACX,mCAAmC;gBACnC,CAAC,CAAC,OAAO,EAAE;oBACT,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI;iBACzB,CAAC,CAAC;YAEL,qEAAqE;YACrE,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;YAEf,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,CACN,aAAa,EACb;gBACE,GAAG,EAAE,QAAQ;gBACb,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,aAAa;gBACb,oBAAoB;gBACpB,aAAa;gBACb,SAAS;aACV,EACD,UAAU,EAAE,CACb,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {\n Comment,\n defineComponent,\n Fragment,\n getCurrentInstance,\n h,\n ref,\n VNode,\n watch,\n} from '@vue/runtime-core';\n\nimport {\n ItemEventData,\n ListView as NSCListView,\n ObservableArray,\n} from '@nativescript/core';\n\nimport { NSVElement, NSVViewFlags } from '../dom';\nimport { registerElement } from '../registry';\nimport { ELEMENT_REF } from '../runtimeHelpers';\nimport { logger } from '../util/logger';\n\nregisterElement('NSCListView', () => NSCListView, {\n viewFlags: NSVViewFlags.NO_CHILDREN,\n});\n\nexport interface ListItem<T = any> {\n item: T;\n index: number;\n even: boolean;\n odd: boolean;\n}\n\n/** Payload of the ListView `itemTap` event. */\nexport type ListViewItemTapEvent<T = any> = ItemEventData & ListItem<T>;\n\nfunction getListItem(item: any, index: number): ListItem {\n return {\n item,\n index,\n even: index % 2 === 0,\n odd: index % 2 !== 0,\n };\n}\n\nconst LIST_CELL_ID = Symbol('list_cell_id');\n\n/**\n * The element vnodes a template renders. Fragments are unwrapped because a\n * forwarded `<slot>` renders as one, and a cell needs an element to hand to\n * the native ListView.\n */\nfunction templateRoots(vnodes: VNode[]): VNode[] {\n return vnodes.flatMap((vnode) => {\n if (vnode.type === Comment) {\n return [];\n }\n if (vnode.type === Fragment) {\n return templateRoots(vnode.children as VNode[]);\n }\n return [vnode];\n });\n}\n\nexport const ListView = /*#__PURE__*/ defineComponent({\n name: 'ListView',\n props: {\n items: {\n validator(value) {\n return Array.isArray(value) || value instanceof ObservableArray;\n },\n },\n itemTemplateSelector: Function,\n },\n emits: {\n itemTap: (event: ListViewItemTapEvent) => !!event,\n },\n setup(props, ctx) {\n const itemTemplates = Object.keys(ctx.slots).map((slotName) => {\n return {\n key: slotName,\n createView() {\n // no need to return anything here\n },\n };\n });\n\n const getSlotName = (itemCtx: ListItem) =>\n props.itemTemplateSelector?.(itemCtx) ?? 'default';\n\n const listView = ref(null);\n\n const vm = getCurrentInstance();\n\n function refresh() {\n try {\n // ObservableArray notifies the native ListView of changes itself\n if (props.items instanceof ObservableArray) {\n return;\n }\n\n const lv: NSCListView = listView.value?.nativeView;\n lv?.refresh();\n } catch (err) {\n console.error('Error while refreshing ListView', err);\n }\n }\n\n // depth 1 tracks the array's length and slots without walking into the\n // items themselves; cells re-render on their own when item fields change\n watch(() => props.items, refresh, { deep: 1 });\n watch(() => props.itemTemplateSelector, refresh);\n\n function listItemAt(index: number): ListItem {\n return getListItem(\n props.items instanceof ObservableArray\n ? props.items.getItem(index)\n : props.items[index],\n index,\n );\n }\n\n // the native event carries only the index; the template's item context\n // is what handlers want\n function onItemTap(event: ItemEventData) {\n ctx.emit('itemTap', Object.assign(event, listItemAt(event.index)));\n }\n\n let cellId = 0;\n interface ItemCellData {\n itemCtx: ListItem;\n slotName: string;\n }\n const cells = ref<Record<string, ItemCellData>>({});\n\n function onItemLoading(event: ItemEventData) {\n const el = event.view?.[ELEMENT_REF] as NSVElement;\n const id = el?.nativeView[LIST_CELL_ID] ?? `LIST_CELL_${cellId++}`;\n\n const itemCtx = listItemAt(event.index);\n\n // update the cell data with the current row\n cells.value[id] = {\n itemCtx,\n slotName: getSlotName(itemCtx),\n };\n\n // trigger an update!\n vm.update();\n\n // find the vnode rendering this cell\n const vnode = (vm.subTree.children as VNode[]).find((vnode) => {\n return vnode.key === id;\n });\n\n // store the cell id on the Element itself so we can retrieve it when recycling kicks in\n const cellEl = vnode.el.nativeView;\n cellEl[LIST_CELL_ID] = id;\n\n // finally, set the event.view to the rendered cellEl\n event.view = cellEl;\n }\n\n function itemTemplateSelector(item, index) {\n // pass on the template selector call with the ListItem context\n return getSlotName(getListItem(item, index));\n }\n\n // render all realized templates as children\n const cellVNODES = () =>\n Object.entries(cells.value).map(([id, entry]) => {\n const roots = templateRoots(\n ctx.slots[entry.slotName]?.(entry.itemCtx) ?? [],\n );\n\n if (roots.length === 0) {\n logger.warn(`ListView template must contain at least one element.`);\n } else if (roots.length > 1) {\n logger.warn(\n `ListView template must contain a single root element. Found: ${roots.length}. Only the first one will be used.`,\n );\n }\n\n const vnode: VNode =\n roots.at(0) ??\n // default template is just a label\n h('Label', {\n text: entry.itemCtx.item,\n });\n\n // set the key to the list cell id, so we can find this cell later...\n vnode.key = id;\n\n return vnode;\n });\n\n return () => {\n return h(\n 'NSCListView',\n {\n ref: listView,\n items: props.items,\n itemTemplates,\n itemTemplateSelector,\n onItemLoading,\n onItemTap,\n },\n cellVNODES(),\n );\n };\n },\n});\n"]}
@@ -0,0 +1,8 @@
1
+ /** Renders its children on Android only. */
2
+ export declare const Android: import("@vue/runtime-core").DefineComponent<{}, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
3
+ [key: string]: any;
4
+ }>[], {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
5
+ /** Renders its children on iOS only. */
6
+ export declare const iOS: import("@vue/runtime-core").DefineComponent<{}, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
7
+ [key: string]: any;
8
+ }>[], {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,15 @@
1
+ import { defineComponent } from '@vue/runtime-core';
2
+ import { isAndroid, isIOS } from '../nativescript';
3
+ function platformComponent(name, enabled) {
4
+ return defineComponent({
5
+ name,
6
+ setup(_props, { slots }) {
7
+ return () => (enabled() ? slots.default?.() : null);
8
+ },
9
+ });
10
+ }
11
+ /** Renders its children on Android only. */
12
+ export const Android = /*#__PURE__*/ platformComponent('Android', () => isAndroid);
13
+ /** Renders its children on iOS only. */
14
+ export const iOS = /*#__PURE__*/ platformComponent('iOS', () => isIOS);
15
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../src/components/Platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEnD,SAAS,iBAAiB,CAAC,IAAY,EAAE,OAAsB;IAC7D,OAAO,eAAe,CAAC;QACrB,IAAI;QACJ,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE;YACrB,OAAO,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,iBAAiB,CACpD,SAAS,EACT,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;AAEF,wCAAwC;AACxC,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC","sourcesContent":["import { defineComponent } from '@vue/runtime-core';\nimport { isAndroid, isIOS } from '../nativescript';\n\nfunction platformComponent(name: string, enabled: () => boolean) {\n return defineComponent({\n name,\n setup(_props, { slots }) {\n return () => (enabled() ? slots.default?.() : null);\n },\n });\n}\n\n/** Renders its children on Android only. */\nexport const Android = /*#__PURE__*/ platformComponent(\n 'Android',\n () => isAndroid,\n);\n\n/** Renders its children on iOS only. */\nexport const iOS = /*#__PURE__*/ platformComponent('iOS', () => isIOS);\n"]}
@@ -1,5 +1,6 @@
1
1
  import { ActionBar } from './ActionBar';
2
- import { ListView, ListItem } from './ListView';
2
+ import { ListView, ListItem, ListViewItemTapEvent } from './ListView';
3
+ import { Android, iOS } from './Platform';
3
4
  export declare const BUILT_IN_COMPONENTS: {
4
5
  ActionBar: import("@vue/runtime-core").DefineComponent<{}, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
5
6
  [key: string]: any;
@@ -11,12 +12,22 @@ export declare const BUILT_IN_COMPONENTS: {
11
12
  itemTemplateSelector: FunctionConstructor;
12
13
  }>, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
13
14
  [key: string]: any;
14
- }>, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
15
+ }>, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
16
+ itemTap: (event: ListViewItemTapEvent) => boolean;
17
+ }, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
15
18
  items: {
16
19
  validator(value: unknown): value is any[] | import("@nativescript/core").ObservableArray<any>;
17
20
  };
18
21
  itemTemplateSelector: FunctionConstructor;
19
- }>> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
22
+ }>> & Readonly<{
23
+ onItemTap?: (event: ListViewItemTapEvent<any>) => any;
24
+ }>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
25
+ Android: import("@vue/runtime-core").DefineComponent<{}, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
26
+ [key: string]: any;
27
+ }>[], {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
28
+ iOS: import("@vue/runtime-core").DefineComponent<{}, () => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
29
+ [key: string]: any;
30
+ }>[], {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
20
31
  };
21
- export { ActionBar, ListView };
22
- export type { ListItem };
32
+ export { ActionBar, ListView, Android, iOS };
33
+ export type { ListItem, ListViewItemTapEvent };
@@ -1,8 +1,11 @@
1
1
  import { ActionBar } from './ActionBar';
2
2
  import { ListView } from './ListView';
3
+ import { Android, iOS } from './Platform';
3
4
  export const BUILT_IN_COMPONENTS = {
4
5
  ActionBar,
5
6
  ListView,
7
+ Android,
8
+ iOS,
6
9
  };
7
- export { ActionBar, ListView };
10
+ export { ActionBar, ListView, Android, iOS };
8
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAEhD,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS;IACT,QAAQ;CACT,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAkC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,SAAS;IACT,QAAQ;IACR,OAAO;IACP,GAAG;CACJ,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC","sourcesContent":["import { ActionBar } from './ActionBar';\nimport { ListView, ListItem, ListViewItemTapEvent } from './ListView';\nimport { Android, iOS } from './Platform';\n\nexport const BUILT_IN_COMPONENTS = {\n ActionBar,\n ListView,\n Android,\n iOS,\n};\n\nexport { ActionBar, ListView, Android, iOS };\n\nexport type { ListItem, ListViewItemTapEvent };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"vShow.js","sourceRoot":"","sources":["../../src/directives/vShow.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,KAAK,GAAkC;IAClD,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE;QACvC,EAAE,CAAC,IAAI;YACL,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,MAAM;gBACtC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAE,EAAE,CAAC,YAAY,CAAC,YAAY,CAAY,CAAC;QAChD,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YACxB,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE;QACnC,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YACxB,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE;QAC7C,IAAI,CAAC,KAAK,KAAK,CAAC,QAAQ;YAAE,OAAO;QACjC,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,KAAK,EAAE,CAAC;gBACV,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;gBAC3B,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBACrB,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,G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E,EAAE,EAAE,UAAU,EAAE;QAC7C,IAAI,CAAC,KAAK,KAAK,CAAC,QAAQ;YAAE,OAAO;QACjC,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,KAAK,EAAE,CAAC;gBACV,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;gBAC3B,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBACrB,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE;oBACxB,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBACxB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,aAAa,CAAC,EAAE;QACd,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;CACF,CAAC;AAEF,SAAS,UAAU,CAAC,EAAgB,EAAE,KAAc;IAClD,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { ObjectDirective } from '@vue/runtime-core';\nimport { NSVElement } from '../dom';\n\ninterface VShowElement extends NSVElement {\n // _vod = vue original display\n _vod: string;\n}\n\nexport const vShow: ObjectDirective<VShowElement> = {\n beforeMount(el, { value }, { transition }) {\n el._vod =\n el.getAttribute('visibility') === 'none'\n ? ''\n : (el.getAttribute('visibility') as string);\n if (transition && value) {\n transition.beforeEnter(el);\n } else {\n setDisplay(el, value);\n }\n },\n mounted(el, { value }, { transition }) {\n if (transition && value) {\n transition.enter(el);\n }\n },\n updated(el, { value, oldValue }, { transition }) {\n if (!value === !oldValue) return;\n if (transition) {\n if (value) {\n transition.beforeEnter(el);\n setDisplay(el, true);\n transition.enter(el);\n } else {\n transition.leave(el, () => {\n setDisplay(el, false);\n });\n }\n } else {\n setDisplay(el, value);\n }\n },\n beforeUnmount(el) {\n setDisplay(el, true);\n },\n};\n\nfunction setDisplay(el: VShowElement, value: unknown): void {\n el.setAttribute('visibility', value ? el._vod : 'collapsed');\n}\n"]}
@@ -3,7 +3,8 @@ export declare const enum NSVNodeTypes {
3
3
  TEXT = "text",
4
4
  ELEMENT = "element",
5
5
  COMMENT = "comment",
6
- ROOT = "root"
6
+ ROOT = "root",
7
+ DETACHED = "detached"
7
8
  }
8
9
  export declare const enum NSVViewFlags {
9
10
  NONE = 0,
@@ -64,3 +65,15 @@ export declare class NSVRoot extends NSVNode {
64
65
  removeChild(el: NSVNode): void;
65
66
  insertBefore(el: NSVNode, anchor?: NSVNode | null): void;
66
67
  }
68
+ /**
69
+ * Parks nodes outside the visual tree, as KeepAlive does with deactivated
70
+ * subtrees. Children keep their place in the node tree so anchors and
71
+ * siblings still resolve, but nothing is added to a native parent: a view
72
+ * moved in here is simply detached until it is moved back out.
73
+ */
74
+ export declare class NSVDetachedContainer extends NSVNode {
75
+ constructor();
76
+ appendChild(el: NSVNode): void;
77
+ insertBefore(el: NSVNode, anchor?: NSVNode | null): void;
78
+ removeChild(el: NSVNode): void;
79
+ }