sdc_client 0.58.6 → 0.158.0

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.
Files changed (39) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/.idea/inspectionProfiles/Project_Default.xml +17 -0
  3. package/.idea/workspace.xml +122 -23
  4. package/.readthedocs.yaml +13 -0
  5. package/dist/index.js +70 -51
  6. package/dist/ugly.index.js +1 -1
  7. package/docs/api-reference.rst +225 -0
  8. package/docs/conf.py +11 -0
  9. package/docs/controllers.rst +228 -0
  10. package/docs/events-and-dom.rst +120 -0
  11. package/docs/getting-started.rst +143 -0
  12. package/docs/index.rst +22 -0
  13. package/docs/models.rst +351 -0
  14. package/docs/overview.rst +66 -0
  15. package/docs/requirements.txt +1 -0
  16. package/eslint.config.js +60 -0
  17. package/gulp/gulp.jsx +15 -13
  18. package/package.json +13 -3
  19. package/src/index.js +44 -11
  20. package/src/simpleDomControl/AbstractSDC.js +287 -286
  21. package/src/simpleDomControl/sdc_controller.js +157 -132
  22. package/src/simpleDomControl/sdc_dom_events.js +99 -88
  23. package/src/simpleDomControl/sdc_events.js +39 -40
  24. package/src/simpleDomControl/sdc_main.js +88 -67
  25. package/src/simpleDomControl/sdc_model.js +1510 -0
  26. package/src/simpleDomControl/sdc_params.js +44 -29
  27. package/src/simpleDomControl/sdc_server_call.js +153 -154
  28. package/src/simpleDomControl/sdc_socket.js +8 -829
  29. package/src/simpleDomControl/sdc_test_utils.js +77 -80
  30. package/src/simpleDomControl/sdc_utils.js +295 -176
  31. package/src/simpleDomControl/sdc_view.js +245 -177
  32. package/test/model.test.js +332 -0
  33. package/test/models/Author.js +145 -0
  34. package/test/models/Book.js +112 -0
  35. package/test/models/BookContent.js +114 -0
  36. package/test/models/SdcUser.js +75 -0
  37. package/test/models/src.js +8 -0
  38. package/test/sdc_model_dates.ai.test.js +57 -0
  39. package/test/sdc_server_call.ai.test.js +267 -0
@@ -1,42 +1,45 @@
1
- import {promiseDummyFactory, tagNameToCamelCase, agileAggregation} from "./sdc_utils.js";
2
1
  import {
3
- CONTROLLER_CLASS,
4
- getController,
5
- loadFilesFromController,
6
- refresh,
7
- runControllerFillContent
2
+ promiseDummyFactory,
3
+ tagNameToCamelCase,
4
+ agileAggregation,
5
+ } from "./sdc_utils.js";
6
+ import {
7
+ CONTROLLER_CLASS,
8
+ getController,
9
+ loadFilesFromController,
10
+ refresh,
11
+ runControllerFillContent,
8
12
  } from "./sdc_view.js";
9
13
 
10
- import {runOnInitWithParameter} from "./sdc_params.js";
11
- import {setControllerEvents} from "./sdc_dom_events.js";
12
- import {app} from "./sdc_main.js";
14
+ import { runOnInitWithParameter } from "./sdc_params.js";
15
+ import { setControllerEvents } from "./sdc_dom_events.js";
16
+ import { app } from "./sdc_main.js";
13
17
 
14
18
  export let Global = [];
15
19
  export let controllerList = {};
16
20
 
17
21
  export function tagList() {
18
- return Object.keys(controllerList);
22
+ return Object.keys(controllerList);
19
23
  }
20
24
 
