Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: handle views imported in script setup#1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rigor789 merged 2 commits intomainfromfix/script-setup-core-view-import-conflicts
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletionsdemo/app/components/FragmentRootComponent.vue
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
<template>
<Label text="Hello Label!" />
<Button text="Hello Button!" />
<TextField text="Hello TextField!" />
</template>
21 changes: 21 additions & 0 deletionsdemo/app/components/GH1017.vue
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
<!-- https://github.com/nativescript-vue/nativescript-vue/issues/1017 -->
<script lang="ts" setup>
import { Label, GridLayout, ContentView } from '@nativescript/core';

import demo_ListView from './demo_ListView.vue';
import FragmentRootComponent from './FragmentRootComponent.vue';
</script>

<template>
<GridLayout rows="auto, auto, *">
<Label text="Hello World" />

<StackLayout row="1">
<FragmentRootComponent />
</StackLayout>

<ContentView row="2">
<demo_ListView />
</ContentView>
</GridLayout>
</template>
46 changes: 45 additions & 1 deletionsrc/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
import { resolveComponent as resolveComponentCore } from '@vue/runtime-core';
import type { CreateAppFunction } from '@vue/runtime-core';
import {
createBlock as createBlockCore,
createElementBlock as createElementBlockCore,
createElementVNode as createElementVNodeCore,
createVNode as createVNodeCore,
resolveComponent as resolveComponentCore,
} from '@vue/runtime-core';

import { BUILT_IN_COMPONENTS } from './components';

Expand DownExpand Up@@ -106,3 +112,41 @@ export function resolveComponent(name: string, maybeSelReference: boolean) {
const component = resolveComponentCore(name, maybeSelReference);
return component;
}

/**
* Checks if the type has a constructor.name that matches a known view or built-in component
* If so, returns the name of the view or component. This allows {N} element imports to be
* used inside script setup context without requiring aliasing.
*/
function maybeConvertToKnownComponentOrViewName(type: any) {
const name = type?.prototype?.constructor?.name;
if (name) {
if (BUILT_IN_COMPONENTS[name]) {
return BUILT_IN_COMPONENTS[name];
}

if (isKnownView(name)) {
return name;
}
}

return type;
}

/**
* Wraps the original function and replaces the first argument if it matches
* a known view or built-in component.
*/
function wrapCreate<T>(originalFunction: T): T {
return ((type: any, ...args: any) => {
return (originalFunction as any)(
maybeConvertToKnownComponentOrViewName(type),
...args
);
}) as T;
}

export const createBlock = wrapCreate(createBlockCore);
export const createElementBlock = wrapCreate(createElementBlockCore);
export const createElementVNode = wrapCreate(createElementVNodeCore);
export const createVNode: typeof createVNodeCore = wrapCreate(createVNodeCore);

[8]ページ先頭

©2009-2025 Movatter.jp