diff options
author | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-05-09 20:59:10 -0400 |
---|---|---|
committer | Sam Wilkins <abdullah_ahmed@brown.edu> | 2019-05-09 20:59:10 -0400 |
commit | 47ecf8d30f4aa5e25a659fc7f3c0c1487420150e (patch) | |
tree | cbae92b4aca6cc8427410cc2ec51b0afff1d8ea2 /src/new_fields/CursorField.ts | |
parent | ff5e275d4d9bb17866a432459884274cd870a640 (diff) |
merge with master, but haven't reconciled internal and external linking
Diffstat (limited to 'src/new_fields/CursorField.ts')
-rw-r--r-- | src/new_fields/CursorField.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/new_fields/CursorField.ts b/src/new_fields/CursorField.ts new file mode 100644 index 000000000..7fd326a5f --- /dev/null +++ b/src/new_fields/CursorField.ts @@ -0,0 +1,55 @@ +import { ObjectField, Copy, OnUpdate } from "./ObjectField"; +import { observable } from "mobx"; +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, createSimpleSchema, object } from "serializr"; + +export type CursorPosition = { + x: number, + y: number +} + +export type CursorMetadata = { + id: string, + identifier: string +} + +export type CursorData = { + metadata: CursorMetadata, + position: CursorPosition +} + +const PositionSchema = createSimpleSchema({ + x: true, + y: true +}); + +const MetadataSchema = createSimpleSchema({ + id: true, + identifier: true +}); + +const CursorSchema = createSimpleSchema({ + metadata: object(MetadataSchema), + position: object(PositionSchema) +}); + +@Deserializable("cursor") +export default class CursorField extends ObjectField { + + @serializable(object(CursorSchema)) + readonly data: CursorData; + + constructor(data: CursorData) { + super(); + this.data = data; + } + + setPosition(position: CursorPosition) { + this.data.position = position; + this[OnUpdate](); + } + + [Copy]() { + return new CursorField(this.data); + } +}
\ No newline at end of file |