@vunk/form 0.0.1-alpha.21 → 0.0.1-alpha.23

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.
Files changed (53) hide show
  1. package/components/button/src/ctx.d.ts +4 -0
  2. package/components/button/src/index.vue.d.ts +10 -0
  3. package/components/checkbox/index.css +38 -0
  4. package/components/checkbox/index.js +13 -4
  5. package/components/checkbox/src/ctx.d.ts +4 -0
  6. package/components/checkbox/src/index.vue.d.ts +18 -8
  7. package/components/color-picker/src/ctx.d.ts +4 -0
  8. package/components/color-picker/src/index.vue.d.ts +13 -3
  9. package/components/date-picker/index.js +11 -5
  10. package/components/date-picker/src/ctx.d.ts +45 -42
  11. package/components/date-picker/src/ctx.js +1 -1
  12. package/components/date-picker/src/index.vue.d.ts +102 -96
  13. package/components/form/index.js +14 -5
  14. package/components/form/src/ctx.d.ts +4 -1
  15. package/components/form/src/ctx.js +5 -2
  16. package/components/form/src/index.vue.d.ts +7 -0
  17. package/components/form-item/index.js +9 -1
  18. package/components/form-item/src/ctx.d.ts +5 -1
  19. package/components/form-item/src/ctx.js +4 -0
  20. package/components/form-item/src/index.vue.d.ts +10 -0
  21. package/components/input/index.js +7 -4
  22. package/components/input/src/ctx.d.ts +46 -43
  23. package/components/input/src/ctx.js +1 -1
  24. package/components/input/src/index.vue.d.ts +96 -90
  25. package/components/input-number/index.css +14 -0
  26. package/components/input-number/index.js +12 -3
  27. package/components/input-number/src/ctx.d.ts +4 -0
  28. package/components/input-number/src/index.vue.d.ts +19 -9
  29. package/components/radio/index.css +29 -0
  30. package/components/radio/index.js +13 -4
  31. package/components/radio/src/ctx.d.ts +4 -0
  32. package/components/radio/src/index.vue.d.ts +15 -5
  33. package/components/select/index.css +11 -0
  34. package/components/select/index.js +12 -4
  35. package/components/select/src/ctx.d.ts +4 -0
  36. package/components/select/src/index.vue.d.ts +33 -23
  37. package/components/switch/index.css +11 -0
  38. package/components/switch/index.js +15 -4
  39. package/components/switch/src/ctx.d.ts +4 -0
  40. package/components/switch/src/index.vue.d.ts +14 -4
  41. package/components/upload/index.css +10 -0
  42. package/components/upload/index.js +14 -6
  43. package/components/upload/src/ctx.d.ts +4 -0
  44. package/components/upload/src/index.vue.d.ts +11 -1
  45. package/composables/index.d.ts +1 -0
  46. package/composables/index.js +318 -7
  47. package/composables/useForm.d.ts +9 -0
  48. package/composables/useSourceManager.d.ts +2 -0
  49. package/index.css +118 -0
  50. package/package.json +1 -1
  51. package/shared/element-plus/ctx.d.ts +9 -9
  52. package/shared/infer-prop/index.d.ts +16 -0
  53. package/shared/infer-prop/index.js +29 -0
@@ -1,4 +1,4 @@
1
- import { isRef, ref, computed, unref } from 'vue';
1
+ import { isRef, ref, computed as computed$1, unref, inject } from 'vue';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defProps = Object.defineProperties;
@@ -27,9 +27,10 @@ const useSourceManager = (source, opts = {}) => {
27
27
  slotsChildren: ["default"]
28
28
  });
29
29
  opts.slotsChildren && op.slotsChildren.push(...opts.slotsChildren);
