@vunk/form 0.0.1-alpha.39 → 0.0.1-alpha.40

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.
@@ -89,293 +89,286 @@ 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
- */
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
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';
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';
109
108
 
110
- let activeEffectScope;
111
- function recordEffectScope(effect, scope = activeEffectScope) {
112
- if (scope && scope.active) {
113
- scope.effects.push(effect);
114
- }
115
- }
109
+ let activeEffectScope;
110
+ function recordEffectScope(effect, scope = activeEffectScope) {
111
+ if (scope && scope.active) {
112
+ scope.effects.push(effect);
113
+ }
114
+ }
116
115
 
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
- }
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
+ }
150
149
  };
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
- }
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;
280
283
  }
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
284
 
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
- }
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
+ }
326
316
 
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;
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;
379
372
  }
380
373
 
381
374
  const useForm = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/form",
3
- "version": "0.0.1-alpha.39",
3
+ "version": "0.0.1-alpha.40",
4
4
  "description": "",
5
5
  "main": "index.esm.js",
6
6
  "scripts": {