@veltra/utils 1.1.2 → 1.1.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/dist/index.d.ts CHANGED
@@ -16,5 +16,5 @@ import { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, sha
16
16
  import { middleProxy } from "./reactive/proxy.js";
17
17
  import { DeconstructValue, DefineEvent, Index, Null, RenderReturn, Undef } from "./types/helper.js";
18
18
  import { BreakpointName, ColorType, ComponentProps, ComponentSize, FormComponentProps, PropsWithServerQuery } from "./types/component-common.js";
19
- import { FormContextInjectProps } from "./types/form-context.js";
20
- export { AnimeConfig, BEM, BEMFactory, BreakpointName, CLS_PREFIX, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, ExpandTransition, ExpandTransitionOptions, FORM_EMPTY_CONTENT, FormComponentProps, FormContextInjectProps, Index, NAME_SPACE, Null, PresetRule, PropsWithServerQuery, RenderReturn, Tween, TweenConfig, Undef, ValidateRule, Validator, ValidatorConfig, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
19
+ import { FormContextModel, FormContextProps, injectFormContext, provideFormContext } from "./types/form-context.js";
20
+ export { AnimeConfig, BEM, BEMFactory, BreakpointName, CLS_PREFIX, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, ExpandTransition, ExpandTransitionOptions, FORM_EMPTY_CONTENT, FormComponentProps, FormContextModel, FormContextProps, Index, NAME_SPACE, Null, PresetRule, PropsWithServerQuery, RenderReturn, Tween, TweenConfig, Undef, ValidateRule, Validator, ValidatorConfig, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, injectFormContext, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, provideFormContext, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
package/dist/index.js CHANGED
@@ -13,4 +13,5 @@ import { Tween } from "./helper/tween.js";
13
13
  import { nextFrame } from "./helper/frame.js";
14
14
  import { extractNormalVNodes, isComment, isFragment, isTemplate, isTextNode, shallowComputed } from "./helper/vue.js";
15
15
  import { middleProxy } from "./reactive/proxy.js";
16
- export { CLS_PREFIX, ExpandTransition, FORM_EMPTY_CONTENT, NAME_SPACE, Tween, Validator, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
16
+ import { injectFormContext, provideFormContext } from "./types/form-context.js";
17
+ export { CLS_PREFIX, ExpandTransition, FORM_EMPTY_CONTENT, NAME_SPACE, Tween, Validator, addClass, bem, createIncrease, createToggle, extractNormalVNodes, getHighlightChunks, getNearestScrollParent, getScrollParents, injectFormContext, isComment, isFragment, isTemplate, isTextNode, makeBEM, middleProxy, nextFrame, provideFormContext, removeClass, removeStyles, scrollIntoContainerView, setStyles, shallowComputed, withUnit, zIndex };
@@ -1,6 +1,34 @@
1
+ import { ComponentSize } from "./component-common.js";
2
+
1
3
  //#region src/types/form-context.d.ts
2
- /** 表单 provide/inject 上下文(完整 props 见 @veltra/desktop/types/form) */
3
- type FormContextInjectProps = Record<string, unknown>;
4
+ interface FormContextModel {
5
+ errors: Map<any, string[] | undefined>;
6
+ fields: Record<string, {
7
+ required?: unknown;
8
+ }>;
9
+ }
10
+ interface FormContextProps {
11
+ /** 表单列宽 */
12
+ labelWidth?: string | number;
13
+ /** 表单尺寸 */
14
+ size?: ComponentSize;
15
+ /** 是否禁用 */
16
+ disabled?: boolean;
17
+ /** 是否只读 */
18
+ readonly?: boolean;
19
+ /** 是否隐藏提示 */
20
+ noTips?: boolean;
21
+ /** 表单数据模型 */
22
+ model?: FormContextModel;
23
+ }
24
+ type FormPropsLike = Partial<FormContextProps> & Record<string, any>;
25
+ type DIContext = {
26
+ /** 表单属性 */formProps: FormPropsLike;
27
+ };
28
+ declare function provideFormContext<T extends FormPropsLike>(props: T): void;
29
+ declare function injectFormContext(): {
30
+ /** 是否在表单中 */inForm: boolean;
31
+ } & Partial<DIContext>;
4
32
  //#endregion
5
- export { FormContextInjectProps };
33
+ export { FormContextModel, FormContextProps, injectFormContext, provideFormContext };
6
34
  //# sourceMappingURL=form-context.d.ts.map
@@ -0,0 +1,17 @@
1
+ import { inject, provide } from "vue";
2
+ //#region src/types/form-context.ts
3
+ const FormComponentDIKey = Symbol("FormComponentDIKey");
4
+ function provideFormContext(props) {
5
+ if (props) provide(FormComponentDIKey, { formProps: props });
6
+ }
7
+ function injectFormContext() {
8
+ const context = inject(FormComponentDIKey, void 0) || {};
9
+ return {
10
+ inForm: !!context,
11
+ ...context
12
+ };
13
+ }
14
+ //#endregion
15
+ export { injectFormContext, provideFormContext };
16
+
17
+ //# sourceMappingURL=form-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-context.js","names":[],"sources":["../../src/types/form-context.ts"],"sourcesContent":["import { type InjectionKey, inject, provide } from 'vue'\n\nimport type { ComponentSize } from './component-common'\n\nexport interface FormContextModel {\n errors: Map<any, string[] | undefined>\n fields: Record<string, { required?: unknown }>\n}\n\nexport interface FormContextProps {\n /** 表单列宽 */\n labelWidth?: string | number\n /** 表单尺寸 */\n size?: ComponentSize\n /** 是否禁用 */\n disabled?: boolean\n /** 是否只读 */\n readonly?: boolean\n /** 是否隐藏提示 */\n noTips?: boolean\n /** 表单数据模型 */\n model?: FormContextModel\n}\n\ntype FormPropsLike = Partial<FormContextProps> & Record<string, any>\n\ntype DIContext = {\n /** 表单属性 */\n formProps: FormPropsLike\n}\n\nconst FormComponentDIKey: InjectionKey<DIContext> = Symbol('FormComponentDIKey')\n\nexport function provideFormContext<T extends FormPropsLike>(props: T): void {\n if (props) {\n provide(FormComponentDIKey, { formProps: props })\n }\n}\n\nexport function injectFormContext(): {\n /** 是否在表单中 */\n inForm: boolean\n} & Partial<DIContext> {\n const context = inject(FormComponentDIKey, undefined) || {}\n return { inForm: !!context, ...context }\n}\n"],"mappings":";;AA+BA,MAAM,qBAA8C,OAAO,qBAAqB;AAEhF,SAAgB,mBAA4C,OAAgB;AAC1E,KAAI,MACF,SAAQ,oBAAoB,EAAE,WAAW,OAAO,CAAC;;AAIrD,SAAgB,oBAGO;CACrB,MAAM,UAAU,OAAO,oBAAoB,KAAA,EAAU,IAAI,EAAE;AAC3D,QAAO;EAAE,QAAQ,CAAC,CAAC;EAAS,GAAG;EAAS"}
@@ -1,5 +1,5 @@
1
1
  import { Data, PresetRule, ValidateRule, ValidatorConfig } from "./utils/form/validate.js";
2
2
  import { DeconstructValue, DefineEvent, Index, Null, RenderReturn, Undef } from "./helper.js";
3
3
  import { BreakpointName, ColorType, ComponentProps, ComponentSize, FormComponentProps, PropsWithServerQuery } from "./component-common.js";
4
- import { FormContextInjectProps } from "./form-context.js";
5
- export { BreakpointName, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, FormComponentProps, FormContextInjectProps, Index, Null, PresetRule, PropsWithServerQuery, RenderReturn, Undef, ValidateRule, ValidatorConfig };
4
+ import { FormContextModel, FormContextProps, injectFormContext, provideFormContext } from "./form-context.js";
5
+ export { BreakpointName, ColorType, ComponentProps, ComponentSize, Data, DeconstructValue, DefineEvent, FormComponentProps, FormContextModel, FormContextProps, Index, Null, PresetRule, PropsWithServerQuery, RenderReturn, Undef, ValidateRule, ValidatorConfig, injectFormContext, provideFormContext };
@@ -0,0 +1,2 @@
1
+ import { injectFormContext, provideFormContext } from "./form-context.js";
2
+ export { injectFormContext, provideFormContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -1,2 +1,46 @@
1
- /** 表单 provide/inject 上下文(完整 props @veltra/desktop/types/form) */
2
- export type FormContextInjectProps = Record<string, unknown>
1
+ import { type InjectionKey, inject, provide } from 'vue'
2
+
3
+ import type { ComponentSize } from './component-common'
4
+
5
+ export interface FormContextModel {
6
+ errors: Map<any, string[] | undefined>
7
+ fields: Record<string, { required?: unknown }>
8
+ }
9
+
10
+ export interface FormContextProps {
11
+ /** 表单列宽 */
12
+ labelWidth?: string | number
13
+ /** 表单尺寸 */
14
+ size?: ComponentSize
15
+ /** 是否禁用 */
16
+ disabled?: boolean
17
+ /** 是否只读 */
18
+ readonly?: boolean
19
+ /** 是否隐藏提示 */
20
+ noTips?: boolean
21
+ /** 表单数据模型 */
22
+ model?: FormContextModel
23
+ }
24
+
25
+ type FormPropsLike = Partial<FormContextProps> & Record<string, any>
26
+
27
+ type DIContext = {
28
+ /** 表单属性 */
29
+ formProps: FormPropsLike
30
+ }
31
+
32
+ const FormComponentDIKey: InjectionKey<DIContext> = Symbol('FormComponentDIKey')
33
+
34
+ export function provideFormContext<T extends FormPropsLike>(props: T): void {
35
+ if (props) {
36
+ provide(FormComponentDIKey, { formProps: props })
37
+ }
38
+ }
39
+
40
+ export function injectFormContext(): {
41
+ /** 是否在表单中 */
42
+ inForm: boolean
43
+ } & Partial<DIContext> {
44
+ const context = inject(FormComponentDIKey, undefined) || {}
45
+ return { inForm: !!context, ...context }
46
+ }