jsgui3-server 0.0.90 → 0.0.91
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.
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const jsgui = require('./square_boxes_client');
|
|
2
|
+
|
|
3
|
+
const {Demo_UI, Square_Box} = jsgui.controls;
|
|
4
|
+
const Server = require('./../../server');
|
|
5
|
+
|
|
6
|
+
// Want to exclude this from the client bundle.
|
|
7
|
+
// Some kind of marking to say that it's server-side only?
|
|
8
|
+
|
|
9
|
+
if (require.main === module) {
|
|
10
|
+
|
|
11
|
+
const server = new Server({
|
|
12
|
+
Ctrl: Demo_UI,
|
|
13
|
+
// Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
|
|
14
|
+
// Putting the JS files through proper parsing and into a syntax tree would be best.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
//'js_mode': 'debug',
|
|
18
|
+
'disk_path_client_js': require.resolve('./square_boxes_client.js')
|
|
19
|
+
//js_client: require.resolve('./square_box.js')
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// A callback or event for when the bundling has been completed
|
|
23
|
+
// a 'ready' event.
|
|
24
|
+
|
|
25
|
+
// then start the server....
|
|
26
|
+
// be able to choose the port / ports?
|
|
27
|
+
console.log('waiting for server ready event');
|
|
28
|
+
server.on('ready', () => {
|
|
29
|
+
console.log('server ready');
|
|
30
|
+
|
|
31
|
+
// server start will change to observable?
|
|
32
|
+
|
|
33
|
+
server.start(8080, function (err, cb_start) {
|
|
34
|
+
if (err) {
|
|
35
|
+
throw err;
|
|
36
|
+
} else {
|
|
37
|
+
// Should have build it by now...
|
|
38
|
+
|
|
39
|
+
console.log('server started');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const jsgui = require('jsgui3-client'); // and will replace this with jsgui-client, I presume.
|
|
2
|
+
const {controls, Control, mixins} = jsgui;
|
|
3
|
+
const {dragable} = mixins;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Square_Box extends Control {
|
|
7
|
+
constructor(spec) {
|
|
8
|
+
spec.__type_name = spec.__type_name || 'square_box';
|
|
9
|
+
super(spec);
|
|
10
|
+
this.add_class('square-box');
|
|
11
|
+
}
|
|
12
|
+
activate() {
|
|
13
|
+
if (!this.__active) {
|
|
14
|
+
super.activate();
|
|
15
|
+
console.log('Activate square box');
|
|
16
|
+
|
|
17
|
+
dragable(this, {
|
|
18
|
+
drag_mode: 'translate'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
//console.log('dragable mixin applied to square');
|
|
22
|
+
this.dragable = true;
|
|
23
|
+
//console.log('this.dragable = true;');
|
|
24
|
+
|
|
25
|
+
this.on('dragend', e => {
|
|
26
|
+
console.log('square box dragend e', e);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Square_Box.css = `
|
|
33
|
+
.square-box {
|
|
34
|
+
background-color: #BB3333;
|
|
35
|
+
width: 220px;
|
|
36
|
+
height: 220px;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// Relies on extracting CSS from JS files.
|
|
42
|
+
|
|
43
|
+
class Demo_UI extends Control {
|
|
44
|
+
constructor(spec) {
|
|
45
|
+
spec.__type_name = spec.__type_name || 'demo_ui';
|
|
46
|
+
super(spec);
|
|
47
|
+
const {context} = this;
|
|
48
|
+
this.add_class('demo-ui');
|
|
49
|
+
|
|
50
|
+
const compose = () => {
|
|
51
|
+
const box = new Square_Box({
|
|
52
|
+
context: context
|
|
53
|
+
})
|
|
54
|
+
this.add(box);
|
|
55
|
+
|
|
56
|
+
const box2 = new Square_Box({
|
|
57
|
+
context: context
|
|
58
|
+
});
|
|
59
|
+
//box2.background_color = '#6655CC';
|
|
60
|
+
//box2.background.color = '#6655CC';
|
|
61
|
+
|
|
62
|
+
// or even box2.color = ... and it would know which color was meant
|
|
63
|
+
// or be able to access the .color reference / property name when asked for.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
box2.dom.attributes.style['background-color'] = '#6655CC';
|
|
67
|
+
this.add(box2);
|
|
68
|
+
|
|
69
|
+
const box3 = new Square_Box({
|
|
70
|
+
context: context
|
|
71
|
+
})
|
|
72
|
+
this.add(box3);
|
|
73
|
+
}
|
|
74
|
+
if (!spec.el) {
|
|
75
|
+
compose();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
activate() {
|
|
79
|
+
if (!this.__active) {
|
|
80
|
+
super.activate();
|
|
81
|
+
const {context} = this;
|
|
82
|
+
|
|
83
|
+
console.log('activate Demo_UI');
|
|
84
|
+
// listen for the context events regarding frames, changes, resizing.
|
|
85
|
+
|
|
86
|
+
context.on('window-resize', e_resize => {
|
|
87
|
+
console.log('window-resize', e_resize);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Include this in bundling.
|
|
95
|
+
// Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
|
|
96
|
+
|
|
97
|
+
//controls.Demo_UI = Demo_UI;
|
|
98
|
+
Demo_UI.css = `
|
|
99
|
+
.demo-ui {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: column;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
align-items: center;
|
|
104
|
+
text-align: center;
|
|
105
|
+
min-height: 100vh;
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
// then if running on the client...?
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//controls.Square_Box = Square_Box;
|
|
114
|
+
// could export jsgui with the updated controls....
|
|
115
|
+
// so that they are in the correct Page Context.?
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
controls.Demo_UI = Demo_UI;
|
|
119
|
+
controls.Square_Box = Square_Box;
|
|
120
|
+
|
|
121
|
+
module.exports = jsgui;
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
module.exports = {
|
|
125
|
+
Square_Box: Square_Box,
|
|
126
|
+
Demo_UI: Demo_UI
|
|
127
|
+
}
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
// Then if window...?
|
|
131
|
+
|
|
132
|
+
// Need to add the Square_Box control to the context or original map of controls...
|
|
133
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const jsgui = require('./grid_1_client');
|
|
2
|
+
|
|
3
|
+
const {Demo_UI, Square_Box} = jsgui.controls;
|
|
4
|
+
const Server = require('../../server');
|
|
5
|
+
|
|
6
|
+
// Want to exclude this from the client bundle.
|
|
7
|
+
// Some kind of marking to say that it's server-side only?
|
|
8
|
+
|
|
9
|
+
if (require.main === module) {
|
|
10
|
+
|
|
11
|
+
const server = new Server({
|
|
12
|
+
Ctrl: Demo_UI,
|
|
13
|
+
// Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
|
|
14
|
+
// Putting the JS files through proper parsing and into a syntax tree would be best.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
//'js_mode': 'debug',
|
|
18
|
+
'disk_path_client_js': require.resolve('./grid_1_client.js')
|
|
19
|
+
//js_client: require.resolve('./square_box.js')
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// A callback or event for when the bundling has been completed
|
|
23
|
+
// a 'ready' event.
|
|
24
|
+
|
|
25
|
+
// then start the server....
|
|
26
|
+
// be able to choose the port / ports?
|
|
27
|
+
console.log('waiting for server ready event');
|
|
28
|
+
server.on('ready', () => {
|
|
29
|
+
console.log('server ready');
|
|
30
|
+
|
|
31
|
+
// server start will change to observable?
|
|
32
|
+
|
|
33
|
+
server.start(8080, function (err, cb_start) {
|
|
34
|
+
if (err) {
|
|
35
|
+
throw err;
|
|
36
|
+
} else {
|
|
37
|
+
// Should have build it by now...
|
|
38
|
+
|
|
39
|
+
console.log('server started');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
const jsgui = require('jsgui3-client'); // and will replace this with jsgui-client, I presume.
|
|
2
|
+
const {controls, Control, mixins} = jsgui;
|
|
3
|
+
const {dragable} = mixins;
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
class Square_Box extends Control {
|
|
7
|
+
constructor(spec) {
|
|
8
|
+
spec.__type_name = spec.__type_name || 'square_box';
|
|
9
|
+
super(spec);
|
|
10
|
+
this.add_class('square-box');
|
|
11
|
+
}
|
|
12
|
+
activate() {
|
|
13
|
+
if (!this.__active) {
|
|
14
|
+
super.activate();
|
|
15
|
+
console.log('Activate square box');
|
|
16
|
+
|
|
17
|
+
dragable(this, {
|
|
18
|
+
drag_mode: 'translate'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
//console.log('dragable mixin applied to square');
|
|
22
|
+
this.dragable = true;
|
|
23
|
+
//console.log('this.dragable = true;');
|
|
24
|
+
|
|
25
|
+
this.on('dragend', e => {
|
|
26
|
+
console.log('square box dragend e', e);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Square_Box.css = `
|
|
33
|
+
.square-box {
|
|
34
|
+
background-color: #BB3333;
|
|
35
|
+
width: 220px;
|
|
36
|
+
height: 220px;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
// Relies on extracting CSS from JS files.
|
|
42
|
+
|
|
43
|
+
const Grid = controls.Grid;
|
|
44
|
+
|
|
45
|
+
class Demo_UI extends Control {
|
|
46
|
+
constructor(spec) {
|
|
47
|
+
spec.__type_name = spec.__type_name || 'demo_ui';
|
|
48
|
+
super(spec);
|
|
49
|
+
const {context} = this;
|
|
50
|
+
this.add_class('demo-ui');
|
|
51
|
+
|
|
52
|
+
const compose = () => {
|
|
53
|
+
|
|
54
|
+
// Would be nice to have a grid / other control that expands to fit available space.
|
|
55
|
+
// Like height and width 100%? May be a bit different in css implementation.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Then indicating how much space it's supposed to take...?
|
|
59
|
+
// Could it automatically size itself depending on space available?
|
|
60
|
+
|
|
61
|
+
const grid = new Grid({
|
|
62
|
+
context: context,
|
|
63
|
+
grid_size: [32, 32],
|
|
64
|
+
cell_size: [10, 10]
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//grid.size = [320, 200];
|
|
68
|
+
|
|
69
|
+
this.add(grid);
|
|
70
|
+
|
|
71
|
+
this._ctrl_fields = this._ctrl_fields || {};
|
|
72
|
+
this._ctrl_fields.grid = grid;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// cell_size property perhaps?
|
|
77
|
+
// cell_size auto?
|
|
78
|
+
|
|
79
|
+
// size: auto for various controls?
|
|
80
|
+
// a 'size' mixin? Autosize mixin?
|
|
81
|
+
|
|
82
|
+
// resizable
|
|
83
|
+
// user-resizable
|
|
84
|
+
|
|
85
|
+
// probably want mixins to represent a fair few behavious that could apply reasonably to different controls.
|
|
86
|
+
// making multi-mode rendering more of a standard too.
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Then if the grid is made flexbox...?
|
|
93
|
+
// A way to make it fill the available space from CSS.
|
|
94
|
+
|
|
95
|
+
// Maybe a mixin to handle more sizing and positioning options?
|
|
96
|
+
// The grid itself autofilling the space may help.
|
|
97
|
+
// Then it can calculate what size to display / render the cells at.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
if (!spec.el) {
|
|
106
|
+
compose();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
activate() {
|
|
110
|
+
if (!this.__active) {
|
|
111
|
+
super.activate();
|
|
112
|
+
const {context, grid} = this;
|
|
113
|
+
|
|
114
|
+
console.log('activate Demo_UI');
|
|
115
|
+
console.log('grid', grid);
|
|
116
|
+
|
|
117
|
+
// .dimensions?
|
|
118
|
+
// Not available yet...?
|
|
119
|
+
// A clearer post-activate time would be best.
|
|
120
|
+
// .do_once_active possibly?
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
console.log('grid.grid_size', grid.grid_size);
|
|
124
|
+
grid.refresh_size();
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// listen for the context events regarding frames, changes, resizing.
|
|
128
|
+
|
|
129
|
+
context.on('window-resize', e_resize => {
|
|
130
|
+
console.log('window-resize', e_resize);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// A delegated click or other event handler may work nicely (for the cells).
|
|
134
|
+
|
|
135
|
+
grid.each_cell(cell => {
|
|
136
|
+
cell.on('click', e_click => {
|
|
137
|
+
//console.log('e_click', e_click);
|
|
138
|
+
//console.log('cell', cell);
|
|
139
|
+
const xy = [cell.x, cell.y];
|
|
140
|
+
//const xy = [cell._.x, cell._.y];
|
|
141
|
+
console.log('xy', xy);
|
|
142
|
+
|
|
143
|
+
if (cell.dom.attributes.style['background-color'] === '#000000') {
|
|
144
|
+
cell.dom.attributes.style['background-color'] = '#FFFFFF';
|
|
145
|
+
} else {
|
|
146
|
+
cell.dom.attributes.style['background-color'] = '#000000';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Include this in bundling.
|
|
158
|
+
// Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
|
|
159
|
+
|
|
160
|
+
//controls.Demo_UI = Demo_UI;
|
|
161
|
+
Demo_UI.css = `
|
|
162
|
+
.demo-ui {
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
justify-content: center;
|
|
166
|
+
align-items: center;
|
|
167
|
+
text-align: center;
|
|
168
|
+
min-height: 100vh;
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
// then if running on the client...?
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
//controls.Square_Box = Square_Box;
|
|
177
|
+
// could export jsgui with the updated controls....
|
|
178
|
+
// so that they are in the correct Page Context.?
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
controls.Demo_UI = Demo_UI;
|
|
182
|
+
//controls.Square_Box = Square_Box;
|
|
183
|
+
|
|
184
|
+
module.exports = jsgui;
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
module.exports = {
|
|
188
|
+
Square_Box: Square_Box,
|
|
189
|
+
Demo_UI: Demo_UI
|
|
190
|
+
}
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
// Then if window...?
|
|
194
|
+
|
|
195
|
+
// Need to add the Square_Box control to the context or original map of controls...
|
|
196
|
+
|
package/package.json
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"cookies": "^0.8.0",
|
|
14
14
|
"fnl": "^0.0.22",
|
|
15
15
|
"fnlfs": "^0.0.25",
|
|
16
|
-
"jsgui3-client": "^0.0.
|
|
17
|
-
"jsgui3-html": "0.0.
|
|
16
|
+
"jsgui3-client": "^0.0.73",
|
|
17
|
+
"jsgui3-html": "0.0.100",
|
|
18
18
|
"multiparty": "^4.2.3",
|
|
19
19
|
"ncp": "^2.0.0",
|
|
20
20
|
"obext": "0.0.24",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "https://github.com/metabench/jsgui3-server.git"
|
|
42
42
|
},
|
|
43
|
-
"version": "0.0.
|
|
43
|
+
"version": "0.0.91"
|
|
44
44
|
}
|