@yuneta/gobj-ui 7.31.7 → 7.31.8

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.
@@ -10494,6 +10494,19 @@ var DATE_TIME_OPTIONS = {
10494
10494
  second: "2-digit",
10495
10495
  hourCycle: "h23"
10496
10496
  };
10497
+ var __date_time_formatters__ = /* @__PURE__ */ new Map();
10498
+ var JANUARY = new Date(Date.UTC(2026, 0, 1));
10499
+ var JULY = new Date(Date.UTC(2026, 6, 1));
10500
+ function date_time_formatter(locale) {
10501
+ let loc = safe_locale(locale);
10502
+ let key = `${loc}|${JANUARY.getTimezoneOffset()}|${JULY.getTimezoneOffset()}`;
10503
+ let f = __date_time_formatters__.get(key);
10504
+ if (!f) {
10505
+ f = date_time_format(loc, DATE_TIME_OPTIONS);
10506
+ __date_time_formatters__.set(key, f);
10507
+ }
10508
+ return f;
10509
+ }
10497
10510
  /***************************************************************
10498
10511
  * A moment as a VIEW shows it as text: the day, the month and the
10499
10512
  * year, then the clock of 24 hours with its seconds, in the APP's
@@ -10504,7 +10517,8 @@ var DATE_TIME_OPTIONS = {
10504
10517
  * fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
10505
10518
  *
10506
10519
  * "" for anything that is not a valid Date. A locale Intl refuses
10507
- * writes in the environment's (date_time_format).
10520
+ * writes in the environment's (date_time_format). The formatter is
10521
+ * built once per locale and time zone (date_time_formatter).
10508
10522
  *
10509
10523
  * The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
10510
10524
  * the reading C_YUI_JSON writes beside a time field all come from
@@ -10512,7 +10526,7 @@ var DATE_TIME_OPTIONS = {
10512
10526
  ***************************************************************/
10513
10527
  function fmt_date_time(date, locale) {
10514
10528
  if (!(date instanceof Date) || isNaN(date.getTime())) return "";
10515
- return date_time_format(locale, DATE_TIME_OPTIONS).format(date);
10529
+ return date_time_formatter(locale).format(date);
10516
10530
  }
10517
10531
  /************************************************************
10518
10532
  * JSON type discriminator (viewer vocabulary)
@@ -44588,7 +44602,9 @@ var PRIVATE_DATA$14 = {
44588
44602
  lit_path: "",
44589
44603
  lit_parent_path: "",
44590
44604
  lit_port: "",
44591
- lit_found: false
44605
+ lit_found: false,
44606
+ lit_edge_id: "",
44607
+ cards: null
44592
44608
  };
44593
44609
  var __gclass__$14 = null;
44594
44610
  var __layout_registered__$1 = false;
@@ -44980,7 +44996,20 @@ function build_graph$4(gobj) {
44980
44996
  stroke: "#999",
44981
44997
  lineWidth: 1,
44982
44998
  endArrow: true
44983
- }
44999
+ },
45000
+ state: { lit: () => {
45001
+ let dark = yui_is_dark();
45002
+ let lit_color = dark ? LIT_COLOR_DARK$1 : LIT_COLOR_LIGHT$1;
45003
+ return {
45004
+ stroke: lit_color,
45005
+ lineWidth: 3,
45006
+ halo: true,
45007
+ haloStroke: dark ? LIT_HALO_DARK$1 : LIT_HALO_LIGHT$1,
45008
+ haloLineWidth: 8,
45009
+ endArrowFill: lit_color,
45010
+ endArrowStroke: lit_color
45011
+ };
45012
+ } }
44984
45013
  },
44985
45014
  layout: layout_cfg.g6_layout,
44986
45015
  behaviors: BEHAVIORS_READING$1.slice()
@@ -45189,19 +45218,19 @@ function get_group_label(path) {
45189
45218
  return path;
45190
45219
  }
45191
45220
  /************************************************************
45192
- * Recursively build nodes and edges from JSON
45221
+ * The rows of the card of `path`: one per key of `kw`, the
45222
+ * containers among them (`pending_complex`, each with the port
45223
+ * and the row it opens), and how many rows the find matched.
45193
45224
  ************************************************************/
