import { observer } from "mobx-react"; import { HtmlField } from "../../../new_fields/HtmlField"; import { WebField } from "../../../new_fields/URLField"; import { DocumentDecorations } from "../DocumentDecorations"; import { InkingControl } from "../InkingControl"; import { FieldView, FieldViewProps } from './FieldView'; import "./WebBox.scss"; import React = require("react"); import { InkTool } from "../../../new_fields/InkField"; import { Cast, FieldValue, NumCast, StrCast } from "../../../new_fields/Types"; import { Utils } from "../../../Utils"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { observable, action, computed } from "mobx"; import { listSpec } from "../../../new_fields/Schema"; import { Field, FieldResult } from "../../../new_fields/Doc"; import { RefField } from "../../../new_fields/RefField"; import { ObjectField } from "../../../new_fields/ObjectField"; import { updateSourceFile } from "typescript"; import { KeyValueBox } from "./KeyValueBox"; @observer export class WebBox extends React.Component { public static LayoutString() { return FieldView.LayoutString(WebBox); } @observable private collapsed: boolean = true; @observable private url: string = ""; componentWillMount() { let field = Cast(this.props.Document[this.props.fieldKey], WebField); if (field && field.url.href.indexOf("youtube") !== -1) { let youtubeaspect = 400 / 315; var nativeWidth = NumCast(this.props.Document.nativeWidth, 0); var nativeHeight = NumCast(this.props.Document.nativeHeight, 0); if (!nativeWidth || !nativeHeight || Math.abs(nativeWidth / nativeHeight - youtubeaspect) > 0.05) { if (!nativeWidth) this.props.Document.nativeWidth = 600; this.props.Document.nativeHeight = NumCast(this.props.Document.nativeWidth) / youtubeaspect; this.props.Document.height = NumCast(this.props.Document.width) / youtubeaspect; } } } @action onURLChange = (e: React.ChangeEvent) => { this.url = e.target.value; } @action submitURL = () => { const script = KeyValueBox.CompileKVPScript(`new WebField("${this.url}")`); if (!script) return; KeyValueBox.ApplyKVPScript(this.props.Document, "data", script); let mod = document.getElementById("webpage-input"); if (mod) mod.style.display = "none"; } @computed get getURL() { let urlField: FieldResult = Cast(this.props.Document.data, WebField) if (urlField) return urlField.url.toString(); return ""; } onValueKeyDown = async (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.stopPropagation(); this.submitURL(); } } urlEditor() { return (
); } @action toggleCollapse = () => { // this.props.CollectionView.props.Document.chromeStatus = this.props.CollectionView.props.Document.chromeStatus === "enabled" ? "this.collapsed" : "enabled"; // if (this.props.collapse) { // this.props.collapse(this.props.CollectionView.props.Document.chromeStatus !== "enabled"); // } this.collapsed = !this.collapsed; } _ignore = 0; onPreWheel = (e: React.WheelEvent) => { this._ignore = e.timeStamp; } onPrePointer = (e: React.PointerEvent) => { this._ignore = e.timeStamp; } onPostPointer = (e: React.PointerEvent) => { if (this._ignore !== e.timeStamp) { e.stopPropagation(); } } onPostWheel = (e: React.WheelEvent) => { if (this._ignore !== e.timeStamp) { e.stopPropagation(); } } render() { let field = this.props.Document[this.props.fieldKey]; let view; if (field instanceof HtmlField) { view = ; } else if (field instanceof WebField) { view =