tutuca 0.10.0 → 0.11.0

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 (48) hide show
  1. package/README.md +14 -14
  2. package/dist/immer.js +1261 -0
  3. package/dist/tutuca-cli.js +1603 -4573
  4. package/dist/tutuca-components.js +194 -424
  5. package/dist/tutuca-dev.ext.js +483 -757
  6. package/dist/tutuca-dev.js +1172 -4999
  7. package/dist/tutuca-dev.min.js +3 -3
  8. package/dist/tutuca-extra.ext.js +460 -547
  9. package/dist/tutuca-extra.js +1136 -4790
  10. package/dist/tutuca-extra.min.js +2 -2
  11. package/dist/tutuca-storybook.js +152 -143
  12. package/dist/tutuca.ext.js +460 -547
  13. package/dist/tutuca.js +1136 -4790
  14. package/dist/tutuca.min.js +2 -2
  15. package/package.json +7 -11
  16. package/skill/tutuca/SKILL.md +0 -4
  17. package/skill/tutuca/advanced.md +12 -4
  18. package/skill/tutuca/cli.md +8 -9
  19. package/skill/tutuca/component-design.md +18 -19
  20. package/skill/tutuca/core.md +83 -81
  21. package/skill/tutuca/iteration.md +2 -2
  22. package/skill/tutuca/macros.md +1 -1
  23. package/skill/tutuca/messages-and-intents.md +24 -23
  24. package/skill/tutuca/patterns/bind-text-and-attributes.md +1 -1
  25. package/skill/tutuca/patterns/conditional-attribute-value.md +1 -1
  26. package/skill/tutuca/patterns/coordinate-components.md +10 -8
  27. package/skill/tutuca/patterns/file-input.md +6 -6
  28. package/skill/tutuca/patterns/filter-and-paginate.md +1 -1
  29. package/skill/tutuca/patterns/handle-events.md +10 -8
  30. package/skill/tutuca/patterns/switch-between-views.md +1 -1
  31. package/skill/tutuca/patterns/tabbed-interface.md +10 -5
  32. package/skill/tutuca/testing.md +37 -28
  33. package/skill/tutuca-source/tutuca.ext.js +460 -547
  34. package/dist/immutable.js +0 -4331
  35. package/skill/immutable-js/SKILL.md +0 -78
  36. package/skill/immutable-js/references/collection.md +0 -346
  37. package/skill/immutable-js/references/conversions.md +0 -99
  38. package/skill/immutable-js/references/deep-updates.md +0 -172
  39. package/skill/immutable-js/references/equality.md +0 -95
  40. package/skill/immutable-js/references/list.md +0 -266
  41. package/skill/immutable-js/references/map.md +0 -300
  42. package/skill/immutable-js/references/predicates.md +0 -93
  43. package/skill/immutable-js/references/range-repeat.md +0 -55
  44. package/skill/immutable-js/references/record.md +0 -196
  45. package/skill/immutable-js/references/seq.md +0 -248
  46. package/skill/immutable-js/references/set.md +0 -270
  47. package/skill/immutable-js/references/shallow-functional.md +0 -99
  48. package/skill/immutable-js/references/stack.md +0 -210
