@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.
- package/dist/gobj-ui.cjs.js +615 -120
- package/dist/gobj-ui.es.js +608 -121
- package/index.js +4 -0
- package/package.json +1 -1
- package/src/c_yui_form.js +160 -4
- package/src/c_yui_treedb_topic_with_form.css +15 -0
- package/src/c_yui_treedb_topic_with_form.js +141 -10
- package/src/yui_file_field.css +67 -0
- package/src/yui_file_field.js +376 -0
- package/src/yui_file_field.test.js +119 -0
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -5832,6 +5832,416 @@ function register_c_yui_wizard() {
|
|
|
5832
5832
|
return create_gclass$17(GCLASS_NAME$17);
|
|
5833
5833
|
}
|
|
5834
5834
|
//#endregion
|
|
5835
|
+
//#region src/yui_file_field.js
|
|
5836
|
+
/***********************************************************************
|
|
5837
|
+
* yui_file_field.js
|
|
5838
|
+
*
|
|
5839
|
+
* The control that PICKS a file for a treedb `file` column, and the
|
|
5840
|
+
* manifest that carries its bytes beside the record.
|
|
5841
|
+
*
|
|
5842
|
+
* A column flagged ['fkey','file'] holds an fkey into the treedb's
|
|
5843
|
+
* system topic `__assets__`: the bytes live on disk under the treedb,
|
|
5844
|
+
* the index in memory, and the record names the asset by its sha256.
|
|
5845
|
+
* So this control does NOT put a file in the record. It keeps the
|
|
5846
|
+
* `File` the person picked and hands up an IDENTITY, and the bytes
|
|
5847
|
+
* travel beside the record in a `__files__` manifest keyed by column.
|
|
5848
|
+
*
|
|
5849
|
+
* Three things about that are not obvious and are the whole reason
|
|
5850
|
+
* this module is separate:
|
|
5851
|
+
*
|
|
5852
|
+
* - **The file is read at SAVE, not at pick.** An `<input type=file>`
|
|
5853
|
+
* hands over a `File`, which is a REFERENCE and not the bytes.
|
|
5854
|
+
* Picking shows a name and a size and reads nothing, so cancelling
|
|
5855
|
+
* a form does not mean a 40 MB video was read for nothing.
|
|
5856
|
+
* - **A `File` cannot travel in a kw.** A kw is plain json -- the
|
|
5857
|
+
* machine trace serialises it -- and a `File` is a host object. The
|
|
5858
|
+
* form KEEPS it and the host asks for it through a local method.
|
|
5859
|
+
* - **Reading is a promise, so saving stops being synchronous**, and
|
|
5860
|
+
* a resolved promise is an OS notification that must enter the
|
|
5861
|
+
* machine as an EVENT, never as a chain of callbacks. That is the
|
|
5862
|
+
* HOST's business; what lives here is the promise it awaits.
|
|
5863
|
+
*
|
|
5864
|
+
* The pure half (manifest, size, sha256, the name of a picked file)
|
|
5865
|
+
* is tested without a DOM; the DOM half builds the control.
|
|
5866
|
+
*
|
|
5867
|
+
* Using Bulma Framework (https://bulma.io)
|
|
5868
|
+
*
|
|
5869
|
+
* Copyright (c) 2026, ArtGins.
|
|
5870
|
+
* All Rights Reserved.
|
|
5871
|
+
***********************************************************************/
|
|
5872
|
+
var YUI_FILE_ACCEPT = [
|
|
5873
|
+
"image/jpeg",
|
|
5874
|
+
"image/png",
|
|
5875
|
+
"image/webp",
|
|
5876
|
+
"image/gif",
|
|
5877
|
+
"application/pdf",
|
|
5878
|
+
"video/mp4",
|
|
5879
|
+
"video/webm",
|
|
5880
|
+
"video/quicktime",
|
|
5881
|
+
"video/ogg",
|
|
5882
|
+
"video/x-matroska",
|
|
5883
|
+
"audio/mpeg",
|
|
5884
|
+
"audio/mp4",
|
|
5885
|
+
"audio/ogg",
|
|
5886
|
+
"audio/wav",
|
|
5887
|
+
"audio/webm",
|
|
5888
|
+
"audio/flac"
|
|
5889
|
+
].join(",");
|
|
5890
|
+
/***************************
|
|
5891
|
+
* The pure half
|
|
5892
|
+
***************************/
|
|
5893
|
+
/***************************************************************************
|
|
5894
|
+
* A size a person reads. Bytes up to 1 KB, then one decimal.
|
|
5895
|
+
***************************************************************************/
|
|
5896
|
+
function yui_file_size_label(bytes) {
|
|
5897
|
+
let n = Number(bytes);
|
|
5898
|
+
if (!isFinite(n) || n < 0) return "";
|
|
5899
|
+
if (n < 1024) return `${n} B`;
|
|
5900
|
+
const units = [
|
|
5901
|
+
"KB",
|
|
5902
|
+
"MB",
|
|
5903
|
+
"GB",
|
|
5904
|
+
"TB"
|
|
5905
|
+
];
|
|
5906
|
+
let i = -1;
|
|
5907
|
+
do {
|
|
5908
|
+
n = n / 1024;
|
|
5909
|
+
i++;
|
|
5910
|
+
} while (n >= 1024 && i < units.length - 1);
|
|
5911
|
+
return `${n.toFixed(1)} ${units[i]}`;
|
|
5912
|
+
}
|
|
5913
|
+
/***************************************************************************
|
|
5914
|
+
* The sha256 of an ArrayBuffer, lowercase hex, or null.
|
|
5915
|
+
*
|
|
5916
|
+
* NULL is a legal answer and not a failure: `crypto.subtle` exists only
|
|
5917
|
+
* in a SECURE CONTEXT, so a dev server on plain http has none. Then the
|
|
5918
|
+
* record carries no id and treedb fills it -- the write path hashes what
|
|
5919
|
+
* arrives anyway, because it never trusts the client's id. What the hash
|
|
5920
|
+
* buys here is an integrity check the backend can make (a wrong id with
|
|
5921
|
+
* good bytes is refused), not the identity itself.
|
|
5922
|
+
***************************************************************************/
|
|
5923
|
+
async function yui_file_sha256(buffer) {
|
|
5924
|
+
const subtle = typeof crypto !== "undefined" && crypto.subtle;
|
|
5925
|
+
if (!subtle) return null;
|
|
5926
|
+
try {
|
|
5927
|
+
const digest = await subtle.digest("SHA-256", buffer);
|
|
5928
|
+
return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
5929
|
+
} catch (e) {
|
|
5930
|
+
(0, _yuneta_gobj_js.log_error)(`cannot hash the picked file: ${e && e.message ? e.message : e}`);
|
|
5931
|
+
return null;
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
/***************************************************************************
|
|
5935
|
+
* base64 of an ArrayBuffer.
|
|
5936
|
+
*
|
|
5937
|
+
* In chunks because `String.fromCharCode(...bytes)` spreads the whole
|
|
5938
|
+
* array onto the call stack, and a few hundred KB is already a
|
|
5939
|
+
* RangeError -- which for a file picker is every file that matters.
|
|
5940
|
+
***************************************************************************/
|
|
5941
|
+
function yui_array_buffer_to_base64(buffer) {
|
|
5942
|
+
const bytes = new Uint8Array(buffer);
|
|
5943
|
+
const CHUNK = 32768;
|
|
5944
|
+
let binary = "";
|
|
5945
|
+
for (let i = 0; i < bytes.length; i += CHUNK) binary += String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK));
|
|
5946
|
+
return btoa(binary);
|
|
5947
|
+
}
|
|
5948
|
+
/***************************************************************************
|
|
5949
|
+
* Read ONE picked file into what the manifest carries.
|
|
5950
|
+
*
|
|
5951
|
+
* -> {content64, content_type, original_name, size, id}
|
|
5952
|
+
*
|
|
5953
|
+
* `id` is the sha256 when it could be computed, and "" when it could
|
|
5954
|
+
* not. Nothing else in here is optional: treedb checks the size on the
|
|
5955
|
+
* base64 before decoding it, and the type against the BYTES.
|
|
5956
|
+
***************************************************************************/
|
|
5957
|
+
async function yui_file_read(file) {
|
|
5958
|
+
const buffer = await file.arrayBuffer();
|
|
5959
|
+
const id = await yui_file_sha256(buffer);
|
|
5960
|
+
return {
|
|
5961
|
+
content64: yui_array_buffer_to_base64(buffer),
|
|
5962
|
+
content_type: file.type || "",
|
|
5963
|
+
original_name: file.name || "",
|
|
5964
|
+
size: file.size,
|
|
5965
|
+
id: id || ""
|
|
5966
|
+
};
|
|
5967
|
+
}
|
|
5968
|
+
/***************************************************************************
|
|
5969
|
+
* The write a record with picked files becomes.
|
|
5970
|
+
*
|
|
5971
|
+
* picks {col: read} what yui_file_read() answered, per column
|
|
5972
|
+
* record the record the form collected (MODIFIED: each picked
|
|
5973
|
+
* column takes the id, or "" when there is none)
|
|
5974
|
+
*
|
|
5975
|
+
* -> {record, __files__}
|
|
5976
|
+
*
|
|
5977
|
+
* `__files__` is not a column: it is an instruction to the write path,
|
|
5978
|
+
* consumed and dropped at the door. The bytes never go INSIDE the
|
|
5979
|
+
* column -- a field that CARRIES the bytes and a field that KEEPS them
|
|
5980
|
+
* are one word apart and 460 MB of RAM apart.
|
|
5981
|
+
***************************************************************************/
|
|
5982
|
+
function yui_files_manifest(picks, record) {
|
|
5983
|
+
const out = record || {};
|
|
5984
|
+
const manifest = {};
|
|
5985
|
+
Object.keys(picks || {}).forEach((col) => {
|
|
5986
|
+
const read = picks[col];
|
|
5987
|
+
if (!read) return;
|
|
5988
|
+
manifest[col] = {
|
|
5989
|
+
content64: read.content64,
|
|
5990
|
+
content_type: read.content_type,
|
|
5991
|
+
original_name: read.original_name
|
|
5992
|
+
};
|
|
5993
|
+
out[col] = read.id || "";
|
|
5994
|
+
});
|
|
5995
|
+
return {
|
|
5996
|
+
record: out,
|
|
5997
|
+
__files__: manifest
|
|
5998
|
+
};
|
|
5999
|
+
}
|
|
6000
|
+
/***************************
|
|
6001
|
+
* The DOM half
|
|
6002
|
+
***************************/
|
|
6003
|
+
/***************************************************************************
|
|
6004
|
+
* What the control shows for what the column HOLDS today: the asset id,
|
|
6005
|
+
* shortened. A sha256 in full is 64 characters of noise in a form.
|
|
6006
|
+
***************************************************************************/
|
|
6007
|
+
function yui_file_id_label(id) {
|
|
6008
|
+
if (!id) return "";
|
|
6009
|
+
return id.length > 16 ? `${id.slice(0, 8)}…${id.slice(-4)}` : id;
|
|
6010
|
+
}
|
|
6011
|
+
/***************************************************************************
|
|
6012
|
+
* The control for a `file` column.
|
|
6013
|
+
*
|
|
6014
|
+
* name the column
|
|
6015
|
+
* value the asset id the record holds today ("" when none)
|
|
6016
|
+
* readonly draw it, do not let it change
|
|
6017
|
+
* on_pick (file|null) -> void. NULL is "the person cleared it".
|
|
6018
|
+
*
|
|
6019
|
+
* Returns the `<div class="control">` content, and hangs the state the
|
|
6020
|
+
* form reads off the returned element:
|
|
6021
|
+
*
|
|
6022
|
+
* $control.yui_file the picked File, or null
|
|
6023
|
+
* $control.yui_file_value the id the column keeps ("" = cleared)
|
|
6024
|
+
*
|
|
6025
|
+
* The `<input type="file">` is hidden and driven by a button, because a
|
|
6026
|
+
* bare file input cannot be styled and says "Sin archivos seleccionados"
|
|
6027
|
+
* in the browser's own language, not the app's.
|
|
6028
|
+
***************************************************************************/
|
|
6029
|
+
function yui_file_control(gobj, { name, value, readonly, accept, on_pick }) {
|
|
6030
|
+
const has_asset = !!value;
|
|
6031
|
+
const $input = (0, _yuneta_gobj_js.createElement2)(["input", {
|
|
6032
|
+
type: "file",
|
|
6033
|
+
class: "FILE_INPUT",
|
|
6034
|
+
name: `${name}__file`,
|
|
6035
|
+
accept: accept || YUI_FILE_ACCEPT,
|
|
6036
|
+
hidden: ""
|
|
6037
|
+
}]);
|
|
6038
|
+
if (readonly) $input.disabled = true;
|
|
6039
|
+
const $pick = (0, _yuneta_gobj_js.createElement2)([
|
|
6040
|
+
"button",
|
|
6041
|
+
{
|
|
6042
|
+
type: "button",
|
|
6043
|
+
class: "FILE_PICK button is-small",
|
|
6044
|
+
"data-i18n-title": "choose a file",
|
|
6045
|
+
"aria-label": "choose a file"
|
|
6046
|
+
},
|
|
6047
|
+
[["span", { class: "FILE_PICK_ICON yi-upload" }], [
|
|
6048
|
+
"span",
|
|
6049
|
+
{
|
|
6050
|
+
class: "FILE_PICK_LABEL",
|
|
6051
|
+
i18n: "choose a file"
|
|
6052
|
+
},
|
|
6053
|
+
"choose a file"
|
|
6054
|
+
]]
|
|
6055
|
+
]);
|
|
6056
|
+
const $clear = (0, _yuneta_gobj_js.createElement2)([
|
|
6057
|
+
"button",
|
|
6058
|
+
{
|
|
6059
|
+
type: "button",
|
|
6060
|
+
class: "FILE_CLEAR button is-small",
|
|
6061
|
+
"data-i18n-title": "remove the file",
|
|
6062
|
+
"aria-label": "remove the file"
|
|
6063
|
+
},
|
|
6064
|
+
[["span", { class: "FILE_CLEAR_ICON yi-trash" }]]
|
|
6065
|
+
]);
|
|
6066
|
+
const $name = (0, _yuneta_gobj_js.createElement2)(["span", { class: "FILE_NAME" }]);
|
|
6067
|
+
const $size = (0, _yuneta_gobj_js.createElement2)(["span", { class: "FILE_SIZE" }]);
|
|
6068
|
+
const $state = (0, _yuneta_gobj_js.createElement2)(["span", { class: "FILE_STATE" }]);
|
|
6069
|
+
const $control = (0, _yuneta_gobj_js.createElement2)([
|
|
6070
|
+
"div",
|
|
6071
|
+
{ class: "FILE_FIELD" },
|
|
6072
|
+
[
|
|
6073
|
+
$input,
|
|
6074
|
+
$pick,
|
|
6075
|
+
$name,
|
|
6076
|
+
$size,
|
|
6077
|
+
$state,
|
|
6078
|
+
$clear
|
|
6079
|
+
]
|
|
6080
|
+
]);
|
|
6081
|
+
$control.yui_file = null;
|
|
6082
|
+
$control.yui_file_value = value || "";
|
|
6083
|
+
const render = () => {
|
|
6084
|
+
const picked = $control.yui_file;
|
|
6085
|
+
const kept = $control.yui_file_value;
|
|
6086
|
+
$name.textContent = picked ? picked.name || "" : yui_file_id_label(kept);
|
|
6087
|
+
$name.title = picked ? picked.name || "" : kept || "";
|
|
6088
|
+
$size.textContent = picked ? yui_file_size_label(picked.size) : "";
|
|
6089
|
+
$state.className = "FILE_STATE";
|
|
6090
|
+
$state.removeAttribute("data-i18n");
|
|
6091
|
+
$state.textContent = "";
|
|
6092
|
+
if (picked) {
|
|
6093
|
+
$state.classList.add("is-picked");
|
|
6094
|
+
$state.setAttribute("data-i18n", "not saved yet");
|
|
6095
|
+
$state.textContent = "not saved yet";
|
|
6096
|
+
} else if (!kept) {
|
|
6097
|
+
$state.classList.add("is-empty");
|
|
6098
|
+
$state.setAttribute("data-i18n", "no file");
|
|
6099
|
+
$state.textContent = "no file";
|
|
6100
|
+
}
|
|
6101
|
+
$clear.hidden = readonly || !picked && !kept;
|
|
6102
|
+
$pick.hidden = !!readonly;
|
|
6103
|
+
};
|
|
6104
|
+
if (!readonly) {
|
|
6105
|
+
$pick.addEventListener("click", () => {
|
|
6106
|
+
$input.click();
|
|
6107
|
+
});
|
|
6108
|
+
$input.addEventListener("change", () => {
|
|
6109
|
+
const file = $input.files && $input.files.length ? $input.files[0] : null;
|
|
6110
|
+
$control.yui_file = file;
|
|
6111
|
+
render();
|
|
6112
|
+
if (on_pick) on_pick(file);
|
|
6113
|
+
});
|
|
6114
|
+
$clear.addEventListener("click", () => {
|
|
6115
|
+
$control.yui_file = null;
|
|
6116
|
+
$control.yui_file_value = "";
|
|
6117
|
+
$input.value = "";
|
|
6118
|
+
render();
|
|
6119
|
+
if (on_pick) on_pick(null);
|
|
6120
|
+
});
|
|
6121
|
+
}
|
|
6122
|
+
$control.yui_file_render = render;
|
|
6123
|
+
render();
|
|
6124
|
+
return {
|
|
6125
|
+
$control,
|
|
6126
|
+
$input,
|
|
6127
|
+
has_asset
|
|
6128
|
+
};
|
|
6129
|
+
}
|
|
6130
|
+
//#endregion
|
|
6131
|
+
//#region src/yui_asset.js
|
|
6132
|
+
function ref_to_id(ref) {
|
|
6133
|
+
if (!ref) return null;
|
|
6134
|
+
if (typeof ref === "string") {
|
|
6135
|
+
if (ref.indexOf("^") < 0) return ref;
|
|
6136
|
+
const parts = ref.split("^");
|
|
6137
|
+
return parts.length >= 2 && parts[1] ? parts[1] : null;
|
|
6138
|
+
}
|
|
6139
|
+
if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
|
|
6140
|
+
return null;
|
|
6141
|
+
}
|
|
6142
|
+
/***************************************************************************
|
|
6143
|
+
* Every asset id a column names, in order. Always an array, possibly empty.
|
|
6144
|
+
***************************************************************************/
|
|
6145
|
+
function yui_asset_ids(ref) {
|
|
6146
|
+
if (Array.isArray(ref)) return ref.map(ref_to_id).filter((id) => !!id);
|
|
6147
|
+
const id = ref_to_id(ref);
|
|
6148
|
+
return id ? [id] : [];
|
|
6149
|
+
}
|
|
6150
|
+
/***************************************************************************
|
|
6151
|
+
* The first asset id a column names, or null.
|
|
6152
|
+
***************************************************************************/
|
|
6153
|
+
function yui_asset_id(ref) {
|
|
6154
|
+
const ids = yui_asset_ids(ref);
|
|
6155
|
+
return ids.length ? ids[0] : null;
|
|
6156
|
+
}
|
|
6157
|
+
/***************************************************************************
|
|
6158
|
+
* Turn a `get-asset` answer into something an element can load.
|
|
6159
|
+
*
|
|
6160
|
+
* Returns null when the answer carries neither -- which the caller must
|
|
6161
|
+
* treat as "missing", never as an empty src: an <img src=""> reloads the
|
|
6162
|
+
* PAGE in some browsers.
|
|
6163
|
+
***************************************************************************/
|
|
6164
|
+
function yui_asset_src(answer) {
|
|
6165
|
+
if (!answer) return null;
|
|
6166
|
+
if (answer.mode === "url" && answer.url) return answer.url;
|
|
6167
|
+
if (answer.mode === "inline" && answer.content64) return `data:${answer.content_type || "application/octet-stream"};base64,${answer.content64}`;
|
|
6168
|
+
return null;
|
|
6169
|
+
}
|
|
6170
|
+
/***************************************************************************
|
|
6171
|
+
* The marker for an asset that is not there.
|
|
6172
|
+
*
|
|
6173
|
+
* A missing image used to leave a broken box and no word about it, which
|
|
6174
|
+
* is indistinguishable from a slow one and from a bug. This says so, and
|
|
6175
|
+
* it says WHICH: `detail` is data (a name, a path) and is never
|
|
6176
|
+
* translated, while the label carries its i18n key so a language change
|
|
6177
|
+
* re-translates it.
|
|
6178
|
+
***************************************************************************/
|
|
6179
|
+
function yui_asset_missing(detail, opts = {}) {
|
|
6180
|
+
const key = opts.key || "asset not available";
|
|
6181
|
+
const children = [["span", { class: "ASSET_MISSING_ICON yi-triangle-exclamation" }], [
|
|
6182
|
+
"span",
|
|
6183
|
+
{
|
|
6184
|
+
class: "ASSET_MISSING_LABEL",
|
|
6185
|
+
i18n: key
|
|
6186
|
+
},
|
|
6187
|
+
key
|
|
6188
|
+
]];
|
|
6189
|
+
if (detail) children.push([
|
|
6190
|
+
"span",
|
|
6191
|
+
{ class: "ASSET_MISSING_DETAIL" },
|
|
6192
|
+
String(detail)
|
|
6193
|
+
]);
|
|
6194
|
+
const attrs = { class: `ASSET_MISSING ${opts.class || ""}`.trim() };
|
|
6195
|
+
if (detail) attrs.title = String(detail);
|
|
6196
|
+
else attrs["data-i18n-title"] = key;
|
|
6197
|
+
return (0, _yuneta_gobj_js.createElement2)([
|
|
6198
|
+
"div",
|
|
6199
|
+
attrs,
|
|
6200
|
+
children
|
|
6201
|
+
]);
|
|
6202
|
+
}
|
|
6203
|
+
/***************************************************************************
|
|
6204
|
+
* The element for one asset.
|
|
6205
|
+
*
|
|
6206
|
+
* The KIND comes from the content type the backend stored, not from the
|
|
6207
|
+
* name a person typed: video and audio are assets too, and an <img> whose
|
|
6208
|
+
* src is a film shows the broken box this module exists to remove.
|
|
6209
|
+
*
|
|
6210
|
+
* `detail` is what the missing marker shows -- pass the original name or
|
|
6211
|
+
* the source path, the thing a person can act on.
|
|
6212
|
+
***************************************************************************/
|
|
6213
|
+
function yui_asset_element(answer, opts = {}) {
|
|
6214
|
+
const src = yui_asset_src(answer);
|
|
6215
|
+
if (!src) return yui_asset_missing(opts.detail, opts);
|
|
6216
|
+
const ct = (answer.content_type || "").toLowerCase();
|
|
6217
|
+
const cls = `ASSET_MEDIA ${opts.class || ""}`.trim();
|
|
6218
|
+
let el;
|
|
6219
|
+
if (ct.startsWith("video/")) el = (0, _yuneta_gobj_js.createElement2)(["video", {
|
|
6220
|
+
class: cls,
|
|
6221
|
+
controls: "",
|
|
6222
|
+
preload: "metadata"
|
|
6223
|
+
}]);
|
|
6224
|
+
else if (ct.startsWith("audio/")) el = (0, _yuneta_gobj_js.createElement2)(["audio", {
|
|
6225
|
+
class: cls,
|
|
6226
|
+
controls: "",
|
|
6227
|
+
preload: "metadata"
|
|
6228
|
+
}]);
|
|
6229
|
+
else {
|
|
6230
|
+
el = (0, _yuneta_gobj_js.createElement2)(["img", {
|
|
6231
|
+
class: cls,
|
|
6232
|
+
loading: "lazy"
|
|
6233
|
+
}]);
|
|
6234
|
+
el.alt = opts.alt || opts.detail || "";
|
|
6235
|
+
}
|
|
6236
|
+
el.src = src;
|
|
6237
|
+
el.onerror = () => {
|
|
6238
|
+
(0, _yuneta_gobj_js.log_error)(`asset could not be loaded: ${opts.detail || src}`);
|
|
6239
|
+
const $marker = yui_asset_missing(opts.detail, opts);
|
|
6240
|
+
if (el.parentNode) el.parentNode.replaceChild($marker, el);
|
|
6241
|
+
};
|
|
6242
|
+
return el;
|
|
6243
|
+
}
|
|
6244
|
+
//#endregion
|
|
5835
6245
|
//#region src/yui_inputs.js
|
|
5836
6246
|
/***************************************************************
|
|
5837
6247
|
* The ✕ shows only when there is something to clear AND the field
|
|
@@ -6805,6 +7215,9 @@ function build_form_field_conf(gobj, field_desc) {
|
|
|
6805
7215
|
field_conf.tag = "select2";
|
|
6806
7216
|
field_conf.options = get_fkey_select_options(gobj, field_desc);
|
|
6807
7217
|
break;
|
|
7218
|
+
case "file":
|
|
7219
|
+
field_conf.tag = "file";
|
|
7220
|
+
break;
|
|
6808
7221
|
case "image":
|
|
6809
7222
|
case "icon":
|
|
6810
7223
|
case "string":
|
|
@@ -7490,6 +7903,17 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
|
|
|
7490
7903
|
$control.appendChild($extend);
|
|
7491
7904
|
break;
|
|
7492
7905
|
}
|
|
7906
|
+
case "file":
|
|
7907
|
+
$extend = yui_file_control(gobj, {
|
|
7908
|
+
name,
|
|
7909
|
+
value: "",
|
|
7910
|
+
readonly,
|
|
7911
|
+
on_pick: function() {
|
|
7912
|
+
(0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
7913
|
+
}
|
|
7914
|
+
}).$control;
|
|
7915
|
+
$control.appendChild($extend);
|
|
7916
|
+
break;
|
|
7493
7917
|
default:
|
|
7494
7918
|
$extend = (0, _yuneta_gobj_js.createElement2)([
|
|
7495
7919
|
"strong",
|
|
@@ -7577,6 +8001,12 @@ function apply_readonly_to_control(readonly, tag, inputType, $extend) {
|
|
|
7577
8001
|
case "jsoneditor":
|
|
7578
8002
|
$extend.classList.add("yui-jse-readonly");
|
|
7579
8003
|
break;
|
|
8004
|
+
case "file":
|
|
8005
|
+
{
|
|
8006
|
+
const $picker = $extend.querySelector(".FILE_INPUT");
|
|
8007
|
+
if ($picker) $picker.disabled = true;
|
|
8008
|
+
}
|
|
8009
|
+
break;
|
|
7580
8010
|
case "input": if (inputType === "color") $extend.setAttribute("disabled", "disabled");
|
|
7581
8011
|
}
|
|
7582
8012
|
}
|
|
@@ -7990,6 +8420,9 @@ function get_form_values(gobj, $form) {
|
|
|
7990
8420
|
case "radio":
|
|
7991
8421
|
value = getInputValue($input);
|
|
7992
8422
|
break;
|
|
8423
|
+
case "file":
|
|
8424
|
+
value = $input.yui_file_value || "";
|
|
8425
|
+
break;
|
|
7993
8426
|
case "jsoneditor":
|
|
7994
8427
|
let jsoneditor = $input.jsoneditor;
|
|
7995
8428
|
if (jsoneditor) {
|
|
@@ -8046,6 +8479,13 @@ function clear_data(gobj, $form) {
|
|
|
8046
8479
|
else $input.value = null;
|
|
8047
8480
|
}
|
|
8048
8481
|
});
|
|
8482
|
+
$form.querySelectorAll(".FILE_FIELD").forEach(($file) => {
|
|
8483
|
+
$file.yui_file = null;
|
|
8484
|
+
$file.yui_file_value = "";
|
|
8485
|
+
let $picker = $file.querySelector(".FILE_INPUT");
|
|
8486
|
+
if ($picker) $picker.value = "";
|
|
8487
|
+
if ($file.yui_file_render) $file.yui_file_render();
|
|
8488
|
+
});
|
|
8049
8489
|
$form.querySelectorAll(".yui-tabulator-table").forEach(($table) => {
|
|
8050
8490
|
if ($table.tabulator.initialized) $table.tabulator.clearData();
|
|
8051
8491
|
$table.querySelectorAll(".yui-tabulator-table-nested").forEach(($table_nested) => {
|
|
@@ -8115,6 +8555,11 @@ function set_form_values(gobj, template, $form, record) {
|
|
|
8115
8555
|
value = treedb_value_2_form_value(gobj, field_desc, value);
|
|
8116
8556
|
if (value === void 0) value = null;
|
|
8117
8557
|
switch (tag) {
|
|
8558
|
+
case "file":
|
|
8559
|
+
$input.yui_file = null;
|
|
8560
|
+
$input.yui_file_value = yui_asset_id(value) || "";
|
|
8561
|
+
if ($input.yui_file_render) $input.yui_file_render();
|
|
8562
|
+
break;
|
|
8118
8563
|
case "input":
|
|
8119
8564
|
switch (input_type) {
|
|
8120
8565
|
case "datetime-local":
|
|
@@ -8204,6 +8649,7 @@ function treedb_value_2_form_value(gobj, field_desc, value) {
|
|
|
8204
8649
|
return { json: (0, _yuneta_gobj_js.is_object)(value) || (0, _yuneta_gobj_js.is_array)(value) ? value : {} };
|
|
8205
8650
|
}
|
|
8206
8651
|
switch (type) {
|
|
8652
|
+
case "file": return value;
|
|
8207
8653
|
case "fkey": {
|
|
8208
8654
|
let new_value = [];
|
|
8209
8655
|
if ((0, _yuneta_gobj_js.is_string)(value) && !(0, _yuneta_gobj_js.empty_string)(value)) {
|
|
@@ -8300,6 +8746,7 @@ function form_value_2_treedb_value(gobj, field_desc, value) {
|
|
|
8300
8746
|
return value;
|
|
8301
8747
|
}
|
|
8302
8748
|
switch (type) {
|
|
8749
|
+
case "file": break;
|
|
8303
8750
|
case "fkey":
|
|
8304
8751
|
value = build_fkey_ref$1(gobj, field_desc, value);
|
|
8305
8752
|
break;
|
|
@@ -8543,11 +8990,63 @@ function ac_timeout(gobj, event, kw, src) {
|
|
|
8543
8990
|
/***************************
|
|
8544
8991
|
* FSM
|
|
8545
8992
|
***************************/
|
|
8993
|
+
/************************************************************
|
|
8994
|
+
* Framework Method command
|
|
8995
|
+
************************************************************/
|
|
8996
|
+
function mt_command_parser$2(gobj, command, kw, src) {
|
|
8997
|
+
switch (command) {
|
|
8998
|
+
case "get_picked_files": return cmd_get_picked_files(gobj, command, kw, src);
|
|
8999
|
+
default:
|
|
9000
|
+
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: command not found: ${command}`);
|
|
9001
|
+
return {
|
|
9002
|
+
result: -1,
|
|
9003
|
+
comment: `Command not found: ${command}`,
|
|
9004
|
+
schema: null,
|
|
9005
|
+
data: null
|
|
9006
|
+
};
|
|
9007
|
+
}
|
|
9008
|
+
}
|
|
9009
|
+
/************************************************************
|
|
9010
|
+
* The files a person picked and the record cannot carry.
|
|
9011
|
+
*
|
|
9012
|
+
* A `File` is a host object and a kw is plain json -- the machine trace
|
|
9013
|
+
* serialises it -- so the picked files never travel in an event. The
|
|
9014
|
+
* form KEEPS them and the HOST asks for them here, at save, and turns
|
|
9015
|
+
* them into the `__files__` manifest that rides beside the record.
|
|
9016
|
+
*
|
|
9017
|
+
* Answers `data: {col: File}`, empty when nothing was picked, which is
|
|
9018
|
+
* the ordinary case and not an error.
|
|
9019
|
+
************************************************************/
|
|
9020
|
+
function cmd_get_picked_files(gobj, cmd, kw, src) {
|
|
9021
|
+
const files = {};
|
|
9022
|
+
const $container = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container");
|
|
9023
|
+
const $form = $container ? $container.querySelector("form") : null;
|
|
9024
|
+
if (!$form) {
|
|
9025
|
+
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: no form to read the picked files from`);
|
|
9026
|
+
return {
|
|
9027
|
+
result: -1,
|
|
9028
|
+
comment: "no form",
|
|
9029
|
+
schema: null,
|
|
9030
|
+
data: null
|
|
9031
|
+
};
|
|
9032
|
+
}
|
|
9033
|
+
$form.querySelectorAll(".yui-form-data-input").forEach(($input) => {
|
|
9034
|
+
if ($input.dataset.form_tag !== "file") return;
|
|
9035
|
+
if ($input.yui_file) files[$input.dataset.treedb_name] = $input.yui_file;
|
|
9036
|
+
});
|
|
9037
|
+
return {
|
|
9038
|
+
result: 0,
|
|
9039
|
+
comment: "",
|
|
9040
|
+
schema: null,
|
|
9041
|
+
data: files
|
|
9042
|
+
};
|
|
9043
|
+
}
|
|
8546
9044
|
var gmt$16 = {
|
|
8547
9045
|
mt_create: mt_create$16,
|
|
8548
9046
|
mt_start: mt_start$15,
|
|
8549
9047
|
mt_stop: mt_stop$15,
|
|
8550
|
-
mt_destroy: mt_destroy$16
|
|
9048
|
+
mt_destroy: mt_destroy$16,
|
|
9049
|
+
mt_command_parser: mt_command_parser$2
|
|
8551
9050
|
};
|
|
8552
9051
|
/***************************************************************
|
|
8553
9052
|
* Create the GClass
|
|
@@ -23990,6 +24489,9 @@ function create_tabulator(gobj) {
|
|
|
23990
24489
|
vertAlign = "middle";
|
|
23991
24490
|
colFormatter = icon_formatter;
|
|
23992
24491
|
break;
|
|
24492
|
+
case "file":
|
|
24493
|
+
colFormatter = file_cell_formatter;
|
|
24494
|
+
break;
|
|
23993
24495
|
case "object":
|
|
23994
24496
|
case "dict":
|
|
23995
24497
|
case "template":
|
|
@@ -24234,6 +24736,33 @@ function table__destroy(gobj) {
|
|
|
24234
24736
|
* render a solid square -- a glyph nobody recognises rather
|
|
24235
24737
|
* than a mistake somebody can fix.
|
|
24236
24738
|
************************************************************/
|
|
24739
|
+
/************************************************************
|
|
24740
|
+
* What a `file` column shows in a table cell: the asset it names.
|
|
24741
|
+
*
|
|
24742
|
+
* A sha256 in full is 64 characters of noise in a column, so it is
|
|
24743
|
+
* shortened and the whole of it is the tooltip. Empty is SAID, not left
|
|
24744
|
+
* blank -- a blank cell and a cell whose asset failed to load look the
|
|
24745
|
+
* same, and only one of them is normal.
|
|
24746
|
+
************************************************************/
|
|
24747
|
+
function file_cell_formatter(cell, formatterParams, onRendered) {
|
|
24748
|
+
const id = yui_asset_id(cell.getValue());
|
|
24749
|
+
if (!id) return (0, _yuneta_gobj_js.createElement2)([
|
|
24750
|
+
"span",
|
|
24751
|
+
{
|
|
24752
|
+
class: "FILE_CELL is-empty",
|
|
24753
|
+
"data-i18n": "no file"
|
|
24754
|
+
},
|
|
24755
|
+
"no file"
|
|
24756
|
+
]);
|
|
24757
|
+
return (0, _yuneta_gobj_js.createElement2)([
|
|
24758
|
+
"span",
|
|
24759
|
+
{
|
|
24760
|
+
class: "FILE_CELL",
|
|
24761
|
+
title: id
|
|
24762
|
+
},
|
|
24763
|
+
yui_file_id_label(id)
|
|
24764
|
+
]);
|
|
24765
|
+
}
|
|
24237
24766
|
function icon_formatter(cell) {
|
|
24238
24767
|
let name = cell.getValue();
|
|
24239
24768
|
if (!(0, _yuneta_gobj_js.is_string)(name) || (0, _yuneta_gobj_js.empty_string)(name)) return "";
|
|
@@ -24329,6 +24858,7 @@ function transform__treedb_value_2_table_value(gobj, col, value, row, field) {
|
|
|
24329
24858
|
].join("");
|
|
24330
24859
|
else value = "";
|
|
24331
24860
|
break;
|
|
24861
|
+
case "file":
|
|
24332
24862
|
case "fkey":
|
|
24333
24863
|
let new_value = [];
|
|
24334
24864
|
if (value) {
|
|
@@ -24853,6 +25383,7 @@ function transform__form_value_2_treedb_value(gobj, col, value, operation) {
|
|
|
24853
25383
|
case "hook":
|
|
24854
25384
|
value = null;
|
|
24855
25385
|
break;
|
|
25386
|
+
case "file": break;
|
|
24856
25387
|
case "fkey":
|
|
24857
25388
|
value = build_fkey_ref(gobj, col, value);
|
|
24858
25389
|
break;
|
|
@@ -25336,13 +25867,71 @@ function ac_paste_rows(gobj, event, kw, src) {
|
|
|
25336
25867
|
function ac_form_save_record(gobj, event, kw, src) {
|
|
25337
25868
|
if (refuse_if_readonly$2(gobj, event)) return -1;
|
|
25338
25869
|
let mode = (0, _yuneta_gobj_js.gobj_read_str_attr)(src, "form_mode");
|
|
25339
|
-
|
|
25870
|
+
let picked = {};
|
|
25871
|
+
const answer = (0, _yuneta_gobj_js.gobj_command)(src, "get_picked_files", {}, gobj);
|
|
25872
|
+
if (answer && answer.result >= 0 && answer.data) picked = answer.data;
|
|
25873
|
+
const cols = Object.keys(picked);
|
|
25874
|
+
if (cols.length === 0) {
|
|
25875
|
+
publish_treedb_write(gobj, mode, kw);
|
|
25876
|
+
setTimeout(function() {
|
|
25877
|
+
close_form_dialog(gobj);
|
|
25878
|
+
}, 0);
|
|
25879
|
+
return 0;
|
|
25880
|
+
}
|
|
25881
|
+
Promise.all(cols.map((col) => {
|
|
25882
|
+
return yui_file_read(picked[col]).then((read) => {
|
|
25883
|
+
return {
|
|
25884
|
+
col,
|
|
25885
|
+
read
|
|
25886
|
+
};
|
|
25887
|
+
});
|
|
25888
|
+
})).then((reads) => {
|
|
25889
|
+
const picks = {};
|
|
25890
|
+
reads.forEach((r) => {
|
|
25891
|
+
picks[r.col] = r.read;
|
|
25892
|
+
});
|
|
25893
|
+
(0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_FILES_READ", {
|
|
25894
|
+
mode,
|
|
25895
|
+
record: kw,
|
|
25896
|
+
picks
|
|
25897
|
+
}, gobj);
|
|
25898
|
+
}).catch((e) => {
|
|
25899
|
+
(0, _yuneta_gobj_js.gobj_send_event)(gobj, "EV_FILES_FAILED", { reason: e && e.message ? e.message : String(e) }, gobj);
|
|
25900
|
+
});
|
|
25901
|
+
return 0;
|
|
25902
|
+
}
|
|
25903
|
+
/************************************************************
|
|
25904
|
+
* The one place a write of this view leaves for the app.
|
|
25905
|
+
************************************************************/
|
|
25906
|
+
function publish_treedb_write(gobj, mode, record, jn_files) {
|
|
25907
|
+
const kw_write = {
|
|
25340
25908
|
topic_name: (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "topic_name"),
|
|
25341
|
-
record
|
|
25909
|
+
record
|
|
25910
|
+
};
|
|
25911
|
+
if (jn_files && Object.keys(jn_files).length > 0) kw_write.record.__files__ = jn_files;
|
|
25912
|
+
(0, _yuneta_gobj_js.gobj_publish_event)(gobj, mode === "create" ? "EV_CREATE_RECORD" : "EV_UPDATE_RECORD", kw_write);
|
|
25913
|
+
}
|
|
25914
|
+
/************************************************************
|
|
25915
|
+
* {mode, record, picks} -- the bytes are here now
|
|
25916
|
+
************************************************************/
|
|
25917
|
+
function ac_files_read(gobj, event, kw, src) {
|
|
25918
|
+
const { record, __files__ } = yui_files_manifest(kw.picks, kw.record);
|
|
25919
|
+
publish_treedb_write(gobj, kw.mode, record, __files__);
|
|
25920
|
+
close_form_dialog(gobj);
|
|
25921
|
+
return 0;
|
|
25922
|
+
}
|
|
25923
|
+
/************************************************************
|
|
25924
|
+
* {reason} -- the browser could not read what was picked
|
|
25925
|
+
*
|
|
25926
|
+
* The form stays OPEN: the record is still there, and closing it would
|
|
25927
|
+
* throw away what the person typed for a failure that is not theirs.
|
|
25928
|
+
************************************************************/
|
|
25929
|
+
function ac_files_failed(gobj, event, kw, src) {
|
|
25930
|
+
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot read the picked file: ${kw.reason}`);
|
|
25931
|
+
yui_shell_confirm_ok(yui_shell_of(gobj), "cannot read the picked file", {
|
|
25932
|
+
t: i18next.t,
|
|
25933
|
+
ok_label: "accept"
|
|
25342
25934
|
});
|
|
25343
|
-
setTimeout(function() {
|
|
25344
|
-
close_form_dialog(gobj);
|
|
25345
|
-
}, 0);
|
|
25346
25935
|
return 0;
|
|
25347
25936
|
}
|
|
25348
25937
|
/************************************************************
|
|
@@ -25861,6 +26450,16 @@ function create_gclass$5(gclass_name) {
|
|
|
25861
26450
|
ac_form_save_record,
|
|
25862
26451
|
null
|
|
25863
26452
|
],
|
|
26453
|
+
[
|
|
26454
|
+
"EV_FILES_READ",
|
|
26455
|
+
ac_files_read,
|
|
26456
|
+
null
|
|
26457
|
+
],
|
|
26458
|
+
[
|
|
26459
|
+
"EV_FILES_FAILED",
|
|
26460
|
+
ac_files_failed,
|
|
26461
|
+
null
|
|
26462
|
+
],
|
|
25864
26463
|
[
|
|
25865
26464
|
"EV_NEW_ROW",
|
|
25866
26465
|
ac_new_row,
|
|
@@ -25995,6 +26594,8 @@ function create_gclass$5(gclass_name) {
|
|
|
25995
26594
|
["EV_NODE_DELETED", 0],
|
|
25996
26595
|
["EV_EDITION_MODE", 0],
|
|
25997
26596
|
["EV_SAVE_RECORD", 0],
|
|
26597
|
+
["EV_FILES_READ", 0],
|
|
26598
|
+
["EV_FILES_FAILED", 0],
|
|
25998
26599
|
["EV_NEW_ROW", 0],
|
|
25999
26600
|
["EV_DELETE_ROWS", 0],
|
|
26000
26601
|
["EV_COPY_ROWS", 0],
|
|
@@ -67507,120 +68108,6 @@ function register_c_yui_period() {
|
|
|
67507
68108
|
return create_gclass(GCLASS_NAME);
|
|
67508
68109
|
}
|
|
67509
68110
|
//#endregion
|
|
67510
|
-
//#region src/yui_asset.js
|
|
67511
|
-
function ref_to_id(ref) {
|
|
67512
|
-
if (!ref) return null;
|
|
67513
|
-
if (typeof ref === "string") {
|
|
67514
|
-
if (ref.indexOf("^") < 0) return ref;
|
|
67515
|
-
const parts = ref.split("^");
|
|
67516
|
-
return parts.length >= 2 && parts[1] ? parts[1] : null;
|
|
67517
|
-
}
|
|
67518
|
-
if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
|
|
67519
|
-
return null;
|
|
67520
|
-
}
|
|
67521
|
-
/***************************************************************************
|
|
67522
|
-
* Every asset id a column names, in order. Always an array, possibly empty.
|
|
67523
|
-
***************************************************************************/
|
|
67524
|
-
function yui_asset_ids(ref) {
|
|
67525
|
-
if (Array.isArray(ref)) return ref.map(ref_to_id).filter((id) => !!id);
|
|
67526
|
-
const id = ref_to_id(ref);
|
|
67527
|
-
return id ? [id] : [];
|
|
67528
|
-
}
|
|
67529
|
-
/***************************************************************************
|
|
67530
|
-
* The first asset id a column names, or null.
|
|
67531
|
-
***************************************************************************/
|
|
67532
|
-
function yui_asset_id(ref) {
|
|
67533
|
-
const ids = yui_asset_ids(ref);
|
|
67534
|
-
return ids.length ? ids[0] : null;
|
|
67535
|
-
}
|
|
67536
|
-
/***************************************************************************
|
|
67537
|
-
* Turn a `get-asset` answer into something an element can load.
|
|
67538
|
-
*
|
|
67539
|
-
* Returns null when the answer carries neither -- which the caller must
|
|
67540
|
-
* treat as "missing", never as an empty src: an <img src=""> reloads the
|
|
67541
|
-
* PAGE in some browsers.
|
|
67542
|
-
***************************************************************************/
|
|
67543
|
-
function yui_asset_src(answer) {
|
|
67544
|
-
if (!answer) return null;
|
|
67545
|
-
if (answer.mode === "url" && answer.url) return answer.url;
|
|
67546
|
-
if (answer.mode === "inline" && answer.content64) return `data:${answer.content_type || "application/octet-stream"};base64,${answer.content64}`;
|
|
67547
|
-
return null;
|
|
67548
|
-
}
|
|
67549
|
-
/***************************************************************************
|
|
67550
|
-
* The marker for an asset that is not there.
|
|
67551
|
-
*
|
|
67552
|
-
* A missing image used to leave a broken box and no word about it, which
|
|
67553
|
-
* is indistinguishable from a slow one and from a bug. This says so, and
|
|
67554
|
-
* it says WHICH: `detail` is data (a name, a path) and is never
|
|
67555
|
-
* translated, while the label carries its i18n key so a language change
|
|
67556
|
-
* re-translates it.
|
|
67557
|
-
***************************************************************************/
|
|
67558
|
-
function yui_asset_missing(detail, opts = {}) {
|
|
67559
|
-
const key = opts.key || "asset not available";
|
|
67560
|
-
const children = [["span", { class: "ASSET_MISSING_ICON yi-triangle-exclamation" }], [
|
|
67561
|
-
"span",
|
|
67562
|
-
{
|
|
67563
|
-
class: "ASSET_MISSING_LABEL",
|
|
67564
|
-
i18n: key
|
|
67565
|
-
},
|
|
67566
|
-
key
|
|
67567
|
-
]];
|
|
67568
|
-
if (detail) children.push([
|
|
67569
|
-
"span",
|
|
67570
|
-
{ class: "ASSET_MISSING_DETAIL" },
|
|
67571
|
-
String(detail)
|
|
67572
|
-
]);
|
|
67573
|
-
const attrs = { class: `ASSET_MISSING ${opts.class || ""}`.trim() };
|
|
67574
|
-
if (detail) attrs.title = String(detail);
|
|
67575
|
-
else attrs["data-i18n-title"] = key;
|
|
67576
|
-
return (0, _yuneta_gobj_js.createElement2)([
|
|
67577
|
-
"div",
|
|
67578
|
-
attrs,
|
|
67579
|
-
children
|
|
67580
|
-
]);
|
|
67581
|
-
}
|
|
67582
|
-
/***************************************************************************
|
|
67583
|
-
* The element for one asset.
|
|
67584
|
-
*
|
|
67585
|
-
* The KIND comes from the content type the backend stored, not from the
|
|
67586
|
-
* name a person typed: video and audio are assets too, and an <img> whose
|
|
67587
|
-
* src is a film shows the broken box this module exists to remove.
|
|
67588
|
-
*
|
|
67589
|
-
* `detail` is what the missing marker shows -- pass the original name or
|
|
67590
|
-
* the source path, the thing a person can act on.
|
|
67591
|
-
***************************************************************************/
|
|
67592
|
-
function yui_asset_element(answer, opts = {}) {
|
|
67593
|
-
const src = yui_asset_src(answer);
|
|
67594
|
-
if (!src) return yui_asset_missing(opts.detail, opts);
|
|
67595
|
-
const ct = (answer.content_type || "").toLowerCase();
|
|
67596
|
-
const cls = `ASSET_MEDIA ${opts.class || ""}`.trim();
|
|
67597
|
-
let el;
|
|
67598
|
-
if (ct.startsWith("video/")) el = (0, _yuneta_gobj_js.createElement2)(["video", {
|
|
67599
|
-
class: cls,
|
|
67600
|
-
controls: "",
|
|
67601
|
-
preload: "metadata"
|
|
67602
|
-
}]);
|
|
67603
|
-
else if (ct.startsWith("audio/")) el = (0, _yuneta_gobj_js.createElement2)(["audio", {
|
|
67604
|
-
class: cls,
|
|
67605
|
-
controls: "",
|
|
67606
|
-
preload: "metadata"
|
|
67607
|
-
}]);
|
|
67608
|
-
else {
|
|
67609
|
-
el = (0, _yuneta_gobj_js.createElement2)(["img", {
|
|
67610
|
-
class: cls,
|
|
67611
|
-
loading: "lazy"
|
|
67612
|
-
}]);
|
|
67613
|
-
el.alt = opts.alt || opts.detail || "";
|
|
67614
|
-
}
|
|
67615
|
-
el.src = src;
|
|
67616
|
-
el.onerror = () => {
|
|
67617
|
-
(0, _yuneta_gobj_js.log_error)(`asset could not be loaded: ${opts.detail || src}`);
|
|
67618
|
-
const $marker = yui_asset_missing(opts.detail, opts);
|
|
67619
|
-
if (el.parentNode) el.parentNode.replaceChild($marker, el);
|
|
67620
|
-
};
|
|
67621
|
-
return el;
|
|
67622
|
-
}
|
|
67623
|
-
//#endregion
|
|
67624
68111
|
//#region src/dev_machine_trace.js
|
|
67625
68112
|
/***********************************************************************
|
|
67626
68113
|
* dev_machine_trace.js
|
|
@@ -69306,6 +69793,7 @@ function setup_frontend_view(self) {
|
|
|
69306
69793
|
//#endregion
|
|
69307
69794
|
exports.EditControl = EditControl;
|
|
69308
69795
|
exports.MarkerControl = MarkerControl;
|
|
69796
|
+
exports.YUI_FILE_ACCEPT = YUI_FILE_ACCEPT;
|
|
69309
69797
|
exports.YUI_PERIODS = YUI_PERIODS;
|
|
69310
69798
|
exports.YUI_PERIODS_DEFAULT = YUI_PERIODS_DEFAULT;
|
|
69311
69799
|
exports.YUI_ROLLING = YUI_ROLLING;
|
|
@@ -69369,11 +69857,18 @@ exports.set_submit_state = set_submit_state;
|
|
|
69369
69857
|
exports.setup_dev = setup_dev;
|
|
69370
69858
|
exports.setup_frontend_view = setup_frontend_view;
|
|
69371
69859
|
exports.toggleClasses = toggleClasses;
|
|
69860
|
+
exports.yui_array_buffer_to_base64 = yui_array_buffer_to_base64;
|
|
69372
69861
|
exports.yui_asset_element = yui_asset_element;
|
|
69373
69862
|
exports.yui_asset_id = yui_asset_id;
|
|
69374
69863
|
exports.yui_asset_ids = yui_asset_ids;
|
|
69375
69864
|
exports.yui_asset_missing = yui_asset_missing;
|
|
69376
69865
|
exports.yui_asset_src = yui_asset_src;
|
|
69866
|
+
exports.yui_file_control = yui_file_control;
|
|
69867
|
+
exports.yui_file_id_label = yui_file_id_label;
|
|
69868
|
+
exports.yui_file_read = yui_file_read;
|
|
69869
|
+
exports.yui_file_sha256 = yui_file_sha256;
|
|
69870
|
+
exports.yui_file_size_label = yui_file_size_label;
|
|
69871
|
+
exports.yui_files_manifest = yui_files_manifest;
|
|
69377
69872
|
exports.yui_is_dark = yui_is_dark;
|
|
69378
69873
|
exports.yui_mount_service_view = yui_mount_service_view;
|
|
69379
69874
|
exports.yui_shell_close_drawer = yui_shell_close_drawer;
|