@atscript/vue-form 0.1.58
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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/as-action-71f9E_bL.cjs +208 -0
- package/dist/as-action-DU17rykn.mjs +203 -0
- package/dist/as-action.cjs +2 -0
- package/dist/as-action.d.cts +2 -0
- package/dist/as-action.d.mts +2 -0
- package/dist/as-action.mjs +2 -0
- package/dist/as-action.vue-BdbAOZCL.d.cts +13 -0
- package/dist/as-action.vue-CmY3eil1.d.mts +13 -0
- package/dist/as-adornment-shell-9UmdNIPR.cjs +97 -0
- package/dist/as-adornment-shell-knFiB7Ct.mjs +92 -0
- package/dist/as-array-Bn27x9cq.cjs +466 -0
- package/dist/as-array-DwarTaKP.mjs +455 -0
- package/dist/as-array-clear-btn-DAGervXL.cjs +48 -0
- package/dist/as-array-clear-btn-DIhzCKC9.mjs +43 -0
- package/dist/as-array.cjs +11 -0
- package/dist/as-array.d.cts +2 -0
- package/dist/as-array.d.mts +2 -0
- package/dist/as-array.mjs +11 -0
- package/dist/as-array.vue-C5r_ycIa.d.mts +9 -0
- package/dist/as-array.vue-CeBZRVm7.d.cts +9 -0
- package/dist/as-checkbox-B_9mwla6.mjs +285 -0
- package/dist/as-checkbox-DXGTVHPE.cjs +296 -0
- package/dist/as-checkbox.cjs +6 -0
- package/dist/as-checkbox.d.cts +2 -0
- package/dist/as-checkbox.d.mts +2 -0
- package/dist/as-checkbox.mjs +6 -0
- package/dist/as-checkbox.vue-BL53Xjmi.d.mts +9 -0
- package/dist/as-checkbox.vue-Da1KVG5J.d.cts +9 -0
- package/dist/as-collapsible-CqxeJut7.cjs +148 -0
- package/dist/as-collapsible-DtNCofNT.mjs +143 -0
- package/dist/as-date-C7tFQDkh.mjs +253 -0
- package/dist/as-date-k3MW3dmA.cjs +258 -0
- package/dist/as-date.cjs +8 -0
- package/dist/as-date.d.cts +2 -0
- package/dist/as-date.d.mts +2 -0
- package/dist/as-date.mjs +8 -0
- package/dist/as-date.vue-C5JaS3Sd.d.mts +9 -0
- package/dist/as-date.vue-e2ewS_V4.d.cts +9 -0
- package/dist/as-datetime-C030mzI5.cjs +258 -0
- package/dist/as-datetime-elcOoDT5.mjs +253 -0
- package/dist/as-datetime.cjs +8 -0
- package/dist/as-datetime.d.cts +2 -0
- package/dist/as-datetime.d.mts +2 -0
- package/dist/as-datetime.mjs +8 -0
- package/dist/as-datetime.vue-ClsSnJSV.d.mts +9 -0
- package/dist/as-datetime.vue-vfHFsby6.d.cts +9 -0
- package/dist/as-decimal-BJIGgPXU.cjs +711 -0
- package/dist/as-decimal-DtXjFPhe.mjs +694 -0
- package/dist/as-decimal.cjs +7 -0
- package/dist/as-decimal.d.cts +2 -0
- package/dist/as-decimal.d.mts +2 -0
- package/dist/as-decimal.mjs +7 -0
- package/dist/as-decimal.vue-B1pEKdjM.d.cts +25 -0
- package/dist/as-decimal.vue-CSCtYRRa.d.mts +25 -0
- package/dist/as-field-CXVjrEPQ.mjs +481 -0
- package/dist/as-field-shell-B2iTn-iM.cjs +346 -0
- package/dist/as-field-shell-Pdy3sAvr.mjs +341 -0
- package/dist/as-field-shell.cjs +5 -0
- package/dist/as-field-shell.d.cts +2 -0
- package/dist/as-field-shell.d.mts +2 -0
- package/dist/as-field-shell.mjs +5 -0
- package/dist/as-field-shell.vue-Ddnp8KxY.d.mts +37 -0
- package/dist/as-field-shell.vue-Dmt05vGD.d.cts +37 -0
- package/dist/as-field-wLYoaZnT.cjs +498 -0
- package/dist/as-field.cjs +4 -0
- package/dist/as-field.d.cts +25 -0
- package/dist/as-field.d.mts +26 -0
- package/dist/as-field.mjs +4 -0
- package/dist/as-form-CWwgyvfw.mjs +425 -0
- package/dist/as-form-DAIkyt7H.cjs +448 -0
- package/dist/as-form.cjs +7 -0
- package/dist/as-form.d.cts +2 -0
- package/dist/as-form.d.mts +2 -0
- package/dist/as-form.mjs +7 -0
- package/dist/as-form.vue-B4Bn0pbC.d.cts +158 -0
- package/dist/as-form.vue-DRrb_yoj.d.mts +158 -0
- package/dist/as-input-CpbV2k3s.cjs +231 -0
- package/dist/as-input-DIa8BzLv.mjs +226 -0
- package/dist/as-input-control-BzELjheN.mjs +266 -0
- package/dist/as-input-control-C5-DelZT.cjs +271 -0
- package/dist/as-input.cjs +8 -0
- package/dist/as-input.d.cts +2 -0
- package/dist/as-input.d.mts +2 -0
- package/dist/as-input.mjs +8 -0
- package/dist/as-input.vue-11ldp9uT.d.cts +17 -0
- package/dist/as-input.vue-fUhcvfv2.d.mts +17 -0
- package/dist/as-iterator-BYMNe6UJ.cjs +61 -0
- package/dist/as-iterator-CT5y1jyn.mjs +56 -0
- package/dist/as-iterator.cjs +5 -0
- package/dist/as-iterator.d.cts +14 -0
- package/dist/as-iterator.d.mts +15 -0
- package/dist/as-iterator.mjs +5 -0
- package/dist/as-number-BA55JIq1.cjs +387 -0
- package/dist/as-number-JPEwPK8Q.mjs +376 -0
- package/dist/as-number.cjs +8 -0
- package/dist/as-number.d.cts +2 -0
- package/dist/as-number.d.mts +2 -0
- package/dist/as-number.mjs +8 -0
- package/dist/as-number.vue-Bk-W7Vwv.d.mts +26 -0
- package/dist/as-number.vue-C2Aih98s.d.cts +26 -0
- package/dist/as-object-CT6lNEqt.mjs +300 -0
- package/dist/as-object-qUL7l8V1.cjs +305 -0
- package/dist/as-object.cjs +11 -0
- package/dist/as-object.d.cts +2 -0
- package/dist/as-object.d.mts +2 -0
- package/dist/as-object.mjs +11 -0
- package/dist/as-object.vue-CKwMyM_F.d.cts +13 -0
- package/dist/as-object.vue-Cg52b61-.d.mts +13 -0
- package/dist/as-paragraph-BGO-j4US.cjs +203 -0
- package/dist/as-paragraph-jIG_dg7_.mjs +198 -0
- package/dist/as-paragraph.cjs +2 -0
- package/dist/as-paragraph.d.cts +2 -0
- package/dist/as-paragraph.d.mts +2 -0
- package/dist/as-paragraph.mjs +2 -0
- package/dist/as-paragraph.vue-BDt0pBG-.d.cts +9 -0
- package/dist/as-paragraph.vue-C3FgTEt5.d.mts +9 -0
- package/dist/as-radio-B1N-gmoI.mjs +242 -0
- package/dist/as-radio-U3OK7bTg.cjs +247 -0
- package/dist/as-radio.cjs +6 -0
- package/dist/as-radio.d.cts +2 -0
- package/dist/as-radio.d.mts +2 -0
- package/dist/as-radio.mjs +6 -0
- package/dist/as-radio.vue-D_fweoN1.d.mts +9 -0
- package/dist/as-radio.vue-ZC4kLBnT.d.cts +9 -0
- package/dist/as-ref-CIifSSCQ.mjs +337 -0
- package/dist/as-ref-SImaIrwK.cjs +342 -0
- package/dist/as-ref.cjs +7 -0
- package/dist/as-ref.d.cts +2 -0
- package/dist/as-ref.d.mts +2 -0
- package/dist/as-ref.mjs +7 -0
- package/dist/as-ref.vue-BNeQeQpO.d.cts +9 -0
- package/dist/as-ref.vue-Cr5jeNDn.d.mts +9 -0
- package/dist/as-select-BB3uxACS.cjs +246 -0
- package/dist/as-select-UBGCVhku.mjs +241 -0
- package/dist/as-select.cjs +6 -0
- package/dist/as-select.d.cts +2 -0
- package/dist/as-select.d.mts +2 -0
- package/dist/as-select.mjs +6 -0
- package/dist/as-select.vue-Dd7huPq2.d.cts +9 -0
- package/dist/as-select.vue-RYpbZbKt.d.mts +9 -0
- package/dist/as-time-C24rvslH.cjs +258 -0
- package/dist/as-time-CQsxUs8P.mjs +253 -0
- package/dist/as-time.cjs +8 -0
- package/dist/as-time.d.cts +2 -0
- package/dist/as-time.d.mts +2 -0
- package/dist/as-time.mjs +8 -0
- package/dist/as-time.vue-huLx2B4l.d.mts +9 -0
- package/dist/as-time.vue-nMEHLXke.d.cts +9 -0
- package/dist/as-tuple-BU--cuuI.cjs +351 -0
- package/dist/as-tuple-DkI9swlW.mjs +340 -0
- package/dist/as-tuple.cjs +11 -0
- package/dist/as-tuple.d.cts +2 -0
- package/dist/as-tuple.d.mts +2 -0
- package/dist/as-tuple.mjs +11 -0
- package/dist/as-tuple.vue-CQhzOJsn.d.mts +9 -0
- package/dist/as-tuple.vue-DyskCkf-.d.cts +9 -0
- package/dist/as-union-BGvdxr3G.mjs +351 -0
- package/dist/as-union-C0btoJn3.cjs +368 -0
- package/dist/as-union.cjs +6 -0
- package/dist/as-union.d.cts +2 -0
- package/dist/as-union.d.mts +2 -0
- package/dist/as-union.mjs +6 -0
- package/dist/as-union.vue-BjlDPZn0.d.mts +9 -0
- package/dist/as-union.vue-CqjU3O10.d.cts +9 -0
- package/dist/as-variant-picker-BVs0AvjK.mjs +96 -0
- package/dist/as-variant-picker-DObQZHmm.cjs +107 -0
- package/dist/index.cjs +173 -0
- package/dist/index.d.cts +966 -0
- package/dist/index.d.mts +966 -0
- package/dist/index.mjs +105 -0
- package/dist/types-C4HRSxgV.d.cts +233 -0
- package/dist/types-Czm-Gtud.d.mts +233 -0
- package/dist/use-as-date-B7CtcRQd.cjs +329 -0
- package/dist/use-as-date-C39i9mzE.mjs +318 -0
- package/dist/use-as-dropdown-BMnEm6jF.mjs +82 -0
- package/dist/use-as-dropdown-C-Qy7Vt0.cjs +105 -0
- package/dist/use-as-locale-BrFdAgnU.mjs +23 -0
- package/dist/use-as-locale-C4z5stwD.cjs +34 -0
- package/dist/use-as-nested-sections-store-jdMRxjBE.cjs +80 -0
- package/dist/use-as-nested-sections-store-lhi0z5z1.mjs +63 -0
- package/dist/use-as-optional-add-flow-CuXEir_i.mjs +43 -0
- package/dist/use-as-optional-add-flow-STOaQWo9.cjs +48 -0
- package/dist/use-as-value-help-CBykDEjZ.mjs +89 -0
- package/dist/use-as-value-help-uANI3zWa.cjs +100 -0
- package/dist/use-form-context-Dwr8Ai1v.cjs +207 -0
- package/dist/use-form-context-bAj7UoSe.mjs +106 -0
- package/package.json +180 -0
- package/styles.d.ts +2 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as TAsComponentProps } from "./types-Czm-Gtud.mjs";
|
|
2
|
+
import * as vue from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/components/defaults/as-field-shell.vue.d.ts
|
|
5
|
+
type __VLS_Props = TAsComponentProps & {
|
|
6
|
+
fieldClass?: string; /** Suppress all default chrome (label/description/clear/placeholder) — for fields with inline headers (e.g. checkbox). */
|
|
7
|
+
chromeless?: boolean; /** Skip the empty-state placeholder; render the input slot directly (e.g. radio group, where unchecked = empty). */
|
|
8
|
+
hideEmptyPlaceholder?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare var __VLS_1: {
|
|
11
|
+
inputId: string;
|
|
12
|
+
descId: string;
|
|
13
|
+
optionalEnabled: boolean;
|
|
14
|
+
}, __VLS_20: {
|
|
15
|
+
inputId: string;
|
|
16
|
+
errorId: string;
|
|
17
|
+
descId: string;
|
|
18
|
+
}, __VLS_22: {
|
|
19
|
+
descId: string;
|
|
20
|
+
};
|
|
21
|
+
type __VLS_Slots = {} & {
|
|
22
|
+
header?: (props: typeof __VLS_1) => any;
|
|
23
|
+
} & {
|
|
24
|
+
default?: (props: typeof __VLS_20) => any;
|
|
25
|
+
} & {
|
|
26
|
+
'after-input'?: (props: typeof __VLS_22) => any;
|
|
27
|
+
};
|
|
28
|
+
declare const __VLS_base: vue.DefineComponent<__VLS_Props, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
|
|
29
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
30
|
+
declare const _default: typeof __VLS_export;
|
|
31
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
32
|
+
new (): {
|
|
33
|
+
$slots: S;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { _default as t };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { i as TAsComponentProps } from "./types-C4HRSxgV.cjs";
|
|
2
|
+
import * as vue from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/components/defaults/as-field-shell.vue.d.ts
|
|
5
|
+
type __VLS_Props = TAsComponentProps & {
|
|
6
|
+
fieldClass?: string; /** Suppress all default chrome (label/description/clear/placeholder) — for fields with inline headers (e.g. checkbox). */
|
|
7
|
+
chromeless?: boolean; /** Skip the empty-state placeholder; render the input slot directly (e.g. radio group, where unchecked = empty). */
|
|
8
|
+
hideEmptyPlaceholder?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare var __VLS_1: {
|
|
11
|
+
inputId: string;
|
|
12
|
+
descId: string;
|
|
13
|
+
optionalEnabled: boolean;
|
|
14
|
+
}, __VLS_20: {
|
|
15
|
+
inputId: string;
|
|
16
|
+
errorId: string;
|
|
17
|
+
descId: string;
|
|
18
|
+
}, __VLS_22: {
|
|
19
|
+
descId: string;
|
|
20
|
+
};
|
|
21
|
+
type __VLS_Slots = {} & {
|
|
22
|
+
header?: (props: typeof __VLS_1) => any;
|
|
23
|
+
} & {
|
|
24
|
+
default?: (props: typeof __VLS_20) => any;
|
|
25
|
+
} & {
|
|
26
|
+
'after-input'?: (props: typeof __VLS_22) => any;
|
|
27
|
+
};
|
|
28
|
+
declare const __VLS_base: vue.DefineComponent<__VLS_Props, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
|
|
29
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
30
|
+
declare const _default: typeof __VLS_export;
|
|
31
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
32
|
+
new (): {
|
|
33
|
+
$slots: S;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { _default as t };
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
const require_use_form_context = require("./use-form-context-Dwr8Ai1v.cjs");
|
|
2
|
+
const require_use_as_locale = require("./use-as-locale-C4z5stwD.cjs");
|
|
3
|
+
let vue = require("vue");
|
|
4
|
+
let _atscript_ui = require("@atscript/ui");
|
|
5
|
+
let _atscript_ui_fns = require("@atscript/ui-fns");
|
|
6
|
+
//#region src/composables/use-as-field.ts
|
|
7
|
+
function useAsField(opts) {
|
|
8
|
+
const formState = (0, vue.inject)(require_use_form_context.FORM_STATE_KEY);
|
|
9
|
+
const formData = (0, vue.inject)(require_use_form_context.FORM_DATA_KEY);
|
|
10
|
+
const formContext = (0, vue.inject)(require_use_form_context.FORM_CONTEXT_KEY);
|
|
11
|
+
const id = Symbol("form-field");
|
|
12
|
+
const submitError = (0, vue.ref)();
|
|
13
|
+
const externalError = (0, vue.ref)();
|
|
14
|
+
const touched = (0, vue.ref)(false);
|
|
15
|
+
const blur = (0, vue.ref)(false);
|
|
16
|
+
const model = (0, vue.computed)({
|
|
17
|
+
get: opts.getValue,
|
|
18
|
+
set: opts.setValue
|
|
19
|
+
});
|
|
20
|
+
(0, vue.watch)(model, () => {
|
|
21
|
+
submitError.value = void 0;
|
|
22
|
+
externalError.value = void 0;
|
|
23
|
+
touched.value = true;
|
|
24
|
+
formState?.freshFields.delete(id);
|
|
25
|
+
}, {});
|
|
26
|
+
const isValidationActive = (0, vue.computed)(() => {
|
|
27
|
+
if (!formState?.firstValidation) return false;
|
|
28
|
+
if (formState.freshFields.has(id)) return false;
|
|
29
|
+
switch (formState.firstValidation) {
|
|
30
|
+
case "on-change": return formState.firstSubmitHappened || touched.value;
|
|
31
|
+
case "touched-on-blur": return formState.firstSubmitHappened || blur.value && touched.value;
|
|
32
|
+
case "on-blur": return formState.firstSubmitHappened || blur.value;
|
|
33
|
+
case "on-submit": return formState.firstSubmitHappened;
|
|
34
|
+
default: return false;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
function validate() {
|
|
38
|
+
if (opts.rules?.length) for (const rule of opts.rules) {
|
|
39
|
+
const result = rule(model.value, formData?.value, formContext?.value);
|
|
40
|
+
if (result !== true) return result || "Wrong value";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const error = (0, vue.computed)(() => {
|
|
44
|
+
if (externalError.value) return externalError.value;
|
|
45
|
+
if (submitError.value) return submitError.value;
|
|
46
|
+
if (isValidationActive.value) return validate();
|
|
47
|
+
});
|
|
48
|
+
function onBlur() {
|
|
49
|
+
blur.value = true;
|
|
50
|
+
formState?.freshFields.delete(id);
|
|
51
|
+
}
|
|
52
|
+
if (formState) formState.register(id, {
|
|
53
|
+
path: opts.path,
|
|
54
|
+
callbacks: {
|
|
55
|
+
validate: () => {
|
|
56
|
+
submitError.value = validate();
|
|
57
|
+
return submitError.value || true;
|
|
58
|
+
},
|
|
59
|
+
clearErrors: () => {
|
|
60
|
+
touched.value = false;
|
|
61
|
+
blur.value = false;
|
|
62
|
+
submitError.value = void 0;
|
|
63
|
+
externalError.value = void 0;
|
|
64
|
+
},
|
|
65
|
+
reset: () => {
|
|
66
|
+
model.value = opts.resetValue ?? "";
|
|
67
|
+
},
|
|
68
|
+
setExternalError: (msg) => {
|
|
69
|
+
externalError.value = msg;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
(0, vue.onUnmounted)(() => {
|
|
74
|
+
formState?.unregister(id);
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
model,
|
|
78
|
+
error,
|
|
79
|
+
onBlur
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/composables/use-as-data.ts
|
|
84
|
+
const EMPTY_PATH = (0, vue.computed)(() => "");
|
|
85
|
+
const EMPTY_DATA = (0, vue.computed)(() => void 0);
|
|
86
|
+
/**
|
|
87
|
+
* Reactive read-only access to form data at any point in the
|
|
88
|
+
* `<AsForm>` tree. Outside a form, all readers return `undefined`.
|
|
89
|
+
*
|
|
90
|
+
* Call sites get a `ComputedRef` so they can compose it directly with
|
|
91
|
+
* other reactive primitives without an extra `computed()` wrapper.
|
|
92
|
+
*/
|
|
93
|
+
function useAsData() {
|
|
94
|
+
const wrapped = (0, vue.inject)(require_use_form_context.ROOT_DATA_KEY, EMPTY_DATA);
|
|
95
|
+
const pathPrefix = (0, vue.inject)(require_use_form_context.PATH_PREFIX_KEY, EMPTY_PATH);
|
|
96
|
+
const rootData = (0, vue.computed)(() => {
|
|
97
|
+
return wrapped.value?.value;
|
|
98
|
+
});
|
|
99
|
+
function getValueAt(path) {
|
|
100
|
+
return (0, vue.computed)(() => {
|
|
101
|
+
const w = wrapped.value;
|
|
102
|
+
if (!w) return void 0;
|
|
103
|
+
return (0, _atscript_ui.getByPath)(w, path);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function siblingValue(name) {
|
|
107
|
+
return (0, vue.computed)(() => {
|
|
108
|
+
const w = wrapped.value;
|
|
109
|
+
if (!w) return void 0;
|
|
110
|
+
const prefix = pathPrefix.value;
|
|
111
|
+
return (0, _atscript_ui.getByPath)(w, prefix ? `${prefix}.${name}` : name);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
rootData,
|
|
116
|
+
getValueAt,
|
|
117
|
+
siblingValue
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/components/as-field.vue?vue&type=script&setup=true&lang.ts
|
|
122
|
+
const _hoisted_1 = { key: 1 };
|
|
123
|
+
const emptyScope = {
|
|
124
|
+
v: void 0,
|
|
125
|
+
data: {},
|
|
126
|
+
context: {},
|
|
127
|
+
entry: void 0
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/components/as-field.vue
|
|
131
|
+
var as_field_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
132
|
+
__name: "as-field",
|
|
133
|
+
props: {
|
|
134
|
+
field: {
|
|
135
|
+
type: Object,
|
|
136
|
+
required: true
|
|
137
|
+
},
|
|
138
|
+
error: {
|
|
139
|
+
type: String,
|
|
140
|
+
required: false
|
|
141
|
+
},
|
|
142
|
+
onRemove: {
|
|
143
|
+
type: Function,
|
|
144
|
+
required: false
|
|
145
|
+
},
|
|
146
|
+
canRemove: {
|
|
147
|
+
type: Boolean,
|
|
148
|
+
required: false
|
|
149
|
+
},
|
|
150
|
+
removeLabel: {
|
|
151
|
+
type: String,
|
|
152
|
+
required: false
|
|
153
|
+
},
|
|
154
|
+
arrayIndex: {
|
|
155
|
+
type: Number,
|
|
156
|
+
required: false
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
setup(__props) {
|
|
160
|
+
const props = __props;
|
|
161
|
+
const types = (0, vue.inject)(require_use_form_context.TYPES_KEY);
|
|
162
|
+
const components = (0, vue.inject)(require_use_form_context.COMPONENTS_KEY);
|
|
163
|
+
const errors = (0, vue.inject)(require_use_form_context.ERRORS_KEY);
|
|
164
|
+
const hideRootTitle = (0, vue.inject)(require_use_form_context.HIDE_ROOT_TITLE_KEY, false);
|
|
165
|
+
const handleAction = (0, vue.inject)(require_use_form_context.ACTION_HANDLER_KEY, () => {});
|
|
166
|
+
const handleChange = (0, vue.inject)(require_use_form_context.CHANGE_HANDLER_KEY, () => {});
|
|
167
|
+
const dismissExternalAt = (0, vue.inject)(require_use_form_context.DISMISS_EXTERNAL_AT_KEY, () => {});
|
|
168
|
+
const { rootFormData, formContext, joinPath, buildPath, getByPath, setByPath, buildScope } = require_use_form_context.useFormContext("AsField");
|
|
169
|
+
const absolutePath = joinPath(() => props.field.path);
|
|
170
|
+
const isStructured = (0, _atscript_ui.isObjectField)(props.field) || (0, _atscript_ui.isArrayField)(props.field) || (0, _atscript_ui.isTupleField)(props.field);
|
|
171
|
+
const isUnion = (0, _atscript_ui.isUnionField)(props.field);
|
|
172
|
+
const parentLevel = (0, vue.inject)(require_use_form_context.LEVEL_KEY, (0, vue.computed)(() => -1));
|
|
173
|
+
const myLevel = isStructured || isUnion ? parentLevel.value + 1 : -1;
|
|
174
|
+
if (isStructured || isUnion) {
|
|
175
|
+
(0, vue.provide)(require_use_form_context.PATH_PREFIX_KEY, (0, vue.computed)(() => absolutePath.value));
|
|
176
|
+
(0, vue.provide)(require_use_form_context.LEVEL_KEY, (0, vue.computed)(() => myLevel));
|
|
177
|
+
}
|
|
178
|
+
const unwrap = (v) => (0, vue.isRef)(v) ? v.value : v;
|
|
179
|
+
function maybeComputed(isDynamic, dynamicFn, staticVal) {
|
|
180
|
+
return isDynamic ? (0, vue.computed)(dynamicFn) : staticVal;
|
|
181
|
+
}
|
|
182
|
+
function buildFieldClasses(classValue, isDisabled, isRequired, isOptional) {
|
|
183
|
+
return {
|
|
184
|
+
...typeof classValue === "string" ? { [classValue]: true } : classValue,
|
|
185
|
+
disabled: isDisabled,
|
|
186
|
+
required: isRequired && !isOptional
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const prop = props.field.prop;
|
|
190
|
+
const autocomplete = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_AUTOCOMPLETE);
|
|
191
|
+
const maxLength = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.EXPECT_MAX_LENGTH)?.length;
|
|
192
|
+
const componentName = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_COMPONENT);
|
|
193
|
+
const prefixIcon = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_PREFIX_ICON);
|
|
194
|
+
const suffixIcon = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_SUFFIX_ICON);
|
|
195
|
+
const valueHelp = (0, _atscript_ui.extractValueHelp)(prop);
|
|
196
|
+
const currencyLiteral = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.DB_AMOUNT_CURRENCY);
|
|
197
|
+
const currencyRefField = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.DB_AMOUNT_CURRENCY_REF);
|
|
198
|
+
const unitLiteral = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.DB_UNIT);
|
|
199
|
+
const unitRefField = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.DB_UNIT_REF);
|
|
200
|
+
const prefixLiteral = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_PREFIX);
|
|
201
|
+
const prefixRefField = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_PREFIX_REF);
|
|
202
|
+
const suffixLiteral = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_SUFFIX);
|
|
203
|
+
const suffixRefField = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_SUFFIX_REF);
|
|
204
|
+
const precisionScale = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.DB_COLUMN_PRECISION)?.scale;
|
|
205
|
+
const hasAdornment = currencyLiteral !== void 0 || currencyRefField !== void 0 || unitLiteral !== void 0 || unitRefField !== void 0 || prefixLiteral !== void 0 || prefixRefField !== void 0 || prefixIcon !== void 0 || suffixLiteral !== void 0 || suffixRefField !== void 0 || suffixIcon !== void 0;
|
|
206
|
+
let resolvedCurrencyCode;
|
|
207
|
+
let resolvedUnitCode;
|
|
208
|
+
let resolvedPrefix;
|
|
209
|
+
let resolvedSuffix;
|
|
210
|
+
let resolvedScale;
|
|
211
|
+
if (hasAdornment) {
|
|
212
|
+
const _data = useAsData();
|
|
213
|
+
const { locale: _locale } = require_use_as_locale.useAsLocale();
|
|
214
|
+
if (currencyLiteral !== void 0) resolvedCurrencyCode = currencyLiteral;
|
|
215
|
+
else if (currencyRefField !== void 0) {
|
|
216
|
+
const ref = _data.siblingValue(currencyRefField);
|
|
217
|
+
resolvedCurrencyCode = (0, vue.computed)(() => {
|
|
218
|
+
const v = ref.value;
|
|
219
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (unitLiteral !== void 0) resolvedUnitCode = unitLiteral;
|
|
223
|
+
else if (unitRefField !== void 0) {
|
|
224
|
+
const ref = _data.siblingValue(unitRefField);
|
|
225
|
+
resolvedUnitCode = (0, vue.computed)(() => {
|
|
226
|
+
const v = ref.value;
|
|
227
|
+
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const readCode = (v) => (0, vue.isRef)(v) ? v.value : v;
|
|
231
|
+
const prefixRefValue = prefixRefField ? _data.siblingValue(prefixRefField) : void 0;
|
|
232
|
+
resolvedPrefix = (0, vue.computed)(() => {
|
|
233
|
+
if (prefixLiteral !== void 0 && prefixLiteral.length > 0) return prefixLiteral;
|
|
234
|
+
if (prefixRefValue) {
|
|
235
|
+
const v = prefixRefValue.value;
|
|
236
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
237
|
+
}
|
|
238
|
+
const code = readCode(resolvedCurrencyCode);
|
|
239
|
+
if (code) return (0, _atscript_ui.getCurrencyDisplayParts)(code, _locale.value).symbol;
|
|
240
|
+
});
|
|
241
|
+
const suffixRefValue = suffixRefField ? _data.siblingValue(suffixRefField) : void 0;
|
|
242
|
+
resolvedSuffix = (0, vue.computed)(() => {
|
|
243
|
+
if (suffixLiteral !== void 0 && suffixLiteral.length > 0) return suffixLiteral;
|
|
244
|
+
if (suffixRefValue) {
|
|
245
|
+
const v = suffixRefValue.value;
|
|
246
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
247
|
+
}
|
|
248
|
+
return readCode(resolvedUnitCode);
|
|
249
|
+
});
|
|
250
|
+
resolvedScale = (0, vue.computed)(() => {
|
|
251
|
+
const code = readCode(resolvedCurrencyCode);
|
|
252
|
+
const currDecimals = code ? (0, _atscript_ui.getCurrencyDecimals)(code, _locale.value) : void 0;
|
|
253
|
+
if (currDecimals !== void 0 && typeof precisionScale === "number") return Math.min(currDecimals, precisionScale);
|
|
254
|
+
if (currDecimals !== void 0) return currDecimals;
|
|
255
|
+
if (typeof precisionScale === "number") return precisionScale;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
let singularLabel;
|
|
259
|
+
if ((0, _atscript_ui.isArrayField)(props.field)) {
|
|
260
|
+
const fromArray = (0, _atscript_ui.resolveSingularLabel)(prop);
|
|
261
|
+
singularLabel = fromArray !== "item" ? fromArray : (0, _atscript_ui.resolveSingularLabel)(props.field.itemField.prop);
|
|
262
|
+
}
|
|
263
|
+
const inputId = `as-field-${(0, vue.useId)()}`;
|
|
264
|
+
const errorId = `${inputId}-err`;
|
|
265
|
+
const descId = `${inputId}-desc`;
|
|
266
|
+
const formActionMeta = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_ACTION);
|
|
267
|
+
const wfActionWithData = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.WF_ACTION_WITH_DATA);
|
|
268
|
+
const formAction = formActionMeta ? {
|
|
269
|
+
id: formActionMeta.id,
|
|
270
|
+
label: formActionMeta.label ?? (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name
|
|
271
|
+
} : wfActionWithData ? {
|
|
272
|
+
id: wfActionWithData,
|
|
273
|
+
label: (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name
|
|
274
|
+
} : void 0;
|
|
275
|
+
const gridClasses = (0, _atscript_ui.buildGridClasses)((0, _atscript_ui.resolveGridSpec)((0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_GRID_COL_SPAN), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_GRID_ROW_SPAN)));
|
|
276
|
+
const formValidate = (0, _atscript_ui.createFieldValidator)(prop, isStructured || isUnion ? { rootOnly: true } : void 0);
|
|
277
|
+
function getModel() {
|
|
278
|
+
return getByPath(absolutePath.value);
|
|
279
|
+
}
|
|
280
|
+
function setModel(value) {
|
|
281
|
+
setByPath(absolutePath.value, value);
|
|
282
|
+
}
|
|
283
|
+
function toggleOptional(enabled) {
|
|
284
|
+
if (enabled) {
|
|
285
|
+
const resolver = (0, _atscript_ui.createFormValueResolver)(rootFormData().value, formContext.value);
|
|
286
|
+
setModel((0, _atscript_ui.createFormData)(props.field.prop, resolver).value);
|
|
287
|
+
} else setModel(void 0);
|
|
288
|
+
handleChange("update", absolutePath.value, getModel());
|
|
289
|
+
}
|
|
290
|
+
const resolvedComponent = (0, vue.computed)(() => {
|
|
291
|
+
if (componentName) return components?.value?.[componentName];
|
|
292
|
+
const map = types?.value;
|
|
293
|
+
if (!map) return void 0;
|
|
294
|
+
return (props.field.customType ? map[props.field.customType] : void 0) ?? map[props.field.type];
|
|
295
|
+
});
|
|
296
|
+
let disabled;
|
|
297
|
+
let hidden;
|
|
298
|
+
let optional;
|
|
299
|
+
let readonly;
|
|
300
|
+
let required;
|
|
301
|
+
let label;
|
|
302
|
+
let description;
|
|
303
|
+
let hint;
|
|
304
|
+
let placeholder;
|
|
305
|
+
let title;
|
|
306
|
+
let styles;
|
|
307
|
+
let options;
|
|
308
|
+
let attrs;
|
|
309
|
+
let classesBase;
|
|
310
|
+
let phantomValue;
|
|
311
|
+
let hasCustomValidators;
|
|
312
|
+
const hasMetaRequired = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_REQUIRED) !== void 0;
|
|
313
|
+
if (props.field.allStatic) {
|
|
314
|
+
hasCustomValidators = false;
|
|
315
|
+
disabled = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_DISABLED) !== void 0;
|
|
316
|
+
hidden = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_HIDDEN) !== void 0;
|
|
317
|
+
optional = props.field.prop.optional ?? false;
|
|
318
|
+
readonly = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_READONLY) !== void 0;
|
|
319
|
+
required = props.field.phantom ? void 0 : hasMetaRequired;
|
|
320
|
+
label = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name;
|
|
321
|
+
description = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_DESCRIPTION);
|
|
322
|
+
hint = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_HINT);
|
|
323
|
+
placeholder = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_PLACEHOLDER);
|
|
324
|
+
styles = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_STYLES);
|
|
325
|
+
options = (0, _atscript_ui.resolveOptions)(prop, emptyScope);
|
|
326
|
+
attrs = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_ATTR) !== void 0 ? (0, _atscript_ui.resolveAttrs)(prop, emptyScope) : void 0;
|
|
327
|
+
title = isStructured || isUnion ? (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name : void 0;
|
|
328
|
+
classesBase = buildFieldClasses((0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_CLASSES), disabled, hasMetaRequired, optional);
|
|
329
|
+
phantomValue = props.field.phantom ? (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_DEFAULT) : void 0;
|
|
330
|
+
} else {
|
|
331
|
+
const hasFn = /* @__PURE__ */ new Set();
|
|
332
|
+
for (const key of prop.metadata.keys()) {
|
|
333
|
+
const k = key;
|
|
334
|
+
if (k.startsWith(_atscript_ui.UI_FORM_FN_PREFIX)) hasFn.add(k.slice(_atscript_ui.UI_FORM_FN_PREFIX.length));
|
|
335
|
+
}
|
|
336
|
+
hasCustomValidators = (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_VALIDATE) !== void 0;
|
|
337
|
+
const needsBaseScope = hasFn.has("disabled") || hasFn.has("hidden") || hasFn.has("readonly");
|
|
338
|
+
const needsFullScope = hasFn.has("label") || hasFn.has("description") || hasFn.has("hint") || hasFn.has("placeholder") || hasFn.has("classes") || hasFn.has("styles") || hasFn.has("options") || hasFn.has("value") || hasFn.has("attr") || hasFn.has("title") || hasCustomValidators;
|
|
339
|
+
const bs = needsBaseScope || needsFullScope ? (0, vue.computed)(() => buildScope(getModel())) : void 0;
|
|
340
|
+
const boolOpts = { staticAsBoolean: true };
|
|
341
|
+
disabled = maybeComputed(hasFn.has("disabled"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_DISABLED, _atscript_ui.UI_FORM_DISABLED, bs.value, boolOpts) ?? false, (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_DISABLED) !== void 0);
|
|
342
|
+
hidden = maybeComputed(hasFn.has("hidden"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_HIDDEN, _atscript_ui.UI_FORM_HIDDEN, bs.value, boolOpts) ?? false, (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_HIDDEN) !== void 0);
|
|
343
|
+
optional = props.field.prop.optional ?? false;
|
|
344
|
+
readonly = maybeComputed(hasFn.has("readonly"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_READONLY, _atscript_ui.META_READONLY, bs.value, boolOpts) ?? false, (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_READONLY) !== void 0);
|
|
345
|
+
required = props.field.phantom ? void 0 : hasMetaRequired;
|
|
346
|
+
const fs = needsFullScope ? (0, vue.computed)(() => (0, _atscript_ui_fns.buildFieldEntry)(prop, bs.value, props.field.path, {
|
|
347
|
+
type: props.field.type,
|
|
348
|
+
component: componentName,
|
|
349
|
+
name: props.field.name,
|
|
350
|
+
optional: unwrap(optional),
|
|
351
|
+
disabled: unwrap(disabled),
|
|
352
|
+
hidden: unwrap(hidden),
|
|
353
|
+
readonly: unwrap(readonly)
|
|
354
|
+
})) : void 0;
|
|
355
|
+
label = maybeComputed(hasFn.has("label"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_LABEL, _atscript_ui.META_LABEL, fs.value) ?? props.field.name, (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name);
|
|
356
|
+
description = maybeComputed(hasFn.has("description"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_DESCRIPTION, _atscript_ui.META_DESCRIPTION, fs.value), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_DESCRIPTION));
|
|
357
|
+
hint = maybeComputed(hasFn.has("hint"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_HINT, _atscript_ui.UI_FORM_HINT, fs.value), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_HINT));
|
|
358
|
+
placeholder = maybeComputed(hasFn.has("placeholder"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_PLACEHOLDER, _atscript_ui.UI_FORM_PLACEHOLDER, fs.value), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_PLACEHOLDER));
|
|
359
|
+
styles = maybeComputed(hasFn.has("styles"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_STYLES, _atscript_ui.UI_FORM_STYLES, fs.value), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_STYLES));
|
|
360
|
+
options = maybeComputed(hasFn.has("options"), () => (0, _atscript_ui.resolveOptions)(prop, fs.value), (0, _atscript_ui.resolveOptions)(prop, emptyScope));
|
|
361
|
+
attrs = hasFn.has("attr") ? (0, vue.computed)(() => (0, _atscript_ui.resolveAttrs)(prop, fs.value)) : (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_ATTR) !== void 0 ? (0, _atscript_ui.resolveAttrs)(prop, emptyScope) : void 0;
|
|
362
|
+
title = isStructured || isUnion ? maybeComputed(hasFn.has("title"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_TITLE, _atscript_ui.META_LABEL, fs.value) ?? props.field.name, (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_LABEL) ?? props.field.name) : void 0;
|
|
363
|
+
const hasFnClasses = hasFn.has("classes");
|
|
364
|
+
classesBase = hasFnClasses || typeof disabled !== "boolean" ? (0, vue.computed)(() => buildFieldClasses(hasFnClasses ? (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_CLASSES, void 0, fs.value) : (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_CLASSES), unwrap(disabled), hasMetaRequired, optional)) : buildFieldClasses((0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.UI_FORM_CLASSES), disabled, hasMetaRequired, optional);
|
|
365
|
+
phantomValue = props.field.phantom ? maybeComputed(hasFn.has("value"), () => (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_VALUE, _atscript_ui.META_DEFAULT, fs.value), (0, _atscript_ui.getFieldMeta)(prop, _atscript_ui.META_DEFAULT)) : void 0;
|
|
366
|
+
if (hasFn.has("value") && !props.field.phantom) (0, vue.watch)((0, vue.computed)(() => {
|
|
367
|
+
if (unwrap(readonly)) return (0, _atscript_ui.resolveFieldProp)(prop, _atscript_ui.UI_FORM_FN_VALUE, _atscript_ui.META_DEFAULT, fs.value);
|
|
368
|
+
}), (newVal) => {
|
|
369
|
+
if (newVal !== void 0) setByPath(absolutePath.value, newVal);
|
|
370
|
+
}, { immediate: true });
|
|
371
|
+
}
|
|
372
|
+
function formRule(v) {
|
|
373
|
+
return formValidate(v, hasCustomValidators ? {
|
|
374
|
+
data: rootFormData(),
|
|
375
|
+
context: formContext.value
|
|
376
|
+
} : void 0);
|
|
377
|
+
}
|
|
378
|
+
const { model, error: formError, onBlur: _onBlur } = useAsField({
|
|
379
|
+
getValue: getModel,
|
|
380
|
+
setValue: setModel,
|
|
381
|
+
rules: [formRule],
|
|
382
|
+
path: () => absolutePath.value,
|
|
383
|
+
...props.field.prop.optional ? { resetValue: void 0 } : (0, _atscript_ui.isArrayField)(props.field) || (0, _atscript_ui.isTupleField)(props.field) ? { resetValue: [] } : (0, _atscript_ui.isObjectField)(props.field) ? { resetValue: {} } : {}
|
|
384
|
+
});
|
|
385
|
+
let lastEmittedValue = model.value;
|
|
386
|
+
const onBlur = isStructured || isUnion ? _onBlur : () => {
|
|
387
|
+
_onBlur();
|
|
388
|
+
const current = model.value;
|
|
389
|
+
if (current !== lastEmittedValue) {
|
|
390
|
+
lastEmittedValue = current;
|
|
391
|
+
handleChange("update", absolutePath.value, current);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
if (!isStructured && !isUnion) (0, vue.watch)(model, (value, prev) => {
|
|
395
|
+
if (value === prev) return;
|
|
396
|
+
const path = absolutePath.value;
|
|
397
|
+
if (path) dismissExternalAt(path);
|
|
398
|
+
});
|
|
399
|
+
const mergedError = (0, vue.computed)(() => {
|
|
400
|
+
const path = buildPath(props.field.path);
|
|
401
|
+
return (path ? errors?.value?.[path] : void 0) ?? props.error ?? formError.value;
|
|
402
|
+
});
|
|
403
|
+
const invariantProps = {
|
|
404
|
+
onBlur,
|
|
405
|
+
model: {
|
|
406
|
+
get value() {
|
|
407
|
+
return model.value;
|
|
408
|
+
},
|
|
409
|
+
set value(v) {
|
|
410
|
+
model.value = v;
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
type: props.field.type,
|
|
414
|
+
formAction,
|
|
415
|
+
name: props.field.name,
|
|
416
|
+
field: props.field,
|
|
417
|
+
maxLength,
|
|
418
|
+
autocomplete,
|
|
419
|
+
prefixIcon,
|
|
420
|
+
suffixIcon,
|
|
421
|
+
level: isStructured || isUnion ? myLevel : void 0,
|
|
422
|
+
path: absolutePath.value,
|
|
423
|
+
valueHelp,
|
|
424
|
+
singularLabel,
|
|
425
|
+
precisionScale,
|
|
426
|
+
hasAdornment,
|
|
427
|
+
inputId,
|
|
428
|
+
errorId,
|
|
429
|
+
descId
|
|
430
|
+
};
|
|
431
|
+
const displayProps = (0, vue.computed)(() => {
|
|
432
|
+
const titleValue = myLevel === 0 && hideRootTitle ? void 0 : unwrap(title);
|
|
433
|
+
return {
|
|
434
|
+
value: unwrap(phantomValue),
|
|
435
|
+
label: unwrap(label),
|
|
436
|
+
description: unwrap(description),
|
|
437
|
+
hint: unwrap(hint),
|
|
438
|
+
placeholder: unwrap(placeholder),
|
|
439
|
+
style: unwrap(styles),
|
|
440
|
+
optional: unwrap(optional),
|
|
441
|
+
onToggleOptional: unwrap(optional) ? toggleOptional : void 0,
|
|
442
|
+
required: required !== void 0 ? unwrap(required) : void 0,
|
|
443
|
+
disabled: unwrap(disabled),
|
|
444
|
+
hidden: unwrap(hidden),
|
|
445
|
+
readonly: unwrap(readonly),
|
|
446
|
+
options: unwrap(options),
|
|
447
|
+
title: titleValue,
|
|
448
|
+
onRemove: props.onRemove,
|
|
449
|
+
canRemove: props.canRemove,
|
|
450
|
+
removeLabel: props.removeLabel,
|
|
451
|
+
arrayIndex: props.arrayIndex,
|
|
452
|
+
currencyCode: unwrap(resolvedCurrencyCode),
|
|
453
|
+
unitCode: unwrap(resolvedUnitCode),
|
|
454
|
+
prefix: unwrap(resolvedPrefix),
|
|
455
|
+
suffix: unwrap(resolvedSuffix),
|
|
456
|
+
scale: unwrap(resolvedScale),
|
|
457
|
+
...unwrap(attrs)
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
const componentProps = (0, vue.computed)(() => {
|
|
461
|
+
const dp = displayProps.value;
|
|
462
|
+
const err = mergedError.value;
|
|
463
|
+
const ariaDescribedBy = err || dp.hint ? errorId : dp.description ? descId : void 0;
|
|
464
|
+
return {
|
|
465
|
+
...invariantProps,
|
|
466
|
+
...dp,
|
|
467
|
+
error: err,
|
|
468
|
+
ariaDescribedBy,
|
|
469
|
+
class: [{
|
|
470
|
+
...unwrap(classesBase),
|
|
471
|
+
error: !!err
|
|
472
|
+
}, gridClasses]
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
return (_ctx, _cache) => {
|
|
476
|
+
return resolvedComponent.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.resolveDynamicComponent)(resolvedComponent.value), (0, vue.mergeProps)({ key: 0 }, componentProps.value, { onAction: (0, vue.unref)(handleAction) }), null, 16, ["onAction"])) : ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_1, " [" + (0, vue.toDisplayString)(unwrap((0, vue.unref)(label))) + "] No component for type \"" + (0, vue.toDisplayString)(__props.field.customType ?? __props.field.type) + "\"" + (0, vue.toDisplayString)((0, vue.unref)(componentName) ? ` (component "${(0, vue.unref)(componentName)}" not supplied)` : ""), 1));
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
//#endregion
|
|
481
|
+
Object.defineProperty(exports, "as_field_default", {
|
|
482
|
+
enumerable: true,
|
|
483
|
+
get: function() {
|
|
484
|
+
return as_field_default;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
Object.defineProperty(exports, "useAsData", {
|
|
488
|
+
enumerable: true,
|
|
489
|
+
get: function() {
|
|
490
|
+
return useAsData;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
Object.defineProperty(exports, "useAsField", {
|
|
494
|
+
enumerable: true,
|
|
495
|
+
get: function() {
|
|
496
|
+
return useAsField;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as vue from "vue";
|
|
2
|
+
import { FormFieldDef } from "@atscript/ui";
|
|
3
|
+
|
|
4
|
+
//#region src/components/as-field.vue.d.ts
|
|
5
|
+
declare const _default: typeof __VLS_export;
|
|
6
|
+
declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
7
|
+
props: vue.PublicProps & __VLS_PrettifyLocal<{
|
|
8
|
+
field: FormFieldDef;
|
|
9
|
+
error?: string;
|
|
10
|
+
onRemove?: () => void;
|
|
11
|
+
canRemove?: boolean;
|
|
12
|
+
removeLabel?: string;
|
|
13
|
+
arrayIndex?: number;
|
|
14
|
+
}> & (typeof globalThis extends {
|
|
15
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
16
|
+
} ? P : {});
|
|
17
|
+
expose: (exposed: {}) => void;
|
|
18
|
+
attrs: any;
|
|
19
|
+
slots: {};
|
|
20
|
+
emit: {};
|
|
21
|
+
}>) => vue.VNode & {
|
|
22
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
23
|
+
};
|
|
24
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
25
|
+
export = _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as vue from "vue";
|
|
2
|
+
import { FormFieldDef } from "@atscript/ui";
|
|
3
|
+
|
|
4
|
+
//#region src/components/as-field.vue.d.ts
|
|
5
|
+
declare const _default: typeof __VLS_export;
|
|
6
|
+
declare const __VLS_export: <TFormData = any, TFormContext = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
7
|
+
props: vue.PublicProps & __VLS_PrettifyLocal<{
|
|
8
|
+
field: FormFieldDef;
|
|
9
|
+
error?: string;
|
|
10
|
+
onRemove?: () => void;
|
|
11
|
+
canRemove?: boolean;
|
|
12
|
+
removeLabel?: string;
|
|
13
|
+
arrayIndex?: number;
|
|
14
|
+
}> & (typeof globalThis extends {
|
|
15
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
16
|
+
} ? P : {});
|
|
17
|
+
expose: (exposed: {}) => void;
|
|
18
|
+
attrs: any;
|
|
19
|
+
slots: {};
|
|
20
|
+
emit: {};
|
|
21
|
+
}>) => vue.VNode & {
|
|
22
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
23
|
+
};
|
|
24
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? { [K in keyof T]: T[K] } : { [K in keyof T as K]: T[K] }) & {};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { _default as default };
|