sdc_client 0.58.6 → 0.158.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.
- package/.github/workflows/node.js.yml +2 -2
- package/.idea/inspectionProfiles/Project_Default.xml +17 -0
- package/.idea/workspace.xml +122 -23
- package/.readthedocs.yaml +13 -0
- package/dist/index.js +70 -51
- package/dist/ugly.index.js +1 -1
- package/docs/api-reference.rst +225 -0
- package/docs/conf.py +11 -0
- package/docs/controllers.rst +228 -0
- package/docs/events-and-dom.rst +120 -0
- package/docs/getting-started.rst +143 -0
- package/docs/index.rst +22 -0
- package/docs/models.rst +351 -0
- package/docs/overview.rst +66 -0
- package/docs/requirements.txt +1 -0
- package/eslint.config.js +60 -0
- package/gulp/gulp.jsx +15 -13
- package/package.json +13 -3
- package/src/index.js +44 -11
- package/src/simpleDomControl/AbstractSDC.js +287 -286
- package/src/simpleDomControl/sdc_controller.js +157 -132
- package/src/simpleDomControl/sdc_dom_events.js +99 -88
- package/src/simpleDomControl/sdc_events.js +39 -40
- package/src/simpleDomControl/sdc_main.js +88 -67
- package/src/simpleDomControl/sdc_model.js +1513 -0
- package/src/simpleDomControl/sdc_params.js +44 -29
- package/src/simpleDomControl/sdc_server_call.js +153 -154
- package/src/simpleDomControl/sdc_socket.js +8 -829
- package/src/simpleDomControl/sdc_test_utils.js +77 -80
- package/src/simpleDomControl/sdc_utils.js +295 -176
- package/src/simpleDomControl/sdc_view.js +245 -177
- package/test/model.test.js +332 -0
- package/test/models/Author.js +145 -0
- package/test/models/Book.js +112 -0
- package/test/models/BookContent.js +114 -0
- package/test/models/SdcUser.js +75 -0
- package/test/models/src.js +8 -0
- package/test/sdc_model_dates.ai.test.js +57 -0
- package/test/sdc_server_call.ai.test.js +267 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {promiseDummyFactory} from "./sdc_utils.js";
|
|
2
|
-
|
|
1
|
+
import { promiseDummyFactory } from "./sdc_utils.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* A list of handler (controller) for the registered events.
|
|
@@ -23,17 +22,17 @@ let eventList = {};
|
|
|
23
22
|
* @param {AbstractSDC} controller - a instance of a JavaScript controller object.
|
|
24
23
|
*/
|
|
25
24
|
export function on(name, controller) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
setEvent(name);
|
|
26
|
+
if (!eventList.hasOwnProperty(name)) {
|
|
27
|
+
return console.log("No event: " + name, controller);
|
|
28
|
+
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
let funcName = eventList[name];
|
|
31
|
+
if (!controller[funcName]) {
|
|
32
|
+
return console.log("No event handler: " + name, controller);
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
handlerList[name].push(controller);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
@@ -44,14 +43,14 @@ export function on(name, controller) {
|
|
|
44
43
|
* @param {string} functionName - function name
|
|
45
44
|
*/
|
|
46
45
|
export function setEvent(name, functionName) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (!functionName) {
|
|
47
|
+
functionName = name;
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (!eventList[name]) {
|
|
51
|
+
eventList[name] = functionName;
|
|
52
|
+
handlerList[name] = [];
|
|
53
|
+
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
|
@@ -61,15 +60,15 @@ export function setEvent(name, functionName) {
|
|
|
61
60
|
* @param {AbstractSDC} controller - a instance of a JavaScript controller object.
|
|
62
61
|
*/
|
|
63
62
|
export function allOff(controller) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
63
|
+
for (let eventName in handlerList) {
|
|
64
|
+
if (handlerList.hasOwnProperty(eventName)) {
|
|
65
|
+
for (let i = handlerList[eventName].length - 1; i >= 0; i--) {
|
|
66
|
+
if (controller === handlerList[eventName][i]) {
|
|
67
|
+
handlerList[eventName].splice(i, 1);
|
|
71
68
|
}
|
|
69
|
+
}
|
|
72
70
|
}
|
|
71
|
+
}
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
/**
|
|
@@ -81,22 +80,22 @@ export function allOff(controller) {
|
|
|
81
80
|
* @returns {Promise<object>} - waits to return all return values of the handler
|
|
82
81
|
*/
|
|
83
82
|
export function trigger(name) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
let args = Array.apply(null, arguments);
|
|
84
|
+
name = args.shift();
|
|
85
|
+
if (!handlerList.hasOwnProperty(name) || !eventList.hasOwnProperty(name)) {
|
|
86
|
+
return promiseDummyFactory();
|
|
87
|
+
}
|
|
88
|
+
let handler = handlerList[name];
|
|
89
|
+
let funcName = eventList[name];
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
let list = [];
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
93
|
+
for (let i = 0; i < handler.length; i++) {
|
|
94
|
+
let return_val = handler[i][funcName].apply(handler[i], args);
|
|
95
|
+
if (typeof return_val !== "undefined") {
|
|
96
|
+
list.push(return_val);
|
|
99
97
|
}
|
|
98
|
+
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
}
|
|
100
|
+
return Promise.all(list);
|
|
101
|
+
}
|
|
@@ -7,39 +7,46 @@ import {
|
|
|
7
7
|
replaceTagElementsInContainer,
|
|
8
8
|
reloadHTMLController,
|
|
9
9
|
DATA_CONTROLLER_KEY,
|
|
10
|
-
CONTROLLER_CLASS,
|
|
10
|
+
CONTROLLER_CLASS,
|
|
11
|
+
getController,
|
|
12
|
+
cleanCache,
|
|
13
|
+
refresh,
|
|
11
14
|
} from "./sdc_view.js";
|
|
12
|
-
import {AbstractSDC} from "./AbstractSDC.js";
|
|
15
|
+
import { AbstractSDC } from "./AbstractSDC.js";
|
|
13
16
|
import {
|
|
14
17
|
Global,
|
|
15
18
|
controllerList,
|
|
16
19
|
tagList,
|
|
17
20
|
resetChildren,
|
|
18
21
|
updateEventAndTriggerOnRefresh,
|
|
19
|
-
prepareRefreshProcess
|
|
22
|
+
prepareRefreshProcess,
|
|
20
23
|
} from "./sdc_controller.js";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
import {
|
|
25
|
+
initEvents,
|
|
26
|
+
STD_EVENT_LIST,
|
|
27
|
+
windowEventHandler,
|
|
28
|
+
} from "./sdc_dom_events.js";
|
|
29
|
+
import { reconcile } from "./sdc_view.js";
|
|
30
|
+
import { trigger } from "./sdc_events.js";
|
|
31
|
+
import { isConnected, close } from "./sdc_server_call.js";
|
|
25
32
|
|
|
26
|
-
const PROPERTIES_UPDATE = {
|
|
33
|
+
const PROPERTIES_UPDATE = { classname: "class" };
|
|
27
34
|
|
|
28
35
|
let sdcDomFragment = function (element, props) {
|
|
29
|
-
let $new_elem,
|
|
30
|
-
|
|
36
|
+
let $new_elem,
|
|
37
|
+
is_self = false;
|
|
38
|
+
if (typeof element === "string") {
|
|
31
39
|
$new_elem = $(document.createElement(element));
|
|
32
40
|
} else {
|
|
33
41
|
const tagName = `this.${element.name}`;
|
|
34
42
|
$new_elem = $(document.createElement(tagName));
|
|
35
|
-
$new_elem.data(
|
|
36
|
-
is_self = true
|
|
43
|
+
$new_elem.data("handler", element);
|
|
44
|
+
is_self = true;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
|
|
40
47
|
if (props) {
|
|
41
48
|
Object.entries(props).forEach(([k, v]) => {
|
|
42
|
-
if (k.startsWith(
|
|
49
|
+
if (k.startsWith("on")) {
|
|
43
50
|
$new_elem[0].addEventListener(k.substring(2).toLowerCase(), v);
|
|
44
51
|
} else {
|
|
45
52
|
if (PROPERTIES_UPDATE[k.toLowerCase()]) {
|
|
@@ -51,29 +58,28 @@ let sdcDomFragment = function (element, props) {
|
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
if (is_self) {
|
|
54
|
-
$new_elem.addClass(
|
|
61
|
+
$new_elem.addClass("_bind_to_update_handler _with_handler");
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
return $new_elem;
|
|
58
|
-
}
|
|
65
|
+
};
|
|
59
66
|
|
|
60
67
|
window.sdcDom = function (tagName, props, ...children) {
|
|
61
68
|
if (!tagName) {
|
|
62
|
-
return
|
|
69
|
+
return "";
|
|
63
70
|
}
|
|
64
71
|
const $new_elem = sdcDomFragment(tagName, props);
|
|
65
72
|
for (const c of children) {
|
|
66
73
|
$new_elem.append(c);
|
|
67
74
|
}
|
|
68
75
|
return $new_elem;
|
|
69
|
-
|
|
70
|
-
}
|
|
76
|
+
};
|
|
71
77
|
|
|
72
78
|
export let app = {
|
|
73
|
-
CSRF_TOKEN: window.CSRF_TOKEN ||
|
|
74
|
-
LANGUAGE_CODE: window.LANGUAGE_CODE ||
|
|
79
|
+
CSRF_TOKEN: window.CSRF_TOKEN || "",
|
|
80
|
+
LANGUAGE_CODE: window.LANGUAGE_CODE || "en",
|
|
75
81
|
DEBUG: window.DEBUG || false,
|
|
76
|
-
VERSION: window.VERSION ||
|
|
82
|
+
VERSION: window.VERSION || "0.0",
|
|
77
83
|
tagNames: [],
|
|
78
84
|
Global: Global,
|
|
79
85
|
rootController: null,
|
|
@@ -88,13 +94,15 @@ export let app = {
|
|
|
88
94
|
if (!app._origin_trigger) {
|
|
89
95
|
app._origin_trigger = $.fn.trigger;
|
|
90
96
|
$.fn.trigger = function (event) {
|
|
91
|
-
const ev_type = {}.hasOwnProperty.call(event, "type")
|
|
97
|
+
const ev_type = {}.hasOwnProperty.call(event, "type")
|
|
98
|
+
? event.type
|
|
99
|
+
: event;
|
|
92
100
|
if (!STD_EVENT_LIST.includes(ev_type)) {
|
|
93
101
|
STD_EVENT_LIST.push(ev_type);
|
|
94
102
|
$(window).on(ev_type, windowEventHandler);
|
|
95
103
|
}
|
|
96
104
|
return app._origin_trigger.call(this, event);
|
|
97
|
-
}
|
|
105
|
+
};
|
|
98
106
|
|
|
99
107
|
app.updateJquery();
|
|
100
108
|
} else {
|
|
@@ -111,16 +119,28 @@ export let app = {
|
|
|
111
119
|
|
|
112
120
|
app.tagNames = tagList();
|
|
113
121
|
|
|
114
|
-
const $globalDiv = $(
|
|
122
|
+
const $globalDiv = $("<div></div>");
|
|
115
123
|
Global.forEach((tagName) => {
|
|
116
124
|
const ControllerClass = controllerList[tagName][0];
|
|
117
|
-
$globalDiv.append(
|
|
125
|
+
$globalDiv.append(
|
|
126
|
+
`<${ControllerClass.prototype._tagName}></${ControllerClass.prototype._tagName}>`,
|
|
127
|
+
);
|
|
118
128
|
});
|
|
119
129
|
|
|
120
|
-
const {refreshProcess} = prepareRefreshProcess(null, app.rootController);
|
|
121
|
-
|
|
122
|
-
return replaceTagElementsInContainer(
|
|
123
|
-
|
|
130
|
+
const { refreshProcess } = prepareRefreshProcess(null, app.rootController);
|
|
131
|
+
|
|
132
|
+
return replaceTagElementsInContainer(
|
|
133
|
+
app.tagNames,
|
|
134
|
+
$globalDiv,
|
|
135
|
+
app.globalRootController,
|
|
136
|
+
refreshProcess,
|
|
137
|
+
).then(() => {
|
|
138
|
+
return replaceTagElementsInContainer(
|
|
139
|
+
app.tagNames,
|
|
140
|
+
getBody(),
|
|
141
|
+
app.rootController,
|
|
142
|
+
refreshProcess,
|
|
143
|
+
).then((res) => {
|
|
124
144
|
updateEventAndTriggerOnRefresh(refreshProcess);
|
|
125
145
|
return res;
|
|
126
146
|
});
|
|
@@ -130,18 +150,18 @@ export let app = {
|
|
|
130
150
|
updateJquery: () => {
|
|
131
151
|
$.fn.safeReplace = function ($elem) {
|
|
132
152
|
return app.safeReplace($(this), $elem);
|
|
133
|
-
}
|
|
153
|
+
};
|
|
134
154
|
$.fn.safeEmpty = function () {
|
|
135
155
|
return app.safeEmpty($(this));
|
|
136
|
-
}
|
|
156
|
+
};
|
|
137
157
|
$.fn.safeRemove = function () {
|
|
138
158
|
return app.safeRemove($(this));
|
|
139
|
-
}
|
|
159
|
+
};
|
|
140
160
|
},
|
|
141
161
|
|
|
142
162
|
controllerToTag: (Controller) => {
|
|
143
163
|
let tagName = camelCaseToTagName(Controller.name);
|
|
144
|
-
return tagName.replace(/-controller$/,
|
|
164
|
+
return tagName.replace(/-controller$/, "");
|
|
145
165
|
},
|
|
146
166
|
|
|
147
167
|
/**
|
|
@@ -180,16 +200,16 @@ export let app = {
|
|
|
180
200
|
if (typeof mixin === "string") {
|
|
181
201
|
mixinName = camelCaseToTagName(mixin);
|
|
182
202
|
} else if (mixin) {
|
|
183
|
-
mixinName = app.controllerToTag(mixin)
|
|
203
|
+
mixinName = app.controllerToTag(mixin);
|
|
184
204
|
}
|
|
185
205
|
controllerList[tagName][1].push(mixinName);
|
|
186
206
|
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
207
|
+
},
|
|
208
|
+
};
|
|
189
209
|
}
|
|
190
210
|
return {
|
|
191
|
-
addMixin: (...mixins) => {}
|
|
192
|
-
}
|
|
211
|
+
addMixin: (...mixins) => {},
|
|
212
|
+
};
|
|
193
213
|
},
|
|
194
214
|
|
|
195
215
|
/**
|
|
@@ -205,7 +225,7 @@ export let app = {
|
|
|
205
225
|
}
|
|
206
226
|
|
|
207
227
|
args.CSRF_TOKEN = app.CSRF_TOKEN;
|
|
208
|
-
return app.ajax(controller, url,
|
|
228
|
+
return app.ajax(controller, url, args, $.post);
|
|
209
229
|
},
|
|
210
230
|
|
|
211
231
|
/**
|
|
@@ -233,19 +253,21 @@ export let app = {
|
|
|
233
253
|
}
|
|
234
254
|
|
|
235
255
|
args.VERSION = app.VERSION;
|
|
236
|
-
args._method = args._method ||
|
|
256
|
+
args._method = args._method || "api";
|
|
237
257
|
|
|
238
258
|
const p = new Promise((resolve, reject) => {
|
|
239
|
-
return method(url, args)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
259
|
+
return method(url, args)
|
|
260
|
+
.then((a, b, c) => {
|
|
261
|
+
resolve(a, b, c);
|
|
262
|
+
if (a.status === "redirect") {
|
|
263
|
+
trigger("onNavLink", a["url-link"]);
|
|
264
|
+
} else {
|
|
265
|
+
p.then(() => {
|
|
266
|
+
app.refresh(controller.$container);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
.catch(reject);
|
|
249
271
|
});
|
|
250
272
|
|
|
251
273
|
return p;
|
|
@@ -254,19 +276,18 @@ export let app = {
|
|
|
254
276
|
submitFormAndUpdateView: (controller, form, url, method) => {
|
|
255
277
|
let formData = new FormData(form);
|
|
256
278
|
const redirector = (a) => {
|
|
257
|
-
if (a[
|
|
258
|
-
trigger(
|
|
279
|
+
if (a["url-link"]) {
|
|
280
|
+
trigger("onNavLink", a["url-link"]);
|
|
259
281
|
} else {
|
|
260
|
-
window.location.href = a[
|
|
282
|
+
window.location.href = a["url"];
|
|
261
283
|
}
|
|
262
|
-
|
|
263
|
-
}
|
|
284
|
+
};
|
|
264
285
|
|
|
265
286
|
const p = new Promise((resolve, reject) => {
|
|
266
|
-
uploadFileFormData(formData,
|
|
287
|
+
uploadFileFormData(formData, url || form.action, method || form.method)
|
|
267
288
|
.then((a, b, c) => {
|
|
268
289
|
resolve(a, b, c);
|
|
269
|
-
if (a.status ===
|
|
290
|
+
if (a.status === "redirect") {
|
|
270
291
|
redirector(a);
|
|
271
292
|
} else {
|
|
272
293
|
p.then(() => {
|
|
@@ -286,14 +307,14 @@ export let app = {
|
|
|
286
307
|
});
|
|
287
308
|
|
|
288
309
|
return p;
|
|
289
|
-
|
|
290
310
|
},
|
|
291
311
|
|
|
292
312
|
submitForm: (form, url, method) => {
|
|
293
313
|
let formData = new FormData(form);
|
|
294
314
|
return new Promise((resolve, reject) => {
|
|
295
|
-
uploadFileFormData(formData,
|
|
296
|
-
.then(resolve)
|
|
315
|
+
uploadFileFormData(formData, url || form.action, method || form.method)
|
|
316
|
+
.then(resolve)
|
|
317
|
+
.catch(reject);
|
|
297
318
|
});
|
|
298
319
|
},
|
|
299
320
|
|
|
@@ -332,7 +353,6 @@ export let app = {
|
|
|
332
353
|
return app.safeRemove($elem);
|
|
333
354
|
},
|
|
334
355
|
|
|
335
|
-
|
|
336
356
|
/**
|
|
337
357
|
* safeRemove removes a dom and deletes all child controller safely.
|
|
338
358
|
*
|
|
@@ -366,7 +386,6 @@ export let app = {
|
|
|
366
386
|
});
|
|
367
387
|
},
|
|
368
388
|
|
|
369
|
-
|
|
370
389
|
/**
|
|
371
390
|
*
|
|
372
391
|
* @param {AbstractSDC} controller
|
|
@@ -385,7 +404,10 @@ export let app = {
|
|
|
385
404
|
|
|
386
405
|
$realNode = $realNode ?? controller.$container;
|
|
387
406
|
|
|
388
|
-
const {refreshProcess, isRunningProcess} = prepareRefreshProcess(
|
|
407
|
+
const { refreshProcess, isRunningProcess } = prepareRefreshProcess(
|
|
408
|
+
process,
|
|
409
|
+
controller,
|
|
410
|
+
);
|
|
389
411
|
|
|
390
412
|
return refresh($virtualNode, controller, refreshProcess).then(() => {
|
|
391
413
|
reconcile($virtualNode, $realNode);
|
|
@@ -395,7 +417,6 @@ export let app = {
|
|
|
395
417
|
}
|
|
396
418
|
return controller;
|
|
397
419
|
});
|
|
398
|
-
|
|
399
420
|
},
|
|
400
421
|
|
|
401
422
|
/**
|
|
@@ -404,7 +425,7 @@ export let app = {
|
|
|
404
425
|
* @param {AbstractSDC} leafController
|
|
405
426
|
* @return {Promise<void>}
|
|
406
427
|
*/
|
|
407
|
-
refresh: ($dom, leafController) => {
|
|
428
|
+
refresh: ($dom, leafController = null) => {
|
|
408
429
|
return refresh($dom, leafController);
|
|
409
430
|
},
|
|
410
|
-
};
|
|
431
|
+
};
|