@cfp-studio/iframe 18.0.0 → 18.0.1

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.mjs CHANGED
@@ -1,991 +1 @@
1
- var assertNever$1 = {};
2
-
3
- Object.defineProperty(assertNever$1, "__esModule", { value: true });
4
- var assertNever_2 = assertNever$1.assertNever = assertNever;
5
- /**
6
- * Helper function for exhaustive checks of discriminated unions.
7
- * https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html
8
- *
9
- * @example
10
- *
11
- * type A = {type: 'a'};
12
- * type B = {type: 'b'};
13
- * type Union = A | B;
14
- *
15
- * function doSomething(arg: Union) {
16
- * if (arg.type === 'a') {
17
- * return something;
18
- * }
19
- *
20
- * if (arg.type === 'b') {
21
- * return somethingElse;
22
- * }
23
- *
24
- * // TS will error if there are other types in the union
25
- * // Will throw an Error when called at runtime.
26
- * // Use `assertNever(arg, true)` instead to fail silently.
27
- * return assertNever(arg);
28
- * }
29
- */
30
- function assertNever(value, errorMessageOrNoThrow) {
31
- if (typeof errorMessageOrNoThrow === 'string') {
32
- throw new Error(errorMessageOrNoThrow);
33
- }
34
- if (typeof errorMessageOrNoThrow === 'function') {
35
- throw new Error(errorMessageOrNoThrow(value));
36
- }
37
- if (errorMessageOrNoThrow) {
38
- return value;
39
- }
40
- throw new Error("Unhandled discriminated union member: ".concat(JSON.stringify(value)));
41
- }
42
- assertNever$1.default = assertNever;
43
-
44
- // src/utils/env.ts
45
- var NOTHING = Symbol.for("immer-nothing");
46
- var DRAFTABLE = Symbol.for("immer-draftable");
47
- var DRAFT_STATE = Symbol.for("immer-state");
48
-
49
- // src/utils/errors.ts
50
- var errors = process.env.NODE_ENV !== "production" ? [
51
- // All error codes, starting by 0:
52
- function(plugin) {
53
- return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
54
- },
55
- function(thing) {
56
- 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}'`;
57
- },
58
- "This object has been frozen and should not be mutated",
59
- function(data) {
60
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
61
- },
62
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
63
- "Immer forbids circular references",
64
- "The first or second argument to `produce` must be a function",
65
- "The third argument to `produce` must be a function or undefined",
66
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
67
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
68
- function(thing) {
69
- return `'current' expects a draft, got: ${thing}`;
70
- },
71
- "Object.defineProperty() cannot be used on an Immer draft",
72
- "Object.setPrototypeOf() cannot be used on an Immer draft",
73
- "Immer only supports deleting array indices",
74
- "Immer only supports setting array indices and the 'length' property",
75
- function(thing) {
76
- return `'original' expects a draft, got: ${thing}`;
77
- }
78
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
79
- // See Patches.ts for additional errors
80
- ] : [];
81
- function die(error, ...args) {
82
- if (process.env.NODE_ENV !== "production") {
83
- const e = errors[error];
84
- const msg = typeof e === "function" ? e.apply(null, args) : e;
85
- throw new Error(`[Immer] ${msg}`);
86
- }
87
- throw new Error(
88
- `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
89
- );
90
- }
91
-
92
- // src/utils/common.ts
93
- var getPrototypeOf = Object.getPrototypeOf;
94
- function isDraft(value) {
95
- return !!value && !!value[DRAFT_STATE];
96
- }
97
- function isDraftable(value) {
98
- if (!value)
99
- return false;
100
- return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
101
- }
102
- var objectCtorString = Object.prototype.constructor.toString();
103
- function isPlainObject(value) {
104
- if (!value || typeof value !== "object")
105
- return false;
106
- const proto = getPrototypeOf(value);
107
- if (proto === null) {
108
- return true;
109
- }
110
- const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
111
- if (Ctor === Object)
112
- return true;
113
- return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
114
- }
115
- function each(obj, iter) {
116
- if (getArchtype(obj) === 0 /* Object */) {
117
- Reflect.ownKeys(obj).forEach((key) => {
118
- iter(key, obj[key], obj);
119
- });
120
- } else {
121
- obj.forEach((entry, index) => iter(index, entry, obj));
122
- }
123
- }
124
- function getArchtype(thing) {
125
- const state = thing[DRAFT_STATE];
126
- return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
127
- }
128
- function has(thing, prop) {
129
- return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
130
- }
131
- function set(thing, propOrOldValue, value) {
132
- const t = getArchtype(thing);
133
- if (t === 2 /* Map */)
134
- thing.set(propOrOldValue, value);
135
- else if (t === 3 /* Set */) {
136
- thing.add(value);
137
- } else
138
- thing[propOrOldValue] = value;
139
- }
140
- function is(x, y) {
141
- if (x === y) {
142
- return x !== 0 || 1 / x === 1 / y;
143
- } else {
144
- return x !== x && y !== y;
145
- }
146
- }
147
- function isMap(target) {
148
- return target instanceof Map;
149
- }
150
- function isSet(target) {
151
- return target instanceof Set;
152
- }
153
- function latest(state) {
154
- return state.copy_ || state.base_;
155
- }
156
- function shallowCopy(base, strict) {
157
- if (isMap(base)) {
158
- return new Map(base);
159
- }
160
- if (isSet(base)) {
161
- return new Set(base);
162
- }
163
- if (Array.isArray(base))
164
- return Array.prototype.slice.call(base);
165
- const isPlain = isPlainObject(base);
166
- if (strict === true || strict === "class_only" && !isPlain) {
167
- const descriptors = Object.getOwnPropertyDescriptors(base);
168
- delete descriptors[DRAFT_STATE];
169
- let keys = Reflect.ownKeys(descriptors);
170
- for (let i = 0; i < keys.length; i++) {
171
- const key = keys[i];
172
- const desc = descriptors[key];
173
- if (desc.writable === false) {
174
- desc.writable = true;
175
- desc.configurable = true;
176
- }
177
- if (desc.get || desc.set)
178
- descriptors[key] = {
179
- configurable: true,
180
- writable: true,
181
- // could live with !!desc.set as well here...
182
- enumerable: desc.enumerable,
183
- value: base[key]
184
- };
185
- }
186
- return Object.create(getPrototypeOf(base), descriptors);
187
- } else {
188
- const proto = getPrototypeOf(base);
189
- if (proto !== null && isPlain) {
190
- return { ...base };
191
- }
192
- const obj = Object.create(proto);
193
- return Object.assign(obj, base);
194
- }
195
- }
196
- function freeze(obj, deep = false) {
197
- if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
198
- return obj;
199
- if (getArchtype(obj) > 1) {
200
- obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
201
- }
202
- Object.freeze(obj);
203
- if (deep)
204
- Object.entries(obj).forEach(([key, value]) => freeze(value, true));
205
- return obj;
206
- }
207
- function dontMutateFrozenCollections() {
208
- die(2);
209
- }
210
- function isFrozen(obj) {
211
- return Object.isFrozen(obj);
212
- }
213
-
214
- // src/utils/plugins.ts
215
- var plugins = {};
216
- function getPlugin(pluginKey) {
217
- const plugin = plugins[pluginKey];
218
- if (!plugin) {
219
- die(0, pluginKey);
220
- }
221
- return plugin;
222
- }
223
-
224
- // src/core/scope.ts
225
- var currentScope;
226
- function getCurrentScope() {
227
- return currentScope;
228
- }
229
- function createScope(parent_, immer_) {
230
- return {
231
- drafts_: [],
232
- parent_,
233
- immer_,
234
- // Whenever the modified draft contains a draft from another scope, we
235
- // need to prevent auto-freezing so the unowned draft can be finalized.
236
- canAutoFreeze_: true,
237
- unfinalizedDrafts_: 0
238
- };
239
- }
240
- function usePatchesInScope(scope, patchListener) {
241
- if (patchListener) {
242
- getPlugin("Patches");
243
- scope.patches_ = [];
244
- scope.inversePatches_ = [];
245
- scope.patchListener_ = patchListener;
246
- }
247
- }
248
- function revokeScope(scope) {
249
- leaveScope(scope);
250
- scope.drafts_.forEach(revokeDraft);
251
- scope.drafts_ = null;
252
- }
253
- function leaveScope(scope) {
254
- if (scope === currentScope) {
255
- currentScope = scope.parent_;
256
- }
257
- }
258
- function enterScope(immer2) {
259
- return currentScope = createScope(currentScope, immer2);
260
- }
261
- function revokeDraft(draft) {
262
- const state = draft[DRAFT_STATE];
263
- if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
264
- state.revoke_();
265
- else
266
- state.revoked_ = true;
267
- }
268
-
269
- // src/core/finalize.ts
270
- function processResult(result, scope) {
271
- scope.unfinalizedDrafts_ = scope.drafts_.length;
272
- const baseDraft = scope.drafts_[0];
273
- const isReplaced = result !== void 0 && result !== baseDraft;
274
- if (isReplaced) {
275
- if (baseDraft[DRAFT_STATE].modified_) {
276
- revokeScope(scope);
277
- die(4);
278
- }
279
- if (isDraftable(result)) {
280
- result = finalize(scope, result);
281
- if (!scope.parent_)
282
- maybeFreeze(scope, result);
283
- }
284
- if (scope.patches_) {
285
- getPlugin("Patches").generateReplacementPatches_(
286
- baseDraft[DRAFT_STATE].base_,
287
- result,
288
- scope.patches_,
289
- scope.inversePatches_
290
- );
291
- }
292
- } else {
293
- result = finalize(scope, baseDraft, []);
294
- }
295
- revokeScope(scope);
296
- if (scope.patches_) {
297
- scope.patchListener_(scope.patches_, scope.inversePatches_);
298
- }
299
- return result !== NOTHING ? result : void 0;
300
- }
301
- function finalize(rootScope, value, path) {
302
- if (isFrozen(value))
303
- return value;
304
- const state = value[DRAFT_STATE];
305
- if (!state) {
306
- each(
307
- value,
308
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
309
- );
310
- return value;
311
- }
312
- if (state.scope_ !== rootScope)
313
- return value;
314
- if (!state.modified_) {
315
- maybeFreeze(rootScope, state.base_, true);
316
- return state.base_;
317
- }
318
- if (!state.finalized_) {
319
- state.finalized_ = true;
320
- state.scope_.unfinalizedDrafts_--;
321
- const result = state.copy_;
322
- let resultEach = result;
323
- let isSet2 = false;
324
- if (state.type_ === 3 /* Set */) {
325
- resultEach = new Set(result);
326
- result.clear();
327
- isSet2 = true;
328
- }
329
- each(
330
- resultEach,
331
- (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
332
- );
333
- maybeFreeze(rootScope, result, false);
334
- if (path && rootScope.patches_) {
335
- getPlugin("Patches").generatePatches_(
336
- state,
337
- path,
338
- rootScope.patches_,
339
- rootScope.inversePatches_
340
- );
341
- }
342
- }
343
- return state.copy_;
344
- }
345
- function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
346
- if (process.env.NODE_ENV !== "production" && childValue === targetObject)
347
- die(5);
348
- if (isDraft(childValue)) {
349
- const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
350
- !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
351
- const res = finalize(rootScope, childValue, path);
352
- set(targetObject, prop, res);
353
- if (isDraft(res)) {
354
- rootScope.canAutoFreeze_ = false;
355
- } else
356
- return;
357
- } else if (targetIsSet) {
358
- targetObject.add(childValue);
359
- }
360
- if (isDraftable(childValue) && !isFrozen(childValue)) {
361
- if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
362
- return;
363
- }
364
- finalize(rootScope, childValue);
365
- if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
366
- maybeFreeze(rootScope, childValue);
367
- }
368
- }
369
- function maybeFreeze(scope, value, deep = false) {
370
- if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
371
- freeze(value, deep);
372
- }
373
- }
374
-
375
- // src/core/proxy.ts
376
- function createProxyProxy(base, parent) {
377
- const isArray = Array.isArray(base);
378
- const state = {
379
- type_: isArray ? 1 /* Array */ : 0 /* Object */,
380
- // Track which produce call this is associated with.
381
- scope_: parent ? parent.scope_ : getCurrentScope(),
382
- // True for both shallow and deep changes.
383
- modified_: false,
384
- // Used during finalization.
385
- finalized_: false,
386
- // Track which properties have been assigned (true) or deleted (false).
387
- assigned_: {},
388
- // The parent draft state.
389
- parent_: parent,
390
- // The base state.
391
- base_: base,
392
- // The base proxy.
393
- draft_: null,
394
- // set below
395
- // The base copy with any updated values.
396
- copy_: null,
397
- // Called by the `produce` function.
398
- revoke_: null,
399
- isManual_: false
400
- };
401
- let target = state;
402
- let traps = objectTraps;
403
- if (isArray) {
404
- target = [state];
405
- traps = arrayTraps;
406
- }
407
- const { revoke, proxy } = Proxy.revocable(target, traps);
408
- state.draft_ = proxy;
409
- state.revoke_ = revoke;
410
- return proxy;
411
- }
412
- var objectTraps = {
413
- get(state, prop) {
414
- if (prop === DRAFT_STATE)
415
- return state;
416
- const source = latest(state);
417
- if (!has(source, prop)) {
418
- return readPropFromProto(state, source, prop);
419
- }
420
- const value = source[prop];
421
- if (state.finalized_ || !isDraftable(value)) {
422
- return value;
423
- }
424
- if (value === peek(state.base_, prop)) {
425
- prepareCopy(state);
426
- return state.copy_[prop] = createProxy(value, state);
427
- }
428
- return value;
429
- },
430
- has(state, prop) {
431
- return prop in latest(state);
432
- },
433
- ownKeys(state) {
434
- return Reflect.ownKeys(latest(state));
435
- },
436
- set(state, prop, value) {
437
- const desc = getDescriptorFromProto(latest(state), prop);
438
- if (desc?.set) {
439
- desc.set.call(state.draft_, value);
440
- return true;
441
- }
442
- if (!state.modified_) {
443
- const current2 = peek(latest(state), prop);
444
- const currentState = current2?.[DRAFT_STATE];
445
- if (currentState && currentState.base_ === value) {
446
- state.copy_[prop] = value;
447
- state.assigned_[prop] = false;
448
- return true;
449
- }
450
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
451
- return true;
452
- prepareCopy(state);
453
- markChanged(state);
454
- }
455
- if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
456
- (value !== void 0 || prop in state.copy_) || // special case: NaN
457
- Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
458
- return true;
459
- state.copy_[prop] = value;
460
- state.assigned_[prop] = true;
461
- return true;
462
- },
463
- deleteProperty(state, prop) {
464
- if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
465
- state.assigned_[prop] = false;
466
- prepareCopy(state);
467
- markChanged(state);
468
- } else {
469
- delete state.assigned_[prop];
470
- }
471
- if (state.copy_) {
472
- delete state.copy_[prop];
473
- }
474
- return true;
475
- },
476
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
477
- // the same guarantee in ES5 mode.
478
- getOwnPropertyDescriptor(state, prop) {
479
- const owner = latest(state);
480
- const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
481
- if (!desc)
482
- return desc;
483
- return {
484
- writable: true,
485
- configurable: state.type_ !== 1 /* Array */ || prop !== "length",
486
- enumerable: desc.enumerable,
487
- value: owner[prop]
488
- };
489
- },
490
- defineProperty() {
491
- die(11);
492
- },
493
- getPrototypeOf(state) {
494
- return getPrototypeOf(state.base_);
495
- },
496
- setPrototypeOf() {
497
- die(12);
498
- }
499
- };
500
- var arrayTraps = {};
501
- each(objectTraps, (key, fn) => {
502
- arrayTraps[key] = function() {
503
- arguments[0] = arguments[0][0];
504
- return fn.apply(this, arguments);
505
- };
506
- });
507
- arrayTraps.deleteProperty = function(state, prop) {
508
- if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
509
- die(13);
510
- return arrayTraps.set.call(this, state, prop, void 0);
511
- };
512
- arrayTraps.set = function(state, prop, value) {
513
- if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
514
- die(14);
515
- return objectTraps.set.call(this, state[0], prop, value, state[0]);
516
- };
517
- function peek(draft, prop) {
518
- const state = draft[DRAFT_STATE];
519
- const source = state ? latest(state) : draft;
520
- return source[prop];
521
- }
522
- function readPropFromProto(state, source, prop) {
523
- const desc = getDescriptorFromProto(source, prop);
524
- return desc ? `value` in desc ? desc.value : (
525
- // This is a very special case, if the prop is a getter defined by the
526
- // prototype, we should invoke it with the draft as context!
527
- desc.get?.call(state.draft_)
528
- ) : void 0;
529
- }
530
- function getDescriptorFromProto(source, prop) {
531
- if (!(prop in source))
532
- return void 0;
533
- let proto = getPrototypeOf(source);
534
- while (proto) {
535
- const desc = Object.getOwnPropertyDescriptor(proto, prop);
536
- if (desc)
537
- return desc;
538
- proto = getPrototypeOf(proto);
539
- }
540
- return void 0;
541
- }
542
- function markChanged(state) {
543
- if (!state.modified_) {
544
- state.modified_ = true;
545
- if (state.parent_) {
546
- markChanged(state.parent_);
547
- }
548
- }
549
- }
550
- function prepareCopy(state) {
551
- if (!state.copy_) {
552
- state.copy_ = shallowCopy(
553
- state.base_,
554
- state.scope_.immer_.useStrictShallowCopy_
555
- );
556
- }
557
- }
558
-
559
- // src/core/immerClass.ts
560
- var Immer2 = class {
561
- constructor(config) {
562
- this.autoFreeze_ = true;
563
- this.useStrictShallowCopy_ = false;
564
- /**
565
- * The `produce` function takes a value and a "recipe function" (whose
566
- * return value often depends on the base state). The recipe function is
567
- * free to mutate its first argument however it wants. All mutations are
568
- * only ever applied to a __copy__ of the base state.
569
- *
570
- * Pass only a function to create a "curried producer" which relieves you
571
- * from passing the recipe function every time.
572
- *
573
- * Only plain objects and arrays are made mutable. All other objects are
574
- * considered uncopyable.
575
- *
576
- * Note: This function is __bound__ to its `Immer` instance.
577
- *
578
- * @param {any} base - the initial state
579
- * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
580
- * @param {Function} patchListener - optional function that will be called with all the patches produced here
581
- * @returns {any} a new state, or the initial state if nothing was modified
582
- */
583
- this.produce = (base, recipe, patchListener) => {
584
- if (typeof base === "function" && typeof recipe !== "function") {
585
- const defaultBase = recipe;
586
- recipe = base;
587
- const self = this;
588
- return function curriedProduce(base2 = defaultBase, ...args) {
589
- return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
590
- };
591
- }
592
- if (typeof recipe !== "function")
593
- die(6);
594
- if (patchListener !== void 0 && typeof patchListener !== "function")
595
- die(7);
596
- let result;
597
- if (isDraftable(base)) {
598
- const scope = enterScope(this);
599
- const proxy = createProxy(base, void 0);
600
- let hasError = true;
601
- try {
602
- result = recipe(proxy);
603
- hasError = false;
604
- } finally {
605
- if (hasError)
606
- revokeScope(scope);
607
- else
608
- leaveScope(scope);
609
- }
610
- usePatchesInScope(scope, patchListener);
611
- return processResult(result, scope);
612
- } else if (!base || typeof base !== "object") {
613
- result = recipe(base);
614
- if (result === void 0)
615
- result = base;
616
- if (result === NOTHING)
617
- result = void 0;
618
- if (this.autoFreeze_)
619
- freeze(result, true);
620
- if (patchListener) {
621
- const p = [];
622
- const ip = [];
623
- getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
624
- patchListener(p, ip);
625
- }
626
- return result;
627
- } else
628
- die(1, base);
629
- };
630
- this.produceWithPatches = (base, recipe) => {
631
- if (typeof base === "function") {
632
- return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
633
- }
634
- let patches, inversePatches;
635
- const result = this.produce(base, recipe, (p, ip) => {
636
- patches = p;
637
- inversePatches = ip;
638
- });
639
- return [result, patches, inversePatches];
640
- };
641
- if (typeof config?.autoFreeze === "boolean")
642
- this.setAutoFreeze(config.autoFreeze);
643
- if (typeof config?.useStrictShallowCopy === "boolean")
644
- this.setUseStrictShallowCopy(config.useStrictShallowCopy);
645
- }
646
- createDraft(base) {
647
- if (!isDraftable(base))
648
- die(8);
649
- if (isDraft(base))
650
- base = current(base);
651
- const scope = enterScope(this);
652
- const proxy = createProxy(base, void 0);
653
- proxy[DRAFT_STATE].isManual_ = true;
654
- leaveScope(scope);
655
- return proxy;
656
- }
657
- finishDraft(draft, patchListener) {
658
- const state = draft && draft[DRAFT_STATE];
659
- if (!state || !state.isManual_)
660
- die(9);
661
- const { scope_: scope } = state;
662
- usePatchesInScope(scope, patchListener);
663
- return processResult(void 0, scope);
664
- }
665
- /**
666
- * Pass true to automatically freeze all copies created by Immer.
667
- *
668
- * By default, auto-freezing is enabled.
669
- */
670
- setAutoFreeze(value) {
671
- this.autoFreeze_ = value;
672
- }
673
- /**
674
- * Pass true to enable strict shallow copy.
675
- *
676
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
677
- */
678
- setUseStrictShallowCopy(value) {
679
- this.useStrictShallowCopy_ = value;
680
- }
681
- applyPatches(base, patches) {
682
- let i;
683
- for (i = patches.length - 1; i >= 0; i--) {
684
- const patch = patches[i];
685
- if (patch.path.length === 0 && patch.op === "replace") {
686
- base = patch.value;
687
- break;
688
- }
689
- }
690
- if (i > -1) {
691
- patches = patches.slice(i + 1);
692
- }
693
- const applyPatchesImpl = getPlugin("Patches").applyPatches_;
694
- if (isDraft(base)) {
695
- return applyPatchesImpl(base, patches);
696
- }
697
- return this.produce(
698
- base,
699
- (draft) => applyPatchesImpl(draft, patches)
700
- );
701
- }
702
- };
703
- function createProxy(value, parent) {
704
- const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
705
- const scope = parent ? parent.scope_ : getCurrentScope();
706
- scope.drafts_.push(draft);
707
- return draft;
708
- }
709
-
710
- // src/core/current.ts
711
- function current(value) {
712
- if (!isDraft(value))
713
- die(10, value);
714
- return currentImpl(value);
715
- }
716
- function currentImpl(value) {
717
- if (!isDraftable(value) || isFrozen(value))
718
- return value;
719
- const state = value[DRAFT_STATE];
720
- let copy;
721
- if (state) {
722
- if (!state.modified_)
723
- return state.base_;
724
- state.finalized_ = true;
725
- copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
726
- } else {
727
- copy = shallowCopy(value, true);
728
- }
729
- each(copy, (key, childValue) => {
730
- set(copy, key, currentImpl(childValue));
731
- });
732
- if (state) {
733
- state.finalized_ = false;
734
- }
735
- return copy;
736
- }
737
-
738
- // src/immer.ts
739
- var immer = new Immer2();
740
- var produce = immer.produce;
741
- immer.produceWithPatches.bind(
742
- immer
743
- );
744
- immer.setAutoFreeze.bind(immer);
745
- immer.setUseStrictShallowCopy.bind(immer);
746
- immer.applyPatches.bind(immer);
747
- immer.createDraft.bind(immer);
748
- immer.finishDraft.bind(immer);
749
-
750
- var __defProp = Object.defineProperty;
751
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
752
- var __publicField = (obj, key, value) => {
753
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
754
- return value;
755
- };
756
- function createController(options) {
757
- const controller = new PreviewIframeControllerImpl(options);
758
- window.__PREVIEWJS_CONTROLLER__ = controller;
759
- return controller;
760
- }
761
- class PreviewIframeControllerImpl {
762
- /**
763
- * 构造函数
764
- * @param options - 创建控制器的选项
765
- */
766
- constructor(options) {
767
- this.options = options;
768
- /**
769
- * 最后一次渲染的信息
770
- */
771
- __publicField(this, "lastRender", null);
772
- /**
773
- * 初始化状态
774
- */
775
- __publicField(this, "bootstrapStatus", "pending");
776
- /**
777
- * 期望渲染的超时定时器
778
- */
779
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
780
- __publicField(this, "expectRenderTimeout");
781
- /**
782
- * 预览 iframe 的当前状态
783
- */
784
- __publicField(this, "state", {
785
- loading: false,
786
- rendered: false,
787
- errors: [],
788
- logs: [],
789
- actions: []
790
- });
791
- /**
792
- * Vite 预更新前的日志长度
793
- */
794
- __publicField(this, "onViteBeforeUpdateLogsLength", 0);
795
- /**
796
- * Vite 预更新前的错误长度
797
- */
798
- __publicField(this, "onViteBeforeUpdateErrorsLength", 0);
799
- }
800
- /**
801
- * 渲染预览
802
- * @param previewableId - 可预览项的 ID
803
- * @param options - 渲染选项
804
- */
805
- async render(previewableId, options) {
806
- const previousRender = this.lastRender;
807
- this.lastRender = { previewableId, options };
808
- if (previousRender?.previewableId !== previewableId || this.bootstrapStatus === "failure") {
809
- this.resetIframe(previewableId);
810
- return;
811
- }
812
- const iframeWindow = this.options.getIframe()?.contentWindow;
813
- if (!iframeWindow || this.bootstrapStatus !== "success") {
814
- return;
815
- }
816
- if (!iframeWindow.__PREVIEWJS_IFRAME__.render) {
817
- iframeWindow.__PREVIEWJS_IFRAME__.reportEvent({
818
- kind: "error",
819
- source: "renderer",
820
- message: "Iframe was bootstrapped but not fully initialised.\n\nPlease report this at https://github.com/fwouts/previewjs."
821
- });
822
- return;
823
- }
824
- const renderPromise = iframeWindow.__PREVIEWJS_IFRAME__.render(options);
825
- this.clearExpectRenderTimeout();
826
- this.expectRenderTimeout = setTimeout(() => {
827
- console.warn(
828
- "Expected render did not occur after 5 seconds. Reloading iframe..."
829
- );
830
- this.resetIframe(previewableId);
831
- }, 5e3);
832
- await renderPromise;
833
- }
834
- /**
835
- * 重置 iframe
836
- * @param id - 可预览项的 ID
837
- */
838
- resetIframe(id) {
839
- const iframe = this.options.getIframe();
840
- if (!iframe) {
841
- return;
842
- }
843
- iframe.src = `/${id}/?t=${Date.now()}`;
844
- this.bootstrapStatus = "not-started";
845
- }
846
- /**
847
- * 处理预览事件
848
- * @param event - 预览事件对象
849
- */
850
- onPreviewEvent(event) {
851
- if (this.bootstrapStatus === "not-started") {
852
- if (event.kind !== "bootstrapping") {
853
- return;
854
- }
855
- }
856
- switch (event.kind) {
857
- case "bootstrapping":
858
- this.bootstrapStatus = "pending";
859
- break;
860
- case "bootstrapped":
861
- this.bootstrapStatus = "success";
862
- this.onViteBeforeUpdateLogsLength = 0;
863
- this.onViteBeforeUpdateErrorsLength = 0;
864
- this.updateState((state) => {
865
- state.loading = true;
866
- state.rendered = false;
867
- state.errors = [];
868
- state.logs = [];
869
- });
870
- if (this.lastRender) {
871
- this.render(
872
- this.lastRender.previewableId,
873
- this.lastRender.options
874
- ).catch(
875
- // eslint-disable-next-line no-console
876
- console.error
877
- );
878
- }
879
- break;
880
- case "vite-before-reload":
881
- this.updateState((state) => {
882
- state.logs = [];
883
- state.errors = [];
884
- });
885
- if (this.lastRender) {
886
- this.resetIframe(this.lastRender.previewableId);
887
- }
888
- break;
889
- case "vite-before-update":
890
- this.onViteBeforeUpdateLogsLength = this.state.logs.length;
891
- this.updateState((state) => {
892
- for (const update of event.payload.updates) {
893
- state.errors = state.errors.filter(
894
- (e) => e.source !== "hmr" || e.modulePath !== update.acceptedPath
895
- );
896
- }
897
- });
898
- this.onViteBeforeUpdateErrorsLength = this.state.errors.length;
899
- break;
900
- case "vite-invalidate":
901
- this.updateState((state) => {
902
- this.onViteBeforeUpdateLogsLength = 0;
903
- this.onViteBeforeUpdateErrorsLength = 0;
904
- state.logs = [];
905
- });
906
- break;
907
- case "vite-after-update":
908
- this.updateState((state) => {
909
- const logsSliceStart = this.onViteBeforeUpdateLogsLength;
910
- const errorsSliceStart = this.onViteBeforeUpdateErrorsLength;
911
- this.onViteBeforeUpdateLogsLength = 0;
912
- this.onViteBeforeUpdateErrorsLength = 0;
913
- state.logs = state.logs.slice(logsSliceStart);
914
- state.errors = state.errors.slice(errorsSliceStart);
915
- });
916
- break;
917
- case "before-render":
918
- this.updateState((state) => {
919
- this.onViteBeforeUpdateLogsLength = 0;
920
- state.logs = [];
921
- });
922
- break;
923
- case "rendered": {
924
- this.updateState((state) => {
925
- state.loading = false;
926
- state.rendered = true;
927
- });
928
- this.clearExpectRenderTimeout();
929
- break;
930
- }
931
- case "error":
932
- this.updateState((state) => {
933
- state.loading = false;
934
- if (event.source === "vite" && event.message.includes(
935
- "Failed to fetch dynamically imported module"
936
- ) && state.errors.find((e) => e.source === "vite")) {
937
- return;
938
- }
939
- state.errors = state.errors.filter((e) => e.source !== event.source);
940
- state.errors.push(event);
941
- });
942
- this.clearExpectRenderTimeout();
943
- if (this.bootstrapStatus === "pending") {
944
- this.bootstrapStatus = "failure";
945
- }
946
- break;
947
- case "log-message":
948
- this.updateState((state) => {
949
- state.logs.push(event);
950
- });
951
- break;
952
- case "action":
953
- this.updateState((state) => {
954
- state.actions.push(event);
955
- });
956
- break;
957
- case "toggle-inspect": {
958
- console.log("\u89E6\u53D1toggle-inspect", event.enabled);
959
- const window2 = this.options.getIframe()?.contentWindow;
960
- if (window2) {
961
- window2.__PREVIEWJS_IFRAME__.toggleInspect = event.enabled;
962
- window2.__PREVIEWJS_IFRAME__.refresh({
963
- refetchWrapperModule: true
964
- });
965
- }
966
- break;
967
- }
968
- default:
969
- throw assertNever_2(event);
970
- }
971
- }
972
- /**
973
- * 更新状态
974
- * @param stateModifier - 状态修改函数
975
- */
976
- updateState(stateModifier) {
977
- this.state = produce(this.state, stateModifier);
978
- this.options.onStateUpdate?.(this.state);
979
- }
980
- /**
981
- * 清除期望渲染的超时定时器
982
- */
983
- clearExpectRenderTimeout() {
984
- if (this.expectRenderTimeout) {
985
- clearTimeout(this.expectRenderTimeout);
986
- this.expectRenderTimeout = null;
987
- }
988
- }
989
- }
990
-
991
- export { createController };
1
+ var z={};Object.defineProperty(z,"__esModule",{value:!0});var Y=z.assertNever=U;function U(e,t){if(typeof t=="string")throw new Error(t);if(typeof t=="function")throw new Error(t(e));if(t)return e;throw new Error("Unhandled discriminated union member: ".concat(JSON.stringify(e)))}z.default=U;var V=Symbol.for("immer-nothing"),B=Symbol.for("immer-draftable"),f=Symbol.for("immer-state"),Z=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){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 '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function c(e,...t){if(process.env.NODE_ENV!=="production"){const r=Z[e],n=typeof r=="function"?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var _=Object.getPrototypeOf;function y(e){return!!e&&!!e[f]}function l(e){return e?M(e)||Array.isArray(e)||!!e[B]||!!e.constructor?.[B]||w(e)||S(e):!1}var ee=Object.prototype.constructor.toString();function M(e){if(!e||typeof e!="object")return!1;const t=_(e);if(t===null)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===ee}function E(e,t){P(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function P(e){const t=e[f];return t?t.type_:Array.isArray(e)?1:w(e)?2:S(e)?3:0}function F(e,t){return P(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function W(e,t,r){const n=P(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function te(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function w(e){return e instanceof Map}function S(e){return e instanceof Set}function h(e){return e.copy_||e.base_}function D(e,t){if(w(e))return new Map(e);if(S(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=M(e);if(t===!0||t==="class_only"&&!r){const n=Object.getOwnPropertyDescriptors(e);delete n[f];let i=Reflect.ownKeys(n);for(let o=0;o<i.length;o++){const s=i[o],a=n[s];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(n[s]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[s]})}return Object.create(_(e),n)}else{const n=_(e);if(n!==null&&r)return{...e};const i=Object.create(n);return Object.assign(i,e)}}function O(e,t=!1){return v(e)||y(e)||!l(e)||(P(e)>1&&(e.set=e.add=e.clear=e.delete=re),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>O(n,!0))),e}function re(){c(2)}function v(e){return Object.isFrozen(e)}var ne={};function p(e){const t=ne[e];return t||c(0,e),t}var g;function j(){return g}function ie(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function $(e,t){t&&(p("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function k(e){A(e),e.drafts_.forEach(oe),e.drafts_=null}function A(e){e===g&&(g=e.parent_)}function J(e){return g=ie(g,e)}function oe(e){const t=e[f];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function K(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];return e!==void 0&&e!==r?(r[f].modified_&&(k(t),c(4)),l(e)&&(e=R(t,e),t.parent_||I(t,e)),t.patches_&&p("Patches").generateReplacementPatches_(r[f].base_,e,t.patches_,t.inversePatches_)):e=R(t,r,[]),k(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==V?e:void 0}function R(e,t,r){if(v(t))return t;const n=t[f];if(!n)return E(t,(i,o)=>G(e,n,t,i,o,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return I(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const i=n.copy_;let o=i,s=!1;n.type_===3&&(o=new Set(i),i.clear(),s=!0),E(o,(a,d)=>G(e,n,i,a,d,r,s)),I(e,i,!1),r&&e.patches_&&p("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function G(e,t,r,n,i,o,s){if(process.env.NODE_ENV!=="production"&&i===r&&c(5),y(i)){const a=o&&t&&t.type_!==3&&!F(t.assigned_,n)?o.concat(n):void 0,d=R(e,i,a);if(W(r,n,d),y(d))e.canAutoFreeze_=!1;else return}else s&&r.add(i);if(l(i)&&!v(i)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;R(e,i),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&I(e,i)}}function I(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&O(t,r)}function se(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:j(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let i=n,o=N;r&&(i=[n],o=b);const{revoke:s,proxy:a}=Proxy.revocable(i,o);return n.draft_=a,n.revoke_=s,a}var N={get(e,t){if(t===f)return e;const r=h(e);if(!F(r,t))return ae(e,r,t);const n=r[t];return e.finalized_||!l(n)?n:n===L(e.base_,t)?(x(e),e.copy_[t]=C(n,e)):n},has(e,t){return t in h(e)},ownKeys(e){return Reflect.ownKeys(h(e))},set(e,t,r){const n=H(h(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const i=L(h(e),t),o=i?.[f];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(te(r,i)&&(r!==void 0||F(e.base_,t)))return!0;x(e),T(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return L(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,x(e),T(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const r=h(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){c(11)},getPrototypeOf(e){return _(e.base_)},setPrototypeOf(){c(12)}},b={};E(N,(e,t)=>{b[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),b.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&c(13),b.set.call(this,e,t,void 0)},b.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&c(14),N.set.call(this,e[0],t,r,e[0])};function L(e,t){const r=e[f];return(r?h(r):e)[t]}function ae(e,t,r){const n=H(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function H(e,t){if(!(t in e))return;let r=_(e);for(;r;){const n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=_(r)}}function T(e){e.modified_||(e.modified_=!0,e.parent_&&T(e.parent_))}function x(e){e.copy_||(e.copy_=D(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var ce=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){const o=r;r=t;const s=this;return function(d=o,...q){return s.produce(d,Q=>r.call(this,Q,...q))}}typeof r!="function"&&c(6),n!==void 0&&typeof n!="function"&&c(7);let i;if(l(t)){const o=J(this),s=C(t,void 0);let a=!0;try{i=r(s),a=!1}finally{a?k(o):A(o)}return $(o,n),K(i,o)}else if(!t||typeof t!="object"){if(i=r(t),i===void 0&&(i=t),i===V&&(i=void 0),this.autoFreeze_&&O(i,!0),n){const o=[],s=[];p("Patches").generateReplacementPatches_(t,i,o,s),n(o,s)}return i}else c(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(s,...a)=>this.produceWithPatches(s,d=>t(d,...a));let n,i;return[this.produce(t,r,(s,a)=>{n=s,i=a}),n,i]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){l(e)||c(8),y(e)&&(e=fe(e));const t=J(this),r=C(e,void 0);return r[f].isManual_=!0,A(t),r}finishDraft(e,t){const r=e&&e[f];(!r||!r.isManual_)&&c(9);const{scope_:n}=r;return $(n,t),K(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const i=t[r];if(i.path.length===0&&i.op==="replace"){e=i.value;break}}r>-1&&(t=t.slice(r+1));const n=p("Patches").applyPatches_;return y(e)?n(e,t):this.produce(e,i=>n(i,t))}};function C(e,t){const r=w(e)?p("MapSet").proxyMap_(e,t):S(e)?p("MapSet").proxySet_(e,t):se(e,t);return(t?t.scope_:j()).drafts_.push(r),r}function fe(e){return y(e)||c(10,e),X(e)}function X(e){if(!l(e)||v(e))return e;const t=e[f];let r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=D(e,t.scope_.immer_.useStrictShallowCopy_)}else r=D(e,!0);return E(r,(n,i)=>{W(r,n,X(i))}),t&&(t.finalized_=!1),r}var u=new ce,ue=u.produce;u.produceWithPatches.bind(u),u.setAutoFreeze.bind(u),u.setUseStrictShallowCopy.bind(u),u.applyPatches.bind(u),u.createDraft.bind(u),u.finishDraft.bind(u);var de=Object.defineProperty,le=(e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,m=(e,t,r)=>(le(e,typeof t!="symbol"?t+"":t,r),r);function he(e){const t=new pe(e);return window.__PREVIEWJS_CONTROLLER__=t,t}class pe{constructor(t){this.options=t,m(this,"lastRender",null),m(this,"bootstrapStatus","pending"),m(this,"expectRenderTimeout"),m(this,"state",{loading:!1,rendered:!1,errors:[],logs:[],actions:[]}),m(this,"onViteBeforeUpdateLogsLength",0),m(this,"onViteBeforeUpdateErrorsLength",0)}async render(t,r){const n=this.lastRender;if(this.lastRender={previewableId:t,options:r},n?.previewableId!==t||this.bootstrapStatus==="failure"){this.resetIframe(t);return}const i=this.options.getIframe()?.contentWindow;if(!i||this.bootstrapStatus!=="success")return;if(!i.__PREVIEWJS_IFRAME__.render){i.__PREVIEWJS_IFRAME__.reportEvent({kind:"error",source:"renderer",message:"Iframe was bootstrapped but not fully initialised."});return}const o=i.__PREVIEWJS_IFRAME__.render(r);this.clearExpectRenderTimeout(),this.expectRenderTimeout=setTimeout(()=>{console.warn("Expected render did not occur after 5 seconds. Reloading iframe..."),this.resetIframe(t)},5e3),await o}resetIframe(t){const r=this.options.getIframe();r&&(r.src=`/${t}/?t=${Date.now()}`,this.bootstrapStatus="not-started")}onPreviewEvent(t){if(!(this.bootstrapStatus==="not-started"&&t.kind!=="bootstrapping"))switch(t.kind){case"bootstrapping":this.bootstrapStatus="pending";break;case"bootstrapped":this.bootstrapStatus="success",this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,this.updateState(r=>{r.loading=!0,r.rendered=!1,r.errors=[],r.logs=[]}),this.lastRender&&this.render(this.lastRender.previewableId,this.lastRender.options).catch(console.error);break;case"vite-before-reload":this.updateState(r=>{r.logs=[],r.errors=[]}),this.lastRender&&this.resetIframe(this.lastRender.previewableId);break;case"vite-before-update":this.onViteBeforeUpdateLogsLength=this.state.logs.length,this.updateState(r=>{for(const n of t.payload.updates)r.errors=r.errors.filter(i=>i.source!=="hmr"||i.modulePath!==n.acceptedPath)}),this.onViteBeforeUpdateErrorsLength=this.state.errors.length;break;case"vite-invalidate":this.updateState(r=>{this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,r.logs=[]});break;case"vite-after-update":this.updateState(r=>{const n=this.onViteBeforeUpdateLogsLength,i=this.onViteBeforeUpdateErrorsLength;this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,r.logs=r.logs.slice(n),r.errors=r.errors.slice(i)});break;case"before-render":this.updateState(r=>{this.onViteBeforeUpdateLogsLength=0,r.logs=[]});break;case"rendered":{this.updateState(r=>{r.loading=!1,r.rendered=!0}),this.clearExpectRenderTimeout();break}case"error":this.updateState(r=>{r.loading=!1,!(t.source==="vite"&&t.message.includes("Failed to fetch dynamically imported module")&&r.errors.find(n=>n.source==="vite"))&&(r.errors=r.errors.filter(n=>n.source!==t.source),r.errors.push(t))}),this.clearExpectRenderTimeout(),this.bootstrapStatus==="pending"&&(this.bootstrapStatus="failure");break;case"log-message":this.updateState(r=>{r.logs.push(t)});break;case"action":this.updateState(r=>{r.actions.push(t)});break;case"toggle-inspect":{console.log("\u89E6\u53D1toggle-inspect",t.enabled);const r=this.options.getIframe()?.contentWindow;r&&(r.__PREVIEWJS_IFRAME__.toggleInspect=t.enabled,r.__PREVIEWJS_IFRAME__.refresh({refetchWrapperModule:!0}));break}default:throw Y(t)}}updateState(t){this.state=ue(this.state,t),this.options.onStateUpdate?.(this.state)}clearExpectRenderTimeout(){this.expectRenderTimeout&&(clearTimeout(this.expectRenderTimeout),this.expectRenderTimeout=null)}}export{he as createController};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfp-studio/iframe",
3
- "version": "18.0.0",
3
+ "version": "18.0.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -17,6 +17,7 @@
17
17
  "vite": "6.2.0"
18
18
  },
19
19
  "scripts": {
20
- "build": "tsc && unbuild"
20
+ "build": "tsc && unbuild",
21
+ "release": "tsc && unbuild --minify"
21
22
  }
22
23
  }
@@ -52,11 +52,16 @@ export async function runRenderer({
52
52
  if (shouldAbortRender()) {
53
53
  return;
54
54
  }
55
+ // Fix: break transformFunctions(properties || presetProps, []) into 2 parts
56
+ // 1. transformFunctions(properties, [])
57
+ // 2. transformFunctions(presetProps, [])
55
58
  await render(({ presetProps, presetGlobalProps }) => ({
56
59
  ...transformFunctions(autogenCallbackProps, []),
57
60
  ...transformFunctions(presetGlobalProps, []),
58
- ...transformFunctions(properties || presetProps, []),
61
+ ...transformFunctions(properties, []),
62
+ ...transformFunctions(presetProps, []),
59
63
  }));
64
+
60
65
  if (shouldAbortRender()) {
61
66
  return;
62
67
  }