45194
- function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port) {
45195
- let group_id = gen_node_id$1(gobj);
45196
- let is_dict = is_object(kw);
45197
- let is_list = is_array(kw);
45198
- if (!is_dict && !is_list) return null;
45225
+ function card_rows_of(gobj, path, kw) {
45199
45226
  let priv = gobj.priv;
45227
+ let is_dict = is_object(kw);
45200
45228
  let needle = priv.search || "";
45201
45229
  let dark = yui_is_dark();
45202
45230
  let lines = [];
45203
45231
  let pending_complex = [];
45204
45232
  let card_matched = false;
45233
+ let matches = 0;
45205
45234
  let colors = json_card_style(is_dict ? GROUP_COLORS.dict : GROUP_COLORS.list, dark);
45206
45235
  let entries = is_dict ? Object.entries(kw) : kw.map((v, i) => [i, v]);
45207
45236
  for (let [key, value] of entries) {
@@ -45209,7 +45238,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45209
45238
  let matched = cell_matches(key, value, type, needle);
45210
45239
  if (matched) {
45211
45240
  card_matched = true;
45212
- priv.match_count++;
45241
+ matches++;
45213
45242
  }
45214
45243
  let fold = null;
45215
45244
  if (has_branch(value)) {
@@ -45231,21 +45260,37 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45231
45260
  }
45232
45261
  lines.push(build_cell_html(key, value, type, dark, matched, fold));
45233
45262
  }
45234
- if (parent_id && is_pure_collection(kw)) {
45235
- if (priv.collapsed.has(path)) {
45236
- push_fold_phantom(gobj, path, parent_id, parent_port, nodes, edges);
45237
- return parent_id;
45238
- }
45239
- for (let pending of pending_complex) build_json_nodes(gobj, add_segment(path, pending.key), pending.value, nodes, edges, parent_id, parent_port);
45240
- return parent_id;
45241
- }
45263
+ return {
45264
+ is_dict,
45265
+ dark,
45266
+ colors,
45267
+ lines,
45268
+ pending_complex,
45269
+ card_matched,
45270
+ matches
45271
+ };
45272
+ }
45273
+ /************************************************************
45274
+ * The html of the card of `path`, from its rows (card_rows_of),
45275
+ * lit or not as priv.lit_* says now. The build draws every card
45276
+ * with it, and repaint_cards() one card alone: the same moment
45277
+ * reads the same either way.
45278
+ ************************************************************/
45279
+ function card_html_of(gobj, path, rows, has_parent) {
45280
+ let priv = gobj.priv;
45281
+ let is_dict = rows.is_dict;
45282
+ let dark = rows.dark;
45283
+ let colors = rows.colors;
45284
+ let lines = rows.lines;
45285
+ let pending_complex = rows.pending_complex;
45286
+ let card_matched = rows.card_matched;
45242
45287
  let label = get_group_label(path) || (is_dict ? "{}" : "[]");
45243
45288
  let foldable = pending_complex.length > 0;
45244
45289
  let folded = foldable && priv.collapsed.has(path);
45245
45290
  let border_color = card_matched ? dark ? "#ffb300" : "#ff8f00" : colors.border;
45246
45291
  let border_width = card_matched ? 2 : 1;
45247
45292
  let lit_color = dark ? LIT_COLOR_DARK$1 : LIT_COLOR_LIGHT$1;
45248
- let lit_child = !!parent_id && !empty_string(priv.lit_path) && path === priv.lit_path;
45293
+ let lit_child = has_parent && !empty_string(priv.lit_path) && path === priv.lit_path;
45249
45294
  let lit_row = -1;
45250
45295
  let lit_parent = !empty_string(priv.lit_path) && path === priv.lit_parent_path;
45251
45296
  if (lit_parent) {
@@ -45255,7 +45300,6 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45255
45300
  }
45256
45301
  }
45257
45302
  let lit_card = lit_child || lit_parent;
45258
- if (lit_child) priv.lit_found = true;
45259
45303
  if (lit_card) {
45260
45304
  border_color = lit_color;
45261
45305
  border_width = 3;
@@ -45265,7 +45309,8 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45265
45309
  }).join("");
