2020-04-05 06:34:14 +00:00
|
|
|
import { GridDefaults } from "constants/WidgetConstants";
|
2019-09-25 17:24:23 +00:00
|
|
|
export const snapToGrid = (
|
|
|
|
|
columnWidth: number,
|
|
|
|
|
rowHeight: number,
|
|
|
|
|
x: number,
|
|
|
|
|
y: number,
|
|
|
|
|
) => {
|
2020-01-16 11:46:21 +00:00
|
|
|
const snappedX = Math.round(x / columnWidth);
|
|
|
|
|
const snappedY = Math.round(y / rowHeight);
|
2019-09-19 22:25:37 +00:00
|
|
|
return [snappedX, snappedY];
|
|
|
|
|
};
|
2019-10-29 12:02:58 +00:00
|
|
|
|
|
|
|
|
export const formatBytes = (bytes: string | number) => {
|
|
|
|
|
if (!bytes) return;
|
|
|
|
|
const value = typeof bytes === "string" ? parseInt(bytes) : bytes;
|
|
|
|
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
|
|
|
if (value === 0) return "0 bytes";
|
|
|
|
|
const i = parseInt(String(Math.floor(Math.log(value) / Math.log(1024))));
|
|
|
|
|
if (i === 0) return bytes + " " + sizes[i];
|
|
|
|
|
return (value / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
|
|
|
|
|
};
|
2019-11-13 07:00:25 +00:00
|
|
|
|
|
|
|
|
export const getAbsolutePixels = (size?: string | null) => {
|
|
|
|
|
if (!size) return 0;
|
|
|
|
|
const _dex = size.indexOf("px");
|
|
|
|
|
if (_dex === -1) return 0;
|
|
|
|
|
return parseInt(size.slice(0, _dex), 10);
|
|
|
|
|
};
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
export const Directions: { [id: string]: string } = {
|
|
|
|
|
UP: "up",
|
|
|
|
|
DOWN: "down",
|
|
|
|
|
LEFT: "left",
|
|
|
|
|
RIGHT: "right",
|
2020-06-02 11:48:54 +00:00
|
|
|
RIGHT_BOTTOM: "RIGHT_BOTTOM",
|
2019-12-23 12:16:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type Direction = typeof Directions[keyof typeof Directions];
|
2020-03-27 09:02:11 +00:00
|
|
|
const SCROLL_THESHOLD = 10;
|
|
|
|
|
|
|
|
|
|
export const getScrollByPixels = function(
|
|
|
|
|
elem: Element,
|
|
|
|
|
scrollParent: Element,
|
|
|
|
|
): number {
|
|
|
|
|
const bounding = elem.getBoundingClientRect();
|
|
|
|
|
const scrollParentBounds = scrollParent.getBoundingClientRect();
|
2020-04-05 06:34:14 +00:00
|
|
|
const scrollAmount =
|
|
|
|
|
GridDefaults.CANVAS_EXTENSION_OFFSET * GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
bounding.top > 0 &&
|
|
|
|
|
bounding.top - scrollParentBounds.top < SCROLL_THESHOLD
|
|
|
|
|
)
|
|
|
|
|
return -scrollAmount;
|
2020-03-27 09:02:11 +00:00
|
|
|
if (scrollParentBounds.bottom - bounding.bottom < SCROLL_THESHOLD)
|
2020-04-05 06:34:14 +00:00
|
|
|
return scrollAmount;
|
2020-03-27 09:02:11 +00:00
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const scrollElementIntoParentCanvasView = (
|
|
|
|
|
el: Element | null,
|
|
|
|
|
parent: Element | null,
|
|
|
|
|
) => {
|
|
|
|
|
if (el) {
|
|
|
|
|
const scrollParent = parent;
|
|
|
|
|
if (scrollParent) {
|
|
|
|
|
const scrollBy: number = getScrollByPixels(el, scrollParent);
|
|
|
|
|
if (scrollBy < 0 && scrollParent.scrollTop > 0) {
|
|
|
|
|
scrollParent.scrollBy({ top: scrollBy, behavior: "smooth" });
|
|
|
|
|
}
|
|
|
|
|
if (scrollBy > 0) {
|
|
|
|
|
scrollParent.scrollBy({ top: scrollBy, behavior: "smooth" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-06-18 07:46:53 +00:00
|
|
|
|
2020-08-27 10:35:15 +00:00
|
|
|
export const removeSpecialChars = (value: string, limit?: number) => {
|
2020-06-18 07:46:53 +00:00
|
|
|
const separatorRegex = /\W+/;
|
|
|
|
|
return value
|
|
|
|
|
.split(separatorRegex)
|
|
|
|
|
.join("_")
|
|
|
|
|
.slice(0, limit || 30);
|
|
|
|
|
};
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
|
|
|
|
|
export const flashElement = (el: HTMLElement) => {
|
|
|
|
|
el.style.backgroundColor = "#FFCB33";
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
el.style.backgroundColor = "transparent";
|
|
|
|
|
}, 1000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const flashElementById = (id: string) => {
|
|
|
|
|
const el = document.getElementById(id);
|
|
|
|
|
el?.scrollIntoView({
|
|
|
|
|
behavior: "smooth",
|
|
|
|
|
block: "center",
|
|
|
|
|
inline: "center",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (el) flashElement(el);
|
|
|
|
|
};
|
2020-08-27 10:35:15 +00:00
|
|
|
|
|
|
|
|
export const resolveAsSpaceChar = (value: string, limit?: number) => {
|
|
|
|
|
const separatorRegex = /[\W_]+/;
|
|
|
|
|
return value
|
|
|
|
|
.split(separatorRegex)
|
|
|
|
|
.join(" ")
|
|
|
|
|
.slice(0, limit || 30);
|
|
|
|
|
};
|
2020-09-16 10:28:01 +00:00
|
|
|
|
|
|
|
|
export const isMac = () => {
|
|
|
|
|
const platform =
|
|
|
|
|
typeof navigator !== "undefined" ? navigator.platform : undefined;
|
|
|
|
|
return !platform ? false : /Mac|iPod|iPhone|iPad/.test(platform);
|
|
|
|
|
};
|