30
- const manager = computed(() => {
30
+ const manager = computed$1(() => {
31
31
  const keyRecord = {};
32
32
  const propRecord = {};
33
+ const idRecord = {};
33
34
  function intoData(list, k = []) {
34
35
  list.forEach((item, index) => {
35
36
  const currentK = [...k, index];
@@ -37,12 +38,16 @@ const useSourceManager = (source, opts = {}) => {
37
38
  source: item,
38
39
  key: currentK,
39
40
  nextKey: [...k, index + 1],
40
- prop: item.prop
41
+ prop: item.prop,
42
+ id: item.id
41
43
  };
42
44
  keyRecord[currentK.join()] = managerInfo;
43
45
  if (item.prop) {
44
46
  propRecord[item.prop] = managerInfo;
45
47
  }
48
+ if (item.id) {
49
+ idRecord[item.id] = managerInfo;
50
+ }
46
51
  if (item.templateSlots) {
47
52
  if (Array.isArray(item.templateSlots)) {
48
53
  currentK.push("templateSlots");
@@ -60,23 +65,329 @@ const useSourceManager = (source, opts = {}) => {
60
65
  intoData(unref(source));
61
66
  return {
62
67
  keyRecord,
63
- propRecord
68
+ propRecord,
69
+ idRecord
64
70
  };
65
71
  });
66
72
  const getManagerInfoByProp = (prop) => {
67
73
  return manager.value.propRecord[prop];
68
74
  };
69
75
  const getManagerInfoByKey = (key) => {
70
- return manager.value.propRecord[key.join()];
76
+ return manager.value.keyRecord[key.join()];
77
+ };
78
+ const getManagerInfoById = (id) => {
79
+ return manager.value.idRecord[id];
71
80
  };
72
81
  return [
73
82
  source,
74
83
  {
75
84
  manager,
76
85
  getManagerInfoByProp,
77
- getManagerInfoByKey
86
+ getManagerInfoByKey,
87
+ getManagerInfoById
78
88
  }
79
89
  ];
80
90
  };
81
91
 
82
- export { useSourceManager };
92
+ /**
93
+ * Make a map and return a function for checking if a key
94
+ * is in that map.
95
+ * IMPORTANT: all calls of this function must be prefixed with
96
+ * \/\*#\_\_PURE\_\_\*\/
97
+ * So that rollup can tree-shake them if necessary.
98
+ */
99
+
100
+ (process.env.NODE_ENV !== 'production')
101
+ ? Object.freeze({})
102
+ : {};
103
+ (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
104
+ const NOOP = () => { };
105
+ const extend = Object.assign;
106
+ const isArray = Array.isArray;
107
+ const isFunction = (val) => typeof val === 'function';
108
+ const isSymbol = (val) => typeof val === 'symbol';
109
+
110
+ let activeEffectScope;
111
+ function recordEffectScope(effect, scope = activeEffectScope) {
112
+ if (scope && scope.active) {
113
+ scope.effects.push(effect);
114
+ }
115
+ }
116
+
117
+ const createDep = (effects) => {
118
+ const dep = new Set(effects);
119
+ dep.w = 0;
120
+ dep.n = 0;
121
+ return dep;
122
+ };
123
+ const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
124
+ const newTracked = (dep) => (dep.n & trackOpBit) > 0;
125
+ const initDepMarkers = ({ deps }) => {
126
+ if (deps.length) {
127
+ for (let i = 0; i < deps.length; i++) {
128
+ deps[i].w |= trackOpBit; // set was tracked
129
+ }
130
+ }
131
+ };
132
+ const finalizeDepMarkers = (effect) => {
133
+ const { deps } = effect;
134
+ if (deps.length) {
135
+ let ptr = 0;
136
+ for (let i = 0; i < deps.length; i++) {
137
+ const dep = deps[i];
138
+ if (wasTracked(dep) && !newTracked(dep)) {
139
+ dep.delete(effect);
140
+ }
141
+ else {
142
+ deps[ptr++] = dep;
143
+ }
144
+ // clear bits
145
+ dep.w &= ~trackOpBit;
146
+ dep.n &= ~trackOpBit;
147
+ }
148
+ deps.length = ptr;
149
+ }
150
+ };
151
+ // The number of effects currently being tracked recursively.
152
+ let effectTrackDepth = 0;
153
+ let trackOpBit = 1;
154
+ /**
155
+ * The bitwise track markers support at most 30 levels of recursion.
156
+ * This value is chosen to enable modern JS engines to use a SMI on all platforms.
157
+ * When recursion depth is greater, fall back to using a full cleanup.
158
+ */
159
+ const maxMarkerBits = 30;
160
+ let activeEffect;
161
+ Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : '');
162
+ Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : '');
163
+ class ReactiveEffect {
164
+ constructor(fn, scheduler = null, scope) {
165
+ this.fn = fn;
166
+ this.scheduler = scheduler;
167
+ this.active = true;
168
+ this.deps = [];
169
+ this.parent = undefined;
170
+ recordEffectScope(this, scope);
171
+ }
172
+ run() {
173
+ if (!this.active) {
174
+ return this.fn();
175
+ }
176
+ let parent = activeEffect;
177
+ let lastShouldTrack = shouldTrack;
178
+ while (parent) {
179
+ if (parent === this) {
180
+ return;
181
+ }
182
+ parent = parent.parent;
183
+ }
184
+ try {
185
+ this.parent = activeEffect;
186
+ activeEffect = this;
187
+ shouldTrack = true;
188
+ trackOpBit = 1 << ++effectTrackDepth;
189
+ if (effectTrackDepth <= maxMarkerBits) {
190
+ initDepMarkers(this);
191
+ }
192
+ else {
193
+ cleanupEffect(this);
194
+ }
195
+ return this.fn();
196
+ }
197
+ finally {
198
+ if (effectTrackDepth <= maxMarkerBits) {
199
+ finalizeDepMarkers(this);
200
+ }
201
+ trackOpBit = 1 << --effectTrackDepth;
202
+ activeEffect = this.parent;
203
+ shouldTrack = lastShouldTrack;
204
+ this.parent = undefined;
205
+ if (this.deferStop) {
206
+ this.stop();
207
+ }
208
+ }
209
+ }
210
+ stop() {
211
+ // stopped while running itself - defer the cleanup
212
+ if (activeEffect === this) {
213
+ this.deferStop = true;
214
+ }
215
+ else if (this.active) {
216
+ cleanupEffect(this);
217
+ if (this.onStop) {
218
+ this.onStop();
219
+ }
220
+ this.active = false;
221
+ }
222
+ }
223
+ }
224
+ function cleanupEffect(effect) {
225
+ const { deps } = effect;
226
+ if (deps.length) {
227
+ for (let i = 0; i < deps.length; i++) {
228
+ deps[i].delete(effect);
229
+ }
230
+ deps.length = 0;
231
+ }
232
+ }
233
+ let shouldTrack = true;
234
+ function trackEffects(dep, debuggerEventExtraInfo) {
235
+ let shouldTrack = false;
236
+ if (effectTrackDepth <= maxMarkerBits) {
237
+ if (!newTracked(dep)) {
238
+ dep.n |= trackOpBit; // set newly tracked
239
+ shouldTrack = !wasTracked(dep);
240
+ }
241
+ }
242
+ else {
243
+ // Full cleanup mode.
244
+ shouldTrack = !dep.has(activeEffect);
245
+ }
246
+ if (shouldTrack) {
247
+ dep.add(activeEffect);
248
+ activeEffect.deps.push(dep);
249
+ if ((process.env.NODE_ENV !== 'production') && activeEffect.onTrack) {
250
+ activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
251
+ }
252
+ }
253
+ }
254
+ function triggerEffects(dep, debuggerEventExtraInfo) {
255
+ // spread into array for stabilization
256
+ const effects = isArray(dep) ? dep : [...dep];
257
+ for (const effect of effects) {
258
+ if (effect.computed) {
259
+ triggerEffect(effect, debuggerEventExtraInfo);
260
+ }
261
+ }
262
+ for (const effect of effects) {
263
+ if (!effect.computed) {
264
+ triggerEffect(effect, debuggerEventExtraInfo);
265
+ }
266
+ }
267
+ }
268
+ function triggerEffect(effect, debuggerEventExtraInfo) {
269
+ if (effect !== activeEffect || effect.allowRecurse) {
270
+ if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
271
+ effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
272
+ }
273
+ if (effect.scheduler) {
274
+ effect.scheduler();
275
+ }
276
+ else {
277
+ effect.run();
278
+ }
279
+ }
280
+ }
281
+ new Set(
282
+ /*#__PURE__*/
283
+ Object.getOwnPropertyNames(Symbol)
284
+ // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
285
+ // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
286
+ // function
287
+ .filter(key => key !== 'arguments' && key !== 'caller')
288
+ .map(key => Symbol[key])
289
+ .filter(isSymbol));
290
+ function toRaw(observed) {
291
+ const raw = observed && observed["__v_raw" /* RAW */];
292
+ return raw ? toRaw(raw) : observed;
293
+ }
294
+
295
+ function trackRefValue(ref) {
296
+ if (shouldTrack && activeEffect) {
297
+ ref = toRaw(ref);
298
+ if ((process.env.NODE_ENV !== 'production')) {
299
+ trackEffects(ref.dep || (ref.dep = createDep()), {
300
+ target: ref,
301
+ type: "get" /* GET */,
302
+ key: 'value'
303
+ });
304
+ }
305
+ else {
306
+ trackEffects(ref.dep || (ref.dep = createDep()));
307
+ }
308
+ }
309
+ }
310
+ function triggerRefValue(ref, newVal) {
311
+ ref = toRaw(ref);
312
+ if (ref.dep) {
313
+ if ((process.env.NODE_ENV !== 'production')) {
314
+ triggerEffects(ref.dep, {
315
+ target: ref,
316
+ type: "set" /* SET */,
317
+ key: 'value',
318
+ newValue: newVal
319
+ });
320
+ }
321
+ else {
322
+ triggerEffects(ref.dep);
323
+ }
324
+ }
325
+ }
326
+
327
+ class ComputedRefImpl {
328
+ constructor(getter, _setter, isReadonly, isSSR) {
329
+ this._setter = _setter;
330
+ this.dep = undefined;
331
+ this.__v_isRef = true;
332
+ this._dirty = true;
333
+ this.effect = new ReactiveEffect(getter, () => {
334
+ if (!this._dirty) {
335
+ this._dirty = true;
336
+ triggerRefValue(this);
337
+ }
338
+ });
339
+ this.effect.computed = this;
340
+ this.effect.active = this._cacheable = !isSSR;
341
+ this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
342
+ }
343
+ get value() {
344
+ // the computed ref may get wrapped by other proxies e.g. readonly() #3376
345
+ const self = toRaw(this);
346
+ trackRefValue(self);
347
+ if (self._dirty || !self._cacheable) {
348
+ self._dirty = false;
349
+ self._value = self.effect.run();
350
+ }
351
+ return self._value;
352
+ }
353
+ set value(newValue) {
354
+ this._setter(newValue);
355
+ }
356
+ }
357
+ function computed(getterOrOptions, debugOptions, isSSR = false) {
358
+ let getter;
359
+ let setter;
360
+ const onlyGetter = isFunction(getterOrOptions);
361
+ if (onlyGetter) {
362
+ getter = getterOrOptions;
363
+ setter = (process.env.NODE_ENV !== 'production')
364
+ ? () => {
365
+ console.warn('Write operation failed: computed value is readonly');
366
+ }
367
+ : NOOP;
368
+ }
369
+ else {
370
+ getter = getterOrOptions.get;
371
+ setter = getterOrOptions.set;
372
+ }
373
+ const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
374
+ if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
375
+ cRef.effect.onTrack = debugOptions.onTrack;
376
+ cRef.effect.onTrigger = debugOptions.onTrigger;
377
+ }
378
+ return cRef;
379
+ }
380
+
381
+ const useForm = () => {
382
+ return inject("vkfFormVm", null);
383
+ };
384
+ const useComputedReadonly = (props) => {
385
+ const form = useForm();
386
+ const readonly = computed(() => {
387
+ var _a, _b;
388
+ return (_b = (_a = props.readonly) != null ? _a : form == null ? void 0 : form.props.readonly) != null ? _b : false;
389
+ });
390
+ return readonly;
391
+ };
392
+
393
+ export { useComputedReadonly, useForm, useSourceManager };
@@ -0,0 +1,9 @@
1
+ import { ComponentInternalInstance, ComputedRef } from 'vue';
2
+ import { VkfForm } from '@vunk/form/components/form';
3
+ import { VueComponentPropsType } from '@vunk/core';
4
+ export declare const useForm: () => (ComponentInternalInstance & {
5
+ props: VueComponentPropsType<typeof VkfForm>;
6
+ }) | null;
7
+ export declare const useComputedReadonly: (props: {
8
+ readonly?: boolean;
9
+ }) => ComputedRef<boolean>;
@@ -7,7 +7,9 @@ export declare const useSourceManager: <T = FormItemRendererSource<string>>(sour
7
7
  readonly manager: import("vue").ComputedRef<{
8
8
  keyRecord: Record<string, ManagerInfo<T>>;
9
9
  propRecord: Record<string, ManagerInfo<T>>;
10
+ idRecord: Record<string, ManagerInfo<T>>;
10
11
  }>;
11
12
  readonly getManagerInfoByProp: <I = T>(prop: string) => ManagerInfo<I>;
12
13
  readonly getManagerInfoByKey: <I_1 = T>(key: (string | number)[]) => ManagerInfo<I_1>;
14
+ readonly getManagerInfoById: <I_2 = T>(id: string) => ManagerInfo<I_2>;
13
15
  }];
package/index.css CHANGED
@@ -1,4 +1,43 @@
1
1
 
2
+ .el-checkbox-group.is-readonly .el-checkbox,
3
+ .el-checkbox-group.is-readonly{
4
+ --el-readonly-cursor: auto;
5
+ --el-disabled-text-color: var(--el-checkbox-text-color);
6
+ --el-checkbox-disabled-checked-input-fill: var(--el-checkbox-bg-color);
7
+ --el-checkbox-disabled-checked-icon-color: var(--el-checkbox-checked-icon-color);
8
+ }
9
+
10
+
11
+ .el-checkbox-group.is-readonly .el-checkbox__input.is-checked+.el-checkbox__label {
12
+ color: var(--el-checkbox-checked-text-color);
13
+ }
14
+ .el-checkbox-group.is-readonly .el-checkbox__input.is-checked .el-checkbox__inner {
15
+ background-color: var(--el-checkbox-checked-bg-color);
16
+ border-color: var(--el-checkbox-checked-input-border-color);
17
+ }
18
+ .el-checkbox-group.is-readonly .el-checkbox__input.is-disabled+span.el-checkbox__label,
19
+ .el-checkbox-group.is-readonly .el-checkbox__input.is-disabled .el-checkbox__inner {
20
+ cursor: var(--el-readonly-cursor);
21
+ }
22
+
23
+
24
+
25
+ .el-checkbox-group.is-readonly .el-checkbox-button.is-checked:first-child .el-checkbox-button__inner{
26
+ border-left-color: var(--el-checkbox-button-checked-border-color);
27
+ }
28
+
29
+ .el-checkbox-group.is-readonly .el-checkbox-button.is-checked .el-checkbox-button__inner {
30
+ color: var(--el-checkbox-button-checked-text-color);
31
+ background-color: var(--el-checkbox-button-checked-bg-color);
32
+ border-color: var(--el-checkbox-button-checked-border-color);
33
+ box-shadow: -1px 0 0 0 var(--el-color-primary-light-7);
34
+ }
35
+
36
+ .el-checkbox-group.is-readonly .el-checkbox-button.is-disabled .el-checkbox-button__inner{
37
+ cursor: var(--el-readonly-cursor);
38
+ }
39
+
40
+
2
41
  .vkf-form-item--inline{
3
42
  display: inline-flex;
4
43
  }
@@ -11,6 +50,85 @@
11
50
  width: 100%;
12
51
  }
13
52
 
53
+
54
+ .el-input-number.is-readonly{
55
+ --el-readonly-cursor: text;
56
+ --el-disabled-bg-color: initial;
57
+ --el-disabled-text-color: var(--el-input-text-color);
58
+ }
59
+ .el-input-number.is-readonly .el-input-number__decrease,
60
+ .el-input-number.is-readonly .el-input-number__increase{
61
+ display: none;
62
+ }
63
+ .el-input-number.is-readonly .el-input.is-disabled,
64
+ .el-input-number.is-readonly .el-input.is-disabled .el-input__inner{
65
+ cursor: var(--el-readonly-cursor);
66
+ }
67
+
68
+
69
+ .el-radio-group.is-readonly,
70
+ .el-radio-group.is-readonly .el-radio-button{
71
+ --el-readonly-cursor: auto;
72
+ --el-disabled-bg-color: initial;
73
+ --el-disabled-text-color: initial;
74
+ --el-radio-button-disabled-checked-fill: var(--el-radio-button-checked-bg-color);
75
+ }
76
+
77
+ .el-radio-group.is-readonly .is-active .el-radio-button__original-radio:disabled+.el-radio-button__inner{
78
+ color: var(--el-radio-button-checked-text-color);
79
+ }
80
+ .el-radio-group.is-readonly .el-radio-button__original-radio:disabled+.el-radio-button__inner {
81
+ cursor: var(--el-readonly-cursor);
82
+ }
83
+
84
+ .el-radio-group.is-readonly .el-radio__input.is-checked+.el-radio__label{
85
+ color: var(--el-color-primary);
86
+ }
87
+ .el-radio-group.is-readonly .el-radio__input.is-checked .el-radio__inner {
88
+ border-color: var(--el-color-primary);
89
+ background: var(--el-color-primary);
90
+
91
+ }
92
+ .el-radio-group.is-readonly .el-radio__input .el-radio__inner,
93
+ .el-radio-group.is-readonly .el-radio__input.is-disabled+span.el-radio__label {
94
+ cursor: var(--el-readonly-cursor);
95
+ }
96
+
97
+
98
+
99
+ .el-select.is-readonly{
100
+ --el-readonly-cursor: text;
101
+ --el-disabled-bg-color: initial;
102
+ --el-disabled-text-color: var(--el-input-text-color);
103
+ }
104
+ .el-select.is-readonly .el-input.is-disabled .el-input__inner,
105
+ .el-select.is-readonly .el-input.is-disabled .el-select__caret,
106
+ .el-select.is-readonly .el-input.is-disabled .el-input__wrapper{
107
+ cursor: var(--el-readonly-cursor);
108
+ }
109
+
110
+
111
+ .el-switch.is-readonly{
112
+ --el-readonly-cursor: auto;
113
+ }
114
+ .el-switch.is-readonly.is-readonly{
115
+ opacity: .9;
116
+ }
117
+ .el-switch.is-readonly.is-readonly .el-switch__core,
118
+ .el-switch.is-readonly.is-readonly .el-switch__label{
119
+ cursor: var(--el-readonly-cursor);
120
+ }
121
+
122
+
123
+
124
+ .vkf-upload.is-readonly .el-upload,
125
+ .vkf-upload.is-readonly .el-upload{
126
+ display: none;
127
+ }
128
+ .vkf-upload .el-upload-list{
129
+ min-width: 100px;
130
+ }
131
+
14
132
 
15
133
  .el-upload-list__item-status-label{
16
134
  z-index: 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/form",
3
- "version": "0.0.1-alpha.21",
3
+ "version": "0.0.1-alpha.23",
4
4
  "description": "",
5
5
  "main": "index.esm.js",
6
6
  "scripts": {