targetj 1.1.0 → 1.1.1

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.
@@ -2,16 +2,16 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
8
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
9
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
10
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
11
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
12
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
13
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
11
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
14
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); 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) : void 0; } }
13
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
14
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
15
15
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
16
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; 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; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; 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); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, 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); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; 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; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
17
17
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -48,15 +48,21 @@ var TModelUtil = /*#__PURE__*/function () {
48
48
  left = page.scrollLeft || 0;
49
49
  top = page.scrollTop || 0;
50
50
  window.scrollTo(left, top);
51
- _context.next = 5;
52
- return new Promise(requestAnimationFrame);
51
+ if (!(left === 0 && top === 0)) {
52
+ _context.next = 5;
53
+ break;
54
+ }
55
+ return _context.abrupt("return");
53
56
  case 5:
57
+ _context.next = 7;
58
+ return new Promise(requestAnimationFrame);
59
+ case 7:
54
60
  window.scrollTo(left, top);
55
- _context.next = 8;
61
+ _context.next = 10;
56
62
  return new Promise(requestAnimationFrame);
57
- case 8:
63
+ case 10:
58
64
  window.scrollTo(left, top);
59
- case 9:
65
+ case 11:
60
66
  case "end":
61
67
  return _context.stop();
62
68
  }
@@ -80,57 +86,85 @@ var TModelUtil = /*#__PURE__*/function () {
80
86
  }, {
81
87
  key: "captureDomState",
82
88
  value: function captureDomState($root) {
83
- if (!($root !== null && $root !== void 0 && $root.getElement())) {
89
+ var root = $root === null || $root === void 0 ? void 0 : $root.getElement();
90
+ if (!root) {
84
91
  return undefined;
85
92
  }
86
- var elements = [$root.getElement()].concat(_toConsumableArray($root.queryAll("*")));
87
93
  var controls = [];
88
94
  var scrollPositions = [];
89
- elements.forEach(function (element, index) {
90
- var _element$tagName;
91
- var tagName = (_element$tagName = element.tagName) === null || _element$tagName === void 0 ? void 0 : _element$tagName.toLowerCase();
92
- if (tagName === "input") {
93
- var type = (element.type || "text").toLowerCase();
94
- if (type !== "file") {
95
+ var doc = root.ownerDocument;
96
+ var focusedElement = doc.activeElement;
97
+ var activeElement = focusedElement === doc.body || focusedElement === doc.documentElement ? null : focusedElement;
98
+ var walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
99
+ var element = root;
100
+ var index = 0;
101
+ var controlIndex = 0;
102
+ var activeIndex = -1;
103
+ while (element) {
104
+ var kind = element.localName;
105
+ if (element === activeElement) {
106
+ activeIndex = index;
107
+ }
108
+ switch (kind) {
109
+ case "input":
110
+ {
111
+ var currentControlIndex = controlIndex++;
112
+ if (element.type !== "file") {
113
+ controls.push({
114
+ index: index,
115
+ controlIndex: currentControlIndex,
116
+ kind: kind,
117
+ value: element.value,
118
+ checked: element.checked,
119
+ indeterminate: element.indeterminate
120
+ });
121
+ }
122
+ break;
123
+ }
124
+ case "textarea":
95
125
  controls.push({
96
126
  index: index,
97
- kind: "input",
98
- value: element.value,
99
- checked: element.checked,
100
- indeterminate: element.indeterminate
127
+ controlIndex: controlIndex++,
128
+ kind: kind,
129
+ value: element.value
101
130
  });
102
- }
103
- } else if (tagName === "textarea") {
104
- controls.push({
105
- index: index,
106
- kind: "textarea",
107
- value: element.value
108
- });
109
- } else if (tagName === "select") {
110
- controls.push({
111
- index: index,
112
- kind: "select",
113
- selected: _toConsumableArray(element.options).map(function (option) {
114
- return option.selected;
115
- })
116
- });
117
- } else if (tagName === "details") {
118
- controls.push({
119
- index: index,
120
- kind: "details",
121
- open: element.open
122
- });
131
+ break;
132
+ case "select":
133
+ {
134
+ var options = element.options;
135
+ var selected = new Array(options.length);
136
+ for (var i = 0; i < options.length; i++) {
137
+ selected[i] = options[i].selected;
138
+ }
139
+ controls.push({
140
+ index: index,
141
+ controlIndex: controlIndex++,
142
+ kind: kind,
143
+ selected: selected
144
+ });
145
+ break;
146
+ }
147
+ case "details":
148
+ controls.push({
149
+ index: index,
150
+ controlIndex: controlIndex++,
151
+ kind: kind,
152
+ open: element.open
153
+ });
154
+ break;
123
155
  }
124
- if (element.scrollLeft || element.scrollTop) {
156
+ var scrollLeft = element.scrollLeft;
157
+ var scrollTop = element.scrollTop;
158
+ if (scrollLeft || scrollTop) {
125
159
  scrollPositions.push({
126
160
  index: index,
127
- scrollLeft: element.scrollLeft,
128
- scrollTop: element.scrollTop
161
+ scrollLeft: scrollLeft,
162
+ scrollTop: scrollTop
129
163
  });
130
164
  }
131
- });
132
- var activeElement = document.activeElement;
133
- var activeIndex = activeElement && $root.contains(activeElement) ? elements.indexOf(activeElement) : -1;
165
+ element = walker.nextNode();
166
+ index++;
167
+ }
134
168
  var selection;
135
169
  if (activeIndex >= 0 && typeof activeElement.selectionStart === "number") {
136
170
  selection = {
@@ -149,38 +183,58 @@ var TModelUtil = /*#__PURE__*/function () {
149
183
  }, {
150
184
  key: "restoreMountedDom",
151
185
  value: function restoreMountedDom($root, domState) {
152
- if (!($root !== null && $root !== void 0 && $root.getElement()) || !domState) {
186
+ var root = $root === null || $root === void 0 ? void 0 : $root.getElement();
187
+ var states = domState === null || domState === void 0 ? void 0 : domState.controls;
188
+ if (!root || !(states !== null && states !== void 0 && states.length)) {
153
189
  return;
154
190
  }
155
- var elements = [$root.getElement()].concat(_toConsumableArray($root.queryAll("*")));
156
- var _iterator = _createForOfIteratorHelper(domState.controls || []),
191
+ var selector = "input,textarea,select,details";
192
+ var offset = root.matches(selector) ? 1 : 0;
193
+ var elements = root.querySelectorAll(selector);
194
+ var _iterator = _createForOfIteratorHelper(states),
157
195
  _step;
158
196
  try {
159
- var _loop = function _loop() {
160
- var _element$tagName2;
197
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
161
198
  var state = _step.value;
162
- var element = elements[state.index];
163
- if (!element) {
164
- return 1; // continue
199
+ var element = offset && state.controlIndex === 0 ? root : elements[state.controlIndex - offset];
200
+ if (!element || element.localName !== state.kind) {
201
+ continue;
165
202
  }
166
- var tagName = (_element$tagName2 = element.tagName) === null || _element$tagName2 === void 0 ? void 0 : _element$tagName2.toLowerCase();
167
- if (state.kind === "input" && tagName === "input") {
168
- element.value = state.value;
169
- element.checked = state.checked;
170
- element.indeterminate = state.indeterminate;
171
- } else if (state.kind === "textarea" && tagName === "textarea") {
172
- element.value = state.value;
173
- } else if (state.kind === "select" && tagName === "select") {
174
- Array.from(element.options).forEach(function (option, index) {
175
- var _state$selected;
176
- option.selected = ((_state$selected = state.selected) === null || _state$selected === void 0 ? void 0 : _state$selected[index]) === true;
177
- });
178
- } else if (state.kind === "details" && tagName === "details") {
179
- element.open = state.open;
203
+ switch (state.kind) {
204
+ case "input":
205
+ if (element.value !== state.value) {
206
+ element.value = state.value;
207
+ }
208
+ if (element.checked !== state.checked) {
209
+ element.checked = state.checked;
210
+ }
211
+ if (element.indeterminate !== state.indeterminate) {
212
+ element.indeterminate = state.indeterminate;
213
+ }
214
+ break;
215
+ case "textarea":
216
+ if (element.value !== state.value) {
217
+ element.value = state.value;
218
+ }
219
+ break;
220
+ case "select":
221
+ {
222
+ var options = element.options;
223
+ var selected = state.selected || [];
224
+ for (var i = 0; i < options.length; i++) {
225
+ var value = selected[i] === true;
226
+ if (options[i].selected !== value) {
227
+ options[i].selected = value;
228
+ }
229
+ }
230
+ break;
231
+ }
232
+ case "details":
233
+ if (element.open !== state.open) {
234
+ element.open = state.open;
235
+ }
236
+ break;
180
237
  }
181
- };
182
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
183
- if (_loop()) continue;
184
238
  }
185
239
  } catch (err) {
186
240
  _iterator.e(err);
@@ -192,77 +246,110 @@ var TModelUtil = /*#__PURE__*/function () {
192
246
  key: "restoreDomInteractionState",
193
247
  value: function () {
194
248
  var _restoreDomInteractionState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2($root, domState) {
195
- var elements, _iterator2, _step2, state, element, activeElement, _activeElement$focus;
249
+ var _domState$activeIndex;
250
+ var _ref,
251
+ _ref$focus,
252
+ focus,
253
+ root,
254
+ scrollPositions,
255
+ activeIndex,
256
+ lastScrollIndex,
257
+ lastIndex,
258
+ walker,
259
+ element,
260
+ activeElement,
261
+ scrollIndex,
262
+ index,
263
+ state,
264
+ left,
265
+ top,
266
+ tag,
267
+ editable,
268
+ _activeElement$focus,
269
+ _activeElement,
270
+ _args2 = arguments;
196
271
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
197
272
  while (1) switch (_context2.prev = _context2.next) {
198
273
  case 0:
199
- if (!(!($root !== null && $root !== void 0 && $root.getElement()) || !domState)) {
200
- _context2.next = 2;
274
+ _ref = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {}, _ref$focus = _ref.focus, focus = _ref$focus === void 0 ? "editable" : _ref$focus;
275
+ root = $root === null || $root === void 0 ? void 0 : $root.getElement();
276
+ if (!(!root || !domState)) {
277
+ _context2.next = 4;
201
278
  break;
202
279
  }
203
280
  return _context2.abrupt("return");
204
- case 2:
205
- _context2.next = 4;
206
- return new Promise(requestAnimationFrame);
207
281
  case 4:
208
- elements = [$root.getElement()].concat(_toConsumableArray($root.queryAll("*")));
209
- _iterator2 = _createForOfIteratorHelper(domState.scrollPositions || []);
210
- _context2.prev = 6;
211
- _iterator2.s();
212
- case 8:
213
- if ((_step2 = _iterator2.n()).done) {
214
- _context2.next = 17;
282
+ scrollPositions = domState.scrollPositions || [];
283
+ activeIndex = (_domState$activeIndex = domState.activeIndex) !== null && _domState$activeIndex !== void 0 ? _domState$activeIndex : -1;
284
+ if (root === root.ownerDocument.body && activeIndex === 0) {
285
+ activeIndex = -1;
286
+ }
287
+ if (!(!scrollPositions.length && activeIndex < 0)) {
288
+ _context2.next = 9;
215
289
  break;
216
290
  }
217
- state = _step2.value;
218
- element = elements[state.index];
219
- if (element) {
220
- _context2.next = 13;
291
+ return _context2.abrupt("return");
292
+ case 9:
293
+ // Wait only when restoring nonzero scroll positions.
294
+ //if (scrollPositions.length) {
295
+ // await new Promise(requestAnimationFrame);
296
+ //}
297
+ lastScrollIndex = scrollPositions.length ? scrollPositions[scrollPositions.length - 1].index : -1;
298
+ lastIndex = Math.max(activeIndex, lastScrollIndex);
299
+ walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
300
+ element = root;
301
+ scrollIndex = 0;
302
+ for (index = 0; element && index <= lastIndex; index++, element = walker.nextNode()) {
303
+ if (index === activeIndex) {
304
+ activeElement = element;
305
+ }
306
+ if (scrollIndex < scrollPositions.length && scrollPositions[scrollIndex].index === index) {
307
+ state = scrollPositions[scrollIndex++];
308
+ left = element.scrollLeft;
309
+ top = element.scrollTop;
310
+ if (left !== state.scrollLeft) {
311
+ element.scrollLeft = state.scrollLeft;
312
+ }
313
+ if (top !== state.scrollTop) {
314
+ element.scrollTop = state.scrollTop;
315
+ }
316
+ }
317
+ }
318
+ if (!(!activeElement || focus === "none")) {
319
+ _context2.next = 17;
221
320
  break;
222
321
  }
223
- return _context2.abrupt("continue", 15);
224
- case 13:
225
- element.scrollLeft = state.scrollLeft;
226
- element.scrollTop = state.scrollTop;
227
- case 15:
228
- _context2.next = 8;
229
- break;
322
+ return _context2.abrupt("return");
230
323
  case 17:
231
- _context2.next = 22;
232
- break;
233
- case 19:
234
- _context2.prev = 19;
235
- _context2.t0 = _context2["catch"](6);
236
- _iterator2.e(_context2.t0);
237
- case 22:
238
- _context2.prev = 22;
239
- _iterator2.f();
240
- return _context2.finish(22);
241
- case 25:
242
- activeElement = elements[domState.activeIndex];
243
- if (activeElement) {
244
- _context2.next = 28;
324
+ if (!(focus === "editable")) {
325
+ _context2.next = 22;
326
+ break;
327
+ }
328
+ tag = activeElement.localName;
329
+ editable = tag === "textarea" || tag === "select" || tag === "input" && activeElement.type !== "hidden" || activeElement.isContentEditable;
330
+ if (editable) {
331
+ _context2.next = 22;
245
332
  break;
246
333
  }
247
334
  return _context2.abrupt("return");
248
- case 28:
335
+ case 22:
249
336
  try {
250
337
  activeElement.focus({
251
338
  preventScroll: true
252
339
  });
253
340
  } catch (_unused) {
254
- (_activeElement$focus = activeElement.focus) === null || _activeElement$focus === void 0 || _activeElement$focus.call(activeElement);
341
+ (_activeElement$focus = (_activeElement = activeElement).focus) === null || _activeElement$focus === void 0 || _activeElement$focus.call(_activeElement);
255
342
  }
256
343
  if (domState.selection && typeof activeElement.setSelectionRange === "function") {
257
344
  try {
258
345
  activeElement.setSelectionRange(domState.selection.start, domState.selection.end, domState.selection.direction);
259
346
  } catch (_unused2) {}
260
347
  }
261
- case 30:
348
+ case 24:
262
349
  case "end":
263
350
  return _context2.stop();
264
351
  }
265
- }, _callee2, null, [[6, 19, 22, 25]]);
352
+ }, _callee2);
266
353
  }));
267
354
  function restoreDomInteractionState(_x2, _x3) {
268
355
  return _restoreDomInteractionState.apply(this, arguments);
@@ -412,20 +499,20 @@ var TModelUtil = /*#__PURE__*/function () {
412
499
  tmodel.domWidthTimestamp = 0;
413
500
  tmodel.tfMap = {};
414
501
  tmodel.styleMap = {};
415
- var _iterator3 = _createForOfIteratorHelper(tmodel.allStyleTargetMap),
416
- _step3;
502
+ var _iterator2 = _createForOfIteratorHelper(tmodel.allStyleTargetMap),
503
+ _step2;
417
504
  try {
418
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
419
- var _step3$value = _slicedToArray(_step3.value, 1),
420
- key = _step3$value[0];
505
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
506
+ var _step2$value = _slicedToArray(_step2.value, 1),
507
+ key = _step2$value[0];
421
508
  if (TUtil.isDefined(tmodel.val(key))) {
422
509
  tmodel.addToStyleTargetList(key);
423
510
  }
424
511
  }
425
512
  } catch (err) {
426
- _iterator3.e(err);
513
+ _iterator2.e(err);
427
514
  } finally {
428
- _iterator3.f();
515
+ _iterator2.f();
429
516
  }
430
517
  }
431
518
  }, {
@@ -506,11 +593,11 @@ var TModelUtil = /*#__PURE__*/function () {
506
593
  return;
507
594
  }
508
595
  var transformChanged = false;
509
- var _iterator4 = _createForOfIteratorHelper(originalKeys),
510
- _step4;
596
+ var _iterator3 = _createForOfIteratorHelper(originalKeys),
597
+ _step3;
511
598
  try {
512
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
513
- var originalKey = _step4.value;
599
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
600
+ var originalKey = _step3.value;
514
601
  var key = TargetUtil.getTargetName(originalKey);
515
602
  var value = tmodel.val(key);
516
603
  if (!TUtil.isDefined(value)) {
@@ -549,9 +636,9 @@ var TModelUtil = /*#__PURE__*/function () {
549
636
  tmodel.$dom.style(key, styleValue);
550
637
  }
551
638
  } catch (err) {
552
- _iterator4.e(err);
639
+ _iterator3.e(err);
553
640
  } finally {
554
- _iterator4.f();
641
+ _iterator3.f();
555
642
  }
556
643
  if (transformChanged) {
557
644
  var transformValues = _objectSpread(_objectSpread({}, TModelUtil.getTransformBaseFromActualValues(tmodel)), tmodel.tfMap);
@@ -638,12 +725,12 @@ var TModelUtil = /*#__PURE__*/function () {
638
725
  if (!tmodel.asyncStyleTargetMap) {
639
726
  return;
640
727
  }
641
- var _iterator5 = _createForOfIteratorHelper(tmodel.asyncStyleTargetMap),
642
- _step5;
728
+ var _iterator4 = _createForOfIteratorHelper(tmodel.asyncStyleTargetMap),
729
+ _step4;
643
730
  try {
644
- var _loop2 = function _loop2() {
645
- var _step5$value = _slicedToArray(_step5.value, 1),
646
- key = _step5$value[0];
731
+ var _loop = function _loop() {
732
+ var _step4$value = _slicedToArray(_step4.value, 1),
733
+ key = _step4$value[0];
647
734
  if (key === 'style') {
648
735
  var style = tmodel.getStyle();
649
736
  if (TUtil.isDefined(style) && tmodel.styleMap.style !== style) {
@@ -678,13 +765,13 @@ var TModelUtil = /*#__PURE__*/function () {
678
765
  }
679
766
  }
680
767
  };
681
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
682
- _loop2();
768
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
769
+ _loop();
683
770
  }
684
771
  } catch (err) {
685
- _iterator5.e(err);
772
+ _iterator4.e(err);
686
773
  } finally {
687
- _iterator5.f();
774
+ _iterator4.f();
688
775
  }
689
776
  tmodel.asyncStyleTargetMap.clear();
690
777
  }
@@ -752,20 +839,20 @@ var TModelUtil = /*#__PURE__*/function () {
752
839
  };
753
840
  var firstIdx = function firstIdx(candidates) {
754
841
  var best = Infinity;
755
- var _iterator6 = _createForOfIteratorHelper(candidates),
756
- _step6;
842
+ var _iterator5 = _createForOfIteratorHelper(candidates),
843
+ _step5;
757
844
  try {
758
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
759
- var c = _step6.value;
845
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
846
+ var c = _step5.value;
760
847
  var i = names.indexOf(c);
761
848
  if (i >= 0 && i < best) {
762
849
  best = i;
763
850
  }
764
851
  }
765
852
  } catch (err) {
766
- _iterator6.e(err);
853
+ _iterator5.e(err);
767
854
  } finally {
768
- _iterator6.f();
855
+ _iterator5.f();
769
856
  }
770
857
  return best;
771
858
  };
package/build/TUtil.js CHANGED
@@ -312,7 +312,7 @@ var TUtil = /*#__PURE__*/function () {
312
312
  }, {
313
313
  key: "advanceTargetByElapsed",
314
314
  value: function advanceTargetByElapsed(tmodel, key) {
315
- var _targetValue$valueLis3;
315
+ var _targetValue$valueLis2;
316
316
  var targetValue = tmodel.targetValues[key];
317
317
  if (!targetValue) {
318
318
  return {
@@ -323,19 +323,19 @@ var TUtil = /*#__PURE__*/function () {
323
323
  };
324
324
  }
325
325
  if (!TUtil.isDefined(targetValue.catchupAt)) {
326
- var _targetValue$valueLis, _targetValue$valueLis2;
326
+ var _targetValue$valueLis;
327
327
  var step = tmodel.getTargetStep(key);
328
328
  var valuePointer = (_targetValue$valueLis = targetValue.valueList) !== null && _targetValue$valueLis !== void 0 && _targetValue$valueLis.length ? tmodel.getValueListPointer(key) : 0;
329
329
  return {
330
330
  step: step,
331
331
  cycle: tmodel.getTargetCycle(key),
332
332
  valuePointer: valuePointer,
333
- done: (_targetValue$valueLis2 = targetValue.valueList) !== null && _targetValue$valueLis2 !== void 0 && _targetValue$valueLis2.length ? valuePointer >= targetValue.valueList.length : false
333
+ done: !TargetUtil.isTargetUpdating(tmodel, key)
334
334
  };
335
335
  }
336
336
  var now = TUtil.now();
337
337
  var elapsedMs = now - targetValue.catchupAt;
338
- var progress = (_targetValue$valueLis3 = targetValue.valueList) !== null && _targetValue$valueLis3 !== void 0 && _targetValue$valueLis3.length ? TUtil.advanceValueListTargetByElapsed(tmodel, key, elapsedMs) : TUtil.advanceSimpleTargetByElapsed(tmodel, key, elapsedMs);
338
+ var progress = (_targetValue$valueLis2 = targetValue.valueList) !== null && _targetValue$valueLis2 !== void 0 && _targetValue$valueLis2.length ? TUtil.advanceValueListTargetByElapsed(tmodel, key, elapsedMs) : TUtil.advanceSimpleTargetByElapsed(tmodel, key, elapsedMs);
339
339
  if (!progress.done) {
340
340
  targetValue.catchupAt = now - progress.remainingMs;
341
341
  }