targetj 1.0.159 → 1.0.166

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/Export.js CHANGED
@@ -1,14 +1,52 @@
1
- export * from "./build/App.js"
2
- export * from "./build/TModel.js"
3
- export * from "./build/Moves.js"
4
- export * from "./build/SearchUtil.js"
5
- export * from "./build/TargetData.js"
6
- export * from "./build/TargetUtil.js"
7
- export * from "./build/TModelUtil.js"
8
- export * from "./build/TUtil.js"
9
- export * from "./build/$Dom.js"
10
- export * from "./build/Bracket.js"
11
- export * from "./build/BracketGenerator.js"
12
- export * from "./build/ColorUtil.js"
13
- export * from "./build/Easing.js"
14
- export * from "./build/TargetExecutor"
1
+ export * from "./build/App.js";
2
+ export * from "./build/TModel.js";
3
+ export * from "./build/Moves.js";
4
+ export * from "./build/SearchUtil.js";
5
+ export * from "./build/TargetData.js";
6
+ export * from "./build/TargetUtil.js";
7
+ export * from "./build/TModelUtil.js";
8
+ export * from "./build/TUtil.js";
9
+ export * from "./build/$Dom.js";
10
+ export * from "./build/Bracket.js";
11
+ export * from "./build/BracketGenerator.js";
12
+ export * from "./build/ColorUtil.js";
13
+ export * from "./build/Easing.js";
14
+ export * from "./build/TargetExecutor.js";
15
+
16
+ import * as App from './build/App.js';
17
+ import * as TModel from './build/TModel.js';
18
+ import * as Moves from './build/Moves.js';
19
+ import * as SearchUtil from './build/SearchUtil.js';
20
+ import * as TargetData from './build/TargetData.js';
21
+ import * as TargetUtil from './build/TargetUtil.js';
22
+ import * as TModelUtil from './build/TModelUtil.js';
23
+ import * as TUtil from './build/TUtil.js';
24
+ import * as Dom from './build/$Dom.js';
25
+ import * as Bracket from './build/Bracket.js';
26
+ import * as BracketGenerator from './build/BracketGenerator.js';
27
+ import * as ColorUtil from './build/ColorUtil.js';
28
+ import * as Easing from './build/Easing.js';
29
+ import * as TargetExecutor from './build/TargetExecutor.js';
30
+
31
+ const TargetJS = {
32
+ ...App,
33
+ ...TModel,
34
+ ...Moves,
35
+ ...SearchUtil,
36
+ ...TargetData,
37
+ ...TargetUtil,
38
+ ...TModelUtil,
39
+ ...TUtil,
40
+ ...Dom,
41
+ ...Bracket,
42
+ ...BracketGenerator,
43
+ ...ColorUtil,
44
+ ...Easing,
45
+ ...TargetExecutor,
46
+ };
47
+
48
+ if (typeof window !== 'undefined') {
49
+ window.TargetJS = TargetJS;
50
+ }
51
+
52
+ export default TargetJS;
package/README.md CHANGED
@@ -99,28 +99,45 @@ App({
99
99
  });
100
100
  ```
101
101
 
102
+ Or in HTML (no JavaScript required), using tg- attributes that mirror object literal keys:
103
+
104
+ ```html
105
+ <div
106
+ tg-background="mediumpurple"
107
+ tg-width="[{ list: [100, 250, 100] }, 50, 10]"
108
+ tg-height$="return this.prevTargetValue / 2;">
109
+ </div>
110
+ ```
111
+
102
112
  ### Simple Loading API Example
103
113
 
104
114
  In this example, we load one user and display its name.
105
115
 
106
- - `loadUser` calls the fetch API to retrieve user details.
116
+ - `fetch` is a special target that performs a data fetch when given a URL string. For more complex API requests, you can use the framework’s built-in `fetch()` function. See examples below.
107
117
  - `html` sets the text content of the div to the user's name. Since the target name is prefixed with `_` and ends with `$`, it executes only when an API call returns a result. `prevTargetValue` refers to the result of the previous target, which, in this case, is the result of the API call.
108
118
 
109
119
  ![first example](https://targetjs.io/img/quick2_4.gif)
110
120
 
111
121
  ```bash
112
- import { App, fetch } from "targetj";
122
+ import { App } from "targetj";
113
123
 
114
124
  App({
115
- loadUser() {
116
- fetch(this, "https://targetjs.io/api/randomUser", { id: "user0" });
117
- },
118
- _html$() {
119
- return this.prevTargetValue.name;
120
- }
125
+ fetch: "https://targetjs.io/api/randomUser?id=user0",
126
+ _html$() {
127
+ return this.prevTargetValue.name;
128
+ }
121
129
  });
