cleaning up no longer needed ui helper methods
This commit is contained in:
@@ -24,9 +24,8 @@
|
||||
newKeyOfSelected = CommonHelper.toArray(newKeyOfSelected, true);
|
||||
|
||||
let newSelected = [];
|
||||
let allItems = getFlattenItems();
|
||||
|
||||
for (let item of allItems) {
|
||||
for (let item of items) {
|
||||
if (CommonHelper.inArray(newKeyOfSelected, item[selectionKey])) {
|
||||
newSelected.push(item);
|
||||
}
|
||||
@@ -48,20 +47,6 @@
|
||||
|
||||
keyOfSelected = multiple ? extractedKeys : extractedKeys[0];
|
||||
}
|
||||
|
||||
function getFlattenItems() {
|
||||
if (!CommonHelper.isObjectArrayWithKeys(items, ["group", "items"])) {
|
||||
return items; // already flatten
|
||||
}
|
||||
|
||||
// extract items from groups
|
||||
let result = [];
|
||||
for (const group of items) {
|
||||
result = result.concat(group.items);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Select bind:selected {items} {multiple} {labelComponent} {optionComponent} on:show on:hide {...$$restProps}>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script>
|
||||
import CommonHelper from "@/utils/CommonHelper";
|
||||
import OverlayPanel from "@/components/base/OverlayPanel.svelte";
|
||||
|
||||
let panel;
|
||||
@@ -10,15 +9,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
CommonHelper.checkImageUrl(newUrl)
|
||||
.then(() => {
|
||||
url = newUrl;
|
||||
panel?.show();
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn("Invalid image preview url: ", newUrl);
|
||||
hide();
|
||||
});
|
||||
url = newUrl;
|
||||
|
||||
panel?.show();
|
||||
}
|
||||
|
||||
export function hide() {
|
||||
@@ -33,11 +26,11 @@
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
|
||||
<img src={url} alt="Preview" />
|
||||
<img src={url} alt="Preview {url}" />
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<a href={url} title="Download" class="link-hint txt-ellipsis">
|
||||
/../{url.substring(url.lastIndexOf("/") + 1)}
|
||||
{url.substring(url.lastIndexOf("/") + 1)}
|
||||
</a>
|
||||
<div class="flex-fill" />
|
||||
<button type="button" class="btn btn-secondary" on:click={hide}>Close</button>
|
||||
|
||||
@@ -87,33 +87,6 @@ export default class CommonHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether `arr` is an object array where the first element has `keys`.
|
||||
* NB! Empty arrays are considered thruethfull.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @param {String|Array} keys
|
||||
* @return {Boolean}
|
||||
*/
|
||||
static isObjectArrayWithKeys(arr, keys) {
|
||||
if (!Array.isArray(arr) || typeof arr[0] !== "object") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arr.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let normalizedKeys = CommonHelper.toArray(keys);
|
||||
for (let key of normalizedKeys) {
|
||||
if (!(key in arr[0])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes and returns arr as a valid array instance (if not already).
|
||||
*
|
||||
@@ -627,37 +600,6 @@ export default class CommonHelper {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens url address within a new popup window.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Number} [width] Popup window width (Default: 600).
|
||||
* @param {Number} [height] Popup window height (Default: 480).
|
||||
* @param {String} [name] The name of the created popup window (default to "popup").
|
||||
* @return {Object} Reference to the newly created window.
|
||||
*/
|
||||
static openInWindow(url, width, height, name) {
|
||||
width = width || 1024;
|
||||
height = height || 768;
|
||||
name = name || "popup";
|
||||
|
||||
let windowWidth = window.innerWidth;
|
||||
let windowHeight = window.innerHeight;
|
||||
|
||||
// normalize window size
|
||||
width = width > windowWidth ? windowWidth : width;
|
||||
height = height > windowHeight ? windowHeight : height;
|
||||
|
||||
let left = (windowWidth / 2) - (width / 2);
|
||||
let top = (windowHeight / 2) - (height / 2);
|
||||
|
||||
return window.open(
|
||||
url,
|
||||
name,
|
||||
"width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",resizable,menubar=no"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string (without "?") for the provided url.
|
||||
*
|
||||
@@ -792,25 +734,6 @@ export default class CommonHelper {
|
||||
return /\.jpg|\.jpeg|\.png|\.svg|\.gif|\.webp|\.avif$/.test(filename)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the image url can be loaded.
|
||||
*
|
||||
* @param {String} url
|
||||
* @return {Promise}
|
||||
*/
|
||||
static checkImageUrl(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = function() {
|
||||
return resolve(true);
|
||||
}
|
||||
image.onerror = function(err) {
|
||||
return reject(err);
|
||||
}
|
||||
image.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a thumbnail from `File` with the specified `width` and `height` params.
|
||||
* Returns a `Promise` with the generated base64 url.
|
||||
|
||||
Reference in New Issue
Block a user