@schemx/vue 1.0.0-next.2 → 1.0.0-next.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/README.md +60 -62
- package/dist/analyze.html +1 -1
- package/dist/bridge/fieldBridge.d.ts +23 -0
- package/dist/bridge/fieldBridge.d.ts.map +1 -0
- package/dist/bridge/formBridge.d.ts +81 -0
- package/dist/bridge/formBridge.d.ts.map +1 -0
- package/dist/bridge/formFacade.d.ts +65 -0
- package/dist/bridge/formFacade.d.ts.map +1 -0
- package/dist/bridge/helpers.d.ts +31 -0
- package/dist/bridge/helpers.d.ts.map +1 -0
- package/dist/bridge/index.d.ts +11 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/types.d.ts +109 -0
- package/dist/bridge/types.d.ts.map +1 -0
- package/dist/components/Button/index.vue.d.ts +30 -0
- package/dist/components/Button/index.vue.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/provideFormContext.d.ts +1 -1
- package/dist/hooks/provideFormContext.d.ts.map +1 -1
- package/dist/hooks/useField.d.ts +1 -1
- package/dist/hooks/useField.d.ts.map +1 -1
- package/dist/hooks/useForm.d.ts +1 -1
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useFormSelector.d.ts.map +1 -1
- package/dist/hooks/useWatch.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +184 -176
- package/dist/index.mjs.map +1 -1
- package/dist/types/form.d.ts +1 -1
- package/dist/types/form.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/formBridge.d.ts +0 -188
- package/dist/formBridge.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ export * from './hooks';
|
|
|
11
11
|
/** 高阶组件 */
|
|
12
12
|
export { WithRemoteOptions } from './hocs';
|
|
13
13
|
/** 组件 */
|
|
14
|
-
export { default as Button } from './components/Button';
|
|
15
|
-
export type { SchemxButtonProps, SchemxButtonSize } from './components/Button';
|
|
16
14
|
export { default as FormItem } from './components/FormItem';
|
|
17
15
|
export { default as FormGroup } from './components/FormGroup';
|
|
18
16
|
/** schemx/core 导出 */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAA;AAE3B,WAAW;AACX,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC9C,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAElD,gBAAgB;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAE3D,iBAAiB;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,YAAY;AACZ,cAAc,SAAS,CAAA;AAEvB,WAAW;AACX,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAE1C,SAAS;AACT,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAA;AAE3B,WAAW;AACX,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC9C,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAElD,gBAAgB;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAE3D,iBAAiB;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,YAAY;AACZ,cAAc,SAAS,CAAA;AAEvB,WAAW;AACX,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAE1C,SAAS;AACT,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE7D,qBAAqB;AACrB,cAAc,cAAc,CAAA;AAE5B,YAAY;AACZ,cAAc,SAAS,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,102 +1,23 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
|
-
import { getCurrentInstance, inject,
|
|
2
|
+
import { shallowRef, getCurrentInstance, inject, onScopeDispose, provide, computed, onUnmounted, ref, onMounted, watchEffect, watch, readonly, defineComponent, createVNode, h, createTextVNode, mergeProps, useAttrs, openBlock, createElementBlock, unref, renderSlot, createCommentVNode, createStaticVNode, Fragment, toDisplayString, useSlots, reactive, normalizeClass, normalizeStyle, renderList, createBlock, createSlots, withCtx } from "vue";
|
|
3
3
|
import { createValidationRuleRegistry, mergeSchemxConfig, createForm, createField, createWatch, isViewGroupSchema, isSchemxViewFieldSchema, isSchemxSchemas, defaultSchemxConfigKeys } from "@schemx/core";
|
|
4
4
|
export * from "@schemx/core";
|
|
5
5
|
import classnames from "classnames";
|
|
6
|
-
import {
|
|
6
|
+
import { createFormStateAdapter, createRendererRegistry } from "@schemx/core/adapter";
|
|
7
7
|
import { pick } from "es-toolkit";
|
|
8
|
-
const SCHEMX_APP_CONFIG_KEY = Symbol("schemx:app-config");
|
|
9
|
-
const EMPTY_SCHEMX_CONFIG = Object.freeze({
|
|
10
|
-
schemaConfig: Object.freeze({}),
|
|
11
|
-
validatorAdapters: Object.freeze([])
|
|
12
|
-
});
|
|
13
|
-
function normalizeSchemxAppConfig(config) {
|
|
14
|
-
const schemaConfig = Object.freeze({ ...config.schemaConfig ?? {} });
|
|
15
|
-
const validatorAdapters = Object.freeze([...config.validatorAdapters ?? []]);
|
|
16
|
-
return Object.freeze({
|
|
17
|
-
schemaConfig,
|
|
18
|
-
rendererProps: normalizeRendererProps(config.rendererProps),
|
|
19
|
-
validatorAdapters,
|
|
20
|
-
defaultRendererType: config.defaultRendererType,
|
|
21
|
-
rendererRegistry: config.rendererRegistry,
|
|
22
|
-
validationRuleRegistry: config.validationRuleRegistry
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function normalizeRendererProps(source) {
|
|
26
|
-
if (source === void 0) {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
const entries = Object.entries(source).map(([type, props]) => {
|
|
30
|
-
return [type, props === void 0 ? void 0 : Object.freeze({ ...props })];
|
|
31
|
-
});
|
|
32
|
-
return Object.freeze(Object.fromEntries(entries));
|
|
33
|
-
}
|
|
34
|
-
function provideSchemxAppConfig(app, config = {}) {
|
|
35
|
-
const normalizedConfig = normalizeSchemxAppConfig(config);
|
|
36
|
-
app.provide(SCHEMX_APP_CONFIG_KEY, normalizedConfig);
|
|
37
|
-
}
|
|
38
|
-
function getSchemxAppConfig() {
|
|
39
|
-
if (getCurrentInstance() === null) {
|
|
40
|
-
return EMPTY_SCHEMX_CONFIG;
|
|
41
|
-
}
|
|
42
|
-
return inject(SCHEMX_APP_CONFIG_KEY, EMPTY_SCHEMX_CONFIG);
|
|
43
|
-
}
|
|
44
|
-
const formBridgeCache = /* @__PURE__ */ new WeakMap();
|
|
45
|
-
const formFacadeCache = /* @__PURE__ */ new WeakMap();
|
|
46
|
-
const facadeCoreFormCache = /* @__PURE__ */ new WeakMap();
|
|
47
8
|
function createVueShallowRef(value) {
|
|
48
9
|
return shallowRef(value);
|
|
49
10
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
return coreForm ?? form;
|
|
53
|
-
}
|
|
54
|
-
function getVueFormBridge(form) {
|
|
55
|
-
const coreForm = getCoreForm(form);
|
|
56
|
-
const cachedBridge = formBridgeCache.get(coreForm);
|
|
57
|
-
if (cachedBridge) {
|
|
58
|
-
return cachedBridge;
|
|
59
|
-
}
|
|
60
|
-
const bridge = createVueFormBridge(coreForm);
|
|
61
|
-
formBridgeCache.set(coreForm, bridge);
|
|
62
|
-
return bridge;
|
|
63
|
-
}
|
|
64
|
-
function getVueFormFacade(form) {
|
|
65
|
-
const coreForm = getCoreForm(form);
|
|
66
|
-
const cachedFacade = formFacadeCache.get(coreForm);
|
|
67
|
-
if (cachedFacade) {
|
|
68
|
-
return cachedFacade;
|
|
69
|
-
}
|
|
70
|
-
const facade = createVueFormFacade(coreForm);
|
|
71
|
-
formFacadeCache.set(coreForm, facade);
|
|
72
|
-
facadeCoreFormCache.set(facade, coreForm);
|
|
73
|
-
return facade;
|
|
74
|
-
}
|
|
75
|
-
function retainVueFormBridge(bridge) {
|
|
76
|
-
if (bridge.destroyed) {
|
|
77
|
-
return () => {
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
bridge.refCount++;
|
|
81
|
-
let released = false;
|
|
82
|
-
return () => {
|
|
83
|
-
if (released || bridge.destroyed) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
released = true;
|
|
87
|
-
bridge.refCount--;
|
|
88
|
-
if (bridge.refCount === 0) {
|
|
89
|
-
disposeVueFormBridge(bridge);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
11
|
+
function areStringListsEqual(previous, next) {
|
|
12
|
+
return previous.length === next.length && previous.every((value, index) => value === next[index]);
|
|
92
13
|
}
|
|
93
14
|
function getVueFieldBridge(bridge, name) {
|
|
94
|
-
const
|
|
95
|
-
const cachedBridge = bridge.fieldBridges.get(
|
|
15
|
+
const source = bridge.stateAdapter.field(name);
|
|
16
|
+
const cachedBridge = bridge.fieldBridges.get(source);
|
|
96
17
|
if (cachedBridge) {
|
|
97
18
|
return cachedBridge;
|
|
98
19
|
}
|
|
99
|
-
const snapshot =
|
|
20
|
+
const snapshot = source.getSnapshot();
|
|
100
21
|
const value = createVueShallowRef(
|
|
101
22
|
snapshot.value
|
|
102
23
|
);
|
|
@@ -104,7 +25,7 @@ function getVueFieldBridge(bridge, name) {
|
|
|
104
25
|
const touched = createVueShallowRef(snapshot.touched);
|
|
105
26
|
const pending = createVueShallowRef(snapshot.pending);
|
|
106
27
|
const updateFieldRefs = () => {
|
|
107
|
-
const nextSnapshot =
|
|
28
|
+
const nextSnapshot = source.getSnapshot();
|
|
108
29
|
if (!Object.is(value.value, nextSnapshot.value)) {
|
|
109
30
|
value.value = nextSnapshot.value;
|
|
110
31
|
}
|
|
@@ -118,122 +39,59 @@ function getVueFieldBridge(bridge, name) {
|
|
|
118
39
|
pending.value = nextSnapshot.pending;
|
|
119
40
|
}
|
|
120
41
|
};
|
|
121
|
-
const unsubscribe =
|
|
42
|
+
const unsubscribe = source.subscribe(updateFieldRefs);
|
|
122
43
|
const dispose = () => {
|
|
123
44
|
unsubscribe();
|
|
124
45
|
};
|
|
125
46
|
const fieldBridge = {
|
|
126
|
-
|
|
47
|
+
source,
|
|
127
48
|
value,
|
|
128
49
|
errors,
|
|
129
50
|
touched,
|
|
130
51
|
pending,
|
|
131
52
|
dispose
|
|
132
53
|
};
|
|
133
|
-
bridge.fieldBridges.set(
|
|
54
|
+
bridge.fieldBridges.set(source, fieldBridge);
|
|
134
55
|
return fieldBridge;
|
|
135
56
|
}
|
|
136
|
-
function
|
|
137
|
-
if (bridge.destroyed) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
bridge.destroyed = true;
|
|
141
|
-
bridge.refCount = 0;
|
|
142
|
-
bridge.unsubscribe();
|
|
143
|
-
for (const fieldBridge of bridge.fieldBridges.values()) {
|
|
144
|
-
fieldBridge.dispose();
|
|
145
|
-
}
|
|
146
|
-
bridge.fieldBridges.clear();
|
|
147
|
-
bridge.externalStore.dispose();
|
|
148
|
-
formBridgeCache.delete(bridge.form);
|
|
149
|
-
}
|
|
150
|
-
function createVueFormBridge(form) {
|
|
151
|
-
const externalStore = createFormExternalStore(form);
|
|
152
|
-
const values = createVueShallowRef(externalStore.values.getSnapshot());
|
|
153
|
-
const touchedFields = createVueShallowRef(
|
|
154
|
-
externalStore.touchedFields.getSnapshot()
|
|
155
|
-
);
|
|
156
|
-
const pendingFields = createVueShallowRef(
|
|
157
|
-
externalStore.pendingFields.getSnapshot()
|
|
158
|
-
);
|
|
159
|
-
const loading = createVueShallowRef(externalStore.loading.getSnapshot());
|
|
160
|
-
const fieldBridges = /* @__PURE__ */ new Map();
|
|
161
|
-
const syncValues = () => {
|
|
162
|
-
values.value = externalStore.values.getSnapshot();
|
|
163
|
-
};
|
|
164
|
-
const syncTouchedFields = () => {
|
|
165
|
-
touchedFields.value = externalStore.touchedFields.getSnapshot();
|
|
166
|
-
};
|
|
167
|
-
const syncPendingFields = () => {
|
|
168
|
-
pendingFields.value = externalStore.pendingFields.getSnapshot();
|
|
169
|
-
};
|
|
170
|
-
const syncLoading = () => {
|
|
171
|
-
loading.value = externalStore.loading.getSnapshot();
|
|
172
|
-
};
|
|
173
|
-
const unsubscribeValues = externalStore.values.subscribe(syncValues);
|
|
174
|
-
const unsubscribeTouchedFields = externalStore.touchedFields.subscribe(syncTouchedFields);
|
|
175
|
-
const unsubscribePendingFields = externalStore.pendingFields.subscribe(syncPendingFields);
|
|
176
|
-
const unsubscribeLoading = externalStore.loading.subscribe(syncLoading);
|
|
177
|
-
const unsubscribe = () => {
|
|
178
|
-
unsubscribeValues();
|
|
179
|
-
unsubscribeTouchedFields();
|
|
180
|
-
unsubscribePendingFields();
|
|
181
|
-
unsubscribeLoading();
|
|
182
|
-
};
|
|
183
|
-
const facade = getVueFormFacade(form);
|
|
184
|
-
const bridge = {
|
|
185
|
-
form,
|
|
186
|
-
externalStore,
|
|
187
|
-
values,
|
|
188
|
-
touchedFields,
|
|
189
|
-
pendingFields,
|
|
190
|
-
loading,
|
|
191
|
-
fieldBridges,
|
|
192
|
-
refCount: 0,
|
|
193
|
-
destroyed: false,
|
|
194
|
-
unsubscribe,
|
|
195
|
-
facade
|
|
196
|
-
};
|
|
197
|
-
return bridge;
|
|
198
|
-
}
|
|
199
|
-
function createVueFormFacade(form) {
|
|
57
|
+
function createVueFormFacade(form, dependencies) {
|
|
200
58
|
let destroyed = false;
|
|
201
59
|
const getFieldValue = (name) => {
|
|
202
60
|
if (!destroyed) {
|
|
203
|
-
const bridge =
|
|
204
|
-
void
|
|
61
|
+
const bridge = dependencies.getFormBridge(form);
|
|
62
|
+
void dependencies.getFieldBridge(bridge, name).value.value;
|
|
205
63
|
}
|
|
206
64
|
return form.getFieldValue(name);
|
|
207
65
|
};
|
|
208
66
|
const getFieldErrors = (name) => {
|
|
209
67
|
if (!destroyed) {
|
|
210
|
-
const bridge =
|
|
211
|
-
void
|
|
68
|
+
const bridge = dependencies.getFormBridge(form);
|
|
69
|
+
void dependencies.getFieldBridge(bridge, name).errors.value;
|
|
212
70
|
}
|
|
213
71
|
return form.getFieldErrors(name);
|
|
214
72
|
};
|
|
215
73
|
const isFieldTouched = (name) => {
|
|
216
74
|
if (!destroyed) {
|
|
217
|
-
const bridge =
|
|
218
|
-
void
|
|
75
|
+
const bridge = dependencies.getFormBridge(form);
|
|
76
|
+
void dependencies.getFieldBridge(bridge, name).touched.value;
|
|
219
77
|
}
|
|
220
78
|
return form.isFieldTouched(name);
|
|
221
79
|
};
|
|
222
80
|
const isFieldPending = (name) => {
|
|
223
81
|
if (!destroyed) {
|
|
224
|
-
const bridge =
|
|
225
|
-
void
|
|
82
|
+
const bridge = dependencies.getFormBridge(form);
|
|
83
|
+
void dependencies.getFieldBridge(bridge, name).pending.value;
|
|
226
84
|
}
|
|
227
85
|
return form.isFieldPending(name);
|
|
228
86
|
};
|
|
229
87
|
const getFieldsValue = (names) => {
|
|
230
88
|
if (!destroyed) {
|
|
231
|
-
const bridge =
|
|
89
|
+
const bridge = dependencies.getFormBridge(form);
|
|
232
90
|
if (names === void 0) {
|
|
233
91
|
void bridge.values.value;
|
|
234
92
|
} else {
|
|
235
93
|
for (const name of names) {
|
|
236
|
-
void
|
|
94
|
+
void dependencies.getFieldBridge(bridge, name).value.value;
|
|
237
95
|
}
|
|
238
96
|
}
|
|
239
97
|
}
|
|
@@ -241,21 +99,21 @@ function createVueFormFacade(form) {
|
|
|
241
99
|
};
|
|
242
100
|
const getTouchedFields = () => {
|
|
243
101
|
if (!destroyed) {
|
|
244
|
-
const bridge =
|
|
102
|
+
const bridge = dependencies.getFormBridge(form);
|
|
245
103
|
void bridge.touchedFields.value;
|
|
246
104
|
}
|
|
247
105
|
return form.getTouchedFields();
|
|
248
106
|
};
|
|
249
107
|
const getPendingFields = () => {
|
|
250
108
|
if (!destroyed) {
|
|
251
|
-
const bridge =
|
|
109
|
+
const bridge = dependencies.getFormBridge(form);
|
|
252
110
|
void bridge.pendingFields.value;
|
|
253
111
|
}
|
|
254
112
|
return form.getPendingFields();
|
|
255
113
|
};
|
|
256
114
|
const isLoading = () => {
|
|
257
115
|
if (!destroyed) {
|
|
258
|
-
const bridge =
|
|
116
|
+
const bridge = dependencies.getFormBridge(form);
|
|
259
117
|
void bridge.loading.value;
|
|
260
118
|
}
|
|
261
119
|
return form.isLoading();
|
|
@@ -265,9 +123,9 @@ function createVueFormFacade(form) {
|
|
|
265
123
|
return;
|
|
266
124
|
}
|
|
267
125
|
destroyed = true;
|
|
268
|
-
const bridge =
|
|
126
|
+
const bridge = dependencies.getCachedFormBridge(form);
|
|
269
127
|
if (bridge) {
|
|
270
|
-
|
|
128
|
+
dependencies.disposeFormBridge(bridge);
|
|
271
129
|
}
|
|
272
130
|
form.destroy();
|
|
273
131
|
};
|
|
@@ -284,8 +142,158 @@ function createVueFormFacade(form) {
|
|
|
284
142
|
destroy
|
|
285
143
|
};
|
|
286
144
|
}
|
|
287
|
-
|
|
288
|
-
|
|
145
|
+
const formBridgeCache = /* @__PURE__ */ new WeakMap();
|
|
146
|
+
const formFacadeCache = /* @__PURE__ */ new WeakMap();
|
|
147
|
+
const facadeCoreFormCache = /* @__PURE__ */ new WeakMap();
|
|
148
|
+
function getCoreForm(form) {
|
|
149
|
+
const coreForm = facadeCoreFormCache.get(form);
|
|
150
|
+
return coreForm ?? form;
|
|
151
|
+
}
|
|
152
|
+
function getVueFormBridge(form) {
|
|
153
|
+
const coreForm = getCoreForm(form);
|
|
154
|
+
const cachedBridge = formBridgeCache.get(coreForm);
|
|
155
|
+
if (cachedBridge) {
|
|
156
|
+
return cachedBridge;
|
|
157
|
+
}
|
|
158
|
+
const bridge = createVueFormBridge(coreForm);
|
|
159
|
+
formBridgeCache.set(coreForm, bridge);
|
|
160
|
+
return bridge;
|
|
161
|
+
}
|
|
162
|
+
function getVueFormFacade(form) {
|
|
163
|
+
const coreForm = getCoreForm(form);
|
|
164
|
+
const cachedFacade = formFacadeCache.get(coreForm);
|
|
165
|
+
if (cachedFacade) {
|
|
166
|
+
return cachedFacade;
|
|
167
|
+
}
|
|
168
|
+
const facade = createVueFormFacade(coreForm, {
|
|
169
|
+
getFormBridge: (bridgeForm) => getVueFormBridge(bridgeForm),
|
|
170
|
+
getFieldBridge: (bridge, name) => getVueFieldBridge(bridge, name),
|
|
171
|
+
getCachedFormBridge: (bridgeForm) => {
|
|
172
|
+
const bridge = formBridgeCache.get(bridgeForm);
|
|
173
|
+
return bridge;
|
|
174
|
+
},
|
|
175
|
+
disposeFormBridge: (bridge) => disposeVueFormBridge(bridge)
|
|
176
|
+
});
|
|
177
|
+
formFacadeCache.set(coreForm, facade);
|
|
178
|
+
facadeCoreFormCache.set(facade, coreForm);
|
|
179
|
+
return facade;
|
|
180
|
+
}
|
|
181
|
+
function retainVueFormBridge(bridge) {
|
|
182
|
+
if (bridge.destroyed) {
|
|
183
|
+
return () => {
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
bridge.refCount++;
|
|
187
|
+
let released = false;
|
|
188
|
+
return () => {
|
|
189
|
+
if (released || bridge.destroyed) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
released = true;
|
|
193
|
+
bridge.refCount--;
|
|
194
|
+
if (bridge.refCount === 0) {
|
|
195
|
+
disposeVueFormBridge(bridge);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function disposeVueFormBridge(bridge) {
|
|
200
|
+
if (bridge.destroyed) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
bridge.destroyed = true;
|
|
204
|
+
bridge.refCount = 0;
|
|
205
|
+
bridge.unsubscribe();
|
|
206
|
+
for (const fieldBridge of bridge.fieldBridges.values()) {
|
|
207
|
+
fieldBridge.dispose();
|
|
208
|
+
}
|
|
209
|
+
bridge.fieldBridges.clear();
|
|
210
|
+
bridge.stateAdapter.dispose();
|
|
211
|
+
formBridgeCache.delete(bridge.form);
|
|
212
|
+
}
|
|
213
|
+
function createVueFormBridge(form) {
|
|
214
|
+
const stateAdapter = createFormStateAdapter(form);
|
|
215
|
+
const values = createVueShallowRef(stateAdapter.values.getSnapshot());
|
|
216
|
+
const touchedFields = createVueShallowRef(
|
|
217
|
+
stateAdapter.touchedFields.getSnapshot()
|
|
218
|
+
);
|
|
219
|
+
const pendingFields = createVueShallowRef(
|
|
220
|
+
stateAdapter.pendingFields.getSnapshot()
|
|
221
|
+
);
|
|
222
|
+
const loading = createVueShallowRef(stateAdapter.loading.getSnapshot());
|
|
223
|
+
const fieldBridges = /* @__PURE__ */ new Map();
|
|
224
|
+
const syncValues = () => {
|
|
225
|
+
values.value = stateAdapter.values.getSnapshot();
|
|
226
|
+
};
|
|
227
|
+
const syncTouchedFields = () => {
|
|
228
|
+
touchedFields.value = stateAdapter.touchedFields.getSnapshot();
|
|
229
|
+
};
|
|
230
|
+
const syncPendingFields = () => {
|
|
231
|
+
pendingFields.value = stateAdapter.pendingFields.getSnapshot();
|
|
232
|
+
};
|
|
233
|
+
const syncLoading = () => {
|
|
234
|
+
loading.value = stateAdapter.loading.getSnapshot();
|
|
235
|
+
};
|
|
236
|
+
const unsubscribeValues = stateAdapter.values.subscribe(syncValues);
|
|
237
|
+
const unsubscribeTouchedFields = stateAdapter.touchedFields.subscribe(syncTouchedFields);
|
|
238
|
+
const unsubscribePendingFields = stateAdapter.pendingFields.subscribe(syncPendingFields);
|
|
239
|
+
const unsubscribeLoading = stateAdapter.loading.subscribe(syncLoading);
|
|
240
|
+
const unsubscribe = () => {
|
|
241
|
+
unsubscribeValues();
|
|
242
|
+
unsubscribeTouchedFields();
|
|
243
|
+
unsubscribePendingFields();
|
|
244
|
+
unsubscribeLoading();
|
|
245
|
+
};
|
|
246
|
+
const facade = getVueFormFacade(form);
|
|
247
|
+
const bridge = {
|
|
248
|
+
form,
|
|
249
|
+
stateAdapter,
|
|
250
|
+
values,
|
|
251
|
+
touchedFields,
|
|
252
|
+
pendingFields,
|
|
253
|
+
loading,
|
|
254
|
+
fieldBridges,
|
|
255
|
+
refCount: 0,
|
|
256
|
+
destroyed: false,
|
|
257
|
+
unsubscribe,
|
|
258
|
+
facade
|
|
259
|
+
};
|
|
260
|
+
return bridge;
|
|
261
|
+
}
|
|
262
|
+
const SCHEMX_APP_CONFIG_KEY = Symbol("schemx:app-config");
|
|
263
|
+
const EMPTY_SCHEMX_CONFIG = Object.freeze({
|
|
264
|
+
schemaConfig: Object.freeze({}),
|
|
265
|
+
validatorAdapters: Object.freeze([])
|
|
266
|
+
});
|
|
267
|
+
function normalizeSchemxAppConfig(config) {
|
|
268
|
+
const schemaConfig = Object.freeze({ ...config.schemaConfig ?? {} });
|
|
269
|
+
const validatorAdapters = Object.freeze([...config.validatorAdapters ?? []]);
|
|
270
|
+
return Object.freeze({
|
|
271
|
+
schemaConfig,
|
|
272
|
+
rendererProps: normalizeRendererProps(config.rendererProps),
|
|
273
|
+
validatorAdapters,
|
|
274
|
+
defaultRendererType: config.defaultRendererType,
|
|
275
|
+
rendererRegistry: config.rendererRegistry,
|
|
276
|
+
validationRuleRegistry: config.validationRuleRegistry
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function normalizeRendererProps(source) {
|
|
280
|
+
if (source === void 0) {
|
|
281
|
+
return void 0;
|
|
282
|
+
}
|
|
283
|
+
const entries = Object.entries(source).map(([type, props]) => {
|
|
284
|
+
return [type, props === void 0 ? void 0 : Object.freeze({ ...props })];
|
|
285
|
+
});
|
|
286
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
287
|
+
}
|
|
288
|
+
function provideSchemxAppConfig(app, config = {}) {
|
|
289
|
+
const normalizedConfig = normalizeSchemxAppConfig(config);
|
|
290
|
+
app.provide(SCHEMX_APP_CONFIG_KEY, normalizedConfig);
|
|
291
|
+
}
|
|
292
|
+
function getSchemxAppConfig() {
|
|
293
|
+
if (getCurrentInstance() === null) {
|
|
294
|
+
return EMPTY_SCHEMX_CONFIG;
|
|
295
|
+
}
|
|
296
|
+
return inject(SCHEMX_APP_CONFIG_KEY, EMPTY_SCHEMX_CONFIG);
|
|
289
297
|
}
|
|
290
298
|
const rendererRegistry = createRendererRegistry("input");
|
|
291
299
|
const validationRuleRegistry = createValidationRuleRegistry();
|
|
@@ -1137,8 +1145,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1137
1145
|
modelValue: { default: () => ({}) },
|
|
1138
1146
|
form: { default: void 0 },
|
|
1139
1147
|
loading: { type: Boolean, default: void 0 },
|
|
1140
|
-
submitter: { type: [Boolean, Object], default:
|
|
1141
|
-
resetter: { type: [Boolean, Object], default:
|
|
1148
|
+
submitter: { type: [Boolean, Object], default: void 0 },
|
|
1149
|
+
resetter: { type: [Boolean, Object], default: void 0 },
|
|
1142
1150
|
class: { default: "" },
|
|
1143
1151
|
style: { type: [Boolean, null, String, Object, Array], default: () => ({}) },
|
|
1144
1152
|
rendererProps: { default: void 0 },
|
|
@@ -1333,11 +1341,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1333
1341
|
},
|
|
1334
1342
|
{ deep: false, immediate: isExternalForm }
|
|
1335
1343
|
);
|
|
1336
|
-
|
|
1344
|
+
const exposed = {
|
|
1337
1345
|
...formInstance,
|
|
1338
1346
|
submit: handleSubmit,
|
|
1339
1347
|
reset: handleReset
|
|
1340
|
-
}
|
|
1348
|
+
};
|
|
1349
|
+
__expose(exposed);
|
|
1341
1350
|
return (_ctx, _cache) => {
|
|
1342
1351
|
return openBlock(), createElementBlock("div", {
|
|
1343
1352
|
class: normalizeClass(["schemx", props.class]),
|
|
@@ -1444,7 +1453,6 @@ function WithRemoteOptions(WrappedComponent) {
|
|
|
1444
1453
|
});
|
|
1445
1454
|
}
|
|
1446
1455
|
export {
|
|
1447
|
-
_sfc_main$1 as Button,
|
|
1448
1456
|
FormGroup$1 as FormGroup,
|
|
1449
1457
|
FormItem$1 as FormItem,
|
|
1450
1458
|
WithRemoteOptions,
|