122
130
  ```
123
131
 
132
+ Or in HTML:
133
+
134
+ ```html
135
+ <div
136
+ tg-fetch="https://targetjs.io/api/randomUser?id=user0"
137
+ tg-html$="return this.prevTargetValue?.name;">
138
+ </div>
139
+ ```
140
+
124
141
  ### Loading Two Users Example
125
142
 
126
143
  In this example, we load two separate users and display two purple boxes, each containing a user's name, based on our first example.
@@ -136,8 +153,8 @@ import { App, fetch } from "targetj";
136
153
 
137
154
  App({
138
155
  loadUsers() {
139
- fetch(this, "https://targetjs.io/api/randomUser", { id: "user0" });
140
- fetch(this, "https://targetjs.io/api/randomUser", { id: "user1" });
156
+ fetch(this, "https://targetjs.io/api/randomUser?id=user0");
157
+ fetch(this, "https://targetjs.io/api/randomUser?id=user1");
141
158
  },
142
159
  _children$() {
143
160
  return {
@@ -292,17 +309,17 @@ App({
292
309
  width: {
293
310
  value: 250,
294
311
  steps: 30,
295
- stepInterval: 50
312
+ interval: 50
296
313
  },
297
314
  height: {
298
315
  value: 250,
299
316
  steps: 30,
300
- stepInterval: 50
317
+ interval: 50
301
318
  },
302
319
  opacity: {
303
320
  value: 0.15,
304
321
  steps: 30,
305
- stepInterval: 50
322
+ interval: 50
306
323
  }
307
324
  });
308
325
  ```
