jsgui3-server 0.0.115 → 0.0.117

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.
@@ -152,26 +152,44 @@ class Demo_UI extends Active_HTML_Document {
152
152
  // Automatically avoiding feedback somehow???
153
153
  // If it gets changed to its current value it does not push the change...?
154
154
 
155
+ // on the data model change instead....
155
156
 
156
- ti1.on('change', e => {
157
+
158
+ // Code has got more complex supporting things by data model changes for the moment.
159
+ // May help a lot when making it more explicit.
160
+
161
+
162
+
163
+ // But could make 'on' (normally?) refer to the .data.model???
164
+ // For the moment, keep the more explicit notations, as well as backwards compatibility.
165
+
166
+ // ctrl.dom.on may help, be a nicer and more concise syntax, just as explicit (considering the 'on' abbreviatrion)
167
+
168
+
169
+ // does seem convenient having .on refer to dom events if it's an appropriate event name for that.
170
+
171
+
172
+
173
+
174
+ ti1.data.model.on('change', e => {
157
175
  //console.log('ti1 change e', e);
158
176
 
159
177
  if (e.value !== e.old) {
160
- ti2.value = e.value;
178
+ ti2.data.model.value = e.value;
161
179
  }
162
180
 
163
181
 
164
182
 
165
- })
166
- ti2.on('change', e => {
183
+ });
184
+ ti2.data.model.on('change', e => {
167
185
  //console.log('ti2 change e', e);
168
186
 
169
187
  if (e.value !== e.old) {
170
- ti1.value = e.value;
188
+ ti1.data.model.value = e.value;
171
189
  }
172
190
 
173
191
 
174
- })
192
+ });
175
193
 
176
194
  // listen for change events.
177
195
  // would be nice to know which change events originated from the user interacting with that specific HTML element (or ctrl???)
@@ -12,6 +12,105 @@ const Active_HTML_Document = require('../../../controls/Active_HTML_Document');
12
12
  // May want code that checks for .el being changed.
13
13
 
14
14
 
15
+ /*
16
+ Though this works through simple principles, it may be much better to do data binding with a shared ctrl.data.model.
17
+ Want the top-level code to be really simple and intuitive when specifying data flows, and when not specifying them
18
+ using sensible defaults.
19
+
20
+ The granularity between data.model and view.model should help a lot.
21
+
22
+ // Also data.model.value being a possible default.
23
+ // Data models will become more advanced and capable of holding multiple values.
24
+ // For the moment, although the Control_Data and Control_View classes exist, will continue with a POJO.
25
+ // Then could later work on getter / setters for when a data.model or a view.model gets changed.
26
+
27
+
28
+
29
+ Also should work on functional constraints or / and class based constraints for fields / text fields.
30
+ // Both for data in the system, as well as in the UI.
31
+ // Could integrate a bit more with data types / class data types.
32
+
33
+ // Typed_Data_Value perhaps.
34
+
35
+ // Anyway, want to set things up better with the .view.model and .data.model system.
36
+
37
+ // Then later support more complex (and / or app-defined) data and view models.
38
+
39
+ // Defining what the underlying data of the app is could help (a lot).
40
+ // Some data may be for editing, some not.
41
+
42
+ // A data model could have a bunch of news articles, and be set up so that they can be viewed nicely.
43
+ // Would not be so important to edit the articles themselves, though maybe the user may want to tag them
44
+ // and comment on them.
45
+
46
+ // Mid-level complexity handling a fair bit of what needs to happen with multiple models, how updates get sequenced
47
+ // but then at a high level code must be really simple.
48
+ // Could distinguish between view and data models at high level - may help a lot in some cases.
49
+ // However, will generally assume a shared data model between controls, not a shared view model, and the data model
50
+ // will be updated with at least some small / sensible hesitation.
51
+ // Maybe even define the update hesitations / update hesitation mode.
52
+ // Data Model Update Hesitation Mode???
53
+
54
+ // View Model To Data Model Syncing Update Hesitation Mode???
55
+ // really explicit names on the more complex mid level will help the code and system to make sense.
56
+
57
+ // syncing.view_to_data.hesitation = 'leave-control' ????
58
+ // And could have that one as the default.
59
+ // Or could hesitate / debounce 250ms for example.
60
+ // Very very explicit on the more complex mid / lower level, so that it's really simple on the higher level,
61
+ // and can (quickly?) get into more explicit details when needed.
62
+
63
+ // Data model syncing seems best in general.
64
+ // Then sync data model changes immediately to view models.
65
+ // Then only sync view model changes to data model after necessary hesitation / event / confirmation.
66
+ // Also be able to cancel view model changes (load values back from data model possibly, some contexts makes a lot more sense)
67
+
68
+
69
+ // The view model is essentially internal to the control - though maybe it would integrate with a whole Page_Context view
70
+ // model that's for all the controls...?
71
+
72
+ // Internal and separate view models for the controls seems best for the moment.
73
+ // Could always use refs to some place else.
74
+
75
+ // Have the controls automatically create their view model.
76
+
77
+ // Some controls should not determine the data model at application (or larger control) start.
78
+ // Maybe some should?
79
+
80
+ // Or better to change it so that the Data_Model gets set first, then all the controls given access to it at start (on server)
81
+ // and get rendered on the server with the correct data, then on the client it only sets the view_model at the start.
82
+ // Or does it???
83
+ // Want different sensible options for getting that Data_Model to the client. Maybe getting the View_Model to the client????
84
+
85
+ // Make it simple and easy to code on the top level API.
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ */
113
+
15
114
 
16
115
 
17
116
 
@@ -65,45 +164,20 @@ class Demo_UI extends Active_HTML_Document {
65
164
 
66
165
  window.size = [480, 160];
67
166
 
68
- // Have Tab_Page items inside???
167
+ // Without specifying the data model.
168
+ // Should be able to use and refer to data and view models even when not specified.
169
+ // Want this complexity on the lower level to enable simple (but not overly simple/simplstic) higher level programming.
69
170
 
70
- // Setting a 'selectable' property at the composition stage could be very helpful in some cases,
71
- // May want composition-level mixins?
72
- // Maybe those mixins would also have code that runs on activation.
73
- // 'compositional mixins' ???
74
171
 
75
- // Need mixins to be very flexible to avoid the probles React had with them.
76
- // Choose what functionality the mixin provides in some cases.
77
- // Need to keep tight control over the coupling of mixins.
78
- // Each mixin may need to be somewhat complex to avoid hiccups - and to consistently act in the set modes.
79
- // If a mixin is to do something different to before that functionality should be called differently.
80
-
81
- // mixin.enabled_feature_sets = [feature_set_1_name, feature_set_2_name] ....
82
-
83
-
84
-
85
- // Will work on more options & perfection for month_view.
86
-
87
- /*
88
-
89
- new Checkbox({
90
- context,
91
- label: {
92
- text: 'A checkbox'
93
- }
94
- })
95
-
96
- */
97
-
98
- // Sensible properties like this will help.
99
-
100
- // A progressively enhancing control could help a lot.
101
- // Something that when it's in the doc will even replace its own element.
102
- // Lower level code to enable really simple to express progressive enhancement could help, maybe would not be needed.
103
172
 
173
+ // Should set up its data model automatically if not specified here.
174
+ // An independent data model, specifically for that text field.
104
175
 
176
+ // Or in the data.model.label_text perhaps?
105
177
 
178
+ // Want to make it easy to make and use somewhat more complex and expressive structures.
106
179
 
180
+ // The text label makes more sense being in the view.data.model???
107
181
 
108
182
  const ti1 = new Text_Field({
109
183
  context,
@@ -131,20 +205,86 @@ class Demo_UI extends Active_HTML_Document {
131
205
 
132
206
 
133
207
  this._ctrl_fields = this._ctrl_fields || {};
134
- this._ctrl_fields.ti1 = ti1;
135
- this._ctrl_fields.ti2 = ti2;
208
+ this._ctrl_fields.ti1 = this.ti1 = ti1;
209
+ this._ctrl_fields.ti2 = this.ti2 = ti2;
136
210
 
137
211
 
138
212
  }
139
213
  if (!spec.el) {
140
214
  compose();
215
+ this.add_change_listeners();
141
216
  }
217
+
218
+
219
+ // Can respond to / deal with changes to the data models here, not only when activated.
220
+ // The data.model and view.model system seems to offer some higher level improved programming by putting
221
+ // more in the constructor. Maybe the activated code ('.activate') would not be needed on higher level controls,
222
+ // because the lower level ones will connect it all up the the dom <> view <> data models / system.
223
+
224
+ // It even has a 'dom model' too, of sorts ????
225
+ // Though currently it's not named that or considered that throughout the code there.
226
+ // Could be worth moding to dom.model
227
+ // then view.model
228
+ // then data.model
229
+
230
+ // Could be a structure that better supports non-dom models.
231
+ // Though in this case, it would no yet have the refs to all the child things????
232
+
233
+ // Getting that back in the 'compose' or 'recompose' stage could help.
234
+ // Though it's currently auto-recompose pre activate.
235
+
236
+ // Maybe want code to run either when activated, or post-compose.
237
+ // add_change_listeners.
238
+
239
+ // Would be run server-side after compose (or when composing it like that on the client)
240
+ // but when it gets recomosed on the client-side would need to run then instead.
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
142
251
  }
252
+
253
+ add_change_listeners() {
254
+ const {ti1, ti2} = this;
255
+
256
+ // Need to fix the text_field data model and view model system.
257
+
258
+ //console.log('add_change_listeners');
259
+ ti1.data.model.on('change', e => {
260
+ //console.log('ti1 e', e);
261
+ if (e.name === 'value') {
262
+ if (e.value !== e.old) {
263
+ ti2.data.model.value = e.value;
264
+ }
265
+ }
266
+ });
267
+
268
+ ti2.data.model.on('change', e => {
269
+ //console.log('ti2 e', e);
270
+ if (e.name === 'value') {
271
+ if (e.value !== e.old) {
272
+ ti1.data.model.value = e.value;
273
+ }
274
+ }
275
+ });
276
+
277
+ }
278
+
279
+
143
280
  activate() {
144
281
  if (!this.__active) {
145
282
  super.activate();
146
283
  const {context, ti1, ti2} = this;
147
284
 
285
+ this.add_change_listeners();
286
+
287
+
148
288
  console.log('activate Demo_UI');
149
289
  // and events dealing with changes to those tis.
150
290
 
@@ -183,13 +323,21 @@ class Demo_UI extends Active_HTML_Document {
183
323
 
184
324
  // Need to work on having it update the dom with value changes....
185
325
 
186
- ti1.view.model.on('change', e => {
187
- //console.log('ti1 change e', e);
326
+ // .data.model change instead.
327
+ // referring to a .data.model does seem like a more explicit way to do it.
328
+ // definitely looks like a good way to avoid confusion, at a small cost of more code to write.
329
+
330
+ /*
331
+
332
+ ti1.data.model.on('change', e => {
333
+ console.log('ti1.data.model change e', e);
334
+
335
+
188
336
 
189
337
 
190
- if (e.property_name === 'value') {
338
+ if (e.name === 'value') {
191
339
  if (e.value !== e.old) {
192
- ti2.value = e.value;
340
+ ti2.data.model.value = e.value;
193
341
  }
194
342
  }
195
343
 
@@ -199,17 +347,22 @@ class Demo_UI extends Active_HTML_Document {
199
347
 
200
348
 
201
349
  })
202
- ti2.view.model.on('change', e => {
203
- //console.log('ti2 change e', e);
350
+ ti2.data.model.on('change', e => {
351
+ console.log('ti2.data.model change e', e);
204
352
 
205
353
  //
206
354
 
207
- if (e.value !== e.old) {
208
- ti1.value = e.value;
355
+ if (e.name === 'value') {
356
+ if (e.value !== e.old) {
357
+ ti1.data.model.value = e.value;
358
+ }
209
359
  }
210
360
 
211
361
 
362
+
363
+
212
364
  })
365
+ */
213
366
 
214
367
  // listen for change events.
215
368
  // would be nice to know which change events originated from the user interacting with that specific HTML element (or ctrl???)
@@ -0,0 +1,585 @@
1
+ const jsgui = require('jsgui3-client');
2
+ const {controls, Control, mixins, Data_Object} = jsgui;
3
+ const {dragable} = mixins;
4
+
5
+ const {field} = require('obext');
6
+
7
+ const {Checkbox, Date_Picker, Text_Input, Text_Field} = controls;
8
+
9
+ const Active_HTML_Document = require('../../../controls/Active_HTML_Document');
10
+
11
+ // Will make Date_Picker use progressive enhancement.
12
+ // On activation would create a new element? Create a new sibling?
13
+ // May want code that checks for .el being changed.
14
+
15
+
16
+
17
+ // Want the data sharing to be really simple and intuitive to set up.
18
+ // But not so simple the comlexities of data flow can't be expressed when needed.
19
+
20
+
21
+ // Make it so sharing a data model is very easy.
22
+ // Sharing a single value, or referring to different values within it.
23
+
24
+ // Be able to handle errors when the view model can't update the data_model for some reason(s).
25
+
26
+
27
+
28
+
29
+
30
+
31
+ class Demo_UI extends Active_HTML_Document {
32
+
33
+
34
+
35
+ constructor(spec = {}) {
36
+ spec.__type_name = spec.__type_name || 'demo_ui';
37
+ super(spec);
38
+ const {context} = this;
39
+
40
+
41
+ // Create the Data_Model here....
42
+
43
+ // Maybe on pre-activate set its values if it's already been set?
44
+
45
+ // Or better send over info about the Data_Model that gets brought into the Page_Context???
46
+
47
+ // data.model transfer needs to be automatic.
48
+ // Possibly it would be a client-side resource?
49
+
50
+ // Want to make the syntax when composing / defining things as simple as possible.
51
+
52
+ // Simple enough for the moment.
53
+ // Could see about auto-registering?
54
+ // Maybe later on.
55
+ // Simple and explicit code will be best for the moment.
56
+ // Must be concise, then could consider more concise and less explicit (but unambiguous) ways to declare things
57
+ // to do with data and view model interactions.
58
+
59
+
60
+ // And using a Control_Data class here could help.
61
+ // Then a Control_View class.
62
+ // And the Control_View has its own internal Data. Maybe even a Control_View_Data ???
63
+
64
+
65
+
66
+ // Needs a little bit more work...
67
+
68
+ // Maybe adding the fields to the Data_Object is needed.
69
+
70
+
71
+
72
+
73
+
74
+ this.data = {
75
+ model: new Data_Object({
76
+ context
77
+ })
78
+ }
79
+
80
+ // Not enough....
81
+
82
+ // Maybe it reconnects it with a data.model on the client that lacks that?
83
+
84
+ field(this.data.model, 'value');
85
+
86
+ // The app as a whole having a view.data.model ????
87
+
88
+
89
+ // Or want defined properties / proxies on the Data_Model?
90
+ // or fields?
91
+
92
+ // want to listen for changes to the data_model.
93
+
94
+ // May need comprehensive changes to a lot of controls.
95
+ // Making this system the standard / default.
96
+ // Getting it working with easy idioms on the top level - don't update the data model on every keystroke.
97
+
98
+ // when setting the bounds of a rect, need to set multiple numbers at once (up to 4).
99
+
100
+ // A ctrl.view.data.model
101
+ // Looks like it's worth making and making use of Control_View and Control_Data classes.
102
+ // Would have / support .model.
103
+
104
+ // The view.data.model would model exactly what data is in the view.
105
+ // It would only get synced to the data.model at appropriate times (like user moving on, or confirming 'ok' or 'go')
106
+
107
+ // 'cancel' and 'go' would be of use in some cases.
108
+ // red (or grey) and then a green (or slightly green) button.
109
+ // a slightly red grey and then a bolder and more colorful green. Would be more color blindness accessible.
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ // this.data.model.set('k', 'v')???
124
+
125
+ // create_shared_data_model function...
126
+ // would happen on activate as well as compose.
127
+
128
+ // Or just make sure there is the 'value' field there...?
129
+
130
+
131
+
132
+
133
+ context.register_control(this.data.model);
134
+
135
+
136
+ // And have it persisted to the HTML by the server that they both use that same data.model???
137
+ // A bit more lower level code to support more properties / objects being reconstructed client-side would help.
138
+
139
+
140
+
141
+
142
+
143
+
144
+ // Then when there is a change to that data_model...?
145
+
146
+
147
+
148
+
149
+ // Context would have a built-in data_model?
150
+ // Maybe for HTML apps. Not all Data_Object contexts.
151
+
152
+ // Server_Page_Context also having and using a Data_Model....
153
+ // Would make sense.
154
+ // Same with the Client_Page_Context
155
+
156
+
157
+
158
+
159
+ // Make sure it requires the correct CSS.
160
+ // Though making that 'effortless' on the server may help more.
161
+
162
+
163
+ // Maybe can't do this here???
164
+
165
+ // Does not have .body (yet) on the client.
166
+ // simple way to get the client to attach the body of the Active_HTML_Document?
167
+ // maybe with jsgui-data-controls?
168
+ // Though automatically having the .body property available on the client without sending extra HTTP
169
+ // plumbing will help.
170
+
171
+ // .body will not be available before activation.
172
+
173
+
174
+ // .body should not be a normal function....?
175
+ // a getter function would be better.
176
+
177
+
178
+ if (typeof this.body.add_class === 'function') {
179
+ this.body.add_class('demo-ui');
180
+ }
181
+
182
+ //console.log('this.body', this.body);
183
+ //console.log('this.body.add_class', this.body.add_class);
184
+
185
+
186
+ const compose = () => {
187
+ // put 20 of them in place.
188
+
189
+ // Then how to arrange them...?
190
+
191
+
192
+ // Setting up the shared model in composition would be best....
193
+ // Or maybe during init, pre-activate?
194
+
195
+ // This seems like it will need some lower level integration for ease of use.
196
+ // Would like this to work server-side when setting properties, so should not rely on having this
197
+ // in the 'activate' code.
198
+
199
+ // a 'model' property.
200
+ // maybe two model properties: view.model, data.model.
201
+
202
+ // There could be a 'confirm / cancel' dialog when the view.model has been changed, and the view model can be updated
203
+
204
+ // Also, a single model could enable an undo history.
205
+
206
+ // app.data.model?
207
+ // context.data.model?
208
+
209
+ // context.view.model could make sense too, for representing the state of the app view (ie windows maximised, minimised, positions)
210
+ // Could help when resuming the app at a later point, or transmitting the view of the app.
211
+ // Maybe for collaborative editing, could operate like shared screen, or each user has control over their own windows.
212
+
213
+
214
+
215
+ // context.model?
216
+
217
+ // ctrl.view.model perhaps???
218
+ // ctrl.data.model = context.model perhaps?
219
+
220
+
221
+
222
+
223
+
224
+
225
+ const window = new controls.Window({
226
+ context: context,
227
+ title: 'jsgui3-html Shared data.model Mirrored Text_Input controls',
228
+ pos: [5, 5]
229
+ });
230
+
231
+ window.size = [480, 160];
232
+
233
+ // Label text better propbably?
234
+
235
+ // .value
236
+
237
+ // .data.model = context.data.model
238
+
239
+
240
+ // set that 'value' to a data model ??? No.
241
+ // set it's 'model' or 'data.model'.
242
+
243
+ // data.model for the moment will be best.
244
+ // That is what we want to bind.
245
+ // View model and data model pair could allow for 'cancel | OK' options to confirm changes.
246
+
247
+
248
+ // 'data_model' property.
249
+ // 'dmodel', 'dm' too...?
250
+ // 'vm' possibly?
251
+
252
+ // .v.m shorthand??
253
+ // .d.m too?
254
+
255
+
256
+
257
+ // or data: {model: obj_data_model}
258
+
259
+ // The data model persistance must not be tricky here.
260
+ // Maybe setting it up at compose is not best???
261
+ // Makes for the nicest syntax here, the 'magic' about jsgui is handing things over to the client
262
+ // in a working way, auto-reconstructing things client-side.
263
+ // Would need to send over info on which Data_Model would be used...
264
+
265
+
266
+ // The shared data model should mean that these fields automatically stay in sync (somewhat)
267
+ // A shared view model would mean a more immediate sync.
268
+
269
+
270
+ // So Text_Field would need to look at data, data.model from the spec.
271
+
272
+ // Write the code in a few controls first, see what is in common and can be abstracted into a mixin
273
+ // such as control-data-model-sync
274
+
275
+
276
+ // Would change the 'value' property by default.
277
+
278
+ const ti1 = new Text_Field({
279
+ context,
280
+
281
+ text: 'A',
282
+ data: {
283
+ model: this.data.model
284
+
285
+ // model: [this.data.model, 'value'] // this seems better
286
+
287
+ // model_property: 'value'
288
+ // model_property: 'value2' // for example
289
+ }
290
+ //label: {
291
+ // text: 'A checkbox'
292
+ //}
293
+ })
294
+
295
+ window.inner.add(ti1);
296
+
297
+ // Though not sure they get reconstructed with that data model?
298
+
299
+ // Want to make this easy for the app programmer to get right in particular.
300
+
301
+ // May need (much) more work on persisting the data model to the client.
302
+ // Or defining it in a way / place so it can be started isomorphically.
303
+ // Though it may make sense to do more to transfer models from the server to the client, with their data.
304
+ // However, reconstructing models from the (values in) the DOM could make a lot of sense.
305
+ // Having it read the DOM to create its DOM model, then from that its view.data model, then its data model.
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+ const ti2 = new Text_Field({
315
+ context,
316
+
317
+ text: 'B',
318
+ data: {
319
+ model: this.data.model
320
+ }
321
+
322
+
323
+ //label: {
324
+ // text: 'A checkbox'
325
+ //}
326
+ })
327
+
328
+ window.inner.add(ti2);
329
+
330
+ this.body.add(window);
331
+
332
+
333
+
334
+
335
+ this._ctrl_fields = this._ctrl_fields || {};
336
+ this._ctrl_fields.ti1 = ti1;
337
+ this._ctrl_fields.ti2 = ti2;
338
+
339
+
340
+ }
341
+ if (!spec.el) {
342
+ compose();
343
+ }
344
+ }
345
+ activate() {
346
+ if (!this.__active) {
347
+ super.activate();
348
+ const {context, ti1, ti2} = this;
349
+
350
+ console.log('activate Demo_UI');
351
+
352
+ //field(this.data.model, 'value');
353
+ // and events dealing with changes to those tis.
354
+
355
+ // ti1, ti2.
356
+
357
+ // Some kind of tracking of what the event initiator could help?
358
+ // Automatically avoiding feedback somehow???
359
+ // If it gets changed to its current value it does not push the change...?
360
+
361
+
362
+ // a non-dom change???
363
+ // or basically .view.model.change even????
364
+
365
+ // ti1.view.model.on('change') could be much clearer, disambiguating it from a dom change event.
366
+ // assign .view.model events ....?
367
+ // doing this on a lower level would help.
368
+
369
+ // Just creating .view and .view.model objects (getters and setters specified) in jsgui3-html will help
370
+ // when referring to them.
371
+
372
+ // Maybe see about better reconstruction....
373
+
374
+ //console.log('ti1.data.model', ti1.data.model);
375
+ //console.log('ti2.data.model', ti2.data.model);
376
+
377
+ console.log('ti1.data.model === ti2.data.model', ti1.data.model === ti2.data.model);
378
+
379
+ if (ti1.data.model === ti2.data.model) {
380
+
381
+ } else {
382
+
383
+ // Should not need this code.
384
+ // Want decent low/mid level code to send the info to the client so the client can automatically reconstruct it.
385
+ /// Maybe a different function as standard to assign isomorphic things.
386
+
387
+
388
+
389
+
390
+ const dm = new Data_Object({context});
391
+ field(dm, 'value');
392
+ ti1.data.model = dm;
393
+ ti2.data.model = dm;
394
+
395
+ // But then need to get them to reassign their data model change listeners....?
396
+ // value change even....
397
+
398
+ ti1.assign_data_model_value_change_handler();
399
+ ti2.assign_data_model_value_change_handler();
400
+
401
+
402
+ }
403
+
404
+ // Create a new data_model (and view_model?) for both of them?
405
+ // The view_model gets created by default and does not need to be shared (and should not be)
406
+
407
+
408
+
409
+
410
+
411
+ // ti1.value.on('change') ????
412
+ // where the value is an Evented_Class or even Data_Object????
413
+ // and where we can also get the value out of it easily / do so automatically, maybe within other useful functions.
414
+
415
+
416
+ // ti1.model.on('change') ????
417
+ // or .view.model to be most specific for the moment...?
418
+ // and raise those events within the controls on those .view.model objects.
419
+
420
+ // Maybe just try it on Text_Field for the moment.
421
+
422
+
423
+
424
+ // Need to work on having it update the dom with value changes....
425
+
426
+ const old_activate_changes = () => {
427
+
428
+ ti1.model.on('change', e => {
429
+ //console.log('ti1 change e', e);
430
+
431
+
432
+ if (e.property_name === 'value') {
433
+ if (e.value !== e.old) {
434
+ ti2.value = e.value;
435
+ }
436
+ }
437
+
438
+ // setting ti2.view.model.value even????
439
+
440
+
441
+
442
+
443
+ })
444
+ ti2.model.on('change', e => {
445
+ //console.log('ti2 change e', e);
446
+
447
+ //
448
+
449
+ if (e.value !== e.old) {
450
+ ti1.value = e.value;
451
+ }
452
+
453
+
454
+ })
455
+ }
456
+
457
+
458
+
459
+ // listen for change events.
460
+ // would be nice to know which change events originated from the user interacting with that specific HTML element (or ctrl???)
461
+
462
+ // e.from_user === true test.
463
+
464
+ // e.user_initiated_on_this ????
465
+
466
+
467
+
468
+
469
+ //console.log('activate Demo_UI');
470
+ // listen for the context events regarding frames, changes, resizing.
471
+
472
+ context.on('window-resize', e_resize => {
473
+
474
+ // Could see about having some window contents bound through CSS to the size of the window.
475
+ // Though having a framework of adjusting CSS from the JS on-the-fly could work too.
476
+
477
+ // May be done with the 'bind' mixin, or will make more specific mixins to do things like bind
478
+ // a control to the space within another control, space within a specific part of that control.
479
+
480
+ // Or bind to parent size. That should be possible with CSS though.
481
+ // May make some controls make more use of CSS by default
482
+ // Or having an absolutely positioned box model used extensively could avoid some ambiguity, though
483
+ // making use of and supporting generally respected CSS features will help too.
484
+
485
+ //console.log('window-resize', e_resize);
486
+
487
+ // Make all internal controls go absolute in terms of position
488
+ // Remove them from their containers too?
489
+ // Ie their containing divs?
490
+
491
+ // Would be nice to do this really simple with a fn call or very simple piece of code.
492
+ // Like get absolute position, set position to be absolute, move to that position.
493
+ // Maybe something within jsgui3-client helps with this, this is more about what needs to be done on the client.
494
+ // Though recognising perf implications, it's (more) OK to include client-side functionality in jsgui3-html.
495
+
496
+
497
+
498
+
499
+
500
+
501
+ });
502
+
503
+ }
504
+ }
505
+ }
506
+
507
+ // Include this in bundling.
508
+ // Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
509
+
510
+ //controls.Demo_UI = Demo_UI;
511
+
512
+ // A css file may be an easier way to get started...?
513
+ // Want to support but not require css in js.
514
+
515
+ // But need to set up the serving of the CSS both on the server, and on the client.
516
+ // Ofc setting it up on the server first is important - then can that stage set it up in the doc sent to the client?
517
+
518
+ // Including the CSS from the JS like before.
519
+ // Needs to extract the CSS and serve it as a separate CSS file.
520
+ // Should also have end-to-end regression tests so this does not break again in the future.
521
+ // The code was kind of clunky and got refactored away.
522
+ //
523
+
524
+ // Would need to parse the JS files to extract the CSS.
525
+ // Maybe could do it an easier way??? Now that it's easy, want a faster way.
526
+
527
+
528
+ Demo_UI.css = `
529
+
530
+ * {
531
+ margin: 0;
532
+ padding: 0;
533
+ }
534
+
535
+ body {
536
+ overflow-x: hidden;
537
+ overflow-y: hidden;
538
+ background-color: #E0E0E0;
539
+ }
540
+
541
+ .demo-ui {
542
+
543
+ /*
544
+
545
+ display: flex;
546
+ flex-wrap: wrap;
547
+
548
+ flex-direction: column;
549
+ justify-content: center;
550
+ align-items: center;
551
+ text-align: center;
552
+ min-height: 100vh;
553
+ */
554
+
555
+ }
556
+ `;
557
+
558
+ // But may want to remove them from that flex upon picking up / dropping them.
559
+ // Maybe best upon drop.
560
+
561
+ // Maybe want other examples that use absolute positioning to position the items at the start?
562
+ //
563
+
564
+
565
+
566
+ //controls.Square_Box = Square_Box;
567
+ // could export jsgui with the updated controls....
568
+ // so that they are in the correct Page Context.?
569
+
570
+
571
+ controls.Demo_UI = Demo_UI;
572
+
573
+ module.exports = jsgui;
574
+
575
+ /*
576
+ module.exports = {
577
+ Square_Box: Square_Box,
578
+ Demo_UI: Demo_UI
579
+ }
580
+ */
581
+
582
+ // Then if window...?
583
+
584
+ // Need to add the Square_Box control to the context or original map of controls...
585
+
@@ -0,0 +1,118 @@
1
+ const jsgui = require('./client');
2
+
3
+ const {Demo_UI} = jsgui.controls;
4
+ const Server = require('../../../server');
5
+
6
+
7
+ // what would be the (best?) way to include the whole thing in one JS file?
8
+ // Maybe don't try that right now.
9
+ // maybe standardise on the dir, then client.js and server.js inside.
10
+
11
+
12
+
13
+ // Want to exclude this from the client bundle.
14
+ // Some kind of marking to say that it's server-side only?
15
+
16
+ // Need to include JSGUI3 js within the client document.
17
+ // Seems like an earlier code simplification removed this functionality?
18
+ // Just specifying a Ctrl for the server - and giving it the 'disk_path_client_js'.
19
+ // May as well fix that....
20
+
21
+
22
+ // The server code may be tiny, it seems best not to abstract it away totally though.
23
+ // At least not for the moment.
24
+
25
+
26
+
27
+
28
+
29
+ if (require.main === module) {
30
+
31
+ // By default should include the JS and the CSS.
32
+ // By reference, serving them from their respective paths.
33
+
34
+
35
+ // This API is not working right now.
36
+
37
+ // A very simple syntax for running a single control would be great.
38
+
39
+ // Need to in the default (server) configuration build and serve the client-side app.
40
+ // Want to be able to make interactive apps quickly with minimal server side code that needs to be written as boilerplate to
41
+ // get the app running.
42
+
43
+ // Though maybe defining a webpage, that serves the client js, and renders the control on the server, and activates it on the client,
44
+ // would be the right approach.
45
+
46
+ // Want to make the code really explicit, in a simple way.
47
+
48
+
49
+ // eg { '/': Demo_UI }
50
+ // eg { '*': Demo_UI }
51
+ // as at least it explicitly assigns it to the '/' route
52
+
53
+
54
+ // But worth keeping the '/' Ctrl property?
55
+ // Could change it to explicitly setting the route(s).
56
+
57
+ // Do want it to build the client js on start.
58
+
59
+ // Could extract the CSS from the file itself, or maybe better reading it from the classes and objects that are loaded / referenced.
60
+ // All kinds of complex server program structures exist already, so could use Publishers if needed for some things.
61
+ // But need to keep the surface-level API really simple.
62
+
63
+ // Maybe define a Webpage and maybe use / define an HTML_Webpage_Publisher for example too.
64
+ // The clearest code would be really explicit about what it does, but in terms of almost English idioms
65
+ // and on the surface-level not spelling out in great detail what it's doing, but referencing objects and
66
+ // instructions with clear purposes, though details could be obscure at the top level. Eg it's the publisher's responsibility
67
+ // to include the CSS and JS that's needed to get it to run. A publisher is referenced and used, and it does its thing.
68
+
69
+ // The Server could automatically involk the use of a Publisher.
70
+ // May be better to either require or recommend more explicit code, have them in the examples,
71
+ // but also to document some shortcuts, defaults, and abbreviations (though they may omit some essential info, so not recommended for beginners)
72
+
73
+ // Could have a tabbed view for examples for 'explicit' and 'short' notations when there are multiple.
74
+
75
+ // jsgui3-html-suite may be of use, for some more extended controls that are built on top of jsgui3-html, but not specifically
76
+ // client or server.
77
+
78
+
79
+
80
+
81
+
82
+
83
+ const server = new Server({
84
+ Ctrl: Demo_UI,
85
+ //debug: true,
86
+ // Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
87
+ // Putting the JS files through proper parsing and into a syntax tree would be best.
88
+
89
+ //'js_mode': 'debug',
90
+ 'src_path_client_js': require.resolve('./client.js'),
91
+ //debug: true // should not minify the js, should include the symbols.
92
+ //js_client: require.resolve('./square_box.js')
93
+ });
94
+ // A callback or event for when the bundling has been completed
95
+ // a 'ready' event.
96
+
97
+ // then start the server....
98
+ // be able to choose the port / ports?
99
+ console.log('waiting for server ready event');
100
+ server.one('ready', () => {
101
+ console.log('server ready');
102
+
103
+ // server start will change to observable?
104
+
105
+ server.start(8080, function (err, cb_start) {
106
+ if (err) {
107
+ throw err;
108
+ } else {
109
+ // Should have build it by now...
110
+
111
+ console.log('server started');
112
+ }
113
+ });
114
+ })
115
+
116
+
117
+
118
+ }
package/package.json CHANGED
@@ -6,16 +6,14 @@
6
6
  "@babel/core": "^7.23.2",
7
7
  "@babel/generator": "^7.23.0",
8
8
  "@babel/parser": "7.23.0",
9
- "babel-plugin-transform-runtime": "^6.23.0",
10
- "babel-preset-minify": "^0.5.2",
11
9
  "cookies": "^0.8.0",
12
10
  "esbuild": "^0.19.5",
13
11
  "fnl": "^0.0.30",
14
12
  "fnlfs": "^0.0.29",
15
- "jsgui3-client": "^0.0.101",
16
- "jsgui3-html": "^0.0.139",
17
- "jsgui3-webpage": "^0.0.7",
18
- "jsgui3-website": "^0.0.7",
13
+ "jsgui3-client": "^0.0.104",
14
+ "jsgui3-html": "^0.0.142",
15
+ "jsgui3-webpage": "^0.0.8",
16
+ "jsgui3-website": "^0.0.8",
19
17
  "lang-tools": "^0.0.22",
20
18
  "multiparty": "^4.2.3",
21
19
  "ncp": "^2.0.0",
@@ -40,5 +38,5 @@
40
38
  "type": "git",
41
39
  "url": "https://github.com/metabench/jsgui3-server.git"
42
40
  },
43
- "version": "0.0.115"
41
+ "version": "0.0.117"
44
42
  }