45266
45310
  let min_width = Math.max(180, label.length * 9);
45267
45311
  let card_height = CARD_HEADER_H$1 + lines.length * CARD_ROW_H$1;
45268
- let node_html = `
45312
+ return {
45313
+ node_html: `
45269
45314
  <div class="JSON_CARD" data-json-path="${escapeHtml(path)}" style="
45270
45315
  min-width: ${min_width}px;
45271
45316
  background: ${colors.bg};
@@ -45286,7 +45331,41 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45286
45331
  gap: 6px;
45287
45332
  ">${FOLD_SPACER}<span style="flex:1 1 auto; text-align:center;">${escapeHtml(label)}</span>${fold_toggle_html(path, foldable, folded, pending_complex.length, colors)}</div>
45288
45333
  ${content_html}
45289
- </div>`;
45334
+ </div>`,
45335
+ min_width,
45336
+ card_height,
45337
+ folded,
45338
+ lit_child
45339
+ };
45340
+ }
45341
+ /************************************************************
45342
+ * Recursively build nodes and edges from JSON
45343
+ ************************************************************/
45344
+ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port) {
45345
+ let group_id = gen_node_id$1(gobj);
45346
+ let is_dict = is_object(kw);
45347
+ let is_list = is_array(kw);
45348
+ if (!is_dict && !is_list) return null;
45349
+ let priv = gobj.priv;
45350
+ let rows = card_rows_of(gobj, path, kw);
45351
+ let dark = rows.dark;
45352
+ let colors = rows.colors;
45353
+ let pending_complex = rows.pending_complex;
45354
+ priv.match_count += rows.matches;
45355
+ if (parent_id && is_pure_collection(kw)) {
45356
+ if (priv.collapsed.has(path)) {
45357
+ push_fold_phantom(gobj, path, parent_id, parent_port, nodes, edges);
45358
+ return parent_id;
45359
+ }
45360
+ for (let pending of pending_complex) build_json_nodes(gobj, add_segment(path, pending.key), pending.value, nodes, edges, parent_id, parent_port);
45361
+ return parent_id;
45362
+ }
45363
+ let card = card_html_of(gobj, path, rows, !!parent_id);
45364
+ let folded = card.folded;
45365
+ let lit_child = card.lit_child;
45366
+ let min_width = card.min_width;
45367
+ let card_height = card.card_height;
45368
+ if (lit_child) priv.lit_found = true;
45290
45369
  let ports = [];
45291
45370
  if (parent_id) ports.push({
45292
45371
  key: "in",
@@ -45312,7 +45391,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45312
45391
  is_dict
45313
45392
  },
45314
45393
  style: {
45315
- innerHTML: node_html,
45394
+ innerHTML: card.node_html,
45316
45395
  size: [min_width, card_height],
45317
45396
  dx: -(min_width / 2),
45318
45397
  dy: -(card_height / 2),
@@ -45323,8 +45402,14 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45323
45402
  }
45324
45403
  };
45325
45404
  nodes.push(node);
45405
+ priv.cards.set(path, {
45406
+ id: group_id,
45407
+ kw,
45408
+ has_parent: !!parent_id
45409
+ });
45326
45410
  if (parent_id) {
45327
45411
  let edge = {
45412
+ id: "je-" + group_id,
45328
45413
  source: parent_id,
45329
45414
  target: group_id,
45330
45415
  style: {
@@ -45339,15 +45424,10 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id, parent_port)
45339
45424
  }
45340
45425
  };
45341
45426
  if (parent_port) edge.style.sourcePort = parent_port;
45342
- if (lit_child) Object.assign(edge.style, {
45343
- stroke: lit_color,
45344
- lineWidth: 3,
45345
- halo: true,
45346
- haloStroke: dark ? LIT_HALO_DARK$1 : LIT_HALO_LIGHT$1,
45347
- haloLineWidth: 8,
45348
- endArrowFill: lit_color,
45349
- endArrowStroke: lit_color
45350
- });
45427
+ if (lit_child) {
45428
+ edge.states = ["lit"];
45429
+ priv.lit_edge_id = edge.id;
45430
+ }
45351
45431
  edges.push(edge);
45352
45432
  }
