targetj 1.0.252 → 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 CHANGED
@@ -56,7 +56,7 @@ npm install targetj
56
56
 
57
57
  **2. Example**
58
58
 
59
- This creates the following sequence: appear → bounce → move → turn red → log. Notice how the code follows the UI sequence. There is only one state, and the animation transitions are part of that state.
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 in.
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
- return this.selector ? !!$Dom.query(this.selector) : false;
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$element;
101
- return this.getTagName() === 'body' || ((_this$element = this.element) === null || _this$element === void 0 ? void 0 : _this$element.getAttribute('data-tj-no-slot')) === 'true';
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$element2;
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
- if (!((_this$element2 = this.element) !== null && _this$element2 !== void 0 && _this$element2.firstChild)) {
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
- var slot = this.ensureContentSlotFirst();
133
- var n = slot.nextSibling;
134
- while (n) {
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$element3;
172
- return (_this$element3 = this.element) === null || _this$element3 === void 0 || (_this$element3 = _this$element3.tagName) === null || _this$element3 === void 0 ? void 0 : _this$element3.toLowerCase();
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$element4;
549
- return (_this$element$scrollT = (_this$element4 = this.element) === null || _this$element4 === void 0 ? void 0 : _this$element4.scrollTop) !== null && _this$element$scrollT !== void 0 ? _this$element$scrollT : 0;
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$element5;
555
- return (_this$element$scrollL = (_this$element5 = this.element) === null || _this$element5 === void 0 ? void 0 : _this$element5.scrollLeft) !== null && _this$element$scrollL !== void 0 ? _this$element$scrollL : 0;
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",
@@ -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 (v) {
192
- return v !== undefined;
193
- }).forEach(function (tmodel) {
194
- if (tmodel.hasDom()) {
195
- if (!tmodel.exists() || !tmodel.isIncluded()) {
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: "shouldCreateDom",
228
- value: function shouldCreateDom(tmodel, visible) {
229
- if (!tmodel.canHaveDom() || !tmodel.isIncluded() || tmodel.hasDom()) {
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
- if (visible) {
233
- return true;
234
- }
235
- if (tmodel.requiresDom()) {
236
- return true;
237
- }
238
- return this.getDomPolicy(tmodel) === "keep";
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() < b.getUIDepth() ? -1 : 1;
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 _tmodel2$domId;
639
- var _tmodel2 = _step11.value;
640
- var domId = (_tmodel2$domId = _tmodel2.domId) !== null && _tmodel2$domId !== void 0 ? _tmodel2$domId : _tmodel2.oid;
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
- _tmodel2.$dom = new $Dom("#".concat(domId));
643
- _tmodel2.$dom.attr('tgjs', 'true');
644
- _tmodel2.hasDomNow = true;
645
- _tmodel2.markLayoutDirty('hasDomNow');
646
- if (this.needsRerender(_tmodel2)) {
647
- this.lists.rerender.push(_tmodel2);
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(_tmodel2)) {
650
- this.lists.restyle.push(_tmodel2);
661
+ if (this.needsRestyle(_tmodel3)) {
662
+ this.lists.restyle.push(_tmodel3);
651
663
  }
652
- if (this.needsReasyncStyle(_tmodel2)) {
653
- this.lists.reasyncStyle.push(_tmodel2);
664
+ if (this.needsReasyncStyle(_tmodel3)) {
665
+ this.lists.reasyncStyle.push(_tmodel3);
654
666
  }
655
667
  } else {
656
- needsDom.push(_tmodel2);
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
- } else {
678
- TModelUtil.createDom(tmodel);
679
- TModelUtil.patchDom(tmodel);
680
- styleBatch.push(tmodel);
681
- var entry = holdersMap.get(domHolder);
682
- if (!entry) {
683
- entry = {
684
- domHolder: domHolder,
685
- fragment: $Dom.createDocumentFragment(),
686
- tmodels: []
687
- };
688
- holdersMap.set(domHolder, entry);
689
- }
690
- entry.fragment.appendChild(tmodel.$dom.element);
691
- entry.tmodels.push(tmodel);
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 _iterator13 = _createForOfIteratorHelper(this.lists.noDom),
709
- _step13;
710
- try {
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 _i6 = 0, _styleBatch = styleBatch; _i6 < _styleBatch.length; _i6++) {
721
- var _tmodel = _styleBatch[_i6];
722
- if (_tmodel.hasDom()) {
723
- _tmodel.hasDomNow = true;
724
- _tmodel.markLayoutDirty('hasDomNow');
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(_tmodel);
727
- TModelUtil.fixStyle(_tmodel);
728
- TModelUtil.fixAsyncStyle(_tmodel);
732
+ TModelUtil.initStyleMaps(_tmodel2);
733
+ TModelUtil.fixStyle(_tmodel2);
734
+ TModelUtil.fixAsyncStyle(_tmodel2);
729
735
  }
730
- this.activatePendingTargetsAfterDom(this.lists.noDom);
731
- getEvents().attachEvents(this.lists.noDom.filter(function (t) {
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
  }));
@@ -590,7 +590,7 @@ var TargetUtil = /*#__PURE__*/function () {
590
590
  if (getManager().needsReattach(tmodel)) {
591
591
  return "needs Reattach";
592
592
  }
593
- if (tmodel.canHaveDom() && !tmodel.hasDom()) {
593
+ if (getManager().shouldHaveDom(tmodel) && !tmodel.hasDom()) {
594
594
  return "no dom";
595
595
  }
596
596
  if (!tmodel.isTargetComplete(key) && !tmodel.isTargetDone(key)) {