@yuneta/gobj-ui 7.23.59 → 7.23.62

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.
@@ -5827,6 +5827,416 @@ function register_c_yui_wizard() {
5827
5827
  return create_gclass$17(GCLASS_NAME$17);
5828
5828
  }
5829
5829
  //#endregion
5830
+ //#region src/yui_file_field.js
5831
+ /***********************************************************************
5832
+ * yui_file_field.js
5833
+ *
5834
+ * The control that PICKS a file for a treedb `file` column, and the
5835
+ * manifest that carries its bytes beside the record.
5836
+ *
5837
+ * A column flagged ['fkey','file'] holds an fkey into the treedb's
5838
+ * system topic `__assets__`: the bytes live on disk under the treedb,
5839
+ * the index in memory, and the record names the asset by its sha256.
5840
+ * So this control does NOT put a file in the record. It keeps the
5841
+ * `File` the person picked and hands up an IDENTITY, and the bytes
5842
+ * travel beside the record in a `__files__` manifest keyed by column.
5843
+ *
5844
+ * Three things about that are not obvious and are the whole reason
5845
+ * this module is separate:
5846
+ *
5847
+ * - **The file is read at SAVE, not at pick.** An `<input type=file>`
5848
+ * hands over a `File`, which is a REFERENCE and not the bytes.
5849
+ * Picking shows a name and a size and reads nothing, so cancelling
5850
+ * a form does not mean a 40 MB video was read for nothing.
5851
+ * - **A `File` cannot travel in a kw.** A kw is plain json -- the
5852
+ * machine trace serialises it -- and a `File` is a host object. The
5853
+ * form KEEPS it and the host asks for it through a local method.
5854
+ * - **Reading is a promise, so saving stops being synchronous**, and
5855
+ * a resolved promise is an OS notification that must enter the
5856
+ * machine as an EVENT, never as a chain of callbacks. That is the
5857
+ * HOST's business; what lives here is the promise it awaits.
5858
+ *
5859
+ * The pure half (manifest, size, sha256, the name of a picked file)
5860
+ * is tested without a DOM; the DOM half builds the control.
5861
+ *
5862
+ * Using Bulma Framework (https://bulma.io)
5863
+ *
5864
+ * Copyright (c) 2026, ArtGins.
5865
+ * All Rights Reserved.
5866
+ ***********************************************************************/
5867
+ var YUI_FILE_ACCEPT = [
5868
+ "image/jpeg",
5869
+ "image/png",
5870
+ "image/webp",
5871
+ "image/gif",
5872
+ "application/pdf",
5873
+ "video/mp4",
5874
+ "video/webm",
5875
+ "video/quicktime",
5876
+ "video/ogg",
5877
+ "video/x-matroska",
5878
+ "audio/mpeg",
5879
+ "audio/mp4",
5880
+ "audio/ogg",
5881
+ "audio/wav",
5882
+ "audio/webm",
5883
+ "audio/flac"
5884
+ ].join(",");
5885
+ /***************************
5886
+ * The pure half
5887
+ ***************************/
5888
+ /***************************************************************************
5889
+ * A size a person reads. Bytes up to 1 KB, then one decimal.
5890
+ ***************************************************************************/
5891
+ function yui_file_size_label(bytes) {
5892
+ let n = Number(bytes);
5893
+ if (!isFinite(n) || n < 0) return "";
5894
+ if (n < 1024) return `${n} B`;
5895
+ const units = [
5896
+ "KB",
5897
+ "MB",
5898
+ "GB",
5899
+ "TB"
5900
+ ];
5901
+ let i = -1;
5902
+ do {
5903
+ n = n / 1024;
5904
+ i++;
5905
+ } while (n >= 1024 && i < units.length - 1);
5906
+ return `${n.toFixed(1)} ${units[i]}`;
5907
+ }
5908
+ /***************************************************************************
5909
+ * The sha256 of an ArrayBuffer, lowercase hex, or null.
5910
+ *
5911
+ * NULL is a legal answer and not a failure: `crypto.subtle` exists only
5912
+ * in a SECURE CONTEXT, so a dev server on plain http has none. Then the
5913
+ * record carries no id and treedb fills it -- the write path hashes what
5914
+ * arrives anyway, because it never trusts the client's id. What the hash
5915
+ * buys here is an integrity check the backend can make (a wrong id with
5916
+ * good bytes is refused), not the identity itself.
5917
+ ***************************************************************************/
5918
+ async function yui_file_sha256(buffer) {
5919
+ const subtle = typeof crypto !== "undefined" && crypto.subtle;
5920
+ if (!subtle) return null;
5921
+ try {
5922
+ const digest = await subtle.digest("SHA-256", buffer);
5923
+ return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
5924
+ } catch (e) {
5925
+ log_error(`cannot hash the picked file: ${e && e.message ? e.message : e}`);
5926
+ return null;
5927
+ }
5928
+ }
5929
+ /***************************************************************************
5930
+ * base64 of an ArrayBuffer.
5931
+ *
5932
+ * In chunks because `String.fromCharCode(...bytes)` spreads the whole
5933
+ * array onto the call stack, and a few hundred KB is already a
5934
+ * RangeError -- which for a file picker is every file that matters.
5935
+ ***************************************************************************/
5936
+ function yui_array_buffer_to_base64(buffer) {
5937
+ const bytes = new Uint8Array(buffer);
5938
+ const CHUNK = 32768;
5939
+ let binary = "";
5940
+ for (let i = 0; i < bytes.length; i += CHUNK) binary += String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK));
5941
+ return btoa(binary);
5942
+ }
5943
+ /***************************************************************************
5944
+ * Read ONE picked file into what the manifest carries.
5945
+ *
5946
+ * -> {content64, content_type, original_name, size, id}
5947
+ *
5948
+ * `id` is the sha256 when it could be computed, and "" when it could
5949
+ * not. Nothing else in here is optional: treedb checks the size on the
5950
+ * base64 before decoding it, and the type against the BYTES.
5951
+ ***************************************************************************/
5952
+ async function yui_file_read(file) {
5953
+ const buffer = await file.arrayBuffer();
5954
+ const id = await yui_file_sha256(buffer);
5955
+ return {
5956
+ content64: yui_array_buffer_to_base64(buffer),
5957
+ content_type: file.type || "",
5958
+ original_name: file.name || "",
5959
+ size: file.size,
5960
+ id: id || ""
5961
+ };
5962
+ }
5963
+ /***************************************************************************
5964
+ * The write a record with picked files becomes.
5965
+ *
5966
+ * picks {col: read} what yui_file_read() answered, per column
5967
+ * record the record the form collected (MODIFIED: each picked
5968
+ * column takes the id, or "" when there is none)
5969
+ *
5970
+ * -> {record, __files__}
5971
+ *
5972
+ * `__files__` is not a column: it is an instruction to the write path,
5973
+ * consumed and dropped at the door. The bytes never go INSIDE the
5974
+ * column -- a field that CARRIES the bytes and a field that KEEPS them
5975
+ * are one word apart and 460 MB of RAM apart.
5976
+ ***************************************************************************/
5977
+ function yui_files_manifest(picks, record) {
5978
+ const out = record || {};
5979
+ const manifest = {};
5980
+ Object.keys(picks || {}).forEach((col) => {
5981
+ const read = picks[col];
5982
+ if (!read) return;
5983
+ manifest[col] = {
5984
+ content64: read.content64,
5985
+ content_type: read.content_type,
5986
+ original_name: read.original_name
5987
+ };
5988
+ out[col] = read.id || "";
5989
+ });
5990
+ return {
5991
+ record: out,
5992
+ __files__: manifest
5993
+ };
5994
+ }
5995
+ /***************************
5996
+ * The DOM half
5997
+ ***************************/
5998
+ /***************************************************************************
5999
+ * What the control shows for what the column HOLDS today: the asset id,
6000
+ * shortened. A sha256 in full is 64 characters of noise in a form.
6001
+ ***************************************************************************/
6002
+ function yui_file_id_label(id) {
6003
+ if (!id) return "";
6004
+ return id.length > 16 ? `${id.slice(0, 8)}…${id.slice(-4)}` : id;
6005
+ }
6006
+ /***************************************************************************
6007
+ * The control for a `file` column.
6008
+ *
6009
+ * name the column
6010
+ * value the asset id the record holds today ("" when none)
6011
+ * readonly draw it, do not let it change
6012
+ * on_pick (file|null) -> void. NULL is "the person cleared it".
6013
+ *
6014
+ * Returns the `<div class="control">` content, and hangs the state the
6015
+ * form reads off the returned element:
6016
+ *
6017
+ * $control.yui_file the picked File, or null
6018
+ * $control.yui_file_value the id the column keeps ("" = cleared)
6019
+ *
6020
+ * The `<input type="file">` is hidden and driven by a button, because a
6021
+ * bare file input cannot be styled and says "Sin archivos seleccionados"
6022
+ * in the browser's own language, not the app's.
6023
+ ***************************************************************************/
6024
+ function yui_file_control(gobj, { name, value, readonly, accept, on_pick }) {
6025
+ const has_asset = !!value;
6026
+ const $input = createElement2(["input", {
6027
+ type: "file",
6028
+ class: "FILE_INPUT",
6029
+ name: `${name}__file`,
6030
+ accept: accept || YUI_FILE_ACCEPT,
6031
+ hidden: ""
6032
+ }]);
6033
+ if (readonly) $input.disabled = true;
6034
+ const $pick = createElement2([
6035
+ "button",
6036
+ {
6037
+ type: "button",
6038
+ class: "FILE_PICK button is-small",
6039
+ "data-i18n-title": "choose a file",
6040
+ "aria-label": "choose a file"
6041
+ },
6042
+ [["span", { class: "FILE_PICK_ICON yi-upload" }], [
6043
+ "span",
6044
+ {
6045
+ class: "FILE_PICK_LABEL",
6046
+ i18n: "choose a file"
6047
+ },
6048
+ "choose a file"
6049
+ ]]
6050
+ ]);
6051
+ const $clear = createElement2([
6052
+ "button",
6053
+ {
6054
+ type: "button",
6055
+ class: "FILE_CLEAR button is-small",
6056
+ "data-i18n-title": "remove the file",
6057
+ "aria-label": "remove the file"
6058
+ },
6059
+ [["span", { class: "FILE_CLEAR_ICON yi-trash" }]]
6060
+ ]);
6061
+ const $name = createElement2(["span", { class: "FILE_NAME" }]);
6062
+ const $size = createElement2(["span", { class: "FILE_SIZE" }]);
6063
+ const $state = createElement2(["span", { class: "FILE_STATE" }]);
6064
+ const $control = createElement2([
6065
+ "div",
6066
+ { class: "FILE_FIELD" },
6067
+ [
6068
+ $input,
6069
+ $pick,
6070
+ $name,
6071
+ $size,
6072
+ $state,
6073
+ $clear
6074
+ ]
6075
+ ]);
6076
+ $control.yui_file = null;
6077
+ $control.yui_file_value = value || "";
6078
+ const render = () => {
6079
+ const picked = $control.yui_file;
6080
+ const kept = $control.yui_file_value;
6081
+ $name.textContent = picked ? picked.name || "" : yui_file_id_label(kept);
6082
+ $name.title = picked ? picked.name || "" : kept || "";
6083
+ $size.textContent = picked ? yui_file_size_label(picked.size) : "";
6084
+ $state.className = "FILE_STATE";
6085
+ $state.removeAttribute("data-i18n");
6086
+ $state.textContent = "";
6087
+ if (picked) {
6088
+ $state.classList.add("is-picked");
6089
+ $state.setAttribute("data-i18n", "not saved yet");
6090
+ $state.textContent = "not saved yet";
6091
+ } else if (!kept) {
6092
+ $state.classList.add("is-empty");
6093
+ $state.setAttribute("data-i18n", "no file");
6094
+ $state.textContent = "no file";
6095
+ }
6096
+ $clear.hidden = readonly || !picked && !kept;
6097
+ $pick.hidden = !!readonly;
6098
+ };
6099
+ if (!readonly) {
6100
+ $pick.addEventListener("click", () => {
6101
+ $input.click();
6102
+ });
6103
+ $input.addEventListener("change", () => {
6104
+ const file = $input.files && $input.files.length ? $input.files[0] : null;
6105
+ $control.yui_file = file;
6106
+ render();
6107
+ if (on_pick) on_pick(file);
6108
+ });
6109
+ $clear.addEventListener("click", () => {
6110
+ $control.yui_file = null;
6111
+ $control.yui_file_value = "";
6112
+ $input.value = "";
6113
+ render();
6114
+ if (on_pick) on_pick(null);
6115
+ });
6116
+ }
6117
+ $control.yui_file_render = render;
6118
+ render();
6119
+ return {
6120
+ $control,
6121
+ $input,
6122
+ has_asset
6123
+ };
6124
+ }
6125
+ //#endregion
6126
+ //#region src/yui_asset.js
6127
+ function ref_to_id(ref) {
6128
+ if (!ref) return null;
6129
+ if (typeof ref === "string") {
6130
+ if (ref.indexOf("^") < 0) return ref;
6131
+ const parts = ref.split("^");
6132
+ return parts.length >= 2 && parts[1] ? parts[1] : null;
6133
+ }
6134
+ if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
6135
+ return null;
6136
+ }
6137
+ /***************************************************************************
6138
+ * Every asset id a column names, in order. Always an array, possibly empty.
6139
+ ***************************************************************************/
6140
+ function yui_asset_ids(ref) {
6141
+ if (Array.isArray(ref)) return ref.map(ref_to_id).filter((id) => !!id);
6142
+ const id = ref_to_id(ref);
6143
+ return id ? [id] : [];
6144
+ }
6145
+ /***************************************************************************
6146
+ * The first asset id a column names, or null.
6147
+ ***************************************************************************/
6148
+ function yui_asset_id(ref) {
6149
+ const ids = yui_asset_ids(ref);
6150
+ return ids.length ? ids[0] : null;
6151
+ }
6152
+ /***************************************************************************
6153
+ * Turn a `get-asset` answer into something an element can load.
6154
+ *
6155
+ * Returns null when the answer carries neither -- which the caller must
6156
+ * treat as "missing", never as an empty src: an <img src=""> reloads the
6157
+ * PAGE in some browsers.
6158
+ ***************************************************************************/
6159
+ function yui_asset_src(answer) {
6160
+ if (!answer) return null;
6161
+ if (answer.mode === "url" && answer.url) return answer.url;
6162
+ if (answer.mode === "inline" && answer.content64) return `data:${answer.content_type || "application/octet-stream"};base64,${answer.content64}`;
6163
+ return null;
6164
+ }
6165
+ /***************************************************************************
6166
+ * The marker for an asset that is not there.
6167
+ *
6168
+ * A missing image used to leave a broken box and no word about it, which
6169
+ * is indistinguishable from a slow one and from a bug. This says so, and
6170
+ * it says WHICH: `detail` is data (a name, a path) and is never
6171
+ * translated, while the label carries its i18n key so a language change
6172
+ * re-translates it.
6173
+ ***************************************************************************/
6174
+ function yui_asset_missing(detail, opts = {}) {
6175
+ const key = opts.key || "asset not available";
6176
+ const children = [["span", { class: "ASSET_MISSING_ICON yi-triangle-exclamation" }], [
6177
+ "span",
6178
+ {
6179
+ class: "ASSET_MISSING_LABEL",
6180
+ i18n: key
6181
+ },
6182
+ key
6183
+ ]];
6184
+ if (detail) children.push([
6185
+ "span",
6186
+ { class: "ASSET_MISSING_DETAIL" },
6187
+ String(detail)
6188
+ ]);
6189
+ const attrs = { class: `ASSET_MISSING ${opts.class || ""}`.trim() };
6190
+ if (detail) attrs.title = String(detail);
6191
+ else attrs["data-i18n-title"] = key;
6192
+ return createElement2([
6193
+ "div",
6194
+ attrs,
6195
+ children
6196
+ ]);
6197
+ }
6198
+ /***************************************************************************
6199
+ * The element for one asset.
6200
+ *
6201
+ * The KIND comes from the content type the backend stored, not from the
6202
+ * name a person typed: video and audio are assets too, and an <img> whose
6203
+ * src is a film shows the broken box this module exists to remove.
6204
+ *
6205
+ * `detail` is what the missing marker shows -- pass the original name or
6206
+ * the source path, the thing a person can act on.
6207
+ ***************************************************************************/
6208
+ function yui_asset_element(answer, opts = {}) {
6209
+ const src = yui_asset_src(answer);
6210
+ if (!src) return yui_asset_missing(opts.detail, opts);
6211
+ const ct = (answer.content_type || "").toLowerCase();
6212
+ const cls = `ASSET_MEDIA ${opts.class || ""}`.trim();
6213
+ let el;
6214
+ if (ct.startsWith("video/")) el = createElement2(["video", {
6215
+ class: cls,
6216
+ controls: "",
6217
+ preload: "metadata"
6218
+ }]);
6219
+ else if (ct.startsWith("audio/")) el = createElement2(["audio", {
6220
+ class: cls,
6221
+ controls: "",
6222
+ preload: "metadata"
6223
+ }]);
6224
+ else {
6225
+ el = createElement2(["img", {
6226
+ class: cls,
6227
+ loading: "lazy"
6228
+ }]);
6229
+ el.alt = opts.alt || opts.detail || "";
6230
+ }
6231
+ el.src = src;
6232
+ el.onerror = () => {
6233
+ log_error(`asset could not be loaded: ${opts.detail || src}`);
6234
+ const $marker = yui_asset_missing(opts.detail, opts);
6235
+ if (el.parentNode) el.parentNode.replaceChild($marker, el);
6236
+ };
6237
+ return el;
6238
+ }
6239
+ //#endregion
5830
6240
  //#region src/yui_inputs.js
