@harbor-design/proform 1.1.8 → 1.1.11

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 N, watch as v, isReactive as R, nextTick as w, ref as M, reactive as se, createVNode as c, withDirectives as Y, mergeProps as U, vShow as Z, createTextVNode as re, isVNode as ie, defineComponent as oe } from "vue";
5
- class f {
1
+ var re = Object.defineProperty;
2
+ var ie = (r, e, t) => e in r ? re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var a = (r, e, t) => (ie(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { isRef as U, watch as I, isReactive as x, toRaw as V, nextTick as w, ref as R, reactive as oe, createVNode as p, withDirectives as Y, mergeProps as M, vShow as Z, createTextVNode as ne, isVNode as le, defineComponent as ae } 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 p(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] = p(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] = p(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 b(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 b(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();
88
- for (let [n, a] of s)
89
- i.set(t(n), t(a));
90
- return i;
87
+ const o = /* @__PURE__ */ new Map();
88
+ for (let [n, u] of s)
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 F(o, e) {
116
- return o.replace(/undefined/g, e);
115
+ function q(r, e) {
116
+ return r.replace(/undefined/g, e);
117
117
  }
118
- class ne {
118
+ class ue {
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 = j.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,25 +142,25 @@ class ne {
149
142
  });
150
143
  this.runtimeCore.hydrateEffect.trackEffect(
151
144
  () => {
152
- N(e) ? v(
145
+ U(e) ? I(
153
146
  () => e.value,
154
147
  () => {
155
- p(this.runtimeCore.model.value, e.value);
148
+ m(this.runtimeCore.model.value, e.value);
156
149
  },
157
150
  {
158
151
  deep: !0,
159
152
  immediate: !0
160
153
  }
161
- ) : R(e) ? v(
154
+ ) : x(e) ? I(
162
155
  () => e,
163
156
  () => {
164
- p(this.runtimeCore.model.value, e);
157
+ m(this.runtimeCore.model.value, e);
165
158
  },
166
159
  {
167
160
  deep: !0,
168
161
  immediate: !0
169
162
  }
170
- ) : p(this.runtimeCore.model.value, e);
163
+ ) : m(this.runtimeCore.model.value, e);
171
164
  },
172
165
  {
173
166
  lazy: !0
@@ -175,9 +168,9 @@ class ne {
175
168
  );
176
169
  }
177
170
  }
178
- class D {
171
+ class N {
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 D {
191
184
  return !t.lazy && e(), this.effects.add(e), () => this.effects.delete(e);
192
185
  }
193
186
  }
194
- class le {
187
+ class ce {
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", V.schemaPreset);
203
- l(this, "componentPropsPreset", V.componentPropsPreset);
204
- l(this, "stableUpdaterProcessProgress");
205
- l(this, "stableUpdaterTimes", 0);
206
- l(this, "schemaEffect", new D());
207
- l(this, "defaultValueEffect", new D());
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), v(
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", j.schemaPreset);
196
+ a(this, "componentPropsPreset", j.componentPropsPreset);
197
+ a(this, "stableUpdaterProcessProgress");
198
+ a(this, "stableUpdaterTimes", 0);
199
+ a(this, "schemaEffect", new N());
200
+ a(this, "defaultValueEffect", new N());
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(
247
- b(e)
239
+ l.isArrayEmpty(this.processedSchemas.value) && (this.baseDefaultValueFunctionsLength = this.countFunctionDefaultValues(
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 = V(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({
270
- length: Object.keys(e).filter((a) => a !== "children").length
262
+ const i = this, o = Array.from({
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
- function n(a) {
274
- const u = a.index, d = a.key, C = a.keyIndex;
275
- if (f.isUndefined(a.stable))
266
+ function n(u) {
267
+ const c = u.index, d = u.key, y = u.keyIndex;
268
+ if (l.isUndefined(u.stable))
276
269
  return;
277
- const A = r.parseStable(a.stable), I = s == null ? void 0 : s.index, P = s == null ? void 0 : s.key;
278
- let y = A;
279
- if (f.isProcessInprogress(y) || (i[C] = !0), s) {
280
- let m = r.processedSchemas.value[I][P][u][d];
281
- m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[I][P][u][d] = y, r.stableUpdater(i);
270
+ const O = i.parseStable(u.stable), v = s == null ? void 0 : s.index, P = s == null ? void 0 : s.key;
271
+ let b = O;
272
+ if (l.isProcessInprogress(b) || (o[y] = !0), s) {
273
+ let h = i.processedSchemas.value[v][P][c][d];
274
+ h && l.isObject(h) && d !== "component" && (b = m(h, b)), i.processedSchemas.value[v][P][c][d] = b, i.stableUpdater(o);
282
275
  } else {
283
- let m = r.processedSchemas.value[u][d];
284
- m && f.isObject(m) && d !== "component" && (y = p(m, y)), r.processedSchemas.value[u][d] = y, r.stableUpdater(i);
276
+ let h = i.processedSchemas.value[c][d];
277
+ h && l.isObject(h) && d !== "component" && (b = m(h, b)), i.processedSchemas.value[c][d] = b, 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
- const n = (a) => {
292
+ const n = (u) => {
300
293
  e.updater({
301
294
  ...e,
302
- key: r,
303
- keyIndex: i,
304
- stable: a
295
+ key: i,
296
+ keyIndex: o,
297
+ stable: u
305
298
  });
306
299
  };
307
- f.isFunction(t[r]) ? r !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
308
- if (r === "component") {
309
- const a = t[r](this.getRuntimeMeta());
310
- this.promiseFieldParser(a, n, !1);
300
+ l.isFunction(t[i]) ? i !== "defaultValue" ? this.schemaEffect.trackEffect(() => {
301
+ if (i === "component") {
302
+ const u = t[i](this.getRuntimeMeta());
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
- const a = this.schemaEffect.trackEffect(() => {
315
- /\{\s*model\s*\}/.test(t[r].toString()) ? this.fieldParser(t[r], (u) => {
316
- if (!u)
317
- return n(u);
318
- this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
307
+ const u = this.schemaEffect.trackEffect(() => {
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(u), this.defaultValueEffect.clearEffects(), w(() => {
321
- a();
322
- })) : n(u);
323
- }) : this.fieldParser(t[r], (u) => {
324
- this.defaultValueInprogressMap.set(t[r], u), !f.isProcessInprogress(u) && this.defaultValueInprogressMap.size === this.baseDefaultValueFunctionsLength && Array.from(this.defaultValueInprogressMap.values()).every(
313
+ ) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
314
+ u();
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(u), this.defaultValueEffect.clearEffects(), w(() => {
327
- a();
328
- })) : n(u);
319
+ ) ? (n(c), this.defaultValueEffect.clearEffects(), w(() => {
320
+ u();
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 = F(r, "")), s && f.isObject(r) ? this.objectParser({
338
- data: r,
329
+ l.isPromise(e) ? e.then((i) => {
330
+ l.isString(i) && (i = q(i, "")), s && l.isObject(i) ? this.objectParser({
331
+ data: i,
339
332
  updater: t
340
- }) : t(r);
341
- }) : (f.isString(e) && (e = F(e, "")), s && f.isObject(e) ? this.objectParser({
333
+ }) : t(i);
334
+ }) : (l.isString(e) && (e = q(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
- N(e) ? v(
354
+ U(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
- ) : R(e) ? v(
366
+ ) : x(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,49 +383,89 @@ 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 = b(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);
401
394
  }
402
395
  }
403
- function fe(o) {
404
- return typeof o == "function" || Object.prototype.toString.call(o) === "[object Object]" && !ie(o);
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
+ }
405
415
  }
406
- class ue {
416
+ class fe {
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 = j.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 = j.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 = j.adapters[this.ui];
433
+ return (e == null ? void 0 : e.getFormModelPropName()) ?? (t == null ? void 0 : t.getFormModelPropName());
434
+ }
435
+ }
436
+ function de(r) {
437
+ return typeof r == "function" || Object.prototype.toString.call(r) === "[object Object]" && !le(r);
438
+ }
439
+ class pe {
407
440
  constructor(e) {
408
- l(this, "schemas", M([]));
409
- l(this, "model", M({}));
410
- l(this, "processorBySchemaType", {
441
+ a(this, "schemas", R([]));
442
+ a(this, "model", R({}));
443
+ a(this, "processorBySchemaType", {
411
444
  item: this.runtimeItemProcessor.bind(this),
412
445
  group: this.runtimeGroupProcessor.bind(this),
413
446
  list: this.runtimeListProcessor.bind(this)
414
447
  });
415
- l(this, "formRef", M(null));
416
- l(this, "hydrateEffect", new D());
417
- l(this, "native", se({}));
418
- l(this, "gridProps", {});
419
- l(this, "runtimeSetters", {});
420
- l(this, "globalNativeFormOverride", {
448
+ a(this, "formRef", R(null));
449
+ a(this, "hydrateEffect", new N());
450
+ a(this, "native", oe({}));
451
+ a(this, "grid", {});
452
+ a(this, "runtime", {});
453
+ a(this, "globalNativeFormOverride", {
421
454
  props: {},
422
455
  slots: {}
423
456
  });
424
- this.setup = e, this.processor = new le(this);
457
+ this.setup = e, this.processor = new ce(this);
425
458
  const t = this.setup(this);
426
- if (N(t.schemas)) {
427
- const s = v(() => t.schemas, () => {
459
+ if (this.ui = t.ui ?? f.presets.ui, this.runtimeAdapter = new fe(this.ui), U(t.schemas)) {
460
+ const s = I(() => t.schemas, () => {
428
461
  this.processor.parseSchemas(t.schemas.value), w(() => {
429
462
  s();
430
463
  });
431
464
  }, {
432
465
  deep: !0
433
466
  });
434
- } else if (R(t.schemas)) {
435
- const s = v(() => t.schemas, () => {
467
+ } else if (x(t.schemas)) {
468
+ const s = I(() => t.schemas, () => {
436
469
  this.processor.parseSchemas(t.schemas), w(() => {
437
470
  s();
438
471
  });
@@ -444,60 +477,55 @@ class ue {
444
477
  }
445
478
  getRuntimeMeta() {
446
479
  return {
447
- model: O(b(this.model.value))
480
+ model: V(g(this.model.value))
448
481
  };
449
482
  }
450
- runtimeItemProcessor(e, t, s = this.model.value, r) {
451
- var _, k, L, z, q, $, B, T, G, K, W, H, J, Q, X;
452
- p(this.globalNativeFormOverride.props, (k = (_ = e.native) == null ? void 0 : _.props) == null ? void 0 : k.Form), p(this.globalNativeFormOverride.slots, (z = (L = e.native) == null ? void 0 : L.slots) == null ? void 0 : z.Form);
453
- const i = p(b(($ = (q = this.native) == null ? void 0 : q.props) == null ? void 0 : $.FormItem) ?? {}, (T = (B = e.native) == null ? void 0 : B.props) == null ? void 0 : T.FormItem), n = p(b((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), a = {
483
+ runtimeItemProcessor(e, t, s = this.model.value, i) {
484
+ var k, z, _, $, B, D, G, T, K, W, H, J, Q;
485
+ const o = V(e.component);
486
+ if (!o)
487
+ return;
488
+ m(this.globalNativeFormOverride.props, (z = (k = e.native) == null ? void 0 : k.props) == null ? void 0 : z.Form), m(this.globalNativeFormOverride.slots, ($ = (_ = e.native) == null ? void 0 : _.slots) == null ? void 0 : $.Form);
489
+ const n = m(g((D = (B = this.native) == null ? void 0 : B.slots) == null ? void 0 : D.FormItem) ?? {}, (T = (G = e.native) == null ? void 0 : G.slots) == null ? void 0 : T.FormItem), u = {
454
490
  display: "grid",
455
491
  gridColumn: "1 / -1",
456
- ...e.gridProps
457
- }, u = r ? `${r.field}.${t}.${e.field}` : e.field, d = O(e.component);
458
- if (!d)
459
- return;
460
- const C = d.name, A = e.componentProps ?? {}, I = V.placeholderPresetByComponentName;
461
- let P = e.placeholder;
462
- const y = e.required;
463
- let m = e.show;
464
- m === void 0 && (m = !0), m || delete s[e.field];
465
- let S = e.label;
466
- const j = (r == null ? void 0 : r.runtimeSetters) ?? this.runtimeSetters;
467
- if (!f.isUndefined(t) && !f.isObjectEmpty(j) && (S = F((J = j == null ? void 0 : j.listItemLabelSetter) == null ? void 0 : J.call(j, e.label, t + 1), ""), P = `${// @ts-expect-error
468
- I[C] ?? "请输入"}${S}`), P || (P = `${// @ts-expect-error
469
- I[C] ?? "请输入"}${S}`), y)
470
- if (!e.rules)
471
- e.rules = [], (Q = e.rules) == null || Q.push({
472
- required: !0,
473
- message: `${S}是必填项`
474
- });
475
- else {
476
- const h = e.rules.findIndex((x) => !f.isUndefined(x.required));
477
- h !== -1 && (e.rules[h].required = !0, e.rules[h].message = `${S}是必填项`);
478
- }
479
- else if (e.rules) {
480
- const h = (X = e.rules) == null ? void 0 : X.findIndex((x) => !!x.required);
481
- h !== -1 && (e.rules[h].required = !1);
492
+ ...e.grid
493
+ }, c = m(g((W = (K = this.native) == null ? void 0 : K.props) == null ? void 0 : W.FormItem) ?? {}, (J = (H = e.native) == null ? void 0 : H.props) == null ? void 0 : J.FormItem), d = this.runtimeAdapter.getRuntimeField({
494
+ schema: e,
495
+ parentSchema: i,
496
+ index: t
497
+ }), y = o.name, O = e.componentProps ?? {}, v = j.placeholderPresetByComponentName;
498
+ let P = e.placeholder, b = e.show;
499
+ b === void 0 && (b = !0), b || delete s[e.field];
500
+ let h = e.label;
501
+ const E = (i == null ? void 0 : i.runtime) ?? this.runtime;
502
+ if (!l.isUndefined(t) && !l.isObjectEmpty(E) && (h = q((Q = E == null ? void 0 : E.customizeItemLabel) == null ? void 0 : Q.call(E, e.label ?? "", t + 1), "")), !P) {
503
+ let C = "请输入";
504
+ l.isUndefined(y) ? P = `${C}${h}` : /* @ts-expect-error */ v[y.toLowerCase()] ? (C = // @ts-expect-error
505
+ v[y.toLowerCase()], P = `${C}${h}`) : (Object.keys(v).forEach((X) => {
506
+ y.toLowerCase().includes(X.toLowerCase()) && (C = v[X]);
507
+ }), P = `${C}${h}`);
482
508
  }
483
- return c("div", {
484
- style: a
485
- }, [c(g.runtimeDoms.Item, null, {
509
+ const ee = this.runtimeAdapter.getRuntimeRequired({
510
+ ...e,
511
+ label: h
512
+ }), te = F.getItemContainer(this), se = F.getFormItemContainer(this);
513
+ return p("div", {
514
+ style: u
515
+ }, [p(te, null, {
486
516
  default() {
487
- return Y(c(g.runtimeDoms.FormItem, U(i, {
488
- label: `${S}:`,
489
- rules: e.rules,
490
- field: u
491
- }), {
517
+ return Y(p(se, M(c, {
518
+ label: `${h}:`
519
+ }, d, ee), {
492
520
  default() {
493
- return c(d, U({
521
+ return p(o, M({
494
522
  modelValue: s[e.field],
495
- "onUpdate:modelValue": (h) => s[e.field] = h,
523
+ "onUpdate:modelValue": (C) => s[e.field] = C,
496
524
  placeholder: P
497
- }, A), null);
525
+ }, O), null);
498
526
  },
499
527
  ...n
500
- }), [[Z, m]]);
528
+ }), [[Z, b]]);
501
529
  }
502
530
  })]);
503
531
  }
@@ -506,13 +534,13 @@ class ue {
506
534
  const s = {
507
535
  display: "grid",
508
536
  gridColumn: "1 / -1",
509
- ...e.gridProps
510
- };
511
- return c("div", {
537
+ ...e.grid
538
+ }, i = F.getGroupContainer(this);
539
+ return p("div", {
512
540
  style: s
513
- }, [c(g.runtimeDoms.Group, {
541
+ }, [p(i, {
514
542
  schema: e
515
- }, fe(t = e.children.map((r) => this.runtimeItemProcessor(r))) ? t : {
543
+ }, de(t = e.children.map((o) => this.runtimeItemProcessor(o))) ? t : {
516
544
  default: () => [t]
517
545
  })]);
518
546
  }
@@ -523,7 +551,7 @@ class ue {
523
551
  code: "0001",
524
552
  message: "异步默认值数据正在处理中,请您耐心等待... "
525
553
  });
526
- (s = this.processor.stableModel[e.field]) != null && s[0] && this.model.value[e.field].push(b(this.processor.stableModel[e.field][0])), this.formRef.value.clearValidate();
554
+ (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();
527
555
  }
528
556
  deleteListItem(e, t) {
529
557
  this.model.value[e.field].splice(t, 1), this.formRef.value.clearValidate();
@@ -532,34 +560,36 @@ class ue {
532
560
  const t = {
533
561
  display: "grid",
534
562
  gridColumn: "1 / -1",
535
- ...e.gridProps
563
+ ...e.grid
536
564
  }, s = this;
537
- return s.model.value[e.field] || (s.model.value[e.field] = [{}]), c("div", {
565
+ s.model.value[e.field] || (s.model.value[e.field] = [{}]);
566
+ const i = F.getListContainer(this), o = F.getListItemContainer(this);
567
+ return p("div", {
538
568
  style: t
539
- }, [c(g.runtimeDoms.List, {
569
+ }, [p(i, {
540
570
  schema: e
541
571
  }, {
542
572
  default() {
543
- return s.model.value[e.field].map((r, i) => c(g.runtimeDoms.ListItem, null, {
573
+ return s.model.value[e.field].map((n, u) => p(o, null, {
544
574
  default() {
545
- return e.children.map((n) => s.runtimeItemProcessor(n, i, r, e));
575
+ return e.children.map((c) => s.runtimeItemProcessor(c, u, n, e));
546
576
  },
547
577
  delete({
548
- container: n
578
+ container: c
549
579
  } = {}) {
550
- var u;
551
- let a = n ?? c("button", null, null);
552
- return Y(c(a, {
553
- onClick: () => s.deleteListItem(e, i)
554
- }, null), [[Z, ((u = s.model.value[e.field]) == null ? void 0 : u.length) > 1]]);
580
+ var y;
581
+ let d = c ?? p("button", null, null);
582
+ return Y(p(d, {
583
+ onClick: () => s.deleteListItem(e, u)
584
+ }, null), [[Z, ((y = s.model.value[e.field]) == null ? void 0 : y.length) > 1]]);
555
585
  }
556
586
  }));
557
587
  },
558
588
  add({
559
- container: r
589
+ container: n
560
590
  } = {}) {
561
- let i = r ?? c("button", null, [re("添加")]);
562
- return c(i, {
591
+ let u = n ?? p("button", null, [ne("添加")]);
592
+ return p(u, {
563
593
  onClick: () => s.addListItem(e)
564
594
  }, null);
565
595
  }
@@ -569,43 +599,137 @@ class ue {
569
599
  return e.map((t) => (t.type || (t.type = "item"), this.processorBySchemaType[t.type](t)));
570
600
  }
571
601
  exec() {
572
- var i, n, a, u;
602
+ var u, c, d, y;
573
603
  const e = {
574
604
  display: "grid",
575
605
  gridColumn: "1 / -1",
576
606
  gridAutoColumns: "1fr",
577
- ...this.gridProps
578
- }, t = this, s = p(b((n = (i = this.native) == null ? void 0 : i.props) == null ? void 0 : n.Form) ?? {}, this.globalNativeFormOverride.props), r = p(b((u = (a = this.native) == null ? void 0 : a.slots) == null ? void 0 : u.Form) ?? {}, this.globalNativeFormOverride.slots);
579
- return c(g.runtimeDoms.Form, U(s, {
580
- ref: this.formRef,
581
- model: this.model.value
607
+ ...this.grid
608
+ }, 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();
609
+ return p(o, M(s, {
610
+ ref: this.formRef
611
+ }, {
612
+ [n]: this.model.value
582
613
  }), {
583
614
  default() {
584
- return c("div", {
615
+ return p("div", {
585
616
  style: e
586
617
  }, [t.runtimeProcessor(t.schemas.value)]);
587
618
  },
588
- ...r
619
+ ...i
589
620
  });
590
621
  }
591
622
  }
592
- class g {
623
+ class f {
624
+ }
625
+ a(f, "presets");
626
+ function A({ parentSchema: r, schema: e, index: t }) {
627
+ return r ? `${r.field}.${t}.${e.field}` : e.field;
593
628
  }
594
- l(g, "runtimeDoms");
595
- const E = class E {
629
+ const he = {
630
+ ArcoVue: {
631
+ getRuntimeField(r) {
632
+ return {
633
+ field: A(r)
634
+ };
635
+ },
636
+ getRuntimeRequired(r) {
637
+ var e, t;
638
+ if (r.required)
639
+ if (!r.rules)
640
+ r.rules = [], (e = r.rules) == null || e.push({
641
+ required: !0,
642
+ message: `${r.label}是必填项`
643
+ });
644
+ else {
645
+ const s = r.rules.findIndex(
646
+ (i) => !l.isUndefined(i.required)
647
+ );
648
+ s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
649
+ }
650
+ else if (r.rules) {
651
+ const s = (t = r.rules) == null ? void 0 : t.findIndex(
652
+ (i) => !!i.required
653
+ );
654
+ s !== -1 && (r.rules[s].required = !1);
655
+ }
656
+ return {
657
+ rules: r.rules
658
+ };
659
+ },
660
+ getFormModelPropName() {
661
+ return "model";
662
+ },
663
+ validateForm(r) {
664
+ return new Promise((e, t) => {
665
+ r.runtimeCore.formRef.value.validate((s) => s ? t(s) : e(
666
+ r.cleanFallbackFields(
667
+ V(r.runtimeCore.processor.processedModel.value)
668
+ )
669
+ ));
670
+ });
671
+ }
672
+ },
673
+ NutUI: {
674
+ getRuntimeField(r) {
675
+ return {
676
+ prop: A(r)
677
+ };
678
+ },
679
+ getRuntimeRequired(r) {
680
+ var e, t;
681
+ if (r.required)
682
+ if (!r.rules)
683
+ r.rules = [], (e = r.rules) == null || e.push({
684
+ required: !0,
685
+ message: `${r.label}是必填项`
686
+ });
687
+ else {
688
+ const s = r.rules.findIndex(
689
+ (i) => !l.isUndefined(i.required)
690
+ );
691
+ s !== -1 && (r.rules[s].required = !0, r.rules[s].message = `${r.label}是必填项`);
692
+ }
693
+ else if (r.rules) {
694
+ const s = (t = r.rules) == null ? void 0 : t.findIndex(
695
+ (i) => !!i.required
696
+ );
697
+ s !== -1 && (r.rules[s].required = !1);
698
+ }
699
+ return {
700
+ rules: r.rules,
701
+ required: r.required
702
+ };
703
+ },
704
+ getFormModelPropName() {
705
+ return "modelValue";
706
+ },
707
+ validateForm(r) {
708
+ return new Promise((e, t) => {
709
+ r.runtimeCore.formRef.value.validate().then(({ valid: s, errors: i }) => {
710
+ s ? e(
711
+ r.cleanFallbackFields(
712
+ V(r.runtimeCore.processor.processedModel.value)
713
+ )
714
+ ) : t(i);
715
+ });
716
+ });
717
+ }
718
+ }
719
+ }, S = class S {
596
720
  static getPlaceholderPrefixPresetByComponentName() {
597
721
  const e = {
598
- 请选择: ["Select", "Tree", "TreeSelect"],
599
- 请输入: ["Input"]
722
+ 请选择: ["select", "tree"],
723
+ 请输入: ["input"]
600
724
  }, t = {};
601
725
  for (let s in e)
602
- e[s].forEach((r) => {
603
- t[r] = s;
726
+ e[s].forEach((i) => {
727
+ t[i] = s;
604
728
  });
605
729
  return t;
606
730
  }
607
731
  };
608
- l(E, "schemaPreset", {
732
+ a(S, "schemaPreset", {
609
733
  type: {
610
734
  defaultValue: "item"
611
735
  },
@@ -639,29 +763,38 @@ l(E, "schemaPreset", {
639
763
  children: {
640
764
  defaultValue: []
641
765
  },
642
- native: void 0,
643
- gridProps: void 0
644
- }), l(E, "componentPropsPreset", {
766
+ native: {
767
+ defaultValue: void 0
768
+ },
769
+ grid: {
770
+ default: void 0
771
+ }
772
+ }), a(S, "componentPropsPreset", {
645
773
  options: {
646
774
  defaultValue: []
647
775
  }
648
776
  }), // 基于基本功能提出基本预设
649
- l(E, "placeholderPresetByComponentName", E.getPlaceholderPrefixPresetByComponentName());
650
- let V = E;
651
- const de = /* @__PURE__ */ oe({
777
+ a(S, "placeholderPresetByComponentName", S.getPlaceholderPrefixPresetByComponentName());
778
+ let L = S;
779
+ const j = {
780
+ ...L,
781
+ adapters: {
782
+ ...he
783
+ }
784
+ }, be = /* @__PURE__ */ ae({
652
785
  props: {
653
786
  setup: {
654
787
  type: Function,
655
788
  required: !0
656
789
  }
657
790
  },
658
- setup(o) {
659
- const e = new ue(o.setup);
791
+ setup(r) {
792
+ const e = new pe(r.setup);
660
793
  return () => e.exec();
661
794
  }
662
795
  });
663
- function pe(o) {
664
- const e = new ne(o);
796
+ function Pe(r) {
797
+ const e = new ue(r);
665
798
  return [
666
799
  e.setup.bind(e),
667
800
  {
@@ -670,22 +803,18 @@ function pe(o) {
670
803
  }
671
804
  ];
672
805
  }
673
- function me(o) {
674
- return {
675
- install() {
676
- g.runtimeDoms = o;
677
- }
678
- };
806
+ function ge(r) {
807
+ f.presets = r;
679
808
  }
680
- function he(o, e) {
681
- return e === "raw" && Object.defineProperty(o, "name", {
682
- value: `__proform_raw_${o.name}`,
809
+ function ve(r, e) {
810
+ return e === "raw" && Object.defineProperty(r, "name", {
811
+ value: `__proform_raw_${r.name}`,
683
812
  writable: !0
684
- }), o;
813
+ }), r;
685
814
  }
686
815
  export {
687
- de as ProForm,
688
- pe as useForm,
689
- me as useFormRenderer,
690
- he as useModifiers
816
+ be as ProForm,
817
+ Pe as useForm,
818
+ ge as useFormPresetConfigurer,
819
+ ve as useModifiers
691
820
  };