@mintjamsinc/ichigojs 0.1.72 → 0.1.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/ichigo.cjs +85 -16
- package/dist/ichigo.cjs.map +1 -1
- package/dist/ichigo.esm.js +85 -16
- package/dist/ichigo.esm.js.map +1 -1
- package/dist/ichigo.esm.min.js +1 -1
- package/dist/ichigo.min.cjs +1 -1
- package/dist/ichigo.umd.js +85 -16
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/dist/types/ichigo/VBindings.d.ts +11 -0
- package/dist/types/ichigo/util/ReactiveProxy.d.ts +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/ichigo.cjs
CHANGED
|
@@ -8023,6 +8023,41 @@
|
|
|
8023
8023
|
* This allows mapping variable names to their actual source paths for dependency tracking.
|
|
8024
8024
|
*/
|
|
8025
8025
|
static pathAliases = new Map();
|
|
8026
|
+
/**
|
|
8027
|
+
* The `Object.prototype.toString` tags of the *only* value types we deeply
|
|
8028
|
+
* proxy. Everything else is returned untouched (raw).
|
|
8029
|
+
*
|
|
8030
|
+
* Rationale: a Proxy can only safely intercept plain data containers. Built-in
|
|
8031
|
+
* and host objects — `Date`, `RegExp`, `File`, `Blob`, `FileList`, `Promise`,
|
|
8032
|
+
* `WeakMap`/`WeakSet`, typed arrays, DOM nodes, etc. — carry private internal
|
|
8033
|
+
* slots, and invoking their native methods with a Proxy as the `this`/receiver
|
|
8034
|
+
* throws "Illegal invocation". They must therefore never be wrapped. This is an
|
|
8035
|
+
* allow-list rather than a deny-list so that *every* such exotic type is
|
|
8036
|
+
* excluded by default, not just the handful we happened to enumerate.
|
|
8037
|
+
*
|
|
8038
|
+
* Plain user-defined class instances report `[object Object]` (unless they set
|
|
8039
|
+
* `Symbol.toStringTag`) and so remain reactive, preserving prior behaviour.
|
|
8040
|
+
* `Map`/`Set` stay reactive because the proxy specially wraps their mutation
|
|
8041
|
+
* methods (see the `get` trap); `WeakMap`/`WeakSet` are intentionally excluded
|
|
8042
|
+
* since they cannot be wrapped that way and would break the same as `File`.
|
|
8043
|
+
*
|
|
8044
|
+
* Callers that want a plain object kept non-reactive can still opt out
|
|
8045
|
+
* explicitly via {@link markRaw}.
|
|
8046
|
+
*/
|
|
8047
|
+
static REACTIVE_TYPE_TAGS = new Set([
|
|
8048
|
+
'[object Object]',
|
|
8049
|
+
'[object Array]',
|
|
8050
|
+
'[object Arguments]',
|
|
8051
|
+
'[object Map]',
|
|
8052
|
+
'[object Set]',
|
|
8053
|
+
]);
|
|
8054
|
+
/**
|
|
8055
|
+
* Whether the given non-null object value is one we deeply proxy.
|
|
8056
|
+
* See {@link REACTIVE_TYPE_TAGS} for the reasoning.
|
|
8057
|
+
*/
|
|
8058
|
+
static isReactivable(value) {
|
|
8059
|
+
return this.REACTIVE_TYPE_TAGS.has(Object.prototype.toString.call(value));
|
|
8060
|
+
}
|
|
8026
8061
|
/**
|
|
8027
8062
|
* Creates a reactive proxy for the given object.
|
|
8028
8063
|
* The proxy will call the onChange callback whenever a property is modified.
|
|
@@ -8042,11 +8077,10 @@
|
|
|
8042
8077
|
if (this.rawObjects.has(target)) {
|
|
8043
8078
|
return target;
|
|
8044
8079
|
}
|
|
8045
|
-
//
|
|
8046
|
-
//
|
|
8047
|
-
//
|
|
8048
|
-
|
|
8049
|
-
if (typeTag === '[object Date]' || typeTag === '[object RegExp]' || typeTag === '[object Error]') {
|
|
8080
|
+
// Only deeply proxy plain data containers; return every built-in/host
|
|
8081
|
+
// object (Date, File, Blob, Promise, WeakMap, DOM nodes, …) as-is, since
|
|
8082
|
+
// their native methods break when invoked through a Proxy receiver.
|
|
8083
|
+
if (!this.isReactivable(target)) {
|
|
8050
8084
|
return target;
|
|
8051
8085
|
}
|
|
8052
8086
|
// Check if the target is already a proxy - if so, return it as-is to prevent double-wrapping
|
|
@@ -8082,10 +8116,10 @@
|
|
|
8082
8116
|
if (ReactiveProxy.rawObjects.has(value)) {
|
|
8083
8117
|
return value;
|
|
8084
8118
|
}
|
|
8085
|
-
//
|
|
8086
|
-
//
|
|
8087
|
-
|
|
8088
|
-
if (
|
|
8119
|
+
// Only deeply proxy plain data containers; hand back built-in
|
|
8120
|
+
// and host objects (Date, File, Blob, Promise, WeakMap, DOM
|
|
8121
|
+
// nodes, …) untouched so their native methods keep working.
|
|
8122
|
+
if (!ReactiveProxy.isReactivable(value)) {
|
|
8089
8123
|
return value;
|
|
8090
8124
|
}
|
|
8091
8125
|
// Build the nested path
|
|
@@ -8406,6 +8440,13 @@
|
|
|
8406
8440
|
* Flag to suppress onChange callbacks temporarily.
|
|
8407
8441
|
*/
|
|
8408
8442
|
#suppressOnChange = false;
|
|
8443
|
+
/**
|
|
8444
|
+
* Flag forcing the next write through the `set` trap to stay in THIS scope's own
|
|
8445
|
+
* local store instead of walking up to an inherited binding of the same name.
|
|
8446
|
+
* Set only by {@link setLocal} for scope-local variables (e.g. v-for loop items),
|
|
8447
|
+
* which must shadow — never overwrite — a parent binding with the same key.
|
|
8448
|
+
*/
|
|
8449
|
+
#localWrite = false;
|
|
8409
8450
|
/**
|
|
8410
8451
|
* Per-instance path aliases. Maps local variable names to their reactive source paths.
|
|
8411
8452
|
* Scoped here instead of the global ReactiveProxy map so that v-for items each maintain
|
|
@@ -8484,8 +8525,13 @@
|
|
|
8484
8525
|
setter(value);
|
|
8485
8526
|
return true;
|
|
8486
8527
|
}
|
|
8528
|
+
// For a key that is not local to this scope, an assignment normally
|
|
8529
|
+
// retargets to the nearest parent that owns it, so reassignments
|
|
8530
|
+
// (e.g. `count = count + 1` in a handler) mutate the original binding.
|
|
8531
|
+
// A scope-local write (setLocal — used for v-for loop variables) skips
|
|
8532
|
+
// this walk so the variable shadows, never clobbers, an inherited key.
|
|
8487
8533
|
let target = obj;
|
|
8488
|
-
if (!Reflect.has(target, key)) {
|
|
8534
|
+
if (!this.#localWrite && !Reflect.has(target, key)) {
|
|
8489
8535
|
for (let parent = this.#parent; parent; parent = parent.#parent) {
|
|
8490
8536
|
if (Reflect.has(parent.#local, key)) {
|
|
8491
8537
|
target = parent.#local;
|
|
@@ -8660,6 +8706,25 @@
|
|
|
8660
8706
|
set(key, value) {
|
|
8661
8707
|
this.#local[key] = value;
|
|
8662
8708
|
}
|
|
8709
|
+
/**
|
|
8710
|
+
* Sets a binding value in THIS scope's own local store, without walking up to a
|
|
8711
|
+
* parent scope. Used for scope-local variables (e.g. v-for loop items) that must
|
|
8712
|
+
* shadow — never overwrite — an inherited binding of the same name. Contrast with
|
|
8713
|
+
* {@link set}, which retargets a write of an inherited key to the owning parent so
|
|
8714
|
+
* that reassignments mutate the original; a loop variable named like a root data /
|
|
8715
|
+
* method / computed key (e.g. `t`) would otherwise clobber it.
|
|
8716
|
+
* @param key The binding name.
|
|
8717
|
+
* @param value The binding value.
|
|
8718
|
+
*/
|
|
8719
|
+
setLocal(key, value) {
|
|
8720
|
+
this.#localWrite = true;
|
|
8721
|
+
try {
|
|
8722
|
+
this.#local[key] = value;
|
|
8723
|
+
}
|
|
8724
|
+
finally {
|
|
8725
|
+
this.#localWrite = false;
|
|
8726
|
+
}
|
|
8727
|
+
}
|
|
8663
8728
|
/**
|
|
8664
8729
|
* Gets a binding value.
|
|
8665
8730
|
* @param key The binding name.
|
|
@@ -10755,26 +10820,30 @@
|
|
|
10755
10820
|
* Sets item bindings for a VNode, handling nested destructuring if needed.
|
|
10756
10821
|
*/
|
|
10757
10822
|
#setItemBindings(bindings, context) {
|
|
10823
|
+
// Loop variables are scope-local: they must shadow, never overwrite, an
|
|
10824
|
+
// inherited binding of the same name (a data / method / computed key on a
|
|
10825
|
+
// parent scope). setLocal writes to this iteration's own store so a loop
|
|
10826
|
+
// variable named like e.g. the i18n helper `t` cannot clobber it.
|
|
10758
10827
|
if (this.#itemDestructure && Array.isArray(context.item)) {
|
|
10759
10828
|
// Nested destructuring: spread array items to individual bindings
|
|
10760
10829
|
// e.g., item = ['alice', 1] with itemDestructure = ['k', 'v']
|
|
10761
|
-
// bindings.
|
|
10762
|
-
// bindings.
|
|
10830
|
+
// bindings.setLocal('k', 'alice')
|
|
10831
|
+
// bindings.setLocal('v', 1)
|
|
10763
10832
|
this.#itemDestructure.forEach((name, i) => {
|
|
10764
|
-
bindings.
|
|
10833
|
+
bindings.setLocal(name, context.item[i]);
|
|
10765
10834
|
});
|
|
10766
10835
|
}
|
|
10767
10836
|
else if (this.#itemName) {
|
|
10768
10837
|
// Simple item binding
|
|
10769
|
-
bindings.
|
|
10838
|
+
bindings.setLocal(this.#itemName, context.item);
|
|
10770
10839
|
}
|
|
10771
10840
|
if (this.#indexName) {
|
|
10772
10841
|
// For objects, use objectKey if available; otherwise use numeric index
|
|
10773
|
-
bindings.
|
|
10842
|
+
bindings.setLocal(this.#indexName, context.objectKey ?? context.index);
|
|
10774
10843
|
}
|
|
10775
10844
|
if (this.#thirdName) {
|
|
10776
10845
|
// Third argument is always the numeric index
|
|
10777
|
-
bindings.
|
|
10846
|
+
bindings.setLocal(this.#thirdName, context.index);
|
|
10778
10847
|
}
|
|
10779
10848
|
}
|
|
10780
10849
|
/**
|