5831
6241
  /***************************************************************
5832
6242
  * The ✕ shows only when there is something to clear AND the field
@@ -6800,6 +7210,9 @@ function build_form_field_conf(gobj, field_desc) {
6800
7210
  field_conf.tag = "select2";
6801
7211
  field_conf.options = get_fkey_select_options(gobj, field_desc);
6802
7212
  break;
7213
+ case "file":
7214
+ field_conf.tag = "file";
7215
+ break;
6803
7216
  case "image":
6804
7217
  case "icon":
6805
7218
  case "string":
@@ -7485,6 +7898,17 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7485
7898
  $control.appendChild($extend);
7486
7899
  break;
7487
7900
  }
7901
+ case "file":
7902
+ $extend = yui_file_control(gobj, {
7903
+ name,
7904
+ value: "",
7905
+ readonly,
7906
+ on_pick: function() {
7907
+ gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
7908
+ }
7909
+ }).$control;
7910
+ $control.appendChild($extend);
7911
+ break;
7488
7912
  default:
7489
7913
  $extend = createElement2([
7490
7914
  "strong",
@@ -7572,6 +7996,12 @@ function apply_readonly_to_control(readonly, tag, inputType, $extend) {
7572
7996
  case "jsoneditor":
7573
7997
  $extend.classList.add("yui-jse-readonly");
7574
7998
  break;
7999
+ case "file":
8000
+ {
8001
+ const $picker = $extend.querySelector(".FILE_INPUT");
8002
+ if ($picker) $picker.disabled = true;
8003
+ }
8004
+ break;
7575
8005
  case "input": if (inputType === "color") $extend.setAttribute("disabled", "disabled");
7576
8006
  }
7577
8007
  }
@@ -7985,6 +8415,9 @@ function get_form_values(gobj, $form) {
7985
8415
  case "radio":
7986
8416
  value = getInputValue($input);
7987
8417
  break;
8418
+ case "file":
8419
+ value = $input.yui_file_value || "";
8420
+ break;
7988
8421
  case "jsoneditor":
7989
8422
  let jsoneditor = $input.jsoneditor;
7990
8423
  if (jsoneditor) {
@@ -8041,6 +8474,13 @@ function clear_data(gobj, $form) {
8041
8474
  else $input.value = null;
8042
8475
  }
8043
8476
  });
8477
+ $form.querySelectorAll(".FILE_FIELD").forEach(($file) => {
8478
+ $file.yui_file = null;
8479
+ $file.yui_file_value = "";
8480
+ let $picker = $file.querySelector(".FILE_INPUT");
8481
+ if ($picker) $picker.value = "";
8482
+ if ($file.yui_file_render) $file.yui_file_render();
8483
+ });
8044
8484
  $form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
8045
8485
  if ($table.tabulator.initialized) $table.tabulator.clearData();
8046
8486
  $table.querySelectorAll(".yui-tabulator-table-nested").forEach(($table_nested) => {
@@ -8110,6 +8550,11 @@ function set_form_values(gobj, template, $form, record) {
8110
8550
  value = treedb_value_2_form_value(gobj, field_desc, value);
8111
8551
  if (value === void 0) value = null;
8112
8552
  switch (tag) {
8553
+ case "file":
8554
+ $input.yui_file = null;
8555
+ $input.yui_file_value = yui_asset_id(value) || "";
8556
+ if ($input.yui_file_render) $input.yui_file_render();
8557
+ break;
8113
8558
  case "input":
8114
8559
  switch (input_type) {
8115
8560
  case "datetime-local":
@@ -8199,6 +8644,7 @@ function treedb_value_2_form_value(gobj, field_desc, value) {
8199
8644
  return { json: is_object(value) || is_array(value) ? value : {} };
8200
8645
  }
8201
8646
  switch (type) {
8647
+ case "file": return value;
8202
8648
  case "fkey": {
8203
8649
  let new_value = [];
8204
8650
  if (is_string(value) && !empty_string(value)) {
@@ -8295,6 +8741,7 @@ function form_value_2_treedb_value(gobj, field_desc, value) {
8295
8741
  return value;
8296
8742
  }
8297
8743
  switch (type) {
8744
+ case "file": break;
8298
8745
  case "fkey":
8299
8746
  value = build_fkey_ref$1(gobj, field_desc, value);
8300
8747
  break;
@@ -8538,11 +8985,63 @@ function ac_timeout(gobj, event, kw, src) {
8538
8985
  /***************************
8539
8986
  * FSM
8540
8987
  ***************************/
