rumious 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs.js +1 -2648
- package/dist/index.cjs.min.js +1 -720
- package/dist/index.esm.js +1 -2637
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -710
- package/dist/index.js +1 -2653
- package/dist/index.min.js +1 -725
- package/package.json +2 -4
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.esm.js
CHANGED
@@ -1,2638 +1,2 @@
|
|
1
|
-
function _arrayLikeToArray(r, a) {
|
2
|
-
(null == a || a > r.length) && (a = r.length);
|
3
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
4
|
-
return n;
|
5
|
-
}
|
6
|
-
function _arrayWithHoles(r) {
|
7
|
-
if (Array.isArray(r)) return r;
|
8
|
-
}
|
9
|
-
function _assertThisInitialized(e) {
|
10
|
-
if (undefined === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
11
|
-
return e;
|
12
|
-
}
|
13
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
14
|
-
try {
|
15
|
-
var i = n[a](c),
|
16
|
-
u = i.value;
|
17
|
-
} catch (n) {
|
18
|
-
return void e(n);
|
19
|
-
}
|
20
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
21
|
-
}
|
22
|
-
function _asyncToGenerator(n) {
|
23
|
-
return function () {
|
24
|
-
var t = this,
|
25
|
-
e = arguments;
|
26
|
-
return new Promise(function (r, o) {
|
27
|
-
var a = n.apply(t, e);
|
28
|
-
function _next(n) {
|
29
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
30
|
-
}
|
31
|
-
function _throw(n) {
|
32
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
33
|
-
}
|
34
|
-
_next(undefined);
|
35
|
-
});
|
36
|
-
};
|
37
|
-
}
|
38
|
-
function _callSuper(t, o, e) {
|
39
|
-
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
40
|
-
}
|
41
|
-
function _classCallCheck(a, n) {
|
42
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
43
|
-
}
|
44
|
-
function _construct(t, e, r) {
|
45
|
-
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
46
|
-
var o = [null];
|
47
|
-
o.push.apply(o, e);
|
48
|
-
var p = new (t.bind.apply(t, o))();
|
49
|
-
return r && _setPrototypeOf(p, r.prototype), p;
|
50
|
-
}
|
51
|
-
function _defineProperties(e, r) {
|
52
|
-
for (var t = 0; t < r.length; t++) {
|
53
|
-
var o = r[t];
|
54
|
-
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
function _createClass(e, r, t) {
|
58
|
-
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
59
|
-
writable: false
|
60
|
-
}), e;
|
61
|
-
}
|
62
|
-
function _createForOfIteratorHelper(r, e) {
|
63
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
64
|
-
if (!t) {
|
65
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
66
|
-
t && (r = t);
|
67
|
-
var n = 0,
|
68
|
-
F = function () {};
|
69
|
-
return {
|
70
|
-
s: F,
|
71
|
-
n: function () {
|
72
|
-
return n >= r.length ? {
|
73
|
-
done: true
|
74
|
-
} : {
|
75
|
-
done: false,
|
76
|
-
value: r[n++]
|
77
|
-
};
|
78
|
-
},
|
79
|
-
e: function (r) {
|
80
|
-
throw r;
|
81
|
-
},
|
82
|
-
f: F
|
83
|
-
};
|
84
|
-
}
|
85
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
86
|
-
}
|
87
|
-
var o,
|
88
|
-
a = true,
|
89
|
-
u = false;
|
90
|
-
return {
|
91
|
-
s: function () {
|
92
|
-
t = t.call(r);
|
93
|
-
},
|
94
|
-
n: function () {
|
95
|
-
var r = t.next();
|
96
|
-
return a = r.done, r;
|
97
|
-
},
|
98
|
-
e: function (r) {
|
99
|
-
u = true, o = r;
|
100
|
-
},
|
101
|
-
f: function () {
|
102
|
-
try {
|
103
|
-
a || null == t.return || t.return();
|
104
|
-
} finally {
|
105
|
-
if (u) throw o;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
};
|
109
|
-
}
|
110
|
-
function _defineProperty(e, r, t) {
|
111
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
112
|
-
value: t,
|
113
|
-
enumerable: true,
|
114
|
-
configurable: true,
|
115
|
-
writable: true
|
116
|
-
}) : e[r] = t, e;
|
117
|
-
}
|
118
|
-
function _getPrototypeOf(t) {
|
119
|
-
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
120
|
-
return t.__proto__ || Object.getPrototypeOf(t);
|
121
|
-
}, _getPrototypeOf(t);
|
122
|
-
}
|
123
|
-
function _inherits(t, e) {
|
124
|
-
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
125
|
-
t.prototype = Object.create(e && e.prototype, {
|
126
|
-
constructor: {
|
127
|
-
value: t,
|
128
|
-
writable: true,
|
129
|
-
configurable: true
|
130
|
-
}
|
131
|
-
}), Object.defineProperty(t, "prototype", {
|
132
|
-
writable: false
|
133
|
-
}), e && _setPrototypeOf(t, e);
|
134
|
-
}
|
135
|
-
function _isNativeFunction(t) {
|
136
|
-
try {
|
137
|
-
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
138
|
-
} catch (n) {
|
139
|
-
return "function" == typeof t;
|
140
|
-
}
|
141
|
-
}
|
142
|
-
function _isNativeReflectConstruct() {
|
143
|
-
try {
|
144
|
-
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
145
|
-
} catch (t) {}
|
146
|
-
return (_isNativeReflectConstruct = function () {
|
147
|
-
return !!t;
|
148
|
-
})();
|
149
|
-
}
|
150
|
-
function _iterableToArrayLimit(r, l) {
|
151
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
152
|
-
if (null != t) {
|
153
|
-
var e,
|
154
|
-
n,
|
155
|
-
i,
|
156
|
-
u,
|
157
|
-
a = [],
|
158
|
-
f = true,
|
159
|
-
o = false;
|
160
|
-
try {
|
161
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
162
|
-
if (Object(t) !== t) return;
|
163
|
-
f = !1;
|
164
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
165
|
-
} catch (r) {
|
166
|
-
o = true, n = r;
|
167
|
-
} finally {
|
168
|
-
try {
|
169
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
170
|
-
} finally {
|
171
|
-
if (o) throw n;
|
172
|
-
}
|
173
|
-
}
|
174
|
-
return a;
|
175
|
-
}
|
176
|
-
}
|
177
|
-
function _nonIterableRest() {
|
178
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
179
|
-
}
|
180
|
-
function ownKeys(e, r) {
|
181
|
-
var t = Object.keys(e);
|
182
|
-
if (Object.getOwnPropertySymbols) {
|
183
|
-
var o = Object.getOwnPropertySymbols(e);
|
184
|
-
r && (o = o.filter(function (r) {
|
185
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
186
|
-
})), t.push.apply(t, o);
|
187
|
-
}
|
188
|
-
return t;
|
189
|
-
}
|
190
|
-
function _objectSpread2(e) {
|
191
|
-
for (var r = 1; r < arguments.length; r++) {
|
192
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
193
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
194
|
-
_defineProperty(e, r, t[r]);
|
195
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
196
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
197
|
-
});
|
198
|
-
}
|
199
|
-
return e;
|
200
|
-
}
|
201
|
-
function _possibleConstructorReturn(t, e) {
|
202
|
-
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
203
|
-
if (undefined !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
204
|
-
return _assertThisInitialized(t);
|
205
|
-
}
|
206
|
-
function _regeneratorRuntime() {
|
207
|
-
_regeneratorRuntime = function () {
|
208
|
-
return e;
|
209
|
-
};
|
210
|
-
var t,
|
211
|
-
e = {},
|
212
|
-
r = Object.prototype,
|
213
|
-
n = r.hasOwnProperty,
|
214
|
-
o = Object.defineProperty || function (t, e, r) {
|
215
|
-
t[e] = r.value;
|
216
|
-
},
|
217
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
218
|
-
a = i.iterator || "@@iterator",
|
219
|
-
c = i.asyncIterator || "@@asyncIterator",
|
220
|
-
u = i.toStringTag || "@@toStringTag";
|
221
|
-
function define(t, e, r) {
|
222
|
-
return Object.defineProperty(t, e, {
|
223
|
-
value: r,
|
224
|
-
enumerable: true,
|
225
|
-
configurable: true,
|
226
|
-
writable: true
|
227
|
-
}), t[e];
|
228
|
-
}
|
229
|
-
try {
|
230
|
-
define({}, "");
|
231
|
-
} catch (t) {
|
232
|
-
define = function (t, e, r) {
|
233
|
-
return t[e] = r;
|
234
|
-
};
|
235
|
-
}
|
236
|
-
function wrap(t, e, r, n) {
|
237
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
238
|
-
a = Object.create(i.prototype),
|
239
|
-
c = new Context(n || []);
|
240
|
-
return o(a, "_invoke", {
|
241
|
-
value: makeInvokeMethod(t, r, c)
|
242
|
-
}), a;
|
243
|
-
}
|
244
|
-
function tryCatch(t, e, r) {
|
245
|
-
try {
|
246
|
-
return {
|
247
|
-
type: "normal",
|
248
|
-
arg: t.call(e, r)
|
249
|
-
};
|
250
|
-
} catch (t) {
|
251
|
-
return {
|
252
|
-
type: "throw",
|
253
|
-
arg: t
|
254
|
-
};
|
255
|
-
}
|
256
|
-
}
|
257
|
-
e.wrap = wrap;
|
258
|
-
var h = "suspendedStart",
|
259
|
-
l = "suspendedYield",
|
260
|
-
f = "executing",
|
261
|
-
s = "completed",
|
262
|
-
y = {};
|
263
|
-
function Generator() {}
|
264
|
-
function GeneratorFunction() {}
|
265
|
-
function GeneratorFunctionPrototype() {}
|
266
|
-
var p = {};
|
267
|
-
define(p, a, function () {
|
268
|
-
return this;
|
269
|
-
});
|
270
|
-
var d = Object.getPrototypeOf,
|
271
|
-
v = d && d(d(values([])));
|
272
|
-
v && v !== r && n.call(v, a) && (p = v);
|
273
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
274
|
-
function defineIteratorMethods(t) {
|
275
|
-
["next", "throw", "return"].forEach(function (e) {
|
276
|
-
define(t, e, function (t) {
|
277
|
-
return this._invoke(e, t);
|
278
|
-
});
|
279
|
-
});
|
280
|
-
}
|
281
|
-
function AsyncIterator(t, e) {
|
282
|
-
function invoke(r, o, i, a) {
|
283
|
-
var c = tryCatch(t[r], t, o);
|
284
|
-
if ("throw" !== c.type) {
|
285
|
-
var u = c.arg,
|
286
|
-
h = u.value;
|
287
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
288
|
-
invoke("next", t, i, a);
|
289
|
-
}, function (t) {
|
290
|
-
invoke("throw", t, i, a);
|
291
|
-
}) : e.resolve(h).then(function (t) {
|
292
|
-
u.value = t, i(u);
|
293
|
-
}, function (t) {
|
294
|
-
return invoke("throw", t, i, a);
|
295
|
-
});
|
296
|
-
}
|
297
|
-
a(c.arg);
|
298
|
-
}
|
299
|
-
var r;
|
300
|
-
o(this, "_invoke", {
|
301
|
-
value: function (t, n) {
|
302
|
-
function callInvokeWithMethodAndArg() {
|
303
|
-
return new e(function (e, r) {
|
304
|
-
invoke(t, n, e, r);
|
305
|
-
});
|
306
|
-
}
|
307
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
308
|
-
}
|
309
|
-
});
|
310
|
-
}
|
311
|
-
function makeInvokeMethod(e, r, n) {
|
312
|
-
var o = h;
|
313
|
-
return function (i, a) {
|
314
|
-
if (o === f) throw Error("Generator is already running");
|
315
|
-
if (o === s) {
|
316
|
-
if ("throw" === i) throw a;
|
317
|
-
return {
|
318
|
-
value: t,
|
319
|
-
done: true
|
320
|
-
};
|
321
|
-
}
|
322
|
-
for (n.method = i, n.arg = a;;) {
|
323
|
-
var c = n.delegate;
|
324
|
-
if (c) {
|
325
|
-
var u = maybeInvokeDelegate(c, n);
|
326
|
-
if (u) {
|
327
|
-
if (u === y) continue;
|
328
|
-
return u;
|
329
|
-
}
|
330
|
-
}
|
331
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
332
|
-
if (o === h) throw o = s, n.arg;
|
333
|
-
n.dispatchException(n.arg);
|
334
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
335
|
-
o = f;
|
336
|
-
var p = tryCatch(e, r, n);
|
337
|
-
if ("normal" === p.type) {
|
338
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
339
|
-
return {
|
340
|
-
value: p.arg,
|
341
|
-
done: n.done
|
342
|
-
};
|
343
|
-
}
|
344
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
345
|
-
}
|
346
|
-
};
|
347
|
-
}
|
348
|
-
function maybeInvokeDelegate(e, r) {
|
349
|
-
var n = r.method,
|
350
|
-
o = e.iterator[n];
|
351
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
352
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
353
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
354
|
-
var a = i.arg;
|
355
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
356
|
-
}
|
357
|
-
function pushTryEntry(t) {
|
358
|
-
var e = {
|
359
|
-
tryLoc: t[0]
|
360
|
-
};
|
361
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
362
|
-
}
|
363
|
-
function resetTryEntry(t) {
|
364
|
-
var e = t.completion || {};
|
365
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
366
|
-
}
|
367
|
-
function Context(t) {
|
368
|
-
this.tryEntries = [{
|
369
|
-
tryLoc: "root"
|
370
|
-
}], t.forEach(pushTryEntry, this), this.reset(true);
|
371
|
-
}
|
372
|
-
function values(e) {
|
373
|
-
if (e || "" === e) {
|
374
|
-
var r = e[a];
|
375
|
-
if (r) return r.call(e);
|
376
|
-
if ("function" == typeof e.next) return e;
|
377
|
-
if (!isNaN(e.length)) {
|
378
|
-
var o = -1,
|
379
|
-
i = function next() {
|
380
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = false, next;
|
381
|
-
return next.value = t, next.done = true, next;
|
382
|
-
};
|
383
|
-
return i.next = i;
|
384
|
-
}
|
385
|
-
}
|
386
|
-
throw new TypeError(typeof e + " is not iterable");
|
387
|
-
}
|
388
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
389
|
-
value: GeneratorFunctionPrototype,
|
390
|
-
configurable: true
|
391
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
392
|
-
value: GeneratorFunction,
|
393
|
-
configurable: true
|
394
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
395
|
-
var e = "function" == typeof t && t.constructor;
|
396
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
397
|
-
}, e.mark = function (t) {
|
398
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
399
|
-
}, e.awrap = function (t) {
|
400
|
-
return {
|
401
|
-
__await: t
|
402
|
-
};
|
403
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
404
|
-
return this;
|
405
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
406
|
-
undefined === i && (i = Promise);
|
407
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
408
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
409
|
-
return t.done ? t.value : a.next();
|
410
|
-
});
|
411
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
412
|
-
return this;
|
413
|
-
}), define(g, "toString", function () {
|
414
|
-
return "[object Generator]";
|
415
|
-
}), e.keys = function (t) {
|
416
|
-
var e = Object(t),
|
417
|
-
r = [];
|
418
|
-
for (var n in e) r.push(n);
|
419
|
-
return r.reverse(), function next() {
|
420
|
-
for (; r.length;) {
|
421
|
-
var t = r.pop();
|
422
|
-
if (t in e) return next.value = t, next.done = false, next;
|
423
|
-
}
|
424
|
-
return next.done = true, next;
|
425
|
-
};
|
426
|
-
}, e.values = values, Context.prototype = {
|
427
|
-
constructor: Context,
|
428
|
-
reset: function (e) {
|
429
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = false, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
430
|
-
},
|
431
|
-
stop: function () {
|
432
|
-
this.done = true;
|
433
|
-
var t = this.tryEntries[0].completion;
|
434
|
-
if ("throw" === t.type) throw t.arg;
|
435
|
-
return this.rval;
|
436
|
-
},
|
437
|
-
dispatchException: function (e) {
|
438
|
-
if (this.done) throw e;
|
439
|
-
var r = this;
|
440
|
-
function handle(n, o) {
|
441
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
442
|
-
}
|
443
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
444
|
-
var i = this.tryEntries[o],
|
445
|
-
a = i.completion;
|
446
|
-
if ("root" === i.tryLoc) return handle("end");
|
447
|
-
if (i.tryLoc <= this.prev) {
|
448
|
-
var c = n.call(i, "catchLoc"),
|
449
|
-
u = n.call(i, "finallyLoc");
|
450
|
-
if (c && u) {
|
451
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
|
452
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
453
|
-
} else if (c) {
|
454
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
|
455
|
-
} else {
|
456
|
-
if (!u) throw Error("try statement without catch or finally");
|
457
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
458
|
-
}
|
459
|
-
}
|
460
|
-
}
|
461
|
-
},
|
462
|
-
abrupt: function (t, e) {
|
463
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
464
|
-
var o = this.tryEntries[r];
|
465
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
466
|
-
var i = o;
|
467
|
-
break;
|
468
|
-
}
|
469
|
-
}
|
470
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
471
|
-
var a = i ? i.completion : {};
|
472
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
473
|
-
},
|
474
|
-
complete: function (t, e) {
|
475
|
-
if ("throw" === t.type) throw t.arg;
|
476
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
477
|
-
},
|
478
|
-
finish: function (t) {
|
479
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
480
|
-
var r = this.tryEntries[e];
|
481
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
482
|
-
}
|
483
|
-
},
|
484
|
-
catch: function (t) {
|
485
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
486
|
-
var r = this.tryEntries[e];
|
487
|
-
if (r.tryLoc === t) {
|
488
|
-
var n = r.completion;
|
489
|
-
if ("throw" === n.type) {
|
490
|
-
var o = n.arg;
|
491
|
-
resetTryEntry(r);
|
492
|
-
}
|
493
|
-
return o;
|
494
|
-
}
|
495
|
-
}
|
496
|
-
throw Error("illegal catch attempt");
|
497
|
-
},
|
498
|
-
delegateYield: function (e, r, n) {
|
499
|
-
return this.delegate = {
|
500
|
-
iterator: values(e),
|
501
|
-
resultName: r,
|
502
|
-
nextLoc: n
|
503
|
-
}, "next" === this.method && (this.arg = t), y;
|
504
|
-
}
|
505
|
-
}, e;
|
506
|
-
}
|
507
|
-
function _setPrototypeOf(t, e) {
|
508
|
-
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
509
|
-
return t.__proto__ = e, t;
|
510
|
-
}, _setPrototypeOf(t, e);
|
511
|
-
}
|
512
|
-
function _slicedToArray(r, e) {
|
513
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
514
|
-
}
|
515
|
-
function _toPrimitive(t, r) {
|
516
|
-
if ("object" != typeof t || !t) return t;
|
517
|
-
var e = t[Symbol.toPrimitive];
|
518
|
-
if (undefined !== e) {
|
519
|
-
var i = e.call(t, r || "default");
|
520
|
-
if ("object" != typeof i) return i;
|
521
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
522
|
-
}
|
523
|
-
return ("string" === r ? String : Number)(t);
|
524
|
-
}
|
525
|
-
function _toPropertyKey(t) {
|
526
|
-
var i = _toPrimitive(t, "string");
|
527
|
-
return "symbol" == typeof i ? i : i + "";
|
528
|
-
}
|
529
|
-
function _typeof(o) {
|
530
|
-
"@babel/helpers - typeof";
|
531
|
-
|
532
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
533
|
-
return typeof o;
|
534
|
-
} : function (o) {
|
535
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
536
|
-
}, _typeof(o);
|
537
|
-
}
|
538
|
-
function _unsupportedIterableToArray(r, a) {
|
539
|
-
if (r) {
|
540
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
541
|
-
var t = {}.toString.call(r).slice(8, -1);
|
542
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : undefined;
|
543
|
-
}
|
544
|
-
}
|
545
|
-
function _wrapNativeSuper(t) {
|
546
|
-
var r = "function" == typeof Map ? new Map() : undefined;
|
547
|
-
return _wrapNativeSuper = function (t) {
|
548
|
-
if (null === t || !_isNativeFunction(t)) return t;
|
549
|
-
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
550
|
-
if (undefined !== r) {
|
551
|
-
if (r.has(t)) return r.get(t);
|
552
|
-
r.set(t, Wrapper);
|
553
|
-
}
|
554
|
-
function Wrapper() {
|
555
|
-
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
556
|
-
}
|
557
|
-
return Wrapper.prototype = Object.create(t.prototype, {
|
558
|
-
constructor: {
|
559
|
-
value: Wrapper,
|
560
|
-
enumerable: false,
|
561
|
-
writable: true,
|
562
|
-
configurable: true
|
563
|
-
}
|
564
|
-
}), _setPrototypeOf(Wrapper, t);
|
565
|
-
}, _wrapNativeSuper(t);
|
566
|
-
}
|
567
|
-
|
568
|
-
var RumiousRenderContext = /*#__PURE__*/function () {
|
569
|
-
function RumiousRenderContext(target) {
|
570
|
-
_classCallCheck(this, RumiousRenderContext);
|
571
|
-
this.target = target;
|
572
|
-
}
|
573
|
-
return _createClass(RumiousRenderContext, [{
|
574
|
-
key: "find",
|
575
|
-
value: function find(name) {
|
576
|
-
return this.target[name];
|
577
|
-
}
|
578
|
-
}, {
|
579
|
-
key: "get",
|
580
|
-
value: function get(name) {
|
581
|
-
return this.target[name];
|
582
|
-
}
|
583
|
-
}]);
|
584
|
-
}();
|
585
|
-
|
586
|
-
var RumiousComponent = /*#__PURE__*/function () {
|
587
|
-
function RumiousComponent() {
|
588
|
-
_classCallCheck(this, RumiousComponent);
|
589
|
-
this.element = null;
|
590
|
-
this.props = {};
|
591
|
-
this.renderContext = new RumiousRenderContext(this);
|
592
|
-
this.renderer = null;
|
593
|
-
this.wrapped = null;
|
594
|
-
}
|
595
|
-
return _createClass(RumiousComponent, [{
|
596
|
-
key: "prepare",
|
597
|
-
value: function prepare(element, props) {
|
598
|
-
var wrapped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
599
|
-
var renderer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
600
|
-
this.element = element;
|
601
|
-
this.props = props;
|
602
|
-
this.renderer = renderer;
|
603
|
-
this.wrapped = wrapped;
|
604
|
-
}
|
605
|
-
}, {
|
606
|
-
key: "template",
|
607
|
-
value: function template() {
|
608
|
-
return {};
|
609
|
-
}
|
610
|
-
}, {
|
611
|
-
key: "requestRender",
|
612
|
-
value: function requestRender() {
|
613
|
-
var template = this.template();
|
614
|
-
var fragment = this.renderer(template, document.createDocumentFragment(), this.renderContext);
|
615
|
-
this.element.appendChild(fragment);
|
616
|
-
this.onRender();
|
617
|
-
}
|
618
|
-
}, {
|
619
|
-
key: "requestCleanUp",
|
620
|
-
value: function () {
|
621
|
-
var _requestCleanUp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
622
|
-
var cloned;
|
623
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
624
|
-
while (1) switch (_context.prev = _context.next) {
|
625
|
-
case 0:
|
626
|
-
if (this.element) {
|
627
|
-
cloned = this.element.cloneNode(true);
|
628
|
-
this.element.replaceWith(cloned);
|
629
|
-
this.element = cloned;
|
630
|
-
while (this.element.firstChild) {
|
631
|
-
this.element.removeChild(this.element.firstChild);
|
632
|
-
}
|
633
|
-
}
|
634
|
-
case 1:
|
635
|
-
case "end":
|
636
|
-
return _context.stop();
|
637
|
-
}
|
638
|
-
}, _callee, this);
|
639
|
-
}));
|
640
|
-
function requestCleanUp() {
|
641
|
-
return _requestCleanUp.apply(this, arguments);
|
642
|
-
}
|
643
|
-
return requestCleanUp;
|
644
|
-
}()
|
645
|
-
}, {
|
646
|
-
key: "onInit",
|
647
|
-
value: function onInit() {}
|
648
|
-
}, {
|
649
|
-
key: "onCreate",
|
650
|
-
value: function onCreate() {}
|
651
|
-
}, {
|
652
|
-
key: "onRender",
|
653
|
-
value: function onRender() {}
|
654
|
-
}, {
|
655
|
-
key: "onUpdate",
|
656
|
-
value: function onUpdate() {}
|
657
|
-
}, {
|
658
|
-
key: "onDestroy",
|
659
|
-
value: function onDestroy() {}
|
660
|
-
}]);
|
661
|
-
}();
|
662
|
-
function isComponent(component) {
|
663
|
-
return Object.getPrototypeOf(component) === RumiousComponent;
|
664
|
-
}
|
665
|
-
|
666
|
-
var RumiousElement = /*#__PURE__*/_createClass(function RumiousElement(type, props) {
|
667
|
-
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
668
|
-
_classCallCheck(this, RumiousElement);
|
669
|
-
this.type = type;
|
670
|
-
this.props = props;
|
671
|
-
this.children = children;
|
672
|
-
});
|
673
|
-
var RumiousElementList = /*#__PURE__*/function () {
|
674
|
-
function RumiousElementList(list) {
|
675
|
-
_classCallCheck(this, RumiousElementList);
|
676
|
-
this.type = "ELEMENT_LIST";
|
677
|
-
this.children = list;
|
678
|
-
}
|
679
|
-
return _createClass(RumiousElementList, [{
|
680
|
-
key: "forEach",
|
681
|
-
value: function forEach(callback) {
|
682
|
-
this.children.forEach(callback);
|
683
|
-
}
|
684
|
-
}]);
|
685
|
-
}();
|
686
|
-
|
687
|
-
function isCamelCase(str) {
|
688
|
-
var camelCaseRegex = /^[a-zA-Z]+([A-Z][a-z]*)*$/;
|
689
|
-
return camelCaseRegex.test(str);
|
690
|
-
}
|
691
|
-
function isFunction(object) {
|
692
|
-
return typeof object === 'function';
|
693
|
-
}
|
694
|
-
|
695
|
-
var RumiousDirective = /*#__PURE__*/function () {
|
696
|
-
function RumiousDirective(type, name, value) {
|
697
|
-
_classCallCheck(this, RumiousDirective);
|
698
|
-
this.type = type;
|
699
|
-
this.name = name;
|
700
|
-
this.value = value;
|
701
|
-
}
|
702
|
-
return _createClass(RumiousDirective, [{
|
703
|
-
key: "init",
|
704
|
-
value: function init() {
|
705
|
-
console.warn("Directive haven't handler !");
|
706
|
-
}
|
707
|
-
}]);
|
708
|
-
}();
|
709
|
-
var RumiousEventBindingDirective = /*#__PURE__*/function (_RumiousDirective) {
|
710
|
-
function RumiousEventBindingDirective() {
|
711
|
-
_classCallCheck(this, RumiousEventBindingDirective);
|
712
|
-
return _callSuper(this, RumiousEventBindingDirective, arguments);
|
713
|
-
}
|
714
|
-
_inherits(RumiousEventBindingDirective, _RumiousDirective);
|
715
|
-
return _createClass(RumiousEventBindingDirective, [{
|
716
|
-
key: "init",
|
717
|
-
value: function () {
|
718
|
-
var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(dom, renderContext) {
|
719
|
-
var _this = this;
|
720
|
-
var fn, getHandler;
|
721
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
722
|
-
while (1) switch (_context.prev = _context.next) {
|
723
|
-
case 0:
|
724
|
-
fn = null;
|
725
|
-
getHandler = function getHandler(value) {
|
726
|
-
if (!renderContext.find(value)) {
|
727
|
-
console.warn("Missing event handler for event: ".concat(_this.name));
|
728
|
-
return null;
|
729
|
-
}
|
730
|
-
var handler = renderContext.get(value);
|
731
|
-
if (!isFunction(handler)) {
|
732
|
-
throw "".concat(value, " is not a function!");
|
733
|
-
}
|
734
|
-
return handler.bind(renderContext.target);
|
735
|
-
};
|
736
|
-
if (!(this.value.type === "string")) {
|
737
|
-
_context.next = 6;
|
738
|
-
break;
|
739
|
-
}
|
740
|
-
fn = getHandler(this.value.value);
|
741
|
-
_context.next = 13;
|
742
|
-
break;
|
743
|
-
case 6:
|
744
|
-
if (!(this.value.type === "expression")) {
|
745
|
-
_context.next = 12;
|
746
|
-
break;
|
747
|
-
}
|
748
|
-
fn = this.value.value;
|
749
|
-
if (isFunction(fn)) {
|
750
|
-
_context.next = 10;
|
751
|
-
break;
|
752
|
-
}
|
753
|
-
throw "Event handler requires a function!";
|
754
|
-
case 10:
|
755
|
-
_context.next = 13;
|
756
|
-
break;
|
757
|
-
case 12:
|
758
|
-
if (this.value.type === "dynamic_value") {
|
759
|
-
fn = getHandler(this.value.value.objectName);
|
760
|
-
}
|
761
|
-
case 13:
|
762
|
-
if (fn) {
|
763
|
-
dom.addEventListener(this.name, fn);
|
764
|
-
}
|
765
|
-
case 14:
|
766
|
-
case "end":
|
767
|
-
return _context.stop();
|
768
|
-
}
|
769
|
-
}, _callee, this);
|
770
|
-
}));
|
771
|
-
function init(_x, _x2) {
|
772
|
-
return _init.apply(this, arguments);
|
773
|
-
}
|
774
|
-
return init;
|
775
|
-
}()
|
776
|
-
}]);
|
777
|
-
}(RumiousDirective);
|
778
|
-
var RumiousPropsBindingDirective = /*#__PURE__*/function (_RumiousDirective2) {
|
779
|
-
function RumiousPropsBindingDirective() {
|
780
|
-
_classCallCheck(this, RumiousPropsBindingDirective);
|
781
|
-
return _callSuper(this, RumiousPropsBindingDirective, arguments);
|
782
|
-
}
|
783
|
-
_inherits(RumiousPropsBindingDirective, _RumiousDirective2);
|
784
|
-
return _createClass(RumiousPropsBindingDirective, [{
|
785
|
-
key: "init",
|
786
|
-
value: function () {
|
787
|
-
var _init2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dom, renderContext) {
|
788
|
-
var _this2 = this;
|
789
|
-
var _this$value$evaluator, _this$value, currentStateValue, currentState;
|
790
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
791
|
-
while (1) switch (_context2.prev = _context2.next) {
|
792
|
-
case 0:
|
793
|
-
if (!(this.value.type === "expression")) {
|
794
|
-
_context2.next = 4;
|
795
|
-
break;
|
796
|
-
}
|
797
|
-
_context2.next = 13;
|
798
|
-
break;
|
799
|
-
case 4:
|
800
|
-
if (!(this.value.type === "dynamic_value")) {
|
801
|
-
_context2.next = 13;
|
802
|
-
break;
|
803
|
-
}
|
804
|
-
currentStateValue = (_this$value$evaluator = (_this$value = this.value).evaluator) === null || _this$value$evaluator === undefined ? undefined : _this$value$evaluator.call(_this$value, renderContext.target);
|
805
|
-
currentState = renderContext.find(this.value.value.objectName);
|
806
|
-
if (currentState) {
|
807
|
-
_context2.next = 11;
|
808
|
-
break;
|
809
|
-
}
|
810
|
-
throw "Invalid props value: Directive bind: require a RumiousState Object !";
|
811
|
-
case 11:
|
812
|
-
currentState.reactor.addBinding(function () {
|
813
|
-
var _this2$value$evaluato, _this2$value;
|
814
|
-
var currentStateValue = (_this2$value$evaluato = (_this2$value = _this2.value).evaluator) === null || _this2$value$evaluato === undefined ? undefined : _this2$value$evaluato.call(_this2$value, renderContext.target);
|
815
|
-
_this2.bindAttr(dom, currentStateValue);
|
816
|
-
});
|
817
|
-
case 12:
|
818
|
-
this.bindAttr(dom, currentStateValue);
|
819
|
-
case 13:
|
820
|
-
case "end":
|
821
|
-
return _context2.stop();
|
822
|
-
}
|
823
|
-
}, _callee2, this);
|
824
|
-
}));
|
825
|
-
function init(_x3, _x4) {
|
826
|
-
return _init2.apply(this, arguments);
|
827
|
-
}
|
828
|
-
return init;
|
829
|
-
}()
|
830
|
-
}, {
|
831
|
-
key: "normalizeValue",
|
832
|
-
value: function normalizeValue(value) {
|
833
|
-
if (_typeof(value) === "object") {
|
834
|
-
var _value$toString, _value$toString2;
|
835
|
-
return (_value$toString = (_value$toString2 = value.toString) === null || _value$toString2 === undefined ? undefined : _value$toString2.call(value)) !== null && _value$toString !== undefined ? _value$toString : "";
|
836
|
-
}
|
837
|
-
return value;
|
838
|
-
}
|
839
|
-
}, {
|
840
|
-
key: "bindAttr",
|
841
|
-
value: function () {
|
842
|
-
var _bindAttr = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(dom, value) {
|
843
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
844
|
-
while (1) switch (_context3.prev = _context3.next) {
|
845
|
-
case 0:
|
846
|
-
_context3.t0 = this.name;
|
847
|
-
_context3.next = _context3.t0 === "html" ? 3 : 5;
|
848
|
-
break;
|
849
|
-
case 3:
|
850
|
-
dom.innerHTML = this.normalizeValue(value);
|
851
|
-
return _context3.abrupt("break", 5);
|
852
|
-
case 5:
|
853
|
-
case "end":
|
854
|
-
return _context3.stop();
|
855
|
-
}
|
856
|
-
}, _callee3, this);
|
857
|
-
}));
|
858
|
-
function bindAttr(_x5, _x6) {
|
859
|
-
return _bindAttr.apply(this, arguments);
|
860
|
-
}
|
861
|
-
return bindAttr;
|
862
|
-
}()
|
863
|
-
}]);
|
864
|
-
}(RumiousDirective);
|
865
|
-
var directives = {
|
866
|
-
on: function on(event, value) {
|
867
|
-
return new RumiousEventBindingDirective("on", event, value);
|
868
|
-
},
|
869
|
-
bind: function bind(attr, value) {
|
870
|
-
return new RumiousPropsBindingDirective("bind", attr, value);
|
871
|
-
}
|
872
|
-
};
|
873
|
-
function registerDirective(type, name, value) {
|
874
|
-
var _directives$type;
|
875
|
-
return (_directives$type = directives[type]) === null || _directives$type === undefined ? undefined : _directives$type.call(directives, name, value);
|
876
|
-
}
|
877
|
-
|
878
|
-
function createDirective(type, name, value) {
|
879
|
-
return registerDirective(type, name, value);
|
880
|
-
}
|
881
|
-
function createElement(type, props) {
|
882
|
-
for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
883
|
-
children[_key - 2] = arguments[_key];
|
884
|
-
}
|
885
|
-
if (isComponent(type)) {
|
886
|
-
return createComponent(type, props, children);
|
887
|
-
}
|
888
|
-
if (type === createFragment) {
|
889
|
-
return createFragment.apply(undefined, children);
|
890
|
-
}
|
891
|
-
return new RumiousElement(type, props || {}, normalizeChildren(children));
|
892
|
-
}
|
893
|
-
function createTextElement(text) {
|
894
|
-
return new RumiousElement("TEXT_ELEMENT", {
|
895
|
-
nodeValue: text
|
896
|
-
}, []);
|
897
|
-
}
|
898
|
-
function createComponent(type, props, children) {
|
899
|
-
return new RumiousElement("COMPONENT", _objectSpread2({
|
900
|
-
component: type
|
901
|
-
}, props), new RumiousElementList(normalizeChildren(children)));
|
902
|
-
}
|
903
|
-
function createFragment() {
|
904
|
-
for (var _len2 = arguments.length, children = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
905
|
-
children[_key2] = arguments[_key2];
|
906
|
-
}
|
907
|
-
return new RumiousElement("FRAGMENT", {}, normalizeChildren(children));
|
908
|
-
}
|
909
|
-
function normalizeChildren(children) {
|
910
|
-
return children.map(function (child) {
|
911
|
-
return _typeof(child) === "object" ? child : createTextElement(child);
|
912
|
-
});
|
913
|
-
}
|
914
|
-
window.RUMIOUS_JSX_SUPPORT = {
|
915
|
-
createElement: createElement,
|
916
|
-
createFragment: createFragment,
|
917
|
-
createDirective: createDirective
|
918
|
-
};
|
919
|
-
|
920
|
-
var RumiousComponentElement = /*#__PURE__*/function (_HTMLElement) {
|
921
|
-
function RumiousComponentElement() {
|
922
|
-
var _this;
|
923
|
-
_classCallCheck(this, RumiousComponentElement);
|
924
|
-
_this = _callSuper(this, RumiousComponentElement);
|
925
|
-
_this.instance = null;
|
926
|
-
return _this;
|
927
|
-
}
|
928
|
-
_inherits(RumiousComponentElement, _HTMLElement);
|
929
|
-
return _createClass(RumiousComponentElement, [{
|
930
|
-
key: "init",
|
931
|
-
value: function init(componentConstructor, props) {
|
932
|
-
var wrapped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
933
|
-
var renderer = arguments.length > 3 ? arguments[3] : undefined;
|
934
|
-
this.instance = new componentConstructor();
|
935
|
-
this.instance.prepare(this, props, wrapped, renderer);
|
936
|
-
this.instance.onInit();
|
937
|
-
}
|
938
|
-
}, {
|
939
|
-
key: "connectedCallback",
|
940
|
-
value: function connectedCallback() {
|
941
|
-
this.instance.onCreate();
|
942
|
-
this.instance.requestRender();
|
943
|
-
}
|
944
|
-
}, {
|
945
|
-
key: "disconnectCallback",
|
946
|
-
value: function disconnectCallback() {
|
947
|
-
this.instance.onDestroy();
|
948
|
-
this.instance.requestCleanUp();
|
949
|
-
}
|
950
|
-
}]);
|
951
|
-
}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));
|
952
|
-
function createComponentElement() {
|
953
|
-
return document.createElement("a-component");
|
954
|
-
}
|
955
|
-
window.customElements.define("a-component", RumiousComponentElement);
|
956
|
-
|
957
|
-
function renderComponent(componentConstructor, props, wrapped, renderer) {
|
958
|
-
var componentElement = createComponentElement();
|
959
|
-
componentElement.init(componentConstructor, props, wrapped, renderer);
|
960
|
-
return componentElement;
|
961
|
-
}
|
962
|
-
|
963
|
-
function handleComponentElement(element, container, render) {
|
964
|
-
var dom = renderComponent(element.props.component, element.props, element.children, render);
|
965
|
-
container.appendChild(dom);
|
966
|
-
return container;
|
967
|
-
}
|
968
|
-
function handleFragmentOrElementList(element, container, renderContext) {
|
969
|
-
element.children.forEach(function (child) {
|
970
|
-
return render(child, container, renderContext);
|
971
|
-
});
|
972
|
-
return container;
|
973
|
-
}
|
974
|
-
function handleTextElement(element) {
|
975
|
-
return document.createTextNode(element.props.nodeValue);
|
976
|
-
}
|
977
|
-
function handleRegularElement(element, renderContext) {
|
978
|
-
var dom = document.createElement(element.type);
|
979
|
-
Object.entries(element.props || {}).forEach(function (_ref) {
|
980
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
981
|
-
name = _ref2[0],
|
982
|
-
propValue = _ref2[1];
|
983
|
-
if (name.startsWith("on") && isCamelCase(name)) {
|
984
|
-
dom.addEventListener(name.substring(2).toLowerCase(), propValue);
|
985
|
-
} else {
|
986
|
-
setElementProps(dom, name, propValue, renderContext);
|
987
|
-
}
|
988
|
-
});
|
989
|
-
return dom;
|
990
|
-
}
|
991
|
-
function handleDirective(dom, directive, renderContext) {
|
992
|
-
directive.init(dom, renderContext);
|
993
|
-
}
|
994
|
-
function setElementProps(dom, name, propValue, renderContext) {
|
995
|
-
if (dom.nodeType === Node.TEXT_NODE) {
|
996
|
-
dom.nodeValue = propValue;
|
997
|
-
} else if (propValue instanceof RumiousDirective) {
|
998
|
-
handleDirective(dom, propValue, renderContext);
|
999
|
-
} else {
|
1000
|
-
dom.setAttribute(name, propValue);
|
1001
|
-
}
|
1002
|
-
}
|
1003
|
-
function render(element, container) {
|
1004
|
-
var renderContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
1005
|
-
if (!element) return container;
|
1006
|
-
var dom;
|
1007
|
-
if (element.type === "COMPONENT") {
|
1008
|
-
return handleComponentElement(element, container, render);
|
1009
|
-
}
|
1010
|
-
if (element.type === "FRAGMENT" || element.type === "ELEMENT_LIST") {
|
1011
|
-
return handleFragmentOrElementList(element, container, renderContext);
|
1012
|
-
}
|
1013
|
-
if (element.type === "TEXT_ELEMENT") {
|
1014
|
-
dom = handleTextElement(element);
|
1015
|
-
} else {
|
1016
|
-
dom = handleRegularElement(element, renderContext);
|
1017
|
-
}
|
1018
|
-
element.children.forEach(function (child) {
|
1019
|
-
return render(child, dom, renderContext);
|
1020
|
-
});
|
1021
|
-
container.appendChild(dom);
|
1022
|
-
return container;
|
1023
|
-
}
|
1024
|
-
|
1025
|
-
var RumiousApp = /*#__PURE__*/function () {
|
1026
|
-
function RumiousApp() {
|
1027
|
-
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.createElement("span");
|
1028
|
-
var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1029
|
-
_classCallCheck(this, RumiousApp);
|
1030
|
-
this.root = root;
|
1031
|
-
this.configs = configs;
|
1032
|
-
this.renderContext = new RumiousRenderContext(this);
|
1033
|
-
}
|
1034
|
-
return _createClass(RumiousApp, [{
|
1035
|
-
key: "render",
|
1036
|
-
value: function render$1(element) {
|
1037
|
-
render(element, this.root, this.renderContext);
|
1038
|
-
}
|
1039
|
-
}]);
|
1040
|
-
}();
|
1041
|
-
|
1042
|
-
var RumiousReactor = /*#__PURE__*/function () {
|
1043
|
-
function RumiousReactor() {
|
1044
|
-
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
1045
|
-
var bindings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
1046
|
-
_classCallCheck(this, RumiousReactor);
|
1047
|
-
this.target = target;
|
1048
|
-
this.bindings = bindings;
|
1049
|
-
}
|
1050
|
-
return _createClass(RumiousReactor, [{
|
1051
|
-
key: "react",
|
1052
|
-
value: function react() {
|
1053
|
-
this.bindings.forEach(function (callback) {
|
1054
|
-
return callback();
|
1055
|
-
});
|
1056
|
-
}
|
1057
|
-
}, {
|
1058
|
-
key: "addBinding",
|
1059
|
-
value: function addBinding(fn) {
|
1060
|
-
this.bindings.push(fn);
|
1061
|
-
}
|
1062
|
-
}]);
|
1063
|
-
}();
|
1064
|
-
|
1065
|
-
var RumiousReducer = /*#__PURE__*/function () {
|
1066
|
-
function RumiousReducer(state) {
|
1067
|
-
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
1068
|
-
var fn = arguments.length > 2 ? arguments[2] : undefined;
|
1069
|
-
_classCallCheck(this, RumiousReducer);
|
1070
|
-
this.state = state;
|
1071
|
-
this.path = path;
|
1072
|
-
this.fn = fn;
|
1073
|
-
}
|
1074
|
-
return _createClass(RumiousReducer, [{
|
1075
|
-
key: "trigger",
|
1076
|
-
value: function trigger() {
|
1077
|
-
var value = this.fn.apply(this, arguments);
|
1078
|
-
this.state.set(this.path, value);
|
1079
|
-
}
|
1080
|
-
}]);
|
1081
|
-
}();
|
1082
|
-
|
1083
|
-
var Operation = {
|
1084
|
-
Remove: 'remove',
|
1085
|
-
Replace: 'replace',
|
1086
|
-
Add: 'add'
|
1087
|
-
};
|
1088
|
-
|
1089
|
-
// Don't use `Symbol()` just for 3rd party access the draft
|
1090
|
-
var PROXY_DRAFT = Symbol["for"]('__MUTATIVE_PROXY_DRAFT__');
|
1091
|
-
var RAW_RETURN_SYMBOL = Symbol('__MUTATIVE_RAW_RETURN_SYMBOL__');
|
1092
|
-
var iteratorSymbol = Symbol.iterator;
|
1093
|
-
var dataTypes = {
|
1094
|
-
mutable: 'mutable',
|
1095
|
-
immutable: 'immutable'
|
1096
|
-
};
|
1097
|
-
var internal = {};
|
1098
|
-
function has(target, key) {
|
1099
|
-
return target instanceof Map ? target.has(key) : Object.prototype.hasOwnProperty.call(target, key);
|
1100
|
-
}
|
1101
|
-
function getDescriptor(target, key) {
|
1102
|
-
if (key in target) {
|
1103
|
-
var prototype = Reflect.getPrototypeOf(target);
|
1104
|
-
while (prototype) {
|
1105
|
-
var descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);
|
1106
|
-
if (descriptor) return descriptor;
|
1107
|
-
prototype = Reflect.getPrototypeOf(prototype);
|
1108
|
-
}
|
1109
|
-
}
|
1110
|
-
return;
|
1111
|
-
}
|
1112
|
-
function isBaseSetInstance(obj) {
|
1113
|
-
return Object.getPrototypeOf(obj) === Set.prototype;
|
1114
|
-
}
|
1115
|
-
function isBaseMapInstance(obj) {
|
1116
|
-
return Object.getPrototypeOf(obj) === Map.prototype;
|
1117
|
-
}
|
1118
|
-
function latest(proxyDraft) {
|
1119
|
-
var _a;
|
1120
|
-
return (_a = proxyDraft.copy) !== null && _a !== undefined ? _a : proxyDraft.original;
|
1121
|
-
}
|
1122
|
-
/**
|
1123
|
-
* Check if the value is a draft
|
1124
|
-
*/
|
1125
|
-
function isDraft(target) {
|
1126
|
-
return !!getProxyDraft(target);
|
1127
|
-
}
|
1128
|
-
function getProxyDraft(value) {
|
1129
|
-
if (_typeof(value) !== 'object') return null;
|
1130
|
-
return value === null || value === undefined ? undefined : value[PROXY_DRAFT];
|
1131
|
-
}
|
1132
|
-
function getValue(value) {
|
1133
|
-
var _a;
|
1134
|
-
var proxyDraft = getProxyDraft(value);
|
1135
|
-
return proxyDraft ? (_a = proxyDraft.copy) !== null && _a !== undefined ? _a : proxyDraft.original : value;
|
1136
|
-
}
|
1137
|
-
/**
|
1138
|
-
* Check if a value is draftable
|
1139
|
-
*/
|
1140
|
-
function isDraftable(value, options) {
|
1141
|
-
if (!value || _typeof(value) !== 'object') return false;
|
1142
|
-
var markResult;
|
1143
|
-
return Object.getPrototypeOf(value) === Object.prototype || Array.isArray(value) || value instanceof Map || value instanceof Set || !!(options === null || options === undefined ? undefined : options.mark) && ((markResult = options.mark(value, dataTypes)) === dataTypes.immutable || typeof markResult === 'function');
|
1144
|
-
}
|
1145
|
-
function getPath(target) {
|
1146
|
-
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
1147
|
-
if (Object.hasOwnProperty.call(target, 'key')) {
|
1148
|
-
// check if the parent is a draft and the original value is not equal to the current value
|
1149
|
-
var parentCopy = target.parent.copy;
|
1150
|
-
var proxyDraft = getProxyDraft(get(parentCopy, target.key));
|
1151
|
-
if (proxyDraft !== null && (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== target.original) {
|
1152
|
-
return null;
|
1153
|
-
}
|
1154
|
-
var isSet = target.parent.type === 3 /* DraftType.Set */;
|
1155
|
-
var key = isSet ? Array.from(target.parent.setMap.keys()).indexOf(target.key) : target.key;
|
1156
|
-
// check if the key is still in the next state parent
|
1157
|
-
if (!(isSet && parentCopy.size > key || has(parentCopy, key))) return null;
|
1158
|
-
path.push(key);
|
1159
|
-
}
|
1160
|
-
if (target.parent) {
|
1161
|
-
return getPath(target.parent, path);
|
1162
|
-
}
|
1163
|
-
// `target` is root draft.
|
1164
|
-
path.reverse();
|
1165
|
-
try {
|
1166
|
-
// check if the path is valid
|
1167
|
-
resolvePath(target.copy, path);
|
1168
|
-
} catch (e) {
|
1169
|
-
return null;
|
1170
|
-
}
|
1171
|
-
return path;
|
1172
|
-
}
|
1173
|
-
function getType(target) {
|
1174
|
-
if (Array.isArray(target)) return 1 /* DraftType.Array */;
|
1175
|
-
if (target instanceof Map) return 2 /* DraftType.Map */;
|
1176
|
-
if (target instanceof Set) return 3 /* DraftType.Set */;
|
1177
|
-
return 0 /* DraftType.Object */;
|
1178
|
-
}
|
1179
|
-
function get(target, key) {
|
1180
|
-
return getType(target) === 2 /* DraftType.Map */ ? target.get(key) : target[key];
|
1181
|
-
}
|
1182
|
-
function set(target, key, value) {
|
1183
|
-
var type = getType(target);
|
1184
|
-
if (type === 2 /* DraftType.Map */) {
|
1185
|
-
target.set(key, value);
|
1186
|
-
} else {
|
1187
|
-
target[key] = value;
|
1188
|
-
}
|
1189
|
-
}
|
1190
|
-
function peek(target, key) {
|
1191
|
-
var state = getProxyDraft(target);
|
1192
|
-
var source = state ? latest(state) : target;
|
1193
|
-
return source[key];
|
1194
|
-
}
|
1195
|
-
function isEqual(x, y) {
|
1196
|
-
if (x === y) {
|
1197
|
-
return x !== 0 || 1 / x === 1 / y;
|
1198
|
-
} else {
|
1199
|
-
return x !== x && y !== y;
|
1200
|
-
}
|
1201
|
-
}
|
1202
|
-
function revokeProxy(proxyDraft) {
|
1203
|
-
if (!proxyDraft) return;
|
1204
|
-
while (proxyDraft.finalities.revoke.length > 0) {
|
1205
|
-
var revoke = proxyDraft.finalities.revoke.pop();
|
1206
|
-
revoke();
|
1207
|
-
}
|
1208
|
-
}
|
1209
|
-
// handle JSON Pointer path with spec https://www.rfc-editor.org/rfc/rfc6901
|
1210
|
-
function escapePath(path, pathAsArray) {
|
1211
|
-
return pathAsArray ? path : [''].concat(path).map(function (_item) {
|
1212
|
-
var item = "".concat(_item);
|
1213
|
-
if (item.indexOf('/') === -1 && item.indexOf('~') === -1) return item;
|
1214
|
-
return item.replace(/~/g, '~0').replace(/\//g, '~1');
|
1215
|
-
}).join('/');
|
1216
|
-
}
|
1217
|
-
function resolvePath(base, path) {
|
1218
|
-
for (var index = 0; index < path.length - 1; index += 1) {
|
1219
|
-
var key = path[index];
|
1220
|
-
// use `index` in Set draft
|
1221
|
-
base = get(getType(base) === 3 /* DraftType.Set */ ? Array.from(base) : base, key);
|
1222
|
-
if (_typeof(base) !== 'object') {
|
1223
|
-
throw new Error("Cannot resolve patch at '".concat(path.join('/'), "'."));
|
1224
|
-
}
|
1225
|
-
}
|
1226
|
-
return base;
|
1227
|
-
}
|
1228
|
-
function strictCopy(target) {
|
1229
|
-
var copy = Object.create(Object.getPrototypeOf(target));
|
1230
|
-
Reflect.ownKeys(target).forEach(function (key) {
|
1231
|
-
var desc = Reflect.getOwnPropertyDescriptor(target, key);
|
1232
|
-
if (desc.enumerable && desc.configurable && desc.writable) {
|
1233
|
-
copy[key] = target[key];
|
1234
|
-
return;
|
1235
|
-
}
|
1236
|
-
// for freeze
|
1237
|
-
if (!desc.writable) {
|
1238
|
-
desc.writable = true;
|
1239
|
-
desc.configurable = true;
|
1240
|
-
}
|
1241
|
-
if (desc.get || desc.set) desc = {
|
1242
|
-
configurable: true,
|
1243
|
-
writable: true,
|
1244
|
-
enumerable: desc.enumerable,
|
1245
|
-
value: target[key]
|
1246
|
-
};
|
1247
|
-
Reflect.defineProperty(copy, key, desc);
|
1248
|
-
});
|
1249
|
-
return copy;
|
1250
|
-
}
|
1251
|
-
var propIsEnum = Object.prototype.propertyIsEnumerable;
|
1252
|
-
function shallowCopy(original, options) {
|
1253
|
-
var markResult;
|
1254
|
-
if (Array.isArray(original)) {
|
1255
|
-
return Array.prototype.concat.call(original);
|
1256
|
-
} else if (original instanceof Set) {
|
1257
|
-
if (!isBaseSetInstance(original)) {
|
1258
|
-
var SubClass = Object.getPrototypeOf(original).constructor;
|
1259
|
-
return new SubClass(original.values());
|
1260
|
-
}
|
1261
|
-
return Set.prototype.difference ? Set.prototype.difference.call(original, new Set()) : new Set(original.values());
|
1262
|
-
} else if (original instanceof Map) {
|
1263
|
-
if (!isBaseMapInstance(original)) {
|
1264
|
-
var _SubClass = Object.getPrototypeOf(original).constructor;
|
1265
|
-
return new _SubClass(original);
|
1266
|
-
}
|
1267
|
-
return new Map(original);
|
1268
|
-
} else if ((options === null || options === undefined ? undefined : options.mark) && (markResult = options.mark(original, dataTypes), markResult !== undefined) && markResult !== dataTypes.mutable) {
|
1269
|
-
if (markResult === dataTypes.immutable) {
|
1270
|
-
return strictCopy(original);
|
1271
|
-
} else if (typeof markResult === 'function') {
|
1272
|
-
if (options.enablePatches || options.enableAutoFreeze) {
|
1273
|
-
throw new Error("You can't use mark and patches or auto freeze together.");
|
1274
|
-
}
|
1275
|
-
return markResult();
|
1276
|
-
}
|
1277
|
-
throw new Error("Unsupported mark result: ".concat(markResult));
|
1278
|
-
} else if (_typeof(original) === 'object' && Object.getPrototypeOf(original) === Object.prototype) {
|
1279
|
-
// For best performance with shallow copies,
|
1280
|
-
// don't use `Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));` by default.
|
1281
|
-
var copy = {};
|
1282
|
-
Object.keys(original).forEach(function (key) {
|
1283
|
-
copy[key] = original[key];
|
1284
|
-
});
|
1285
|
-
Object.getOwnPropertySymbols(original).forEach(function (key) {
|
1286
|
-
if (propIsEnum.call(original, key)) {
|
1287
|
-
copy[key] = original[key];
|
1288
|
-
}
|
1289
|
-
});
|
1290
|
-
return copy;
|
1291
|
-
} else {
|
1292
|
-
throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
|
1293
|
-
}
|
1294
|
-
}
|
1295
|
-
function ensureShallowCopy(target) {
|
1296
|
-
if (target.copy) return;
|
1297
|
-
target.copy = shallowCopy(target.original, target.options);
|
1298
|
-
}
|
1299
|
-
function deepClone(target) {
|
1300
|
-
if (!isDraftable(target)) return getValue(target);
|
1301
|
-
if (Array.isArray(target)) return target.map(deepClone);
|
1302
|
-
if (target instanceof Map) {
|
1303
|
-
var iterable = Array.from(target.entries()).map(function (_ref) {
|
1304
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
1305
|
-
k = _ref2[0],
|
1306
|
-
v = _ref2[1];
|
1307
|
-
return [k, deepClone(v)];
|
1308
|
-
});
|
1309
|
-
if (!isBaseMapInstance(target)) {
|
1310
|
-
var SubClass = Object.getPrototypeOf(target).constructor;
|
1311
|
-
return new SubClass(iterable);
|
1312
|
-
}
|
1313
|
-
return new Map(iterable);
|
1314
|
-
}
|
1315
|
-
if (target instanceof Set) {
|
1316
|
-
var _iterable = Array.from(target).map(deepClone);
|
1317
|
-
if (!isBaseSetInstance(target)) {
|
1318
|
-
var _SubClass2 = Object.getPrototypeOf(target).constructor;
|
1319
|
-
return new _SubClass2(_iterable);
|
1320
|
-
}
|
1321
|
-
return new Set(_iterable);
|
1322
|
-
}
|
1323
|
-
var copy = Object.create(Object.getPrototypeOf(target));
|
1324
|
-
for (var key in target) copy[key] = deepClone(target[key]);
|
1325
|
-
return copy;
|
1326
|
-
}
|
1327
|
-
function cloneIfNeeded(target) {
|
1328
|
-
return isDraft(target) ? deepClone(target) : target;
|
1329
|
-
}
|
1330
|
-
function markChanged(proxyDraft) {
|
1331
|
-
var _a;
|
1332
|
-
proxyDraft.assignedMap = (_a = proxyDraft.assignedMap) !== null && _a !== undefined ? _a : new Map();
|
1333
|
-
if (!proxyDraft.operated) {
|
1334
|
-
proxyDraft.operated = true;
|
1335
|
-
if (proxyDraft.parent) {
|
1336
|
-
markChanged(proxyDraft.parent);
|
1337
|
-
}
|
1338
|
-
}
|
1339
|
-
}
|
1340
|
-
function throwFrozenError() {
|
1341
|
-
throw new Error('Cannot modify frozen object');
|
1342
|
-
}
|
1343
|
-
function deepFreeze(target, subKey, updatedValues, stack, keys) {
|
1344
|
-
{
|
1345
|
-
updatedValues = updatedValues !== null && updatedValues !== undefined ? updatedValues : new WeakMap();
|
1346
|
-
stack = stack !== null && stack !== undefined ? stack : [];
|
1347
|
-
keys = keys !== null && keys !== undefined ? keys : [];
|
1348
|
-
var value = updatedValues.has(target) ? updatedValues.get(target) : target;
|
1349
|
-
if (stack.length > 0) {
|
1350
|
-
var index = stack.indexOf(value);
|
1351
|
-
if (value && _typeof(value) === 'object' && index !== -1) {
|
1352
|
-
if (stack[0] === value) {
|
1353
|
-
throw new Error("Forbids circular reference");
|
1354
|
-
}
|
1355
|
-
throw new Error("Forbids circular reference: ~/".concat(keys.slice(0, index).map(function (key, index) {
|
1356
|
-
if (_typeof(key) === 'symbol') return "[".concat(key.toString(), "]");
|
1357
|
-
var parent = stack[index];
|
1358
|
-
if (_typeof(key) === 'object' && (parent instanceof Map || parent instanceof Set)) return Array.from(parent.keys()).indexOf(key);
|
1359
|
-
return key;
|
1360
|
-
}).join('/')));
|
1361
|
-
}
|
1362
|
-
stack.push(value);
|
1363
|
-
keys.push(subKey);
|
1364
|
-
} else {
|
1365
|
-
stack.push(value);
|
1366
|
-
}
|
1367
|
-
}
|
1368
|
-
if (Object.isFrozen(target) || isDraft(target)) {
|
1369
|
-
{
|
1370
|
-
stack.pop();
|
1371
|
-
keys.pop();
|
1372
|
-
}
|
1373
|
-
return;
|
1374
|
-
}
|
1375
|
-
var type = getType(target);
|
1376
|
-
switch (type) {
|
1377
|
-
case 2 /* DraftType.Map */:
|
1378
|
-
var _iterator = _createForOfIteratorHelper(target),
|
1379
|
-
_step;
|
1380
|
-
try {
|
1381
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
1382
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
1383
|
-
key = _step$value[0],
|
1384
|
-
_value2 = _step$value[1];
|
1385
|
-
deepFreeze(key, key, updatedValues, stack, keys);
|
1386
|
-
deepFreeze(_value2, key, updatedValues, stack, keys);
|
1387
|
-
}
|
1388
|
-
} catch (err) {
|
1389
|
-
_iterator.e(err);
|
1390
|
-
} finally {
|
1391
|
-
_iterator.f();
|
1392
|
-
}
|
1393
|
-
target.set = target.clear = target["delete"] = throwFrozenError;
|
1394
|
-
break;
|
1395
|
-
case 3 /* DraftType.Set */:
|
1396
|
-
var _iterator2 = _createForOfIteratorHelper(target),
|
1397
|
-
_step2;
|
1398
|
-
try {
|
1399
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
1400
|
-
var _value3 = _step2.value;
|
1401
|
-
deepFreeze(_value3, _value3, updatedValues, stack, keys);
|
1402
|
-
}
|
1403
|
-
} catch (err) {
|
1404
|
-
_iterator2.e(err);
|
1405
|
-
} finally {
|
1406
|
-
_iterator2.f();
|
1407
|
-
}
|
1408
|
-
target.add = target.clear = target["delete"] = throwFrozenError;
|
1409
|
-
break;
|
1410
|
-
case 1 /* DraftType.Array */:
|
1411
|
-
Object.freeze(target);
|
1412
|
-
var _index = 0;
|
1413
|
-
var _iterator3 = _createForOfIteratorHelper(target),
|
1414
|
-
_step3;
|
1415
|
-
try {
|
1416
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
1417
|
-
var _value4 = _step3.value;
|
1418
|
-
deepFreeze(_value4, _index, updatedValues, stack, keys);
|
1419
|
-
_index += 1;
|
1420
|
-
}
|
1421
|
-
} catch (err) {
|
1422
|
-
_iterator3.e(err);
|
1423
|
-
} finally {
|
1424
|
-
_iterator3.f();
|
1425
|
-
}
|
1426
|
-
break;
|
1427
|
-
default:
|
1428
|
-
Object.freeze(target);
|
1429
|
-
// ignore non-enumerable or symbol properties
|
1430
|
-
Object.keys(target).forEach(function (name) {
|
1431
|
-
var value = target[name];
|
1432
|
-
deepFreeze(value, name, updatedValues, stack, keys);
|
1433
|
-
});
|
1434
|
-
}
|
1435
|
-
{
|
1436
|
-
stack.pop();
|
1437
|
-
keys.pop();
|
1438
|
-
}
|
1439
|
-
}
|
1440
|
-
function forEach(target, iter) {
|
1441
|
-
var type = getType(target);
|
1442
|
-
if (type === 0 /* DraftType.Object */) {
|
1443
|
-
Reflect.ownKeys(target).forEach(function (key) {
|
1444
|
-
iter(key, target[key], target);
|
1445
|
-
});
|
1446
|
-
} else if (type === 1 /* DraftType.Array */) {
|
1447
|
-
var index = 0;
|
1448
|
-
var _iterator4 = _createForOfIteratorHelper(target),
|
1449
|
-
_step4;
|
1450
|
-
try {
|
1451
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
1452
|
-
var entry = _step4.value;
|
1453
|
-
iter(index, entry, target);
|
1454
|
-
index += 1;
|
1455
|
-
}
|
1456
|
-
} catch (err) {
|
1457
|
-
_iterator4.e(err);
|
1458
|
-
} finally {
|
1459
|
-
_iterator4.f();
|
1460
|
-
}
|
1461
|
-
} else {
|
1462
|
-
target.forEach(function (entry, index) {
|
1463
|
-
return iter(index, entry, target);
|
1464
|
-
});
|
1465
|
-
}
|
1466
|
-
}
|
1467
|
-
function handleValue(target, handledSet, options) {
|
1468
|
-
if (isDraft(target) || !isDraftable(target, options) || handledSet.has(target) || Object.isFrozen(target)) return;
|
1469
|
-
var isSet = target instanceof Set;
|
1470
|
-
var setMap = isSet ? new Map() : undefined;
|
1471
|
-
handledSet.add(target);
|
1472
|
-
forEach(target, function (key, value) {
|
1473
|
-
var _a;
|
1474
|
-
if (isDraft(value)) {
|
1475
|
-
var proxyDraft = getProxyDraft(value);
|
1476
|
-
ensureShallowCopy(proxyDraft);
|
1477
|
-
// A draft where a child node has been changed, or assigned a value
|
1478
|
-
var updatedValue = ((_a = proxyDraft.assignedMap) === null || _a === void 0 ? void 0 : _a.size) || proxyDraft.operated ? proxyDraft.copy : proxyDraft.original;
|
1479
|
-
// final update value
|
1480
|
-
set(isSet ? setMap : target, key, updatedValue);
|
1481
|
-
} else {
|
1482
|
-
handleValue(value, handledSet, options);
|
1483
|
-
}
|
1484
|
-
});
|
1485
|
-
if (setMap) {
|
1486
|
-
var _set = target;
|
1487
|
-
var values = Array.from(_set);
|
1488
|
-
_set.clear();
|
1489
|
-
values.forEach(function (value) {
|
1490
|
-
_set.add(setMap.has(value) ? setMap.get(value) : value);
|
1491
|
-
});
|
1492
|
-
}
|
1493
|
-
}
|
1494
|
-
function finalizeAssigned(proxyDraft, key) {
|
1495
|
-
// handle the draftable assigned values, and the value is not a draft
|
1496
|
-
var copy = proxyDraft.type === 3 /* DraftType.Set */ ? proxyDraft.setMap : proxyDraft.copy;
|
1497
|
-
if (proxyDraft.finalities.revoke.length > 1 && proxyDraft.assignedMap.get(key) && copy) {
|
1498
|
-
handleValue(get(copy, key), proxyDraft.finalities.handledSet, proxyDraft.options);
|
1499
|
-
}
|
1500
|
-
}
|
1501
|
-
function finalizeSetValue(target) {
|
1502
|
-
if (target.type === 3 /* DraftType.Set */ && target.copy) {
|
1503
|
-
target.copy.clear();
|
1504
|
-
target.setMap.forEach(function (value) {
|
1505
|
-
target.copy.add(getValue(value));
|
1506
|
-
});
|
1507
|
-
}
|
1508
|
-
}
|
1509
|
-
function finalizePatches(target, generatePatches, patches, inversePatches) {
|
1510
|
-
var shouldFinalize = target.operated && target.assignedMap && target.assignedMap.size > 0 && !target.finalized;
|
1511
|
-
if (shouldFinalize) {
|
1512
|
-
if (patches && inversePatches) {
|
1513
|
-
var basePath = getPath(target);
|
1514
|
-
if (basePath) {
|
1515
|
-
generatePatches(target, basePath, patches, inversePatches);
|
1516
|
-
}
|
1517
|
-
}
|
1518
|
-
target.finalized = true;
|
1519
|
-
}
|
1520
|
-
}
|
1521
|
-
function markFinalization(target, key, value, generatePatches) {
|
1522
|
-
var proxyDraft = getProxyDraft(value);
|
1523
|
-
if (proxyDraft) {
|
1524
|
-
// !case: assign the draft value
|
1525
|
-
if (!proxyDraft.callbacks) {
|
1526
|
-
proxyDraft.callbacks = [];
|
1527
|
-
}
|
1528
|
-
proxyDraft.callbacks.push(function (patches, inversePatches) {
|
1529
|
-
var _a;
|
1530
|
-
var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
|
1531
|
-
if (isEqual(get(copy, key), value)) {
|
1532
|
-
var updatedValue = proxyDraft.original;
|
1533
|
-
if (proxyDraft.copy) {
|
1534
|
-
updatedValue = proxyDraft.copy;
|
1535
|
-
}
|
1536
|
-
finalizeSetValue(target);
|
1537
|
-
finalizePatches(target, generatePatches, patches, inversePatches);
|
1538
|
-
if (target.options.enableAutoFreeze) {
|
1539
|
-
target.options.updatedValues = (_a = target.options.updatedValues) !== null && _a !== undefined ? _a : new WeakMap();
|
1540
|
-
target.options.updatedValues.set(updatedValue, proxyDraft.original);
|
1541
|
-
}
|
1542
|
-
// final update value
|
1543
|
-
set(copy, key, updatedValue);
|
1544
|
-
}
|
1545
|
-
});
|
1546
|
-
if (target.options.enableAutoFreeze) {
|
1547
|
-
// !case: assign the draft value in cross draft tree
|
1548
|
-
if (proxyDraft.finalities !== target.finalities) {
|
1549
|
-
target.options.enableAutoFreeze = false;
|
1550
|
-
}
|
1551
|
-
}
|
1552
|
-
}
|
1553
|
-
if (isDraftable(value, target.options)) {
|
1554
|
-
// !case: assign the non-draft value
|
1555
|
-
target.finalities.draft.push(function () {
|
1556
|
-
var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
|
1557
|
-
if (isEqual(get(copy, key), value)) {
|
1558
|
-
finalizeAssigned(target, key);
|
1559
|
-
}
|
1560
|
-
});
|
1561
|
-
}
|
1562
|
-
}
|
1563
|
-
function generateArrayPatches(proxyState, basePath, patches, inversePatches, pathAsArray) {
|
1564
|
-
var original = proxyState.original,
|
1565
|
-
assignedMap = proxyState.assignedMap,
|
1566
|
-
options = proxyState.options;
|
1567
|
-
var copy = proxyState.copy;
|
1568
|
-
if (copy.length < original.length) {
|
1569
|
-
var _ref3 = [copy, original];
|
1570
|
-
original = _ref3[0];
|
1571
|
-
copy = _ref3[1];
|
1572
|
-
var _ref4 = [inversePatches, patches];
|
1573
|
-
patches = _ref4[0];
|
1574
|
-
inversePatches = _ref4[1];
|
1575
|
-
}
|
1576
|
-
for (var index = 0; index < original.length; index += 1) {
|
1577
|
-
if (assignedMap.get(index.toString()) && copy[index] !== original[index]) {
|
1578
|
-
var _path = basePath.concat([index]);
|
1579
|
-
var path = escapePath(_path, pathAsArray);
|
1580
|
-
patches.push({
|
1581
|
-
op: Operation.Replace,
|
1582
|
-
path: path,
|
1583
|
-
// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
|
1584
|
-
value: cloneIfNeeded(copy[index])
|
1585
|
-
});
|
1586
|
-
inversePatches.push({
|
1587
|
-
op: Operation.Replace,
|
1588
|
-
path: path,
|
1589
|
-
// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
|
1590
|
-
value: cloneIfNeeded(original[index])
|
1591
|
-
});
|
1592
|
-
}
|
1593
|
-
}
|
1594
|
-
for (var _index2 = original.length; _index2 < copy.length; _index2 += 1) {
|
1595
|
-
var _path2 = basePath.concat([_index2]);
|
1596
|
-
var _path3 = escapePath(_path2, pathAsArray);
|
1597
|
-
patches.push({
|
1598
|
-
op: Operation.Add,
|
1599
|
-
path: _path3,
|
1600
|
-
// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
|
1601
|
-
value: cloneIfNeeded(copy[_index2])
|
1602
|
-
});
|
1603
|
-
}
|
1604
|
-
if (original.length < copy.length) {
|
1605
|
-
// https://www.rfc-editor.org/rfc/rfc6902#appendix-A.4
|
1606
|
-
// For performance, here we only generate an operation that replaces the length of the array,
|
1607
|
-
// which is inconsistent with JSON Patch specification
|
1608
|
-
var _options$enablePatche = options.enablePatches.arrayLengthAssignment,
|
1609
|
-
arrayLengthAssignment = _options$enablePatche === undefined ? true : _options$enablePatche;
|
1610
|
-
if (arrayLengthAssignment) {
|
1611
|
-
var _path4 = basePath.concat(['length']);
|
1612
|
-
var _path5 = escapePath(_path4, pathAsArray);
|
1613
|
-
inversePatches.push({
|
1614
|
-
op: Operation.Replace,
|
1615
|
-
path: _path5,
|
1616
|
-
value: original.length
|
1617
|
-
});
|
1618
|
-
} else {
|
1619
|
-
for (var _index3 = copy.length; original.length < _index3; _index3 -= 1) {
|
1620
|
-
var _path6 = basePath.concat([_index3 - 1]);
|
1621
|
-
var _path7 = escapePath(_path6, pathAsArray);
|
1622
|
-
inversePatches.push({
|
1623
|
-
op: Operation.Remove,
|
1624
|
-
path: _path7
|
1625
|
-
});
|
1626
|
-
}
|
1627
|
-
}
|
1628
|
-
}
|
1629
|
-
}
|
1630
|
-
function generatePatchesFromAssigned(_ref5, basePath, patches, inversePatches, pathAsArray) {
|
1631
|
-
var original = _ref5.original,
|
1632
|
-
copy = _ref5.copy,
|
1633
|
-
assignedMap = _ref5.assignedMap;
|
1634
|
-
assignedMap.forEach(function (assignedValue, key) {
|
1635
|
-
var originalValue = get(original, key);
|
1636
|
-
var value = cloneIfNeeded(get(copy, key));
|
1637
|
-
var op = !assignedValue ? Operation.Remove : has(original, key) ? Operation.Replace : Operation.Add;
|
1638
|
-
if (isEqual(originalValue, value) && op === Operation.Replace) return;
|
1639
|
-
var _path = basePath.concat(key);
|
1640
|
-
var path = escapePath(_path, pathAsArray);
|
1641
|
-
patches.push(op === Operation.Remove ? {
|
1642
|
-
op: op,
|
1643
|
-
path: path
|
1644
|
-
} : {
|
1645
|
-
op: op,
|
1646
|
-
path: path,
|
1647
|
-
value: value
|
1648
|
-
});
|
1649
|
-
inversePatches.push(op === Operation.Add ? {
|
1650
|
-
op: Operation.Remove,
|
1651
|
-
path: path
|
1652
|
-
} : op === Operation.Remove ? {
|
1653
|
-
op: Operation.Add,
|
1654
|
-
path: path,
|
1655
|
-
value: originalValue
|
1656
|
-
} : {
|
1657
|
-
op: Operation.Replace,
|
1658
|
-
path: path,
|
1659
|
-
value: originalValue
|
1660
|
-
});
|
1661
|
-
});
|
1662
|
-
}
|
1663
|
-
function generateSetPatches(_ref6, basePath, patches, inversePatches, pathAsArray) {
|
1664
|
-
var original = _ref6.original,
|
1665
|
-
copy = _ref6.copy;
|
1666
|
-
var index = 0;
|
1667
|
-
original.forEach(function (value) {
|
1668
|
-
if (!copy.has(value)) {
|
1669
|
-
var _path = basePath.concat([index]);
|
1670
|
-
var path = escapePath(_path, pathAsArray);
|
1671
|
-
patches.push({
|
1672
|
-
op: Operation.Remove,
|
1673
|
-
path: path,
|
1674
|
-
value: value
|
1675
|
-
});
|
1676
|
-
inversePatches.unshift({
|
1677
|
-
op: Operation.Add,
|
1678
|
-
path: path,
|
1679
|
-
value: value
|
1680
|
-
});
|
1681
|
-
}
|
1682
|
-
index += 1;
|
1683
|
-
});
|
1684
|
-
index = 0;
|
1685
|
-
copy.forEach(function (value) {
|
1686
|
-
if (!original.has(value)) {
|
1687
|
-
var _path = basePath.concat([index]);
|
1688
|
-
var path = escapePath(_path, pathAsArray);
|
1689
|
-
patches.push({
|
1690
|
-
op: Operation.Add,
|
1691
|
-
path: path,
|
1692
|
-
value: value
|
1693
|
-
});
|
1694
|
-
inversePatches.unshift({
|
1695
|
-
op: Operation.Remove,
|
1696
|
-
path: path,
|
1697
|
-
value: value
|
1698
|
-
});
|
1699
|
-
}
|
1700
|
-
index += 1;
|
1701
|
-
});
|
1702
|
-
}
|
1703
|
-
function generatePatches(proxyState, basePath, patches, inversePatches) {
|
1704
|
-
var _proxyState$options$e = proxyState.options.enablePatches.pathAsArray,
|
1705
|
-
pathAsArray = _proxyState$options$e === undefined ? true : _proxyState$options$e;
|
1706
|
-
switch (proxyState.type) {
|
1707
|
-
case 0 /* DraftType.Object */:
|
1708
|
-
case 2 /* DraftType.Map */:
|
1709
|
-
return generatePatchesFromAssigned(proxyState, basePath, patches, inversePatches, pathAsArray);
|
1710
|
-
case 1 /* DraftType.Array */:
|
1711
|
-
return generateArrayPatches(proxyState, basePath, patches, inversePatches, pathAsArray);
|
1712
|
-
case 3 /* DraftType.Set */:
|
1713
|
-
return generateSetPatches(proxyState, basePath, patches, inversePatches, pathAsArray);
|
1714
|
-
}
|
1715
|
-
}
|
1716
|
-
var checkReadable = function checkReadable(value, options) {
|
1717
|
-
var ignoreCheckDraftable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
1718
|
-
if (_typeof(value) === 'object' && value !== null && (!isDraftable(value, options) || ignoreCheckDraftable) && true) {
|
1719
|
-
throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
|
1720
|
-
}
|
1721
|
-
};
|
1722
|
-
var mapHandler = _defineProperty({
|
1723
|
-
get size() {
|
1724
|
-
var current = latest(getProxyDraft(this));
|
1725
|
-
return current.size;
|
1726
|
-
},
|
1727
|
-
has: function has(key) {
|
1728
|
-
return latest(getProxyDraft(this)).has(key);
|
1729
|
-
},
|
1730
|
-
set: function set(key, value) {
|
1731
|
-
var target = getProxyDraft(this);
|
1732
|
-
var source = latest(target);
|
1733
|
-
if (!source.has(key) || !isEqual(source.get(key), value)) {
|
1734
|
-
ensureShallowCopy(target);
|
1735
|
-
markChanged(target);
|
1736
|
-
target.assignedMap.set(key, true);
|
1737
|
-
target.copy.set(key, value);
|
1738
|
-
markFinalization(target, key, value, generatePatches);
|
1739
|
-
}
|
1740
|
-
return this;
|
1741
|
-
},
|
1742
|
-
"delete": function _delete(key) {
|
1743
|
-
if (!this.has(key)) {
|
1744
|
-
return false;
|
1745
|
-
}
|
1746
|
-
var target = getProxyDraft(this);
|
1747
|
-
ensureShallowCopy(target);
|
1748
|
-
markChanged(target);
|
1749
|
-
if (target.original.has(key)) {
|
1750
|
-
target.assignedMap.set(key, false);
|
1751
|
-
} else {
|
1752
|
-
target.assignedMap["delete"](key);
|
1753
|
-
}
|
1754
|
-
target.copy["delete"](key);
|
1755
|
-
return true;
|
1756
|
-
},
|
1757
|
-
clear: function clear() {
|
1758
|
-
var target = getProxyDraft(this);
|
1759
|
-
if (!this.size) return;
|
1760
|
-
ensureShallowCopy(target);
|
1761
|
-
markChanged(target);
|
1762
|
-
target.assignedMap = new Map();
|
1763
|
-
var _iterator5 = _createForOfIteratorHelper(target.original),
|
1764
|
-
_step5;
|
1765
|
-
try {
|
1766
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
1767
|
-
var _step5$value = _slicedToArray(_step5.value, 1),
|
1768
|
-
key = _step5$value[0];
|
1769
|
-
target.assignedMap.set(key, false);
|
1770
|
-
}
|
1771
|
-
} catch (err) {
|
1772
|
-
_iterator5.e(err);
|
1773
|
-
} finally {
|
1774
|
-
_iterator5.f();
|
1775
|
-
}
|
1776
|
-
target.copy.clear();
|
1777
|
-
},
|
1778
|
-
forEach: function forEach(callback, thisArg) {
|
1779
|
-
var _this = this;
|
1780
|
-
var target = getProxyDraft(this);
|
1781
|
-
latest(target).forEach(function (_value, _key) {
|
1782
|
-
callback.call(thisArg, _this.get(_key), _key, _this);
|
1783
|
-
});
|
1784
|
-
},
|
1785
|
-
get: function get(key) {
|
1786
|
-
var _a, _b;
|
1787
|
-
var target = getProxyDraft(this);
|
1788
|
-
var value = latest(target).get(key);
|
1789
|
-
var mutable = ((_b = (_a = target.options).mark) === null || _b === undefined ? undefined : _b.call(_a, value, dataTypes)) === dataTypes.mutable;
|
1790
|
-
if (target.options.strict) {
|
1791
|
-
checkReadable(value, target.options, mutable);
|
1792
|
-
}
|
1793
|
-
if (mutable) {
|
1794
|
-
return value;
|
1795
|
-
}
|
1796
|
-
if (target.finalized || !isDraftable(value, target.options)) {
|
1797
|
-
return value;
|
1798
|
-
}
|
1799
|
-
// drafted or reassigned
|
1800
|
-
if (value !== target.original.get(key)) {
|
1801
|
-
return value;
|
1802
|
-
}
|
1803
|
-
var draft = internal.createDraft({
|
1804
|
-
original: value,
|
1805
|
-
parentDraft: target,
|
1806
|
-
key: key,
|
1807
|
-
finalities: target.finalities,
|
1808
|
-
options: target.options
|
1809
|
-
});
|
1810
|
-
ensureShallowCopy(target);
|
1811
|
-
target.copy.set(key, draft);
|
1812
|
-
return draft;
|
1813
|
-
},
|
1814
|
-
keys: function keys() {
|
1815
|
-
return latest(getProxyDraft(this)).keys();
|
1816
|
-
},
|
1817
|
-
values: function values() {
|
1818
|
-
var _this2 = this;
|
1819
|
-
var iterator = this.keys();
|
1820
|
-
return _defineProperty(_defineProperty({}, iteratorSymbol, function () {
|
1821
|
-
return _this2.values();
|
1822
|
-
}), "next", function next() {
|
1823
|
-
var result = iterator.next();
|
1824
|
-
if (result.done) return result;
|
1825
|
-
var value = _this2.get(result.value);
|
1826
|
-
return {
|
1827
|
-
done: false,
|
1828
|
-
value: value
|
1829
|
-
};
|
1830
|
-
});
|
1831
|
-
},
|
1832
|
-
entries: function entries() {
|
1833
|
-
var _this3 = this;
|
1834
|
-
var iterator = this.keys();
|
1835
|
-
return _defineProperty(_defineProperty({}, iteratorSymbol, function () {
|
1836
|
-
return _this3.entries();
|
1837
|
-
}), "next", function next() {
|
1838
|
-
var result = iterator.next();
|
1839
|
-
if (result.done) return result;
|
1840
|
-
var value = _this3.get(result.value);
|
1841
|
-
return {
|
1842
|
-
done: false,
|
1843
|
-
value: [result.value, value]
|
1844
|
-
};
|
1845
|
-
});
|
1846
|
-
}
|
1847
|
-
}, iteratorSymbol, function () {
|
1848
|
-
return this.entries();
|
1849
|
-
});
|
1850
|
-
var mapHandlerKeys = Reflect.ownKeys(mapHandler);
|
1851
|
-
var getNextIterator = function getNextIterator(target, iterator, _ref9) {
|
1852
|
-
var isValuesIterator = _ref9.isValuesIterator;
|
1853
|
-
return function () {
|
1854
|
-
var _a, _b;
|
1855
|
-
var result = iterator.next();
|
1856
|
-
if (result.done) return result;
|
1857
|
-
var key = result.value;
|
1858
|
-
var value = target.setMap.get(key);
|
1859
|
-
var currentDraft = getProxyDraft(value);
|
1860
|
-
var mutable = ((_b = (_a = target.options).mark) === null || _b === undefined ? undefined : _b.call(_a, value, dataTypes)) === dataTypes.mutable;
|
1861
|
-
if (target.options.strict) {
|
1862
|
-
checkReadable(key, target.options, mutable);
|
1863
|
-
}
|
1864
|
-
if (!mutable && !currentDraft && isDraftable(key, target.options) && !target.finalized && target.original.has(key)) {
|
1865
|
-
// draft a draftable original set item
|
1866
|
-
var proxy = internal.createDraft({
|
1867
|
-
original: key,
|
1868
|
-
parentDraft: target,
|
1869
|
-
key: key,
|
1870
|
-
finalities: target.finalities,
|
1871
|
-
options: target.options
|
1872
|
-
});
|
1873
|
-
target.setMap.set(key, proxy);
|
1874
|
-
value = proxy;
|
1875
|
-
} else if (currentDraft) {
|
1876
|
-
// drafted
|
1877
|
-
value = currentDraft.proxy;
|
1878
|
-
}
|
1879
|
-
return {
|
1880
|
-
done: false,
|
1881
|
-
value: isValuesIterator ? value : [value, value]
|
1882
|
-
};
|
1883
|
-
};
|
1884
|
-
};
|
1885
|
-
var setHandler = _defineProperty(_defineProperty({
|
1886
|
-
get size() {
|
1887
|
-
var target = getProxyDraft(this);
|
1888
|
-
return target.setMap.size;
|
1889
|
-
},
|
1890
|
-
has: function has(value) {
|
1891
|
-
var target = getProxyDraft(this);
|
1892
|
-
// reassigned or non-draftable values
|
1893
|
-
if (target.setMap.has(value)) return true;
|
1894
|
-
ensureShallowCopy(target);
|
1895
|
-
var valueProxyDraft = getProxyDraft(value);
|
1896
|
-
// drafted
|
1897
|
-
if (valueProxyDraft && target.setMap.has(valueProxyDraft.original)) return true;
|
1898
|
-
return false;
|
1899
|
-
},
|
1900
|
-
add: function add(value) {
|
1901
|
-
var target = getProxyDraft(this);
|
1902
|
-
if (!this.has(value)) {
|
1903
|
-
ensureShallowCopy(target);
|
1904
|
-
markChanged(target);
|
1905
|
-
target.assignedMap.set(value, true);
|
1906
|
-
target.setMap.set(value, value);
|
1907
|
-
markFinalization(target, value, value, generatePatches);
|
1908
|
-
}
|
1909
|
-
return this;
|
1910
|
-
},
|
1911
|
-
"delete": function _delete(value) {
|
1912
|
-
if (!this.has(value)) {
|
1913
|
-
return false;
|
1914
|
-
}
|
1915
|
-
var target = getProxyDraft(this);
|
1916
|
-
ensureShallowCopy(target);
|
1917
|
-
markChanged(target);
|
1918
|
-
var valueProxyDraft = getProxyDraft(value);
|
1919
|
-
if (valueProxyDraft && target.setMap.has(valueProxyDraft.original)) {
|
1920
|
-
// delete drafted
|
1921
|
-
target.assignedMap.set(valueProxyDraft.original, false);
|
1922
|
-
return target.setMap["delete"](valueProxyDraft.original);
|
1923
|
-
}
|
1924
|
-
if (!valueProxyDraft && target.setMap.has(value)) {
|
1925
|
-
// non-draftable values
|
1926
|
-
target.assignedMap.set(value, false);
|
1927
|
-
} else {
|
1928
|
-
// reassigned
|
1929
|
-
target.assignedMap["delete"](value);
|
1930
|
-
}
|
1931
|
-
// delete reassigned or non-draftable values
|
1932
|
-
return target.setMap["delete"](value);
|
1933
|
-
},
|
1934
|
-
clear: function clear() {
|
1935
|
-
if (!this.size) return;
|
1936
|
-
var target = getProxyDraft(this);
|
1937
|
-
ensureShallowCopy(target);
|
1938
|
-
markChanged(target);
|
1939
|
-
var _iterator6 = _createForOfIteratorHelper(target.original),
|
1940
|
-
_step6;
|
1941
|
-
try {
|
1942
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
1943
|
-
var value = _step6.value;
|
1944
|
-
target.assignedMap.set(value, false);
|
1945
|
-
}
|
1946
|
-
} catch (err) {
|
1947
|
-
_iterator6.e(err);
|
1948
|
-
} finally {
|
1949
|
-
_iterator6.f();
|
1950
|
-
}
|
1951
|
-
target.setMap.clear();
|
1952
|
-
},
|
1953
|
-
values: function values() {
|
1954
|
-
var _this4 = this;
|
1955
|
-
var target = getProxyDraft(this);
|
1956
|
-
ensureShallowCopy(target);
|
1957
|
-
var iterator = target.setMap.keys();
|
1958
|
-
return _defineProperty(_defineProperty({}, Symbol.iterator, function () {
|
1959
|
-
return _this4.values();
|
1960
|
-
}), "next", getNextIterator(target, iterator, {
|
1961
|
-
isValuesIterator: true
|
1962
|
-
}));
|
1963
|
-
},
|
1964
|
-
entries: function entries() {
|
1965
|
-
var _this5 = this;
|
1966
|
-
var target = getProxyDraft(this);
|
1967
|
-
ensureShallowCopy(target);
|
1968
|
-
var iterator = target.setMap.keys();
|
1969
|
-
return _defineProperty(_defineProperty({}, Symbol.iterator, function () {
|
1970
|
-
return _this5.entries();
|
1971
|
-
}), "next", getNextIterator(target, iterator, {
|
1972
|
-
isValuesIterator: false
|
1973
|
-
}));
|
1974
|
-
},
|
1975
|
-
keys: function keys() {
|
1976
|
-
return this.values();
|
1977
|
-
}
|
1978
|
-
}, iteratorSymbol, function () {
|
1979
|
-
return this.values();
|
1980
|
-
}), "forEach", function forEach(callback, thisArg) {
|
1981
|
-
var iterator = this.values();
|
1982
|
-
var result = iterator.next();
|
1983
|
-
while (!result.done) {
|
1984
|
-
callback.call(thisArg, result.value, result.value, this);
|
1985
|
-
result = iterator.next();
|
1986
|
-
}
|
1987
|
-
});
|
1988
|
-
if (Set.prototype.difference) {
|
1989
|
-
// for compatibility with new Set methods
|
1990
|
-
// https://github.com/tc39/proposal-set-methods
|
1991
|
-
// And `https://github.com/tc39/proposal-set-methods/blob/main/details.md#symbolspecies` has some details about the `@@species` symbol.
|
1992
|
-
// So we can't use SubSet instance constructor to get the constructor of the SubSet instance.
|
1993
|
-
Object.assign(setHandler, {
|
1994
|
-
intersection: function intersection(other) {
|
1995
|
-
return Set.prototype.intersection.call(new Set(this.values()), other);
|
1996
|
-
},
|
1997
|
-
union: function union(other) {
|
1998
|
-
return Set.prototype.union.call(new Set(this.values()), other);
|
1999
|
-
},
|
2000
|
-
difference: function difference(other) {
|
2001
|
-
return Set.prototype.difference.call(new Set(this.values()), other);
|
2002
|
-
},
|
2003
|
-
symmetricDifference: function symmetricDifference(other) {
|
2004
|
-
return Set.prototype.symmetricDifference.call(new Set(this.values()), other);
|
2005
|
-
},
|
2006
|
-
isSubsetOf: function isSubsetOf(other) {
|
2007
|
-
return Set.prototype.isSubsetOf.call(new Set(this.values()), other);
|
2008
|
-
},
|
2009
|
-
isSupersetOf: function isSupersetOf(other) {
|
2010
|
-
return Set.prototype.isSupersetOf.call(new Set(this.values()), other);
|
2011
|
-
},
|
2012
|
-
isDisjointFrom: function isDisjointFrom(other) {
|
2013
|
-
return Set.prototype.isDisjointFrom.call(new Set(this.values()), other);
|
2014
|
-
}
|
2015
|
-
});
|
2016
|
-
}
|
2017
|
-
var setHandlerKeys = Reflect.ownKeys(setHandler);
|
2018
|
-
var draftsCache = new WeakSet();
|
2019
|
-
var proxyHandler = {
|
2020
|
-
get: function get(target, key, receiver) {
|
2021
|
-
var _a, _b;
|
2022
|
-
var copy = (_a = target.copy) === null || _a === undefined ? undefined : _a[key];
|
2023
|
-
// Improve draft reading performance by caching the draft copy.
|
2024
|
-
if (copy && draftsCache.has(copy)) {
|
2025
|
-
return copy;
|
2026
|
-
}
|
2027
|
-
if (key === PROXY_DRAFT) return target;
|
2028
|
-
var markResult;
|
2029
|
-
if (target.options.mark) {
|
2030
|
-
// handle `Uncaught TypeError: Method get Map.prototype.size called on incompatible receiver #<Map>`
|
2031
|
-
// or `Uncaught TypeError: Method get Set.prototype.size called on incompatible receiver #<Set>`
|
2032
|
-
var _value5 = key === 'size' && (target.original instanceof Map || target.original instanceof Set) ? Reflect.get(target.original, key) : Reflect.get(target.original, key, receiver);
|
2033
|
-
markResult = target.options.mark(_value5, dataTypes);
|
2034
|
-
if (markResult === dataTypes.mutable) {
|
2035
|
-
if (target.options.strict) {
|
2036
|
-
checkReadable(_value5, target.options, true);
|
2037
|
-
}
|
2038
|
-
return _value5;
|
2039
|
-
}
|
2040
|
-
}
|
2041
|
-
var source = latest(target);
|
2042
|
-
if (source instanceof Map && mapHandlerKeys.includes(key)) {
|
2043
|
-
if (key === 'size') {
|
2044
|
-
return Object.getOwnPropertyDescriptor(mapHandler, 'size').get.call(target.proxy);
|
2045
|
-
}
|
2046
|
-
var handle = mapHandler[key];
|
2047
|
-
if (handle) {
|
2048
|
-
return handle.bind(target.proxy);
|
2049
|
-
}
|
2050
|
-
}
|
2051
|
-
if (source instanceof Set && setHandlerKeys.includes(key)) {
|
2052
|
-
if (key === 'size') {
|
2053
|
-
return Object.getOwnPropertyDescriptor(setHandler, 'size').get.call(target.proxy);
|
2054
|
-
}
|
2055
|
-
var _handle = setHandler[key];
|
2056
|
-
if (_handle) {
|
2057
|
-
return _handle.bind(target.proxy);
|
2058
|
-
}
|
2059
|
-
}
|
2060
|
-
if (!has(source, key)) {
|
2061
|
-
var desc = getDescriptor(source, key);
|
2062
|
-
return desc ? "value" in desc ? desc.value :
|
2063
|
-
// !case: support for getter
|
2064
|
-
(_b = desc.get) === null || _b === undefined ? undefined : _b.call(target.proxy) : undefined;
|
2065
|
-
}
|
2066
|
-
var value = source[key];
|
2067
|
-
if (target.options.strict) {
|
2068
|
-
checkReadable(value, target.options);
|
2069
|
-
}
|
2070
|
-
if (target.finalized || !isDraftable(value, target.options)) {
|
2071
|
-
return value;
|
2072
|
-
}
|
2073
|
-
// Ensure that the assigned values are not drafted
|
2074
|
-
if (value === peek(target.original, key)) {
|
2075
|
-
ensureShallowCopy(target);
|
2076
|
-
target.copy[key] = createDraft({
|
2077
|
-
original: target.original[key],
|
2078
|
-
parentDraft: target,
|
2079
|
-
key: target.type === 1 /* DraftType.Array */ ? Number(key) : key,
|
2080
|
-
finalities: target.finalities,
|
2081
|
-
options: target.options
|
2082
|
-
});
|
2083
|
-
// !case: support for custom shallow copy function
|
2084
|
-
if (typeof markResult === 'function') {
|
2085
|
-
var subProxyDraft = getProxyDraft(target.copy[key]);
|
2086
|
-
ensureShallowCopy(subProxyDraft);
|
2087
|
-
// Trigger a custom shallow copy to update to a new copy
|
2088
|
-
markChanged(subProxyDraft);
|
2089
|
-
return subProxyDraft.copy;
|
2090
|
-
}
|
2091
|
-
return target.copy[key];
|
2092
|
-
}
|
2093
|
-
return value;
|
2094
|
-
},
|
2095
|
-
set: function set(target, key, value) {
|
2096
|
-
var _a;
|
2097
|
-
if (target.type === 3 /* DraftType.Set */ || target.type === 2 /* DraftType.Map */) {
|
2098
|
-
throw new Error("Map/Set draft does not support any property assignment.");
|
2099
|
-
}
|
2100
|
-
var _key;
|
2101
|
-
if (target.type === 1 /* DraftType.Array */ && key !== 'length' && !(Number.isInteger(_key = Number(key)) && _key >= 0 && (key === 0 || _key === 0 || String(_key) === String(key)))) {
|
2102
|
-
throw new Error("Only supports setting array indices and the 'length' property.");
|
2103
|
-
}
|
2104
|
-
var desc = getDescriptor(latest(target), key);
|
2105
|
-
if (desc === null || desc === undefined ? undefined : desc.set) {
|
2106
|
-
// !case: cover the case of setter
|
2107
|
-
desc.set.call(target.proxy, value);
|
2108
|
-
return true;
|
2109
|
-
}
|
2110
|
-
var current = peek(latest(target), key);
|
2111
|
-
var currentProxyDraft = getProxyDraft(current);
|
2112
|
-
if (currentProxyDraft && isEqual(currentProxyDraft.original, value)) {
|
2113
|
-
// !case: ignore the case of assigning the original draftable value to a draft
|
2114
|
-
target.copy[key] = value;
|
2115
|
-
target.assignedMap = (_a = target.assignedMap) !== null && _a !== undefined ? _a : new Map();
|
2116
|
-
target.assignedMap.set(key, false);
|
2117
|
-
return true;
|
2118
|
-
}
|
2119
|
-
// !case: handle new props with value 'undefined'
|
2120
|
-
if (isEqual(value, current) && (value !== undefined || has(target.original, key))) return true;
|
2121
|
-
ensureShallowCopy(target);
|
2122
|
-
markChanged(target);
|
2123
|
-
if (has(target.original, key) && isEqual(value, target.original[key])) {
|
2124
|
-
// !case: handle the case of assigning the original non-draftable value to a draft
|
2125
|
-
target.assignedMap["delete"](key);
|
2126
|
-
} else {
|
2127
|
-
target.assignedMap.set(key, true);
|
2128
|
-
}
|
2129
|
-
target.copy[key] = value;
|
2130
|
-
markFinalization(target, key, value, generatePatches);
|
2131
|
-
return true;
|
2132
|
-
},
|
2133
|
-
has: function has(target, key) {
|
2134
|
-
return key in latest(target);
|
2135
|
-
},
|
2136
|
-
ownKeys: function ownKeys(target) {
|
2137
|
-
return Reflect.ownKeys(latest(target));
|
2138
|
-
},
|
2139
|
-
getOwnPropertyDescriptor: function getOwnPropertyDescriptor(target, key) {
|
2140
|
-
var source = latest(target);
|
2141
|
-
var descriptor = Reflect.getOwnPropertyDescriptor(source, key);
|
2142
|
-
if (!descriptor) return descriptor;
|
2143
|
-
return {
|
2144
|
-
writable: true,
|
2145
|
-
configurable: target.type !== 1 /* DraftType.Array */ || key !== 'length',
|
2146
|
-
enumerable: descriptor.enumerable,
|
2147
|
-
value: source[key]
|
2148
|
-
};
|
2149
|
-
},
|
2150
|
-
getPrototypeOf: function getPrototypeOf(target) {
|
2151
|
-
return Reflect.getPrototypeOf(target.original);
|
2152
|
-
},
|
2153
|
-
setPrototypeOf: function setPrototypeOf() {
|
2154
|
-
throw new Error("Cannot call 'setPrototypeOf()' on drafts");
|
2155
|
-
},
|
2156
|
-
defineProperty: function defineProperty() {
|
2157
|
-
throw new Error("Cannot call 'defineProperty()' on drafts");
|
2158
|
-
},
|
2159
|
-
deleteProperty: function deleteProperty(target, key) {
|
2160
|
-
var _a;
|
2161
|
-
if (target.type === 1 /* DraftType.Array */) {
|
2162
|
-
return proxyHandler.set.call(this, target, key, undefined, target.proxy);
|
2163
|
-
}
|
2164
|
-
if (peek(target.original, key) !== undefined || key in target.original) {
|
2165
|
-
// !case: delete an existing key
|
2166
|
-
ensureShallowCopy(target);
|
2167
|
-
markChanged(target);
|
2168
|
-
target.assignedMap.set(key, false);
|
2169
|
-
} else {
|
2170
|
-
target.assignedMap = (_a = target.assignedMap) !== null && _a !== undefined ? _a : new Map();
|
2171
|
-
// The original non-existent key has been deleted
|
2172
|
-
target.assignedMap["delete"](key);
|
2173
|
-
}
|
2174
|
-
if (target.copy) delete target.copy[key];
|
2175
|
-
return true;
|
2176
|
-
}
|
2177
|
-
};
|
2178
|
-
function createDraft(createDraftOptions) {
|
2179
|
-
var original = createDraftOptions.original,
|
2180
|
-
parentDraft = createDraftOptions.parentDraft,
|
2181
|
-
key = createDraftOptions.key,
|
2182
|
-
finalities = createDraftOptions.finalities,
|
2183
|
-
options = createDraftOptions.options;
|
2184
|
-
var type = getType(original);
|
2185
|
-
var proxyDraft = {
|
2186
|
-
type: type,
|
2187
|
-
finalized: false,
|
2188
|
-
parent: parentDraft,
|
2189
|
-
original: original,
|
2190
|
-
copy: null,
|
2191
|
-
proxy: null,
|
2192
|
-
finalities: finalities,
|
2193
|
-
options: options,
|
2194
|
-
// Mapping of draft Set items to their corresponding draft values.
|
2195
|
-
setMap: type === 3 /* DraftType.Set */ ? new Map(original.entries()) : undefined
|
2196
|
-
};
|
2197
|
-
// !case: undefined as a draft map key
|
2198
|
-
if (key || 'key' in createDraftOptions) {
|
2199
|
-
proxyDraft.key = key;
|
2200
|
-
}
|
2201
|
-
var _Proxy$revocable = Proxy.revocable(type === 1 /* DraftType.Array */ ? Object.assign([], proxyDraft) : proxyDraft, proxyHandler),
|
2202
|
-
proxy = _Proxy$revocable.proxy,
|
2203
|
-
revoke = _Proxy$revocable.revoke;
|
2204
|
-
finalities.revoke.push(revoke);
|
2205
|
-
draftsCache.add(proxy);
|
2206
|
-
proxyDraft.proxy = proxy;
|
2207
|
-
if (parentDraft) {
|
2208
|
-
var target = parentDraft;
|
2209
|
-
target.finalities.draft.push(function (patches, inversePatches) {
|
2210
|
-
var _a, _b;
|
2211
|
-
var oldProxyDraft = getProxyDraft(proxy);
|
2212
|
-
// if target is a Set draft, `setMap` is the real Set copies proxy mapping.
|
2213
|
-
var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
|
2214
|
-
var draft = get(copy, key);
|
2215
|
-
var proxyDraft = getProxyDraft(draft);
|
2216
|
-
if (proxyDraft) {
|
2217
|
-
// assign the updated value to the copy object
|
2218
|
-
var updatedValue = proxyDraft.original;
|
2219
|
-
if (proxyDraft.operated) {
|
2220
|
-
updatedValue = getValue(draft);
|
2221
|
-
}
|
2222
|
-
finalizeSetValue(proxyDraft);
|
2223
|
-
finalizePatches(proxyDraft, generatePatches, patches, inversePatches);
|
2224
|
-
if (target.options.enableAutoFreeze) {
|
2225
|
-
target.options.updatedValues = (_a = target.options.updatedValues) !== null && _a !== undefined ? _a : new WeakMap();
|
2226
|
-
target.options.updatedValues.set(updatedValue, proxyDraft.original);
|
2227
|
-
}
|
2228
|
-
// final update value
|
2229
|
-
set(copy, key, updatedValue);
|
2230
|
-
}
|
2231
|
-
// !case: handle the deleted key
|
2232
|
-
(_b = oldProxyDraft.callbacks) === null || _b === undefined ? undefined : _b.forEach(function (callback) {
|
2233
|
-
callback(patches, inversePatches);
|
2234
|
-
});
|
2235
|
-
});
|
2236
|
-
} else {
|
2237
|
-
// !case: handle the root draft
|
2238
|
-
var _target = getProxyDraft(proxy);
|
2239
|
-
_target.finalities.draft.push(function (patches, inversePatches) {
|
2240
|
-
finalizeSetValue(_target);
|
2241
|
-
finalizePatches(_target, generatePatches, patches, inversePatches);
|
2242
|
-
});
|
2243
|
-
}
|
2244
|
-
return proxy;
|
2245
|
-
}
|
2246
|
-
internal.createDraft = createDraft;
|
2247
|
-
function finalizeDraft(result, returnedValue, patches, inversePatches, enableAutoFreeze) {
|
2248
|
-
var _a;
|
2249
|
-
var proxyDraft = getProxyDraft(result);
|
2250
|
-
var original = (_a = proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== null && _a !== undefined ? _a : result;
|
2251
|
-
var hasReturnedValue = !!returnedValue.length;
|
2252
|
-
if (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.operated) {
|
2253
|
-
while (proxyDraft.finalities.draft.length > 0) {
|
2254
|
-
var finalize = proxyDraft.finalities.draft.pop();
|
2255
|
-
finalize(patches, inversePatches);
|
2256
|
-
}
|
2257
|
-
}
|
2258
|
-
var state = hasReturnedValue ? returnedValue[0] : proxyDraft ? proxyDraft.operated ? proxyDraft.copy : proxyDraft.original : result;
|
2259
|
-
if (proxyDraft) revokeProxy(proxyDraft);
|
2260
|
-
if (enableAutoFreeze) {
|
2261
|
-
deepFreeze(state, state, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options.updatedValues);
|
2262
|
-
}
|
2263
|
-
return [state, patches && hasReturnedValue ? [{
|
2264
|
-
op: Operation.Replace,
|
2265
|
-
path: [],
|
2266
|
-
value: returnedValue[0]
|
2267
|
-
}] : patches, inversePatches && hasReturnedValue ? [{
|
2268
|
-
op: Operation.Replace,
|
2269
|
-
path: [],
|
2270
|
-
value: original
|
2271
|
-
}] : inversePatches];
|
2272
|
-
}
|
2273
|
-
function draftify(baseState, options) {
|
2274
|
-
var _a;
|
2275
|
-
var finalities = {
|
2276
|
-
draft: [],
|
2277
|
-
revoke: [],
|
2278
|
-
handledSet: new WeakSet()
|
2279
|
-
};
|
2280
|
-
var patches;
|
2281
|
-
var inversePatches;
|
2282
|
-
if (options.enablePatches) {
|
2283
|
-
patches = [];
|
2284
|
-
inversePatches = [];
|
2285
|
-
}
|
2286
|
-
var isMutable = ((_a = options.mark) === null || _a === undefined ? undefined : _a.call(options, baseState, dataTypes)) === dataTypes.mutable || !isDraftable(baseState, options);
|
2287
|
-
var draft = isMutable ? baseState : createDraft({
|
2288
|
-
original: baseState,
|
2289
|
-
parentDraft: null,
|
2290
|
-
finalities: finalities,
|
2291
|
-
options: options
|
2292
|
-
});
|
2293
|
-
return [draft, function () {
|
2294
|
-
var returnedValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
2295
|
-
var _finalizeDraft = finalizeDraft(draft, returnedValue, patches, inversePatches, options.enableAutoFreeze),
|
2296
|
-
_finalizeDraft2 = _slicedToArray(_finalizeDraft, 3),
|
2297
|
-
finalizedState = _finalizeDraft2[0],
|
2298
|
-
finalizedPatches = _finalizeDraft2[1],
|
2299
|
-
finalizedInversePatches = _finalizeDraft2[2];
|
2300
|
-
return options.enablePatches ? [finalizedState, finalizedPatches, finalizedInversePatches] : finalizedState;
|
2301
|
-
}];
|
2302
|
-
}
|
2303
|
-
function handleReturnValue(options) {
|
2304
|
-
var rootDraft = options.rootDraft,
|
2305
|
-
value = options.value,
|
2306
|
-
_options$useRawReturn = options.useRawReturn,
|
2307
|
-
useRawReturn = _options$useRawReturn === undefined ? false : _options$useRawReturn,
|
2308
|
-
_options$isRoot = options.isRoot,
|
2309
|
-
isRoot = _options$isRoot === undefined ? true : _options$isRoot;
|
2310
|
-
forEach(value, function (key, item, source) {
|
2311
|
-
var proxyDraft = getProxyDraft(item);
|
2312
|
-
// just handle the draft which is created by the same rootDraft
|
2313
|
-
if (proxyDraft && rootDraft && proxyDraft.finalities === rootDraft.finalities) {
|
2314
|
-
options.isContainDraft = true;
|
2315
|
-
var currentValue = proxyDraft.original;
|
2316
|
-
// final update value, but just handle return value
|
2317
|
-
if (source instanceof Set) {
|
2318
|
-
var arr = Array.from(source);
|
2319
|
-
source.clear();
|
2320
|
-
arr.forEach(function (_item) {
|
2321
|
-
return source.add(key === _item ? currentValue : _item);
|
2322
|
-
});
|
2323
|
-
} else {
|
2324
|
-
set(source, key, currentValue);
|
2325
|
-
}
|
2326
|
-
} else if (_typeof(item) === 'object' && item !== null) {
|
2327
|
-
options.value = item;
|
2328
|
-
options.isRoot = false;
|
2329
|
-
handleReturnValue(options);
|
2330
|
-
}
|
2331
|
-
});
|
2332
|
-
if (isRoot) {
|
2333
|
-
if (!options.isContainDraft) console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance.");
|
2334
|
-
if (useRawReturn) {
|
2335
|
-
console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value.");
|
2336
|
-
}
|
2337
|
-
}
|
2338
|
-
}
|
2339
|
-
function getCurrent(target) {
|
2340
|
-
var _a;
|
2341
|
-
var proxyDraft = getProxyDraft(target);
|
2342
|
-
if (!isDraftable(target, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options)) return target;
|
2343
|
-
var type = getType(target);
|
2344
|
-
if (proxyDraft && !proxyDraft.operated) return proxyDraft.original;
|
2345
|
-
var currentValue;
|
2346
|
-
function ensureShallowCopy() {
|
2347
|
-
currentValue = type === 2 /* DraftType.Map */ ? !isBaseMapInstance(target) ? new (Object.getPrototypeOf(target).constructor)(target) : new Map(target) : type === 3 /* DraftType.Set */ ? Array.from(proxyDraft.setMap.values()) : shallowCopy(target, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options);
|
2348
|
-
}
|
2349
|
-
if (proxyDraft) {
|
2350
|
-
// It's a proxy draft, let's create a shallow copy eagerly
|
2351
|
-
proxyDraft.finalized = true;
|
2352
|
-
try {
|
2353
|
-
ensureShallowCopy();
|
2354
|
-
} finally {
|
2355
|
-
proxyDraft.finalized = false;
|
2356
|
-
}
|
2357
|
-
} else {
|
2358
|
-
// It's not a proxy draft, let's use the target directly and let's see
|
2359
|
-
// lazily if we need to create a shallow copy
|
2360
|
-
currentValue = target;
|
2361
|
-
}
|
2362
|
-
forEach(currentValue, function (key, value) {
|
2363
|
-
if (proxyDraft && isEqual(get(proxyDraft.original, key), value)) return;
|
2364
|
-
var newValue = getCurrent(value);
|
2365
|
-
if (newValue !== value) {
|
2366
|
-
if (currentValue === target) ensureShallowCopy();
|
2367
|
-
set(currentValue, key, newValue);
|
2368
|
-
}
|
2369
|
-
});
|
2370
|
-
if (type === 3 /* DraftType.Set */) {
|
2371
|
-
var value = (_a = proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== null && _a !== undefined ? _a : currentValue;
|
2372
|
-
return !isBaseSetInstance(value) ? new (Object.getPrototypeOf(value).constructor)(currentValue) : new Set(currentValue);
|
2373
|
-
}
|
2374
|
-
return currentValue;
|
2375
|
-
}
|
2376
|
-
function current(target) {
|
2377
|
-
if (!isDraft(target)) {
|
2378
|
-
throw new Error("current() is only used for Draft, parameter: ".concat(target));
|
2379
|
-
}
|
2380
|
-
return getCurrent(target);
|
2381
|
-
}
|
2382
|
-
|
2383
|
-
/**
|
2384
|
-
* `makeCreator(options)` to make a creator function.
|
2385
|
-
*
|
2386
|
-
* ## Example
|
2387
|
-
*
|
2388
|
-
* ```ts
|
2389
|
-
* import { makeCreator } from '../index';
|
2390
|
-
*
|
2391
|
-
* const baseState = { foo: { bar: 'str' }, arr: [] };
|
2392
|
-
* const create = makeCreator({ enableAutoFreeze: true });
|
2393
|
-
* const state = create(
|
2394
|
-
* baseState,
|
2395
|
-
* (draft) => {
|
2396
|
-
* draft.foo.bar = 'str2';
|
2397
|
-
* },
|
2398
|
-
* );
|
2399
|
-
*
|
2400
|
-
* expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
|
2401
|
-
* expect(state).not.toBe(baseState);
|
2402
|
-
* expect(state.foo).not.toBe(baseState.foo);
|
2403
|
-
* expect(state.arr).toBe(baseState.arr);
|
2404
|
-
* expect(Object.isFrozen(state)).toBeTruthy();
|
2405
|
-
* ```
|
2406
|
-
*/
|
2407
|
-
var makeCreator = function makeCreator(arg) {
|
2408
|
-
return function create(arg0, arg1, arg2) {
|
2409
|
-
var _a, _b, _c;
|
2410
|
-
if (typeof arg0 === 'function' && typeof arg1 !== 'function') {
|
2411
|
-
return function (base) {
|
2412
|
-
var _this6 = this;
|
2413
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
|
2414
|
-
args[_key2 - 1] = arguments[_key2];
|
2415
|
-
}
|
2416
|
-
return create(base, function (draft) {
|
2417
|
-
return arg0.call.apply(arg0, [_this6, draft].concat(args));
|
2418
|
-
}, arg1);
|
2419
|
-
};
|
2420
|
-
}
|
2421
|
-
var base = arg0;
|
2422
|
-
var mutate = arg1;
|
2423
|
-
var options = arg2;
|
2424
|
-
if (typeof arg1 !== 'function') {
|
2425
|
-
options = arg1;
|
2426
|
-
}
|
2427
|
-
if (options !== undefined && Object.prototype.toString.call(options) !== '[object Object]') {
|
2428
|
-
throw new Error("Invalid options: ".concat(options, ", 'options' should be an object."));
|
2429
|
-
}
|
2430
|
-
options = Object.assign(Object.assign({}, arg), options);
|
2431
|
-
var state = isDraft(base) ? current(base) : base;
|
2432
|
-
var mark = Array.isArray(options.mark) ? function (value, types) {
|
2433
|
-
var _iterator7 = _createForOfIteratorHelper(options.mark),
|
2434
|
-
_step7;
|
2435
|
-
try {
|
2436
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
2437
|
-
var _mark = _step7.value;
|
2438
|
-
if (typeof _mark !== 'function') {
|
2439
|
-
throw new Error("Invalid mark: ".concat(_mark, ", 'mark' should be a function."));
|
2440
|
-
}
|
2441
|
-
var _result = _mark(value, types);
|
2442
|
-
if (_result) {
|
2443
|
-
return _result;
|
2444
|
-
}
|
2445
|
-
}
|
2446
|
-
} catch (err) {
|
2447
|
-
_iterator7.e(err);
|
2448
|
-
} finally {
|
2449
|
-
_iterator7.f();
|
2450
|
-
}
|
2451
|
-
return;
|
2452
|
-
} : options.mark;
|
2453
|
-
var enablePatches = (_a = options.enablePatches) !== null && _a !== undefined ? _a : false;
|
2454
|
-
var strict = (_b = options.strict) !== null && _b !== undefined ? _b : false;
|
2455
|
-
var enableAutoFreeze = (_c = options.enableAutoFreeze) !== null && _c !== undefined ? _c : false;
|
2456
|
-
var _options = {
|
2457
|
-
enableAutoFreeze: enableAutoFreeze,
|
2458
|
-
mark: mark,
|
2459
|
-
strict: strict,
|
2460
|
-
enablePatches: enablePatches
|
2461
|
-
};
|
2462
|
-
if (!isDraftable(state, _options) && _typeof(state) === 'object' && state !== null) {
|
2463
|
-
throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
|
2464
|
-
}
|
2465
|
-
var _draftify = draftify(state, _options),
|
2466
|
-
_draftify2 = _slicedToArray(_draftify, 2),
|
2467
|
-
draft = _draftify2[0],
|
2468
|
-
finalize = _draftify2[1];
|
2469
|
-
if (typeof arg1 !== 'function') {
|
2470
|
-
if (!isDraftable(state, _options)) {
|
2471
|
-
throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
|
2472
|
-
}
|
2473
|
-
return [draft, finalize];
|
2474
|
-
}
|
2475
|
-
var result;
|
2476
|
-
try {
|
2477
|
-
result = mutate(draft);
|
2478
|
-
} catch (error) {
|
2479
|
-
revokeProxy(getProxyDraft(draft));
|
2480
|
-
throw error;
|
2481
|
-
}
|
2482
|
-
var returnValue = function returnValue(value) {
|
2483
|
-
var proxyDraft = getProxyDraft(draft);
|
2484
|
-
if (!isDraft(value)) {
|
2485
|
-
if (value !== undefined && !isEqual(value, draft) && (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.operated)) {
|
2486
|
-
throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");
|
2487
|
-
}
|
2488
|
-
var rawReturnValue = value === null || value === undefined ? undefined : value[RAW_RETURN_SYMBOL];
|
2489
|
-
if (rawReturnValue) {
|
2490
|
-
var _value = rawReturnValue[0];
|
2491
|
-
if (_options.strict && _typeof(value) === 'object' && value !== null) {
|
2492
|
-
handleReturnValue({
|
2493
|
-
rootDraft: proxyDraft,
|
2494
|
-
value: value,
|
2495
|
-
useRawReturn: true
|
2496
|
-
});
|
2497
|
-
}
|
2498
|
-
return finalize([_value]);
|
2499
|
-
}
|
2500
|
-
if (value !== undefined) {
|
2501
|
-
if (_typeof(value) === 'object' && value !== null) {
|
2502
|
-
handleReturnValue({
|
2503
|
-
rootDraft: proxyDraft,
|
2504
|
-
value: value
|
2505
|
-
});
|
2506
|
-
}
|
2507
|
-
return finalize([value]);
|
2508
|
-
}
|
2509
|
-
}
|
2510
|
-
if (value === draft || value === undefined) {
|
2511
|
-
return finalize([]);
|
2512
|
-
}
|
2513
|
-
var returnedProxyDraft = getProxyDraft(value);
|
2514
|
-
if (_options === returnedProxyDraft.options) {
|
2515
|
-
if (returnedProxyDraft.operated) {
|
2516
|
-
throw new Error("Cannot return a modified child draft.");
|
2517
|
-
}
|
2518
|
-
return finalize([current(value)]);
|
2519
|
-
}
|
2520
|
-
return finalize([value]);
|
2521
|
-
};
|
2522
|
-
if (result instanceof Promise) {
|
2523
|
-
return result.then(returnValue, function (error) {
|
2524
|
-
revokeProxy(getProxyDraft(draft));
|
2525
|
-
throw error;
|
2526
|
-
});
|
2527
|
-
}
|
2528
|
-
return returnValue(result);
|
2529
|
-
};
|
2530
|
-
};
|
2531
|
-
|
2532
|
-
/**
|
2533
|
-
* `create(baseState, callback, options)` to create the next state
|
2534
|
-
*
|
2535
|
-
* ## Example
|
2536
|
-
*
|
2537
|
-
* ```ts
|
2538
|
-
* import { create } from '../index';
|
2539
|
-
*
|
2540
|
-
* const baseState = { foo: { bar: 'str' }, arr: [] };
|
2541
|
-
* const state = create(
|
2542
|
-
* baseState,
|
2543
|
-
* (draft) => {
|
2544
|
-
* draft.foo.bar = 'str2';
|
2545
|
-
* },
|
2546
|
-
* );
|
2547
|
-
*
|
2548
|
-
* expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
|
2549
|
-
* expect(state).not.toBe(baseState);
|
2550
|
-
* expect(state.foo).not.toBe(baseState.foo);
|
2551
|
-
* expect(state.arr).toBe(baseState.arr);
|
2552
|
-
* ```
|
2553
|
-
*/
|
2554
|
-
var create = makeCreator();
|
2555
|
-
Object.prototype.constructor.toString();
|
2556
|
-
|
2557
|
-
function produceState(state, fn) {
|
2558
|
-
state.set(create(state.get(), fn));
|
2559
|
-
}
|
2560
|
-
|
2561
|
-
var RumiousState = /*#__PURE__*/function () {
|
2562
|
-
function RumiousState(target) {
|
2563
|
-
var reactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
2564
|
-
_classCallCheck(this, RumiousState);
|
2565
|
-
this.value = target;
|
2566
|
-
this.reactor = reactor !== null && reactor !== undefined ? reactor : new RumiousReactor(this, []);
|
2567
|
-
}
|
2568
|
-
return _createClass(RumiousState, [{
|
2569
|
-
key: "produce",
|
2570
|
-
value: function produce(recipe) {
|
2571
|
-
return produceState(this, recipe);
|
2572
|
-
}
|
2573
|
-
}, {
|
2574
|
-
key: "reducer",
|
2575
|
-
value: function reducer() {
|
2576
|
-
var computedObj;
|
2577
|
-
if (arguments.length === 1) {
|
2578
|
-
computedObj = new RumiousReducer(this, "", arguments.length <= 0 ? undefined : arguments[0]);
|
2579
|
-
} else {
|
2580
|
-
computedObj = new RumiousReducer(this, arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1]);
|
2581
|
-
}
|
2582
|
-
return computedObj.trigger.bind(computedObj);
|
2583
|
-
}
|
2584
|
-
}, {
|
2585
|
-
key: "setObjectByPath",
|
2586
|
-
value: function setObjectByPath() {
|
2587
|
-
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
2588
|
-
var value = arguments.length > 1 ? arguments[1] : undefined;
|
2589
|
-
if (path.length == 0) {
|
2590
|
-
this.value = value;
|
2591
|
-
return;
|
2592
|
-
}
|
2593
|
-
if (typeof path !== 'string' || !path) {
|
2594
|
-
throw new Error('Invalid path');
|
2595
|
-
}
|
2596
|
-
var keys = path.split('.');
|
2597
|
-
var obj = this.value;
|
2598
|
-
for (var i = 0; i < keys.length - 1; i++) {
|
2599
|
-
var key = keys[i];
|
2600
|
-
if (!(key in obj)) {
|
2601
|
-
obj[key] = {};
|
2602
|
-
}
|
2603
|
-
obj = obj[key];
|
2604
|
-
}
|
2605
|
-
obj[keys[keys.length - 1]] = value;
|
2606
|
-
}
|
2607
|
-
}, {
|
2608
|
-
key: "set",
|
2609
|
-
value: function set() {
|
2610
|
-
if (arguments.length === 1) {
|
2611
|
-
this.value = arguments.length <= 0 ? undefined : arguments[0];
|
2612
|
-
} else {
|
2613
|
-
var path = arguments.length <= 0 ? undefined : arguments[0];
|
2614
|
-
var value = arguments.length <= 1 ? undefined : arguments[1];
|
2615
|
-
this.setObjectByPath(path, value);
|
2616
|
-
}
|
2617
|
-
this.reactor.react();
|
2618
|
-
}
|
2619
|
-
}, {
|
2620
|
-
key: "get",
|
2621
|
-
value: function get() {
|
2622
|
-
return this.value;
|
2623
|
-
}
|
2624
|
-
}]);
|
2625
|
-
}();
|
2626
|
-
function createState(value) {
|
2627
|
-
return new RumiousState(value);
|
2628
|
-
}
|
2629
|
-
function isState(obj) {
|
2630
|
-
return obj instanceof RumiousState;
|
2631
|
-
}
|
2632
|
-
|
2633
|
-
function watcher(state, callback) {
|
2634
|
-
state.reactor.addBinding(callback);
|
2635
|
-
}
|
2636
|
-
|
2637
|
-
export { RumiousApp, RumiousComponent, RumiousComponentElement, RumiousState, createComponentElement, createState, isComponent, isState, watcher };
|
1
|
+
class e{constructor(e){this.target=e}find(e){return this.target[e]}get(e){return this.target[e]}}class t{constructor(){this.element=null,this.props={},this.renderContext=new e(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n}template(){return{}}requestRender(){let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}onRender(){}onUpdate(){}onDestroy(){}}function n(e){return Object.getPrototypeOf(e)===t}class r{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class o{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function i(e){return"function"==typeof e}class s{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){console.warn("Directive haven't handler !")}}class a extends s{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return console.warn(`Missing event handler for event: ${this.name}`),null;const n=t.get(e);if(!i(n))throw`${e} is not a function!`;return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!i(n))throw"Event handler requires a function!"}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class l extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive bind: require a RumiousState Object !";t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw"Invalid props value: Directive bind: require a RumiousState Object !";r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){if("html"===this.name)e.innerHTML=this.normalizeValue(t)}}class c extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive ref: require a RumiousRef Object !";t.set(e)}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target);if(!n)throw"Invalid props value: Directive ref: require a RumiousRef Object !";n.set(e)}}}class u extends s{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive childsRef: require a RumiousChildRef Object !";t.set(e)}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target);if(!n)throw"Invalid props value: Directive childsRef: require a RumiousChildRef Object !";n.set(e)}}}const p={on:(e,t)=>new a("on",e,t),bind:(e,t)=>new l("bind",e,t),ref:(e,t,n="element")=>new c("ref",e,t),childsRef:(e,t)=>new u("childsRef",e,t)};function f(...e){return new r("FRAGMENT",{},h(e))}function h(e){return e.map((e=>"object"==typeof e?e:new r("TEXT_ELEMENT",{nodeValue:e},[])))}window.RUMIOUS_JSX_SUPPORT={createElement:function(e,t,...i){return n(e)?function(e,t,n){return new r("COMPONENT",{component:e,...t},new o(h(n)))}(e,t,i):e===f?f(...i):new r(e,t||{},h(i))},createFragment:f,createDirective:function(e,t,n){return function(e,t,n){return p[e]?.(t,n)}(e,t,n)}};class d extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}setRef(e){this.ref=e}init(e,t,n={},r){this.instance=new e,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){this.instance.onCreate(),this.instance.requestRender(),this.instance.forwardRef=this.ref??{}}disconnectCallback(){this.instance.onDestroy(),this.instance.requestCleanUp()}}function y(){return document.createElement("a-component")}function g(e,t,n,r){const o=function(e,t,n,r){const o=y();return o.init(e,t,n,r),o}(e.props.component,e.props,e.children,n);return Object.entries(e.props||{}).forEach((([e,t])=>{t instanceof s&&b(o,t,r)})),t.appendChild(o),t}function v(e,t){const n=document.createElement(e.type);return Object.entries(e.props||{}).forEach((([e,r])=>{e.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(e)?n.addEventListener(e.substring(2).toLowerCase(),r):function(e,t,n,r){e.nodeType===Node.TEXT_NODE?e.nodeValue=n:n instanceof s?b(e,n,r):e.setAttribute(t,n)}(n,e,r,t)})),n}function b(e,t,n){t.init(e,n)}function m(e,t,n={}){if(!e)return t;let r;return"COMPONENT"===e.type?g(e,t,m,n):"FRAGMENT"===e.type||"ELEMENT_LIST"===e.type?function(e,t,n){return e.children.forEach((e=>m(e,t,n))),t}(e,t,n):(r="TEXT_ELEMENT"===e.type?function(e){return document.createTextNode(e.props.nodeValue)}(e):v(e,n),e.children.forEach((e=>m(e,r,n))),t.appendChild(r),t)}window.customElements.define("a-component",d);class w{constructor(t=document.createElement("span"),n={}){this.root=t,this.configs=n,this.renderContext=new e(this)}render(e){m(e,this.root,this.renderContext)}}class O{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(){this.bindings.forEach((e=>e()))}addBinding(e){this.bindings.push(e)}}class M{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const E="remove",j="replace",k="add",S=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),R=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),P=Symbol.iterator,A={mutable:"mutable",immutable:"immutable"},x={};function z(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function D(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function C(e){return Object.getPrototypeOf(e)===Set.prototype}function T(e){return Object.getPrototypeOf(e)===Map.prototype}function _(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function I(e){return!!N(e)}function N(e){return"object"!=typeof e?null:null==e?void 0:e[S]}function F(e){var t;const n=N(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function V(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,A))===A.immutable||"function"==typeof n)}function L(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=N($(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const o=3===e.parent.type,i=o?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(o&&n.size>i||z(n,i)))return null;t.push(i)}if(e.parent)return L(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=$(3===q(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function q(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function $(e,t){return 2===q(e)?e.get(t):e[t]}function U(e,t,n){2===q(e)?e.set(t,n):e[t]=n}function W(e,t){const n=N(e);return(n?_(n):e)[t]}function B(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function K(e){if(e)for(;e.finalities.revoke.length>0;){e.finalities.revoke.pop()()}}function X(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const H=Object.prototype.propertyIsEnumerable;function Y(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!C(e)){return new(0,Object.getPrototypeOf(e).constructor)(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}if(e instanceof Map){if(!T(e)){return new(0,Object.getPrototypeOf(e).constructor)(e)}return new Map(e)}if((null==t?void 0:t.mark)&&(n=t.mark(e,A),void 0!==n)&&n!==A.mutable){if(n===A.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{H.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function G(e){e.copy||(e.copy=Y(e.original,e.options))}function Z(e){if(!V(e))return F(e);if(Array.isArray(e))return e.map(Z);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,Z(t)]));if(!T(e)){return new(0,Object.getPrototypeOf(e).constructor)(t)}return new Map(t)}if(e instanceof Set){const t=Array.from(e).map(Z);if(!C(e)){return new(0,Object.getPrototypeOf(e).constructor)(t)}return new Set(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=Z(e[n]);return t}function J(e){return I(e)?Z(e):e}function Q(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&Q(e.parent))}function ee(){throw new Error("Cannot modify frozen object")}function te(e,t,n,r,o){{n=null!=n?n:new WeakMap,r=null!=r?r:[],o=null!=o?o:[];const i=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(i);if(i&&"object"==typeof i&&-1!==e){if(r[0]===i)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${o.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(i),o.push(t)}else r.push(i)}if(Object.isFrozen(e)||I(e))return r.pop(),void o.pop();switch(q(e)){case 2:for(const[t,i]of e)te(t,t,n,r,o),te(i,t,n,r,o);e.set=e.clear=e.delete=ee;break;case 3:for(const t of e)te(t,t,n,r,o);e.add=e.clear=e.delete=ee;break;case 1:Object.freeze(e);let t=0;for(const i of e)te(i,t,n,r,o),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{te(e[t],t,n,r,o)}))}r.pop(),o.pop()}function ne(e,t){const n=q(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function re(e,t,n){if(I(e)||!V(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,o=r?new Map:void 0;if(t.add(e),ne(e,((i,s)=>{var a;if(I(s)){const t=N(s);G(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;U(r?o:e,i,n)}else re(s,t,n)})),o){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(o.has(e)?o.get(e):e)}))}}function oe(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&re($(n,t),e.finalities.handledSet,e.options)}function ie(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(F(t))})))}function se(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const o=L(e);o&&t(e,o,n,r)}e.finalized=!0}}function ae(e,t,n,r){const o=N(n);o&&(o.callbacks||(o.callbacks=[]),o.callbacks.push(((i,s)=>{var a;const l=3===e.type?e.setMap:e.copy;if(B($(l,t),n)){let n=o.original;o.copy&&(n=o.copy),ie(e),se(e,r,i,s),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,o.original)),U(l,t,n)}})),e.options.enableAutoFreeze&&o.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),V(n,e.options)&&e.finalities.draft.push((()=>{B($(3===e.type?e.setMap:e.copy,t),n)&&oe(e,t)}))}function le(e,t,n,r){const{pathAsArray:o=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,o,i,s){n.forEach(((n,a)=>{const l=$(e,a),c=J($(t,a)),u=n?z(e,a)?j:k:E;if(B(l,c)&&u===j)return;const p=X(r.concat(a),s);o.push(u===E?{op:u,path:p}:{op:u,path:p,value:c}),i.push(u===k?{op:E,path:p}:u===E?{op:k,path:p,value:l}:{op:j,path:p,value:l})}))}(e,t,n,r,o);case 1:return function(e,t,n,r,o){let{original:i,assignedMap:s,options:a}=e,l=e.copy;l.length<i.length&&([i,l]=[l,i],[n,r]=[r,n]);for(let e=0;e<i.length;e+=1)if(s.get(e.toString())&&l[e]!==i[e]){const s=X(t.concat([e]),o);n.push({op:j,path:s,value:J(l[e])}),r.push({op:j,path:s,value:J(i[e])})}for(let e=i.length;e<l.length;e+=1){const r=X(t.concat([e]),o);n.push({op:k,path:r,value:J(l[e])})}if(i.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=X(t.concat(["length"]),o);r.push({op:j,path:e,value:i.length})}else for(let e=l.length;i.length<e;e-=1){const n=X(t.concat([e-1]),o);r.push({op:E,path:n})}}}(e,t,n,r,o);case 3:return function({original:e,copy:t},n,r,o,i){let s=0;e.forEach((e=>{if(!t.has(e)){const t=X(n.concat([s]),i);r.push({op:E,path:t,value:e}),o.unshift({op:k,path:t,value:e})}s+=1})),s=0,t.forEach((t=>{if(!e.has(t)){const e=X(n.concat([s]),i);r.push({op:k,path:e,value:t}),o.unshift({op:E,path:e,value:t})}s+=1}))}(e,t,n,r,o)}}const ce=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!V(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},ue={get size(){return _(N(this)).size},has(e){return _(N(this)).has(e)},set(e,t){const n=N(this),r=_(n);return r.has(e)&&B(r.get(e),t)||(G(n),Q(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ae(n,e,t,le)),this},delete(e){if(!this.has(e))return!1;const t=N(this);return G(t),Q(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=N(this);if(this.size){G(e),Q(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){_(N(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=N(this),o=_(r).get(e),i=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,o,A))===A.mutable;if(r.options.strict&&ce(o,r.options,i),i)return o;if(r.finalized||!V(o,r.options))return o;if(o!==r.original.get(e))return o;const s=x.createDraft({original:o,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return G(r),r.copy.set(e,s),s},keys(){return _(N(this)).keys()},values(){const e=this.keys();return{[P]:()=>this.values(),next:()=>{const t=e.next();if(t.done)return t;return{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[P]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[P](){return this.entries()}},pe=Reflect.ownKeys(ue),fe=(e,t,{isValuesIterator:n})=>()=>{var r,o;const i=t.next();if(i.done)return i;const s=i.value;let a=e.setMap.get(s);const l=N(a),c=(null===(o=(r=e.options).mark)||void 0===o?void 0:o.call(r,a,A))===A.mutable;if(e.options.strict&&ce(s,e.options,c),c||l||!V(s,e.options)||e.finalized||!e.original.has(s))l&&(a=l.proxy);else{const t=x.createDraft({original:s,parentDraft:e,key:s,finalities:e.finalities,options:e.options});e.setMap.set(s,t),a=t}return{done:!1,value:n?a:[a,a]}},he={get size(){return N(this).setMap.size},has(e){const t=N(this);if(t.setMap.has(e))return!0;G(t);const n=N(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=N(this);return this.has(e)||(G(t),Q(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ae(t,e,e,le)),this},delete(e){if(!this.has(e))return!1;const t=N(this);G(t),Q(t);const n=N(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=N(this);G(e),Q(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=N(this);G(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:fe(e,t,{isValuesIterator:!0})}},entries(){const e=N(this);G(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:fe(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[P](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(he,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const de=Reflect.ownKeys(he),ye=new WeakSet,ge={get(e,t,n){var r,o;const i=null===(r=e.copy)||void 0===r?void 0:r[t];if(i&&ye.has(i))return i;if(t===S)return e;let s;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(s=e.options.mark(r,A),s===A.mutable)return e.options.strict&&ce(r,e.options,!0),r}const a=_(e);if(a instanceof Map&&pe.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ue,"size").get.call(e.proxy);const n=ue[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&de.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(he,"size").get.call(e.proxy);const n=he[t];if(n)return n.bind(e.proxy)}if(!z(a,t)){const n=D(a,t);return n?"value"in n?n.value:null===(o=n.get)||void 0===o?void 0:o.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&ce(l,e.options),e.finalized||!V(l,e.options))return l;if(l===W(e.original,t)){if(G(e),e.copy[t]=ve({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof s){const n=N(e.copy[t]);return G(n),Q(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let o;if(1===e.type&&"length"!==t&&(!(Number.isInteger(o=Number(t))&&o>=0)||0!==t&&0!==o&&String(o)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const i=D(_(e),t);if(null==i?void 0:i.set)return i.set.call(e.proxy,n),!0;const s=W(_(e),t),a=N(s);return a&&B(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(B(n,s)&&(void 0!==n||z(e.original,t))||(G(e),Q(e),z(e.original,t)&&B(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ae(e,t,n,le)),!0)},has:(e,t)=>t in _(e),ownKeys:e=>Reflect.ownKeys(_(e)),getOwnPropertyDescriptor(e,t){const n=_(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?ge.set.call(this,e,t,void 0,e.proxy):(void 0!==W(e.original,t)||t in e.original?(G(e),Q(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function ve(e){const{original:t,parentDraft:n,key:r,finalities:o,options:i}=e,s=q(t),a={type:s,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:o,options:i,setMap:3===s?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===s?Object.assign([],a):a,ge);if(o.revoke.push(c),ye.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var o,i;const s=N(l);let a=3===e.type?e.setMap:e.copy;const c=$(a,r),u=N(c);if(u){let i=u.original;u.operated&&(i=F(c)),ie(u),se(u,le,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(o=e.options.updatedValues)&&void 0!==o?o:new WeakMap,e.options.updatedValues.set(i,u.original)),U(a,r,i)}null===(i=s.callbacks)||void 0===i||i.forEach((e=>{e(t,n)}))}))}else{const e=N(l);e.finalities.draft.push(((t,n)=>{ie(e),se(e,le,t,n)}))}return l}function be(e,t,n,r,o){var i;const s=N(e),a=null!==(i=null==s?void 0:s.original)&&void 0!==i?i:e,l=!!t.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;){s.finalities.draft.pop()(n,r)}const c=l?t[0]:s?s.operated?s.copy:s.original:e;return s&&K(s),o&&te(c,c,null==s?void 0:s.options.updatedValues),[c,n&&l?[{op:j,path:[],value:t[0]}]:n,r&&l?[{op:j,path:[],value:a}]:r]}function me(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:o=!0}=e;ne(n,((n,r,o)=>{const i=N(r);if(i&&t&&i.finalities===t.finalities){e.isContainDraft=!0;const t=i.original;if(o instanceof Set){const e=Array.from(o);o.clear(),e.forEach((e=>o.add(n===e?t:e)))}else U(o,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,me(e))})),o&&(e.isContainDraft||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function we(e){var t;const n=N(e);if(!V(e,null==n?void 0:n.options))return e;const r=q(e);if(n&&!n.operated)return n.original;let o;function i(){o=2===r?T(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):Y(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{i()}finally{n.finalized=!1}}else o=e;if(ne(o,((t,r)=>{if(n&&B($(n.original,t),r))return;const s=we(r);s!==r&&(o===e&&i(),U(o,t,s))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:o;return C(e)?new Set(o):new(Object.getPrototypeOf(e).constructor)(o)}return o}function Oe(e){if(!I(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return we(e)}x.createDraft=ve;const Me=function e(t,n,r){var o,i,s;if("function"==typeof t&&"function"!=typeof n)return function(r,...o){return e(r,(e=>t.call(this,e,...o)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},Ee),c);const u=I(a)?Oe(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,f=null!==(o=c.enablePatches)&&void 0!==o&&o,h=null!==(i=c.strict)&&void 0!==i&&i,d={enableAutoFreeze:null!==(s=c.enableAutoFreeze)&&void 0!==s&&s,mark:p,strict:h,enablePatches:f};if(!V(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,g]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let o,i;t.enablePatches&&(o=[],i=[]);const s=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,A))!==A.mutable&&V(e,t)?ve({original:e,parentDraft:null,finalities:r,options:t}):e;return[s,(e=[])=>{const[n,r,a]=be(s,e,o,i,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!V(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,g]}let v;try{v=l(y)}catch(e){throw K(N(y)),e}const b=e=>{const t=N(y);if(!I(e)){if(void 0!==e&&!B(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[R];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&me({rootDraft:t,value:e,useRawReturn:!0}),g([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&me({rootDraft:t,value:e}),g([e])}if(e===y||void 0===e)return g([]);const n=N(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return g([Oe(e)])}return g([e])};return v instanceof Promise?v.then(b,(e=>{throw K(N(y)),e})):b(v)};var Ee;Object.prototype.constructor.toString();class je{constructor(e,t=null){this.value=e,this.reactor=t??new O(this,[])}produce(e){return n=e,void(t=this).set(Me(t.get(),n));var t,n}reducer(...e){let t;return t=1===e.length?new M(this,"",e[0]):new M(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0==e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0];else{let t=e[0],n=e[1];this.setObjectByPath(t,n)}this.reactor.react()}get(){return this.value}}function ke(e){return new je(e)}function Se(e){return e instanceof je}function Re(e,t){e.reactor.addBinding(t)}class Pe{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function Ae(e){return new Pe(e)}class xe{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}function ze(e){return new xe(e)}class De{constructor(e){this.target=e}set(e){this.target=e,e.setRef(this)}}function Ce(e){return new De(e)}export{w as RumiousApp,xe as RumiousChildrensRef,t as RumiousComponent,d as RumiousComponentElement,De as RumiousComponentRef,Pe as RumiousElementRef,je as RumiousState,ze as createChildrensRef,y as createComponentElement,Ce as createComponentRef,Ae as createElementRef,ke as createState,n as isComponent,Se as isState,Re as watcher};
|
2638
2
|
//# sourceMappingURL=index.esm.js.map
|