jsgui3-server 0.0.90 → 0.0.92

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,329 @@
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 {press_events} = jsgui.mixins;
44
+
45
+ const Grid = controls.Grid;
46
+
47
+ class Demo_UI extends Control {
48
+ constructor(spec) {
49
+ spec.__type_name = spec.__type_name || 'demo_ui';
50
+ super(spec);
51
+ const {context} = this;
52
+ this.add_class('demo-ui');
53
+
54
+ const compose = () => {
55
+
56
+ // Would be nice to have a grid / other control that expands to fit available space.
57
+ // Like height and width 100%? May be a bit different in css implementation.
58
+
59
+
60
+ // Then indicating how much space it's supposed to take...?
61
+ // Could it automatically size itself depending on space available?
62
+
63
+ const grid = new Grid({
64
+ context: context,
65
+ grid_size: [32, 32],
66
+ cell_size: [10, 10]
67
+ });
68
+
69
+ //grid.size = [320, 200];
70
+
71
+ this.add(grid);
72
+
73
+ this._ctrl_fields = this._ctrl_fields || {};
74
+ this._ctrl_fields.grid = grid;
75
+
76
+
77
+
78
+ // cell_size property perhaps?
79
+ // cell_size auto?
80
+
81
+ // size: auto for various controls?
82
+ // a 'size' mixin? Autosize mixin?
83
+
84
+ // resizable
85
+ // user-resizable
86
+
87
+ // probably want mixins to represent a fair few behavious that could apply reasonably to different controls.
88
+ // making multi-mode rendering more of a standard too.
89
+
90
+
91
+
92
+
93
+
94
+ // Then if the grid is made flexbox...?
95
+ // A way to make it fill the available space from CSS.
96
+
97
+ // Maybe a mixin to handle more sizing and positioning options?
98
+ // The grid itself autofilling the space may help.
99
+ // Then it can calculate what size to display / render the cells at.
100
+
101
+
102
+
103
+
104
+
105
+
106
+ }
107
+ if (!spec.el) {
108
+ compose();
109
+ }
110
+ }
111
+ activate() {
112
+ if (!this.__active) {
113
+ super.activate();
114
+ const {context, grid} = this;
115
+
116
+ console.log('activate Demo_UI');
117
+ console.log('grid', grid);
118
+
119
+ // .dimensions?
120
+ // Not available yet...?
121
+ // A clearer post-activate time would be best.
122
+ // .do_once_active possibly?
123
+
124
+
125
+ console.log('grid.grid_size', grid.grid_size);
126
+ grid.refresh_size();
127
+
128
+ press_events(grid);
129
+
130
+ // the grid press start should contain the cell.
131
+ // that is the specific kind of API improvement that helps the grid with customised specific events.
132
+
133
+ // This is having trouble on iOS with touch events.
134
+
135
+ // Better ways to check which cell is being pressed?
136
+ // Seems like we don't get the new cell upon the touch move event.
137
+
138
+ // Pressing and moving to a different ctrl / cell not working on iOS mobile safari.
139
+
140
+ // Maybe improve grid painting for iOS?
141
+ // Maybe improve the 'move on grid' event handlings?
142
+
143
+ // Maybe press events isn't the best way?
144
+ // Or need better handling of iOS within press events even?
145
+ // Determining grid square by the coordinates would be possible if there is a rendering model.
146
+ // Maybe further work within mixins.
147
+ // Maybe within grid / grid mixins.
148
+
149
+ // More work within Grid to better enable cell retrieval?
150
+ // And then specific work on grid press events?
151
+
152
+
153
+
154
+ const setup_grid_painting = () => {
155
+
156
+ // ctrl_target maybe is not stable accross all devices and browsers.
157
+ // Could be better to get some lower level things working right....
158
+
159
+ let paint_color = '#000000';
160
+ grid.on('press-start', e => {
161
+ //console.log('grid press-start ', e);
162
+ const {ctrl_target} = e;
163
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
164
+
165
+ // grid.get_cell_at_px_coords([xpx, ypx]);
166
+ // grid.get_cell_at_pos([x, y]);
167
+
168
+ //console.log('[x, y]', [x, y]);
169
+
170
+ // the colour of the cell there at start determines colour of paint brush?
171
+ // will be best to incorporate painting / grid painting code into the mixins?
172
+ // probably only a few lines of code for the right API.
173
+
174
+ if (ctrl_target.dom.attributes.style['background-color'] === '#000000') {
175
+ paint_color = '#FFFFFF';
176
+ } else {
177
+ paint_color = '#000000';
178
+ }
179
+ ctrl_target.dom.attributes.style['background-color'] = paint_color;
180
+
181
+ e.preventDefault();
182
+ });
183
+
184
+ // and that would be a press-grid-move? press-gridcell-move?
185
+ // this is just a place to set up and test different behaviours for grid ui.
186
+ // may have things like area fills, or select area.
187
+
188
+ let lastx, lasty;
189
+ grid.on('press-move', e => {
190
+
191
+ // Not getting the expeced ctrl_target that is right under the movement touch event on iOS.
192
+ // Could we get the specific cell by using its display coords to determine which cell it is over?
193
+
194
+ // Gets the right pixel coords from the event for this.
195
+
196
+
197
+ console.log('grid press-move ', e);
198
+
199
+ // Not working right on iOS. Not detecting which cell is directly underneith.
200
+ const {ctrl_target} = e;
201
+ //const {ctrl} = e;
202
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
203
+
204
+ if (x !== lastx || y !== lasty) {
205
+ grid.raise('press-cell-move', e);
206
+ }
207
+
208
+ //console.log('[x, y]', [x, y]);
209
+ lastx = x;
210
+ lasty = y;
211
+
212
+ //e.preventDefault();
213
+ });
214
+
215
+ grid.on('press-cell-move', e => {
216
+ const {ctrl_target} = e;
217
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
218
+ //console.log('press-cell-move [x, y]', [x, y]);
219
+ ctrl_target.dom.attributes.style['background-color'] = paint_color;
220
+ });
221
+ }
222
+ setup_grid_painting();
223
+
224
+
225
+
226
+ // 'press-move'
227
+
228
+
229
+ // listen for the context events regarding frames, changes, resizing.
230
+
231
+ context.on('window-resize', e_resize => {
232
+ console.log('window-resize', e_resize);
233
+ });
234
+
235
+ // A delegated click or other event handler may work nicely (for the cells).
236
+
237
+ // Could use press events to deal with events more smoothly?
238
+ // A grid-events mixin?
239
+ // Want to make high quality and specific code that is outside of the grid js component.
240
+ // More swappable, composable, and upgradable components.
241
+
242
+ // More functionality within the mixins makes sense.
243
+ // Mixins as interfaces too.
244
+
245
+ // grid.enable(Drag_Box)
246
+ // or similar.
247
+ // grid.mx_grid_press_ui possibly.
248
+ // details of ui handling behavious moving out of the controls themselves.
249
+ // more general within the mixins.
250
+
251
+ // grid.on('drag-over') or similar.
252
+ // specialised events within the appropriate mixins.
253
+ // could try them here first though?
254
+
255
+ // a different box-area-select mixin? or just a bit different when on a grid...?
256
+ // may need to repeat code a little, but code will be simple at the app level at least.
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+ grid.each_cell(cell => {
266
+
267
+ /*
268
+ cell.on('click', e_click => {
269
+ //console.log('e_click', e_click);
270
+ //console.log('cell', cell);
271
+ const xy = [cell.x, cell.y];
272
+ //const xy = [cell._.x, cell._.y];
273
+ console.log('xy', xy);
274
+
275
+ if (cell.dom.attributes.style['background-color'] === '#000000') {
276
+ cell.dom.attributes.style['background-color'] = '#FFFFFF';
277
+ } else {
278
+ cell.dom.attributes.style['background-color'] = '#000000';
279
+ }
280
+
281
+
282
+ })
283
+ */
284
+ })
285
+
286
+ }
287
+ }
288
+ }
289
+
290
+ // Include this in bundling.
291
+ // Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
292
+
293
+ //controls.Demo_UI = Demo_UI;
294
+ Demo_UI.css = `
295
+ .demo-ui {
296
+ display: flex;
297
+ flex-direction: column;
298
+ justify-content: center;
299
+ align-items: center;
300
+ text-align: center;
301
+ min-height: 100vh;
302
+ }
303
+ `;
304
+
305
+ // then if running on the client...?
306
+
307
+
308
+
309
+ //controls.Square_Box = Square_Box;
310
+ // could export jsgui with the updated controls....
311
+ // so that they are in the correct Page Context.?
312
+
313
+
314
+ controls.Demo_UI = Demo_UI;
315
+ //controls.Square_Box = Square_Box;
316
+
317
+ module.exports = jsgui;
318
+
319
+ /*
320
+ module.exports = {
321
+ Square_Box: Square_Box,
322
+ Demo_UI: Demo_UI
323
+ }
324
+ */
325
+
326
+ // Then if window...?
327
+
328
+ // Need to add the Square_Box control to the context or original map of controls...
329
+
@@ -0,0 +1,46 @@
1
+ const jsgui = require('./mx_display_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('./mx_display_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,444 @@
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 {press_events} = jsgui.mixins;
44
+
45
+ const Grid = controls.Grid;
46
+
47
+ class Demo_UI extends Control {
48
+ constructor(spec) {
49
+ spec.__type_name = spec.__type_name || 'demo_ui';
50
+ super(spec);
51
+ const {context} = this;
52
+ this.add_class('demo-ui');
53
+
54
+ const compose = () => {
55
+
56
+ // Would be nice to have a grid / other control that expands to fit available space.
57
+ // Like height and width 100%? May be a bit different in css implementation.
58
+
59
+
60
+ // Then indicating how much space it's supposed to take...?
61
+ // Could it automatically size itself depending on space available?
62
+
63
+ // Grid should use the 'display' mixin by default?
64
+ // display_modes may be a better name after all.
65
+ //
66
+
67
+ // Have Grid and other controls able to adaptively choose / grow to a size.
68
+ // Could that be css flexbox though?
69
+
70
+ // cell size being content item size.
71
+ //
72
+
73
+ const grid = new Grid({
74
+ context: context,
75
+ grid_size: [32, 32],
76
+ cell_size: [10, 10]
77
+ });
78
+
79
+ //grid.size = [320, 200];
80
+
81
+ this.add(grid);
82
+
83
+ this._ctrl_fields = this._ctrl_fields || {};
84
+ this._ctrl_fields.grid = grid;
85
+
86
+ // cell_size property perhaps?
87
+ // cell_size auto?
88
+
89
+ // Want basic usage of .display mixin...
90
+ // display_mode may well be the better name....
91
+ // display.mode makes sense though!
92
+
93
+ // mx display makes a lot of sense for higher level display properties and functionality.
94
+ // or even .ui rather than display?
95
+
96
+ // .ui mixin perhaps?
97
+ // easy naming.
98
+ // .ui and .data
99
+ // so a control represents actual data (model in mvc)
100
+ // .view perhaps?
101
+ // .model even?
102
+
103
+ // Could move towards some MVC naming fundamentals.
104
+ // It would be as a higher level then some core things like CSS.
105
+ // .data = .model probably.
106
+
107
+ // the .mvc or .mv 'overhaul' mixin should come.
108
+ // .model could / should refer to a part of a larger model.
109
+ // the data being represented by the control.
110
+
111
+ // view.editable property could be standard.
112
+ // as in user_editable possibly.
113
+
114
+ // Dividing into .model and .view could make sense.
115
+ // view.dom.attributes for example
116
+ // of course there can be models of the view.
117
+
118
+ // ctrl.model would (always?) hold and represent the core data.
119
+ // class Model_Data_Access
120
+ // full_model
121
+ // access_path (string???)
122
+ // part of model (model for that control)
123
+
124
+ // model = {text: 'hello'}
125
+ // then the view we tell it to display the text (maybe it knows to do that, or its one very simple setting.)
126
+
127
+ // Even make a Control_View component?
128
+ // That seemed to be what the Control was before?
129
+ // Being more explicit about referencing the View may help.
130
+ // Especially with different view / display modes.
131
+
132
+ // Also, keeping control data model logic while changing view logic...?
133
+ // Keeping code separate should help with upgradability.
134
+
135
+ // .model.data_type for example.
136
+ // such as date.
137
+ // or some types / structs which have definitions.
138
+
139
+ // Then when making a View, we can specify that it only works for a set data_type
140
+ // Then different implementations could compete / be compared.
141
+
142
+ // Editors for specific data types, only supposed to or designed to work to edit a limited range of data.
143
+ // Enforced programatically.
144
+ // Have a schema of the data or something like it.
145
+ // Then with the data defined, an editor could be put together programatically automatically.
146
+ // May be a bit of a rudimentary / unflexible one but may be useful.
147
+
148
+ // UI components for viewing and editing data
149
+ // Could / should start with some really simple types of data
150
+ // Need data type definitions within the code so that the editiors know what to do.
151
+ // Could have them within JSON of course.
152
+
153
+ // Max number, min number, integers only, etc...
154
+
155
+ // so .view rather than .display probably...
156
+ // .controller even could refer to various algorithms / hooks that get used when connecting the model and the view.
157
+ // may be possible to use the control without accessing control.controller?
158
+ // or the control itself is the controller?
159
+ // .controller may make sense for accessing some properties.
160
+
161
+ // const [mvc] = ctrl.mvc for example.
162
+ //
163
+
164
+ // Doing this more gradually...?
165
+ // Where properties may have two means of accessing them?
166
+ // or move some lower level view things into .view perhaps.
167
+
168
+
169
+ // making .view as a mixin perhaps...?
170
+ // could make some of the functions more universally callable perhaps?
171
+ // not so sure about performance when used so widely. Could still make good use of prototypes somehow though.
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ // size: auto for various controls?
197
+ // a 'size' mixin? Autosize mixin?
198
+
199
+ // resizable
200
+ // user-resizable
201
+
202
+ // probably want mixins to represent a fair few behavious that could apply reasonably to different controls.
203
+ // making multi-mode rendering more of a standard too.
204
+
205
+
206
+
207
+
208
+
209
+ // Then if the grid is made flexbox...?
210
+ // A way to make it fill the available space from CSS.
211
+
212
+ // Maybe a mixin to handle more sizing and positioning options?
213
+ // The grid itself autofilling the space may help.
214
+ // Then it can calculate what size to display / render the cells at.
215
+
216
+
217
+
218
+
219
+
220
+
221
+ }
222
+ if (!spec.el) {
223
+ compose();
224
+ }
225
+ }
226
+ activate() {
227
+ if (!this.__active) {
228
+ super.activate();
229
+ const {context, grid} = this;
230
+
231
+ console.log('activate Demo_UI');
232
+ console.log('grid', grid);
233
+
234
+ // .dimensions?
235
+ // Not available yet...?
236
+ // A clearer post-activate time would be best.
237
+ // .do_once_active possibly?
238
+
239
+
240
+ console.log('grid.grid_size', grid.grid_size);
241
+ grid.refresh_size();
242
+
243
+ press_events(grid);
244
+
245
+ // the grid press start should contain the cell.
246
+ // that is the specific kind of API improvement that helps the grid with customised specific events.
247
+
248
+ // This is having trouble on iOS with touch events.
249
+
250
+ // Better ways to check which cell is being pressed?
251
+ // Seems like we don't get the new cell upon the touch move event.
252
+
253
+ // Pressing and moving to a different ctrl / cell not working on iOS mobile safari.
254
+
255
+ // Maybe improve grid painting for iOS?
256
+ // Maybe improve the 'move on grid' event handlings?
257
+
258
+ // Maybe press events isn't the best way?
259
+ // Or need better handling of iOS within press events even?
260
+ // Determining grid square by the coordinates would be possible if there is a rendering model.
261
+ // Maybe further work within mixins.
262
+ // Maybe within grid / grid mixins.
263
+
264
+ // More work within Grid to better enable cell retrieval?
265
+ // And then specific work on grid press events?
266
+
267
+
268
+
269
+ const setup_grid_painting = () => {
270
+
271
+ // ctrl_target maybe is not stable accross all devices and browsers.
272
+ // Could be better to get some lower level things working right....
273
+
274
+ let paint_color = '#000000';
275
+ grid.on('press-start', e => {
276
+ //console.log('grid press-start ', e);
277
+ const {ctrl_target} = e;
278
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
279
+
280
+ // grid.get_cell_at_px_coords([xpx, ypx]);
281
+ // grid.get_cell_at_pos([x, y]);
282
+
283
+ //console.log('[x, y]', [x, y]);
284
+
285
+ // the colour of the cell there at start determines colour of paint brush?
286
+ // will be best to incorporate painting / grid painting code into the mixins?
287
+ // probably only a few lines of code for the right API.
288
+
289
+ if (ctrl_target.dom.attributes.style['background-color'] === '#000000') {
290
+ paint_color = '#FFFFFF';
291
+ } else {
292
+ paint_color = '#000000';
293
+ }
294
+ ctrl_target.dom.attributes.style['background-color'] = paint_color;
295
+
296
+ e.preventDefault();
297
+ });
298
+
299
+ // and that would be a press-grid-move? press-gridcell-move?
300
+ // this is just a place to set up and test different behaviours for grid ui.
301
+ // may have things like area fills, or select area.
302
+
303
+ let lastx, lasty;
304
+ grid.on('press-move', e => {
305
+
306
+ // Not getting the expeced ctrl_target that is right under the movement touch event on iOS.
307
+ // Could we get the specific cell by using its display coords to determine which cell it is over?
308
+
309
+ // Gets the right pixel coords from the event for this.
310
+
311
+
312
+ console.log('grid press-move ', e);
313
+
314
+ // Not working right on iOS. Not detecting which cell is directly underneith.
315
+ const {ctrl_target} = e;
316
+ //const {ctrl} = e;
317
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
318
+
319
+ if (x !== lastx || y !== lasty) {
320
+ grid.raise('press-cell-move', e);
321
+ }
322
+
323
+ //console.log('[x, y]', [x, y]);
324
+ lastx = x;
325
+ lasty = y;
326
+
327
+ //e.preventDefault();
328
+ });
329
+
330
+ grid.on('press-cell-move', e => {
331
+ const {ctrl_target} = e;
332
+ const [x, y] = [ctrl_target.x, ctrl_target.y];
333
+ //console.log('press-cell-move [x, y]', [x, y]);
334
+ ctrl_target.dom.attributes.style['background-color'] = paint_color;
335
+ });
336
+ }
337
+ setup_grid_painting();
338
+
339
+
340
+
341
+ // 'press-move'
342
+
343
+
344
+ // listen for the context events regarding frames, changes, resizing.
345
+
346
+ context.on('window-resize', e_resize => {
347
+ console.log('window-resize', e_resize);
348
+ });
349
+
350
+ // A delegated click or other event handler may work nicely (for the cells).
351
+
352
+ // Could use press events to deal with events more smoothly?
353
+ // A grid-events mixin?
354
+ // Want to make high quality and specific code that is outside of the grid js component.
355
+ // More swappable, composable, and upgradable components.
356
+
357
+ // More functionality within the mixins makes sense.
358
+ // Mixins as interfaces too.
359
+
360
+ // grid.enable(Drag_Box)
361
+ // or similar.
362
+ // grid.mx_grid_press_ui possibly.
363
+ // details of ui handling behavious moving out of the controls themselves.
364
+ // more general within the mixins.
365
+
366
+ // grid.on('drag-over') or similar.
367
+ // specialised events within the appropriate mixins.
368
+ // could try them here first though?
369
+
370
+ // a different box-area-select mixin? or just a bit different when on a grid...?
371
+ // may need to repeat code a little, but code will be simple at the app level at least.
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+ grid.each_cell(cell => {
381
+
382
+ /*
383
+ cell.on('click', e_click => {
384
+ //console.log('e_click', e_click);
385
+ //console.log('cell', cell);
386
+ const xy = [cell.x, cell.y];
387
+ //const xy = [cell._.x, cell._.y];
388
+ console.log('xy', xy);
389
+
390
+ if (cell.dom.attributes.style['background-color'] === '#000000') {
391
+ cell.dom.attributes.style['background-color'] = '#FFFFFF';
392
+ } else {
393
+ cell.dom.attributes.style['background-color'] = '#000000';
394
+ }
395
+
396
+
397
+ })
398
+ */
399
+ })
400
+
401
+ }
402
+ }
403
+ }
404
+
405
+ // Include this in bundling.
406
+ // Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
407
+
408
+ //controls.Demo_UI = Demo_UI;
409
+ Demo_UI.css = `
410
+ .demo-ui {
411
+ display: flex;
412
+ flex-direction: column;
413
+ justify-content: center;
414
+ align-items: center;
415
+ text-align: center;
416
+ min-height: 100vh;
417
+ }
418
+ `;
419
+
420
+ // then if running on the client...?
421
+
422
+
423
+
424
+ //controls.Square_Box = Square_Box;
425
+ // could export jsgui with the updated controls....
426
+ // so that they are in the correct Page Context.?
427
+
428
+
429
+ controls.Demo_UI = Demo_UI;
430
+ //controls.Square_Box = Square_Box;
431
+
432
+ module.exports = jsgui;
433
+
434
+ /*
435
+ module.exports = {
436
+ Square_Box: Square_Box,
437
+ Demo_UI: Demo_UI
438
+ }
439
+ */
440
+
441
+ // Then if window...?
442
+
443
+ // Need to add the Square_Box control to the context or original map of controls...
444
+
package/package.json CHANGED
@@ -3,18 +3,18 @@
3
3
  "main": "module.js",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@babel/core": "^7.17.9",
7
- "@babel/generator": "^7.17.9",
8
- "@babel/parser": "7.17.9",
6
+ "@babel/core": "^7.19.1",
7
+ "@babel/generator": "^7.19.0",
8
+ "@babel/parser": "7.19.1",
9
9
  "babel-plugin-transform-runtime": "^6.23.0",
10
- "babel-preset-minify": "^0.5.1",
10
+ "babel-preset-minify": "^0.5.2",
11
11
  "browserify": "17.0.0",
12
12
  "child-process": "^1.0.2",
13
13
  "cookies": "^0.8.0",
14
14
  "fnl": "^0.0.22",
15
15
  "fnlfs": "^0.0.25",
16
- "jsgui3-client": "^0.0.72",
17
- "jsgui3-html": "0.0.99",
16
+ "jsgui3-client": "^0.0.73",
17
+ "jsgui3-html": "0.0.102",
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.90"
43
+ "version": "0.0.92"
44
44
  }