Skip to content

Commit

Permalink
fix(vueformdata): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jan 24, 2024
1 parent a0e2d21 commit 451d41f
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 224 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion nodedevpkg/vue-vite-presets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@vitejs/plugin-vue": "^4.5.0",
"hastscript": "^8.0.0",
"unist-util-visit": "^5.0.0",
"vite": "^5.0.11",
"vite": "^5.0.12",
"vite-plugin-pages": "^0.31.0",
"vite-tsconfig-paths": "^4.2.1"
},
Expand Down
5 changes: 3 additions & 2 deletions nodepkg/gents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
},
"dependencies": {
"@innoai-tech/config": "0.5.2",
"@innoai-tech/config": "0.5.3",
"@innoai-tech/lodash": "0.2.1",
"@innoai-tech/typedef": "workspace:^",
"node-fetch": "^3.3.2"
},
"peerDependencies": {},
"devDependencies": {
"@innoai-tech/fetcher": "0.5.3"
"@innoai-tech/fetcher": "0.5.5"
},
"exports": {
".": {
Expand Down Expand Up @@ -45,6 +45,7 @@
"directory": "nodepkg/gents"
},
"scripts": {
"test": "bun test .",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build",
"lint": "bunx --bun @biomejs/biome check --apply ."
Expand Down
3 changes: 2 additions & 1 deletion nodepkg/vue-jsx-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
},
"dependencies": {
"vue": "v3.4.8"
"vue": "v3.4.15"
},
"peerDependencies": {},
"exports": {
Expand Down Expand Up @@ -44,6 +44,7 @@
"directory": "nodepkg/vue-jsx-runtime"
},
"scripts": {
"test": "bun test .",
"lint": "bunx --bun @biomejs/biome check --apply .",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build"
Expand Down
3 changes: 2 additions & 1 deletion nodepkg/vueformdata/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@innoai-tech/vueformdata",
"version": "0.1.8",
"version": "0.2.2",
"monobundle": {
"exports": {
".": "./src/index.ts"
Expand Down Expand Up @@ -38,6 +38,7 @@
"directory": "nodepkg/vueformdata"
},
"scripts": {
"test": "bun test .",
"lint": "bunx --bun @biomejs/biome check --apply .",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build"
Expand Down
12 changes: 6 additions & 6 deletions nodepkg/vueformdata/src/FormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type Infer,
type MetaBuilder,
createMetaBuilder,
type Component,
rx, SymbolRecordKey,
} from "@innoai-tech/vuekit";
import {Observable, Subject, distinctUntilChanged, map} from "rxjs";
Expand Down Expand Up @@ -119,19 +120,18 @@ export class FormData<T extends AnyType = AnyType> extends Subject<Infer<T>> {

export interface InputComponentProps<T> {
name: string;
value?: T;
onValueChange: (v: T) => void;
type: string;
readOnly?: boolean;
focus?: boolean;
onBlur?: () => void;
onFocus?: () => void;
value?: T;
onValueChange?: (v: T) => void;
}

export interface FieldMeta {
label?: string;
readOnlyWhenInitialExist?: boolean;
input?: (props: InputComponentProps<any>) => JSX.Element;
input?: Component<InputComponentProps<any>>;
valueDisplay?: (props: InputComponentProps<any>) => JSX.Element | string;
}

Expand Down Expand Up @@ -231,8 +231,8 @@ export class Field extends ImmerBehaviorSubject<FieldState> {

validate(value: any): string[] | undefined {
const v =
this.typedef.type === "array"
? (value ?? []).filter((v: any) => !isUndefined(v))
this.typedef.type === "array" && !isUndefined(value)
? value.filter((v: any) => !isUndefined(v))
: value;

const [err] = this.typedef.validate(v);
Expand Down
2 changes: 1 addition & 1 deletion nodepkg/vuekit/example/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default component(() => {

可复用组件:

- `props``emits` 合并声明,基于 [zod](https://zod.dev/)
- `props``emits` 合并声明

```tsx preview
import { component, t, type VNode, type VNodeChild } from "@innoai-tech/vuekit";
Expand Down
5 changes: 3 additions & 2 deletions nodepkg/vuekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@innoai-tech/vuekit",
"version": "0.6.7",
"version": "0.6.9",
"monobundle": {
"exports": {
".": "./src/index.ts",
Expand All @@ -14,7 +14,7 @@
"@innoai-tech/vue-jsx-runtime": "workspace:^",
"immer": "^10.0.3",
"rxjs": "^7.8.1",
"vue": "v3.4.8",
"vue": "v3.4.15",
"vue-router": "^4.2.5"
},
"peerDependencies": {},
Expand Down Expand Up @@ -58,6 +58,7 @@
"directory": "nodepkg/vuekit"
},
"scripts": {
"test": "bun test .",
"lint": "bunx --bun @biomejs/biome check --apply .",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build"
Expand Down
130 changes: 68 additions & 62 deletions nodepkg/vuekit/src/component.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,88 @@
import { isFunction, kebabCase, partition } from "@innoai-tech/lodash";
import { Fragment as OriginFragment } from "vue";
import {isFunction, kebabCase, partition} from "@innoai-tech/lodash";
import {Fragment as OriginFragment} from "vue";
import type {
Component,
PublicPropsOf,
SetupFunction,
WithDefaultSlot,
Component,
PublicPropsOf,
SetupFunction,
WithDefaultSlot,
} from "./vue";

import { type AnyType } from "@innoai-tech/typedef";
import {type AnyType} from "@innoai-tech/typedef";

export interface ComponentOptions {
name?: string;
inheritAttrs?: boolean;
name?: string;
inheritAttrs?: boolean;

[K: string]: any
}

export const Fragment: Component<WithDefaultSlot> = OriginFragment as any;

export function component(
setup: SetupFunction<{}>,
options?: ComponentOptions,
setup: SetupFunction<{}>,
options?: ComponentOptions,
): Component<{}>;
export function component<PropTypes extends Record<string, AnyType>>(
propTypes: PropTypes,
setup: SetupFunction<PropTypes>,
options?: ComponentOptions,
propTypes: PropTypes,
setup: SetupFunction<PropTypes>,
options?: ComponentOptions,
): Component<PublicPropsOf<PropTypes>>;
export function component<PropTypes extends Record<string, AnyType>>(
propTypesOrSetup: PropTypes | SetupFunction<PropTypes>,
setupOrOptions?: SetupFunction<PropTypes> | ComponentOptions,
options: ComponentOptions = {},
propTypesOrSetup: PropTypes | SetupFunction<PropTypes>,
setupOrOptions?: SetupFunction<PropTypes> | ComponentOptions,
options: ComponentOptions = {},
): Component<PublicPropsOf<PropTypes>> {
const finalOptions = (options ?? setupOrOptions) as ComponentOptions;
const finalSetup = (setupOrOptions ?? propTypesOrSetup) as SetupFunction<any>;
const finalPropTypes = (
isFunction(propTypesOrSetup) ? {} : propTypesOrSetup
) as Record<string, AnyType>;
const finalOptions = (options ?? setupOrOptions) as ComponentOptions;
const finalSetup = (setupOrOptions ?? propTypesOrSetup) as SetupFunction<any>;
const finalPropTypes = (
isFunction(propTypesOrSetup) ? {} : propTypesOrSetup
) as Record<string, AnyType>;

const [emits, props] = partition(Object.keys(finalPropTypes), (v: string) =>
/^on[A-Z]/.test(v),
);

const [emits, props] = partition(Object.keys(finalPropTypes), (v: string) =>
/^on[A-Z]/.test(v),
);
const emitsAndProps = {
emits: emits.map((v) => kebabCase(v.slice("on".length))),
props: props
.filter((p) => !/^[$]/.test(p))
.reduce((ret, prop) => {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
const d = finalPropTypes[prop]!;

const emitsAndProps = {
emits: emits.map((v) => kebabCase(v.slice("on".length))),
props: props
.filter((p) => !/^[$]/.test(p))
.reduce((ret, prop) => {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
const d = finalPropTypes[prop]!;
return {
// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
...ret,
[prop]: {
default: () => {
try {
return d.create(undefined);
} catch (e) {
}
return;
},
validator: (value: any) => {
return d.validate(value);
},
},
};
}, {}),
};

return {
// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
...ret,
[prop]: {
default: () => {
try {
return d.create(undefined);
} catch (e) {}
return;
},
validator: (value: any) => {
return d.validate(value);
},
},
};
}, {}),
};
const {name, inheritAttrs, ...others} = finalOptions

return {
get name() {
return this.displayName ?? finalOptions.name;
},
set name(n: string) {
finalOptions.name = n;
},
setup: (props: any, ctx: any) => finalSetup(props, ctx),
emits: emitsAndProps.emits,
props: emitsAndProps.props,
inheritAttrs: finalOptions.inheritAttrs,
propTypes: finalPropTypes,
} as any;
return {
...others,
get name() {
return this.displayName ?? name;
},
set name(n: string) {
finalOptions.name = n;
},
setup: (props: any, ctx: any) => finalSetup(props, ctx),
emits: emitsAndProps.emits,
props: emitsAndProps.props,
inheritAttrs: inheritAttrs,
propTypes: finalPropTypes,
} as any;
}
Loading

0 comments on commit 451d41f

Please sign in to comment.