Visual Console Client: WIP work on the line item
Former-commit-id: 0f40636ebd9d01ccdf618579e5e7c25be015ad04
This commit is contained in:
parent
c0f8c289e6
commit
1eaf187215
|
@ -45,16 +45,6 @@ export interface ItemProps extends Position, Size {
|
|||
aclGroupId: number | null;
|
||||
}
|
||||
|
||||
interface VisualConsoleLineItemProps {
|
||||
readonly id: number;
|
||||
readonly type: 13;
|
||||
isOnTop: boolean;
|
||||
startPosition: Position;
|
||||
endPosition: Position;
|
||||
borderWidth: string;
|
||||
borderColor: string;
|
||||
}
|
||||
|
||||
// FIXME: Fix type compatibility.
|
||||
export interface ItemClickEvent<Props extends ItemProps> {
|
||||
// data: Props;
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import { UnknownObject, Position } from "../types";
|
||||
import { parseIntOr, notEmptyStringOr } from "../lib";
|
||||
import Item, { ItemType, ItemProps, itemBasePropsDecoder } from "../Item";
|
||||
|
||||
interface LineProps extends ItemProps {
|
||||
// Overrided properties.
|
||||
readonly type: ItemType.LINE_ITEM;
|
||||
label: null;
|
||||
isLinkEnabled: false;
|
||||
parentId: null;
|
||||
aclGroupId: null;
|
||||
// Clear Position & Size.
|
||||
x: 0;
|
||||
y: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
// Custom properties.
|
||||
startPosition: Position;
|
||||
endPosition: Position;
|
||||
lineWidth: number;
|
||||
color: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a valid typed object from a raw object.
|
||||
* This will allow us to ensure the type safety.
|
||||
*
|
||||
* @param data Raw object.
|
||||
* @return An object representing the item props.
|
||||
* @throws Will throw a TypeError if some property
|
||||
* is missing from the raw object or have an invalid type.
|
||||
*/
|
||||
export function linePropsDecoder(data: UnknownObject): LineProps | never {
|
||||
return {
|
||||
...itemBasePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||
type: ItemType.LINE_ITEM,
|
||||
label: null,
|
||||
isLinkEnabled: false,
|
||||
parentId: null,
|
||||
aclGroupId: null,
|
||||
// Clear Position & Size.
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
// Custom properties.
|
||||
startPosition: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
endPosition: {
|
||||
x: 0,
|
||||
y: 0
|
||||
},
|
||||
lineWidth: parseIntOr(data.lineWidth, 0),
|
||||
color: notEmptyStringOr(data.color, null)
|
||||
};
|
||||
}
|
||||
|
||||
export default class Line extends Item<LineProps> {
|
||||
public createDomElement(): HTMLElement {
|
||||
const line: HTMLDivElement = document.createElement("div");
|
||||
line.className = "line";
|
||||
|
||||
return line;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue