@yuneta/gobj-ui 7.26.46 → 7.26.48

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.
@@ -1703,7 +1703,7 @@ function declared_value(b, url, seen)
1703
1703
  if(b.steps.length === 0 && FUNCTION_RE.test(b.init.type)) {
1704
1704
  return {kind: "fn", fn: b.init, scope: b.scope, name: b.name, url};
1705
1705
  }
1706
- return {kind: "const", init: b.init, steps: b.steps, default: b.default, scope: b.scope, url};
1706
+ return {kind: "const", init: b.init, steps: b.steps, default: b.default, scope: b.scope, url, name: b.name};
1707
1707
  }
1708
1708
  if(b.kind === "import") {
1709
1709
  return import_target(b, seen);
@@ -2697,6 +2697,7 @@ const CONST_READING = new Set(); // the inits being read
2697
2697
 
2698
2698
  function const_values(b, node, scope, via, depth)
2699
2699
  {
2700
+ note_const_array(b);
2700
2701
  let ctx = {scope: b.scope, via: via, off: true};
2701
2702
  let unknown = () => [{kind: "unknown", node: b.init, scope: b.scope, via, off: true}];
2702
2703
  if(!CONST_VALUES.has(b.init) && CONST_READING.has(b.init)) {
@@ -2970,12 +2971,126 @@ function written_elements(n, scope)
2970
2971
  if(n.type !== "Identifier") {
2971
2972
  return null;
2972
2973
  }
2973
- let b = binding_of(n.name, scope);
2974
- if(!b || b.kind !== "const" || b.steps.length > 0 || !b.init || b.init.type !== "ArrayExpression"
2975
- || b.init.elements.some((e) => e === null || e.type === "SpreadElement")) {
2974
+ let array = const_array(n, scope);
2975
+ if(!array || array.elements.some((e) => e === null || e.type === "SpreadElement")) {
2976
2976
  return null;
2977
2977
  }
2978
- return b.init.elements.map((e, i) => element_ref(n, i));
2978
+ return array.elements.map((e, i) => element_ref(n, i));
2979
+ }
2980
+
2981
+ /***************************************************************
2982
+ * The array literal a name is a const of, or null: its own value
2983
+ * (`Object.freeze()`d too), an import of one, or a const ALIAS of
2984
+ * one (`const B = A`), followed to its end. Up to gobj-ui 7.26.46 an
2985
+ * alias or an import was a spread of what the source does not write.
2986
+ ***************************************************************/
2987
+ function const_array(n, scope)
2988
+ {
2989
+ let seen = new Set();
2990
+ for(;;) {
2991
+ let b = binding_of(n.name, scope);
2992
+ if(b && b.kind === "import") {
2993
+ b = import_target(b);
2994
+ }
2995
+ if(!b || b.kind !== "const" || (b.steps || []).length > 0 || b.default || !b.init || seen.has(b.init)) {
2996
+ return null;
2997
+ }
2998
+ seen.add(b.init);
2999
+ let init = b.init;
3000
+ if(is_object_call(init, "freeze") && init.arguments.length === 1) {
3001
+ init = init.arguments[0];
3002
+ }
3003
+ if(init.type === "ArrayExpression") {
3004
+ return init;
3005
+ }
3006
+ if(init.type !== "Identifier") {
3007
+ return null;
3008
+ }
3009
+ n = init;
3010
+ scope = b.scope;
3011
+ }
3012
+ }
3013
+
3014
+ /***************************************************************
3015
+ * The array literals an element is read from by its index
3016
+ * (step_values()): the value of a const that its scope does not
3017
+ * write INTO -- `X[i] = k`, `X.length = n`, `X[i]++`, `delete X[i]`,
3018
+ * `X.push()` and every method that moves its elements (`reverse()`,
3019
+ * `sort()`, `shift()`, ...), `Object.assign(X, ...)`. Any other
3020
+ * array -- one written into, where an element read by its index may
3021
+ * be another one by then (`X.reverse(); t(X[0])`), the value of a
3022
+ * `let`, an `export default` -- is read by every element written out,
3023
+ * at any index. What is written into it is not read (the invisible
3024
+ * list of the README), nor a write through an alias of it, from a
3025
+ * module that imports it, or by a function it is handed to.
3026
+ ***************************************************************/
3027
+ const INDEXED_ARRAYS = new WeakSet(); // the array literals of consts not written into
3028
+ const ARRAY_WRITERS = new Set(["push", "unshift", "splice", "fill", "copyWithin", "reverse", "sort", "shift",
3029
+ "pop"]);
3030
+ const NOTED_ARRAYS = new WeakSet(); // the inits of consts already asked
3031
+
3032
+ function note_const_array(b)
3033
+ {
3034
+ let init = b.init;
3035
+ if(!init || init.type !== "ArrayExpression" || NOTED_ARRAYS.has(init) || !b.name || !b.scope) {
3036
+ return;
3037
+ }
3038
+ NOTED_ARRAYS.add(init);
3039
+ let root = b.scope[b.scope.length - 1];
3040
+ for(let chain of (in_place_writes(root).get(b.name) || [])) {
3041
+ let w = binding_of(b.name, chain);
3042
+ if(w && w.kind === "const" && w.init === init) {
3043
+ return;
3044
+ }
3045
+ }
3046
+ INDEXED_ARRAYS.add(init);
3047
+ }
3048
+
3049
+ /* The places a scope writes INTO what a name holds: name -> [the
3050
+ * chain from the scope to the name written], found in one walk */
3051
+ const IN_PLACE_WRITES = new WeakMap(); // a scope -> Map(name -> [chain])
3052
+
3053
+ function in_place_writes(root)
3054
+ {
3055
+ let known = IN_PLACE_WRITES.get(root);
3056
+ if(known) {
3057
+ return known;
3058
+ }
3059
+ known = new Map();
3060
+ let add = (target, ancestors) => {
3061
+ let chain = [...ancestors];
3062
+ while(target && target.type === "MemberExpression") {
3063
+ target = target.object;
3064
+ }
3065
+ if(target && target.type === "Identifier") {
3066
+ if(!known.has(target.name)) {
3067
+ known.set(target.name, []);
3068
+ }
3069
+ known.get(target.name).push(chain);
3070
+ }
3071
+ };
3072
+ walk(root, (n, ancestors) => {
3073
+ if(n.type === "AssignmentExpression") {
3074
+ for(let t of write_targets(n.left)) {
3075
+ if(t.type === "MemberExpression") {
3076
+ add(t, [...ancestors, n]);
3077
+ }
3078
+ }
3079
+ } else if((n.type === "UpdateExpression" && n.argument.type === "MemberExpression")
3080
+ || (n.type === "UnaryExpression" && n.operator === "delete" && n.argument.type === "MemberExpression")) {
3081
+ add(n.argument, [...ancestors, n]);
3082
+ } else if(n.type === "CallExpression") {
3083
+ let c = n.callee;
3084
+ if(c.type === "MemberExpression" && ARRAY_WRITERS.has(member_step(c).prop)) {
3085
+ add(c.object, [...ancestors, n]);
3086
+ } else if((is_object_call(n, "assign") || is_object_call(n, "defineProperty")
3087
+ || is_object_call(n, "defineProperties")) && n.arguments.length > 0) {
3088
+ add(n.arguments[0], [...ancestors, n]);
3089
+ }
3090
+ }
3091
+ });
3092
+ IN_PLACE_WRITES.set(root, known);
3093
+ return known;
2979
3094
  }
2980
3095
 
2981
3096
  function is_spread(n)
@@ -3041,6 +3156,11 @@ function step_values(o, step, node, depth)
3041
3156
  return assigned_properties(o, step, depth + 1);
3042
3157
  }
3043
3158
  if(o.kind === "value" && o.node.type === "ArrayExpression" && step.computed) {
3159
+ let i = array_index(step);
3160
+ if(i !== null && INDEXED_ARRAYS.has(o.node)
3161
+ && !o.node.elements.slice(0, i + 1).some((e) => e && e.type === "SpreadElement")) {
3162
+ return indexed_values(o, i, at, depth + 1);
3163
+ }
3044
3164
  return element_values(o, depth + 1);
3045
3165
  }
3046
3166
  if(o.kind === "nothing" || (o.kind === "value" && o.node.type === "Literal")) {
@@ -3169,6 +3289,52 @@ function property_values_of(o, name, depth)
3169
3289
  return out;
3170
3290
  }
3171
3291
 
3292
+ /***************************************************************
3293
+ * The index a step reads, when it is one written out (`X[1]`,
3294
+ * `X["1"]`, ``X[`1`]``), or null
3295
+ ***************************************************************/
3296
+ function array_index(step)
3297
+ {
3298
+ return (step.prop !== null && /^(0|[1-9][0-9]{0,8})$/.test(step.prop))? Number(step.prop) : null;
3299
+ }
3300
+
3301
+ /***************************************************************
3302
+ * The element `i` of an array literal with no spread up to it: that
3303
+ * element followed with expand() -- a hole, or past the end, is
3304
+ * nothing. Up to gobj-ui 7.26.46 `X[1]` read every element of X, and
3305
+ * so did the spread of a const array (written_args()):
3306
+ * `t.apply(null, ["k", "a default value"])` asked for the default
3307
+ * value, and `f.apply(x, [shell, "k"])` gave `shell` to the key
3308
+ * position of a key function. Kept per element, as a property is
3309
+ * (property_values()).
3310
+ ***************************************************************/
3311
+ const INDEXED_VALUES = new WeakMap(); // an array literal -> Map(index -> {values, steps}), `via` left out
3312
+
3313
+ function indexed_values(o, i, at, depth)
3314
+ {
3315
+ if(i >= o.node.elements.length || o.node.elements[i] === null) {
3316
+ return [Object.assign({}, o, {kind: "nothing", node: at})];
3317
+ }
3318
+ if(!o.off) {
3319
+ return capped(o, indexed_values_of(o, i, depth));
3320
+ }
3321
+ let known = INDEXED_VALUES.get(o.node);
3322
+ if(!known) {
3323
+ known = new Map();
3324
+ INDEXED_VALUES.set(o.node, known);
3325
+ }
3326
+ let bare = Object.assign({}, o, {via: []});
3327
+ let values = kept_values(known, i, depth, o.node, o.scope,
3328
+ () => capped(bare, unique_values(indexed_values_of(bare, i, depth))),
3329
+ () => [Object.assign({}, bare, {kind: "unknown", binding: null, var_root: null})]);
3330
+ return values.map((v) => Object.assign({}, v, {via: o.via}));
3331
+ }
3332
+
3333
+ function indexed_values_of(o, i, depth)
3334
+ {
3335
+ return expand(o.node.elements[i], {scope: [...o.scope, o.node], via: o.via, off: o.off}, depth + 1);
3336
+ }
3337
+
3172
3338
  /***************************************************************
3173
3339
  * The elements of whatever `node` is, when it is an array literal
3174
3340
  * (after expand()): each element followed with expand(). A `.map()`
@@ -6410,6 +6576,11 @@ try {
6410
6576
  is_main = false;
6411
6577
  }
6412
6578
  if(is_main) {
6579
+ process.on("unhandledRejection", (reason) => {
6580
+ console.error("validate-locales: a promise was rejected and nothing handled it (a locale is " +
6581
+ `imported, so its code runs): ${(reason && reason.stack) || reason}`);
6582
+ process.exitCode = 1;
6583
+ });
6413
6584
  try {
6414
6585
  await main();
6415
6586
  } catch(e) {
@@ -6426,7 +6597,11 @@ if(is_main) {
6426
6597
  * process for ever, verdict or not (up to gobj-ui 7.26.45, also a run
6427
6598
  * that failed). process.exit() runs from the callbacks of a last
6428
6599
  * write to each stream, which come after every write before them, so
6429
- * a long list on its way to a pipe still reaches it whole.
6600
+ * a long list on its way to a pipe still reaches it whole. It waits
6601
+ * for a timer first: a promise rejected with nothing to handle it is
6602
+ * told only when the loop turns, and a timer of 0 a locale set is due
6603
+ * before it -- up to gobj-ui 7.26.46 such a rejection was lost, and
6604
+ * the run passed.
6430
6605
  ***************************************************************/
6431
6606
  function exit_when_written()
6432
6607
  {
@@ -6437,6 +6612,8 @@ function exit_when_written()
6437
6612
  process.exit();
6438
6613
  }
6439
6614
  };
6440
- process.stdout.write("", written);
6441
- process.stderr.write("", written);
6615
+ setTimeout(() => {
6616
+ process.stdout.write("", written);
6617
+ process.stderr.write("", written);
6618
+ }, 0);
6442
6619
  }