@@ -72,9 +72,12 @@ var LoadingManager = exports.LoadingManager = /*#__PURE__*/function () {
72
72
  key: "fetch",
73
73
  value: function fetch(tmodel, url, query, cacheId) {
74
74
  var _this = this;
75
- var fetchId = "".concat(tmodel.oid, "_").concat(url, "_").concat(JSON.stringify(query));
76
- this.fetchCommon(fetchId, cacheId, tmodel, this.fetchingAPIMap, function () {
77
- _this.ajaxAPI(url, query, _this.fetchingAPIMap[fetchId]);
75
+ var urls = Array.isArray(url) ? url : [url];
76
+ urls.forEach(function (singleUrl) {
77
+ var fetchId = "".concat(tmodel.oid, "_").concat(singleUrl, "_").concat(JSON.stringify(query));
78
+ _this.fetchCommon(fetchId, cacheId, tmodel, _this.fetchingAPIMap, function () {
79
+ _this.ajaxAPI(singleUrl, query, _this.fetchingAPIMap[fetchId]);
80
+ });
78
81
  });
79
82
  }
80
83
  }, {
@@ -134,7 +137,10 @@ var LoadingManager = exports.LoadingManager = /*#__PURE__*/function () {
134
137
  key: "isLoading",
135
138
  value: function isLoading(tmodel, targetName) {
136
139
  var key = this.getTModelKey(tmodel, targetName);
137
- return this.tmodelKeyMap[key];
140
+ var tmodelEntry = this.tmodelKeyMap[key];
141
+ if (tmodelEntry && tmodelEntry.accessIndex < tmodelEntry.resultCount) {
142
+ return true;
143
+ }
138
144
  }
139
145
  }, {
140
146
  key: "isLoadingSuccessful",
@@ -131,14 +131,16 @@ var RunScheduler = exports.RunScheduler = /*#__PURE__*/function () {
131
131
  this.schedule(1, "rerun-".concat(this.rerunId));
132
132
  } else {
133
133
  var newDelay = this.nextRuns.length > 0 ? this.nextRuns[0].delay - (_TUtil.TUtil.now() - this.nextRuns[0].insertTime) : undefined;
134
- if (newDelay === undefined) {
134
+ if (newDelay === undefined || (0, _App.getManager)().lists.activeTModels.length > 0) {
135
135
  if ((0, _App.getEvents)().eventQueue.length > 0) {
136
136
  this.schedule(15, "events-".concat((0, _App.getEvents)().eventQueue.length));
137
137
  } else if ((0, _App.getManager)().lists.updatingTModels.length > 0) {
138
138
  this.schedule(15, "getManager-needsRerun-updatingTModels");
139
139
  } else if ((0, _App.getManager)().lists.activeTModels.length > 0) {
140
140
  var activeTModel = (0, _App.getManager)().lists.activeTModels.find(function (tmodel) {
141
- return tmodel.targetExecutionCount === 0 || tmodel.activeTargetList.some(function (target) {
141
+ return tmodel.targetExecutionCount === 0 || tmodel.activeTargetList.filter(function (target) {
142
+ return !tmodel.isScheduledPending(target);
143
+ }).some(function (target) {
142
144
  return tmodel.shouldScheduleRun(target);
143
145
  });
144
146
  });
package/build/TModel.js CHANGED
@@ -348,6 +348,19 @@ var TModel = exports.TModel = /*#__PURE__*/function (_BaseModel) {
348
348
  var parent = _SearchUtil.SearchUtil.findParentByTarget(this, targetName);
349
349
  return parent ? parent.val(targetName) : undefined;
350
350
  }
351
+ }, {
352
+ key: "getParentValueAtMyIndex",
353
+ value: function getParentValueAtMyIndex(targetName) {
354
+ var parentValue = this.getParentValue(targetName);
355
+ if (Array.isArray(parentValue)) {
356
+ var _this$getParent;
357
+ var index = (_this$getParent = this.getParent()) === null || _this$getParent === void 0 ? void 0 : _this$getParent.getChildIndex(this);
358
+ if (typeof index === 'number') {
359
+ return parentValue[index];
360
+ }
361
+ }
362
+ return parentValue;
363
+ }
351
364
  }, {
352
365
  key: "delVal",
353
366
  value: function delVal(key) {
package/build/TUtil.js CHANGED
@@ -7,11 +7,11 @@ exports.TUtil = void 0;
7
7
  var _$Dom = require("./$Dom.js");
8
8
  var _App = require("./App.js");
9
9
  var _TargetData = require("./TargetData.js");
10
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
10
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
12
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."); }
13
12
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
14
13
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
14
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
15
15
  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; }
16
16
  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; }
17
17
  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; }
@@ -108,11 +108,11 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
108
108
  });
109
109
  var attributeSet = {};
110
110
  if (isTargetElement) {
111
- var _iterator3 = _createForOfIteratorHelper(attrs),
112
- _step3;
111
+ var _iterator4 = _createForOfIteratorHelper(attrs),
112
+ _step4;
113
113
  try {
114
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
115
- var attr = _step3.value;
114
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
115
+ var attr = _step4.value;
116
116
  if (attr.name.startsWith("tg-")) {
117
117
  var rawKey = attr.name.slice(3);
118
118
  var key = _TargetData.TargetData.attributesToTargets[rawKey] || rawKey;
@@ -122,9 +122,9 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
122
122
  }
123
123
  }
124
124
  } catch (err) {
125
- _iterator3.e(err);
125
+ _iterator4.e(err);
126
126
  } finally {
127
- _iterator3.f();
127
+ _iterator4.f();
128
128
  }
129
129
  }
130
130
  var parentEl = element.parentElement;
@@ -152,32 +152,26 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
152
152
  $dom: new _$Dom.$Dom(element)
153
153
  };
154
154
  }
155
- newModel.shouldBeBracketed = false;
156
- newModel.otype = newModel.id || (parentModel.id || _App.App.getOid('blank').oid) + "_";
157
- newModel.$dom.detach();
158
- delete newModel.$dom;
159
- delete newModel.id;
160
- newModel.isVisible = function () {
161
- return this.getParent().isVisible();
162
- };
163
- newModel.domParent = function () {
164
- return this.getParent();
165
- };
166
- if (parentModel.children) {
167
- if (Array.isArray(parentModel.children.value)) {
168
- parentModel.children.value.push(newModel);
169
- } else {
170
- parentModel.children.value = [newModel];
155
+ var childrenKey = TUtil.getChildrenKey(parentModel);
156
+ if (childrenKey) {
157
+ if (Array.isArray(parentModel[childrenKey].value)) {
158
+ parentModel[childrenKey].value.push(newModel);
159
+ } else if (typeof parentModel[childrenKey] === 'string') {
160
+ parentModel[childrenKey] = {
161
+ cycles: TUtil.isNumber(+parentModel[childrenKey]) ? +parentModel[childrenKey] : 0,
162
+ value: [newModel]
163
+ };
164
+ } else if (_typeof(parentModel[childrenKey]) === 'object') {
165
+ parentModel[childrenKey].value = [newModel];
171
166
  }
172
167
  } else {
173
- parentModel.children = {
168
+ parentModel._children$ = {
169
+ cycles: 0,
174
170
  value: [newModel]
175
171
  };
176
172
  }
177
173
  elementToModel.set(element, newModel);
178
174
  } else if (newModel) {
179
- newModel.isVisible = true;
180
- (0, _App.tRoot)().addChild(newModel);
181
175
  elementToModel.set(element, newModel);
182
176
  }
183
177
  }
@@ -186,18 +180,58 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
186
180
  } finally {
187
181
  _iterator2.f();
188
182
  }
183
+ var _iterator3 = _createForOfIteratorHelper(elementToModel.values()),
184
+ _step3;
185
+ try {
186
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
187
+ var _value = _step3.value;
188
+ var _parentEl = _value.$dom.element.parentElement;
189
+ var _parentModel = elementToModel.get(_parentEl);
190
+ if (_parentModel) {
191
+ _value.$dom.detach();
192
+ delete _value.$dom;
193
+ delete _value.id;
194
+ _value.shouldBeBracketed = false;
195
+ _value.otype = _value.id || (_parentModel.id || _App.App.getOid('blank').oid) + "_";
196
+ _value.isVisible = function () {
197
+ return this.getParent().isVisible();
198
+ };
199
+ _value.domParent = function () {
200
+ return this.getParent();
201
+ };
202
+ } else {
203
+ _value.isVisible = true;
204
+ (0, _App.tRoot)().addChild(_value);
205
+ }
206
+ }
207
+ } catch (err) {
208
+ _iterator3.e(err);
209
+ } finally {
210
+ _iterator3.f();
211
+ }
212
+ }
213
+ }, {
214
+ key: "getChildrenKey",
215
+ value: function getChildrenKey(obj) {
216
+ for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
217
+ var key = _Object$keys[_i];
218
+ if (key.toLowerCase().includes("children")) {
219
+ return key;
220
+ }
221
+ }
222
+ return null;
189
223
  }
