dphelper 0.2.88 → 0.2.89
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/.editorconfig +13 -0
- package/.env +3 -0
- package/.eslintignore +13 -0
- package/.eslintrc.json +87 -0
- package/.eslintrc.legacy.json +91 -0
- package/.gitattributes +2 -0
- package/.hintrc +11 -0
- package/.jsbeautifyrc +25 -0
- package/.jshintrc +16 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +8 -0
- package/.stylelintignore +0 -0
- package/.stylelintrc.json +468 -0
- package/.vscode/launch.json +34 -0
- package/.vscode/settings.json +58 -0
- package/3party/shortcut.js +224 -0
- package/__mocks__/fileMock.js +3 -0
- package/__mocks__/styleMock.js +3 -0
- package/babel.config.js +30 -0
- package/backup.bat +43 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +0 -0
- package/data/list.json +19 -0
- package/dist/LICENSE.txt +209 -0
- package/dist/README.md +79 -0
- package/elements/button/component.js +0 -0
- package/elements/code/component.js +0 -0
- package/elements/costants.tsx +13 -0
- package/elements/fieldset/component.js +0 -0
- package/elements/input/checkbox/component.js +0 -0
- package/elements/input/date/component.js +27 -0
- package/elements/input/number/component.js +0 -0
- package/elements/input/radio/component.js +0 -0
- package/elements/input/search/component.js +0 -0
- package/elements/input/select/component.js +0 -0
- package/elements/input/slider/component.js +0 -0
- package/elements/input/switch/component.js +0 -0
- package/elements/tab/component.js +0 -0
- package/elements/table/component.js +0 -0
- package/elements/tags.less +0 -0
- package/elements/textarea/component.js +0 -0
- package/elements/x-foo/define.js +33 -0
- package/elements/x-foo/namespace.d.ts +7 -0
- package/index.js +12 -2
- package/init.js +87 -0
- package/jest.config.js +81 -0
- package/node/createTag.js +7 -0
- package/node/gitDeploy.js +7 -0
- package/node/goLive.js +7 -0
- package/package.json +7 -7
- package/{assets → public/assets}/images/banner.png +0 -0
- package/{assets → public/assets}/logos/logo.svg +0 -0
- package/{documents → public/documents}/iDB/list.html +0 -0
- package/{documents → public/documents}/iDB/toState.html +0 -0
- package/scripts/.OLD/import.js +48 -0
- package/scripts/.OLD/onBeforeUnLoad.js +120 -0
- package/scripts/.OLD/purge.js +53 -0
- package/scripts/.OLD/string.js +27 -0
- package/scripts/anchor.js +73 -0
- package/scripts/array.js +203 -0
- package/scripts/avoid.js +48 -0
- package/scripts/browser.js +100 -0
- package/scripts/color.js +121 -0
- package/scripts/console.js +97 -0
- package/scripts/console.mapped.js +160 -0
- package/scripts/coods.js +57 -0
- package/scripts/cookie.js +105 -0
- package/scripts/date.js +179 -0
- package/scripts/disable.js +91 -0
- package/scripts/errors.js +3 -0
- package/scripts/event.js +57 -0
- package/scripts/font.js +60 -0
- package/scripts/form.js +211 -0
- package/scripts/format.js +71 -0
- package/scripts/function.js +55 -0
- package/scripts/iDB.js +688 -0
- package/scripts/json.js +84 -0
- package/scripts/load.js +112 -0
- package/scripts/math.js +100 -0
- package/scripts/obj.js +118 -0
- package/scripts/path.js +101 -0
- package/scripts/promise.js +56 -0
- package/scripts/screen.js +82 -0
- package/scripts/scrollbar.js +293 -0
- package/scripts/shortcut.js +83 -0
- package/scripts/socket.js +184 -0
- package/scripts/state.js +87 -0
- package/scripts/storage.js +93 -0
- package/scripts/store.js +115 -0
- package/scripts/svg.js +380 -0
- package/scripts/text.js +116 -0
- package/scripts/time.js +43 -0
- package/scripts/timer.js +54 -0
- package/scripts/tool.js +73 -0
- package/scripts/trigger.js +57 -0
- package/scripts/type.js +76 -0
- package/scripts/ui.js +41 -0
- package/scripts/window.js +244 -0
- package/styles/console.less +95 -0
- package/tests/setupJest.tsx +4 -0
- package/typings/.OLD/cordova.d.ts +12 -0
- package/typings/.OLD/layerpro.d.ts +20 -0
- package/typings/.OLD/menupro.d.ts +20 -0
- package/typings/dphelper.d.ts +26 -0
- package/typings/image.d.ts +5 -0
- package/typings/styles.d.ts +23 -0
- package/webpack.config.js +249 -0
- package/index.js.LICENSE.txt +0 -31
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
dpHelper
|
|
3
|
+
Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under the Apache-2.0, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/***********************************************************************/
|
|
9
|
+
|
|
10
|
+
var description = {
|
|
11
|
+
"name" : "Scrollbar",
|
|
12
|
+
"description" : "",
|
|
13
|
+
"version" : "0.0.1",
|
|
14
|
+
"command" : "scrollbar",
|
|
15
|
+
"subCommand" : [
|
|
16
|
+
{
|
|
17
|
+
"name":"custom",
|
|
18
|
+
"description":"test"
|
|
19
|
+
},{
|
|
20
|
+
"name":"indicator",
|
|
21
|
+
"description":"test"
|
|
22
|
+
},{
|
|
23
|
+
"name":"position.get",
|
|
24
|
+
"description":"test"
|
|
25
|
+
},{
|
|
26
|
+
"name":"position.set",
|
|
27
|
+
"description":"test"
|
|
28
|
+
},{
|
|
29
|
+
"name":"smooth",
|
|
30
|
+
"description":"test"
|
|
31
|
+
},{
|
|
32
|
+
"name":"scrollTo",
|
|
33
|
+
"description":"test"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"example" : "",
|
|
37
|
+
"author" : "Dario Passariello",
|
|
38
|
+
"active" : true
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
dphelper._list.scripts.push( description );
|
|
42
|
+
|
|
43
|
+
/***********************************************************************/
|
|
44
|
+
|
|
45
|
+
dphelper.scrollbar = {
|
|
46
|
+
|
|
47
|
+
custom: ( el, options ) => {
|
|
48
|
+
|
|
49
|
+
if(!options['color_1']) options['color_1'] = "black";
|
|
50
|
+
if(!options['color_1_hover']) options['color_1_hover'] = "black";
|
|
51
|
+
if(!options['color_2']) options['color_2'] = "transparent";
|
|
52
|
+
if(!options['color_3']) options['color_3'] = "rgba(30,150,255,.5)";
|
|
53
|
+
if(!options['type']) options['type'] = "thin";
|
|
54
|
+
if(!options['behavior']) options['behavior'] = "smooth";
|
|
55
|
+
if(!options['width']) options['width'] = "16px";
|
|
56
|
+
if(!options['height']) options['height'] = "16px";
|
|
57
|
+
if(!options['rounded']) options['rounded'] = "10px";
|
|
58
|
+
if(!options['margin']) options['margin'] = "0";
|
|
59
|
+
if(!options['border']) options['border'] = "5px";
|
|
60
|
+
if(!options['opacity']) options['opacity'] = "1";
|
|
61
|
+
|
|
62
|
+
const $style = `${el}{
|
|
63
|
+
scrollbar-width:auto;
|
|
64
|
+
scrollbar-color: ${options['color_1']};
|
|
65
|
+
scrollbar-width: ${options['type']};
|
|
66
|
+
scroll-behavior: ${options['behavior']};
|
|
67
|
+
scroll-margin: ${options['margin']};
|
|
68
|
+
-ms-overflow-style: -ms-autohiding-scrollbar;
|
|
69
|
+
}
|
|
70
|
+
${el}::-webkit-scrollbar {
|
|
71
|
+
scroll-behavior: ${options['behavior']};
|
|
72
|
+
width: ${options['width']};
|
|
73
|
+
height: ${options['height']};
|
|
74
|
+
}
|
|
75
|
+
${el}::-webkit-scrollbar-thumb {
|
|
76
|
+
opacity: ${options['opacity']} !important;
|
|
77
|
+
-webkit-border-radius: ${options['rounded']} !important;
|
|
78
|
+
-webkit-box-shadow: none !important;
|
|
79
|
+
box-shadow: none !important;
|
|
80
|
+
border-radius: ${options['rounded']} !important;
|
|
81
|
+
background: ${options['color_1']} !important;
|
|
82
|
+
background-clip: content-box !important;
|
|
83
|
+
border: ${options['border']} solid transparent !important;
|
|
84
|
+
min-height: 2px !important;
|
|
85
|
+
min-width: 2px !important;
|
|
86
|
+
}
|
|
87
|
+
${el}::-webkit-scrollbar-thumb:hover,
|
|
88
|
+
${el}::-webkit-scrollbar-thumb:active{
|
|
89
|
+
background: ${options['color_1']} !important;
|
|
90
|
+
background-clip: content-box !important;
|
|
91
|
+
border: calc( ${ options['border']} - 1.5px ) solid transparent !important;
|
|
92
|
+
}
|
|
93
|
+
${el}::-webkit-scrollbar-track {
|
|
94
|
+
background: ${options['color_2']};
|
|
95
|
+
border-radius: ${options['rounded']};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
${el}::-webkit-scrollbar-track:hover {
|
|
99
|
+
/*background: rgba(128,128,128,.15) !important;*/
|
|
100
|
+
background: transparent !important;
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
${el}::-webkit-scrollbar-track:vertical:hover {
|
|
104
|
+
/* border-left: 1px solid rgba(0,0,0,.1) !important; */
|
|
105
|
+
}
|
|
106
|
+
${el}::-webkit-scrollbar-track:horizontal:hover {
|
|
107
|
+
/* border-top: 1px solid rgba(0,0,0,.1) !important; */
|
|
108
|
+
}
|
|
109
|
+
/*
|
|
110
|
+
${el}::-webkit-scrollbar-thumb:window-inactive {
|
|
111
|
+
background: ${options['color_3']}
|
|
112
|
+
}
|
|
113
|
+
*/
|
|
114
|
+
select::-webkit-scrollbar-thumb {
|
|
115
|
+
border: 4px solid hsl(0 0% 92% / 1) !important;
|
|
116
|
+
}
|
|
117
|
+
select::-webkit-scrollbar-track {
|
|
118
|
+
background: hsl(0 0% 92% / 1) !important;
|
|
119
|
+
}
|
|
120
|
+
select::-webkit-scrollbar-track:vertical,
|
|
121
|
+
select::-webkit-scrollbar-track:horizontal {
|
|
122
|
+
border-top: none !important;
|
|
123
|
+
border-left: none !important;
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
let styleToHead = document.createElement( "style" );
|
|
128
|
+
document.head.appendChild( styleToHead );
|
|
129
|
+
styleToHead.innerHTML = $style;
|
|
130
|
+
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
indicator: ( props ) => {
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
/* This timeout it's to be suse that whole UI is loaded
|
|
137
|
+
/* Just smaller trick!
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
let cont = document.querySelector( props.el );
|
|
141
|
+
let sc = document.querySelector('.scrollindicator');
|
|
142
|
+
|
|
143
|
+
if( !sc ){
|
|
144
|
+
|
|
145
|
+
const createEl = document.createElement('div');
|
|
146
|
+
createEl.classList.add("scrollindicator");
|
|
147
|
+
document.querySelector('header').appendChild(createEl);
|
|
148
|
+
|
|
149
|
+
createEl.style.cssText = `
|
|
150
|
+
height:5px;
|
|
151
|
+
background:#65c45c;
|
|
152
|
+
position:absolute;
|
|
153
|
+
bottom:0;
|
|
154
|
+
left:0;
|
|
155
|
+
z-index:2
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if( !props.el && sc) {
|
|
160
|
+
sc.style.width = 0 + '%';
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try{
|
|
165
|
+
let sc = document.querySelector('.scrollindicator');
|
|
166
|
+
cont.addEventListener( 'scroll' , function ( e ) {
|
|
167
|
+
|
|
168
|
+
sc.style.width = 0 + '%';
|
|
169
|
+
let winScroll = this.scrollTop || this.scrollTop;
|
|
170
|
+
let height = this.scrollHeight - this.clientHeight;
|
|
171
|
+
let scrolled = Math.min(Math.max(parseInt( (winScroll / height) * 100 ), 0), 100);
|
|
172
|
+
sc.style.width = scrolled + '%';
|
|
173
|
+
|
|
174
|
+
sc.click();
|
|
175
|
+
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
window.addEventListener('popstate', function ( e ) {
|
|
179
|
+
sc.style.width = 0;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
}catch( e ){
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return null;
|
|
187
|
+
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
position: {
|
|
191
|
+
|
|
192
|
+
set: ( el ) => {
|
|
193
|
+
|
|
194
|
+
let ar = [$( el ).scrollTop(),$( el ).scrollLeft()];
|
|
195
|
+
if( ar[0] != null && ar[1] != null ){ dphelper.storage.set( el , ar ); }
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
get: ( el ) => {
|
|
199
|
+
if( !dphelper.storage.get( el ) ) return;
|
|
200
|
+
let ar = JSON.parse( dphelper.storage.get( el ) );
|
|
201
|
+
|
|
202
|
+
$( el ).scrollTop( ar[0] );
|
|
203
|
+
$( el ).scrollLeft( ar[1] );
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
smooth: (target, speed, smooth) => {
|
|
209
|
+
|
|
210
|
+
if (target === document)
|
|
211
|
+
target = (document.scrollingElement || document.documentElement || document.body.parentNode || document.body); // cross browser support for document scrolling
|
|
212
|
+
|
|
213
|
+
let moving = false;
|
|
214
|
+
let pos = target.scrollTop;
|
|
215
|
+
let frame = target === document.body && document.documentElement ? document.documentElement : target; // safari is the new IE
|
|
216
|
+
|
|
217
|
+
target.addEventListener('mousewheel', scrolled, { passive: false });
|
|
218
|
+
target.addEventListener('DOMMouseScroll', scrolled, { passive: false });
|
|
219
|
+
|
|
220
|
+
function scrolled( e ) {
|
|
221
|
+
e.preventDefault(); // disable default scrolling
|
|
222
|
+
|
|
223
|
+
let delta = normalizeWheelDelta( e );
|
|
224
|
+
|
|
225
|
+
pos += -delta * speed;
|
|
226
|
+
pos = Math.max(0, Math.min(pos, target.scrollHeight - frame.clientHeight)); // limit scrolling
|
|
227
|
+
|
|
228
|
+
if (!moving) update();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function normalizeWheelDelta( e ){
|
|
232
|
+
if(e.detail){
|
|
233
|
+
if(e.wheelDelta)
|
|
234
|
+
return e.wheelDelta/e.detail/40 * (e.detail>0 ? 1 : -1); // Opera
|
|
235
|
+
else
|
|
236
|
+
return -e.detail/3; // Firefox
|
|
237
|
+
}else
|
|
238
|
+
return e.wheelDelta/120; // IE,Safari,Chrome
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function update() {
|
|
242
|
+
moving = true;
|
|
243
|
+
|
|
244
|
+
let delta = (pos - target.scrollTop) / smooth;
|
|
245
|
+
|
|
246
|
+
target.scrollTop += delta;
|
|
247
|
+
|
|
248
|
+
if (Math.abs(delta) > 0.5)
|
|
249
|
+
requestFrame(update);
|
|
250
|
+
else
|
|
251
|
+
moving = false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let requestFrame = function() { // requestAnimationFrame cross browser
|
|
255
|
+
return (
|
|
256
|
+
window.requestAnimationFrame ||
|
|
257
|
+
window.webkitRequestAnimationFrame ||
|
|
258
|
+
window.mozRequestAnimationFrame ||
|
|
259
|
+
window.oRequestAnimationFrame ||
|
|
260
|
+
window.msRequestAnimationFrame ||
|
|
261
|
+
function(func) {
|
|
262
|
+
window.setTimeout(func, 1000 / 50);
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}();
|
|
266
|
+
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
scrollTo: function( container, element, gap = 0 ) {
|
|
270
|
+
|
|
271
|
+
let el1 = document.querySelector( container );
|
|
272
|
+
let el2 = document.querySelector( element );
|
|
273
|
+
let el3 = gap; // DIVERGENCE
|
|
274
|
+
|
|
275
|
+
if( !el1 || !el2 || !el3 ) return;
|
|
276
|
+
|
|
277
|
+
el1.scrollTo({
|
|
278
|
+
top: el2.offsetTop,
|
|
279
|
+
behavior: "smooth"
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
//example: dphelper.scrollbar.custom('*')
|
|
287
|
+
|
|
288
|
+
Object.defineProperty( dphelper, 'scrollbar', {
|
|
289
|
+
writable: false,
|
|
290
|
+
configurable: false
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
//console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
dpHelper
|
|
3
|
+
Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under the Apache-2.0, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/***********************************************************************/
|
|
9
|
+
|
|
10
|
+
var description = {
|
|
11
|
+
"name" : "Shortcut",
|
|
12
|
+
"description" : "",
|
|
13
|
+
"version" : "0.0.1",
|
|
14
|
+
"command" : "shortcut",
|
|
15
|
+
"example" : "",
|
|
16
|
+
"author" : "Dario Passariello",
|
|
17
|
+
"active" : true,
|
|
18
|
+
"subCommand" : []
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
dphelper._list.scripts.push( description );
|
|
22
|
+
|
|
23
|
+
/***********************************************************************/
|
|
24
|
+
|
|
25
|
+
dphelper.shortcut = ( e, trigger ) => {
|
|
26
|
+
const code = e.which ? e.which : e.keyCode;
|
|
27
|
+
|
|
28
|
+
(e) = {
|
|
29
|
+
tes: console.log('try')
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if( !trigger ) trigger = {
|
|
33
|
+
|
|
34
|
+
"data" : [
|
|
35
|
+
{
|
|
36
|
+
"key" : "83",
|
|
37
|
+
"ctrl" : true,
|
|
38
|
+
"active" : true,
|
|
39
|
+
"description" : "CTRL+S",
|
|
40
|
+
//"element" : "#formSave",
|
|
41
|
+
"function" : ""
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"key" : "27",
|
|
45
|
+
"ctrl" : false,
|
|
46
|
+
"active" : true,
|
|
47
|
+
"description" : "ESC",
|
|
48
|
+
"element" : "",
|
|
49
|
+
"function" : ""
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"key" : "80",
|
|
53
|
+
"ctrl" : true,
|
|
54
|
+
"active" : true,
|
|
55
|
+
"description" : "CTRL+P",
|
|
56
|
+
"element" : "",
|
|
57
|
+
"function" : "function(){ Print }"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
trigger.map( list => {
|
|
63
|
+
|
|
64
|
+
// IF CTRL COMMAND
|
|
65
|
+
if ( e.ctrlKey || e.metaKey && list.ctrl === true ) {
|
|
66
|
+
if( code === parseInt(list.key) && list.active === true ){
|
|
67
|
+
if( list.element ) simulateClick( list.element );
|
|
68
|
+
if( list.function ) JSON.stringify( list.function );
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
Object.defineProperty( dphelper, 'shortcut', {
|
|
79
|
+
writable: false,
|
|
80
|
+
configurable: false
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
//console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
dpHelper
|
|
3
|
+
Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under the Apache-2.0, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
///////////////////////////////////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
var description = {
|
|
11
|
+
"name" : "Socket",
|
|
12
|
+
"description" : "",
|
|
13
|
+
"version" : "0.0.1",
|
|
14
|
+
"command" : "socket",
|
|
15
|
+
"subCommand" : [
|
|
16
|
+
{
|
|
17
|
+
"name":"info",
|
|
18
|
+
"description":""
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name":"start",
|
|
22
|
+
"description":"test"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name":"conn",
|
|
26
|
+
"description":"test"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name":"connect",
|
|
30
|
+
"description":"test"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name":"open",
|
|
34
|
+
"description":"test"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name":"send",
|
|
38
|
+
"description":"test"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name":"receive",
|
|
42
|
+
"description":"test"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name":"keepAlive",
|
|
46
|
+
"description":""
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"example" : "",
|
|
50
|
+
"author" : "Dario Passariello",
|
|
51
|
+
"active" : true
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
dphelper._list.scripts.push( description );
|
|
55
|
+
|
|
56
|
+
///////////////////////////////////////////////////////////////////////////////////
|
|
57
|
+
|
|
58
|
+
dphelper.socket = {
|
|
59
|
+
|
|
60
|
+
info: () => {
|
|
61
|
+
return 'Created by Dario Passariello'
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
start: ( element , server ) => {
|
|
65
|
+
dphelper.socket.connect( server )
|
|
66
|
+
dphelper.socket.receive( element )
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
conn: ( id , server ) => {
|
|
70
|
+
if( !id || !server ){
|
|
71
|
+
console.log( 'please use connect!' )
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const ws = new WebSocket( server )
|
|
75
|
+
ws.binaryType = "string"
|
|
76
|
+
ws.headers = {
|
|
77
|
+
test: "test"
|
|
78
|
+
}
|
|
79
|
+
return [ ws, id ]
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
///////////////////////////////////////////
|
|
83
|
+
|
|
84
|
+
connect: ( server ) => {
|
|
85
|
+
if( !server ) return
|
|
86
|
+
dphelper.socket.open( dphelper.tool.uuid.v5() , server )
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
///////////////////////////////////////////
|
|
90
|
+
|
|
91
|
+
open: ( id , server ) => {
|
|
92
|
+
if( !id ) return
|
|
93
|
+
dphelper.socket.connection = dphelper.socket.conn( id , server )
|
|
94
|
+
console.log( id )
|
|
95
|
+
dphelper.socket.connection[0].onopen = () => console.debug( id + ' connected')
|
|
96
|
+
dphelper.socket.connection[0].onclose = ( event ) => console.debug( ( event.wasClean ) ? 'Disconnected' : 'Connection break: ' + ( event.reason || event.code ) )
|
|
97
|
+
dphelper.socket.connection[0].onerror = ( err ) => console.error( err.message )
|
|
98
|
+
// socket.onmessage = ( event ) => console.debug( event.data ) }
|
|
99
|
+
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
///////////////////////////////////////////
|
|
103
|
+
|
|
104
|
+
send: ( mex ) => {
|
|
105
|
+
if( !dphelper.socket.connection[1] ) return
|
|
106
|
+
let ws = dphelper.socket.connection[0]
|
|
107
|
+
let id = dphelper.socket.connection[1]
|
|
108
|
+
//ws.addEventListener( 'open' , function ( event ) { console.log( event ) });
|
|
109
|
+
var obj = `{"${id}":"${mex}"}`
|
|
110
|
+
ws.send( obj )
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
///////////////////////////////////////////
|
|
114
|
+
|
|
115
|
+
receive: ( element ) => {
|
|
116
|
+
if( !dphelper.socket.connection[1] ) return
|
|
117
|
+
let ws = dphelper.socket.connection[0]
|
|
118
|
+
|
|
119
|
+
ws.addEventListener( 'message', function ( message ) {
|
|
120
|
+
|
|
121
|
+
try{
|
|
122
|
+
|
|
123
|
+
var data = Object.values( JSON.parse( message.data ) )
|
|
124
|
+
|
|
125
|
+
console.debug( `%cMEX: %c` + message.data, "color: orange", "" )
|
|
126
|
+
|
|
127
|
+
if( $( element ) ){
|
|
128
|
+
$( element ).prepend( data[0] + "<br/>" )
|
|
129
|
+
//$( element ).append( data[0] + "<br/>" )
|
|
130
|
+
}
|
|
131
|
+
return data[0]
|
|
132
|
+
|
|
133
|
+
} catch (e) {
|
|
134
|
+
|
|
135
|
+
console.error( `error: ${e}` )
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
keepAlive: () => {
|
|
144
|
+
|
|
145
|
+
var tm
|
|
146
|
+
function ping() {
|
|
147
|
+
dphelper.socket.send('__ping__')
|
|
148
|
+
tm = setTimeout(function () {
|
|
149
|
+
// console.log('ping')
|
|
150
|
+
/// ---connection closed ///
|
|
151
|
+
}, 5000)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function pong() {
|
|
155
|
+
// console.log('pong')
|
|
156
|
+
clearTimeout(tm)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
intraGlobal.ws.onopen = function () {
|
|
160
|
+
// console.log('open')
|
|
161
|
+
setInterval( ping, 30000 )
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
intraGlobal.ws.onmessage = function (evt) {
|
|
165
|
+
var ck = Object.values( JSON.parse( evt.data ) )
|
|
166
|
+
// console.log( evt )
|
|
167
|
+
// console.log( '>', ck[0] )
|
|
168
|
+
if ( ck[0] === '__ping__') {
|
|
169
|
+
pong()
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
//////-- other operation --//
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Object.defineProperty( dphelper, 'socket', {
|
|
180
|
+
writable: false,
|
|
181
|
+
configurable: false
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
//console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
|
package/scripts/state.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
dpHelper
|
|
3
|
+
Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under the Apache-2.0, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/***********************************************************************/
|
|
9
|
+
|
|
10
|
+
var description = {
|
|
11
|
+
"name" : "State",
|
|
12
|
+
"description" : "",
|
|
13
|
+
"version" : "0.0.1",
|
|
14
|
+
"command" : "state",
|
|
15
|
+
"subCommand" : [],
|
|
16
|
+
"example" : "state() or dphelper.state()",
|
|
17
|
+
"author" : "Dario Passariello",
|
|
18
|
+
"active" : true
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
dphelper._list.scripts.push( description );
|
|
22
|
+
|
|
23
|
+
/***********************************************************************/
|
|
24
|
+
|
|
25
|
+
dphelper.state = function ( key, value ){
|
|
26
|
+
|
|
27
|
+
// LIST ALL ARRAY FROM STATE
|
|
28
|
+
if( !key && !value ){
|
|
29
|
+
|
|
30
|
+
// NEW ARRAY
|
|
31
|
+
let final = [];
|
|
32
|
+
|
|
33
|
+
// GET CLEAN ARRAY FROM JSON
|
|
34
|
+
let clear = dphelper.obj.toArray( dphelper.state );
|
|
35
|
+
|
|
36
|
+
// FINAL ARRAY (remove functions)
|
|
37
|
+
clear.map( ( list , i ) => {
|
|
38
|
+
if( typeof list[1] === 'function' ) return;
|
|
39
|
+
final[ list[0] ] = list[1];
|
|
40
|
+
//final.push( list );
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return dphelper.array.toObj( final );
|
|
44
|
+
|
|
45
|
+
}else{
|
|
46
|
+
|
|
47
|
+
// CHECK
|
|
48
|
+
if( ( !key && value ) ){
|
|
49
|
+
console.debug( 'Error: State works in this way: state( key, value ) or only key' );
|
|
50
|
+
void 0;
|
|
51
|
+
|
|
52
|
+
// RETURN
|
|
53
|
+
}else if( key && !value ){
|
|
54
|
+
//return dphelper.state[ key ];
|
|
55
|
+
|
|
56
|
+
// SAVE
|
|
57
|
+
}else if( key && value ){
|
|
58
|
+
|
|
59
|
+
// check if is a function
|
|
60
|
+
if( typeof dphelper?.state[ key ] === 'function' ){
|
|
61
|
+
return `Error, ${ key } is a protect function name`;
|
|
62
|
+
}else{
|
|
63
|
+
// if ok register
|
|
64
|
+
dphelper.state[ key ] = value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// OPTIONS
|
|
74
|
+
this.delete = ( key ) => dphelper.state[ key ] = undefined;
|
|
75
|
+
//thi._deleteAll = () => dphelper.state = [];
|
|
76
|
+
|
|
77
|
+
// SIMPLIFY STATE CALL
|
|
78
|
+
window.state = dphelper.state;
|
|
79
|
+
|
|
80
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
81
|
+
|
|
82
|
+
Object.defineProperty( dphelper, 'state', {
|
|
83
|
+
writable: false,
|
|
84
|
+
configurable: false
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
//console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
|