@yuneta/gobj-ui 7.23.19 → 7.23.20

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.
@@ -10159,6 +10159,268 @@ function ensure_drag_canvas_patch() {
10159
10159
  register(ExtensionCategory.BEHAVIOR, "drag-canvas", DragCanvasTouch);
10160
10160
  __drag_canvas_patched__ = true;
10161
10161
  }
10162
+ /************************************************************
10163
+ * JSON type discriminator (viewer vocabulary)
10164
+ ************************************************************/
10165
+ function json_type(value) {
10166
+ if (value === null) return "null";
10167
+ if (Array.isArray(value)) return "array";
10168
+ switch (typeof value) {
10169
+ case "string": return "string";
10170
+ case "number": return "number";
10171
+ case "boolean": return "boolean";
10172
+ case "object": return "object";
10173
+ default: return "unknown";
10174
+ }
10175
+ }
10176
+ /************************************************************
10177
+ * Detect a kw_collapse() sentinel.
10178
+ *
10179
+ * The kernel replaces an over-limit dict with:
10180
+ * { "__collapsed__": { "path": ..., "size": N } }
10181
+ * and an over-limit array with:
10182
+ * [ { "__collapsed__": { "path": ..., "size": N } } ]
10183
+ *
10184
+ * Returns { size, path, is_array } or null.
10185
+ ************************************************************/
10186
+ function is_collapsed(value) {
10187
+ if (value && typeof value === "object" && !Array.isArray(value)) {
10188
+ let keys = Object.keys(value);
10189
+ if (keys.length === 1 && keys[0] === "__collapsed__") {
10190
+ let c = value.__collapsed__ || {};
10191
+ return {
10192
+ size: c.size,
10193
+ path: c.path,
10194
+ is_array: false
10195
+ };
10196
+ }
10197
+ return null;
10198
+ }
10199
+ if (Array.isArray(value) && value.length === 1) {
10200
+ let e = value[0];
10201
+ if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
10202
+ let c = e.__collapsed__ || {};
10203
+ return {
10204
+ size: c.size,
10205
+ path: c.path,
10206
+ is_array: true
10207
+ };
10208
+ }
10209
+ }
10210
+ return null;
10211
+ }
10212
+ /************************************************************
10213
+ * Join / split absolute path segments (kernel convention)
10214
+ ************************************************************/
10215
+ function seg_join(segments) {
10216
+ return segments.map(function(s) {
10217
+ return String(s);
10218
+ }).join("`");
10219
+ }
10220
+ function seg_split(path) {
10221
+ if (path === "" || path === null || path === void 0) return [];
10222
+ return path.split("`");
10223
+ }
10224
+ /************************************************************
10225
+ * Walk a JSON tree by absolute segments; undefined if the
10226
+ * path does not resolve.
10227
+ ************************************************************/
10228
+ function get_by_segments(root, segments) {
10229
+ let v = root;
10230
+ for (let seg of segments) {
10231
+ if (v === null || v === void 0) return;
10232
+ if (Array.isArray(v)) v = v[Number(seg)];
10233
+ else if (typeof v === "object") v = v[seg];
10234
+ else return;
10235
+ }
10236
+ return v;
10237
+ }
10238
+ /************************************************************
10239
+ * Set a value at absolute segments (mutates root).
10240
+ *
10241
+ * segments == [] means "replace the whole root" — the caller
10242
+ * must use the RETURNED value in that case (a primitive/array
10243
+ * root cannot be mutated in place).
10244
+ ************************************************************/
10245
+ function set_by_segments(root, segments, new_value) {
10246
+ if (segments.length === 0) return new_value;
10247
+ let parent = get_by_segments(root, segments.slice(0, -1));
10248
+ if (parent === null || parent === void 0 || typeof parent !== "object") return root;
10249
+ let last = segments[segments.length - 1];
10250
+ if (Array.isArray(parent)) parent[Number(last)] = new_value;
10251
+ else parent[last] = new_value;
10252
+ return root;
10253
+ }
10254
+ /************************************************************
10255
+ * Does `value` (or any loaded descendant / its own key)
10256
+ * contain the lower-cased search term?
10257
+ *
10258
+ * Collapsed (not-yet-loaded) subtrees can't be searched, so
10259
+ * they never match on content — only their key can match,
10260
+ * which the renderer checks separately.
10261
+ ************************************************************/
10262
+ function subtree_matches(value, term) {
10263
+ if (!term) return true;
10264
+ if (is_collapsed(value)) return false;
10265
+ let type = json_type(value);
10266
+ if (type === "object") {
10267
+ for (let [k, v] of Object.entries(value)) {
10268
+ if (String(k).toLowerCase().includes(term)) return true;
10269
+ if (subtree_matches(v, term)) return true;
10270
+ }
10271
+ return false;
10272
+ }
10273
+ if (type === "array") {
10274
+ for (let v of value) if (subtree_matches(v, term)) return true;
10275
+ return false;
10276
+ }
10277
+ return String(value).toLowerCase().includes(term);
10278
+ }
10279
+ /************************************************************
10280
+ * Fields whose numeric value is an epoch timestamp.
10281
+ * Mirrors the timestampTag list wired into C_YUI_FORM's
10282
+ * jsoneditor control, so the two viewers agree.
10283
+ ************************************************************/
10284
+ function is_time_field(field) {
10285
+ return field === "__t__" || field === "__tm__" || field === "tm" || field === "t" || field === "time" || field === "from_t" || field === "to_t" || field === "t_input" || field === "t_output" || field === "from_tm" || field === "to_tm";
10286
+ }
10287
+ /************************************************************
10288
+ * Format an epoch value as a local wall-clock string.
10289
+ * Accepts seconds or milliseconds; returns null when the
10290
+ * value is not a usable positive timestamp (0 == "unset").
10291
+ ************************************************************/
10292
+ function format_epoch(value) {
10293
+ if (typeof value !== "number" || !isFinite(value) || value <= 0) return null;
10294
+ let ms = Math.abs(value) < 0xe8d4a51000 ? value * 1e3 : value;
10295
+ let d = new Date(ms);
10296
+ if (isNaN(d.getTime())) return null;
10297
+ return d.toLocaleString();
10298
+ }
10299
+ /************************************************************
10300
+ * The text view's payload: the document as text, indented
10301
+ * four characters, cut at `max_chars`.
10302
+ *
10303
+ * Returns {text, capped}. `capped` is what the caller
10304
+ * announces under the dump — a cut that is not announced
10305
+ * reads as a document that ends there.
10306
+ ************************************************************/
10307
+ function json_text_dump(root, max_chars) {
10308
+ let text;
10309
+ try {
10310
+ text = JSON.stringify(root, null, 4);
10311
+ } catch (e) {
10312
+ return {
10313
+ text: "",
10314
+ capped: false,
10315
+ error: String(e)
10316
+ };
10317
+ }
10318
+ if (text === void 0) return {
10319
+ text: "",
10320
+ capped: false,
10321
+ error: "not representable as JSON"
10322
+ };
10323
+ if (typeof max_chars === "number" && max_chars > 0 && text.length > max_chars) return {
10324
+ text: text.slice(0, max_chars),
10325
+ capped: true
10326
+ };
10327
+ return {
10328
+ text,
10329
+ capped: false
10330
+ };
10331
+ }
10332
+ /************************************************************
10333
+ * Which view a freshly mounted viewer opens on.
10334
+ *
10335
+ * Three answers, in order of authority: what the HOST asked
10336
+ * for, what the READER chose last time, and `fallback`.
10337
+ *
10338
+ * The host wins because a viewer mounted to show a graph has
10339
+ * to show one. The memory comes next, because reopening a
10340
+ * document in the view you just left is the whole point of
10341
+ * remembering it. `fallback` is the floor.
10342
+ *
10343
+ * Anything not in `modes` is treated as unsaid, which covers
10344
+ * an absent value, an empty one, and a stored string from an
10345
+ * older release that named a view no longer offered.
10346
+ ************************************************************/
10347
+ function pick_view_mode(asked, remembered, modes, fallback) {
10348
+ let known = (m) => Array.isArray(modes) && modes.indexOf(m) >= 0;
10349
+ if (known(asked)) return asked;
10350
+ if (known(remembered)) return remembered;
10351
+ return fallback;
10352
+ }
10353
+ /************************************************************
10354
+ * The short label a container row carries beside its size.
10355
+ *
10356
+ * An array of dicts that carry an `id` is a list of RECORDS,
10357
+ * and a row that says only `2: {15}` makes you open all
10358
+ * fifteen fields of every one of them to find out WHICH
10359
+ * record it is. The id is the one field that answers that,
10360
+ * so the row says it without being opened.
10361
+ *
10362
+ * Only a SCALAR id, and only when it is really there: an `id`
10363
+ * that is itself a dict or a list is not a name, it is more
10364
+ * document, and printing `[object Object]` beside the size
10365
+ * would be worse than printing nothing.
10366
+ *
10367
+ * Cut at `max_chars`, because this rides on a row whose job
10368
+ * is to stay one line.
10369
+ ************************************************************/
10370
+ function container_label(value, max_chars) {
10371
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return "";
10372
+ if (!Object.prototype.hasOwnProperty.call(value, "id")) return "";
10373
+ let id = value.id;
10374
+ let t = typeof id;
10375
+ if (t !== "string" && t !== "number" && t !== "boolean") return "";
10376
+ let text = String(id).trim();
10377
+ if (text === "") return "";
10378
+ let cap = typeof max_chars === "number" && max_chars > 0 ? max_chars : 0;
10379
+ if (cap && text.length > cap) return text.slice(0, cap) + "…";
10380
+ return text;
10381
+ }
10382
+ /************************************************************
10383
+ * A dict, in the JSON sense: not an array and not null.
10384
+ ************************************************************/
10385
+ function is_plain_object(v) {
10386
+ return v !== null && typeof v === "object" && !Array.isArray(v);
10387
+ }
10388
+ /************************************************************
10389
+ * Does this container hold ONLY other containers?
10390
+ *
10391
+ * Such a value is not a thing, it is a LIST of things -- and a
10392
+ * list is fully described by the row that names it in its
10393
+ * parent, plus the edges to what it holds. Drawing it as a
10394
+ * card of its own put a node in the middle of the graph with no
10395
+ * data in it, saying nothing the parent's row did not already
10396
+ * say, and pushed everything below it one level down.
10397
+ *
10398
+ * An EMPTY container inside counts as content: `{0}` is
10399
+ * something the card has to show, and there is no child card
10400
+ * to show it instead.
10401
+ ************************************************************/
10402
+ function is_pure_collection(value) {
10403
+ let entries = is_plain_object(value) ? Object.entries(value) : Array.isArray(value) ? value.map((v, i) => [i, v]) : [];
10404
+ if (entries.length === 0) return false;
10405
+ for (let [, v] of entries) if (!has_branch(v)) return false;
10406
+ return true;
10407
+ }
10408
+ /************************************************************
10409
+ * A value that gets a card, or children, of its own.
10410
+ ************************************************************/
10411
+ function has_branch(value) {
10412
+ return is_plain_object(value) && Object.keys(value).length > 0 || Array.isArray(value) && value.length > 0;
10413
+ }
10414
+ /************************************************************
10415
+ * How many branches a container has, which is what the fold
10416
+ * chip counts.
10417
+ ************************************************************/
10418
+ function count_branches(value) {
10419
+ let entries = is_plain_object(value) ? Object.values(value) : Array.isArray(value) ? value : [];
10420
+ let n = 0;
10421
+ for (let v of entries) if (has_branch(v)) n++;
10422
+ return n;
10423
+ }
10162
10424
  //#endregion