21
-
22
25
  function prepareMixins(superTagNameList, tagName) {
23
- superTagNameList = superTagNameList.concat(controllerList[tagName][1]);
24
- superTagNameList = superTagNameList.filter((value, index, self) => {
25
- return self.indexOf(value) === index;
26
- });
27
- let hasAdded = true;
28
- while (hasAdded) {
29
- hasAdded = false;
30
- for (let tag of superTagNameList) {
31
- for (let newTag of controllerList[tag][1]) {
32
- if (!superTagNameList.includes(newTag)) {
33
- superTagNameList.push(newTag);
34
- hasAdded = true;
35
- }
36
- }
26
+ superTagNameList = superTagNameList.concat(controllerList[tagName][1]);
27
+ superTagNameList = superTagNameList.filter((value, index, self) => {
28
+ return self.indexOf(value) === index;
29
+ });
30
+ let hasAdded = true;
31
+ while (hasAdded) {
32
+ hasAdded = false;
33
+ for (let tag of superTagNameList) {
34
+ for (let newTag of controllerList[tag][1]) {
35
+ if (!superTagNameList.includes(newTag)) {
36
+ superTagNameList.push(newTag);
37
+ hasAdded = true;
37
38
  }
39
+ }
38
40
  }
39
- return superTagNameList;
41
+ }
42
+ return superTagNameList;
40
43
  }
41
44
 
42
45
  /**
@@ -49,16 +52,16 @@ function prepareMixins(superTagNameList, tagName) {
49
52
  * @return {AbstractSDC} - parentController
50
53
  */
51
54
  function setParentController(parentController, controller) {
52
- if (parentController) {
53
- let controllerName = tagNameToCamelCase(controller._tagName);
54
- if (!parentController._childController[controllerName]) {
55
- parentController._childController[controllerName] = [];
56
- }
57
-
58
- parentController._childController[controllerName].push(controller);
55
+ if (parentController) {
56
+ let controllerName = tagNameToCamelCase(controller._tagName);
57
+ if (!parentController._childController[controllerName]) {
58
+ parentController._childController[controllerName] = [];
59
59
  }
60
60
 
61
- return (controller._parentController = parentController)
61
+ parentController._childController[controllerName].push(controller);
62
+ }
63
+
64
+ return (controller._parentController = parentController);
62
65
  }
63
66
 
64
67
  /**
@@ -67,14 +70,14 @@ function setParentController(parentController, controller) {
67
70
  * @param {AbstractSDC} parentController
68
71
  */
69
72
  export function resetChildren(parentController) {
70
- parentController._childController = {};
71
- parentController.find(`.${CONTROLLER_CLASS}`).each(function () {
72
- const $this = $(this);
73
- const cController = getController($this);
74
- if (cController === parentController) {
75
- setParentController(parentController, cController);
76
- }
77
- });
73
+ parentController._childController = {};
74
+ parentController.find(`.${CONTROLLER_CLASS}`).each(function () {
75
+ const $this = $(this);
76
+ const cController = getController($this);
77
+ if (cController === parentController) {
78
+ setParentController(parentController, cController);
79
+ }
80
+ });
78
81
  }
79
82
 
80
83
  /**
@@ -92,24 +95,30 @@ export function resetChildren(parentController) {
92
95
  * @param {Array<string>} superTagNameList - tag names of super controller
93
96
  * @return {AbstractSDC} - new Controller
94
97
  */
95
- function controllerFactoryInstance(parentController, $element, tagName, superTagNameList) {
96
-
97
- let mixinControllerClass = [];
98
- superTagNameList = prepareMixins(superTagNameList, tagName);
99
- for (let superTagName of superTagNameList) {
100
- mixinControllerClass.push(controllerList[superTagName][0]);
101
- }
102
-
103
- let controllerClass = controllerList[tagName][0];
104
- let controller = new (agileAggregation(controllerClass, ...mixinControllerClass))();
105
- controller._tagName = tagName;
106
-
107
- setParentController(parentController, controller);
108
- controller.$container = $element;
109
- runOnInitWithParameter($element, controller);
110
-
111
-
112
- return controller;
98
+ function controllerFactoryInstance(
99
+ parentController,
100
+ $element,
101
+ tagName,
102
+ superTagNameList,
103
+ ) {
104
+ let mixinControllerClass = [];
105
+ superTagNameList = prepareMixins(superTagNameList, tagName);
106
+ for (let superTagName of superTagNameList) {
107
+ mixinControllerClass.push(controllerList[superTagName][0]);
108
+ }
109
+
110
+ let controllerClass = controllerList[tagName][0];
111
+ let controller = new (agileAggregation(
112
+ controllerClass,
113
+ ...mixinControllerClass,
114
+ ))();
115
+ controller._tagName = tagName;
116
+
117
+ setParentController(parentController, controller);
118
+ controller.$container = $element;
119
+ runOnInitWithParameter($element, controller);
120
+
121
+ return controller;
113
122
  }
114
123
 
115
124
  /**
@@ -125,19 +134,33 @@ function controllerFactoryInstance(parentController, $element, tagName, superTag
125
134
  * @param {Array<string>} superTagNameList - tag names of super controller
126
135
  * @return {AbstractSDC} - new Controller
127
136
  */
128
- export function controllerFactory(parentController, $element, tagName, superTagNameList) {
129
-
130
- if (Global.includes(tagName)) {
131
- let gTagName = tagNameToCamelCase(tagName);
132
- if (!window[gTagName]) {
133
- window[gTagName] = controllerFactoryInstance(parentController, $element, tagName, superTagNameList);
134
- }
135
-
136
- window[gTagName].$container = $element;
137
- return window[gTagName];
137
+ export function controllerFactory(
138
+ parentController,
139
+ $element,
140
+ tagName,
141
+ superTagNameList,
142
+ ) {
143
+ if (Global.includes(tagName)) {
144
+ let gTagName = tagNameToCamelCase(tagName);
145
+ if (!window[gTagName]) {
146
+ window[gTagName] = controllerFactoryInstance(
147
+ parentController,
148
+ $element,
149
+ tagName,
150
+ superTagNameList,
151
+ );
138
152
  }
139
153
 
140
- return controllerFactoryInstance(parentController, $element, tagName, superTagNameList);
154
+ window[gTagName].$container = $element;
155
+ return window[gTagName];
156
+ }
157
+
158
+ return controllerFactoryInstance(
159
+ parentController,
160
+ $element,
161
+ tagName,
162
+ superTagNameList,
163
+ );
141
164
  }
142
165
 
143
166
  /**
@@ -150,22 +173,21 @@ export function controllerFactory(parentController, $element, tagName, superTagN
150
173
  * @return {Promise<*>} - return of the onLoad function
151
174
  */
152
175
  function runControllerShow(controller, $html) {
153
- return runControllerFillContent(controller, $html).then(function (args) {
154
- args = args || true;
155
- if (controller.willShow) {
156
- let loadPromiseOrContent = controller.willShow();
157
- if (loadPromiseOrContent instanceof Promise) {
158
- return loadPromiseOrContent.then(function () {
159
- return args;
160
- });
161
- }
162
- }
176
+ return runControllerFillContent(controller, $html).then(function (args) {
177
+ args = args || true;
178
+ if (controller.willShow) {
179
+ let loadPromiseOrContent = controller.willShow();
180
+ if (loadPromiseOrContent instanceof Promise) {
181
+ return loadPromiseOrContent.then(function () {
182
+ return args;
183
+ });
184
+ }
185
+ }
163
186
 
164
- return args;
165
- });
187
+ return args;
188
+ });
166
189
  }
167
190
 
168
-
169
191
  /**
170
192
  * runControllerLoad Calls the onLoad function of the controller.
171
193
  * This function is called before the HTML is set to the page.
@@ -175,17 +197,17 @@ function runControllerShow(controller, $html) {
175
197
  * @return {Promise<*>} - return of the onLoad function
176
198
  */
177
199
  function runControllerLoad(controller) {
178
- return loadFilesFromController(controller).then((html) => {
179
- if (!controller.onLoad || controller._onLoadDone) {
180
- return html;
181
- }
200
+ return loadFilesFromController(controller).then((html) => {
201
+ if (!controller.onLoad || controller._onLoadDone) {
202
+ return html;
203
+ }
182
204
 
183
- controller._onLoadDone = true;
184
- let loadPromise = controller.onLoad(html);
185
- return (loadPromise || promiseDummyFactory()).then(() => {
186
- return html;
187
- });
205
+ controller._onLoadDone = true;
206
+ let loadPromise = controller.onLoad(html);
207
+ return (loadPromise || promiseDummyFactory()).then(() => {
208
+ return html;
188
209
  });
210
+ });
189
211
  }
190
212
 
191
213
  /**
@@ -198,21 +220,23 @@ function runControllerLoad(controller) {
198
220
  * @param controller
199
221
  * @param {Object} process - Process object containing the refresh process
200
222
  */
201
- export function runControlFlowFunctions(controller, process ) {
202
- const prom_controller = runControllerLoad(controller)
203
- .then(function ($html) {
204
- return runControllerShow(controller, $html);
205
- }).then(() => {
206
- return runRefresh(controller, process);
207
- }).catch(function ($html) {
208
- return runControllerFillContent(controller, $html);
209
- });
223
+ export function runControlFlowFunctions(controller, process) {
224
+ const prom_controller = runControllerLoad(controller)
225
+ .then(function ($html) {
226
+ return runControllerShow(controller, $html);
227
+ })
228
+ .then(() => {
229
+ return runRefresh(controller, process);
230
+ })
231
+ .catch(function ($html) {
232
+ return runControllerFillContent(controller, $html);
233
+ });
210
234
 
211
- if (controller.load_async) {
212
- return Promise.resolve();
213
- }
235
+ if (controller.load_async) {
236
+ return Promise.resolve();
237
+ }
214
238
 
215
- return prom_controller;
239
+ return prom_controller;
216
240
  }
217
241
 
218
242
  /**
@@ -221,17 +245,17 @@ export function runControlFlowFunctions(controller, process ) {
221
245
  * @param {Object} process - Process object containing the refresh process
222
246
  */
223
247
  export function runRefresh(controller, process) {
224
- return refresh(null, controller, process);
248
+ return refresh(null, controller, process);
225
249
  }
226
250
 
227
251
  function getParentList(controller) {
228
- let controllerList = [];
229
- while (controller) {
230
- controller._isEventsSet = false;
231
- controllerList.unshift(controller);
232
- controller = controller._parentController;
233
- }
234
- return controllerList
252
+ let controllerList = [];
253
+ while (controller) {
254
+ controller._isEventsSet = false;
255
+ controllerList.unshift(controller);
256
+ controller = controller._parentController;
257
+ }
258
+ return controllerList;
235
259
  }
236
260
 
237
261
  /**
@@ -239,26 +263,27 @@ function getParentList(controller) {
239
263
  * @param {Object} process - Process object containing the refresh process
240
264
  */
241
265
  export function updateEventAndTriggerOnRefresh(process) {
242
- const parentList = getParentList(process.controller[0]);
243
- const controllerList = parentList.concat(process.controller.slice(1));
266
+ const parentList = getParentList(process.controller[0]);
267
+ const controllerList = parentList.concat(process.controller.slice(1));
244
268
 
245
- for (let con of controllerList) {
246
- setControllerEvents(con);
247
- con.onRefresh(process.controller[0]);
248
- }
269
+ for (let con of controllerList) {
270
+ setControllerEvents(con);
271
+ con.onRefresh(process.controller[0]);
272
+ }
249
273
  }
250
274
 
251
-
252
275
  export function prepareRefreshProcess(refreshProcess, controller) {
253
- let isRunningProcess = Boolean(refreshProcess);
254
-
255
- if (!isRunningProcess) {
256
- refreshProcess = {uuids: new Set([controller._uuid]), controller: [controller]};
257
- } else if (!refreshProcess.uuids.has(controller._uuid)) {
258
- refreshProcess.uuids.add(controller._uuid);
259
- refreshProcess.controller.push(controller);
260
- }
261
-
262
- return {isRunningProcess, refreshProcess};
276
+ let isRunningProcess = Boolean(refreshProcess);
277
+
278
+ if (!isRunningProcess) {
279
+ refreshProcess = {
280
+ uuids: new Set([controller._uuid]),
281
+ controller: [controller],
282
+ };
283
+ } else if (!refreshProcess.uuids.has(controller._uuid)) {
284
+ refreshProcess.uuids.add(controller._uuid);
285
+ refreshProcess.controller.push(controller);
286
+ }
287
+
288
+ return { isRunningProcess, refreshProcess };
263
289
  }
264
-
@@ -1,116 +1,127 @@
1
- import {getController} from './sdc_view.js';
1
+ import { getController } from "./sdc_view.js";
2
2
 
3
- export const STD_EVENT_BLACK_LIST = ['onbeforeunload', 'onunload'];
4
- export const STD_EVENT_LIST = Object.keys(window).filter(key => /^on/.test(key) && !STD_EVENT_BLACK_LIST.includes(key)).map(x => x.slice(2));
3
+ export const STD_EVENT_BLACK_LIST = ["onbeforeunload", "onunload"];
4
+ export const STD_EVENT_LIST = Object.keys(window)
5
+ .filter((key) => /^on/.test(key) && !STD_EVENT_BLACK_LIST.includes(key))
6
+ .map((x) => x.slice(2));
5
7
 
6
8
  function checkIfEventFits(ev_type, e, target) {
7
- let elementUnderMouse;
8
- switch (ev_type) {
9
- case "mouseleave":
10
- case "mouseout":
11
- elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
12
- return target !== elementUnderMouse && !target.contains(elementUnderMouse);
13
- case "mouseenter":
14
- case "mousein":
15
- elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
16
- return target !== elementUnderMouse && !target.contains(elementUnderMouse);
17
- default:
18
- return true;
19
- };
9
+ let elementUnderMouse;
10
+ switch (ev_type) {
11
+ case "mouseleave":
12
+ case "mouseout":
13
+ elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
14
+ return (
15
+ target !== elementUnderMouse && !target.contains(elementUnderMouse)
16
+ );
17
+ case "mouseenter":
18
+ case "mousein":
19
+ elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
20
+ return (
21
+ target !== elementUnderMouse && !target.contains(elementUnderMouse)
22
+ );
23
+ default:
24
+ return true;
25
+ }
20
26
  }
21
27
 
22
28
  export function windowEventHandler(event) {
23
- let ev_type = event.type;
24
- if (event.hasOwnProperty('namespace') && event.namespace && event.namespace.length) ev_type += `.${event.namespace}`;
29
+ let ev_type = event.type;
30
+ if (
31
+ event.hasOwnProperty("namespace") &&
32
+ event.namespace &&
33
+ event.namespace.length
34
+ )
35
+ ev_type += `.${event.namespace}`;
25
36
 
26
- let $elm = $(event.target);
27
- let controller = null;
28
- let is_done = false;
29
- let is_last_elem = false;
30
- event.stopImmediatePropagation = () => is_last_elem = true;
31
- event.stopPropagation = () => is_last_elem = is_done = true;
32
- while ($elm.length) {
33
- let attrs = $elm.attr(`sdc_${ev_type}`);
34
- if (attrs && checkIfEventFits(ev_type, event, $elm[0])) {
35
- if (!controller) {
36
- controller = getController($elm);
37
- if (!controller) return;
37
+ let $elm = $(event.target);
38
+ let controller = null;
39
+ let is_done = false;
40
+ let is_last_elem = false;
41
+ event.stopImmediatePropagation = () => (is_last_elem = true);
42
+ event.stopPropagation = () => (is_last_elem = is_done = true);
43
+ while ($elm.length) {
44
+ let attrs = $elm.attr(`sdc_${ev_type}`);
45
+ if (attrs && checkIfEventFits(ev_type, event, $elm[0])) {
46
+ if (!controller) {
47
+ controller = getController($elm);
48
+ if (!controller) return;
49
+ }
50
+ while (controller) {
51
+ attrs.split(" ").forEach((attr) => {
52
+ if (is_done) return;
53
+ let handler = null;
54
+ if (typeof attr === "function") {
55
+ handler = attr;
56
+ } else if (typeof controller[attr] === "function") {
57
+ handler = controller[attr];
58
+ } else if (
59
+ typeof attr === "string" &&
60
+ attr.startsWith("this.event_")
61
+ ) {
62
+ handler = controller.getEvents()[ev_type];
63
+ if (!handler) {
64
+ return;
38
65
  }
39
- while (controller) {
40
- attrs.split(' ').forEach((attr) => {
41
- if (is_done) return;
42
- let handler = null;
43
- if (typeof attr === 'function') {
44
- handler = attr;
45
- } else if (typeof controller[attr] === 'function') {
46
- handler = controller[attr];
47
- } else if (typeof attr === 'string' && attr.startsWith('this.event_')) {
48
- handler = controller.getEvents()[ev_type];
49
- if (!handler) {
50
- return;
51
- }
52
- handler = handler[attr.slice('this.event_'.length)];
53
- if (!handler) {
54
- return;
55
- }
56
- }
57
-
58
- handler && handler.call(controller, $elm, event);
59
- });
60
- if (is_last_elem) return;
61
- controller = controller._parentController
66
+ handler = handler[attr.slice("this.event_".length)];
67
+ if (!handler) {
68
+ return;
62
69
  }
63
- }
64
- if (is_done) return;
65
- $elm = $elm.parent();
70
+ }
71
+
72
+ handler && handler.call(controller, $elm, event);
73
+ });
74
+ if (is_last_elem) return;
75
+ controller = controller._parentController;
76
+ }
66
77
  }
78
+ if (is_done) return;
79
+ $elm = $elm.parent();
80
+ }
67
81
 
68
- return {res: true};
82
+ return { res: true };
69
83
  }
70
84
 
71
85
  /**
72
86
  *
73
87
  */
74
88
  export function initEvents() {
75
- const $window = $(window);
76
- STD_EVENT_LIST.forEach(ev_type => {
77
- $window.off(ev_type).on(ev_type, windowEventHandler);
78
- });
89
+ const $window = $(window);
90
+ STD_EVENT_LIST.forEach((ev_type) => {
91
+ $window.off(ev_type).on(ev_type, windowEventHandler);
92
+ });
79
93
  }
80
94
 
81
-
82
95
  /**
83
96
  *
84
97
  * @param {AbstractSDC} controller
85
98
  */
86
99
  export function setControllerEvents(controller) {
100
+ if (controller._isEventsSet) {
101
+ return;
102
+ }
87
103
 
88
- if (controller._isEventsSet) {
89
- return;
90
- }
91
-
92
- const events = controller.getEvents();
93
- for (let ev_type in events) {
94
- if (events.hasOwnProperty(ev_type)) {
95
- let eventList = events[ev_type];
96
- for (let domSelector in eventList) {
97
- if (eventList.hasOwnProperty(domSelector)) {
98
- controller.find(domSelector).each(function () {
99
- let $elements = $(this);
100
- let event_list = $elements.attr(`sdc_${ev_type}`) || null;
101
- if (!event_list) event_list = [];
102
- else event_list = event_list.split(' ');
103
- const new_key = `this.event_${domSelector}`;
104
- if (event_list.indexOf(new_key) === -1) {
105
- event_list.push(new_key);
106
- $elements.attr(`sdc_${ev_type}`, event_list.join(' '))
107
- }
108
-
109
- });
110
- }
104
+ const events = controller.getEvents();
105
+ for (let ev_type in events) {
106
+ if (events.hasOwnProperty(ev_type)) {
107
+ let eventList = events[ev_type];
108
+ for (let domSelector in eventList) {
109
+ if (eventList.hasOwnProperty(domSelector)) {
110
+ controller.find(domSelector).each(function () {
111
+ let $elements = $(this);
112
+ let event_list = $elements.attr(`sdc_${ev_type}`) || null;
113
+ if (!event_list) event_list = [];
114
+ else event_list = event_list.split(" ");
115
+ const new_key = `this.event_${domSelector}`;
116
+ if (event_list.indexOf(new_key) === -1) {
117
+ event_list.push(new_key);
118
+ $elements.attr(`sdc_${ev_type}`, event_list.join(" "));
111
119
  }
120
+ });
112
121
  }
122
+ }
113
123
  }
114
- // TODO: Is it needed
115
- //controller._isEventsSet = true;
116
- }
124
+ }
125
+ // TODO: Is it needed
126
+ //controller._isEventsSet = true;
127
+ }