@harbor-design/proform 1.1.9 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var ee = Object.defineProperty;
2
- var te = (o, e, t) => e in o ? ee(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var l = (o, e, t) => (te(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { toRaw as O, isRef as D, watch as j, isReactive as N, nextTick as A, ref as M, reactive as se, createVNode as c, withDirectives as Y, mergeProps as F, vShow as Z, createTextVNode as re, isVNode as ie, defineComponent as oe } from "vue";
5
- class f {
1
+ var ie = Object.defineProperty;
2
+ var oe = (r, e, t) => e in r ? ie(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var a = (r, e, t) => (oe(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { isRef as x, watch as I, isReactive as k, toRaw as E, nextTick as w, ref as q, reactive as ne, createVNode as p, withDirectives as Z, mergeProps as R, vShow as A, createTextVNode as le, isVNode as ae, defineComponent as ue } from "vue";
5
+ class l {
6
6
  static typeChecker(e) {
7
7
  return {}.toString.call(e);
8
8
  }
@@ -63,18 +63,18 @@ class f {
63
63
  return !1;
64
64
  }
65
65
  }
66
- function m(o, ...e) {
66
+ function m(r, ...e) {
67
67
  return e.forEach((t) => {
68
68
  if (Array.isArray(t))
69
- Array.isArray(o) || (o = []), t.forEach((s, r) => {
70
- typeof s == "object" && s !== null ? o[r] = m(Array.isArray(s) ? [] : {}, s) : o[r] = s;
69
+ Array.isArray(r) || (r = []), t.forEach((s, i) => {
70
+ typeof s == "object" && s !== null ? r[i] = m(Array.isArray(s) ? [] : {}, s) : r[i] = s;
71
71
  });
72
72
  else
73
73
  for (let s in t)
74
- t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? o[s] = m(o[s] || {}, t[s]) : o[s] = t[s]);
75
- }), o;
74
+ t.hasOwnProperty(s) && (typeof t[s] == "object" && t[s] !== null ? r[s] = m(r[s] || {}, t[s]) : r[s] = t[s]);
75
+ }), r;
76
76
  }
77
- function g(o) {
77
+ function g(r) {
78
78
  const e = /* @__PURE__ */ new WeakMap();
79
79
  function t(s) {
80
80
  if (s === null || typeof s != "object")
@@ -84,40 +84,40 @@ function g(o) {
84
84
  if (s instanceof RegExp)
85
85
  return new RegExp(s);
86
86
  if (s instanceof Map) {
87
- const i = /* @__PURE__ */ new Map();
87
+ const o = /* @__PURE__ */ new Map();
88
88
  for (let [n, u] of s)
89
- i.set(t(n), t(u));
90
- return i;
89
+ o.set(t(n), t(u));
90
+ return o;
91
91
  }
92
92
  if (s instanceof Set) {
93
- const i = /* @__PURE__ */ new Set();
93
+ const o = /* @__PURE__ */ new Set();
94
94
  for (let n of s)
95
- i.add(t(n));
96
- return i;
95
+ o.add(t(n));
96
+ return o;
97
97
  }
98
98
  if (e.has(s))
99
99
  return e.get(s);
100
100
  if (Array.isArray(s)) {
101
- const i = [];
102
- e.set(s, i);
101
+ const o = [];
102
+ e.set(s, o);
103
103
  for (let n = 0; n < s.length; n++)
104
- i[n] = t(s[n]);
105
- return i;
104
+ o[n] = t(s[n]);
105
+ return o;
106
106
  }
107
- const r = Object.create(Object.getPrototypeOf(s));
108
- e.set(s, r);
109
- for (let i in s)
110
- s.hasOwnProperty(i) && (r[i] = t(s[i]));
111
- return r;
107
+ const i = Object.create(Object.getPrototypeOf(s));
108
+ e.set(s, i);
109
+ for (let o in s)
110
+ s.hasOwnProperty(o) && (i[o] = t(s[o]));
111
+ return i;
112
112
  }
113
- return t(o);
113
+ return t(r);
114
114
  }
115
- function L(o, e) {
116
- return o.replace(/undefined/g, e);
115
+ function N(r, e) {
116
+ return r.replace(/undefined/g, e);
117
117
  }
118
- class ne {
118
+ class ce {
119
119
  constructor(e) {
120
- l(this, "runtimeCore");
120
+ a(this, "runtimeCore");
121
121
  this.formCustomization = e;
122
122
  }
123
123
  // happy path, 后续可以完善更多的 fallback 处理,fallback 处理是为了不卡住异步时的首次渲染做的优化
@@ -127,19 +127,12 @@ class ne {
127
127
  })), e;
128
128
  }
129
129
  setup(e) {
130
- return this.runtimeCore = e, Object.assign(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.gridProps, this.formCustomization.gridProps), Object.assign(
131
- this.runtimeCore.runtimeSetters,
132
- this.formCustomization.runtimeSetters
133
- ), this.formCustomization;
130
+ return this.runtimeCore = e, Object.assign(this.runtimeCore.native, this.formCustomization.native), Object.assign(this.runtimeCore.grid, this.formCustomization.grid), Object.assign(this.runtimeCore.runtime, this.formCustomization.runtime), this.formCustomization.ui && (this.runtimeCore.ui = this.formCustomization.ui), this.formCustomization;
134
131
  }
135
132
  submit() {
136
- return new Promise((e, t) => {
137
- this.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
138
- this.cleanFallbackFields(
139
- O(this.runtimeCore.processor.processedModel.value)
140
- )
141
- ));
142
- });
133
+ var s;
134
+ const e = (s = f.presets.uiPresets[this.runtimeCore.ui]) == null ? void 0 : s.adapter, t = b.adapters[this.runtimeCore.ui];
135
+ return (e == null ? void 0 : e.validateForm(this)) ?? (t == null ? void 0 : t.validateForm(this));
143
136
  }
144
137
  hydrate(e) {
145
138
  if (!this.runtimeCore)
@@ -149,7 +142,7 @@ class ne {
149
142
  });
150
143
  this.runtimeCore.hydrateEffect.trackEffect(
151
144
  () => {
152
- D(e) ? j(
145
+ x(e) ? I(
153
146
  () => e.value,
154
147
  () => {
155
148
  m(this.runtimeCore.model.value, e.value);
@@ -158,7 +151,7 @@ class ne {
158
151
  deep: !0,
159
152
  immediate: !0
160
153
  }
161
- ) : N(e) ? j(
154
+ ) : k(e) ? I(
162
155
  () => e,
163
156
  () => {
164
157
  m(this.runtimeCore.model.value, e);
@@ -175,9 +168,9 @@ class ne {
175
168
  );
176
169
  }
177
170
  }
178
- class x {
171
+ class U {
179
172
  constructor() {
180
- l(this, "effects", /* @__PURE__ */ new Set());
173
+ a(this, "effects", /* @__PURE__ */ new Set());
181
174
  }
182
175
  clearEffects() {
183
176
  this.effects.clear();
@@ -191,23 +184,23 @@ class x {
191
184
  return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
192
185
  }
193
186
  }
194
- class le {
187
+ class fe {
195
188
  constructor(e) {
196
- l(this, "runtimeCore");
197
- l(this, "processedSchemas");
198
- l(this, "processedModel");
199
- l(this, "getRuntimeMeta");
200
- l(this, "stableSchemas", []);
201
- l(this, "stableModel", {});
202
- l(this, "schemaPreset", w.schemaPreset);
203
- l(this, "componentPropsPreset", w.componentPropsPreset);
204
- l(this, "stableUpdaterProcessProgress");
205
- l(this, "stableUpdaterTimes", 0);
206
- l(this, "schemaEffect", new x());
207
- l(this, "defaultValueEffect", new x());
208
- l(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
209
- l(this, "baseDefaultValueFunctionsLength");
210
- this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), j(
189
+ a(this, "runtimeCore");
190
+ a(this, "processedSchemas");
191
+ a(this, "processedModel");
192
+ a(this, "getRuntimeMeta");
193
+ a(this, "stableSchemas", []);
194
+ a(this, "stableModel", {});
195
+ a(this, "schemaPreset", b.schemaPreset);
196
+ a(this, "componentPropsPreset", b.componentPropsPreset);
197
+ a(this, "stableUpdaterProcessProgress");
198
+ a(this, "stableUpdaterTimes", 0);
199
+ a(this, "schemaEffect", new U());
200
+ a(this, "defaultValueEffect", new U());
201
+ a(this, "defaultValueInprogressMap", /* @__PURE__ */ new Map());
202
+ a(this, "baseDefaultValueFunctionsLength");
203
+ this.runtimeCore = e, this.processedSchemas = e.schemas, this.processedModel = e.model, this.getRuntimeMeta = e.getRuntimeMeta.bind(e), I(
211
204
  () => this.processedModel.value,
212
205
  () => {
213
206
  this.schemaEffect.triggerEffects();
@@ -219,8 +212,8 @@ class le {
219
212
  }
220
213
  // 核心处理过程,接收一个初始的代理数据结构,由其衍生的有 parseSchema
221
214
  parse(e, t) {
222
- e.forEach((s, r) => {
223
- this.parseItem(s, r, t);
215
+ e.forEach((s, i) => {
216
+ this.parseItem(s, i, t);
224
217
  });
225
218
  }
226
219
  // 初始化空数据结构,避免后续复杂的 if else
@@ -232,24 +225,24 @@ class le {
232
225
  }
233
226
  countFunctionDefaultValues(e) {
234
227
  let t = 0, s = /* @__PURE__ */ new Set();
235
- function r(i) {
236
- if (!s.has(i) && (Array.isArray(i) || i !== null && typeof i == "object")) {
237
- s.add(i);
238
- for (let n in i)
239
- i.hasOwnProperty(n) && (n === "defaultValue" && typeof i[n] == "function" && !i[n].toString().includes("[native code]") && t++, r(i[n]));
228
+ function i(o) {
229
+ if (!s.has(o) && (Array.isArray(o) || o !== null && typeof o == "object")) {
230
+ s.add(o);
231
+ for (let n in o)
232
+ o.hasOwnProperty(n) && (n === "defaultValue" && typeof o[n] == "function" && !o[n].toString().includes("[native code]") && t++, i(o[n]));
240
233
  }
241
234
  }
242
- return r(e), t;
235
+ return i(e), t;
243
236
  }
244
237
  // 派生过程,用于外部应用
245
238
  parseSchemas(e, t) {
246
- f.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
239
+ l.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
247
240
  g(e)
248
241
  ), this.processedSchemas.value = this.initSchemas(e)), this.parse(e, t);
249
242
  }
250
243
  parseStable(e) {
251
244
  const t = {};
252
- if (!f.isUndefined(e.stable))
245
+ if (!l.isUndefined(e.stable))
253
246
  t[e.key] = this.parseStable(e.stable);
254
247
  else
255
248
  return e;
@@ -258,110 +251,110 @@ class le {
258
251
  // 对于稳定初始化更新的抽象
259
252
  stableUpdater(e = []) {
260
253
  if (e.every(Boolean)) {
261
- const t = O(this.processedSchemas.value);
262
- !f.isProcessInprogress(t) && f.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
254
+ const t = E(this.processedSchemas.value);
255
+ !l.isProcessInprogress(t) && l.isObjectEmpty(this.stableModel) && (this.stableUpdaterProcessProgress || (this.stableUpdaterProcessProgress = Array.from({
263
256
  length: t.length
264
257
  }).fill(!1)), this.stableUpdaterProcessProgress[this.stableUpdaterTimes] = !0, this.stableUpdaterTimes++, this.modelProcessor(t));
265
258
  }
266
259
  }
267
260
  // 核心单 schema 处理过程,接收一个对象键值对的数据结构
268
261
  parseItem(e, t, s) {
269
- const r = this, i = Array.from({
262
+ const i = this, o = Array.from({
270
263
  length: Object.keys(e).filter((u) => u !== "children").length
271
264
  }).fill(!1);
272
265
  this.objectParser({ data: e, index: t, updater: n });
273
266
  function n(u) {
274
- const a = u.index, d = u.key, E = u.keyIndex;
275
- if (f.isUndefined(u.stable))
267
+ const c = u.index, d = u.key, y = u.keyIndex;
268
+ if (l.isUndefined(u.stable))
276
269
  return;
277
- const U = r.parseStable(u.stable), v = s == null ? void 0 : s.index, b = s == null ? void 0 : s.key;
278
- let y = U;
279
- if (f.isProcessInprogress(y) || (i[E] = !0), s) {
280
- let h = r.processedSchemas.value[v][b][a][d];
281
- h && f.isObject(h) && d !== "component" && (y = m(h, y)), r.processedSchemas.value[v][b][a][d] = y, r.stableUpdater(i);
270
+ const O = i.parseStable(u.stable), C = s == null ? void 0 : s.index, v = s == null ? void 0 : s.key;
271
+ let P = O;
272
+ if (l.isProcessInprogress(P) || (o[y] = !0), s) {
273
+ let h = i.processedSchemas.value[C][v][c][d];
274
+ h && l.isObject(h) && d !== "component" && (P = m(h, P)), i.processedSchemas.value[C][v][c][d] = P, i.stableUpdater(o);
282
275
  } else {
283
- let h = r.processedSchemas.value[a][d];
284
- h && f.isObject(h) && d !== "component" && (y = m(h, y)), r.processedSchemas.value[a][d] = y, r.stableUpdater(i);
276
+ let h = i.processedSchemas.value[c][d];
277
+ h && l.isObject(h) && d !== "component" && (P = m(h, P)), i.processedSchemas.value[c][d] = P, i.stableUpdater(o);
285
278
  }
286
279
  }
287
280
  }
288
281
  // 只做基本的对象 parser
289
282
  objectParser(e) {
290
283
  const t = e.data;
291
- Object.keys(t).forEach((r, i) => {
292
- if (r === "children")
293
- this.parseSchemas(t[r], {
284
+ Object.keys(t).forEach((i, o) => {
285
+ if (i === "children")
286
+ this.parseSchemas(t[i], {
294
287
  ...e,
295
- key: r,
296
- keyIndex: i
288
+ key: i,
289
+ keyIndex: o
297
290
  });
298
291
  else {
299
292
  const n = (u) => {
300
293
  e.updater({
301
294
  ...e,
302
- key: r,
303
- keyIndex: i,
295
+ key: i,
296
+ keyIndex: o,
304
297
  stable: u
305
298
  });
306
299
  };
307
- f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
308
- if (r === "component") {
309
- const u = t[r](this.getRuntimeMeta());
300
+ l.isFunction(t[i]) ? i !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
301
+ if (i === "component") {
302
+ const u = t[i](this.getRuntimeMeta());
310
303
  this.promiseFieldParser(u, n, !1);
311
304
  } else
312
- this.fieldParser(t[r], n);
305
+ this.fieldParser(t[i], n);
313
306
  }) : this.defaultValueEffect.trackEffect(() => {
314
307
  const u = this.schemaEffect.trackEffect(() => {
315
- /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (a) => {
316
- if (!a)
317
- return n(a);
318
- this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
308
+ /\{\s*model\s*\}/.test(t[i].toString()) ? this.fieldParser(t[i], (c) => {
309
+ if (!c)
310
+ return n(c);
311
+ this.defaultValueInprogressMap.set(t[i], c), !l.isProcessInprogress(c) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
319
312
  (d) => !d.includes("undefined")
320
- ) ? (n(a), this.defaultValueEffect.clearEffects(), A(() => {
313
+ ) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
321
314
  u();
322
- })) : n(a);
323
- }) : this.fieldParser(t[r], (a) => {
324
- this.defaultValueInprogressMap.set(t[r], a), !f.isProcessInprogress(a) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
315
+ })) : n(c);
316
+ }) : this.fieldParser(t[i], (c) => {
317
+ this.defaultValueInprogressMap.set(t[i], c), !l.isProcessInprogress(c) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
325
318
  (d) => !d.includes("undefined")
326
- ) ? (n(a), this.defaultValueEffect.clearEffects(), A(() => {
319
+ ) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
327
320
  u();
328
- })) : n(a);
321
+ })) : n(c);
329
322
  });
330
323
  });
331
- }) : r === "component" || r === "slots" || r === "runtimeSetters" ? this.promiseFieldParser(t[r], n, !1) : this.fieldParser(t[r], n);
324
+ }) : i === "component" || i === "slots" || i === "runtime" ? this.promiseFieldParser(t[i], n, !1) : this.fieldParser(t[i], n);
332
325
  }
333
326
  });
334
327
  }
335
328
  promiseFieldParser(e, t, s) {
336
- f.isPromise(e) ? e.then((r) => {
337
- f.isString(r) && (r = L(r, "")), s && f.isObject(r) ? this.objectParser({
338
- data: r,
329
+ l.isPromise(e) ? e.then((i) => {
330
+ l.isString(i) && (i = N(i, "")), s && l.isObject(i) ? this.objectParser({
331
+ data: i,
339
332
  updater: t
340
- }) : t(r);
341
- }) : (f.isString(e) && (e = L(e, "")), s && f.isObject(e) ? this.objectParser({
333
+ }) : t(i);
334
+ }) : (l.isString(e) && (e = N(e, "")), s && l.isObject(e) ? this.objectParser({
342
335
  data: e,
343
336
  updater: t
344
337
  }) : t(e));
345
338
  }
346
339
  // 对任意对象中单个字段的 parse: 做基本处理
347
340
  fieldParser(e, t, s = !0) {
348
- if (f.isFunction(e))
341
+ if (l.isFunction(e))
349
342
  if (e.name.startsWith("__proform_raw_"))
350
- t((...r) => {
343
+ t((...i) => {
351
344
  e({
352
- rawArgs: r,
345
+ rawArgs: i,
353
346
  ...this.getRuntimeMeta()
354
347
  });
355
348
  });
356
349
  else {
357
- const r = e(this.getRuntimeMeta());
358
- this.promiseFieldParser(r, t, s);
350
+ const i = e(this.getRuntimeMeta());
351
+ this.promiseFieldParser(i, t, s);
359
352
  }
360
353
  else
361
- D(e) ? j(
354
+ x(e) ? I(
362
355
  () => e.value,
363
356
  () => {
364
- f.isUndefined(e.value) || (s && f.isObject(e.value) ? this.objectParser({
357
+ l.isUndefined(e.value) || (s && l.isObject(e.value) ? this.objectParser({
365
358
  data: e.value,
366
359
  updater: t
367
360
  }) : t(e.value));
@@ -370,10 +363,10 @@ class le {
370
363
  immediate: !0,
371
364
  deep: !0
372
365
  }
373
- ) : N(e) ? j(
366
+ ) : k(e) ? I(
374
367
  () => e,
375
368
  () => {
376
- f.isUndefined(e) || (s && f.isObject(e) ? this.objectParser({
369
+ l.isUndefined(e) || (s && l.isObject(e) ? this.objectParser({
377
370
  data: e,
378
371
  updater: t
379
372
  }) : t(e));
@@ -382,7 +375,7 @@ class le {
382
375
  immediate: !0,
383
376
  deep: !0
384
377
  }
385
- ) : s && f.isObject(e) ? this.objectParser({
378
+ ) : s && l.isObject(e) ? this.objectParser({
386
379
  data: e,
387
380
  updater: t
388
381
  }) : t(e);
@@ -390,50 +383,100 @@ class le {
390
383
  modelProcessor(e) {
391
384
  e.map(
392
385
  (t) => this.createModel(t, this.processedModel.value)
393
- ), f.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = g(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
386
+ ), l.isObjectEmpty(this.stableModel) && this.stableUpdaterProcessProgress.every(Boolean) && this.defaultValueEffect.effects.size === 0 && (this.stableModel = g(this.processedModel.value), this.runtimeCore.hydrateEffect.triggerEffects(), this.runtimeCore.hydrateEffect.clearEffects());
394
387
  }
395
388
  createModel(e, t) {
396
- f.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
389
+ l.isListSchema(e) && (t[e.field] || (t[e.field] = [{}]), e.children.forEach((s) => {
397
390
  this.createModel(s, t[e.field][0]);
398
- })), f.isGroupSchema(e) && e.children.forEach((s) => {
391
+ })), l.isGroupSchema(e) && e.children.forEach((s) => {
399
392
  this.createModel(s, t);
400
- }), f.isItemSchema(e) && (t[e.field] = e.defaultValue);
393
+ }), l.isItemSchema(e) && (t[e.field] = e.defaultValue);
394
+ }
395
+ }
396
+ class F {
397
+ static getFormContainer({ ui: e } = {}) {
398
+ return f.presets.uiPresets[e ?? f.presets.ui].container.Form;
399
+ }
400
+ static getFormItemContainer({ ui: e } = {}) {
401
+ return f.presets.uiPresets[e ?? f.presets.ui].container.FormItem;
402
+ }
403
+ static getItemContainer({ ui: e } = {}) {
404
+ return f.presets.uiPresets[e ?? f.presets.ui].container.Item;
405
+ }
406
+ static getGroupContainer({ ui: e } = {}) {
407
+ return f.presets.uiPresets[e ?? f.presets.ui].container.Group;
408
+ }
409
+ static getListContainer({ ui: e } = {}) {
410
+ return f.presets.uiPresets[e ?? f.presets.ui].container.List;
411
+ }
412
+ static getListItemContainer({ ui: e } = {}) {
413
+ return f.presets.uiPresets[e ?? f.presets.ui].container.ListItem;
414
+ }
415
+ }
416
+ class de {
417
+ constructor(e) {
418
+ this.ui = e;
419
+ }
420
+ getRuntimeField(e) {
421
+ var i;
422
+ const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = b.adapters[this.ui];
423
+ return (t == null ? void 0 : t.getRuntimeField(e)) ?? (s == null ? void 0 : s.getRuntimeField(e));
424
+ }
425
+ getRuntimeRequired(e) {
426
+ var i;
427
+ const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = b.adapters[this.ui];
428
+ return (t == null ? void 0 : t.getRuntimeRequired(e)) ?? (s == null ? void 0 : s.getRuntimeRequired(e));
429
+ }
430
+ getFormModelPropName() {
431
+ var s;
432
+ const e = (s = f.presets.uiPresets[this.ui]) == null ? void 0 : s.adapter, t = b.adapters[this.ui];
433
+ return (e == null ? void 0 : e.getFormModelPropName()) ?? (t == null ? void 0 : t.getFormModelPropName());
434
+ }
435
+ formComponentRenderer(e) {
436
+ var i;
437
+ const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = b.adapters[this.ui];
438
+ return (t == null ? void 0 : t.formComponentRenderer(e)) ?? (s == null ? void 0 : s.formComponentRenderer(e));
439
+ }
440
+ clearValidate(e) {
441
+ var i;
442
+ const t = (i = f.presets.uiPresets[this.ui]) == null ? void 0 : i.adapter, s = b.adapters[this.ui];
443
+ return (t == null ? void 0 : t.clearValidate(e)) ?? (s == null ? void 0 : s.clearValidate(e));
401
444
  }
402
445
  }
403
- function fe(o) {
404
- return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !ie(o);
446
+ function pe(r) {
447
+ return typeof r == "function" || Object.prototype.toString.call(r) === "[object Object]" && !ae(r);
405
448
  }
406
- class ae {
449
+ class he {
407
450
  constructor(e) {
408
- l(this, "schemas", M([]));
409
- l(this, "model", M({}));
410
- l(this, "processorBySchemaType", {
451
+ a(this, "schemas", q([]));
452
+ a(this, "model", q({}));
453
+ a(this, "processorBySchemaType", {
411
454
  item: this.runtimeItemProcessor.bind(this),
412
455
  group: this.runtimeGroupProcessor.bind(this),
413
456
  list: this.runtimeListProcessor.bind(this)
414
457
  });
415
- l(this, "formRef", M(null));
416
- l(this, "hydrateEffect", new x());
417
- l(this, "native", se({}));
418
- l(this, "gridProps", {});
419
- l(this, "runtimeSetters", {});
420
- l(this, "globalNativeFormOverride", {
458
+ a(this, "formRef", q(null));
459
+ a(this, "hydrateEffect", new U());
460
+ a(this, "native", ne({}));
461
+ a(this, "grid", {});
462
+ a(this, "runtime", {});
463
+ a(this, "globalNativeFormOverride", {
421
464
  props: {},
422
465
  slots: {}
423
466
  });
424
- this.setup = e, this.processor = new le(this);
467
+ this.setup = e, this.processor = new fe(this);
425
468
  const t = this.setup(this);
426
- if (D(t.schemas)) {
427
- const s = j(() => t.schemas, () => {
428
- this.processor.parseSchemas(t.schemas.value), A(() => {
469
+ if (this.ui = t.ui ?? f.presets.ui, this.runtimeAdapter = new de(this.ui), x(t.schemas)) {
470
+ const s = I(() => t.schemas, () => {
471
+ this.processor.parseSchemas(t.schemas.value), w(() => {
429
472
  s();
430
473
  });
431
474
  }, {
432
475
  deep: !0
433
476
  });
434
- } else if (N(t.schemas)) {
435
- const s = j(() => t.schemas, () => {
436
- this.processor.parseSchemas(t.schemas), A(() => {
477
+ } else if (k(t.schemas)) {
478
+ const s = I(() => t.schemas, () => {
479
+ this.processor.parseSchemas(t.schemas), w(() => {
437
480
  s();
438
481
  });
439
482
  }, {
@@ -444,65 +487,57 @@ class ae {
444
487
  }
445
488
  getRuntimeMeta() {
446
489
  return {
447
- model: O(g(this.model.value))
490
+ model: E(g(this.model.value))
448
491
  };
449
492
  }
450
- runtimeItemProcessor(e, t, s = this.model.value, r) {
451
- var R, k, _, z, $, q, B, T, G, K, W, H, J, Q, X;
452
- m(this.globalNativeFormOverride.props, (k = (R = e.native) == null ? void 0 : R.props) == null ? void 0 : k.Form), m(this.globalNativeFormOverride.slots, (z = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : z.Form);
453
- const i = m(g((q = ($ = this.native) == null ? void 0 : $.props) == null ? void 0 : q.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.props) == null ? void 0 : T.FormItem), n = m(g((K = (G = this.native) == null ? void 0 : G.slots) == null ? void 0 : K.FormItem) ?? {}, (H = (W = e.native) == null ? void 0 : W.slots) == null ? void 0 : H.FormItem), u = {
493
+ runtimeItemProcessor(e, t, s = this.model.value, i) {
494
+ var z, $, _, B, D, G, T, K, W, H, J, Q, X;
495
+ const o = E(e.component);
496
+ if (!o)
497
+ return;
498
+ m(this.globalNativeFormOverride.props, ($ = (z = e.native) == null ? void 0 : z.props) == null ? void 0 : $.Form), m(this.globalNativeFormOverride.slots, (B = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : B.Form);
499
+ const n = m(g((G = (D = this.native) == null ? void 0 : D.slots) == null ? void 0 : G.FormItem) ?? {}, (K = (T = e.native) == null ? void 0 : T.slots) == null ? void 0 : K.FormItem), u = {
454
500
  display: "grid",
455
501
  gridColumn: "1 / -1",
456
- ...e.gridProps
457
- }, a = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
458
- if (!d)
459
- return;
460
- const E = d.name, U = e.componentProps ?? {}, v = w.placeholderPresetByComponentName;
461
- let b = e.placeholder;
462
- const y = e.required;
463
- let h = e.show;
464
- h === void 0 && (h = !0), h || delete s[e.field];
465
- let S = e.label;
466
- const I = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
467
- if (!f.isUndefined(t) && !f.isObjectEmpty(I) && (S = L((J = I == null ? void 0 : I.listItemLabelSetter) == null ? void 0 : J.call(I, e.label, t + 1), "")), !b) {
468
- let p = "请输入";
469
- f.isUndefined(E) ? b = `${p}${S}` : /* @ts-expect-error */ v[E.toLowerCase()] ? (p = // @ts-expect-error
470
- v[E.toLowerCase()], b = `${p}${S}`) : (Object.keys(v).forEach((C) => {
471
- E.toLowerCase().includes(C.toLowerCase()) && (p = v[C]);
472
- }), b = `${p}${S}`);
502
+ ...e.grid
503
+ }, c = m(g((H = (W = this.native) == null ? void 0 : W.props) == null ? void 0 : H.FormItem) ?? {}, (Q = (J = e.native) == null ? void 0 : J.props) == null ? void 0 : Q.FormItem), d = this.runtimeAdapter.getRuntimeField({
504
+ schema: e,
505
+ parentSchema: i,
506
+ index: t
507
+ }), y = o.name, O = e.componentProps ?? {}, C = b.placeholderPresetByComponentName;
508
+ let v = e.placeholder, P = e.show;
509
+ P === void 0 && (P = !0), P || delete s[e.field];
510
+ let h = e.label;
511
+ const V = (i == null ? void 0 : i.runtime) ?? this.runtime;
512
+ if (!l.isUndefined(t) && !l.isObjectEmpty(V) && (h = N((X = V == null ? void 0 : V.customizeItemLabel) == null ? void 0 : X.call(V, e.label ?? "", t + 1), "")), !v) {
513
+ let S = "请输入";
514
+ l.isUndefined(y) ? v = `${S}${h}` : /* @ts-expect-error */ C[y.toLowerCase()] ? (S = // @ts-expect-error
515
+ C[y.toLowerCase()], v = `${S}${h}`) : (Object.keys(C).forEach((Y) => {
516
+ y.toLowerCase().includes(Y.toLowerCase()) && (S = C[Y]);
517
+ }), v = `${S}${h}`);
473
518
  }
474
- if (y)
475
- if (!e.rules)
476
- e.rules = [], (Q = e.rules) == null || Q.push({
477
- required: !0,
478
- message: `${S}是必填项`
479
- });
480
- else {
481
- const p = e.rules.findIndex((C) => !f.isUndefined(C.required));
482
- p !== -1 && (e.rules[p].required = !0, e.rules[p].message = `${S}是必填项`);
483
- }
484
- else if (e.rules) {
485
- const p = (X = e.rules) == null ? void 0 : X.findIndex((C) => !!C.required);
486
- p !== -1 && (e.rules[p].required = !1);
487
- }
488
- return c("div", {
519
+ const ee = this.runtimeAdapter.getRuntimeRequired({
520
+ ...e,
521
+ label: h
522
+ }), te = F.getItemContainer(this), se = F.getFormItemContainer(this), re = this;
523
+ return p("div", {
489
524
  style: u
490
- }, [c(P.runtimeDoms.Item, null, {
525
+ }, [p(te, null, {
491
526
  default() {
492
- return Y(c(P.runtimeDoms.FormItem, F(i, {
493
- label: `${S}:`,
494
- rules: e.rules,
495
- field: a
496
- }), {
527
+ return Z(p(se, R(c, {
528
+ label: `${h}:`
529
+ }, d, ee), {
497
530
  default() {
498
- return c(d, F({
499
- modelValue: s[e.field],
500
- "onUpdate:modelValue": (p) => s[e.field] = p,
501
- placeholder: b
502
- }, U), null);
531
+ return re.runtimeAdapter.formComponentRenderer({
532
+ Component: o,
533
+ schema: e,
534
+ baseModel: s,
535
+ placeholder: v,
536
+ props: O
537
+ });
503
538
  },
504
539
  ...n
505
- }), [[Z, h]]);
540
+ }), [[A, P]]);
506
541
  }
507
542
  })]);
508
543
  }
@@ -511,13 +546,13 @@ class ae {
511
546
  const s = {
512
547
  display: "grid",
513
548
  gridColumn: "1 / -1",
514
- ...e.gridProps
515
- };
516
- return c("div", {
549
+ ...e.grid
550
+ }, i = F.getGroupContainer(this);
551
+ return p("div", {
517
552
  style: s
518
- }, [c(P.runtimeDoms.Group, {
553
+ }, [p(i, {
519
554
  schema: e
520
- }, fe(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
555
+ }, pe(t = e.children.map((o) => this.runtimeItemProcessor(o))) ? t : {
521
556
  default: () => [t]
522
557
  })]);
523
558
  }
@@ -528,43 +563,45 @@ class ae {
528
563
  code: "0001",
529
564
  message: "异步默认值数据正在处理中,请您耐心等待... "
530
565
  });
531
- (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(g(this.processor.stableModel[e.field][0])), this.formRef.value.clearValidate();
566
+ (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(g(this.processor.stableModel[e.field][0])), this.runtimeAdapter.clearValidate(this);
532
567
  }
533
568
  deleteListItem(e, t) {
534
- this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
569
+ this.model.value[e.field].splice(t, 1), this.runtimeAdapter.clearValidate(this);
535
570
  }
536
571
  runtimeListProcessor(e) {
537
572
  const t = {
538
573
  display: "grid",
539
574
  gridColumn: "1 / -1",
540
- ...e.gridProps
575
+ ...e.grid
541
576
  }, s = this;
542
- return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
577
+ s.model.value[e.field] || (s.model.value[e.field] = [{}]);
578
+ const i = F.getListContainer(this), o = F.getListItemContainer(this);
579
+ return p("div", {
543
580
  style: t
544
- }, [c(P.runtimeDoms.List, {
581
+ }, [p(i, {
545
582
  schema: e
546
583
  }, {
547
584
  default() {
548
- return s.model.value[e.field].map((r, i) => c(P.runtimeDoms.ListItem, null, {
585
+ return s.model.value[e.field].map((n, u) => p(o, null, {
549
586
  default() {
550
- return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
587
+ return e.children.map((c) => s.runtimeItemProcessor(c, u, n, e));
551
588
  },
552
589
  delete({
553
- container: n
590
+ container: c
554
591
  } = {}) {
555
- var a;
556
- let u = n ?? c("button", null, null);
557
- return Y(c(u, {
558
- onClick: () => s.deleteListItem(e, i)
559
- }, null), [[Z, ((a = s.model.value[e.field]) == null ? void 0 : a.length) > 1]]);
592
+ var y;
593
+ let d = c ?? p("button", null, null);
594
+ return Z(p(d, {
595
+ onClick: () => s.deleteListItem(e, u)
596
+ }, null), [[A, ((y = s.model.value[e.field]) == null ? void 0 : y.length) > 1]]);
560
597
  }
561
598
  }));
562
599
  },
563
600
  add({
564
- container: r
601
+ container: n
565
602
  } = {}) {
566
- let i = r ?? c("button", null, [re("添加")]);
567
- return c(i, {
603
+ let u = n ?? p("button", null, [le("添加")]);
604
+ return p(u, {
568
605
  onClick: () => s.addListItem(e)
569
606
  }, null);
570
607
  }
@@ -574,43 +611,212 @@ class ae {
574
611
  return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
575
612
  }
576
613
  exec() {
577
- var i, n, u, a;
614
+ var u, c, d, y;
578
615
  const e = {
579
616
  display: "grid",
580
617
  gridColumn: "1 / -1",
581
618
  gridAutoColumns: "1fr",
582
- ...this.gridProps
583
- }, t = this, s = m(g((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = m(g((a = (u = this.native) == null ? void 0 : u.slots) == null ? void 0 : a.Form) ?? {}, this.globalNativeFormOverride.slots);
584
- return c(P.runtimeDoms.Form, F(s, {
585
- ref: this.formRef,
586
- model: this.model.value
619
+ ...this.grid
620
+ }, t = this, s = m(g((c = (u = this.native) == null ? void 0 : u.props) == null ? void 0 : c.Form) ?? {}, this.globalNativeFormOverride.props), i = m(g((y = (d = this.native) == null ? void 0 : d.slots) == null ? void 0 : y.Form) ?? {}, this.globalNativeFormOverride.slots), o = F.getFormContainer(this), n = this.runtimeAdapter.getFormModelPropName();
621
+ return p(o, R(s, {
622
+ ref: this.formRef
623
+ }, {
624
+ [n]: this.model.value
587
625
  }), {
588
626
  default() {
589
- return c("div", {
627
+ return p("div", {
590
628
  style: e
591
629
  }, [t.runtimeProcessor(t.schemas.value)]);
592
630
  },
593
- ...r
631
+ ...i
594
632
  });
595
633
  }
596
634
  }
597
- class P {
635
+ class f {
636
+ }
637
+ a(f, "presets");
638
+ function M({
639
+ parentSchema: r,
640
+ schema: e,
641
+ index: t
642
+ }) {
643
+ return r ? `${r.field}.${t}.${e.field}` : e.field;
598
644
  }
599
- l(P, "runtimeDoms");
600
- const V = class V {
645
+ const me = {
646
+ ArcoVue: {
647
+ getRuntimeField(r) {
648
+ return {
649
+ field: M(r)
650
+ };
651
+ },
652
+ getRuntimeRequired(r) {
653
+ var e, t;
654
+ if (r.required)
655
+ if (!r.rules)
656
+ r.rules = [], (e = r.rules) == null || e.push({
657
+ required: !0,
658
+ message: `${r.label}是必填项`
659
+ });
660
+ else {
661
+ const s = r.rules.findIndex((i) => !l.isUndefined(i.required));
662
+ s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
663
+ }
664
+ else if (r.rules) {
665
+ const s = (t = r.rules) == null ? void 0 : t.findIndex((i) => !!i.required);
666
+ s !== -1 && (r.rules[s].required = !1);
667
+ }
668
+ return {
669
+ rules: r.rules
670
+ };
671
+ },
672
+ getFormModelPropName() {
673
+ return "model";
674
+ },
675
+ formComponentRenderer({
676
+ Component: r,
677
+ baseModel: e,
678
+ schema: t,
679
+ placeholder: s,
680
+ props: i
681
+ }) {
682
+ return p(r, R({
683
+ modelValue: e[t.field],
684
+ "onUpdate:modelValue": (o) => e[t.field] = o,
685
+ placeholder: s
686
+ }, i), null);
687
+ },
688
+ validateForm(r) {
689
+ return new Promise((e, t) => {
690
+ r.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(r.cleanFallbackFields(E(r.runtimeCore.processor.processedModel.value))));
691
+ });
692
+ },
693
+ clearValidate(r) {
694
+ r.formRef.value.clearValidate();
695
+ }
696
+ },
697
+ NutUI: {
698
+ getRuntimeField(r) {
699
+ return {
700
+ prop: M(r)
701
+ };
702
+ },
703
+ getRuntimeRequired(r) {
704
+ var e, t;
705
+ if (r.required)
706
+ if (!r.rules)
707
+ r.rules = [], (e = r.rules) == null || e.push({
708
+ required: !0,
709
+ message: `${r.label}是必填项`
710
+ });
711
+ else {
712
+ const s = r.rules.findIndex((i) => !l.isUndefined(i.required));
713
+ s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
714
+ }
715
+ else if (r.rules) {
716
+ const s = (t = r.rules) == null ? void 0 : t.findIndex((i) => !!i.required);
717
+ s !== -1 && (r.rules[s].required = !1);
718
+ }
719
+ return {
720
+ rules: r.rules,
721
+ required: r.required
722
+ };
723
+ },
724
+ getFormModelPropName() {
725
+ return "modelValue";
726
+ },
727
+ formComponentRenderer({
728
+ Component: r,
729
+ baseModel: e,
730
+ schema: t,
731
+ placeholder: s,
732
+ props: i
733
+ }) {
734
+ return p(r, R({
735
+ modelValue: e[t.field],
736
+ "onUpdate:modelValue": (o) => e[t.field] = o,
737
+ placeholder: s
738
+ }, i), null);
739
+ },
740
+ validateForm(r) {
741
+ return new Promise((e, t) => {
742
+ r.runtimeCore.formRef.value.validate().then(({
743
+ valid: s,
744
+ errors: i
745
+ }) => {
746
+ s ? e(r.cleanFallbackFields(E(r.runtimeCore.processor.processedModel.value))) : t(i);
747
+ });
748
+ });
749
+ },
750
+ clearValidate(r) {
751
+ r.formRef.value.reset();
752
+ }
753
+ },
754
+ NaiveUI: {
755
+ getRuntimeField(r) {
756
+ return {
757
+ path: M(r)
758
+ };
759
+ },
760
+ getRuntimeRequired(r) {
761
+ var e, t;
762
+ if (r.required)
763
+ if (!r.rules)
764
+ r.rules = [], (e = r.rules) == null || e.push({
765
+ required: !0,
766
+ message: `${r.label}是必填项`,
767
+ trigger: ["input", "blur"]
768
+ });
769
+ else {
770
+ const s = r.rules.findIndex((i) => !l.isUndefined(i.required));
771
+ s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
772
+ }
773
+ else if (r.rules) {
774
+ const s = (t = r.rules) == null ? void 0 : t.findIndex((i) => !!i.required);
775
+ s !== -1 && (r.rules[s].required = !1);
776
+ }
777
+ return {
778
+ rule: r.rules
779
+ };
780
+ },
781
+ getFormModelPropName() {
782
+ return "model";
783
+ },
784
+ formComponentRenderer({
785
+ Component: r,
786
+ baseModel: e,
787
+ schema: t,
788
+ placeholder: s,
789
+ props: i
790
+ }) {
791
+ return p(r, R({
792
+ value: e[t.field],
793
+ "onUpdate:value": (o) => e[t.field] = o,
794
+ placeholder: s
795
+ }, i), null);
796
+ },
797
+ validateForm(r) {
798
+ return new Promise((e, t) => {
799
+ r.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(r.cleanFallbackFields(E(r.runtimeCore.processor.processedModel.value))));
800
+ });
801
+ },
802
+ clearValidate(r) {
803
+ r.formRef.value.restoreValidation();
804
+ }
805
+ }
806
+ }, j = class j {
601
807
  static getPlaceholderPrefixPresetByComponentName() {
602
808
  const e = {
603
- 请选择: ["select", "tree", "treeselect"],
809
+ 请选择: ["select", "tree"],
604
810
  请输入: ["input"]
605
811
  }, t = {};
606
812
  for (let s in e)
607
- e[s].forEach((r) => {
608
- t[r] = s;
813
+ e[s].forEach((i) => {
814
+ t[i] = s;
609
815
  });
610
816
  return t;
611
817
  }
612
818
  };
613
- l(V, "schemaPreset", {
819
+ a(j, "schemaPreset", {
614
820
  type: {
615
821
  defaultValue: "item"
616
822
  },
@@ -644,29 +850,38 @@ l(V, "schemaPreset", {
644
850
  children: {
645
851
  defaultValue: []
646
852
  },
647
- native: void 0,
648
- gridProps: void 0
649
- }), l(V, "componentPropsPreset", {
853
+ native: {
854
+ defaultValue: void 0
855
+ },
856
+ grid: {
857
+ default: void 0
858
+ }
859
+ }), a(j, "componentPropsPreset", {
650
860
  options: {
651
861
  defaultValue: []
652
862
  }
653
863
  }), // 基于基本功能提出基本预设
654
- l(V, "placeholderPresetByComponentName", V.getPlaceholderPrefixPresetByComponentName());
655
- let w = V;
656
- const de = /* @__PURE__ */ oe({
864
+ a(j, "placeholderPresetByComponentName", j.getPlaceholderPrefixPresetByComponentName());
865
+ let L = j;
866
+ const b = {
867
+ ...L,
868
+ adapters: {
869
+ ...me
870
+ }
871
+ }, be = /* @__PURE__ */ ue({
657
872
  props: {
658
873
  setup: {
659
874
  type: Function,
660
875
  required: !0
661
876
  }
662
877
  },
663
- setup(o) {
664
- const e = new ae(o.setup);
878
+ setup(r) {
879
+ const e = new he(r.setup);
665
880
  return () => e.exec();
666
881
  }
667
882
  });
668
- function pe(o) {
669
- const e = new ne(o);
883
+ function ve(r) {
884
+ const e = new ce(r);
670
885
  return [
671
886
  e.setup.bind(e),
672
887
  {
@@ -675,22 +890,18 @@ function pe(o) {
675
890
  }
676
891
  ];
677
892
  }
678
- function me(o) {
679
- return {
680
- install() {
681
- P.runtimeDoms = o;
682
- }
683
- };
893
+ function ge(r) {
894
+ f.presets = r;
684
895
  }
685
- function he(o, e) {
686
- return e === "raw" && Object.defineProperty(o, "name", {
687
- value: `__proform_raw_${o.name}`,
896
+ function Ce(r, e) {
897
+ return e === "raw" && Object.defineProperty(r, "name", {
898
+ value: `__proform_raw_${r.name}`,
688
899
  writable: !0
689
- }), o;
900
+ }), r;
690
901
  }
691
902
  export {
692
- de as ProForm,
693
- pe as useForm,
694
- me as useFormRenderer,
695
- he as useModifiers
903
+ be as ProForm,
904
+ ve as useForm,
905
+ ge as useFormPresetConfigurer,
906
+ Ce as useModifiers
696
907
  };