@@ -98,3 +98,12 @@
98
98
  .C_YUI_FORM input[type="color"] {
99
99
  vertical-align: middle;
100
100
  }
101
+
102
+ /*--- A cell editor holding what is not a value yet (an incomplete date,
103
+ * form_time_cell_editor.js): it stays open, and says so. Above
104
+ * Tabulator's own `.tabulator-row .tabulator-cell.tabulator-editing
105
+ * input {outline: none}`. ---*/
106
+ .C_YUI_FORM .tabulator-cell.tabulator-editing input[aria-invalid="true"] {
107
+ outline: 2px solid var(--bulma-danger, #ff6685);
108
+ outline-offset: -2px;
109
+ }
package/src/c_yui_form.js CHANGED
@@ -95,7 +95,10 @@ import "tabulator-tables/dist/css/tabulator_bulma.css";
95
95
 
96
96
  import "./tabulator.css";
97
97
  import {is_time_field} from "./json_view_helpers.js";
98
- import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
98
+ import {
99
+ date_to_datetime_local, datetime_local_to_epoch, time_value_to_date, epoch_to_time_value,
100
+ time_value_to_text
101
+ } from "./form_time_value.js";
99
102
  import {form_time_cell_editor} from "./form_time_cell_editor.js";
100
103
  import {parse_json_field, json_editor_value} from "./form_json_field.js";
101
104
  import {
@@ -134,7 +137,7 @@ SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "Treedb topic na
134
137
  SDATA(data_type_t.DTP_BOOLEAN, "editable", 0, false, "Default is editable, set false to readonly"),
135
138
  SDATA(data_type_t.DTP_BOOLEAN, "readonly", 0, false, "Show EVERY field read-only, whatever its schema says: a record being LOOKED at, not edited. Independent of `editable`, which drives the TABLE rendering; this one drives the FORM"),
136
139
  SDATA(data_type_t.DTP_BOOLEAN, "selectable", 0, true, "A click selects a row, when tabulator_settings selects rows (selectableRows)"),
137
- SDATA(data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows (not drawn when the form is not `selectable`)"),
140
+ SDATA(data_type_t.DTP_BOOLEAN, "with_checkbox", 0, false, "Show a first column with checkbox to select rows (hidden while the form is not `selectable`)"),
138
141
  SDATA(data_type_t.DTP_BOOLEAN, "with_rownum", 0, false, "Print first column with row number"),
139
142
  SDATA(data_type_t.DTP_BOOLEAN, "with_delete_row_btn", 0, false, "Print last column with delete row button"),
140
143
  /*
@@ -190,6 +193,13 @@ let PRIVATE_DATA = {
190
193
  json_names_posted: false,
191
194
  /* The shell this form hears the language change from. */
192
195
  lang_shell: null,
196
+ /* Moved by every write of `changes` (set_changed_stated): a cell
197
+ * editor cancelled gives back the state it opened on only if
198
+ * nothing but its own typing moved it since (cell_edit). */
199
+ change_seq: 0,
200
+ /* The cell editor open: {table_id, edited, changes, seq}, see
201
+ * ac_cell_edit_opened. */
202
+ cell_edit: null,
193
203
  };
194
204
 
195
205
  let __gclass__ = null;
@@ -225,6 +235,25 @@ function mt_create(gobj)
225
235
  build_ui(gobj);
226
236
  }
227
237
 
238
+ /************************************************************
239
+ * Framework Method writing
240
+ ************************************************************/
241
+ function mt_writing(gobj, path)
242
+ {
243
+ if(path === "selectable") {
244
+ /* The checkbox column follows it, in every table built */
245
+ let $container = gobj_read_attr(gobj, "$container");
246
+ if(!$container) {
247
+ return;
248
+ }
249
+ for(let $table of $container.querySelectorAll(".yui-tabulator-table, .yui-tabulator-table-nested")) {
250
+ if($table.tabulator) {
251
+ show_row_selection(gobj, $table.tabulator);
252
+ }
253
+ }
254
+ }
255
+ }
256
+
228
257
  /************************************************************
229
258
  * Framework Method destroy
230
259
  * In this point, all children
@@ -292,6 +321,7 @@ function mt_stop(gobj)
292
321
  ************************************************************/
293
322
  function set_changed_stated(gobj, changed)
294
323
  {
324
+ gobj.priv.change_seq += 1;
295
325
  let $container = gobj_read_attr(gobj, "$container");
296
326
  let $form = $container.querySelector('form');
297
327
 
@@ -890,6 +920,12 @@ function build_form(gobj)
890
920
  {
891
921
  let form_id = gobj_read_str_attr(gobj, "form_id");
892
922
  let $form = createElement2(['form', {id: form_id, class: 'yui-form'}]);
923
+ /* Widget plumbing, not an action: the values are read from the
924
+ * controls, never submitted. Enter in a form of a single text box
925
+ * is an implicit submission, and up to 7.26.46 it reloaded the page. */
926
+ $form.addEventListener("submit", function(ev) {
927
+ ev.preventDefault();
928
+ });
893
929
 
894
930
  /*----------------------------*
895
931
  * Check if template exists
@@ -1544,7 +1580,7 @@ function create_form_field(
1544
1580
  ['div', {class: 'field-body'}, [
1545
1581
  ['div', {class: 'field'}, [
1546
1582
  ['div', {class: '' }, [
1547
- ['button', {class: 'button p-1',
1583
+ ['button', {class: 'button p-1', type: 'button',
1548
1584
  title: t('add'), 'data-i18n-title': 'add',
1549
1585
  'aria-label': t('add'), 'data-i18n-aria-label': 'add'}, [
1550
1586
  ['span', {class: 'icon m-0'}, html_markup('<i class="yi-plus"></i>')],
@@ -2262,6 +2298,31 @@ function create_coordinates(gobj, attrs)
2262
2298
  return $extend;
2263
2299
  }
2264
2300
 
2301
+ /******************************************************************
2302
+ * Show the checkbox column of a table while the form is
2303
+ * `selectable`, hide it while it is not. The column is the table's
2304
+ * row header, the first of its structured columns. A table not
2305
+ * built yet does it when it is (tableBuilt).
2306
+ ******************************************************************/
2307
+ function show_row_selection(gobj, tabulator)
2308
+ {
2309
+ if(!gobj_read_bool_attr(gobj, "with_checkbox") || !tabulator.initialized) {
2310
+ return;
2311
+ }
2312
+ let column = tabulator.getColumns(true).find(
2313
+ (c) => c.getDefinition().formatter === "rowSelection"
2314
+ );
2315
+ if(!column) {
2316
+ log_error(`${gobj_short_name(gobj)}: the table has no checkbox column to show or hide`);
2317
+ return;
2318
+ }
2319
+ if(gobj_read_bool_attr(gobj, "selectable")) {
2320
+ column.show();
2321
+ } else {
2322
+ column.hide();
2323
+ }
2324
+ }
2325
+
2265
2326
  /******************************************************************
2266
2327
  * Create tabulator
2267
2328
  *
@@ -2292,11 +2353,13 @@ function create_coordinates(gobj, attrs)
2292
2353
  * `"highlight"` is left as it is, hover and all.
2293
2354
  *
2294
2355
  * The checkbox column (`with_checkbox`) asks `selectable` too, and is
2295
- * not drawn when the form is not selectable: Tabulator's row box ticks
2296
- * before its toggle is refused (a ticked box over a row not selected),
2297
- * and its header box selects every row asking nothing. Up to 7.26.45
2298
- * the boxes were drawn and lied; with the default `selectableRows`
2299
- * they selected whatever `selectable` said.
2356
+ * not shown while the form is not selectable: Tabulator's row box
2357
+ * ticks before its toggle is refused (a ticked box over a row not
2358
+ * selected), and its header box selects every row asking nothing. Up
2359
+ * to 7.26.45 the boxes were drawn and lied; with the default
2360
+ * `selectableRows` they selected whatever `selectable` said. Up to
2361
+ * 7.26.46 `selectable` was read when the table was built; the column
2362
+ * now follows every write of it (mt_writing, show_row_selection).
2300
2363
  *
2301
2364
  * A click in a nested table stays there: it bubbled to the row that
2302
2365
  * holds the table, whose own click listener (SelectRow's) toggled
@@ -2395,7 +2458,7 @@ function create_tabulator(gobj, $extend, name, template, rows)
2395
2458
  );
2396
2459
  }
2397
2460
 
2398
- if(with_checkbox && gobj_read_bool_attr(gobj, "selectable")) {
2461
+ if(with_checkbox) {
2399
2462
  tabulator_settings.rowHeader = {
2400
2463
  formatter: "rowSelection",
2401
2464
  titleFormatter: "rowSelection",
@@ -2403,7 +2466,8 @@ function create_tabulator(gobj, $extend, name, template, rows)
2403
2466
  resizable: false,
2404
2467
  frozen: true,
2405
2468
  headerHozAlign: "center",
2406
- hozAlign: "center"
2469
+ hozAlign: "center",
2470
+ visible: gobj_read_bool_attr(gobj, "selectable")
2407
2471
  };
2408
2472
  }
2409
2473
 
@@ -2441,10 +2505,29 @@ function create_tabulator(gobj, $extend, name, template, rows)
2441
2505
  table_element_of($target) !== $extend) {
2442
2506
  return;
2443
2507
  }
2444
- gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
2508
+ gobj_send_event(gobj, "EV_RECORD_CHANGED",
2509
+ {typed_in: table_identity(gobj, $extend)}, gobj);
2510
+ });
2511
+ /* An edit CANCELLED (Escape, a box left as it was) gives back the
2512
+ * `edited` and `changes` the form had when its editor opened: what
2513
+ * was typed in it is gone (ac_cell_edit_cancelled). */
2514
+ tabulator.on("cellEditing", function() {
2515
+ if(gobj_is_destroying(gobj)) {
2516
+ return;
2517
+ }
2518
+ gobj_send_event(gobj, "EV_CELL_EDIT_OPENED",
2519
+ {table_id: table_identity(gobj, $extend)}, gobj);
2520
+ });
2521
+ tabulator.on("cellEditCancelled", function() {
2522
+ if(gobj_is_destroying(gobj)) {
2523
+ return; // closed by the teardown (close_table_editor)
2524
+ }
2525
+ gobj_send_event(gobj, "EV_CELL_EDIT_CANCELLED",
2526
+ {table_id: table_identity(gobj, $extend)}, gobj);
2445
2527
  });
2446
2528
  $extend.yui_pending_rows = null;
2447
2529
  tabulator.on("tableBuilt", function() {
2530
+ show_row_selection(gobj, tabulator);
2448
2531
  let rows = $extend.yui_pending_rows;
2449
2532
  $extend.yui_pending_rows = null;
2450
2533
  if(rows && !gobj_is_destroying(gobj)) {
@@ -2714,6 +2797,11 @@ function template2columns(gobj, columns, template, sub_elements)
2714
2797
  column.editorParams = {
2715
2798
  verticalNavigation: "table", //navigate cursor around table without changing the value
2716
2799
  };
2800
+ /* The clock, not the epoch: up to 7.26.46 the cell showed
2801
+ * the raw number. */
2802
+ column.formatter = function(cell) {
2803
+ return text_node(time_value_to_text(cell.getValue(), field_desc.real_type));
2804
+ };
2717
2805
  break;
2718
2806
 
2719
2807
  case "color":
@@ -3532,9 +3620,9 @@ function treedb_value_2_form_value(gobj, field_desc, value)
3532
3620
  break;
3533
3621
  case "now":
3534
3622
  case "time":
3535
- /* Stored epoch is in SECONDS (Yuneta/timeranger convention),
3536
- * matching get_form_values() which saves getTime()/1000. */
3537
- value = new Date((parseInt(value) || 0) * 1000);
3623
+ /* An epoch in SECONDS, or an ISO text for a string column;
3624
+ * null when it holds no time (form_time_value.js). */
3625
+ value = time_value_to_date(value, field_desc.real_type);
3538
3626
  break;
3539
3627
  case "date":
3540
3628
  case "color":
@@ -3671,14 +3759,12 @@ function form_value_2_treedb_value(gobj, field_desc, value)
3671
3759
  case "time":
3672
3760
  switch(real_type) {
3673
3761
  case "string":
3674
- if(value && is_date(value)) {
3675
- value = value.toISOString();
3676
- }
3677
- break;
3678
3762
  case "integer":
3679
- if(value && is_date(value)) {
3680
- value = (value.getTime())/1000;
3763
+ /* The box gives an epoch in seconds (get_form_values) */
3764
+ if(is_date(value)) {
3765
+ value = Math.floor(value.getTime() / 1000);
3681
3766
  }
3767
+ value = epoch_to_time_value(value, real_type);
3682
3768
  break;
3683
3769
  default:
3684
3770
  log_error("incompatible type for time: " + real_type);
@@ -4018,8 +4104,55 @@ function ac_load_table_rows(gobj, event, kw, src)
4018
4104
  function ac_record_changed(gobj, event, kw, src)
4019
4105
  {
4020
4106
  if(gobj_read_bool_attr(gobj, "initialized")) {
4107
+ let priv = gobj.priv;
4108
+ let open = priv.cell_edit;
4109
+ /* Typing in the open editor, and nothing else since it opened */
4110
+ let own = !!(open && kw && kw.typed_in === open.table_id &&
4111
+ open.seq === priv.change_seq);
4021
4112
  set_edited_by_reader(gobj);
4113
+ if(own) {
4114
+ open.seq = priv.change_seq;
4115
+ }
4116
+ }
4117
+ return 0;
4118
+ }
4119
+
4120
+ /************************************************************
4121
+ * A cell editor opened, in the table `table_id`: what the form
4122
+ * says now is what a cancel of it gives back.
4123
+ ************************************************************/
4124
+ function ac_cell_edit_opened(gobj, event, kw, src)
4125
+ {
4126
+ let priv = gobj.priv;
4127
+ priv.cell_edit = {
4128
+ table_id: kw.table_id,
4129
+ edited: gobj_read_bool_attr(gobj, "edited"),
4130
+ changes: gobj_read_bool_attr(gobj, "changes"),
4131
+ seq: priv.change_seq
4132
+ };
4133
+ return 0;
4134
+ }
4135
+
4136
+ /************************************************************
4137
+ * A cell editor cancelled -- Escape, or a box left as it was:
4138
+ * the value comes back, and so do the `edited` and `changes` the
4139
+ * form had when it opened. Up to gobj-ui 7.26.46 what was typed
4140
+ * in it still counted, and closing asked about a change that was
4141
+ * gone. Nothing is given back when anything but that editor's
4142
+ * own typing changed the form meanwhile: that change is real.
4143
+ ************************************************************/
4144
+ function ac_cell_edit_cancelled(gobj, event, kw, src)
4145
+ {
4146
+ let priv = gobj.priv;
4147
+ let open = priv.cell_edit;
4148
+ priv.cell_edit = null;
4149
+ if(!open || open.table_id !== kw.table_id || open.seq !== priv.change_seq) {
4150
+ return 0; // not the editor that opened, or the form changed meanwhile
4151
+ }
4152
+ if(gobj_read_bool_attr(gobj, "changes") !== open.changes) {
4153
+ set_changed_stated(gobj, open.changes);
4022
4154
  }
4155
+ gobj_write_bool_attr(gobj, "edited", open.edited);
4023
4156
  return 0;
4024
4157
  }
4025
4158
 
@@ -4225,6 +4358,7 @@ function cmd_get_picked_files(gobj, cmd, kw, src)
4225
4358
  *---------------------------------------------*/
4226
4359
  const gmt = {
4227
4360
  mt_create: mt_create,
4361
+ mt_writing: mt_writing,
4228
4362
  mt_start: mt_start,
4229
4363
  mt_stop: mt_stop,
4230
4364
  mt_destroy: mt_destroy,
@@ -4253,6 +4387,8 @@ function create_gclass(gclass_name)
4253
4387
  ["EV_ADD_TABLE_ROW", ac_add_table_row, null],
4254
4388
  ["EV_LOAD_TABLE_ROWS", ac_load_table_rows, null],
4255
4389
  ["EV_RECORD_CHANGED", ac_record_changed, null],
4390
+ ["EV_CELL_EDIT_OPENED", ac_cell_edit_opened, null],
4391
+ ["EV_CELL_EDIT_CANCELLED", ac_cell_edit_cancelled, null],
4256
4392
  ["EV_COPY_RECORD", ac_copy_record, null],
4257
4393
  ["EV_PASTE_RECORD", ac_paste_record, null],
4258
4394
  ["EV_SET_FILE_PREVIEW", ac_set_file_preview, null],
@@ -4280,6 +4416,8 @@ function create_gclass(gclass_name)
4280
4416
  ["EV_ADD_TABLE_ROW", 0],
4281
4417
  ["EV_LOAD_TABLE_ROWS", 0],
4282
4418
  ["EV_RECORD_CHANGED", 0],
4419
+ ["EV_CELL_EDIT_OPENED", 0],
4420
+ ["EV_CELL_EDIT_CANCELLED", 0],
4283
4421
  ["EV_COPY_RECORD", 0],
4284
4422
  ["EV_PASTE_RECORD", 0],
4285
4423
  ["EV_SET_FILE_PREVIEW", 0],