File tree 7 files changed +69
-24
lines changed
7 files changed +69
-24
lines changed Original file line number Diff line number Diff line change
1
+ <script setup lang="ts">
2
+ import naiveUISchemaParser , { NaiveUISchema } from " ../module/schema/schema.parser.ts" ;
3
+ import {defineAsyncComponent , h } from ' vue'
4
+
5
+ const props = defineProps <{
6
+ schema: NaiveUISchema
7
+ }>()
8
+
9
+
10
+ const node = naiveUISchemaParser (props .schema )
11
+
12
+ </script >
13
+
14
+ <template >
15
+ <div class =" schema" >
16
+ <h1 >Test</h1 >
17
+ <template v-for =" i of node " >
18
+ <component :is =" i" />
19
+ </template >
20
+ </div >
21
+ </template >
22
+
23
+ <style scoped>
24
+
25
+ </style >
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import FnSchema from " ./fn-schema.vue" ;
3
+ import { NaiveUISchema } from " ../module/schema/schema.parser.ts" ;
4
+
5
+ const json = [
6
+ {
7
+ $type: ' input' ,
8
+ value: ' test'
9
+ }
10
+ ] as NaiveUISchema
2
11
3
12
</script >
4
13
5
14
<template >
6
15
<n-config-provider >
7
-
16
+ < fn-schema :schema = " json " />
8
17
</n-config-provider >
9
18
</template >
10
19
Original file line number Diff line number Diff line change
1
+ export const toPascalCase = ( str : string ) => {
2
+ return str . replace ( / \w + / g, function ( w ) {
3
+ return w [ 0 ] . toUpperCase ( ) + w . slice ( 1 ) . toLowerCase ( )
4
+ } )
5
+ }
Original file line number Diff line number Diff line change 1
1
import { createApp } from 'vue'
2
- import { plugin , defaultConfig } from '@formkit/vue'
3
2
import './style.css'
4
3
import App from './App.vue'
5
4
import naive from 'naive-ui'
6
5
7
6
createApp ( App )
8
7
. use ( naive )
9
- . use ( plugin , defaultConfig )
10
8
. mount ( '#app' )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- import { NaiveUISchema , NaiveUITypes } from "./schema" ;
2
- import { defineAsyncComponent } from 'vue'
1
+ // @ts -ignore
2
+ import NaiveUISchema = FNScheme . NaiveUISchema ;
3
+ import { toPascalCase } from "../../helper/helper.path.ts" ;
4
+ import { defineAsyncComponent , h } from "vue" ;
5
+ export enum NaiveUITypes {
6
+ Form = 'form' ,
7
+ Input = 'input' ,
8
+ }
9
+
10
+ export type NaiveUISchema = NaiveUISchemaEl [ ]
11
+ export declare interface NaiveUISchemaEl {
12
+ $type : NaiveUITypes
13
+ $children : any [ ]
14
+ }
3
15
16
+ export const fnComponentPath = ( name : string ) => `/node_modules/naive-ui/es/${ name } /src/${ toPascalCase ( name ) } .js`
4
17
export default function naiveUISchemaParser ( json : NaiveUISchema ) {
5
- for ( const _el of json ) {
6
- switch ( _el . $type ) {
7
- case NaiveUITypes . Form :
18
+ return json . map ( ( _el : any ) => {
19
+ const index = Object . values ( NaiveUITypes ) . indexOf ( _el . $type as unknown as NaiveUITypes )
8
20
9
- default :
10
- throw new Error ( 'Element property $type not defined' )
21
+ if ( index === - 1 ) {
22
+ throw new Error (
23
+ `Type ${ _el . $type } is not support. Supported types: \n ${ JSON . stringify ( NaiveUITypes , null , 4 ) } `
24
+ )
11
25
}
12
- }
13
- }
14
- //
15
- export const fnComponent = ( name : string ) => defineAsyncComponent ( ( ) => import ( `naive-ui/lib/${ name } ` ) )
26
+
27
+ const { $type, ...schemeEl } = _el
28
+ const { $children, ...props } = schemeEl
29
+
30
+ return h ( defineAsyncComponent ( ( ) => import ( fnComponentPath ( _el . $type ) ) ) , props )
31
+ } )
32
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
+ "typeRoots" : [" ./src/types" ],
3
4
"target" : " ES2020" ,
4
5
"useDefineForClassFields" : true ,
5
6
"module" : " ESNext" ,
You can’t perform that action at this time.
0 commit comments