@vunk/form 0.0.1-alpha.42 → 0.0.1-alpha.44
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/composables/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRef, ref, computed
|
|
1
|
+
import { isRef, ref, computed, unref, inject } from 'vue';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __defProps = Object.defineProperties;
|
|
@@ -27,7 +27,7 @@ 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(() => {
|
|
31
31
|
const keyRecord = {};
|
|
32
32
|
const propRecord = {};
|
|
33
33
|
const idRecord = {};
|
|
@@ -89,288 +89,6 @@ const useSourceManager = (source, opts = {}) => {
|
|
|
89
89
|
];
|
|
90
90
|
};
|
|
91
91
|
|
|
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
|
-
|
|
109
|
-
let activeEffectScope;
|
|
110
|
-
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
111
|
-
if (scope && scope.active) {
|
|
112
|
-
scope.effects.push(effect);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const createDep = (effects) => {
|
|
117
|
-
const dep = new Set(effects);
|
|
118
|
-
dep.w = 0;
|
|
119
|
-
dep.n = 0;
|
|
120
|
-
return dep;
|
|
121
|
-
};
|
|
122
|
-
const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
|
|
123
|
-
const newTracked = (dep) => (dep.n & trackOpBit) > 0;
|
|
124
|
-
const initDepMarkers = ({ deps }) => {
|
|
125
|
-
if (deps.length) {
|
|
126
|
-
for (let i = 0; i < deps.length; i++) {
|
|
127
|
-
deps[i].w |= trackOpBit; // set was tracked
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const finalizeDepMarkers = (effect) => {
|
|
132
|
-
const { deps } = effect;
|
|
133
|
-
if (deps.length) {
|
|
134
|
-
let ptr = 0;
|
|
135
|
-
for (let i = 0; i < deps.length; i++) {
|
|
136
|
-
const dep = deps[i];
|
|
137
|
-
if (wasTracked(dep) && !newTracked(dep)) {
|
|
138
|
-
dep.delete(effect);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
deps[ptr++] = dep;
|
|
142
|
-
}
|
|
143
|
-
// clear bits
|
|
144
|
-
dep.w &= ~trackOpBit;
|
|
145
|
-
dep.n &= ~trackOpBit;
|
|
146
|
-
}
|
|
147
|
-
deps.length = ptr;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
// The number of effects currently being tracked recursively.
|
|
151
|
-
let effectTrackDepth = 0;
|
|
152
|
-
let trackOpBit = 1;
|
|
153
|
-
/**
|
|
154
|
-
* The bitwise track markers support at most 30 levels of recursion.
|
|
155
|
-
* This value is chosen to enable modern JS engines to use a SMI on all platforms.
|
|
156
|
-
* When recursion depth is greater, fall back to using a full cleanup.
|
|
157
|
-
*/
|
|
158
|
-
const maxMarkerBits = 30;
|
|
159
|
-
let activeEffect;
|
|
160
|
-
Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : '');
|
|
161
|
-
Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : '');
|
|
162
|
-
class ReactiveEffect {
|
|
163
|
-
constructor(fn, scheduler = null, scope) {
|
|
164
|
-
this.fn = fn;
|
|
165
|
-
this.scheduler = scheduler;
|
|
166
|
-
this.active = true;
|
|
167
|
-
this.deps = [];
|
|
168
|
-
this.parent = undefined;
|
|
169
|
-
recordEffectScope(this, scope);
|
|
170
|
-
}
|
|
171
|
-
run() {
|
|
172
|
-
if (!this.active) {
|
|
173
|
-
return this.fn();
|
|
174
|
-
}
|
|
175
|
-
let parent = activeEffect;
|
|
176
|
-
let lastShouldTrack = shouldTrack;
|
|
177
|
-
while (parent) {
|
|
178
|
-
if (parent === this) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
parent = parent.parent;
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
this.parent = activeEffect;
|
|
185
|
-
activeEffect = this;
|
|
186
|
-
shouldTrack = true;
|
|
187
|
-
trackOpBit = 1 << ++effectTrackDepth;
|
|
188
|
-
if (effectTrackDepth <= maxMarkerBits) {
|
|
189
|
-
initDepMarkers(this);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
cleanupEffect(this);
|
|
193
|
-
}
|
|
194
|
-
return this.fn();
|
|
195
|
-
}
|
|
196
|
-
finally {
|
|
197
|
-
if (effectTrackDepth <= maxMarkerBits) {
|
|
198
|
-
finalizeDepMarkers(this);
|
|
199
|
-
}
|
|
200
|
-
trackOpBit = 1 << --effectTrackDepth;
|
|
201
|
-
activeEffect = this.parent;
|
|
202
|
-
shouldTrack = lastShouldTrack;
|
|
203
|
-
this.parent = undefined;
|
|
204
|
-
if (this.deferStop) {
|
|
205
|
-
this.stop();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
stop() {
|
|
210
|
-
// stopped while running itself - defer the cleanup
|
|
211
|
-
if (activeEffect === this) {
|
|
212
|
-
this.deferStop = true;
|
|
213
|
-
}
|
|
214
|
-
else if (this.active) {
|
|
215
|
-
cleanupEffect(this);
|
|
216
|
-
if (this.onStop) {
|
|
217
|
-
this.onStop();
|
|
218
|
-
}
|
|
219
|
-
this.active = false;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function cleanupEffect(effect) {
|
|
224
|
-
const { deps } = effect;
|
|
225
|
-
if (deps.length) {
|
|
226
|
-
for (let i = 0; i < deps.length; i++) {
|
|
227
|
-
deps[i].delete(effect);
|
|
228
|
-
}
|
|
229
|
-
deps.length = 0;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
let shouldTrack = true;
|
|
233
|
-
function trackEffects(dep, debuggerEventExtraInfo) {
|
|
234
|
-
let shouldTrack = false;
|
|
235
|
-
if (effectTrackDepth <= maxMarkerBits) {
|
|
236
|
-
if (!newTracked(dep)) {
|
|
237
|
-
dep.n |= trackOpBit; // set newly tracked
|
|
238
|
-
shouldTrack = !wasTracked(dep);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
// Full cleanup mode.
|
|
243
|
-
shouldTrack = !dep.has(activeEffect);
|
|
244
|
-
}
|
|
245
|
-
if (shouldTrack) {
|
|
246
|
-
dep.add(activeEffect);
|
|
247
|
-
activeEffect.deps.push(dep);
|
|
248
|
-
if ((process.env.NODE_ENV !== 'production') && activeEffect.onTrack) {
|
|
249
|
-
activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function triggerEffects(dep, debuggerEventExtraInfo) {
|
|
254
|
-
// spread into array for stabilization
|
|
255
|
-
const effects = isArray(dep) ? dep : [...dep];
|
|
256
|
-
for (const effect of effects) {
|
|
257
|
-
if (effect.computed) {
|
|
258
|
-
triggerEffect(effect, debuggerEventExtraInfo);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
for (const effect of effects) {
|
|
262
|
-
if (!effect.computed) {
|
|
263
|
-
triggerEffect(effect, debuggerEventExtraInfo);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function triggerEffect(effect, debuggerEventExtraInfo) {
|
|
268
|
-
if (effect !== activeEffect || effect.allowRecurse) {
|
|
269
|
-
if ((process.env.NODE_ENV !== 'production') && effect.onTrigger) {
|
|
270
|
-
effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
|
|
271
|
-
}
|
|
272
|
-
if (effect.scheduler) {
|
|
273
|
-
effect.scheduler();
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
effect.run();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function toRaw(observed) {
|
|
281
|
-
const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
|
|
282
|
-
return raw ? toRaw(raw) : observed;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function trackRefValue(ref) {
|
|
286
|
-
if (shouldTrack && activeEffect) {
|
|
287
|
-
ref = toRaw(ref);
|
|
288
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
289
|
-
trackEffects(ref.dep || (ref.dep = createDep()), {
|
|
290
|
-
target: ref,
|
|
291
|
-
type: "get" /* TrackOpTypes.GET */,
|
|
292
|
-
key: 'value'
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
trackEffects(ref.dep || (ref.dep = createDep()));
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function triggerRefValue(ref, newVal) {
|
|
301
|
-
ref = toRaw(ref);
|
|
302
|
-
if (ref.dep) {
|
|
303
|
-
if ((process.env.NODE_ENV !== 'production')) {
|
|
304
|
-
triggerEffects(ref.dep, {
|
|
305
|
-
target: ref,
|
|
306
|
-
type: "set" /* TriggerOpTypes.SET */,
|
|
307
|
-
key: 'value',
|
|
308
|
-
newValue: newVal
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
triggerEffects(ref.dep);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
var _a;
|
|
318
|
-
class ComputedRefImpl {
|
|
319
|
-
constructor(getter, _setter, isReadonly, isSSR) {
|
|
320
|
-
this._setter = _setter;
|
|
321
|
-
this.dep = undefined;
|
|
322
|
-
this.__v_isRef = true;
|
|
323
|
-
this[_a] = false;
|
|
324
|
-
this._dirty = true;
|
|
325
|
-
this.effect = new ReactiveEffect(getter, () => {
|
|
326
|
-
if (!this._dirty) {
|
|
327
|
-
this._dirty = true;
|
|
328
|
-
triggerRefValue(this);
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
this.effect.computed = this;
|
|
332
|
-
this.effect.active = this._cacheable = !isSSR;
|
|
333
|
-
this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
|
|
334
|
-
}
|
|
335
|
-
get value() {
|
|
336
|
-
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
|
|
337
|
-
const self = toRaw(this);
|
|
338
|
-
trackRefValue(self);
|
|
339
|
-
if (self._dirty || !self._cacheable) {
|
|
340
|
-
self._dirty = false;
|
|
341
|
-
self._value = self.effect.run();
|
|
342
|
-
}
|
|
343
|
-
return self._value;
|
|
344
|
-
}
|
|
345
|
-
set value(newValue) {
|
|
346
|
-
this._setter(newValue);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
_a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
|
|
350
|
-
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
351
|
-
let getter;
|
|
352
|
-
let setter;
|
|
353
|
-
const onlyGetter = isFunction(getterOrOptions);
|
|
354
|
-
if (onlyGetter) {
|
|
355
|
-
getter = getterOrOptions;
|
|
356
|
-
setter = (process.env.NODE_ENV !== 'production')
|
|
357
|
-
? () => {
|
|
358
|
-
console.warn('Write operation failed: computed value is readonly');
|
|
359
|
-
}
|
|
360
|
-
: NOOP;
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
getter = getterOrOptions.get;
|
|
364
|
-
setter = getterOrOptions.set;
|
|
365
|
-
}
|
|
366
|
-
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
367
|
-
if ((process.env.NODE_ENV !== 'production') && debugOptions && !isSSR) {
|
|
368
|
-
cRef.effect.onTrack = debugOptions.onTrack;
|
|
369
|
-
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
370
|
-
}
|
|
371
|
-
return cRef;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
92
|
const useForm = () => {
|
|
375
93
|
return inject("vkfFormVm", null);
|
|
376
94
|
};
|
package/index.css
CHANGED