@piying/view-vue 2.9.10 → 2.10.1
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/index.js +95 -50
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/src/component/field-control-bind.vue.d.ts +35 -0
- package/{component → src/component}/field-template.vue.d.ts +2 -0
- package/{component → src/component}/piying-view.vue.d.ts +3 -6
- package/{index.d.ts → src/index.d.ts} +2 -0
- package/src/token.d.ts +5 -0
- package/src/util/convert-wrapper.d.ts +4 -0
- package/token.d.ts +0 -14
- /package/{action → src/action}/index.d.ts +0 -0
- /package/{builder.d.ts → src/builder.d.ts} +0 -0
- /package/{component → src/component}/group.vue.d.ts +0 -0
- /package/{component → src/component}/wrapper.vue.d.ts +0 -0
- /package/{const.d.ts → src/const.d.ts} +0 -0
- /package/{type → src/type}/group.d.ts +0 -0
- /package/{type → src/type}/index.d.ts +0 -0
- /package/{util → src/util}/index.d.ts +0 -0
- /package/{util → src/util}/signal-convert.d.ts +0 -0
- /package/{util → src/util}/typed-component.d.ts +0 -0
- /package/{util → src/util}/use-control-value-accessor.d.ts +0 -0
- /package/{vue-schema.d.ts → src/vue-schema.d.ts} +0 -0
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inject, shallowRef, watchEffect, defineComponent, computed, createBlock, renderSlot, openBlock, resolveDynamicComponent, mergeProps, unref, toHandlers, withCtx, createVNode, normalizeProps, guardReactiveProps, defineAsyncComponent, provide, watch, onUnmounted, createElementBlock, createCommentVNode, Fragment, ref, renderList } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { isLazyMark, getLazyImport, isFieldControl, createViewControlLink, FormBuilder, CoreSchemaHandle, createConvertToField, initListen, setComponent, actions, NFCSchema } from "@piying/view-core";
|
|
3
3
|
import { effect, createRootInjector, ChangeDetectionSchedulerImpl, ChangeDetectionScheduler, createInjector, untracked } from "static-injector";
|
|
4
4
|
var store;
|
|
5
5
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -127,15 +127,8 @@ function pipe(...pipe2) {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
class VueSchemaHandle extends CoreSchemaHandle {
|
|
131
|
-
}
|
|
132
|
-
class VueFormBuilder extends FormBuilder {
|
|
133
|
-
}
|
|
134
130
|
const InjectorToken = /* @__PURE__ */ Symbol();
|
|
135
131
|
const PI_VIEW_FIELD_TOKEN = /* @__PURE__ */ Symbol();
|
|
136
|
-
const PI_INPUT_OPTIONS_TOKEN = /* @__PURE__ */ Symbol();
|
|
137
|
-
const PI_INPUT_SCHEMA_TOKEN = /* @__PURE__ */ Symbol();
|
|
138
|
-
const PI_INPUT_MODEL_TOKEN = /* @__PURE__ */ Symbol();
|
|
139
132
|
function signalToRef(value) {
|
|
140
133
|
const injector = inject(InjectorToken);
|
|
141
134
|
const dataRef = shallowRef(void 0);
|
|
@@ -156,7 +149,7 @@ function signalToRef(value) {
|
|
|
156
149
|
});
|
|
157
150
|
return dataRef;
|
|
158
151
|
}
|
|
159
|
-
const _sfc_main$
|
|
152
|
+
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
160
153
|
__name: "wrapper",
|
|
161
154
|
props: {
|
|
162
155
|
wrappers: {}
|
|
@@ -170,7 +163,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
170
163
|
return (_ctx, _cache) => {
|
|
171
164
|
return wrapper.value ? (openBlock(), createBlock(resolveDynamicComponent(wrapper.value.type), mergeProps({ key: 0 }, unref(inputs), toHandlers(outputs.value)), {
|
|
172
165
|
default: withCtx(() => [
|
|
173
|
-
createVNode(_sfc_main$
|
|
166
|
+
createVNode(_sfc_main$4, normalizeProps(guardReactiveProps({ wrappers: restWrappers.value })), {
|
|
174
167
|
default: withCtx(() => [
|
|
175
168
|
renderSlot(_ctx.$slots, "default")
|
|
176
169
|
]),
|
|
@@ -182,28 +175,32 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
182
175
|
};
|
|
183
176
|
}
|
|
184
177
|
});
|
|
185
|
-
const _sfc_main$
|
|
178
|
+
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
186
179
|
__name: "field-template",
|
|
187
180
|
props: {
|
|
188
|
-
field: {}
|
|
181
|
+
field: {},
|
|
182
|
+
path: {}
|
|
189
183
|
},
|
|
190
184
|
setup(__props) {
|
|
191
185
|
const props = __props;
|
|
186
|
+
const field = computed(() => {
|
|
187
|
+
const keyPath = props.path;
|
|
188
|
+
return keyPath ? props.field.get(keyPath) : props.field;
|
|
189
|
+
});
|
|
192
190
|
const injector = inject(InjectorToken);
|
|
193
|
-
const renderConfig = signalToRef(() =>
|
|
194
|
-
const inputs = signalToRef(() =>
|
|
195
|
-
const attributes = signalToRef(() =>
|
|
191
|
+
const renderConfig = signalToRef(() => field.value.renderConfig());
|
|
192
|
+
const inputs = signalToRef(() => field.value.inputs?.());
|
|
193
|
+
const attributes = signalToRef(() => field.value.attributes?.());
|
|
196
194
|
const fieldInput = computed(() => ({ ...attributes.value, ...inputs.value }));
|
|
197
|
-
const outputs = signalToRef(() =>
|
|
198
|
-
const events = signalToRef(() =>
|
|
195
|
+
const outputs = signalToRef(() => field.value.outputs?.());
|
|
196
|
+
const events = signalToRef(() => field.value.events?.());
|
|
199
197
|
const fieldOutput = computed(() => ({ ...outputs.value, ...events.value }));
|
|
200
|
-
const fieldChildren = signalToRef(() =>
|
|
201
|
-
const wrappers = signalToRef(() =>
|
|
202
|
-
const define = signalToRef(() =>
|
|
198
|
+
const fieldChildren = signalToRef(() => field.value.children?.());
|
|
199
|
+
const wrappers = signalToRef(() => field.value.wrappers());
|
|
200
|
+
const define = signalToRef(() => field.value.define?.());
|
|
203
201
|
const componentType = computed(
|
|
204
202
|
() => typeof define.value?.type === "function" || isLazyMark(define.value?.type) ? defineAsyncComponent(getLazyImport(define.value?.type)) : define.value?.type
|
|
205
203
|
);
|
|
206
|
-
const field = computed(() => props.field);
|
|
207
204
|
provide(PI_VIEW_FIELD_TOKEN, field);
|
|
208
205
|
const childRef = shallowRef(null);
|
|
209
206
|
const isControl = isFieldControl(field.value.form.control);
|
|
@@ -224,7 +221,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
224
221
|
});
|
|
225
222
|
return (_ctx, _cache) => {
|
|
226
223
|
return !unref(renderConfig).hidden ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
227
|
-
unref(define)?.type ? (openBlock(), createBlock(_sfc_main$
|
|
224
|
+
unref(define)?.type ? (openBlock(), createBlock(_sfc_main$4, {
|
|
228
225
|
key: 0,
|
|
229
226
|
wrappers: unref(wrappers)
|
|
230
227
|
}, {
|
|
@@ -242,7 +239,26 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
242
239
|
};
|
|
243
240
|
}
|
|
244
241
|
});
|
|
245
|
-
|
|
242
|
+
class VueFormBuilder extends FormBuilder {
|
|
243
|
+
}
|
|
244
|
+
class VueSchemaHandle extends CoreSchemaHandle {
|
|
245
|
+
}
|
|
246
|
+
const DefaultConvertOptions = {
|
|
247
|
+
builder: VueFormBuilder,
|
|
248
|
+
handle: VueSchemaHandle
|
|
249
|
+
};
|
|
250
|
+
const convertToField = createConvertToField(
|
|
251
|
+
DefaultConvertOptions,
|
|
252
|
+
createRootInjector({
|
|
253
|
+
providers: [
|
|
254
|
+
{
|
|
255
|
+
provide: ChangeDetectionScheduler,
|
|
256
|
+
useClass: ChangeDetectionSchedulerImpl
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
246
262
|
__name: "piying-view",
|
|
247
263
|
props: {
|
|
248
264
|
schema: {},
|
|
@@ -265,18 +281,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
265
281
|
})
|
|
266
282
|
);
|
|
267
283
|
provide(InjectorToken, rootInjector);
|
|
268
|
-
provide(
|
|
269
|
-
PI_INPUT_OPTIONS_TOKEN,
|
|
270
|
-
computed(() => inputs.options)
|
|
271
|
-
);
|
|
272
|
-
provide(
|
|
273
|
-
PI_INPUT_SCHEMA_TOKEN,
|
|
274
|
-
computed(() => inputs.schema)
|
|
275
|
-
);
|
|
276
|
-
provide(
|
|
277
|
-
PI_INPUT_MODEL_TOKEN,
|
|
278
|
-
computed(() => inputs.modelValue)
|
|
279
|
-
);
|
|
280
284
|
const initResult = shallowRef();
|
|
281
285
|
watch(
|
|
282
286
|
() => [inputs.schema, inputs.options, rootInjector.value],
|
|
@@ -285,12 +289,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
285
289
|
onCleanup(() => {
|
|
286
290
|
subInjector.destroy();
|
|
287
291
|
});
|
|
288
|
-
const field2 =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
});
|
|
292
|
+
const field2 = convertToField(
|
|
293
|
+
() => inputs.schema,
|
|
294
|
+
subInjector,
|
|
295
|
+
() => inputs.options
|
|
296
|
+
);
|
|
294
297
|
initResult.value = [field2, subInjector];
|
|
295
298
|
},
|
|
296
299
|
{ immediate: true }
|
|
@@ -317,7 +320,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
317
320
|
{ immediate: true }
|
|
318
321
|
);
|
|
319
322
|
return (_ctx, _cache) => {
|
|
320
|
-
return openBlock(), createBlock(_sfc_main$
|
|
323
|
+
return openBlock(), createBlock(_sfc_main$3, {
|
|
321
324
|
field: field.value
|
|
322
325
|
}, null, 8, ["field"]);
|
|
323
326
|
};
|
|
@@ -506,14 +509,14 @@ function typedComponent(input) {
|
|
|
506
509
|
}
|
|
507
510
|
};
|
|
508
511
|
}
|
|
509
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
512
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
510
513
|
__name: "group",
|
|
511
514
|
setup(__props) {
|
|
512
515
|
const field = inject(PI_VIEW_FIELD_TOKEN);
|
|
513
516
|
const children = signalToRef(() => field?.value.children());
|
|
514
517
|
return (_ctx, _cache) => {
|
|
515
518
|
return openBlock(true), createElementBlock(Fragment, null, renderList(unref(children), (field2, index) => {
|
|
516
|
-
return openBlock(), createBlock(_sfc_main$
|
|
519
|
+
return openBlock(), createBlock(_sfc_main$3, {
|
|
517
520
|
key: index,
|
|
518
521
|
field: field2
|
|
519
522
|
}, null, 8, ["field"]);
|
|
@@ -521,15 +524,57 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
521
524
|
};
|
|
522
525
|
}
|
|
523
526
|
});
|
|
527
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
528
|
+
__name: "field-control-bind",
|
|
529
|
+
props: {
|
|
530
|
+
field: {},
|
|
531
|
+
path: {}
|
|
532
|
+
},
|
|
533
|
+
setup(__props) {
|
|
534
|
+
const props = __props;
|
|
535
|
+
const resolvedField = computed(() => {
|
|
536
|
+
const keyPath = props.path;
|
|
537
|
+
return keyPath ? props.field.get(keyPath) : props.field;
|
|
538
|
+
});
|
|
539
|
+
let dispose;
|
|
540
|
+
const { cva, cvaa } = useControlValueAccessor();
|
|
541
|
+
watch(
|
|
542
|
+
[resolvedField],
|
|
543
|
+
([field]) => {
|
|
544
|
+
dispose?.();
|
|
545
|
+
if (field?.form?.control) {
|
|
546
|
+
const control = field.form.control;
|
|
547
|
+
if (!control) {
|
|
548
|
+
throw new Error(`📍 fieldControlBind:[${field.keyPath || ""}]->[${props.path || ""}]❗`);
|
|
549
|
+
}
|
|
550
|
+
if (!isFieldControl(control)) {
|
|
551
|
+
throw new Error(`🏷️ fieldControl❗`);
|
|
552
|
+
}
|
|
553
|
+
dispose = createViewControlLink(() => control, cva, field.injector);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
{ immediate: true }
|
|
557
|
+
);
|
|
558
|
+
onUnmounted(() => {
|
|
559
|
+
dispose?.(true);
|
|
560
|
+
dispose = void 0;
|
|
561
|
+
});
|
|
562
|
+
return (_ctx, _cache) => {
|
|
563
|
+
return renderSlot(_ctx.$slots, "default", {
|
|
564
|
+
cvaa: unref(cvaa),
|
|
565
|
+
field: resolvedField.value
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
});
|
|
524
570
|
export {
|
|
571
|
+
_sfc_main as Field,
|
|
525
572
|
InjectorToken,
|
|
526
|
-
PI_INPUT_MODEL_TOKEN,
|
|
527
|
-
PI_INPUT_OPTIONS_TOKEN,
|
|
528
|
-
PI_INPUT_SCHEMA_TOKEN,
|
|
529
573
|
PI_VIEW_FIELD_TOKEN,
|
|
530
|
-
_sfc_main
|
|
531
|
-
_sfc_main$
|
|
532
|
-
_sfc_main as
|
|
574
|
+
_sfc_main as PiyingFieldControlBind,
|
|
575
|
+
_sfc_main$3 as PiyingFieldTemplate,
|
|
576
|
+
_sfc_main$2 as PiyingView,
|
|
577
|
+
_sfc_main$1 as PiyingViewGroup,
|
|
533
578
|
VueFormBuilder,
|
|
534
579
|
VueSchemaHandle,
|
|
535
580
|
signalToRef,
|