8988
+ /************************************************************
8989
+ * Framework Method command
8990
+ ************************************************************/
8991
+ function mt_command_parser$2(gobj, command, kw, src) {
8992
+ switch (command) {
8993
+ case "get_picked_files": return cmd_get_picked_files(gobj, command, kw, src);
8994
+ default:
8995
+ log_error(`${gobj_short_name(gobj)}: command not found: ${command}`);
8996
+ return {
8997
+ result: -1,
8998
+ comment: `Command not found: ${command}`,
8999
+ schema: null,
9000
+ data: null
9001
+ };
9002
+ }
9003
+ }
9004
+ /************************************************************
9005
+ * The files a person picked and the record cannot carry.
9006
+ *
9007
+ * A `File` is a host object and a kw is plain json -- the machine trace
9008
+ * serialises it -- so the picked files never travel in an event. The
9009
+ * form KEEPS them and the HOST asks for them here, at save, and turns
9010
+ * them into the `__files__` manifest that rides beside the record.
9011
+ *
9012
+ * Answers `data: {col: File}`, empty when nothing was picked, which is
9013
+ * the ordinary case and not an error.
9014
+ ************************************************************/
9015
+ function cmd_get_picked_files(gobj, cmd, kw, src) {
9016
+ const files = {};
9017
+ const $container = gobj_read_attr(gobj, "$container");
9018
+ const $form = $container ? $container.querySelector("form") : null;
9019
+ if (!$form) {
9020
+ log_error(`${gobj_short_name(gobj)}: no form to read the picked files from`);
9021
+ return {
9022
+ result: -1,
9023
+ comment: "no form",
9024
+ schema: null,
9025
+ data: null
9026
+ };
9027
+ }
9028
+ $form.querySelectorAll(".yui-form-data-input").forEach(($input) => {
9029
+ if ($input.dataset.form_tag !== "file") return;
9030
+ if ($input.yui_file) files[$input.dataset.treedb_name] = $input.yui_file;
9031
+ });
9032
+ return {
9033
+ result: 0,
9034
+ comment: "",
9035
+ schema: null,
9036
+ data: files
9037
+ };
9038
+ }
8541
9039
  var gmt$16 = {
8542
9040
  mt_create: mt_create$16,
8543
9041
  mt_start: mt_start$15,
8544
9042
  mt_stop: mt_stop$15,
8545
- mt_destroy: mt_destroy$16
9043
+ mt_destroy: mt_destroy$16,
9044
+ mt_command_parser: mt_command_parser$2
8546
9045
  };
