From e262d9ac73af5b2cef384468c47d69917e205d44 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Tue, 7 Apr 2020 23:01:46 -0400 Subject: lots of code cleanup - removed all northstar db stuff. added scriptingBox. renamed things. made collectiontypes strings not numbers. --- src/client/documents/DocumentTypes.ts | 61 +++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'src/client/documents/DocumentTypes.ts') diff --git a/src/client/documents/DocumentTypes.ts b/src/client/documents/DocumentTypes.ts index b6a6cc75a..ab32d7301 100644 --- a/src/client/documents/DocumentTypes.ts +++ b/src/client/documents/DocumentTypes.ts @@ -1,31 +1,36 @@ export enum DocumentType { NONE = "none", - TEXT = "text", - HIST = "histogram", - IMG = "image", - WEB = "web", - COL = "collection", - KVP = "kvp", - VID = "video", - AUDIO = "audio", - PDF = "pdf", - IMPORT = "import", - LINK = "link", - LINKDB = "linkdb", - BUTTON = "button", - SLIDER = "slider", - YOUTUBE = "youtube", - WEBCAM = "webcam", - FONTICON = "fonticonbox", - PRES = "presentation", - RECOMMENDATION = "recommendation", - LINKFOLLOW = "linkfollow", - PRESELEMENT = "preselement", - QUERY = "query", - COLOR = "color", - DOCULINK = "doculink", - PDFANNO = "pdfanno", - INK = "ink", - DOCUMENT = "document", - SCREENSHOT = "screenshot", + + // core data types + RTF = "rtf", // rich text + IMG = "image", // image box + WEB = "web", // web page or html clipping + COL = "collection", // collection + KVP = "kvp", // key value pane + VID = "video", // video + AUDIO = "audio", // audio + PDF = "pdf", // pdf + INK = "ink", // ink stroke + SCREENSHOT = "screenshot", // view of a desktop application + FONTICON = "fonticonbox", // font icon + QUERY = "query", // search query + LABEL = "label", // simple text label + WEBCAM = "webcam", // webcam + PDFANNO = "pdfanno", // pdf text selection (could be just a collection?) + DATE = "date", // calendar view of a date + SCRIPTING = "script", // script editor + + // special purpose wrappers that either take no data or are compositions of lower level types + LINK = "link", // link (view of a document that acts as a link) + LINKANCHOR = "linkanchor", // blue dot link anchor (view of a link document's anchor) + IMPORT = "import", // directory import box (file system directory) + SLIDER = "slider", // number slider (view of a number) + PRES = "presentation", // presentation (view of a collection) --- shouldn't this be a view type? technically requires a special view in which documents must have their aliasOf fields filled in + PRESELEMENT = "preselement",// presentation item (view of a document in a collection) + COLOR = "color", // color picker (view of a color picker for a color string) + YOUTUBE = "youtube", // youtube directory (view of you tube search results) + DOCHOLDER = "docholder", // nested document (view of a document) + + LINKDB = "linkdb", // database of links ??? why do we have this + RECOMMENDATION = "recommendation", // view of a recommendation } \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 929512da59d8678ac37c7ac9d0f6c2c9fa968d50 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Fri, 10 Apr 2020 14:08:22 -0400 Subject: rearranged button/script field keys to -rawscript, - --- src/client/documents/DocumentTypes.ts | 1 + src/client/documents/Documents.ts | 7 +++++-- src/client/util/DragManager.ts | 4 ++-- src/client/views/ScriptBox.tsx | 5 +++-- src/client/views/nodes/DocumentView.tsx | 4 ++-- src/client/views/nodes/LabelBox.tsx | 23 +++++++++++------------ src/client/views/nodes/ScriptingBox.tsx | 7 ++++--- 7 files changed, 28 insertions(+), 23 deletions(-) (limited to 'src/client/documents/DocumentTypes.ts') diff --git a/src/client/documents/DocumentTypes.ts b/src/client/documents/DocumentTypes.ts index ab32d7301..de366763b 100644 --- a/src/client/documents/DocumentTypes.ts +++ b/src/client/documents/DocumentTypes.ts @@ -15,6 +15,7 @@ export enum DocumentType { FONTICON = "fonticonbox", // font icon QUERY = "query", // search query LABEL = "label", // simple text label + BUTTON = "button", // onClick button WEBCAM = "webcam", // webcam PDFANNO = "pdfanno", // pdf text selection (could be just a collection?) DATE = "date", // calendar view of a date diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 22f22cbfd..b5c6dc06a 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -116,6 +116,7 @@ export interface DocumentOptions { borderRounding?: string; boxShadow?: string; dontRegisterChildren?: boolean; + "onClick-rawScript"?:string; // onClick script in raw text form _pivotField?: string; // field key used to determine headings for sections in stacking, masonry, pivot views schemaColumns?: List; dockingConfig?: string; @@ -144,7 +145,6 @@ export interface DocumentOptions { treeViewChecked?: ScriptField; // script to call when a tree view checkbox is checked isFacetFilter?: boolean; // whether document functions as a facet filter in a tree view limitHeight?: number; // maximum height for newly created (eg, from pasting) text documents - editScriptOnClick?: string; // script field key to edit when document is clicked (e.g., "onClick", "onChecked") // [key: string]: Opt; pointerHack?: boolean; // for buttons, allows onClick handler to fire onPointerDown textTransform?: string; // is linear view expanded @@ -247,6 +247,9 @@ export namespace Docs { [DocumentType.LABEL, { layout: { view: LabelBox, dataField: data }, }], + [DocumentType.BUTTON, { + layout: { view: LabelBox, dataField: "onClick" }, + }], [DocumentType.SLIDER, { layout: { view: SliderBox, dataField: data }, }], @@ -654,7 +657,7 @@ export namespace Docs { } export function ButtonDocument(options?: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.LABEL), undefined, { ...(options || {}), editScriptOnClick: "onClick" }); + return InstanceFromProto(Prototypes.get(DocumentType.BUTTON), undefined, { ...(options || {}), "onClick-rawScript": "-script-" }); } export function SliderDocument(options?: DocumentOptions) { diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts index 346eb2fb4..b28bac125 100644 --- a/src/client/util/DragManager.ts +++ b/src/client/util/DragManager.ts @@ -220,9 +220,9 @@ export namespace DragManager { export function StartButtonDrag(eles: HTMLElement[], script: string, title: string, vars: { [name: string]: Field }, params: string[], initialize: (button: Doc) => void, downX: number, downY: number, options?: DragOptions) { const finishDrag = (e: DragCompleteEvent) => { const bd = Docs.Create.ButtonDocument({ _width: 150, _height: 50, title, onClick: ScriptField.MakeScript(script) }); - params.map(p => Object.keys(vars).indexOf(p) !== -1 && (Doc.GetProto(bd)[p] = new PrefetchProxy(vars[p] as Doc))); + params.map(p => Object.keys(vars).indexOf(p) !== -1 && (Doc.GetProto(bd)[p] = new PrefetchProxy(vars[p] as Doc))); // copy all "captured" arguments into document parameterfields initialize?.(bd); - bd["onclick-params"] = new List(params); + Doc.GetProto(bd)["onClick-paramFieldKeys"] = new List(params); e.docDragData && (e.docDragData.droppedDocuments = [bd]); }; StartDrag(eles, new DragManager.DocumentDragData([]), downX, downY, options, finishDrag); diff --git a/src/client/views/ScriptBox.tsx b/src/client/views/ScriptBox.tsx index 6735a8b54..153b81876 100644 --- a/src/client/views/ScriptBox.tsx +++ b/src/client/views/ScriptBox.tsx @@ -12,6 +12,7 @@ import { CompileScript } from "../util/Scripting"; import { ScriptField } from "../../new_fields/ScriptField"; import { DragManager } from "../util/DragManager"; import { EditableView } from "./EditableView"; +import { getEffectiveTypeRoots } from "typescript"; export interface ScriptBoxProps { onSave: (text: string, onError: (error: string) => void) => void; @@ -92,7 +93,7 @@ export class ScriptBox extends React.Component { const setParams = (p: string[]) => params.splice(0, params.length, ...p); const scriptingBox = { if (!text) { - doc[fieldKey] = undefined; + Doc.GetProto(doc)[fieldKey] = undefined; } else { const script = CompileScript(text, { params: { this: Doc.name, ...contextParams }, @@ -115,7 +116,7 @@ export class ScriptBox extends React.Component { div.innerHTML = "button"; params.length && DragManager.StartButtonDrag([div], text, doc.title + "-instance", {}, params, (button: Doc) => { }, clientX, clientY); - doc[fieldKey] = new ScriptField(script); + Doc.GetProto(doc)[fieldKey] = new ScriptField(script); overlayDisposer(); } }} showDocumentIcons />; diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 1e22dbc0b..7a47ad10a 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -305,8 +305,8 @@ export class DocumentView extends DocComponent(Docu if (this.props.Document !== Doc.UserDoc().undoBtn && this.props.Document !== Doc.UserDoc().redoBtn) { UndoManager.RunInBatch(func, "on click"); } else func(); - } else if (this.Document.editScriptOnClick) { - UndoManager.RunInBatch(() => ScriptBox.EditButtonScript("On Button Clicked ...", this.props.Document, StrCast(this.Document.editScriptOnClick), e.clientX, e.clientY), "on button click"); + } else if (this.Document["onClick-rawScript"]) { + UndoManager.RunInBatch(() => ScriptBox.EditButtonScript("On Button Clicked ...", this.props.Document, "onClick", e.clientX, e.clientY), "on button click"); } else if (this.Document.isLinkButton) { DocListCast(this.props.Document.links).length && this.followLinkClick(e.altKey, e.ctrlKey, e.shiftKey); } else { diff --git a/src/client/views/nodes/LabelBox.tsx b/src/client/views/nodes/LabelBox.tsx index b9701f923..9b063e2aa 100644 --- a/src/client/views/nodes/LabelBox.tsx +++ b/src/client/views/nodes/LabelBox.tsx @@ -1,21 +1,20 @@ import { library } from '@fortawesome/fontawesome-svg-core'; import { faEdit } from '@fortawesome/free-regular-svg-icons'; -import { action, computed } from 'mobx'; +import { action } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { Doc, DocListCast } from '../../../new_fields/Doc'; +import { documentSchema } from '../../../new_fields/documentSchemas'; import { List } from '../../../new_fields/List'; -import { createSchema, makeInterface, listSpec } from '../../../new_fields/Schema'; -import { ScriptField } from '../../../new_fields/ScriptField'; -import { BoolCast, StrCast, Cast, FieldValue, NumCast } from '../../../new_fields/Types'; +import { createSchema, listSpec, makeInterface } from '../../../new_fields/Schema'; +import { Cast, NumCast, StrCast } from '../../../new_fields/Types'; import { DragManager } from '../../util/DragManager'; import { undoBatch } from '../../util/UndoManager'; +import { ContextMenu } from '../ContextMenu'; +import { ContextMenuProps } from '../ContextMenuItem'; import { ViewBoxBaseComponent } from '../DocComponent'; -import './LabelBox.scss'; import { FieldView, FieldViewProps } from './FieldView'; -import { ContextMenuProps } from '../ContextMenuItem'; -import { ContextMenu } from '../ContextMenu'; -import { documentSchema } from '../../../new_fields/documentSchemas'; +import './LabelBox.scss'; library.add(faEdit as any); @@ -41,7 +40,7 @@ export class LabelBox extends ViewBoxBaseComponent { - const params = Cast(this.dataDoc[this.fieldKey + "-params"], listSpec("string"), []); + const params = Cast(this.dataDoc[this.fieldKey + "-paramFieldKeys"], listSpec("string"), []); params?.map(p => this.dataDoc[p] = undefined); }, icon: "trash" }); @@ -53,7 +52,7 @@ export class LabelBox extends ViewBoxBaseComponent { const docDragData = de.complete.docDragData; - const params = Cast(this.dataDoc[this.fieldKey + "-params"], listSpec("string"), []); + const params = Cast(this.dataDoc[this.fieldKey + "-paramFieldKeys"], listSpec("string"), []); const missingParams = params?.filter(p => this.dataDoc[p] === undefined); if (docDragData && missingParams?.includes((e.target as any).textContent)) { this.dataDoc[(e.target as any).textContent] = new List(docDragData.droppedDocuments.map((d, i) => @@ -63,7 +62,7 @@ export class LabelBox extends ViewBoxBaseComponent m + ":").join(" ") + ")") render() { - const params = Cast(this.dataDoc[this.fieldKey + "-params"], listSpec("string"), []); + const params = Cast(this.dataDoc[this.fieldKey + "-paramFieldKeys"], listSpec("string"), []); const missingParams = params?.filter(p => this.dataDoc[p] === undefined); params?.map(p => DocListCast(this.dataDoc[p])); // bcz: really hacky form of prefetching ... return ( @@ -80,7 +79,7 @@ export class LabelBox extends ViewBoxBaseComponent -
+
{!missingParams?.length ? (null) : missingParams.map(m =>
{m}
)}
diff --git a/src/client/views/nodes/ScriptingBox.tsx b/src/client/views/nodes/ScriptingBox.tsx index 70f29e1dc..8a1d270b3 100644 --- a/src/client/views/nodes/ScriptingBox.tsx +++ b/src/client/views/nodes/ScriptingBox.tsx @@ -28,9 +28,9 @@ export class ScriptingBox extends ViewBoxAnnotatableComponent e.messageText).join("\n") : ""; return this.dataDoc[this.props.fieldKey] = result.compiled ? new ScriptField(result) : undefined; -- cgit v1.2.3-70-g09d2