dphelper 0.2.89 → 0.2.93
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/{LICENSE.txt → LICENSE.md} +0 -0
- package/README.md +6 -0
- package/index.js +2 -12
- package/package.json +130 -136
- package/.editorconfig +0 -13
- package/.env +0 -3
- package/.eslintignore +0 -13
- package/.eslintrc.json +0 -87
- package/.eslintrc.legacy.json +0 -91
- package/.gitattributes +0 -2
- package/.github/FUNDING.yml +0 -12
- package/.github/dependabot.yml +0 -12
- package/.hintrc +0 -11
- package/.jsbeautifyrc +0 -25
- package/.jshintrc +0 -16
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -8
- package/.stylelintignore +0 -0
- package/.stylelintrc.json +0 -468
- package/.vscode/launch.json +0 -34
- package/.vscode/settings.json +0 -58
- package/3party/shortcut.js +0 -224
- package/CHANGELOG.txt +0 -4
- package/SECURITY.md +0 -3
- package/__mocks__/fileMock.js +0 -3
- package/__mocks__/styleMock.js +0 -3
- package/babel.config.js +0 -30
- package/backup.bat +0 -43
- package/coverage/coverage-final.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -101
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -0
- package/data/list.json +0 -19
- package/dist/LICENSE.txt +0 -209
- package/dist/README.md +0 -79
- package/elements/button/component.js +0 -0
- package/elements/code/component.js +0 -0
- package/elements/costants.tsx +0 -13
- package/elements/fieldset/component.js +0 -0
- package/elements/input/checkbox/component.js +0 -0
- package/elements/input/date/component.js +0 -27
- 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 +0 -33
- package/elements/x-foo/namespace.d.ts +0 -7
- package/init.js +0 -87
- package/jest.config.js +0 -81
- package/node/createTag.js +0 -7
- package/node/gitDeploy.js +0 -7
- package/node/goLive.js +0 -7
- package/public/assets/images/banner.png +0 -0
- package/public/assets/logos/logo.svg +0 -64
- package/public/documents/iDB/list.html +0 -11
- package/public/documents/iDB/toState.html +0 -11
- package/scripts/.OLD/import.js +0 -48
- package/scripts/.OLD/onBeforeUnLoad.js +0 -120
- package/scripts/.OLD/purge.js +0 -53
- package/scripts/.OLD/string.js +0 -27
- package/scripts/anchor.js +0 -73
- package/scripts/array.js +0 -203
- package/scripts/avoid.js +0 -48
- package/scripts/browser.js +0 -100
- package/scripts/color.js +0 -121
- package/scripts/console.js +0 -97
- package/scripts/console.mapped.js +0 -160
- package/scripts/coods.js +0 -57
- package/scripts/cookie.js +0 -105
- package/scripts/date.js +0 -179
- package/scripts/disable.js +0 -91
- package/scripts/errors.js +0 -3
- package/scripts/event.js +0 -57
- package/scripts/font.js +0 -60
- package/scripts/form.js +0 -211
- package/scripts/format.js +0 -71
- package/scripts/function.js +0 -55
- package/scripts/iDB.js +0 -688
- package/scripts/json.js +0 -84
- package/scripts/load.js +0 -112
- package/scripts/math.js +0 -100
- package/scripts/obj.js +0 -118
- package/scripts/path.js +0 -101
- package/scripts/promise.js +0 -56
- package/scripts/screen.js +0 -82
- package/scripts/scrollbar.js +0 -293
- package/scripts/shortcut.js +0 -83
- package/scripts/socket.js +0 -184
- package/scripts/state.js +0 -87
- package/scripts/storage.js +0 -93
- package/scripts/store.js +0 -115
- package/scripts/svg.js +0 -380
- package/scripts/text.js +0 -116
- package/scripts/time.js +0 -43
- package/scripts/timer.js +0 -54
- package/scripts/tool.js +0 -73
- package/scripts/trigger.js +0 -57
- package/scripts/type.js +0 -76
- package/scripts/ui.js +0 -41
- package/scripts/window.js +0 -244
- package/styles/console.less +0 -95
- package/tests/setupJest.tsx +0 -4
- package/typings/.OLD/cordova.d.ts +0 -12
- package/typings/.OLD/layerpro.d.ts +0 -20
- package/typings/.OLD/menupro.d.ts +0 -20
- package/typings/dphelper.d.ts +0 -26
- package/typings/image.d.ts +0 -5
- package/typings/styles.d.ts +0 -23
- package/webpack.config.js +0 -249
package/scripts/scrollbar.js
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
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' ) )
|
package/scripts/shortcut.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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' ) )
|
package/scripts/socket.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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' ) )
|