45353
45433
  if (folded) {
@@ -45420,6 +45500,8 @@ function load_json(gobj) {
45420
45500
  priv.node_counter = 0;
45421
45501
  priv.match_count = 0;
45422
45502
  priv.lit_found = false;
45503
+ priv.lit_edge_id = "";
45504
+ priv.cards = /* @__PURE__ */ new Map();
45423
45505
  let nodes = [];
45424
45506
  let edges = [];
45425
45507
  build_json_nodes(gobj, path, json, nodes, edges, null);
@@ -45623,6 +45705,86 @@ function refresh_json(gobj, opts) {
45623
45705
  }
45624
45706
  }
45625
45707
  /************************************************************
45708
+ * Repaint the cards of these paths alone, lit or not as
45709
+ * priv.lit_* says now, and draw once. A click on an edge
45710
+ * changes two cards: rebuilding the graph for them redrew
45711
+ * every card, the layout and the camera's frame.
45712
+ ************************************************************/
45713
+ function repaint_cards$2(gobj, paths) {
45714
+ let priv = gobj.priv;
45715
+ let graph = priv.graph;
45716
+ if (!graph || !priv.cards) return;
45717
+ let updates = [];
45718
+ for (let path of paths) {
45719
+ let c = priv.cards.get(path);
45720
+ if (!c) continue;
45721
+ let card = card_html_of(gobj, path, card_rows_of(gobj, path, c.kw), c.has_parent);
45722
+ updates.push({
45723
+ id: c.id,
45724
+ style: { innerHTML: card.node_html }
45725
+ });
45726
+ }
45727
+ try {
45728
+ if (updates.length) graph.updateNodeData(updates);
45729
+ Promise.resolve(graph.draw()).then(() => {
45730
+ paint_anchor_mark$1(gobj);
45731
+ }).catch((e) => {
45732
+ log_error(`${gobj_short_name(gobj)}: redraw failed: ${e}`);
45733
+ });
45734
+ } catch (e) {
45735
+ log_error(`${gobj_short_name(gobj)}: cannot repaint the cards: ${e}`);
45736
+ }
45737
+ }
45738
+ /************************************************************
45739
+ * Put the lit edge out: its state off, and the paths of its
45740
+ * two cards returned, to be repainted plain. Draws nothing:
45741
+ * the caller repaints once, and two draws race. [] when
45742
+ * nothing is lit.
45743
+ ************************************************************/
45744
+ function put_out_edge(gobj) {
45745
+ let priv = gobj.priv;
45746
+ let graph = priv.graph;
45747
+ if (empty_string(priv.lit_path)) return [];
45748
+ let paths = [priv.lit_path, priv.lit_parent_path];
45749
+ let edge_id = priv.lit_edge_id;
45750
+ priv.lit_path = "";
45751
+ priv.lit_parent_path = "";
45752
+ priv.lit_port = "";
45753
+ priv.lit_edge_id = "";
45754
+ if (graph && !empty_string(edge_id)) try {
45755
+ graph.updateData({ edges: [{
45756
+ id: edge_id,
45757
+ states: []
45758
+ }] });
45759
+ } catch (e) {
45760
+ log_error(`${gobj_short_name(gobj)}: edge state not cleared: ${e}`);
45761
+ }
45762
+ return paths;
45763
+ }
45764
+ /************************************************************
45765
+ * Light an edge: its `lit` state on, and the paths of its two
45766
+ * cards returned, to be repainted with the ring (the parent's
45767
+ * row of the key it leaves from washed). The cards are html,
45768
+ * where G6 paints no state, so their mark is in their html.
45769
+ * Draws nothing, as put_out_edge().
45770
+ ************************************************************/
45771
+ function light_edge$2(gobj, edge_id, child_path, parent_path, port) {
45772
+ let priv = gobj.priv;
45773
+ priv.lit_path = child_path;
45774
+ priv.lit_parent_path = parent_path;
45775
+ priv.lit_port = port;
45776
+ priv.lit_edge_id = edge_id;
45777
+ try {
45778
+ priv.graph.updateData({ edges: [{
45779
+ id: edge_id,
45780
+ states: ["lit"]
45781
+ }] });
45782
+ } catch (e) {
45783
+ log_error(`${gobj_short_name(gobj)}: edge state not set: ${e}`);
45784
+ }
45785
+ return [child_path, parent_path];
45786
+ }
45787
+ /************************************************************
45626
45788
  * Custom tree layout for JSON visualization
45627
45789
  ************************************************************/
45628
45790
  var JsonTreeLayout = class extends BaseLayout {
@@ -45723,6 +45885,7 @@ function ac_load_data$1(gobj, event, kw, src) {
45723
45885
  gobj.priv.lit_path = "";
45724
45886
  gobj.priv.lit_parent_path = "";
45725
45887
  gobj.priv.lit_port = "";
45888
+ gobj.priv.lit_edge_id = "";
45726
45889
  }
45727
45890
  refresh_json(gobj);
45728
45891
  return 0;
@@ -45840,10 +46003,10 @@ function ac_collapse_all$2(gobj, event, kw, src) {
45840
46003
  * EV_EDGE_CLICK { id }
45841
46004
  *
45842
46005
  * Light the edge and its two ends, or put it out when it is
45843
- * the lit one. Baked into the drawing, like a find match: the
45844
- * cards are html, where G6 paints no state, so the drawing is
45845
- * rebuilt with the camera kept. The edge is kept by the PATH
45846
- * of its child card, which a rebuild keeps and the ids do not.
46006
+ * the lit one. Only the edge and its two cards are redrawn
46007
+ * (light_edge). The edge is kept by the PATH of its child
46008
+ * card, which a rebuild (a fold, a find) keeps and the ids do
46009
+ * not: the rebuild lights it again.
45847
46010
  ************************************************************/
45848
46011
  function ac_edge_click$2(gobj, event, kw, src) {
45849
46012
  let priv = gobj.priv;
@@ -45862,16 +46025,10 @@ function ac_edge_click$2(gobj, event, kw, src) {
45862
46025
  }
45863
46026
  let tdata = target && target.data || {};
45864
46027
  if (tdata.phantom || empty_string(tdata.path)) return 0;
45865
- if (priv.lit_path === tdata.path) {
45866
- priv.lit_path = "";
45867
- priv.lit_parent_path = "";
45868
- priv.lit_port = "";
45869
- } else {
45870
- priv.lit_path = tdata.path;
45871
- priv.lit_parent_path = source && source.data && source.data.path || "";
45872
- priv.lit_port = edge.style && edge.style.sourcePort || "";
45873
- }
45874
- refresh_json(gobj, { preserve_view: true });
46028
+ let same = priv.lit_path === tdata.path;
46029
+ let paths = put_out_edge(gobj);
46030
+ if (!same) paths = paths.concat(light_edge$2(gobj, edge.id, tdata.path, source && source.data && source.data.path || "", edge.style && edge.style.sourcePort || ""));
46031
+ repaint_cards$2(gobj, new Set(paths));
45875
46032
  return 0;
45876
46033
  }
45877
46034
  /************************************************************
@@ -45880,10 +46037,7 @@ function ac_edge_click$2(gobj, event, kw, src) {
45880
46037
  function ac_canvas_click$2(gobj, event, kw, src) {
45881
46038
  let priv = gobj.priv;
45882
46039
  if (empty_string(priv.lit_path)) return 0;
45883
- priv.lit_path = "";
45884
- priv.lit_parent_path = "";
45885
- priv.lit_port = "";
45886
- refresh_json(gobj, { preserve_view: true });
46040
+ repaint_cards$2(gobj, put_out_edge(gobj));
45887
46041
  return 0;
45888
46042
  }
45889
46043
  /************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.31.7",
3
+ "version": "7.31.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",