@yuneta/gobj-ui 7.23.46 → 7.23.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gobj-ui.cjs.js +3 -1
- package/dist/gobj-ui.es.js +3 -1
- package/package.json +1 -1
- package/src/yui_asset.js +31 -6
- package/src/yui_asset.test.js +21 -2
package/README.md
CHANGED
|
@@ -1388,7 +1388,7 @@ backend** — asking is an action and belongs in the view's own FSM:
|
|
|
1388
1388
|
|
|
1389
1389
|
| | |
|
|
1390
1390
|
|---|---|
|
|
1391
|
-
| `yui_asset_id(ref)` / `yui_asset_ids(ref)` | the id(s) a column names.
|
|
1391
|
+
| `yui_asset_id(ref)` / `yui_asset_ids(ref)` | the id(s) a column names. A link comes back in whichever shape the READER asked for — the stored `"assets^<id>^as_foto"`, the bare `"<id>"` that `fkey_only_id` collapses it to, or an expanded `{id}` — and either alone or in a list, because an unset single-valued fkey is still an empty list. All of them are read; an empty column answers nothing rather than throwing |
|
|
1392
1392
|
| `yui_asset_src(answer)` | the two shapes into one `src`. `null` when the answer carries neither — never an empty string, because `<img src="">` reloads the page in some browsers |
|
|
1393
1393
|
| `yui_asset_element(answer, opts)` | the element, picked from the **content type the backend stored**: `<img>`, `<video>` or `<audio>`. Video and audio are assets too, and an `<img>` whose src is a film shows the broken box this exists to remove |
|
|
1394
1394
|
| `yui_asset_missing(detail, opts)` | the marker, for when there is nothing to show |
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -67047,8 +67047,9 @@ function register_c_yui_period() {
|
|
|
67047
67047
|
function ref_to_id(ref) {
|
|
67048
67048
|
if (!ref) return null;
|
|
67049
67049
|
if (typeof ref === "string") {
|
|
67050
|
+
if (ref.indexOf("^") < 0) return ref;
|
|
67050
67051
|
const parts = ref.split("^");
|
|
67051
|
-
return parts.length >= 2 ? parts[1] : null;
|
|
67052
|
+
return parts.length >= 2 && parts[1] ? parts[1] : null;
|
|
67052
67053
|
}
|
|
67053
67054
|
if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
|
|
67054
67055
|
return null;
|
|
@@ -67149,6 +67150,7 @@ function yui_asset_element(answer, opts = {}) {
|
|
|
67149
67150
|
}
|
|
67150
67151
|
el.src = src;
|
|
67151
67152
|
el.onerror = () => {
|
|
67153
|
+
(0, _yuneta_gobj_js.log_error)(`asset could not be loaded: ${opts.detail || src}`);
|
|
67152
67154
|
const $marker = yui_asset_missing(opts.detail, opts);
|
|
67153
67155
|
if (el.parentNode) el.parentNode.replaceChild($marker, el);
|
|
67154
67156
|
};
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -67042,8 +67042,9 @@ function register_c_yui_period() {
|
|
|
67042
67042
|
function ref_to_id(ref) {
|
|
67043
67043
|
if (!ref) return null;
|
|
67044
67044
|
if (typeof ref === "string") {
|
|
67045
|
+
if (ref.indexOf("^") < 0) return ref;
|
|
67045
67046
|
const parts = ref.split("^");
|
|
67046
|
-
return parts.length >= 2 ? parts[1] : null;
|
|
67047
|
+
return parts.length >= 2 && parts[1] ? parts[1] : null;
|
|
67047
67048
|
}
|
|
67048
67049
|
if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
|
|
67049
67050
|
return null;
|
|
@@ -67144,6 +67145,7 @@ function yui_asset_element(answer, opts = {}) {
|
|
|
67144
67145
|
}
|
|
67145
67146
|
el.src = src;
|
|
67146
67147
|
el.onerror = () => {
|
|
67148
|
+
log_error(`asset could not be loaded: ${opts.detail || src}`);
|
|
67147
67149
|
const $marker = yui_asset_missing(opts.detail, opts);
|
|
67148
67150
|
if (el.parentNode) el.parentNode.replaceChild($marker, el);
|
|
67149
67151
|
};
|
package/package.json
CHANGED
package/src/yui_asset.js
CHANGED
|
@@ -16,16 +16,28 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
createElement2
|
|
19
|
+
createElement2, log_error
|
|
20
20
|
} from "@yuneta/gobj-js";
|
|
21
21
|
|
|
22
22
|
import "./yui_asset.css";
|
|
23
23
|
|
|
24
24
|
/*
|
|
25
|
-
* A
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* A column that holds a link comes back in one of THREE shapes, and which
|
|
26
|
+
* one is the READER's choice, not the schema's:
|
|
27
|
+
*
|
|
28
|
+
* "assets^<id>^as_foto" the stored fkey, as it is persisted;
|
|
29
|
+
* "<id>" what `fkey_only_id` collapses it to, which is
|
|
30
|
+
* what a caller asks for when it wants clean ids;
|
|
31
|
+
* {id: "<id>", ...} an expanded ref, from the `refs` options.
|
|
32
|
+
*
|
|
33
|
+
* And a column holds either ONE of them (a single-valued fkey, like a
|
|
34
|
+
* device's photo) or a LIST (an array fkey, like the plans of a bay) --
|
|
35
|
+
* and an UNSET single-valued fkey still comes back as an empty list.
|
|
36
|
+
*
|
|
37
|
+
* Reading only the first shape was a real bug: against a backend that
|
|
38
|
+
* reads with `fkey_only_id` every link looked like no link at all. The
|
|
39
|
+
* `^` is what tells the two string shapes apart, and an id can never carry
|
|
40
|
+
* one -- that is why the qualified key uses `.` and not `^`.
|
|
29
41
|
*/
|
|
30
42
|
function ref_to_id(ref)
|
|
31
43
|
{
|
|
@@ -33,8 +45,11 @@ function ref_to_id(ref)
|
|
|
33
45
|
return null;
|
|
34
46
|
}
|
|
35
47
|
if(typeof ref === "string") {
|
|
48
|
+
if(ref.indexOf("^") < 0) {
|
|
49
|
+
return ref; // already only the id
|
|
50
|
+
}
|
|
36
51
|
const parts = ref.split("^");
|
|
37
|
-
return parts.length >= 2? parts[1]: null;
|
|
52
|
+
return parts.length >= 2 && parts[1]? parts[1]: null;
|
|
38
53
|
}
|
|
39
54
|
if(typeof ref === "object" && typeof ref.id === "string") {
|
|
40
55
|
return ref.id;
|
|
@@ -162,6 +177,16 @@ function yui_asset_element(answer, opts = {})
|
|
|
162
177
|
* silent gap this module was written to stop.
|
|
163
178
|
*/
|
|
164
179
|
el.onerror = () => {
|
|
180
|
+
/*
|
|
181
|
+
* And it is REPORTED, not only drawn. The marker tells the person
|
|
182
|
+
* looking at the screen; log_error is what reaches the yuno, which
|
|
183
|
+
* is the only place anybody can count how often it happens. An
|
|
184
|
+
* asset the backend served and the browser could not load is a
|
|
185
|
+
* fact of the system -- an expired signature, a blob gone from the
|
|
186
|
+
* store, a codec nobody has -- and a failure only a user can see
|
|
187
|
+
* is a failure nobody measures.
|
|
188
|
+
*/
|
|
189
|
+
log_error(`asset could not be loaded: ${opts.detail || src}`);
|
|
165
190
|
const $marker = yui_asset_missing(opts.detail, opts);
|
|
166
191
|
if(el.parentNode) {
|
|
167
192
|
el.parentNode.replaceChild($marker, el);
|
package/src/yui_asset.test.js
CHANGED
|
@@ -27,6 +27,26 @@ test("reads every id out of an array fkey, in order", () => {
|
|
|
27
27
|
expect(yui_asset_id(["assets^p1^as_plano", "assets^p2^as_plano"])).toBe("p1");
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
/*
|
|
31
|
+
* `fkey_only_id` is a normal way to read a node -- yunovatios reads every
|
|
32
|
+
* device that way -- and it collapses a link to the bare id. Reading only
|
|
33
|
+
* the `topic^id^hook` form made every such link look like no link at all.
|
|
34
|
+
*/
|
|
35
|
+
test("reads a link collapsed by fkey_only_id, list or bare", () => {
|
|
36
|
+
expect(yui_asset_id(["7b09b140"])).toBe("7b09b140");
|
|
37
|
+
expect(yui_asset_id("7b09b140")).toBe("7b09b140");
|
|
38
|
+
expect(yui_asset_ids(["p1", "p2"])).toEqual(["p1", "p2"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* An UNSET single-valued fkey comes back as an EMPTY LIST, not as an empty
|
|
43
|
+
* string: that is the shape of "this device has no photo".
|
|
44
|
+
*/
|
|
45
|
+
test("an unset single-valued fkey is an empty list", () => {
|
|
46
|
+
expect(yui_asset_id([])).toBe(null);
|
|
47
|
+
expect(yui_asset_ids([])).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
30
50
|
test("reads an EXPANDED ref, which is what the refs options give back", () => {
|
|
31
51
|
expect(yui_asset_id({id: "abc123", content_type: "image/jpeg"})).toBe("abc123");
|
|
32
52
|
});
|
|
@@ -41,9 +61,8 @@ test("an empty or malformed column yields nothing, and does not throw", () => {
|
|
|
41
61
|
expect(yui_asset_ids("")).toEqual([]);
|
|
42
62
|
expect(yui_asset_ids([])).toEqual([]);
|
|
43
63
|
expect(yui_asset_id(null)).toBe(null);
|
|
44
|
-
expect(yui_asset_id("not-an-fkey")).toBe(null);
|
|
45
64
|
expect(yui_asset_id({})).toBe(null);
|
|
46
|
-
expect(yui_asset_ids(["assets^ok^as_foto", "
|
|
65
|
+
expect(yui_asset_ids(["assets^ok^as_foto", null, ""])).toEqual(["ok"]);
|
|
47
66
|
});
|
|
48
67
|
|
|
49
68
|
/*
|