8547
9046
  /***************************************************************
8548
9047
  * Create the GClass
@@ -23985,6 +24484,9 @@ function create_tabulator(gobj) {
23985
24484
  vertAlign = "middle";
23986
24485
  colFormatter = icon_formatter;
23987
24486
  break;
24487
+ case "file":
24488
+ colFormatter = file_cell_formatter;
24489
+ break;
23988
24490
  case "object":
23989
24491
  case "dict":
23990
24492
  case "template":
@@ -24229,6 +24731,33 @@ function table__destroy(gobj) {
24229
24731
  * render a solid square -- a glyph nobody recognises rather
24230
24732
  * than a mistake somebody can fix.
24231
24733
  ************************************************************/
24734
+ /************************************************************
24735
+ * What a `file` column shows in a table cell: the asset it names.
24736
+ *
24737
+ * A sha256 in full is 64 characters of noise in a column, so it is
24738
+ * shortened and the whole of it is the tooltip. Empty is SAID, not left
24739
+ * blank -- a blank cell and a cell whose asset failed to load look the
24740
+ * same, and only one of them is normal.
24741
+ ************************************************************/
24742
+ function file_cell_formatter(cell, formatterParams, onRendered) {
24743
+ const id = yui_asset_id(cell.getValue());
24744
+ if (!id) return createElement2([
24745
+ "span",
24746
+ {
24747
+ class: "FILE_CELL is-empty",
24748
+ "data-i18n": "no file"
24749
+ },
24750
+ "no file"
24751
+ ]);
24752
+ return createElement2([
24753
+ "span",
24754
+ {
24755
+ class: "FILE_CELL",
24756
+ title: id
24757
+ },
24758
+ yui_file_id_label(id)
24759
+ ]);
24760
+ }
24232
24761
  function icon_formatter(cell) {
24233
24762
  let name = cell.getValue();
24234
24763
  if (!is_string(name) || empty_string(name)) return "";
@@ -24324,6 +24853,7 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field) {
24324
24853
  ].join("");