190
224
  }, {
191
225
  key: "parseString",
192
226
  value: function parseString(rawValue) {
193
- try {
194
- return eval("(".concat(rawValue, ")"));
195
- } catch (_unused) {}
196
- if (typeof rawValue === 'string' && (rawValue.includes('return') || rawValue.includes('setTarget'))) {
227
+ if (typeof rawValue === 'string' && (rawValue.includes('return') || rawValue.includes('setTarget') || rawValue.includes('TargetJS.'))) {
197
228
  try {
198
229
  return new Function(rawValue);
199
- } catch (_unused2) {}
230
+ } catch (_unused) {}
200
231
  }
232
+ try {
233
+ return eval("(".concat(rawValue, ")"));
234
+ } catch (_unused2) {}
201
235
  try {
202
236
  return JSON.parse(rawValue);
203
237
  } catch (_unused3) {}
@@ -339,11 +373,11 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
339
373
  var tmodel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _App.tRoot)();
340
374
  var tab = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
341
375
  var list = (0, _App.getLocationManager)().getChildren(tmodel);
342
- var _iterator4 = _createForOfIteratorHelper(list),
343
- _step4;
376
+ var _iterator5 = _createForOfIteratorHelper(list),
377
+ _step5;
344
378
  try {
345
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
346
- var g = _step4.value;
379
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
380
+ var g = _step5.value;
347
381
  var gtab = g.isVisible() ? tab + '| ' : tab + 'x ';
348
382
  if (g.type === 'BI') {
349
383
  console.log("".concat(gtab).concat(g.oid, " v:").concat(g.isVisible(), " x:").concat(Math.floor(g.getX()), " y:").concat(Math.floor(g.getY()), ", absY:").concat(Math.floor(g.absY), " yy:").concat(Math.floor(g.absY + g.getDomParent().absY), " w:").concat(Math.floor(g.getWidth()), " h:").concat(Math.floor(g.getHeight()), " hc:").concat(Math.floor(g.getContentHeight())));
@@ -355,9 +389,9 @@ var TUtil = exports.TUtil = /*#__PURE__*/function () {
355
389
  }
356
390
  }
357
391
  } catch (err) {
358
- _iterator4.e(err);
392
+ _iterator5.e(err);
359
393
  } finally {
360
- _iterator4.f();
394
+ _iterator5.f();
361
395
  }
362
396
  }
363
397
  }]);
@@ -197,12 +197,12 @@ var TargetUtil = exports.TargetUtil = /*#__PURE__*/function () {
197
197
  }
198
198
  }, {
199
199
  key: "activateNextTarget",
200
- value: function activateNextTarget(tmodel, _activateNextTarget) {
201
- if (tmodel.targetValues[_activateNextTarget]) {
202
- tmodel.targetValues[_activateNextTarget].isImperative = false;
200
+ value: function activateNextTarget(tmodel, target) {
201
+ if (tmodel.targetValues[target]) {
202
+ tmodel.targetValues[target].isImperative = false;
203
203
  }
204
- if (!tmodel.activeTargetMap[_activateNextTarget]) {
205
- tmodel.activate(_activateNextTarget);
204
+ if (!tmodel.activeTargetMap[target]) {
205
+ tmodel.activate(target);
206
206
  }
207
207
  }
208
208
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "targetj",
3
- "version": "1.0.159",
3
+ "version": "1.0.166",
4
4
  "description": "TargetJS is a JavaScript framework designed for creating animated and efficient web user interfaces.",
5
5
  "keywords": ["targetjs"],
6
6
  "main": "Export.js",
@@ -24,7 +24,7 @@
24
24
  "build": "babel src --out-dir build"
25
25
  },
26
26
  "files": [
27
- "Export.js",
27
+ "Export.js",
28
28
  "build/",
29
29
  "README.md",
30
30
  "LICENSE"