10163
10425
  //#region src/c_yui_json_graph.js
10164
10426
  /***********************************************************************
@@ -10669,7 +10931,7 @@ function build_graph$3(gobj) {
10669
10931
  /************************************************************
10670
10932
  * Build cell value HTML (matching old mx_json_viewer colors)
10671
10933
  ************************************************************/
10672
- function build_cell_html(key, value, type, dark, matched) {
10934
+ function build_cell_html(key, value, type, dark, matched, fold) {
10673
10935
  let on_light = matched ? false : dark;
10674
10936
  let color = type_color(type, on_light);
10675
10937
  let key_color = json_card_style(GROUP_COLORS.dict, on_light).key;
@@ -10696,6 +10958,7 @@ function build_cell_html(key, value, type, dark, matched) {
10696
10958
  default: display_value = String(value);
10697
10959
  }
10698
10960
  let row = `<span style="color:${key_color}">• ${escapeHtml(String(key))}: </span><span style="color:${color}">${display_value}</span>`;
10961
+ if (fold) row += `<span style="margin-left:8px;">` + fold_toggle_html(fold.path, true, fold.folded, fold.branches, fold.colors) + `</span>`;
10699
10962
  if (matched) row = `<span style="background:#ffe082; border-radius:2px; padding:0 2px;">${row}</span>`;
10700
10963
  return row;
10701
10964
  }
@@ -10819,6 +11082,7 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id) {
10819
11082
  let lines = [];
10820
11083
  let pending_complex = [];
10821
11084
  let card_matched = false;
11085
+ let colors = json_card_style(is_dict ? GROUP_COLORS.dict : GROUP_COLORS.list, dark);
10822
11086
  let entries = is_dict ? Object.entries(kw) : kw.map((v, i) => [i, v]);
10823
11087
  for (let [key, value] of entries) {
10824
11088
  let type = get_json_type(value);
@@ -10827,20 +11091,32 @@ function build_json_nodes(gobj, path, kw, nodes, edges, parent_id) {
10827
11091
  card_matched = true;
10828
11092
  priv.match_count++;
10829
11093
  }
10830
- if (is_object(value) && json_object_size(value) > 0 || is_array(value) && value.length > 0) {
11094
+ let fold = null;
11095
+ if (has_branch(value)) {
10831
11096
  pending_complex.push({
10832
11097
  key,
10833
11098
  value
10834
11099
  });
10835
- continue;
11100
+ if (is_pure_collection(value)) {
11101
+ let child_path = add_segment(path, key);
11102
+ fold = {
11103
+ path: child_path,
11104
+ folded: priv.collapsed.has(child_path),
11105
+ branches: count_branches(value),
11106
+ colors
11107
+ };
11108
+ }
10836
11109
  }
10837
- lines.push(build_cell_html(key, value, type, dark, matched));
11110
+ lines.push(build_cell_html(key, value, type, dark, matched, fold));
11111
+ }
11112
+ if (parent_id && is_pure_collection(kw)) {
11113
+ if (priv.collapsed.has(path)) return parent_id;
11114
+ for (let pending of pending_complex) build_json_nodes(gobj, add_segment(path, pending.key), pending.value, nodes, edges, parent_id);
11115
+ return parent_id;
10838
11116
  }
10839
11117
  let label = get_group_label(path) || (is_dict ? "{}" : "[]");
10840
- if (pending_complex.length > 0) label += is_dict ? ` {${pending_complex.length}}` : ` [${pending_complex.length}]`;
10841
11118
  let foldable = pending_complex.length > 0;
10842
11119
  let folded = foldable && priv.collapsed.has(path);
10843
- let colors = json_card_style(is_dict ? GROUP_COLORS.dict : GROUP_COLORS.list, dark);
10844
11120
  let border_color = card_matched ? dark ? "#ffb300" : "#ff8f00" : colors.border;
10845
11121
  let border_width = card_matched ? 2 : 1;
10846
11122
  let content_html = lines.map((line) => `<div style="font-family:monospace; font-size:13px; padding:1px 6px; white-space:nowrap;">${line}</div>`).join("");
@@ -10934,22 +11210,25 @@ function load_json(gobj) {
10934
11210
  }
10935
11211
  /************************************************************
10936
11212
  * Every path that HAS a branch to fold, in the same recursion
10937
- * build_json_nodes uses — so "collapse all" can never name a
10938
- * card that does not exist. The root is excluded: folding it
11213
+ * build_json_nodes uses — so "collapse all" can never name
11214
+ * something with no handle. The handle is a card's header chip
11215
+ * for a container that gets a card, and the chip on its ROW in
11216
+ * the parent for a pure collection, which gets none; both are
11217
+ * keyed by this same path. The root is excluded: folding it
10939
11218
  * would leave an empty canvas.
10940
11219
  ************************************************************/
10941
11220
  function collect_foldable_paths(value, path, out, is_root) {
10942
11221
  let is_dict = is_object(value);
10943
11222
  let is_list = is_array(value);
10944
11223
  if (!is_dict && !is_list) return false;
10945
- let has_branch = false;
11224
+ let found_branch = false;
10946
11225
  let entries = is_dict ? Object.entries(value) : value.map((v, i) => [i, v]);
10947
- for (let [key, child] of entries) if (is_object(child) && json_object_size(child) > 0 || is_array(child) && child.length > 0) {
10948
- has_branch = true;
11226
+ for (let [key, child] of entries) if (has_branch(child)) {
11227
+ found_branch = true;
10949
11228
  collect_foldable_paths(child, add_segment(path, key), out, false);
10950
11229
  }
10951
- if (has_branch && !is_root) out.push(path);
10952
- return has_branch;
11230
+ if (found_branch && !is_root) out.push(path);
11231
+ return found_branch;
10953
11232
  }
10954
11233
  /************************************************************
10955
11234
  * Show the find count, or hide the chip when there is no
@@ -11508,226 +11787,6 @@ function register_c_yui_json_graph() {
11508
11787
  if (gclass_find_by_name(GCLASS_NAME$11, false)) return 0;
11509
11788
  return create_gclass$11(GCLASS_NAME$11);
11510
11789
  }
11511
- /************************************************************
11512
- * JSON type discriminator (viewer vocabulary)
11513
- ************************************************************/
11514
- function json_type(value) {
11515
- if (value === null) return "null";
11516
- if (Array.isArray(value)) return "array";
11517
- switch (typeof value) {
11518
- case "string": return "string";
11519
- case "number": return "number";
11520
- case "boolean": return "boolean";
11521
- case "object": return "object";
11522
- default: return "unknown";
11523
- }
11524
- }
11525
- /************************************************************
11526
- * Detect a kw_collapse() sentinel.
11527
- *
11528
- * The kernel replaces an over-limit dict with:
11529
- * { "__collapsed__": { "path": ..., "size": N } }
11530
- * and an over-limit array with:
11531
- * [ { "__collapsed__": { "path": ..., "size": N } } ]
11532
- *
11533
- * Returns { size, path, is_array } or null.
11534
- ************************************************************/
11535
- function is_collapsed(value) {
11536
- if (value && typeof value === "object" && !Array.isArray(value)) {
11537
- let keys = Object.keys(value);
11538
- if (keys.length === 1 && keys[0] === "__collapsed__") {
11539
- let c = value.__collapsed__ || {};
11540
- return {
11541
- size: c.size,
11542
- path: c.path,
11543
- is_array: false
11544
- };
11545
- }
11546
- return null;
11547
- }
11548
- if (Array.isArray(value) && value.length === 1) {
11549
- let e = value[0];
11550
- if (e && typeof e === "object" && !Array.isArray(e) && Object.keys(e).length === 1 && e.__collapsed__) {
11551
- let c = e.__collapsed__ || {};
11552
- return {
11553
- size: c.size,
11554
- path: c.path,
11555
- is_array: true
11556
- };
11557
- }
11558
- }
11559
- return null;
11560
- }
11561
- /************************************************************
11562
- * Join / split absolute path segments (kernel convention)
11563
- ************************************************************/
11564
- function seg_join(segments) {
11565
- return segments.map(function(s) {
11566
- return String(s);
11567
- }).join("`");
11568
- }
11569
- function seg_split(path) {
11570
- if (path === "" || path === null || path === void 0) return [];
11571
- return path.split("`");
11572
- }
11573
- /************************************************************
11574
- * Walk a JSON tree by absolute segments; undefined if the
11575
- * path does not resolve.
11576
- ************************************************************/
11577
- function get_by_segments(root, segments) {
11578
- let v = root;
11579
- for (let seg of segments) {
11580
- if (v === null || v === void 0) return;
11581
- if (Array.isArray(v)) v = v[Number(seg)];
11582
- else if (typeof v === "object") v = v[seg];
11583
- else return;
11584
- }
11585
- return v;
11586
- }
11587
- /************************************************************
11588
- * Set a value at absolute segments (mutates root).
11589
- *
11590
- * segments == [] means "replace the whole root" — the caller
11591
- * must use the RETURNED value in that case (a primitive/array
11592
- * root cannot be mutated in place).
11593
- ************************************************************/
11594
- function set_by_segments(root, segments, new_value) {
11595
- if (segments.length === 0) return new_value;
11596
- let parent = get_by_segments(root, segments.slice(0, -1));
11597
- if (parent === null || parent === void 0 || typeof parent !== "object") return root;
11598
- let last = segments[segments.length - 1];
11599
- if (Array.isArray(parent)) parent[Number(last)] = new_value;
11600
- else parent[last] = new_value;
11601
- return root;
11602
- }
11603
- /************************************************************
11604
- * Does `value` (or any loaded descendant / its own key)
11605
- * contain the lower-cased search term?
11606
- *
11607
- * Collapsed (not-yet-loaded) subtrees can't be searched, so
11608
- * they never match on content — only their key can match,
11609
- * which the renderer checks separately.
11610
- ************************************************************/
11611
- function subtree_matches(value, term) {
11612
- if (!term) return true;
11613
- if (is_collapsed(value)) return false;
11614
- let type = json_type(value);
11615
- if (type === "object") {
11616
- for (let [k, v] of Object.entries(value)) {
11617
- if (String(k).toLowerCase().includes(term)) return true;
11618
- if (subtree_matches(v, term)) return true;
11619
- }
11620
- return false;
11621
- }
11622
- if (type === "array") {
11623
- for (let v of value) if (subtree_matches(v, term)) return true;
11624
- return false;
11625
- }
11626
- return String(value).toLowerCase().includes(term);
11627
- }
11628
- /************************************************************
11629
- * Fields whose numeric value is an epoch timestamp.
11630
- * Mirrors the timestampTag list wired into C_YUI_FORM's
11631
- * jsoneditor control, so the two viewers agree.
11632
- ************************************************************/
11633
- function is_time_field(field) {
11634
- return field === "__t__" || field === "__tm__" || field === "tm" || field === "t" || field === "time" || field === "from_t" || field === "to_t" || field === "t_input" || field === "t_output" || field === "from_tm" || field === "to_tm";
11635
- }
11636
- /************************************************************
11637
- * Format an epoch value as a local wall-clock string.
11638
- * Accepts seconds or milliseconds; returns null when the
11639
- * value is not a usable positive timestamp (0 == "unset").
11640
- ************************************************************/
11641
- function format_epoch(value) {
11642
- if (typeof value !== "number" || !isFinite(value) || value <= 0) return null;
11643
- let ms = Math.abs(value) < 0xe8d4a51000 ? value * 1e3 : value;
11644
- let d = new Date(ms);
11645
- if (isNaN(d.getTime())) return null;
11646
- return d.toLocaleString();
11647
- }
11648
- /************************************************************
11649
- * The text view's payload: the document as text, indented
11650
- * four characters, cut at `max_chars`.
11651
- *
11652
- * Returns {text, capped}. `capped` is what the caller
11653
- * announces under the dump — a cut that is not announced
11654
- * reads as a document that ends there.
11655
- ************************************************************/
11656
- function json_text_dump(root, max_chars) {
11657
- let text;
11658
- try {
11659
- text = JSON.stringify(root, null, 4);
11660
- } catch (e) {
11661
- return {
11662
- text: "",
11663
- capped: false,
11664
- error: String(e)
11665
- };
11666
- }
11667
- if (text === void 0) return {
11668
- text: "",
11669
- capped: false,
11670
- error: "not representable as JSON"
11671
- };
11672
- if (typeof max_chars === "number" && max_chars > 0 && text.length > max_chars) return {
11673
- text: text.slice(0, max_chars),
11674
- capped: true
11675
- };
11676
- return {
11677
- text,
11678
- capped: false
11679
- };
11680
- }
11681
- /************************************************************
11682
- * Which view a freshly mounted viewer opens on.
11683
- *
11684
- * Three answers, in order of authority: what the HOST asked
11685
- * for, what the READER chose last time, and `fallback`.
11686
- *
11687
- * The host wins because a viewer mounted to show a graph has
11688
- * to show one. The memory comes next, because reopening a
11689
- * document in the view you just left is the whole point of
11690
- * remembering it. `fallback` is the floor.
11691
- *
11692
- * Anything not in `modes` is treated as unsaid, which covers
11693
- * an absent value, an empty one, and a stored string from an
11694
- * older release that named a view no longer offered.
11695
- ************************************************************/
11696
- function pick_view_mode(asked, remembered, modes, fallback) {
11697
- let known = (m) => Array.isArray(modes) && modes.indexOf(m) >= 0;
11698
- if (known(asked)) return asked;
11699
- if (known(remembered)) return remembered;
11700
- return fallback;
11701
- }
11702
- /************************************************************
11703
- * The short label a container row carries beside its size.
11704
- *
11705
- * An array of dicts that carry an `id` is a list of RECORDS,
11706
- * and a row that says only `2: {15}` makes you open all
11707
- * fifteen fields of every one of them to find out WHICH
11708
- * record it is. The id is the one field that answers that,
11709
- * so the row says it without being opened.
11710
- *
11711
- * Only a SCALAR id, and only when it is really there: an `id`
11712
- * that is itself a dict or a list is not a name, it is more
11713
- * document, and printing `[object Object]` beside the size
11714
- * would be worse than printing nothing.
11715
- *
11716
- * Cut at `max_chars`, because this rides on a row whose job
11717
- * is to stay one line.
11718
- ************************************************************/
11719
- function container_label(value, max_chars) {
11720
- if (value === null || typeof value !== "object" || Array.isArray(value)) return "";
11721
- if (!Object.prototype.hasOwnProperty.call(value, "id")) return "";
11722
- let id = value.id;
11723
- let t = typeof id;
11724
- if (t !== "string" && t !== "number" && t !== "boolean") return "";
11725
- let text = String(id).trim();
11726
- if (text === "") return "";
11727
- let cap = typeof max_chars === "number" && max_chars > 0 ? max_chars : 0;
11728
- if (cap && text.length > cap) return text.slice(0, cap) + "…";
11729
- return text;
11730
- }
11731
11790
  //#endregion
11732
11791
  //#region src/c_yui_json.js
11733
11792
  /***********************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.19",
3
+ "version": "7.23.20",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",