24325
24854
  else value = "";
24326
24855
  break;
24856
+ case "file":
24327
24857
  case "fkey":
24328
24858
  let new_value = [];
24329
24859
  if (value) {
@@ -24848,6 +25378,7 @@ function transform__form_value_2_treedb_value(gobj, col, value, operation) {
24848
25378
  case "hook":
24849
25379
  value = null;
24850
25380
  break;
25381
+ case "file": break;
24851
25382
  case "fkey":
24852
25383
  value = build_fkey_ref(gobj, col, value);
24853
25384
  break;
@@ -25331,13 +25862,71 @@ function ac_paste_rows(gobj, event, kw, src) {
25331
25862
  function ac_form_save_record(gobj, event, kw, src) {
25332
25863
  if (refuse_if_readonly$2(gobj, event)) return -1;
25333
25864
  let mode = gobj_read_str_attr(src, "form_mode");
25334
- gobj_publish_event(gobj, mode === "create" ? "EV_CREATE_RECORD" : "EV_UPDATE_RECORD", {
25865
+ let picked = {};
25866
+ const answer = gobj_command(src, "get_picked_files", {}, gobj);
25867
+ if (answer && answer.result >= 0 && answer.data) picked = answer.data;
25868
+ const cols = Object.keys(picked);
25869
+ if (cols.length === 0) {
25870
+ publish_treedb_write(gobj, mode, kw);
25871
+ setTimeout(function() {
25872
+ close_form_dialog(gobj);
25873
+ }, 0);
25874
+ return 0;
25875
+ }
25876
+ Promise.all(cols.map((col) => {
25877
+ return yui_file_read(picked[col]).then((read) => {
25878
+ return {
25879
+ col,
25880
+ read
25881
+ };
25882
+ });
25883
+ })).then((reads) => {
25884
+ const picks = {};
25885
+ reads.forEach((r) => {
25886
+ picks[r.col] = r.read;
25887
+ });
25888
+ gobj_send_event(gobj, "EV_FILES_READ", {
25889
+ mode,
25890
+ record: kw,
25891
+ picks
25892
+ }, gobj);
25893
+ }).catch((e) => {
25894
+ gobj_send_event(gobj, "EV_FILES_FAILED", { reason: e && e.message ? e.message : String(e) }, gobj);
25895
+ });
25896
+ return 0;
25897
+ }
25898
+ /************************************************************
25899
+ * The one place a write of this view leaves for the app.
25900
+ ************************************************************/
25901
+ function publish_treedb_write(gobj, mode, record, jn_files) {
25902
+ const kw_write = {
25335
25903
  topic_name: gobj_read_str_attr(gobj, "topic_name"),
25336
- record: kw
25904
+ record
25905
+ };
25906
+ if (jn_files && Object.keys(jn_files).length > 0) kw_write.record.__files__ = jn_files;
25907
+ gobj_publish_event(gobj, mode === "create" ? "EV_CREATE_RECORD" : "EV_UPDATE_RECORD", kw_write);
25908
+ }
25909
+ /************************************************************
25910
+ * {mode, record, picks} -- the bytes are here now
25911
+ ************************************************************/
25912
+ function ac_files_read(gobj, event, kw, src) {
25913
+ const { record, __files__ } = yui_files_manifest(kw.picks, kw.record);
25914
+ publish_treedb_write(gobj, kw.mode, record, __files__);
25915
+ close_form_dialog(gobj);
25916
+ return 0;
25917
+ }
25918
+ /************************************************************
25919
+ * {reason} -- the browser could not read what was picked
25920
+ *
25921
+ * The form stays OPEN: the record is still there, and closing it would
25922
+ * throw away what the person typed for a failure that is not theirs.
25923
+ ************************************************************/
25924
+ function ac_files_failed(gobj, event, kw, src) {
25925
+ log_error(`${gobj_short_name(gobj)}: cannot read the picked file: ${kw.reason}`);
25926
+ yui_shell_confirm_ok(yui_shell_of(gobj), "cannot read the picked file", {
25927
+ t,
25928
+ ok_label: "accept"
25337
25929
  });
25338
- setTimeout(function() {
25339
- close_form_dialog(gobj);
25340
- }, 0);
25341
25930
  return 0;
25342
25931
  }
25343
25932
  /************************************************************
@@ -25856,6 +26445,16 @@ function create_gclass$5(gclass_name) {
25856
26445
  ac_form_save_record,
25857
26446
  null
25858
26447
  ],
26448
+ [
26449
+ "EV_FILES_READ",
26450
+ ac_files_read,
26451
+ null
26452
+ ],
26453
+ [
26454
+ "EV_FILES_FAILED",
26455
+ ac_files_failed,
26456
+ null
26457
+ ],
25859
26458
  [
25860
26459
  "EV_NEW_ROW",
25861
26460
  ac_new_row,
@@ -25990,6 +26589,8 @@ function create_gclass$5(gclass_name) {
25990
26589
  ["EV_NODE_DELETED", 0],
25991
26590
  ["EV_EDITION_MODE", 0],
25992
26591
  ["EV_SAVE_RECORD", 0],
26592
+ ["EV_FILES_READ", 0],
26593
+ ["EV_FILES_FAILED", 0],
25993
26594
  ["EV_NEW_ROW", 0],
25994
26595
  ["EV_DELETE_ROWS", 0],
25995
26596
  ["EV_COPY_ROWS", 0],
@@ -67502,120 +68103,6 @@ function register_c_yui_period() {
67502
68103
  return create_gclass(GCLASS_NAME);
67503
68104
  }
67504
68105
  //#endregion
67505
- //#region src/yui_asset.js
67506
- function ref_to_id(ref) {
67507
- if (!ref) return null;
67508
- if (typeof ref === "string") {
67509
- if (ref.indexOf("^") < 0) return ref;
67510
- const parts = ref.split("^");
67511
- return parts.length >= 2 && parts[1] ? parts[1] : null;
67512
- }
67513
- if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
67514
- return null;
67515
- }
67516
- /***************************************************************************
67517
- * Every asset id a column names, in order. Always an array, possibly empty.
67518
- ***************************************************************************/
67519
- function yui_asset_ids(ref) {
67520
- if (Array.isArray(ref)) return ref.map(ref_to_id).filter((id) => !!id);
67521
- const id = ref_to_id(ref);
67522
- return id ? [id] : [];
67523
- }
67524
- /***************************************************************************
67525
- * The first asset id a column names, or null.
67526
- ***************************************************************************/
67527
- function yui_asset_id(ref) {
67528
- const ids = yui_asset_ids(ref);
67529
- return ids.length ? ids[0] : null;
67530
- }
67531
- /***************************************************************************
67532
- * Turn a `get-asset` answer into something an element can load.
67533
- *
67534
- * Returns null when the answer carries neither -- which the caller must
67535
- * treat as "missing", never as an empty src: an <img src=""> reloads the
67536
- * PAGE in some browsers.
67537
- ***************************************************************************/
67538
- function yui_asset_src(answer) {
67539
- if (!answer) return null;
67540
- if (answer.mode === "url" && answer.url) return answer.url;
67541
- if (answer.mode === "inline" && answer.content64) return `data:${answer.content_type || "application/octet-stream"};base64,${answer.content64}`;
67542
- return null;
67543
- }
67544
- /***************************************************************************
67545
- * The marker for an asset that is not there.
67546
- *
67547
- * A missing image used to leave a broken box and no word about it, which
67548
- * is indistinguishable from a slow one and from a bug. This says so, and
67549
- * it says WHICH: `detail` is data (a name, a path) and is never
67550
- * translated, while the label carries its i18n key so a language change
67551
- * re-translates it.
67552
- ***************************************************************************/
67553
- function yui_asset_missing(detail, opts = {}) {
67554
- const key = opts.key || "asset not available";
67555
- const children = [["span", { class: "ASSET_MISSING_ICON yi-triangle-exclamation" }], [
67556
- "span",
67557
- {
67558
- class: "ASSET_MISSING_LABEL",
67559
- i18n: key
67560
- },
67561
- key
67562
- ]];
67563
- if (detail) children.push([
67564
- "span",
67565
- { class: "ASSET_MISSING_DETAIL" },
67566
- String(detail)
67567
- ]);
67568
- const attrs = { class: `ASSET_MISSING ${opts.class || ""}`.trim() };
67569
- if (detail) attrs.title = String(detail);
67570
- else attrs["data-i18n-title"] = key;
67571
- return createElement2([
67572
- "div",
67573
- attrs,
67574
- children
67575
- ]);
67576
- }
67577
- /***************************************************************************
67578
- * The element for one asset.
67579
- *
67580
- * The KIND comes from the content type the backend stored, not from the
67581
- * name a person typed: video and audio are assets too, and an <img> whose
67582
- * src is a film shows the broken box this module exists to remove.
67583
- *
67584
- * `detail` is what the missing marker shows -- pass the original name or
67585
- * the source path, the thing a person can act on.
67586
- ***************************************************************************/
67587
- function yui_asset_element(answer, opts = {}) {
67588
- const src = yui_asset_src(answer);
67589
- if (!src) return yui_asset_missing(opts.detail, opts);
67590
- const ct = (answer.content_type || "").toLowerCase();
67591
- const cls = `ASSET_MEDIA ${opts.class || ""}`.trim();
67592
- let el;
67593
- if (ct.startsWith("video/")) el = createElement2(["video", {
67594
- class: cls,
67595
- controls: "",
67596
- preload: "metadata"
67597
- }]);
67598
- else if (ct.startsWith("audio/")) el = createElement2(["audio", {
67599
- class: cls,
67600
- controls: "",
67601
- preload: "metadata"
67602
- }]);
67603
- else {
67604
- el = createElement2(["img", {
67605
- class: cls,
67606
- loading: "lazy"
67607
- }]);
67608
- el.alt = opts.alt || opts.detail || "";
67609
- }
67610
- el.src = src;
67611
- el.onerror = () => {
67612
- log_error(`asset could not be loaded: ${opts.detail || src}`);
67613
- const $marker = yui_asset_missing(opts.detail, opts);
67614
- if (el.parentNode) el.parentNode.replaceChild($marker, el);
67615
- };
67616
- return el;
67617
- }
67618
- //#endregion
67619
68106
  //#region src/dev_machine_trace.js
67620
68107
  /***********************************************************************
67621
68108
  * dev_machine_trace.js
@@ -69299,6 +69786,6 @@ function setup_frontend_view(self) {
69299
69786
  return win;
69300
69787
  }
69301
69788
  //#endregion
69302
- export { EditControl, MarkerControl, YUI_PERIODS, YUI_PERIODS_DEFAULT, YUI_ROLLING, addClasses, apply_dev_traces, attach_clear, build_dev_panel, dev_window_was_open, disableElements, enableElements, epoch_to_local_input, epoch_to_ms, expose_view_container, fmt_epoch, getStrokeColor, infer_period, info_traffic, inject_svg_icons, is_current_period, iso_week, local_input_to_epoch, ms_to_epoch, period_bounds, period_bounds_epoch, period_label, period_name, period_shift, period_spec, period_start, refresh_clear, register_c_g6_nodes_tree, register_c_yui_form, register_c_yui_fsm_graph, register_c_yui_gclass, register_c_yui_gobj_tree_js, register_c_yui_json, register_c_yui_json_graph, register_c_yui_map, register_c_yui_nav, register_c_yui_pager, register_c_yui_period, register_c_yui_schema_editor, register_c_yui_service_view, register_c_yui_shell, register_c_yui_treedb_graph, register_c_yui_treedb_schema, register_c_yui_treedb_topic_with_form, register_c_yui_treedb_topics, register_c_yui_uplot, register_c_yui_window, register_c_yui_window_manager, register_c_yui_wizard, removeChildElements, removeClasses, rolling_bounds, safe_locale, set_active_state, set_cancel_state, set_pressed_state, set_submit_state, setup_dev, setup_frontend_view, toggleClasses, yui_asset_element, yui_asset_id, yui_asset_ids, yui_asset_missing, yui_asset_src, yui_is_dark, yui_mount_service_view, yui_shell_close_drawer, yui_shell_close_dropdown, yui_shell_confirm_danger, yui_shell_confirm_ok, yui_shell_confirm_yesno, yui_shell_confirm_yesnocancel, yui_shell_navigate, yui_shell_open_drawer, yui_shell_overlay_dismissed, yui_shell_pop_escape, yui_shell_push_escape, yui_shell_refresh_avatars, yui_shell_register_event_handler, yui_shell_register_overlay, yui_shell_set_avatar_provider, yui_shell_set_connection_state, yui_shell_set_sub_routes, yui_shell_set_toolbar_item_badge, yui_shell_set_toolbar_item_icon, yui_shell_set_translator, yui_shell_show_error, yui_shell_show_info, yui_shell_show_modal, yui_shell_show_route_map, yui_shell_show_warning, yui_shell_toggle_drawer, yui_shell_unpark_route, yui_theme_now, yui_toolbar, yui_watch_theme };
69789
+ export { EditControl, MarkerControl, YUI_FILE_ACCEPT, YUI_PERIODS, YUI_PERIODS_DEFAULT, YUI_ROLLING, addClasses, apply_dev_traces, attach_clear, build_dev_panel, dev_window_was_open, disableElements, enableElements, epoch_to_local_input, epoch_to_ms, expose_view_container, fmt_epoch, getStrokeColor, infer_period, info_traffic, inject_svg_icons, is_current_period, iso_week, local_input_to_epoch, ms_to_epoch, period_bounds, period_bounds_epoch, period_label, period_name, period_shift, period_spec, period_start, refresh_clear, register_c_g6_nodes_tree, register_c_yui_form, register_c_yui_fsm_graph, register_c_yui_gclass, register_c_yui_gobj_tree_js, register_c_yui_json, register_c_yui_json_graph, register_c_yui_map, register_c_yui_nav, register_c_yui_pager, register_c_yui_period, register_c_yui_schema_editor, register_c_yui_service_view, register_c_yui_shell, register_c_yui_treedb_graph, register_c_yui_treedb_schema, register_c_yui_treedb_topic_with_form, register_c_yui_treedb_topics, register_c_yui_uplot, register_c_yui_window, register_c_yui_window_manager, register_c_yui_wizard, removeChildElements, removeClasses, rolling_bounds, safe_locale, set_active_state, set_cancel_state, set_pressed_state, set_submit_state, setup_dev, setup_frontend_view, toggleClasses, yui_array_buffer_to_base64, yui_asset_element, yui_asset_id, yui_asset_ids, yui_asset_missing, yui_asset_src, yui_file_control, yui_file_id_label, yui_file_read, yui_file_sha256, yui_file_size_label, yui_files_manifest, yui_is_dark, yui_mount_service_view, yui_shell_close_drawer, yui_shell_close_dropdown, yui_shell_confirm_danger, yui_shell_confirm_ok, yui_shell_confirm_yesno, yui_shell_confirm_yesnocancel, yui_shell_navigate, yui_shell_open_drawer, yui_shell_overlay_dismissed, yui_shell_pop_escape, yui_shell_push_escape, yui_shell_refresh_avatars, yui_shell_register_event_handler, yui_shell_register_overlay, yui_shell_set_avatar_provider, yui_shell_set_connection_state, yui_shell_set_sub_routes, yui_shell_set_toolbar_item_badge, yui_shell_set_toolbar_item_icon, yui_shell_set_translator, yui_shell_show_error, yui_shell_show_info, yui_shell_show_modal, yui_shell_show_route_map, yui_shell_show_warning, yui_shell_toggle_drawer, yui_shell_unpark_route, yui_theme_now, yui_toolbar, yui_watch_theme };
69303
69790
 
69304
69791
  //# sourceMappingURL=gobj-ui.es.js.map