targetj 1.0.221 → 1.0.223
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 +35 -1
- package/build/App.js +51 -37
- package/build/DomInit.js +9 -0
- package/build/TModel.js +9 -0
- package/build/TModelManager.js +3 -0
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,8 +177,9 @@ Each target has its own state and lifecycle. Targets execute automatically in th
|
|
|
177
177
|
## Table of Contents
|
|
178
178
|
|
|
179
179
|
1. [📦 Alternative Installation Via CDN](#-alternative-installation-via-cdn)
|
|
180
|
+
1. [Using TargetJS as a Library](#using-targetjs-as-a-library)
|
|
180
181
|
1. [🚀 Why TargetJS?](#-why-targetjs)
|
|
181
|
-
1.
|
|
182
|
+
1. Deeper Examples:
|
|
182
183
|
- [Loading Five Users Example](#loading-five-users-example)
|
|
183
184
|
- [Infinite Loading and Scrolling Example](#infinite-loading-and-scrolling-example)
|
|
184
185
|
1. [Target Methods](#target-methods)
|
|
@@ -225,6 +226,39 @@ TargetJS can also be used as a "no-code" library. Elements with tg- attributes a
|
|
|
225
226
|
</div>
|
|
226
227
|
```
|
|
227
228
|
|
|
229
|
+
## Using TargetJS as a Library
|
|
230
|
+
|
|
231
|
+
TargetJS can run inside an existing app mounted into a DOM element managed by another framework.
|
|
232
|
+
|
|
233
|
+
### React (mount + cleanup)
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
import React, { useLayoutEffect, useRef } from "react";
|
|
237
|
+
import { App as TJApp } from "targetj";
|
|
238
|
+
|
|
239
|
+
export default function TargetIsland() {
|
|
240
|
+
const hostRef = useRef(null);
|
|
241
|
+
|
|
242
|
+
useLayoutEffect(() => {
|
|
243
|
+
const el = hostRef.current;
|
|
244
|
+
if (!el) return;
|
|
245
|
+
|
|
246
|
+
TJApp({
|
|
247
|
+
width: { value: [100, 500], steps: 100 },
|
|
248
|
+
height: 200,
|
|
249
|
+
backgroundColor: "purple",
|
|
250
|
+
onClick() { console.log("click"); }
|
|
251
|
+
}).mount(el);
|
|
252
|
+
|
|
253
|
+
return () => {
|
|
254
|
+
TJApp.unmount();
|
|
255
|
+
};
|
|
256
|
+
}, []);
|
|
257
|
+
|
|
258
|
+
return <div ref={hostRef} style={{ width: 100, height: 200, overflow: "hidden" }} />;
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
228
262
|
## 🚀 Why TargetJS?
|
|
229
263
|
|
|
230
264
|
1. Zero Boilerplate Async: The $$ postfix handles the "wait" for you.
|
package/build/App.js
CHANGED
|
@@ -192,17 +192,29 @@ var AppFn = function AppFn() {
|
|
|
192
192
|
};
|
|
193
193
|
return my;
|
|
194
194
|
};
|
|
195
|
-
var
|
|
195
|
+
var ensureRunning = function ensureRunning() {
|
|
196
196
|
var _tApp;
|
|
197
|
+
if ((_tApp = tApp) !== null && _tApp !== void 0 && _tApp.tRoot || document.readyState === "loading") {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
runApp();
|
|
201
|
+
};
|
|
202
|
+
var App = exports.App = function App(firstChild) {
|
|
203
|
+
var _tApp2;
|
|
197
204
|
if (!firstChild) {
|
|
198
205
|
return;
|
|
199
206
|
}
|
|
200
|
-
var tmodel = firstChild instanceof _TModel.TModel ? firstChild : new _TModel.TModel(
|
|
201
|
-
if (!((
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
var tmodel = firstChild instanceof _TModel.TModel ? firstChild : new _TModel.TModel("App", firstChild);
|
|
208
|
+
if (!((_tApp2 = tApp) !== null && _tApp2 !== void 0 && _tApp2.tRoot)) {
|
|
209
|
+
if (document.readyState === "loading") {
|
|
210
|
+
queuedAppCalls.push(tmodel);
|
|
211
|
+
return tmodel;
|
|
212
|
+
}
|
|
213
|
+
ensureRunning();
|
|
204
214
|
tApp.tRoot.addChild(tmodel);
|
|
215
|
+
return tmodel;
|
|
205
216
|
}
|
|
217
|
+
tApp.tRoot.addChild(tmodel);
|
|
206
218
|
return tmodel;
|
|
207
219
|
};
|
|
208
220
|
App.unmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
@@ -242,9 +254,8 @@ App.unmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime()
|
|
|
242
254
|
case 14:
|
|
243
255
|
App.oids = {};
|
|
244
256
|
App.tmodelIdMap = {};
|
|
245
|
-
queuedAppCalls.length = 0;
|
|
246
257
|
exports.tApp = tApp = undefined;
|
|
247
|
-
case
|
|
258
|
+
case 17:
|
|
248
259
|
case "end":
|
|
249
260
|
return _context4.stop();
|
|
250
261
|
}
|
|
@@ -267,64 +278,64 @@ var isRunning = exports.isRunning = function isRunning() {
|
|
|
267
278
|
return tApp ? tApp.runningFlag : false;
|
|
268
279
|
};
|
|
269
280
|
var tRoot = exports.tRoot = function tRoot() {
|
|
270
|
-
var
|
|
271
|
-
return (
|
|
281
|
+
var _tApp3;
|
|
282
|
+
return (_tApp3 = tApp) === null || _tApp3 === void 0 ? void 0 : _tApp3.tRoot;
|
|
272
283
|
};
|
|
273
284
|
var getEvents = exports.getEvents = function getEvents() {
|
|
274
|
-
var
|
|
275
|
-
return (
|
|
285
|
+
var _tApp4;
|
|
286
|
+
return (_tApp4 = tApp) === null || _tApp4 === void 0 ? void 0 : _tApp4.events;
|
|
276
287
|
};
|
|
277
288
|
var getPager = exports.getPager = function getPager() {
|
|
278
|
-
var
|
|
279
|
-
return (
|
|
289
|
+
var _tApp5;
|
|
290
|
+
return (_tApp5 = tApp) === null || _tApp5 === void 0 ? void 0 : _tApp5.pager;
|
|
280
291
|
};
|
|
281
292
|
var getLoader = exports.getLoader = function getLoader() {
|
|
282
|
-
var
|
|
283
|
-
return (
|
|
293
|
+
var _tApp6;
|
|
294
|
+
return (_tApp6 = tApp) === null || _tApp6 === void 0 ? void 0 : _tApp6.loader;
|
|
284
295
|
};
|
|
285
296
|
var fetch = exports.fetch = function fetch(tmodel, url, query, cacheId) {
|
|
286
|
-
var
|
|
287
|
-
return (
|
|
297
|
+
var _tApp7;
|
|
298
|
+
return (_tApp7 = tApp) === null || _tApp7 === void 0 || (_tApp7 = _tApp7.loader) === null || _tApp7 === void 0 ? void 0 : _tApp7.fetch(tmodel, url, query, cacheId);
|
|
288
299
|
};
|
|
289
300
|
var fetchImage = exports.fetchImage = function fetchImage(tmodel, src, cacheId) {
|
|
290
|
-
var
|
|
291
|
-
return (
|
|
301
|
+
var _tApp8;
|
|
302
|
+
return (_tApp8 = tApp) === null || _tApp8 === void 0 || (_tApp8 = _tApp8.loader) === null || _tApp8 === void 0 ? void 0 : _tApp8.fetchImage(tmodel, src, cacheId);
|
|
292
303
|
};
|
|
293
304
|
var getManager = exports.getManager = function getManager() {
|
|
294
|
-
var
|
|
295
|
-
return (
|
|
305
|
+
var _tApp9;
|
|
306
|
+
return (_tApp9 = tApp) === null || _tApp9 === void 0 ? void 0 : _tApp9.manager;
|
|
296
307
|
};
|
|
297
308
|
var getTargetManager = exports.getTargetManager = function getTargetManager() {
|
|
298
|
-
var
|
|
299
|
-
return (
|
|
309
|
+
var _tApp10;
|
|
310
|
+
return (_tApp10 = tApp) === null || _tApp10 === void 0 ? void 0 : _tApp10.targetManager;
|
|
300
311
|
};
|
|
301
312
|
var getAnimationManager = exports.getAnimationManager = function getAnimationManager() {
|
|
302
|
-
var
|
|
303
|
-
return (
|
|
313
|
+
var _tApp11;
|
|
314
|
+
return (_tApp11 = tApp) === null || _tApp11 === void 0 ? void 0 : _tApp11.animationManager;
|
|
304
315
|
};
|
|
305
316
|
var getRunScheduler = exports.getRunScheduler = function getRunScheduler() {
|
|
306
|
-
var
|
|
307
|
-
return (
|
|
317
|
+
var _tApp12;
|
|
318
|
+
return (_tApp12 = tApp) === null || _tApp12 === void 0 ? void 0 : _tApp12.runScheduler;
|
|
308
319
|
};
|
|
309
320
|
var getLocationManager = exports.getLocationManager = function getLocationManager() {
|
|
310
|
-
var
|
|
311
|
-
return (
|
|
321
|
+
var _tApp13;
|
|
322
|
+
return (_tApp13 = tApp) === null || _tApp13 === void 0 ? void 0 : _tApp13.locationManager;
|
|
312
323
|
};
|
|
313
324
|
var getScreenWidth = exports.getScreenWidth = function getScreenWidth() {
|
|
314
|
-
var _tApp$tRoot$val,
|
|
315
|
-
return (_tApp$tRoot$val = (
|
|
325
|
+
var _tApp$tRoot$val, _tApp14;
|
|
326
|
+
return (_tApp$tRoot$val = (_tApp14 = tApp) === null || _tApp14 === void 0 || (_tApp14 = _tApp14.tRoot) === null || _tApp14 === void 0 ? void 0 : _tApp14.val('screenWidth')) !== null && _tApp$tRoot$val !== void 0 ? _tApp$tRoot$val : 0;
|
|
316
327
|
};
|
|
317
328
|
var getScreenHeight = exports.getScreenHeight = function getScreenHeight() {
|
|
318
|
-
var _tApp$tRoot$val2,
|
|
319
|
-
return (_tApp$tRoot$val2 = (
|
|
329
|
+
var _tApp$tRoot$val2, _tApp15;
|
|
330
|
+
return (_tApp$tRoot$val2 = (_tApp15 = tApp) === null || _tApp15 === void 0 || (_tApp15 = _tApp15.tRoot) === null || _tApp15 === void 0 ? void 0 : _tApp15.val('screenHeight')) !== null && _tApp$tRoot$val2 !== void 0 ? _tApp$tRoot$val2 : 0;
|
|
320
331
|
};
|
|
321
332
|
var getVisibles = exports.getVisibles = function getVisibles() {
|
|
322
|
-
var
|
|
323
|
-
return (
|
|
333
|
+
var _tApp16;
|
|
334
|
+
return (_tApp16 = tApp) === null || _tApp16 === void 0 || (_tApp16 = _tApp16.manager) === null || _tApp16 === void 0 ? void 0 : _tApp16.getVisibles();
|
|
324
335
|
};
|
|
325
336
|
var getResizeLastUpdate = exports.getResizeLastUpdate = function getResizeLastUpdate() {
|
|
326
|
-
var
|
|
327
|
-
return (
|
|
337
|
+
var _tApp17;
|
|
338
|
+
return (_tApp17 = tApp) === null || _tApp17 === void 0 ? void 0 : _tApp17.resizeLastUpdate;
|
|
328
339
|
};
|
|
329
340
|
var getTModelById = exports.getTModelById = function getTModelById(id) {
|
|
330
341
|
return App.tmodelIdMap[id];
|
|
@@ -335,6 +346,9 @@ var getDomTModelById = exports.getDomTModelById = function getDomTModelById(id)
|
|
|
335
346
|
};
|
|
336
347
|
window.t = window.t || getTModelById;
|
|
337
348
|
var runApp = function runApp() {
|
|
349
|
+
if (tApp) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
338
352
|
exports.tApp = tApp = AppFn();
|
|
339
353
|
tApp.init().start();
|
|
340
354
|
};
|
package/build/DomInit.js
CHANGED
|
@@ -75,6 +75,14 @@ var DomInit = exports.DomInit = /*#__PURE__*/function () {
|
|
|
75
75
|
if (elemTarget !== undefined) {
|
|
76
76
|
var $dom = DomInit.normalizeElementTarget(elemTarget);
|
|
77
77
|
if ($dom) {
|
|
78
|
+
var _tmodel$$dom;
|
|
79
|
+
if ((_tmodel$$dom = tmodel.$dom) !== null && _tmodel$$dom !== void 0 && _tmodel$$dom.exists()) {
|
|
80
|
+
if (tmodel.domState) {
|
|
81
|
+
DomInit.restoreDomState(tmodel.$dom.element, tmodel.domState);
|
|
82
|
+
} else {
|
|
83
|
+
tmodel.$dom.detach();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
78
86
|
tmodel.domState = DomInit.snapshotDomState($dom.element);
|
|
79
87
|
tmodel.targets.$dom = $dom;
|
|
80
88
|
tmodel.val('$dom', $dom);
|
|
@@ -110,6 +118,7 @@ var DomInit = exports.DomInit = /*#__PURE__*/function () {
|
|
|
110
118
|
}
|
|
111
119
|
$dom.attr('tgjs-oid', tmodel.oid);
|
|
112
120
|
$dom.attr('tgjs', 'true');
|
|
121
|
+
tmodel.$dom = undefined;
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
}
|
package/build/TModel.js
CHANGED
|
@@ -649,6 +649,15 @@ var TModel = exports.TModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
649
649
|
_DomInit.DomInit.mount(this, elemTarget);
|
|
650
650
|
return this;
|
|
651
651
|
}
|
|
652
|
+
}, {
|
|
653
|
+
key: "unmount",
|
|
654
|
+
value: function unmount() {
|
|
655
|
+
var _this$parent2;
|
|
656
|
+
if (this.hasDom() && this.val('sourceDom') && this.domState) {
|
|
657
|
+
_DomInit.DomInit.restoreDomState(this.$dom.element, this.domState);
|
|
658
|
+
}
|
|
659
|
+
(_this$parent2 = this.parent) === null || _this$parent2 === void 0 || _this$parent2.removeChild(this);
|
|
660
|
+
}
|
|
652
661
|
}, {
|
|
653
662
|
key: "hasDom",
|
|
654
663
|
value: function hasDom() {
|
package/build/TModelManager.js
CHANGED
|
@@ -350,6 +350,9 @@ var TModelManager = exports.TModelManager = /*#__PURE__*/function () {
|
|
|
350
350
|
try {
|
|
351
351
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
352
352
|
var tmodel = _step5.value;
|
|
353
|
+
if (tmodel.val('sourceDom')) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
353
356
|
this.deleteDom(tmodel);
|
|
354
357
|
}
|
|
355
358
|
} catch (err) {
|