package/dist/immer.js ADDED
@@ -0,0 +1,1261 @@
1
+ // node_modules/immer/dist/immer.mjs
2
+ var NOTHING = /* @__PURE__ */ Symbol.for("immer-nothing");
3
+ var DRAFTABLE = /* @__PURE__ */ Symbol.for("immer-draftable");
4
+ var DRAFT_STATE = /* @__PURE__ */ Symbol.for("immer-state");
5
+ var errors = true ? [
6
+ // All error codes, starting by 0:
7
+ function(plugin) {
8
+ return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
9
+ },
10
+ function(thing) {
11
+ return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
12
+ },
13
+ "This object has been frozen and should not be mutated",
14
+ function(data) {
15
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
16
+ },
17
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
18
+ "Immer forbids circular references",
19
+ "The first or second argument to `produce` must be a function",
20
+ "The third argument to `produce` must be a function or undefined",
21
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
22
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
23
+ function(thing) {
24
+ return `'current' expects a draft, got: ${thing}`;
25
+ },
26
+ "Object.defineProperty() cannot be used on an Immer draft",
27
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
28
+ "Immer only supports deleting array indices",
29
+ "Immer only supports setting array indices and the 'length' property",
30
+ function(thing) {
31
+ return `'original' expects a draft, got: ${thing}`;
32
+ }
33
+ // Note: if more errors are added, the errorOffset in Patches.ts should be increased
34
+ // See Patches.ts for additional errors
35
+ ] : [];
36
+ function die(error, ...args) {
37
+ if (true) {
38
+ const e = errors[error];
39
+ const msg = typeof e === "function" ? e.apply(null, args) : e;
40
+ throw new Error(`[Immer] ${msg}`);
41
+ }
42
+ throw new Error(
43
+ `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
44
+ );
45
+ }
46
+ var getPrototypeOf = Object.getPrototypeOf;
47
+ function isDraft(value) {
48
+ return !!value && !!value[DRAFT_STATE];
49
+ }
50
+ function isDraftable(value) {
51
+ if (!value)
52
+ return false;
53
+ return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
54
+ }
55
+ var objectCtorString = Object.prototype.constructor.toString();
56
+ var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
57
+ function isPlainObject(value) {
58
+ if (!value || typeof value !== "object")
59
+ return false;
60
+ const proto = Object.getPrototypeOf(value);
61
+ if (proto === null || proto === Object.prototype)
62
+ return true;
63
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
64
+ if (Ctor === Object)
65
+ return true;
66
+ if (typeof Ctor !== "function")
67
+ return false;
68
+ let ctorString = cachedCtorStrings.get(Ctor);
69
+ if (ctorString === void 0) {
70
+ ctorString = Function.toString.call(Ctor);
71
+ cachedCtorStrings.set(Ctor, ctorString);
72
+ }
73
+ return ctorString === objectCtorString;
74
+ }
75
+ function original(value) {
76
+ if (!isDraft(value))
77
+ die(15, value);
78
+ return value[DRAFT_STATE].base_;
79
+ }
80
+ function each(obj, iter, strict = true) {
81
+ if (getArchtype(obj) === 0) {
82
+ const keys = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
83
+ keys.forEach((key) => {
84
+ iter(key, obj[key], obj);
85
+ });
86
+ } else {
87
+ obj.forEach((entry, index) => iter(index, entry, obj));
88
+ }
89
+ }
90
+ function getArchtype(thing) {
91
+ const state = thing[DRAFT_STATE];
92
+ return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
93
+ }
94
+ function has(thing, prop) {
95
+ return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
96
+ }
97
+ function get(thing, prop) {
98
+ return getArchtype(thing) === 2 ? thing.get(prop) : thing[prop];
99
+ }
100
+ function set(thing, propOrOldValue, value) {
101
+ const t = getArchtype(thing);
102
+ if (t === 2)
103
+ thing.set(propOrOldValue, value);
104
+ else if (t === 3) {
105
+ thing.add(value);
106
+ } else
107
+ thing[propOrOldValue] = value;
108
+ }
109
+ function is(x, y) {
110
+ if (x === y) {
111
+ return x !== 0 || 1 / x === 1 / y;
112
+ } else {
113
+ return x !== x && y !== y;
114
+ }
115
+ }
116
+ function isMap(target) {
117
+ return target instanceof Map;
118
+ }
119
+ function isSet(target) {
120
+ return target instanceof Set;
121
+ }
122
+ function latest(state) {
123
+ return state.copy_ || state.base_;
124
+ }
125
+ function shallowCopy(base, strict) {
126
+ if (isMap(base)) {
127
+ return new Map(base);
128
+ }
129
+ if (isSet(base)) {
130
+ return new Set(base);
131
+ }
132
+ if (Array.isArray(base))
133
+ return Array.prototype.slice.call(base);
134
+ const isPlain = isPlainObject(base);
135
+ if (strict === true || strict === "class_only" && !isPlain) {
136
+ const descriptors = Object.getOwnPropertyDescriptors(base);
137
+ delete descriptors[DRAFT_STATE];
138
+ let keys = Reflect.ownKeys(descriptors);
139
+ for (let i = 0; i < keys.length; i++) {
140
+ const key = keys[i];
141
+ const desc = descriptors[key];
142
+ if (desc.writable === false) {
143
+ desc.writable = true;
144
+ desc.configurable = true;
145
+ }
146
+ if (desc.get || desc.set)
147
+ descriptors[key] = {
148
+ configurable: true,
149
+ writable: true,
150
+ // could live with !!desc.set as well here...
151
+ enumerable: desc.enumerable,
152
+ value: base[key]
153
+ };
154
+ }
155
+ return Object.create(getPrototypeOf(base), descriptors);
156
+ } else {
157
+ const proto = getPrototypeOf(base);
158
+ if (proto !== null && isPlain) {
159
+ return { ...base };
160
+ }
161
+ const obj = Object.create(proto);
162
+ return Object.assign(obj, base);
163
+ }
164
+ }
165
+ function freeze(obj, deep = false) {
166
+ if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
167
+ return obj;
168
+ if (getArchtype(obj) > 1) {
169
+ Object.defineProperties(obj, {
170
+ set: dontMutateMethodOverride,
171
+ add: dontMutateMethodOverride,
172
+ clear: dontMutateMethodOverride,
173
+ delete: dontMutateMethodOverride
174
+ });
175
+ }
176
+ Object.freeze(obj);
177
+ if (deep)
178
+ Object.values(obj).forEach((value) => freeze(value, true));
179
+ return obj;
180
+ }
181
+ function dontMutateFrozenCollections() {
182
+ die(2);
183
+ }
184
+ var dontMutateMethodOverride = {
185
+ value: dontMutateFrozenCollections
186
+ };
187
+ function isFrozen(obj) {
188
+ if (obj === null || typeof obj !== "object")
189
+ return true;
190
+ return Object.isFrozen(obj);
191
+ }
192
+ var plugins = {};
193
+ function getPlugin(pluginKey) {
194
+ const plugin = plugins[pluginKey];
195
+ if (!plugin) {
196
+ die(0, pluginKey);
197
+ }
198
+ return plugin;
199
+ }
200
+ function loadPlugin(pluginKey, implementation) {
201
+ if (!plugins[pluginKey])
202
+ plugins[pluginKey] = implementation;
203
+ }
204
+ var currentScope;
205
+ function getCurrentScope() {
206
+ return currentScope;
207
+ }
208
+ function createScope(parent_, immer_) {
209
+ return {
210
+ drafts_: [],
211
+ parent_,
212
+ immer_,
213
+ // Whenever the modified draft contains a draft from another scope, we
214
+ // need to prevent auto-freezing so the unowned draft can be finalized.
215
+ canAutoFreeze_: true,
216
+ unfinalizedDrafts_: 0
217
+ };
218
+ }
219
+ function usePatchesInScope(scope, patchListener) {
220
+ if (patchListener) {
221
+ getPlugin("Patches");
222
+ scope.patches_ = [];
223
+ scope.inversePatches_ = [];
224
+ scope.patchListener_ = patchListener;
225
+ }
226
+ }
227
+ function revokeScope(scope) {
228
+ leaveScope(scope);
229
+ scope.drafts_.forEach(revokeDraft);
230
+ scope.drafts_ = null;
231
+ }
232
+ function leaveScope(scope) {
233
+ if (scope === currentScope) {
234
+ currentScope = scope.parent_;
235
+ }
236
+ }
237
+ function enterScope(immer2) {
238
+ return currentScope = createScope(currentScope, immer2);
239
+ }
240
+ function revokeDraft(draft) {
241
+ const state = draft[DRAFT_STATE];
242
+ if (state.type_ === 0 || state.type_ === 1)
243
+ state.revoke_();
244
+ else
245
+ state.revoked_ = true;
246
+ }
247
+ function processResult(result, scope) {
248
+ scope.unfinalizedDrafts_ = scope.drafts_.length;
249
+ const baseDraft = scope.drafts_[0];
250
+ const isReplaced = result !== void 0 && result !== baseDraft;
251
+ if (isReplaced) {
252
+ if (baseDraft[DRAFT_STATE].modified_) {
253
+ revokeScope(scope);
254
+ die(4);
255
+ }
256
+ if (isDraftable(result)) {
257
+ result = finalize(scope, result);
258
+ if (!scope.parent_)
259
+ maybeFreeze(scope, result);
260
+ }
261
+ if (scope.patches_) {
262
+ getPlugin("Patches").generateReplacementPatches_(
263
+ baseDraft[DRAFT_STATE].base_,
264
+ result,
265
+ scope.patches_,
266
+ scope.inversePatches_
267
+ );
268
+ }
269
+ } else {
270
+ result = finalize(scope, baseDraft, []);
271
+ }
272
+ revokeScope(scope);
273
+ if (scope.patches_) {
274
+ scope.patchListener_(scope.patches_, scope.inversePatches_);
275
+ }
276
+ return result !== NOTHING ? result : void 0;
277
+ }
278
+ function finalize(rootScope, value, path) {
279
+ if (isFrozen(value))
280
+ return value;
281
+ const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
282
+ const state = value[DRAFT_STATE];
283
+ if (!state) {
284
+ each(
285
+ value,
286
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path),
287
+ useStrictIteration
288
+ );
289
+ return value;
290
+ }
291
+ if (state.scope_ !== rootScope)
292
+ return value;
293
+ if (!state.modified_) {
294
+ maybeFreeze(rootScope, state.base_, true);
295
+ return state.base_;
296
+ }
297
+ if (!state.finalized_) {
298
+ state.finalized_ = true;
299
+ state.scope_.unfinalizedDrafts_--;
300
+ const result = state.copy_;
301
+ let resultEach = result;
302
+ let isSet2 = false;
303
+ if (state.type_ === 3) {
304
+ resultEach = new Set(result);
305
+ result.clear();
306
+ isSet2 = true;
307
+ }
308
+ each(
309
+ resultEach,
310
+ (key, childValue) => finalizeProperty(
311
+ rootScope,
312
+ state,
313
+ result,
314
+ key,
315
+ childValue,
316
+ path,
317
+ isSet2
318
+ ),
319
+ useStrictIteration
320
+ );
321
+ maybeFreeze(rootScope, result, false);
322
+ if (path && rootScope.patches_) {
323
+ getPlugin("Patches").generatePatches_(
324
+ state,
325
+ path,
326
+ rootScope.patches_,
327
+ rootScope.inversePatches_
328
+ );
329
+ }
330
+ }
331
+ return state.copy_;
332
+ }
333
+ function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
334
+ if (childValue == null) {
335
+ return;
336
+ }
337
+ if (typeof childValue !== "object" && !targetIsSet) {
338
+ return;
339
+ }
340
+ const childIsFrozen = isFrozen(childValue);
341
+ if (childIsFrozen && !targetIsSet) {
342
+ return;
343
+ }
344
+ if (childValue === targetObject)
345
+ die(5);
346
+ if (isDraft(childValue)) {
347
+ const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
348
+ !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
349
+ const res = finalize(rootScope, childValue, path);
350
+ set(targetObject, prop, res);
351
+ if (isDraft(res)) {
352
+ rootScope.canAutoFreeze_ = false;
353
+ } else
354
+ return;
355
+ } else if (targetIsSet) {
356
+ targetObject.add(childValue);
357
+ }
358
+ if (isDraftable(childValue) && !childIsFrozen) {
359
+ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
360
+ return;
361
+ }
362
+ if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) {
363
+ return;
364
+ }
365
+ finalize(rootScope, childValue);
366
+ if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop)))
367
+ maybeFreeze(rootScope, childValue);
368
+ }
369
+ }
370
+ function maybeFreeze(scope, value, deep = false) {
371
+ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
372
+ freeze(value, deep);
373
+ }
374
+ }
375
+ function createProxyProxy(base, parent) {
376
+ const isArray = Array.isArray(base);
377
+ const state = {
378
+ type_: isArray ? 1 : 0,
379
+ // Track which produce call this is associated with.
380
+ scope_: parent ? parent.scope_ : getCurrentScope(),
381
+ // True for both shallow and deep changes.
382
+ modified_: false,
383
+ // Used during finalization.
384
+ finalized_: false,
385
+ // Track which properties have been assigned (true) or deleted (false).
386
+ assigned_: {},
387
+ // The parent draft state.
388
+ parent_: parent,
389
+ // The base state.
390
+ base_: base,
391
+ // The base proxy.
392
+ draft_: null,
393
+ // set below
394
+ // The base copy with any updated values.
395
+ copy_: null,
396
+ // Called by the `produce` function.
397
+ revoke_: null,
398
+ isManual_: false
399
+ };
400
+ let target = state;
401
+ let traps = objectTraps;
402
+ if (isArray) {
403
+ target = [state];
404
+ traps = arrayTraps;
405
+ }
406
+ const { revoke, proxy } = Proxy.revocable(target, traps);
407
+ state.draft_ = proxy;
408
+ state.revoke_ = revoke;
409
+ return proxy;
410
+ }
411
+ var objectTraps = {
412
+ get(state, prop) {
413
+ if (prop === DRAFT_STATE)
414
+ return state;
415
+ const source = latest(state);
416
+ if (!has(source, prop)) {
417
+ return readPropFromProto(state, source, prop);
418
+ }
419
+ const value = source[prop];
420
+ if (state.finalized_ || !isDraftable(value)) {
421
+ return value;
422
+ }
423
+ if (value === peek(state.base_, prop)) {
424
+ prepareCopy(state);
425
+ return state.copy_[prop] = createProxy(value, state);
426
+ }
427
+ return value;
428
+ },
429
+ has(state, prop) {
430
+ return prop in latest(state);
431
+ },
432
+ ownKeys(state) {
433
+ return Reflect.ownKeys(latest(state));
434
+ },
435
+ set(state, prop, value) {
436
+ const desc = getDescriptorFromProto(latest(state), prop);
437
+ if (desc?.set) {
438
+ desc.set.call(state.draft_, value);
439
+ return true;
440
+ }
441
+ if (!state.modified_) {
442
+ const current2 = peek(latest(state), prop);
443
+ const currentState = current2?.[DRAFT_STATE];
444
+ if (currentState && currentState.base_ === value) {
445
+ state.copy_[prop] = value;
446
+ state.assigned_[prop] = false;
447
+ return true;
448
+ }
449
+ if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
450
+ return true;
451
+ prepareCopy(state);
452
+ markChanged(state);
453
+ }
454
+ if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
455
+ (value !== void 0 || prop in state.copy_) || // special case: NaN
456
+ Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
457
+ return true;
458
+ state.copy_[prop] = value;
459
+ state.assigned_[prop] = true;
460
+ return true;
461
+ },
462
+ deleteProperty(state, prop) {
463
+ if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
464
+ state.assigned_[prop] = false;
465
+ prepareCopy(state);
466
+ markChanged(state);
467
+ } else {
468
+ delete state.assigned_[prop];
469
+ }
470
+ if (state.copy_) {
471
+ delete state.copy_[prop];
472
+ }
473
+ return true;
474
+ },
475
+ // Note: We never coerce `desc.value` into an Immer draft, because we can't make
476
+ // the same guarantee in ES5 mode.
477
+ getOwnPropertyDescriptor(state, prop) {
478
+ const owner = latest(state);
479
+ const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
480
+ if (!desc)
481
+ return desc;
482
+ return {
483
+ writable: true,
484
+ configurable: state.type_ !== 1 || prop !== "length",
485
+ enumerable: desc.enumerable,
486
+ value: owner[prop]
487
+ };
488
+ },
489
+ defineProperty() {
490
+ die(11);
491
+ },
492
+ getPrototypeOf(state) {
493
+ return getPrototypeOf(state.base_);
494
+ },
495
+ setPrototypeOf() {
496
+ die(12);
497
+ }
498
+ };
499
+ var arrayTraps = {};
500
+ each(objectTraps, (key, fn) => {
501
+ arrayTraps[key] = function() {
502
+ arguments[0] = arguments[0][0];
503
+ return fn.apply(this, arguments);
504
+ };
505
+ });
506
+ arrayTraps.deleteProperty = function(state, prop) {
507
+ if (isNaN(parseInt(prop)))
508
+ die(13);
509
+ return arrayTraps.set.call(this, state, prop, void 0);
510
+ };
511
+ arrayTraps.set = function(state, prop, value) {
512
+ if (prop !== "length" && isNaN(parseInt(prop)))
513
+ die(14);
514
+ return objectTraps.set.call(this, state[0], prop, value, state[0]);
515
+ };
516
+ function peek(draft, prop) {
517
+ const state = draft[DRAFT_STATE];
518
+ const source = state ? latest(state) : draft;
519
+ return source[prop];
520
+ }
521
+ function readPropFromProto(state, source, prop) {
522
+ const desc = getDescriptorFromProto(source, prop);
523
+ return desc ? `value` in desc ? desc.value : (
524
+ // This is a very special case, if the prop is a getter defined by the
525
+ // prototype, we should invoke it with the draft as context!
526
+ desc.get?.call(state.draft_)
527
+ ) : void 0;
528
+ }
529
+ function getDescriptorFromProto(source, prop) {
530
+ if (!(prop in source))
531
+ return void 0;
532
+ let proto = getPrototypeOf(source);
533
+ while (proto) {
534
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
535
+ if (desc)
536
+ return desc;
537
+ proto = getPrototypeOf(proto);
538
+ }
539
+ return void 0;
540
+ }
541
+ function markChanged(state) {
542
+ if (!state.modified_) {
543
+ state.modified_ = true;
544
+ if (state.parent_) {
545
+ markChanged(state.parent_);
546
+ }
547
+ }
548
+ }
549
+ function prepareCopy(state) {
550
+ if (!state.copy_) {
551
+ state.copy_ = shallowCopy(
552
+ state.base_,
553
+ state.scope_.immer_.useStrictShallowCopy_
554
+ );
555
+ }
556
+ }
557
+ var Immer2 = class {
558
+ constructor(config) {
559
+ this.autoFreeze_ = true;
560
+ this.useStrictShallowCopy_ = false;
561
+ this.useStrictIteration_ = true;
562
+ this.produce = (base, recipe, patchListener) => {
563
+ if (typeof base === "function" && typeof recipe !== "function") {
564
+ const defaultBase = recipe;
565
+ recipe = base;
566
+ const self = this;
567
+ return function curriedProduce(base2 = defaultBase, ...args) {
568
+ return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
569
+ };
570
+ }
571
+ if (typeof recipe !== "function")
572
+ die(6);
573
+ if (patchListener !== void 0 && typeof patchListener !== "function")
574
+ die(7);
575
+ let result;
576
+ if (isDraftable(base)) {
577
+ const scope = enterScope(this);
578
+ const proxy = createProxy(base, void 0);
579
+ let hasError = true;
580
+ try {
581
+ result = recipe(proxy);
582
+ hasError = false;
583
+ } finally {
584
+ if (hasError)
585
+ revokeScope(scope);
586
+ else
587
+ leaveScope(scope);
588
+ }
589
+ usePatchesInScope(scope, patchListener);
590
+ return processResult(result, scope);
591
+ } else if (!base || typeof base !== "object") {
592
+ result = recipe(base);
593
+ if (result === void 0)
594
+ result = base;
595
+ if (result === NOTHING)
596
+ result = void 0;
597
+ if (this.autoFreeze_)
598
+ freeze(result, true);
599
+ if (patchListener) {
600
+ const p = [];
601
+ const ip = [];
602
+ getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
603
+ patchListener(p, ip);
604
+ }
605
+ return result;
606
+ } else
607
+ die(1, base);
608
+ };
609
+ this.produceWithPatches = (base, recipe) => {
610
+ if (typeof base === "function") {
611
+ return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
612
+ }
613
+ let patches, inversePatches;
614
+ const result = this.produce(base, recipe, (p, ip) => {
615
+ patches = p;
616
+ inversePatches = ip;
617
+ });
618
+ return [result, patches, inversePatches];
619
+ };
620
+ if (typeof config?.autoFreeze === "boolean")
621
+ this.setAutoFreeze(config.autoFreeze);
622
+ if (typeof config?.useStrictShallowCopy === "boolean")
623
+ this.setUseStrictShallowCopy(config.useStrictShallowCopy);
624
+ if (typeof config?.useStrictIteration === "boolean")
625
+ this.setUseStrictIteration(config.useStrictIteration);
626
+ }
627
+ createDraft(base) {
628
+ if (!isDraftable(base))
629
+ die(8);
630
+ if (isDraft(base))
631
+ base = current(base);
632
+ const scope = enterScope(this);
633
+ const proxy = createProxy(base, void 0);
634
+ proxy[DRAFT_STATE].isManual_ = true;
635
+ leaveScope(scope);
636
+ return proxy;
637
+ }
638
+ finishDraft(draft, patchListener) {
639
+ const state = draft && draft[DRAFT_STATE];
640
+ if (!state || !state.isManual_)
641
+ die(9);
642
+ const { scope_: scope } = state;
643
+ usePatchesInScope(scope, patchListener);
644
+ return processResult(void 0, scope);
645
+ }
646
+ /**
647
+ * Pass true to automatically freeze all copies created by Immer.
648
+ *
649
+ * By default, auto-freezing is enabled.
650
+ */
651
+ setAutoFreeze(value) {
652
+ this.autoFreeze_ = value;
653
+ }
654
+ /**
655
+ * Pass true to enable strict shallow copy.
656
+ *
657
+ * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
658
+ */
659
+ setUseStrictShallowCopy(value) {
660
+ this.useStrictShallowCopy_ = value;
661
+ }
662
+ /**
663
+ * Pass false to use faster iteration that skips non-enumerable properties
664
+ * but still handles symbols for compatibility.
665
+ *
666
+ * By default, strict iteration is enabled (includes all own properties).
667
+ */
668
+ setUseStrictIteration(value) {
669
+ this.useStrictIteration_ = value;
670
+ }
671
+ shouldUseStrictIteration() {
672
+ return this.useStrictIteration_;
673
+ }
674
+ applyPatches(base, patches) {
675
+ let i;
676
+ for (i = patches.length - 1; i >= 0; i--) {
677
+ const patch = patches[i];
678
+ if (patch.path.length === 0 && patch.op === "replace") {
679
+ base = patch.value;
680
+ break;
681
+ }
682
+ }
683
+ if (i > -1) {
684
+ patches = patches.slice(i + 1);
685
+ }
686
+ const applyPatchesImpl = getPlugin("Patches").applyPatches_;
687
+ if (isDraft(base)) {
688
+ return applyPatchesImpl(base, patches);
689
+ }
690
+ return this.produce(
691
+ base,
692
+ (draft) => applyPatchesImpl(draft, patches)
693
+ );
694
+ }
695
+ };
696
+ function createProxy(value, parent) {
697
+ const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
698
+ const scope = parent ? parent.scope_ : getCurrentScope();
699
+ scope.drafts_.push(draft);
700
+ return draft;
701
+ }
702
+ function current(value) {
703
+ if (!isDraft(value))
704
+ die(10, value);
705
+ return currentImpl(value);
706
+ }
707
+ function currentImpl(value) {
708
+ if (!isDraftable(value) || isFrozen(value))
709
+ return value;
710
+ const state = value[DRAFT_STATE];
711
+ let copy;
712
+ let strict = true;
713
+ if (state) {
714
+ if (!state.modified_)
715
+ return state.base_;
716
+ state.finalized_ = true;
717
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
718
+ strict = state.scope_.immer_.shouldUseStrictIteration();
719
+ } else {
720
+ copy = shallowCopy(value, true);
721
+ }
722
+ each(
723
+ copy,
724
+ (key, childValue) => {
725
+ set(copy, key, currentImpl(childValue));
726
+ },
727
+ strict
728
+ );
729
+ if (state) {
730
+ state.finalized_ = false;
731
+ }
732
+ return copy;
733
+ }
734
+ function enablePatches() {
735
+ const errorOffset = 16;
736
+ if (true) {
737
+ errors.push(
738
+ 'Sets cannot have "replace" patches.',
739
+ function(op) {
740
+ return "Unsupported patch operation: " + op;
741
+ },
742
+ function(path) {
743
+ return "Cannot apply patch, path doesn't resolve: " + path;
744
+ },
745
+ "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
746
+ );
747
+ }
748
+ const REPLACE = "replace";
749
+ const ADD = "add";
750
+ const REMOVE = "remove";
751
+ function generatePatches_(state, basePath, patches, inversePatches) {
752
+ switch (state.type_) {
753
+ case 0:
754
+ case 2:
755
+ return generatePatchesFromAssigned(
756
+ state,
757
+ basePath,
758
+ patches,
759
+ inversePatches
760
+ );
761
+ case 1:
762
+ return generateArrayPatches(state, basePath, patches, inversePatches);
763
+ case 3:
764
+ return generateSetPatches(
765
+ state,
766
+ basePath,
767
+ patches,
768
+ inversePatches
769
+ );
770
+ }
771
+ }
772
+ function generateArrayPatches(state, basePath, patches, inversePatches) {
773
+ let { base_, assigned_ } = state;
774
+ let copy_ = state.copy_;
775
+ if (copy_.length < base_.length) {
776
+ ;
777
+ [base_, copy_] = [copy_, base_];
778
+ [patches, inversePatches] = [inversePatches, patches];
779
+ }
780
+ for (let i = 0; i < base_.length; i++) {
781
+ if (assigned_[i] && copy_[i] !== base_[i]) {
782
+ const path = basePath.concat([i]);
783
+ patches.push({
784
+ op: REPLACE,
785
+ path,
786
+ // Need to maybe clone it, as it can in fact be the original value
787
+ // due to the base/copy inversion at the start of this function
788
+ value: clonePatchValueIfNeeded(copy_[i])
789
+ });
790
+ inversePatches.push({
791
+ op: REPLACE,
792
+ path,
793
+ value: clonePatchValueIfNeeded(base_[i])
794
+ });
795
+ }
796
+ }
797
+ for (let i = base_.length; i < copy_.length; i++) {
798
+ const path = basePath.concat([i]);
799
+ patches.push({
800
+ op: ADD,
801
+ path,
802
+ // Need to maybe clone it, as it can in fact be the original value
803
+ // due to the base/copy inversion at the start of this function
804
+ value: clonePatchValueIfNeeded(copy_[i])
805
+ });
806
+ }
807
+ for (let i = copy_.length - 1; base_.length <= i; --i) {
808
+ const path = basePath.concat([i]);
809
+ inversePatches.push({
810
+ op: REMOVE,
811
+ path
812
+ });
813
+ }
814
+ }
815
+ function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
816
+ const { base_, copy_ } = state;
817
+ each(state.assigned_, (key, assignedValue) => {
818
+ const origValue = get(base_, key);
819
+ const value = get(copy_, key);
820
+ const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;
821
+ if (origValue === value && op === REPLACE)
822
+ return;
823
+ const path = basePath.concat(key);
824
+ patches.push(op === REMOVE ? { op, path } : { op, path, value });
825
+ inversePatches.push(
826
+ op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) }
827
+ );
828
+ });
829
+ }
830
+ function generateSetPatches(state, basePath, patches, inversePatches) {
831
+ let { base_, copy_ } = state;
832
+ let i = 0;
833
+ base_.forEach((value) => {
834
+ if (!copy_.has(value)) {
835
+ const path = basePath.concat([i]);
836
+ patches.push({
837
+ op: REMOVE,
838
+ path,
839
+ value
840
+ });
841
+ inversePatches.unshift({
842
+ op: ADD,
843
+ path,
844
+ value
845
+ });
846
+ }
847
+ i++;
848
+ });
849
+ i = 0;
850
+ copy_.forEach((value) => {
851
+ if (!base_.has(value)) {
852
+ const path = basePath.concat([i]);
853
+ patches.push({
854
+ op: ADD,
855
+ path,
856
+ value
857
+ });
858
+ inversePatches.unshift({
859
+ op: REMOVE,
860
+ path,
861
+ value
862
+ });
863
+ }
864
+ i++;
865
+ });
866
+ }
867
+ function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {
868
+ patches.push({
869
+ op: REPLACE,
870
+ path: [],
871
+ value: replacement === NOTHING ? void 0 : replacement
872
+ });
873
+ inversePatches.push({
874
+ op: REPLACE,
875
+ path: [],
876
+ value: baseValue
877
+ });
878
+ }
879
+ function applyPatches_(draft, patches) {
880
+ patches.forEach((patch) => {
881
+ const { path, op } = patch;
882
+ let base = draft;
883
+ for (let i = 0; i < path.length - 1; i++) {
884
+ const parentType = getArchtype(base);
885
+ let p = path[i];
886
+ if (typeof p !== "string" && typeof p !== "number") {
887
+ p = "" + p;
888
+ }
889
+ if ((parentType === 0 || parentType === 1) && (p === "__proto__" || p === "constructor"))
890
+ die(errorOffset + 3);
891
+ if (typeof base === "function" && p === "prototype")
892
+ die(errorOffset + 3);
893
+ base = get(base, p);
894
+ if (typeof base !== "object")
895
+ die(errorOffset + 2, path.join("/"));
896
+ }
897
+ const type = getArchtype(base);
898
+ const value = deepClonePatchValue(patch.value);
899
+ const key = path[path.length - 1];
900
+ switch (op) {
901
+ case REPLACE:
902
+ switch (type) {
903
+ case 2:
904
+ return base.set(key, value);
905
+ case 3:
906
+ die(errorOffset);
907
+ default:
908
+ return base[key] = value;
909
+ }
910
+ case ADD:
911
+ switch (type) {
912
+ case 1:
913
+ return key === "-" ? base.push(value) : base.splice(key, 0, value);
914
+ case 2:
915
+ return base.set(key, value);
916
+ case 3:
917
+ return base.add(value);
918
+ default:
919
+ return base[key] = value;
920
+ }
921
+ case REMOVE:
922
+ switch (type) {
923
+ case 1:
924
+ return base.splice(key, 1);
925
+ case 2:
926
+ return base.delete(key);
927
+ case 3:
928
+ return base.delete(patch.value);
929
+ default:
930
+ return delete base[key];
931
+ }
932
+ default:
933
+ die(errorOffset + 1, op);
934
+ }
935
+ });
936
+ return draft;
937
+ }
938
+ function deepClonePatchValue(obj) {
939
+ if (!isDraftable(obj))
940
+ return obj;
941
+ if (Array.isArray(obj))
942
+ return obj.map(deepClonePatchValue);
943
+ if (isMap(obj))
944
+ return new Map(
945
+ Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])
946
+ );
947
+ if (isSet(obj))
948
+ return new Set(Array.from(obj).map(deepClonePatchValue));
949
+ const cloned = Object.create(getPrototypeOf(obj));
950
+ for (const key in obj)
951
+ cloned[key] = deepClonePatchValue(obj[key]);
952
+ if (has(obj, DRAFTABLE))
953
+ cloned[DRAFTABLE] = obj[DRAFTABLE];
954
+ return cloned;
955
+ }
956
+ function clonePatchValueIfNeeded(obj) {
957
+ if (isDraft(obj)) {
958
+ return deepClonePatchValue(obj);
959
+ } else
960
+ return obj;
961
+ }
962
+ loadPlugin("Patches", {
963
+ applyPatches_,
964
+ generatePatches_,
965
+ generateReplacementPatches_
966
+ });
967
+ }
968
+ function enableMapSet() {
969
+ class DraftMap extends Map {
970
+ constructor(target, parent) {
971
+ super();
972
+ this[DRAFT_STATE] = {
973
+ type_: 2,
974
+ parent_: parent,
975
+ scope_: parent ? parent.scope_ : getCurrentScope(),
976
+ modified_: false,
977
+ finalized_: false,
978
+ copy_: void 0,
979
+ assigned_: void 0,
980
+ base_: target,
981
+ draft_: this,
982
+ isManual_: false,
983
+ revoked_: false
984
+ };
985
+ }
986
+ get size() {
987
+ return latest(this[DRAFT_STATE]).size;
988
+ }
989
+ has(key) {
990
+ return latest(this[DRAFT_STATE]).has(key);
991
+ }
992
+ set(key, value) {
993
+ const state = this[DRAFT_STATE];
994
+ assertUnrevoked(state);
995
+ if (!latest(state).has(key) || latest(state).get(key) !== value) {
996
+ prepareMapCopy(state);
997
+ markChanged(state);
998
+ state.assigned_.set(key, true);
999
+ state.copy_.set(key, value);
1000
+ state.assigned_.set(key, true);
1001
+ }
1002
+ return this;
1003
+ }
1004
+ delete(key) {
1005
+ if (!this.has(key)) {
1006
+ return false;
1007
+ }
1008
+ const state = this[DRAFT_STATE];
1009
+ assertUnrevoked(state);
1010
+ prepareMapCopy(state);
1011
+ markChanged(state);
1012
+ if (state.base_.has(key)) {
1013
+ state.assigned_.set(key, false);
1014
+ } else {
1015
+ state.assigned_.delete(key);
1016
+ }
1017
+ state.copy_.delete(key);
1018
+ return true;
1019
+ }
1020
+ clear() {
1021
+ const state = this[DRAFT_STATE];
1022
+ assertUnrevoked(state);
1023
+ if (latest(state).size) {
1024
+ prepareMapCopy(state);
1025
+ markChanged(state);
1026
+ state.assigned_ = /* @__PURE__ */ new Map();
1027
+ each(state.base_, (key) => {
1028
+ state.assigned_.set(key, false);
1029
+ });
1030
+ state.copy_.clear();
1031
+ }
1032
+ }
1033
+ forEach(cb, thisArg) {
1034
+ const state = this[DRAFT_STATE];
1035
+ latest(state).forEach((_value, key, _map) => {
1036
+ cb.call(thisArg, this.get(key), key, this);
1037
+ });
1038
+ }
1039
+ get(key) {
1040
+ const state = this[DRAFT_STATE];
1041
+ assertUnrevoked(state);
1042
+ const value = latest(state).get(key);
1043
+ if (state.finalized_ || !isDraftable(value)) {
1044
+ return value;
1045
+ }
1046
+ if (value !== state.base_.get(key)) {
1047
+ return value;
1048
+ }
1049
+ const draft = createProxy(value, state);
1050
+ prepareMapCopy(state);
1051
+ state.copy_.set(key, draft);
1052
+ return draft;
1053
+ }
1054
+ keys() {
1055
+ return latest(this[DRAFT_STATE]).keys();
1056
+ }
1057
+ values() {
1058
+ const iterator = this.keys();
1059
+ return {
1060
+ [Symbol.iterator]: () => this.values(),
1061
+ next: () => {
1062
+ const r = iterator.next();
1063
+ if (r.done)
1064
+ return r;
1065
+ const value = this.get(r.value);
1066
+ return {
1067
+ done: false,
1068
+ value
1069
+ };
1070
+ }
1071
+ };
1072
+ }
1073
+ entries() {
1074
+ const iterator = this.keys();
1075
+ return {
1076
+ [Symbol.iterator]: () => this.entries(),
1077
+ next: () => {
1078
+ const r = iterator.next();
1079
+ if (r.done)
1080
+ return r;
1081
+ const value = this.get(r.value);
1082
+ return {
1083
+ done: false,
1084
+ value: [r.value, value]
1085
+ };
1086
+ }
1087
+ };
1088
+ }
1089
+ [(DRAFT_STATE, Symbol.iterator)]() {
1090
+ return this.entries();
1091
+ }
1092
+ }
1093
+ function proxyMap_(target, parent) {
1094
+ return new DraftMap(target, parent);
1095
+ }
1096
+ function prepareMapCopy(state) {
1097
+ if (!state.copy_) {
1098
+ state.assigned_ = /* @__PURE__ */ new Map();
1099
+ state.copy_ = new Map(state.base_);
1100
+ }
1101
+ }
1102
+ class DraftSet extends Set {
1103
+ constructor(target, parent) {
1104
+ super();
1105
+ this[DRAFT_STATE] = {
1106
+ type_: 3,
1107
+ parent_: parent,
1108
+ scope_: parent ? parent.scope_ : getCurrentScope(),
1109
+ modified_: false,
1110
+ finalized_: false,
1111
+ copy_: void 0,
1112
+ base_: target,
1113
+ draft_: this,
1114
+ drafts_: /* @__PURE__ */ new Map(),
1115
+ revoked_: false,
1116
+ isManual_: false
1117
+ };
1118
+ }
1119
+ get size() {
1120
+ return latest(this[DRAFT_STATE]).size;
1121
+ }
1122
+ has(value) {
1123
+ const state = this[DRAFT_STATE];
1124
+ assertUnrevoked(state);
1125
+ if (!state.copy_) {
1126
+ return state.base_.has(value);
1127
+ }
1128
+ if (state.copy_.has(value))
1129
+ return true;
1130
+ if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))
1131
+ return true;
1132
+ return false;
1133
+ }
1134
+ add(value) {
1135
+ const state = this[DRAFT_STATE];
1136
+ assertUnrevoked(state);
1137
+ if (!this.has(value)) {
1138
+ prepareSetCopy(state);
1139
+ markChanged(state);
1140
+ state.copy_.add(value);
1141
+ }
1142
+ return this;
1143
+ }
1144
+ delete(value) {
1145
+ if (!this.has(value)) {
1146
+ return false;
1147
+ }
1148
+ const state = this[DRAFT_STATE];
1149
+ assertUnrevoked(state);
1150
+ prepareSetCopy(state);
1151
+ markChanged(state);
1152
+ return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : (
1153
+ /* istanbul ignore next */
1154
+ false
1155
+ ));
1156
+ }
1157
+ clear() {
1158
+ const state = this[DRAFT_STATE];
1159
+ assertUnrevoked(state);
1160
+ if (latest(state).size) {
1161
+ prepareSetCopy(state);
1162
+ markChanged(state);
1163
+ state.copy_.clear();
1164
+ }
1165
+ }
1166
+ values() {
1167
+ const state = this[DRAFT_STATE];
1168
+ assertUnrevoked(state);
1169
+ prepareSetCopy(state);
1170
+ return state.copy_.values();
1171
+ }
1172
+ entries() {
1173
+ const state = this[DRAFT_STATE];
1174
+ assertUnrevoked(state);
1175
+ prepareSetCopy(state);
1176
+ return state.copy_.entries();
1177
+ }
1178
+ keys() {
1179
+ return this.values();
1180
+ }
1181
+ [(DRAFT_STATE, Symbol.iterator)]() {
1182
+ return this.values();
1183
+ }
1184
+ forEach(cb, thisArg) {
1185
+ const iterator = this.values();
1186
+ let result = iterator.next();
1187
+ while (!result.done) {
1188
+ cb.call(thisArg, result.value, result.value, this);
1189
+ result = iterator.next();
1190
+ }
1191
+ }
1192
+ }
1193
+ function proxySet_(target, parent) {
1194
+ return new DraftSet(target, parent);
1195
+ }
1196
+ function prepareSetCopy(state) {
1197
+ if (!state.copy_) {
1198
+ state.copy_ = /* @__PURE__ */ new Set();
1199
+ state.base_.forEach((value) => {
1200
+ if (isDraftable(value)) {
1201
+ const draft = createProxy(value, state);
1202
+ state.drafts_.set(value, draft);
1203
+ state.copy_.add(draft);
1204
+ } else {
1205
+ state.copy_.add(value);
1206
+ }
1207
+ });
1208
+ }
1209
+ }
1210
+ function assertUnrevoked(state) {
1211
+ if (state.revoked_)
1212
+ die(3, JSON.stringify(latest(state)));
1213
+ }
1214
+ loadPlugin("MapSet", { proxyMap_, proxySet_ });
1215
+ }
1216
+ var immer = new Immer2();
1217
+ var produce = immer.produce;
1218
+ var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(
1219
+ immer
1220
+ );
1221
+ var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer);
1222
+ var setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(
1223
+ immer
1224
+ );
1225
+ var setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(
1226
+ immer
1227
+ );
1228
+ var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer);
1229
+ var createDraft = /* @__PURE__ */ immer.createDraft.bind(immer);
1230
+ var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer);
1231
+ function castDraft(value) {
1232
+ return value;
1233
+ }
1234
+ function castImmutable(value) {
1235
+ return value;
1236
+ }
1237
+
1238
+ // src/immer.js
1239
+ enableMapSet();
1240
+ export {
1241
+ Immer2 as Immer,
1242
+ applyPatches,
1243
+ castDraft,
1244
+ castImmutable,
1245
+ createDraft,
1246
+ current,
1247
+ enableMapSet,
1248
+ enablePatches,
1249
+ finishDraft,
1250
+ freeze,
1251
+ DRAFTABLE as immerable,
1252
+ isDraft,
1253
+ isDraftable,
1254
+ NOTHING as nothing,
1255
+ original,
1256
+ produce,
1257
+ produceWithPatches,
1258
+ setAutoFreeze,
1259
+ setUseStrictIteration,
1260
+ setUseStrictShallowCopy
1261
+ };