@piying/view-vue 1.1.0

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.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { RawConfigCommon } from '@piying/valibot-visit';
2
+ import type { VueSchemaHandle } from '../vue-schema';
3
+ export declare const rawConfig: RawConfigCommon<VueSchemaHandle>;
@@ -0,0 +1,6 @@
1
+ import { FormBuilder } from '@piying/view-core';
2
+ import type { PiResolvedFormlyFieldConfig } from './type/group';
3
+ import type { VueSchemaHandle } from './vue-schema';
4
+ export declare class VueFormBuilder extends FormBuilder<VueSchemaHandle> {
5
+ afterResolveConfig(rawConfig: VueSchemaHandle, config: PiResolvedFormlyFieldConfig): PiResolvedFormlyFieldConfig;
6
+ }
@@ -0,0 +1,15 @@
1
+ import type { PiResolvedFormlyFieldConfig } from '../type/group';
2
+ type __VLS_Props = {
3
+ fields: PiResolvedFormlyFieldConfig[];
4
+ };
5
+ declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>>, {}, {}>;
6
+ export default _default;
7
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
8
+ type __VLS_TypePropsToOption<T> = {
9
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
10
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
11
+ } : {
12
+ type: import('vue').PropType<T[K]>;
13
+ required: true;
14
+ };
15
+ };
@@ -0,0 +1,10 @@
1
+ export declare const EMPTY_ARRAY: never[];
2
+ export declare const NG_CONFIG_DEFAULT_MERGE_STRAGEGY: {
3
+ directives: string;
4
+ formConfig: string;
5
+ inputs: string;
6
+ outputs: string;
7
+ props: string;
8
+ renderConfig: string;
9
+ wrappers: string;
10
+ };
@@ -0,0 +1,15 @@
1
+ import type { PiResolvedFormlyFieldConfig } from './type/group';
2
+ type __VLS_Props = {
3
+ field: PiResolvedFormlyFieldConfig;
4
+ };
5
+ declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>>, {}, {}>;
6
+ export default _default;
7
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
8
+ type __VLS_TypePropsToOption<T> = {
9
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
10
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
11
+ } : {
12
+ type: import('vue').PropType<T[K]>;
13
+ required: true;
14
+ };
15
+ };
@@ -0,0 +1,21 @@
1
+ import * as v from 'valibot';
2
+ type __VLS_Props = {
3
+ schema: v.BaseSchema<any, any, any> | v.SchemaWithPipe<any>;
4
+ modelValue?: any;
5
+ options: any;
6
+ };
7
+ declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
8
+ "update:modelValue": (...args: any[]) => void;
9
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>> & {
10
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
11
+ }, {}, {}>;
12
+ export default _default;
13
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
14
+ type __VLS_TypePropsToOption<T> = {
15
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
16
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
17
+ } : {
18
+ type: import('vue').PropType<T[K]>;
19
+ required: true;
20
+ };
21
+ };
@@ -0,0 +1,5 @@
1
+ import type { Injector } from 'static-injector';
2
+ import type { ComputedRef, InjectionKey } from 'vue';
3
+ import type { PiResolvedFormlyFieldConfig } from './type/group';
4
+ export declare const InjectorToken: InjectionKey<Injector>;
5
+ export declare const FieldToken: InjectionKey<ComputedRef<PiResolvedFormlyFieldConfig>>;
@@ -0,0 +1,40 @@
1
+ import type { ConfigMergeStrategyObject, VueSchemaHandle } from '../vue-schema';
2
+ import type { ConfigMergeStrategy, CoreResolvedComponentDefine, PiResolvedCommonViewFieldConfig } from '@piying/view-core';
3
+ import type { SetOptional } from '@piying/view-core';
4
+ export interface RawDirectiveOutputs {
5
+ [name: string]: (event: any, field: PiResolvedFormlyFieldConfig) => void;
6
+ }
7
+ export type RawWrapperDefine = {
8
+ inputs?: Record<string, any>;
9
+ type: string;
10
+ };
11
+ export type ResolvedrapperDefine = {
12
+ inputs?: Record<string, any>;
13
+ type: any;
14
+ };
15
+ export interface RawComponentDefine {
16
+ type: string;
17
+ }
18
+ export interface ComponentFieldConfig {
19
+ type?: string;
20
+ contents?: any[];
21
+ }
22
+ export type ResolvedComponentFieldConfig = Omit<ComponentFieldConfig, 'inputs' | 'outputs' | 'directives' | 'wrappers'>;
23
+ export type PiDefaultRawFormlyFieldConfig = Pick<VueSchemaHandle, 'inputs' | 'outputs' | 'wrappers' | 'formConfig' | 'renderConfig' | 'props'>;
24
+ export type PiResolvedFormlyFieldConfig = PiResolvedCommonViewFieldConfig<() => PiResolvedFormlyFieldConfig, CoreResolvedComponentDefine> & ResolvedComponentFieldConfig & {
25
+ /** 除了无component的控件,其他情况下都应该有define,group/array会赋值默认 */
26
+ define?: RawComponentDefine;
27
+ };
28
+ export type PiComponentDefaultConfig = {
29
+ type: any | (() => Promise<any>);
30
+ } & Omit<SetOptional<PiDefaultRawFormlyFieldConfig, 'formConfig'>, 'type'>;
31
+ export interface PiFormlyConfig {
32
+ types?: Record<string, PiComponentDefaultConfig>;
33
+ wrappers?: Record<string, {
34
+ type: any | (() => Promise<any>);
35
+ inputs?: Record<string, any>;
36
+ }>;
37
+ defaultConfig?: PiDefaultRawFormlyFieldConfig;
38
+ /** merge 数组/对象会合并 replace 优先自身/组件/全局 */
39
+ defaultConfigMergeStrategy?: ConfigMergeStrategy | ConfigMergeStrategyObject;
40
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type AbstractControl } from '@piying/view-core';
2
+ export declare function useFieldConnect(controlFn: () => AbstractControl | undefined): readonly [import("vue").ShallowRef<any>, (value: any) => void];
@@ -0,0 +1,3 @@
1
+ import type { Injector } from 'static-injector';
2
+ import { AbstractControl } from '@piying/view-core';
3
+ export declare function initListen(input: any, control: AbstractControl, injector: Injector, fn: (input: any) => void): import("static-injector").EffectRef;
@@ -0,0 +1,5 @@
1
+ import { type Injector, type Signal } from 'static-injector';
2
+ import type { UnWrapSignal } from '@piying/view-core';
3
+ import { type ShallowRef } from 'vue';
4
+ export declare function useSignalConvert<T>(value: Signal<T> | undefined, injector: Injector): T extends undefined ? ShallowRef<undefined> : ShallowRef<UnWrapSignal<T>>;
5
+ export declare function watchChange<T>(value: () => T | undefined, injector: Injector): import("vue").Ref<any> extends T ? T extends T & import("vue").Ref<any> ? import("@vue/shared").IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
@@ -0,0 +1,8 @@
1
+ import { CoreSchemaHandle, type ConfigMergeStrategy } from '@piying/view-core';
2
+ import type { PiResolvedFormlyFieldConfig } from './type/group';
3
+ export declare class VueSchemaHandle extends CoreSchemaHandle<VueSchemaHandle, () => PiResolvedFormlyFieldConfig> {
4
+ type?: any;
5
+ contents?: any[];
6
+ }
7
+ export type PiDefaultRawFormlyFieldConfig = Pick<VueSchemaHandle, 'inputs' | 'outputs' | 'wrappers' | 'formConfig' | 'renderConfig' | 'props'>;
8
+ export type ConfigMergeStrategyObject = Record<keyof PiDefaultRawFormlyFieldConfig, ConfigMergeStrategy>;
@@ -0,0 +1,27 @@
1
+ import type { CoreResolvedWrapperConfig } from '@piying/view-core';
2
+ type __VLS_Props = {
3
+ wrappers: CoreResolvedWrapperConfig[];
4
+ };
5
+ declare var __VLS_9: {}, __VLS_11: {};
6
+ type __VLS_Slots = {} & {
7
+ default?: (props: typeof __VLS_9) => any;
8
+ } & {
9
+ default?: (props: typeof __VLS_11) => any;
10
+ };
11
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_Props>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_Props>>>, {}, {}>;
12
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
13
+ export default _default;
14
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
15
+ type __VLS_TypePropsToOption<T> = {
16
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
17
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
18
+ } : {
19
+ type: import('vue').PropType<T[K]>;
20
+ required: true;
21
+ };
22
+ };
23
+ type __VLS_WithSlots<T, S> = T & {
24
+ new (): {
25
+ $slots: S;
26
+ };
27
+ };
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import PiyingView from './formly/piying-view.vue';
2
+ export { PiyingView };
3
+ export * from '@piying/view-core';
package/index.js ADDED
@@ -0,0 +1,212 @@
1
+ var U = Object.defineProperty;
2
+ var q = (r, e, t) => e in r ? U(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var E = (r, e, t) => q(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { shallowRef as F, watchEffect as R, defineComponent as T, inject as G, computed as m, createBlock as y, renderSlot as N, openBlock as c, resolveDynamicComponent as C, mergeProps as $, unref as a, toHandlers as g, withCtx as D, createVNode as z, normalizeProps as L, guardReactiveProps as W, defineAsyncComponent as J, provide as H, createElementBlock as x, createCommentVNode as P, Fragment as S, createTextVNode as K, watch as M } from "vue";
5
+ import { CoreSchemaHandle as Q, FormBuilder as X, isFieldControl as Y, convert as Z } from "@piying/view-core";
6
+ export * from "@piying/view-core";
7
+ import { effect as B, createRootInjector as ee, ChangeDetectionSchedulerImpl as te, ChangeDetectionScheduler as oe, createInjector as ne, DestroyRef as le, untracked as re } from "static-injector";
8
+ import { deepEqual as se } from "fast-equals";
9
+ class ue extends Q {
10
+ constructor() {
11
+ super(...arguments);
12
+ E(this, "contents");
13
+ }
14
+ }
15
+ class ae extends X {
16
+ afterResolveConfig(e, t) {
17
+ var n;
18
+ const o = e;
19
+ return e.type, {
20
+ ...t,
21
+ contents: (n = o.contents) == null ? void 0 : n.sort((l, u) => l.nodes && u.nodes ? 0 : l.nodes ? -1 : 1)
22
+ // define,
23
+ };
24
+ }
25
+ }
26
+ const A = Symbol(), ie = Symbol();
27
+ function f(r, e) {
28
+ const t = F(void 0);
29
+ return R((o) => {
30
+ t.value = r();
31
+ const n = B(
32
+ () => {
33
+ const l = r();
34
+ Object.is(t.value, l) || (t.value = l);
35
+ },
36
+ { injector: e }
37
+ );
38
+ o(() => {
39
+ n.destroy();
40
+ });
41
+ }), t;
42
+ }
43
+ function ce(r) {
44
+ const e = F(void 0);
45
+ let t = !1, o;
46
+ return R((l) => {
47
+ let u = !0;
48
+ if (o = r(), o && Y(o))
49
+ t = !0, e.value = o.modelValueToViewValue$$();
50
+ else {
51
+ t = !1;
52
+ return;
53
+ }
54
+ const s = B(
55
+ () => {
56
+ const i = o.modelValueToViewValue$$();
57
+ u ? (u = !1, Object.is(e.value, i) || (e.value = i)) : e.value = i;
58
+ },
59
+ { injector: o.injector }
60
+ );
61
+ l(() => {
62
+ s.destroy();
63
+ });
64
+ }), [e, (l) => {
65
+ t && o.setViewValue(l);
66
+ }];
67
+ }
68
+ const O = /* @__PURE__ */ T({
69
+ __name: "wrapper",
70
+ props: {
71
+ wrappers: {}
72
+ },
73
+ setup(r) {
74
+ const e = G(A), t = r, o = m(() => t.wrappers.slice(1)), n = m(() => t.wrappers[0]), l = f(
75
+ () => {
76
+ var s, i;
77
+ return { ...(s = n.value) == null ? void 0 : s.inputs(), ...(i = n.value) == null ? void 0 : i.attributes() };
78
+ },
79
+ e
80
+ ), u = m(() => {
81
+ var s;
82
+ return ((s = n.value) == null ? void 0 : s.outputs) ?? {};
83
+ });
84
+ return (s, i) => n.value ? (c(), y(C(n.value.type), $({ key: 0 }, a(l), g(u.value)), {
85
+ default: D(() => [
86
+ z(O, L(W({ wrappers: o.value })), {
87
+ default: D(() => [
88
+ N(s.$slots, "default")
89
+ ]),
90
+ _: 3
91
+ }, 16)
92
+ ]),
93
+ _: 3
94
+ }, 16)) : N(s.$slots, "default", { key: 1 });
95
+ }
96
+ }), de = /* @__PURE__ */ T({
97
+ __name: "field-template",
98
+ props: {
99
+ field: {}
100
+ },
101
+ setup(r) {
102
+ const e = r, t = G(A), o = f(() => e.field.inputs(), t), n = f(() => e.field.outputs(), t), l = f(() => e.field.renderConfig(), t), [u, s] = ce(() => e.field.form.control), i = f(() => e.field.attributes(), t), I = m(() => ({ ...o.value, fields: e.field.fieldGroup() })), V = m(() => ({ ...o.value, fields: e.field.fieldArray() })), _ = f(() => e.field.wrappers$$(), t), h = f(() => {
103
+ var d, p;
104
+ return (p = (d = e.field).fieldGroup) == null ? void 0 : p.call(d);
105
+ }, t), w = f(() => {
106
+ var d, p;
107
+ return (p = (d = e.field).fieldArray) == null ? void 0 : p.call(d);
108
+ }, t), j = m(() => ({ ...i.value, ...o.value })), v = m(
109
+ () => {
110
+ var d, p, k;
111
+ return typeof ((d = e.field.define) == null ? void 0 : d.type) == "function" ? J((p = e.field.define) == null ? void 0 : p.type) : (k = e.field.define) == null ? void 0 : k.type;
112
+ }
113
+ ), b = m(() => e.field);
114
+ return H(ie, b), (d, p) => {
115
+ var k;
116
+ return a(l).hidden ? P("", !0) : (c(), x(S, { key: 0 }, [
117
+ (k = b.value.define) != null && k.type ? (c(), y(O, {
118
+ key: 0,
119
+ wrappers: a(_)
120
+ }, {
121
+ default: D(() => [
122
+ a(h) ? (c(), y(C(v.value), $({ key: 0 }, I.value, g(a(n))), null, 16)) : a(w) ? (c(), y(C(v.value), $({ key: 1 }, V.value, g(a(n))), null, 16)) : (c(), x(S, { key: 2 }, [
123
+ b.value.form.control ? (c(), x(S, { key: 0 }, [
124
+ K(" 111 "),
125
+ (c(), y(C(v.value), $(j.value, g(a(n)), {
126
+ modelValue: a(u),
127
+ "onUpdate:modelValue": a(s)
128
+ }), null, 16, ["modelValue", "onUpdate:modelValue"]))
129
+ ], 64)) : (c(), y(C(v.value), $({ key: 1 }, j.value, g(a(n))), null, 16))
130
+ ], 64))
131
+ ]),
132
+ _: 1
133
+ }, 8, ["wrappers"])) : P("", !0)
134
+ ], 64));
135
+ };
136
+ }
137
+ });
138
+ function pe(r, e, t, o) {
139
+ let n = !0;
140
+ return B(
141
+ () => {
142
+ const l = e.value$$();
143
+ n ? (se(l, r) || o(l), n = !1) : o(l);
144
+ },
145
+ { injector: t }
146
+ );
147
+ }
148
+ const _e = /* @__PURE__ */ T({
149
+ __name: "piying-view",
150
+ props: {
151
+ schema: {},
152
+ modelValue: {},
153
+ options: {}
154
+ },
155
+ emits: ["update:modelValue"],
156
+ setup(r, { emit: e }) {
157
+ const t = r, o = e, n = ee({
158
+ providers: [
159
+ {
160
+ provide: oe,
161
+ useClass: te
162
+ }
163
+ ]
164
+ });
165
+ H(A, n);
166
+ const l = F(void 0);
167
+ return M(
168
+ () => [t.schema, t.options],
169
+ ([u, s], i, I) => {
170
+ const V = ne({ providers: [], parent: n }), _ = Z(u, {
171
+ handle: ue,
172
+ builder: ae,
173
+ injector: V,
174
+ registerOnDestroy: (w) => {
175
+ V.get(le).onDestroy(() => {
176
+ w();
177
+ });
178
+ },
179
+ ...s
180
+ });
181
+ l.value = _;
182
+ let h;
183
+ if (_.form.control) {
184
+ const w = t.modelValue;
185
+ h = pe(
186
+ typeof w < "u" ? w : void 0,
187
+ _.form.control,
188
+ V,
189
+ (j) => {
190
+ re(() => {
191
+ var v;
192
+ (v = _.form.control) != null && v.valueNoError$$() && o("update:modelValue", j);
193
+ });
194
+ }
195
+ );
196
+ }
197
+ I(() => {
198
+ V.destroy(), h == null || h.destroy();
199
+ });
200
+ },
201
+ { immediate: !0 }
202
+ ), R(() => {
203
+ var u;
204
+ (u = l.value.form.control) == null || u.updateValue(t.modelValue);
205
+ }), (u, s) => (c(), y(de, {
206
+ field: l.value
207
+ }, null, 8, ["field"]));
208
+ }
209
+ });
210
+ export {
211
+ _e as PiyingView
212
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@piying/view-vue",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@piying/view-core": "^0.6.5",
7
+ "fast-equals": "^5.2.2",
8
+ "rfdc": "^1.4.1",
9
+ "static-injector": "^6.1.2"
10
+ },
11
+ "sideEffects": false,
12
+ "peerDependencies": {
13
+ "vue": "^3.4.21"
14
+ },
15
+ "module": "index.js",
16
+ "typings": "index.d.ts",
17
+ "exports": {
18
+ "./package.json": {
19
+ "default": "./package.json"
20
+ },
21
+ ".": {
22
+ "types": "./index.d.ts",
23
+ "default": "./index.js"
24
+ }
25
+ }
26
+ }