@mintjamsinc/ichigojs 0.1.83 → 0.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ichigo.cjs +112 -1
- package/dist/ichigo.cjs.map +1 -1
- package/dist/ichigo.esm.js +112 -1
- 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 +112 -1
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/ichigo.esm.js
CHANGED
|
@@ -11313,6 +11313,25 @@ class VForDirective {
|
|
|
11313
11313
|
* Previous iterations to detect changes
|
|
11314
11314
|
*/
|
|
11315
11315
|
#previousIterations = [];
|
|
11316
|
+
/**
|
|
11317
|
+
* The source array watched for writes made directly to it, and the function
|
|
11318
|
+
* that stops watching it.
|
|
11319
|
+
*
|
|
11320
|
+
* A write such as `items[1] = x` is reported as a change of "items[1]", which
|
|
11321
|
+
* does not match this directive's dependency on "items", and the row's loop
|
|
11322
|
+
* variable holds the value it was rendered with. The directive therefore
|
|
11323
|
+
* watches the array itself and refreshes the rows that were written.
|
|
11324
|
+
*/
|
|
11325
|
+
#watchedSource;
|
|
11326
|
+
#unwatchSource;
|
|
11327
|
+
/**
|
|
11328
|
+
* Positions written since the last refresh, and whether a write (such as one
|
|
11329
|
+
* to `length`) needs the whole list rendered again.
|
|
11330
|
+
*/
|
|
11331
|
+
#writtenIndexes = new Set();
|
|
11332
|
+
#writtenWhole = false;
|
|
11333
|
+
#refreshScheduled = false;
|
|
11334
|
+
#destroyed = false;
|
|
11316
11335
|
/**
|
|
11317
11336
|
* @param context The context for parsing the directive.
|
|
11318
11337
|
*/
|
|
@@ -11429,6 +11448,10 @@ class VForDirective {
|
|
|
11429
11448
|
* @inheritdoc
|
|
11430
11449
|
*/
|
|
11431
11450
|
destroy() {
|
|
11451
|
+
this.#destroyed = true;
|
|
11452
|
+
this.#unwatchSource?.();
|
|
11453
|
+
this.#unwatchSource = undefined;
|
|
11454
|
+
this.#watchedSource = undefined;
|
|
11432
11455
|
// Clean up all rendered items
|
|
11433
11456
|
// First destroy all VNodes (calls @unmount hooks), then remove from DOM
|
|
11434
11457
|
for (const { vNode } of this.#renderedItems) {
|
|
@@ -11460,6 +11483,10 @@ class VForDirective {
|
|
|
11460
11483
|
}
|
|
11461
11484
|
// Evaluate the source expression to get the data
|
|
11462
11485
|
const sourceData = this.#sourceEvaluator.evaluate();
|
|
11486
|
+
// Every row is rendered from the source below, including those written in place
|
|
11487
|
+
this.#watchSource(sourceData);
|
|
11488
|
+
this.#writtenIndexes.clear();
|
|
11489
|
+
this.#writtenWhole = false;
|
|
11463
11490
|
// Get iterations from the source data
|
|
11464
11491
|
let iterations = this.#getIterations(sourceData);
|
|
11465
11492
|
// If we don't have a key evaluator yet, try to create it
|
|
@@ -11853,6 +11880,89 @@ class VForDirective {
|
|
|
11853
11880
|
}
|
|
11854
11881
|
vNode.update();
|
|
11855
11882
|
}
|
|
11883
|
+
/**
|
|
11884
|
+
* Watches the source for writes made directly to its elements. Only a
|
|
11885
|
+
* reactive array can be written that way; anything else is not watched.
|
|
11886
|
+
*/
|
|
11887
|
+
#watchSource(source) {
|
|
11888
|
+
if (source === this.#watchedSource) {
|
|
11889
|
+
return;
|
|
11890
|
+
}
|
|
11891
|
+
this.#unwatchSource?.();
|
|
11892
|
+
this.#unwatchSource = undefined;
|
|
11893
|
+
this.#watchedSource = source;
|
|
11894
|
+
const path = Array.isArray(source) ? ReactiveProxy.getPath(source) : undefined;
|
|
11895
|
+
if (!path) {
|
|
11896
|
+
return;
|
|
11897
|
+
}
|
|
11898
|
+
this.#unwatchSource = ReactiveProxy.subscribe(source, (changedPath) => {
|
|
11899
|
+
this.#onSourceWritten(path, changedPath);
|
|
11900
|
+
});
|
|
11901
|
+
}
|
|
11902
|
+
/**
|
|
11903
|
+
* Notes a write made directly to the source array. A change below an
|
|
11904
|
+
* element (e.g. "items[1].name") is followed by the row's own bindings, and
|
|
11905
|
+
* a change of the whole array (e.g. by splice) by the usual dependency on it.
|
|
11906
|
+
*/
|
|
11907
|
+
#onSourceWritten(path, changedPath) {
|
|
11908
|
+
if (!changedPath || !changedPath.startsWith(path + '[') || !changedPath.endsWith(']')) {
|
|
11909
|
+
return;
|
|
11910
|
+
}
|
|
11911
|
+
const property = changedPath.substring(path.length + 1, changedPath.length - 1);
|
|
11912
|
+
if (property.includes(']')) {
|
|
11913
|
+
return;
|
|
11914
|
+
}
|
|
11915
|
+
if (/^\d+$/.test(property)) {
|
|
11916
|
+
this.#writtenIndexes.add(Number(property));
|
|
11917
|
+
}
|
|
11918
|
+
else {
|
|
11919
|
+
// e.g. `items.length = 0`
|
|
11920
|
+
this.#writtenWhole = true;
|
|
11921
|
+
}
|
|
11922
|
+
// Writes made together are refreshed together, after the application's update
|
|
11923
|
+
if (!this.#refreshScheduled) {
|
|
11924
|
+
this.#refreshScheduled = true;
|
|
11925
|
+
queueMicrotask(() => {
|
|
11926
|
+
this.#refreshScheduled = false;
|
|
11927
|
+
this.#refreshWritten();
|
|
11928
|
+
});
|
|
11929
|
+
}
|
|
11930
|
+
}
|
|
11931
|
+
/**
|
|
11932
|
+
* Shows the elements written since the last refresh. A row whose position or
|
|
11933
|
+
* key no longer holds is not patched; the whole list is rendered again.
|
|
11934
|
+
*/
|
|
11935
|
+
#refreshWritten() {
|
|
11936
|
+
if (this.#destroyed || (!this.#writtenWhole && this.#writtenIndexes.size === 0)) {
|
|
11937
|
+
return;
|
|
11938
|
+
}
|
|
11939
|
+
const indexes = [...this.#writtenIndexes];
|
|
11940
|
+
const whole = this.#writtenWhole;
|
|
11941
|
+
this.#writtenIndexes.clear();
|
|
11942
|
+
this.#writtenWhole = false;
|
|
11943
|
+
const source = this.#sourceEvaluator?.evaluate();
|
|
11944
|
+
if (whole || source !== this.#watchedSource || !Array.isArray(source) || source.length !== this.#renderedItems.length) {
|
|
11945
|
+
this.#render();
|
|
11946
|
+
return;
|
|
11947
|
+
}
|
|
11948
|
+
for (const index of indexes) {
|
|
11949
|
+
const rendered = this.#renderedItems[index];
|
|
11950
|
+
let context = { key: index, item: source[index], index };
|
|
11951
|
+
if (this.#evaluateKey && (this.#itemName || this.#itemDestructure)) {
|
|
11952
|
+
const itemBindings = new VBindings({
|
|
11953
|
+
parent: this.#vNode.bindings
|
|
11954
|
+
});
|
|
11955
|
+
this.#setItemBindings(itemBindings, context);
|
|
11956
|
+
context = { ...context, key: this.#evaluateKey(itemBindings) };
|
|
11957
|
+
}
|
|
11958
|
+
if (!rendered || context.key !== rendered.key) {
|
|
11959
|
+
this.#render();
|
|
11960
|
+
return;
|
|
11961
|
+
}
|
|
11962
|
+
this.#updateItemBindings(rendered.vNode, context);
|
|
11963
|
+
this.#previousIterations[index] = context;
|
|
11964
|
+
}
|
|
11965
|
+
}
|
|
11856
11966
|
/**
|
|
11857
11967
|
* Get iterations from various data types
|
|
11858
11968
|
* Supports: Arrays, Objects, Sets, Maps, Iterables, Numbers, Strings
|
|
@@ -11862,7 +11972,8 @@ class VForDirective {
|
|
|
11862
11972
|
return [];
|
|
11863
11973
|
// Array
|
|
11864
11974
|
if (Array.isArray(data)) {
|
|
11865
|
-
|
|
11975
|
+
// Array.from rather than map: a hole (e.g. after `items[5] = x` past the end) is a row of undefined
|
|
11976
|
+
return Array.from(data, (item, index) => ({
|
|
11866
11977
|
item,
|
|
11867
11978
|
index,
|
|
11868
11979
|
key: index
|