targetj 1.0.251 → 1.0.253
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 +2 -2
- package/build/$Dom.js +50 -17
- package/build/Bracket.js +4 -4
- package/build/BracketGenerator.js +3 -3
- package/build/LoadingManager.js +1 -1
- package/build/TModelManager.js +72 -66
- package/build/TargetUtil.js +1 -1
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ npm install targetj
|
|
|
56
56
|
|
|
57
57
|
**2. Example**
|
|
58
58
|
|
|
59
|
-
This creates the following sequence:
|
|
59
|
+
This creates the following sequence: bounce → move → turn red → log. Notice how the code read like the UI sequence. The `$$` suffix makes each step wait for the preceding ones. There is only one state. The transitions are part of that state.
|
|
60
60
|
|
|
61
61
|
```javascript
|
|
62
62
|
import { App } from "targetj";
|
|
@@ -66,7 +66,7 @@ App({
|
|
|
66
66
|
height: 100,
|
|
67
67
|
backgroundColor: "blue",
|
|
68
68
|
|
|
69
|
-
// Starts immediately: bounce
|
|
69
|
+
// Starts immediately: bounce.
|
|
70
70
|
scale: { value: [0.5, 1.2, 1], steps: 24, interval: 12 },
|
|
71
71
|
|
|
72
72
|
// Waits for scale to finish, then moves right.
|
package/build/$Dom.js
CHANGED
|
@@ -30,6 +30,7 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
30
30
|
this.textOnly = true;
|
|
31
31
|
this.transformProp = null;
|
|
32
32
|
this.initTransformProp();
|
|
33
|
+
this.restoreSlotState();
|
|
33
34
|
}
|
|
34
35
|
return _createClass($Dom, [{
|
|
35
36
|
key: "create",
|
|
@@ -67,7 +68,8 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
67
68
|
}, {
|
|
68
69
|
key: "exists",
|
|
69
70
|
value: function exists() {
|
|
70
|
-
|
|
71
|
+
var _this$element;
|
|
72
|
+
return !!((_this$element = this.element) !== null && _this$element !== void 0 && _this$element.isConnected);
|
|
71
73
|
}
|
|
72
74
|
}, {
|
|
73
75
|
key: "getElement",
|
|
@@ -79,6 +81,23 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
79
81
|
value: function supportsWAAPI() {
|
|
80
82
|
return !!(this.element && typeof this.element.animate === 'function');
|
|
81
83
|
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "restoreSlotState",
|
|
86
|
+
value: function restoreSlotState() {
|
|
87
|
+
var _this$element2;
|
|
88
|
+
if (((_this$element2 = this.element) === null || _this$element2 === void 0 ? void 0 : _this$element2.nodeType) !== 1 || this.isNoSlotHost()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
var slot = this.element.querySelector(':scope > [data-tj-slot="content"]');
|
|
92
|
+
if (!slot) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.contentSlot = slot;
|
|
96
|
+
this.slotModeEnabled = true;
|
|
97
|
+
this.hasRealChildren = Array.from(this.element.childNodes).some(function (child) {
|
|
98
|
+
return child !== slot && child.getAttribute("tgjs") === "true";
|
|
99
|
+
});
|
|
100
|
+
}
|
|
82
101
|
}, {
|
|
83
102
|
key: "findContentSlot",
|
|
84
103
|
value: function findContentSlot() {
|
|
@@ -97,8 +116,8 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
97
116
|
}, {
|
|
98
117
|
key: "isNoSlotHost",
|
|
99
118
|
value: function isNoSlotHost() {
|
|
100
|
-
var _this$
|
|
101
|
-
return
|
|
119
|
+
var _this$element3;
|
|
120
|
+
return ((_this$element3 = this.element) === null || _this$element3 === void 0 ? void 0 : _this$element3.nodeType) !== 1 || this.getTagName() === "body" || this.element.getAttribute("data-tj-no-slot") === "true";
|
|
102
121
|
}
|
|
103
122
|
}, {
|
|
104
123
|
key: "ensureContentSlotFirst",
|
|
@@ -117,7 +136,7 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
117
136
|
}, {
|
|
118
137
|
key: "enableSlotMode",
|
|
119
138
|
value: function enableSlotMode() {
|
|
120
|
-
var _this$
|
|
139
|
+
var _this$element4;
|
|
121
140
|
if (this.slotModeEnabled) {
|
|
122
141
|
return;
|
|
123
142
|
}
|
|
@@ -125,17 +144,31 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
125
144
|
this.slotModeEnabled = true;
|
|
126
145
|
return;
|
|
127
146
|
}
|
|
128
|
-
|
|
147
|
+
var existingSlot = this.findContentSlot();
|
|
148
|
+
if (existingSlot) {
|
|
149
|
+
if (this.element.firstChild !== existingSlot) {
|
|
150
|
+
this.element.insertBefore(existingSlot, this.element.firstChild);
|
|
151
|
+
}
|
|
152
|
+
this.contentSlot = existingSlot;
|
|
129
153
|
this.slotModeEnabled = true;
|
|
154
|
+
this.hasRealChildren = Array.from(this.element.childNodes).some(function (node) {
|
|
155
|
+
return node !== existingSlot;
|
|
156
|
+
});
|
|
130
157
|
return;
|
|
131
158
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var next = n.nextSibling;
|
|
136
|
-
slot.appendChild(n);
|
|
137
|
-
n = next;
|
|
159
|
+
if (!((_this$element4 = this.element) !== null && _this$element4 !== void 0 && _this$element4.firstChild)) {
|
|
160
|
+
this.slotModeEnabled = true;
|
|
161
|
+
return;
|
|
138
162
|
}
|
|
163
|
+
var existingNodes = Array.from(this.element.childNodes);
|
|
164
|
+
var slot = document.createElement("div");
|
|
165
|
+
slot.setAttribute("data-tj-slot", "content");
|
|
166
|
+
this.element.insertBefore(slot, this.element.firstChild);
|
|
167
|
+
for (var _i = 0, _existingNodes = existingNodes; _i < _existingNodes.length; _i++) {
|
|
168
|
+
var node = _existingNodes[_i];
|
|
169
|
+
slot.appendChild(node);
|
|
170
|
+
}
|
|
171
|
+
this.contentSlot = slot;
|
|
139
172
|
this.slotModeEnabled = true;
|
|
140
173
|
}
|
|
141
174
|
}, {
|
|
@@ -168,8 +201,8 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
168
201
|
}, {
|
|
169
202
|
key: "getTagName",
|
|
170
203
|
value: function getTagName() {
|
|
171
|
-
var _this$
|
|
172
|
-
return (_this$
|
|
204
|
+
var _this$element5;
|
|
205
|
+
return (_this$element5 = this.element) === null || _this$element5 === void 0 || (_this$element5 = _this$element5.tagName) === null || _this$element5 === void 0 ? void 0 : _this$element5.toLowerCase();
|
|
173
206
|
}
|
|
174
207
|
}, {
|
|
175
208
|
key: "setSelector",
|
|
@@ -545,14 +578,14 @@ var $Dom = /*#__PURE__*/function () {
|
|
|
545
578
|
}, {
|
|
546
579
|
key: "getScrollTop",
|
|
547
580
|
value: function getScrollTop() {
|
|
548
|
-
var _this$element$scrollT, _this$
|
|
549
|
-
return (_this$element$scrollT = (_this$
|
|
581
|
+
var _this$element$scrollT, _this$element6;
|
|
582
|
+
return (_this$element$scrollT = (_this$element6 = this.element) === null || _this$element6 === void 0 ? void 0 : _this$element6.scrollTop) !== null && _this$element$scrollT !== void 0 ? _this$element$scrollT : 0;
|
|
550
583
|
}
|
|
551
584
|
}, {
|
|
552
585
|
key: "getScrollLeft",
|
|
553
586
|
value: function getScrollLeft() {
|
|
554
|
-
var _this$element$scrollL, _this$
|
|
555
|
-
return (_this$element$scrollL = (_this$
|
|
587
|
+
var _this$element$scrollL, _this$element7;
|
|
588
|
+
return (_this$element$scrollL = (_this$element7 = this.element) === null || _this$element7 === void 0 ? void 0 : _this$element7.scrollLeft) !== null && _this$element$scrollL !== void 0 ? _this$element$scrollL : 0;
|
|
556
589
|
}
|
|
557
590
|
}], [{
|
|
558
591
|
key: "createTemplate",
|
package/build/Bracket.js
CHANGED
|
@@ -24,7 +24,7 @@ var Bracket = /*#__PURE__*/function (_TModel) {
|
|
|
24
24
|
_classCallCheck(this, Bracket);
|
|
25
25
|
_this = _callSuper(this, Bracket, ["BI"]);
|
|
26
26
|
_this.parent = parent;
|
|
27
|
-
_this.
|
|
27
|
+
_this.currentBracketStatus = 2;
|
|
28
28
|
return _this;
|
|
29
29
|
}
|
|
30
30
|
_inherits(Bracket, _TModel);
|
|
@@ -145,12 +145,12 @@ var Bracket = /*#__PURE__*/function (_TModel) {
|
|
|
145
145
|
if (hasEventDirty) {
|
|
146
146
|
return true;
|
|
147
147
|
}
|
|
148
|
-
if (this.
|
|
149
|
-
this.
|
|
148
|
+
if (this.currentBracketStatus >= 1 || this.isNowVisible || this.isNowInvisible) {
|
|
149
|
+
this.currentBracketStatus = Math.max(0, this.currentBracketStatus - 1);
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
152
|
if (nowVisible) {
|
|
153
|
-
this.
|
|
153
|
+
this.currentBracketStatus = Math.min(2, this.currentBracketStatus + 1);
|
|
154
154
|
}
|
|
155
155
|
if (this.getDirtyLayout() === false) {
|
|
156
156
|
return false;
|
|
@@ -140,13 +140,13 @@ var BracketGenerator = /*#__PURE__*/function () {
|
|
|
140
140
|
var bracket = targetBracket;
|
|
141
141
|
bracket.startIndex = Math.min(bracket.startIndex, index);
|
|
142
142
|
bracket.endIndex = bracket.startIndex + bracket.allChildrenList.length;
|
|
143
|
-
bracket.
|
|
143
|
+
bracket.currentBracketStatus = 2;
|
|
144
144
|
bracket.markLayoutDirty('update');
|
|
145
145
|
bracket = targetBracket.getParent();
|
|
146
146
|
while (bracket instanceof Bracket) {
|
|
147
147
|
bracket.startIndex = Math.min(bracket.startIndex, index);
|
|
148
148
|
bracket.endIndex = Math.max(bracket.endIndex, index + 1);
|
|
149
|
-
bracket.
|
|
149
|
+
bracket.currentBracketStatus = 2;
|
|
150
150
|
bracket.markLayoutDirty('update');
|
|
151
151
|
bracket = bracket.getParent();
|
|
152
152
|
}
|
|
@@ -291,7 +291,7 @@ var BracketGenerator = /*#__PURE__*/function () {
|
|
|
291
291
|
value: function markBracketDirty(bracket) {
|
|
292
292
|
var current = bracket;
|
|
293
293
|
while (current && current.type === 'BI') {
|
|
294
|
-
current.
|
|
294
|
+
current.currentBracketStatus = 2;
|
|
295
295
|
current.markLayoutDirty('update');
|
|
296
296
|
current = current.parent;
|
|
297
297
|
}
|
package/build/LoadingManager.js
CHANGED
|
@@ -407,7 +407,7 @@ var LoadingManager = /*#__PURE__*/function () {
|
|
|
407
407
|
var onError = (_tmodel$targets$targe2 = tmodel.targets[targetName]) === null || _tmodel$targets$targe2 === void 0 ? void 0 : _tmodel$targets$targe2.onError;
|
|
408
408
|
if (onError) {
|
|
409
409
|
if (typeof onError === 'function') {
|
|
410
|
-
tmodel.setTargetMethodName(targetName, '
|
|
410
|
+
tmodel.setTargetMethodName(targetName, 'onError');
|
|
411
411
|
onError.call(tmodel, tmodel.val(targetName));
|
|
412
412
|
} else if (Array.isArray(onError)) {
|
|
413
413
|
onError.forEach(function (t) {
|
package/build/TModelManager.js
CHANGED
|
@@ -188,13 +188,22 @@ var TModelManager = /*#__PURE__*/function () {
|
|
|
188
188
|
activated.forEach(function (t) {
|
|
189
189
|
return t.deactivate();
|
|
190
190
|
});
|
|
191
|
-
Object.values(_objectSpread(_objectSpread({}, lastVisibleMap), lastPreservedMap)).filter(function (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
if (
|
|
191
|
+
Object.values(_objectSpread(_objectSpread({}, lastVisibleMap), lastPreservedMap)).filter(Boolean).forEach(function (tmodel) {
|
|
192
|
+
var exists = tmodel.exists();
|
|
193
|
+
var included = exists && tmodel.isIncluded();
|
|
194
|
+
if (!exists || !included) {
|
|
195
|
+
if (tmodel.hasDom()) {
|
|
196
196
|
_this.addToDeletedDom(tmodel);
|
|
197
|
+
} else {
|
|
198
|
+
delete _this.visibleOidMap[tmodel.oid];
|
|
199
|
+
delete _this.preservedDomMap[tmodel.oid];
|
|
200
|
+
_this.domPolicyMap.delete(tmodel.oid);
|
|
197
201
|
}
|
|
202
|
+
} else if (!tmodel.hasDom() && tmodel.canHaveDom()) {
|
|
203
|
+
delete _this.visibleOidMap[tmodel.oid];
|
|
204
|
+
delete _this.preservedDomMap[tmodel.oid];
|
|
205
|
+
tmodel.visibilityStatus = undefined;
|
|
206
|
+
tmodel.markLayoutDirty("noDom");
|
|
198
207
|
}
|
|
199
208
|
});
|
|
200
209
|
return this.lists.noDom.length > 0 ? 0 : this.lists.reattach.length > 0 ? 1 : this.lists.relocation.length > 0 ? 2 : this.lists.rerender.length > 0 ? 3 : this.lists.reasyncStyle.length > 0 ? 4 : this.lists.deletedDom.length > 0 ? 5 : this.lists.restyle.length > 0 ? 10 : -1;
|
|
@@ -224,18 +233,19 @@ var TModelManager = /*#__PURE__*/function () {
|
|
|
224
233
|
return false;
|
|
225
234
|
}
|
|
226
235
|
}, {
|
|
227
|
-
key: "
|
|
228
|
-
value: function
|
|
229
|
-
|
|
236
|
+
key: "shouldHaveDom",
|
|
237
|
+
value: function shouldHaveDom(tmodel) {
|
|
238
|
+
var visible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tmodel.isVisible();
|
|
239
|
+
if (!tmodel.canHaveDom() || !tmodel.isIncluded()) {
|
|
230
240
|
return false;
|
|
231
241
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return this.
|
|
242
|
+
return visible || tmodel.requiresDom() || this.getDomPolicy(tmodel) === "keep";
|
|
243
|
+
}
|
|
244
|
+
}, {
|
|
245
|
+
key: "shouldCreateDom",
|
|
246
|
+
value: function shouldCreateDom(tmodel) {
|
|
247
|
+
var visible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : tmodel.isVisible();
|
|
248
|
+
return !tmodel.hasDom() && this.shouldHaveDom(tmodel, visible);
|
|
239
249
|
}
|
|
240
250
|
}, {
|
|
241
251
|
key: "getDomPolicy",
|
|
@@ -628,32 +638,34 @@ var TModelManager = /*#__PURE__*/function () {
|
|
|
628
638
|
var holdersMap = new Map();
|
|
629
639
|
var styleBatch = [];
|
|
630
640
|
var needsDom = [];
|
|
641
|
+
var attached = [];
|
|
631
642
|
this.lists.noDom.sort(function (a, b) {
|
|
632
|
-
return a.getUIDepth()
|
|
643
|
+
return a.getUIDepth() - b.getUIDepth();
|
|
633
644
|
});
|
|
634
645
|
var _iterator11 = _createForOfIteratorHelper(this.lists.noDom),
|
|
635
646
|
_step11;
|
|
636
647
|
try {
|
|
637
648
|
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
638
|
-
var
|
|
639
|
-
var
|
|
640
|
-
var domId = (
|
|
649
|
+
var _tmodel3$domId;
|
|
650
|
+
var _tmodel3 = _step11.value;
|
|
651
|
+
var domId = (_tmodel3$domId = _tmodel3.domId) !== null && _tmodel3$domId !== void 0 ? _tmodel3$domId : _tmodel3.oid;
|
|
641
652
|
if ($Dom.query("#".concat(domId))) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
653
|
+
_tmodel3.$dom = new $Dom("#".concat(domId));
|
|
654
|
+
_tmodel3.$dom.attr('tgjs', 'true');
|
|
655
|
+
_tmodel3.hasDomNow = true;
|
|
656
|
+
_tmodel3.markLayoutDirty('hasDomNow');
|
|
657
|
+
attached.push(_tmodel3);
|
|
658
|
+
if (this.needsRerender(_tmodel3)) {
|
|
659
|
+
this.lists.rerender.push(_tmodel3);
|
|
648
660
|
}
|
|
649
|
-
if (this.needsRestyle(
|
|
650
|
-
this.lists.restyle.push(
|
|
661
|
+
if (this.needsRestyle(_tmodel3)) {
|
|
662
|
+
this.lists.restyle.push(_tmodel3);
|
|
651
663
|
}
|
|
652
|
-
if (this.needsReasyncStyle(
|
|
653
|
-
this.lists.reasyncStyle.push(
|
|
664
|
+
if (this.needsReasyncStyle(_tmodel3)) {
|
|
665
|
+
this.lists.reasyncStyle.push(_tmodel3);
|
|
654
666
|
}
|
|
655
667
|
} else {
|
|
656
|
-
needsDom.push(
|
|
668
|
+
needsDom.push(_tmodel3);
|
|
657
669
|
}
|
|
658
670
|
}
|
|
659
671
|
} catch (err) {
|
|
@@ -674,22 +686,24 @@ var TModelManager = /*#__PURE__*/function () {
|
|
|
674
686
|
if (!tmodel.hasDom()) {
|
|
675
687
|
domHolder.appendTModel$Dom(tmodel);
|
|
676
688
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
689
|
+
attached.push(tmodel);
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
TModelUtil.createDom(tmodel);
|
|
693
|
+
TModelUtil.patchDom(tmodel);
|
|
694
|
+
styleBatch.push(tmodel);
|
|
695
|
+
attached.push(tmodel);
|
|
696
|
+
var entry = holdersMap.get(domHolder);
|
|
697
|
+
if (!entry) {
|
|
698
|
+
entry = {
|
|
699
|
+
domHolder: domHolder,
|
|
700
|
+
fragment: $Dom.createDocumentFragment(),
|
|
701
|
+
tmodels: []
|
|
702
|
+
};
|
|
703
|
+
holdersMap.set(domHolder, entry);
|
|
692
704
|
}
|
|
705
|
+
entry.fragment.appendChild(tmodel.$dom.element);
|
|
706
|
+
entry.tmodels.push(tmodel);
|
|
693
707
|
}
|
|
694
708
|
var _iterator12 = _createForOfIteratorHelper(holdersMap.values()),
|
|
695
709
|
_step12;
|
|
@@ -705,30 +719,22 @@ var TModelManager = /*#__PURE__*/function () {
|
|
|
705
719
|
} finally {
|
|
706
720
|
_iterator12.f();
|
|
707
721
|
}
|
|
708
|
-
var
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
712
|
-
var _tmodel3 = _step13.value;
|
|
713
|
-
this.catchupNoDomTargetsBeforeStyle(_tmodel3);
|
|
714
|
-
}
|
|
715
|
-
} catch (err) {
|
|
716
|
-
_iterator13.e(err);
|
|
717
|
-
} finally {
|
|
718
|
-
_iterator13.f();
|
|
722
|
+
for (var _i6 = 0, _attached = attached; _i6 < _attached.length; _i6++) {
|
|
723
|
+
var _tmodel = _attached[_i6];
|
|
724
|
+
this.catchupNoDomTargetsBeforeStyle(_tmodel);
|
|
719
725
|
}
|
|
720
|
-
for (var
|
|
721
|
-
var
|
|
722
|
-
if (
|
|
723
|
-
|
|
724
|
-
|
|
726
|
+
for (var _i7 = 0, _styleBatch = styleBatch; _i7 < _styleBatch.length; _i7++) {
|
|
727
|
+
var _tmodel2 = _styleBatch[_i7];
|
|
728
|
+
if (_tmodel2.hasDom()) {
|
|
729
|
+
_tmodel2.hasDomNow = true;
|
|
730
|
+
_tmodel2.markLayoutDirty('hasDomNow');
|
|
725
731
|
}
|
|
726
|
-
TModelUtil.initStyleMaps(
|
|
727
|
-
TModelUtil.fixStyle(
|
|
728
|
-
TModelUtil.fixAsyncStyle(
|
|
732
|
+
TModelUtil.initStyleMaps(_tmodel2);
|
|
733
|
+
TModelUtil.fixStyle(_tmodel2);
|
|
734
|
+
TModelUtil.fixAsyncStyle(_tmodel2);
|
|
729
735
|
}
|
|
730
|
-
this.activatePendingTargetsAfterDom(
|
|
731
|
-
getEvents().attachEvents(
|
|
736
|
+
this.activatePendingTargetsAfterDom(attached);
|
|
737
|
+
getEvents().attachEvents(attached.filter(function (t) {
|
|
732
738
|
var _t$externalEventMap;
|
|
733
739
|
return ((_t$externalEventMap = t.externalEventMap) === null || _t$externalEventMap === void 0 ? void 0 : _t$externalEventMap.size) > 0;
|
|
734
740
|
}));
|
package/build/TargetUtil.js
CHANGED
|
@@ -590,7 +590,7 @@ var TargetUtil = /*#__PURE__*/function () {
|
|
|
590
590
|
if (getManager().needsReattach(tmodel)) {
|
|
591
591
|
return "needs Reattach";
|
|
592
592
|
}
|
|
593
|
-
if (
|
|
593
|
+
if (getManager().shouldHaveDom(tmodel) && !tmodel.hasDom()) {
|
|
594
594
|
return "no dom";
|
|
595
595
|
}
|
|
596
596
|
if (!tmodel.isTargetComplete(key) && !tmodel.isTargetDone(key)) {
|