aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/EditableView.tsx21
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx2
-rw-r--r--src/client/views/collections/collectionSchema/SchemaCellField.tsx4
-rw-r--r--src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx77
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx1713
-rw-r--r--src/client/views/nodes/ImageBox.tsx18
6 files changed, 912 insertions, 923 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx
index 41079045b..898a98c98 100644
--- a/src/client/views/EditableView.tsx
+++ b/src/client/views/EditableView.tsx
@@ -53,7 +53,8 @@ export interface EditableProps {
placeholder?: string;
wrap?: string; // nowrap, pre-wrap, etc
- schemaFieldType?: SchemaFieldType;
+ inputString?: boolean;
+ inputStringPlaceholder?: string;
prohibitedText?: Array<string>;
onClick?: () => void;
updateAlt?: (newAlt: string) => void;
@@ -288,16 +289,14 @@ export class EditableView extends ObservableReactComponent<EditableProps> {
staticDisplay = () => {
let toDisplay;
const gval = this._props.GetValue()?.replace(/\n/g, '\\r\\n');
- if (this._props.schemaFieldType === SchemaFieldType.Header) {
- toDisplay = (
- <input
- className="editableView-input"
- value={gval}
- placeholder="Add key"
- readOnly
- style={{ display: this._props.display, overflow: 'auto', pointerEvents: 'none', fontSize: this._props.fontSize, width: '100%', margin: 0, background: this._props.background }}
- />
- );
+ if (this._props.inputString){
+ toDisplay = <input className="editableView-input"
+ value={gval}
+ placeholder={this._props.inputStringPlaceholder}
+ readOnly
+ style={{ display: this._props.display, overflow: 'auto', pointerEvents: 'none', fontSize: this._props.fontSize, width: '100%', margin: 0, background: this._props.background}}
+ // eslint-disable-next-line jsx-a11y/no-autofocus
+ />
} else {
toDisplay = (
<span
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 0cc63d632..d2bc8f2c2 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1221,7 +1221,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection
* Function that creates a drawing--a group of ink strokes--to go with the smart draw function.
*/
@undoBatch
- createDrawingDoc = (strokeData: [InkData, string, string][], opts: DrawingOptions, gptRes: string) => {
+ createDrawingDoc = (strokeData: [InkData, string, string][], opts: DrawingOptions) => {
this._drawing = [];
const xf = this.screenToFreeformContentsXf;
strokeData.forEach((stroke: [InkData, string, string]) => {
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
index 3924ed087..5a64ecc62 100644
--- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
@@ -5,7 +5,7 @@ import { OverlayView } from '../../OverlayView';
import { DocumentIconContainer } from '../../nodes/DocumentIcon';
import React, { FormEvent } from 'react';
import { FieldView, FieldViewProps } from '../../nodes/FieldView';
-import { ObjectField } from '../../../../fields/ObjectField';
+import { FieldType, ObjectField } from '../../../../fields/ObjectField';
import { Doc } from '../../../../fields/Doc';
import { DocumentView } from '../../nodes/DocumentView';
import DOMPurify from 'dompurify';
@@ -21,7 +21,7 @@ import DOMPurify from 'dompurify';
*/
export interface SchemaCellFieldProps {
- contents: any;
+ contents: FieldType;
fieldContents?: FieldViewProps;
editing?: boolean;
oneLine?: boolean;
diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
index 47918f9c1..9ffdd812f 100644
--- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
@@ -122,52 +122,45 @@ export class SchemaColumnHeader extends ObservableReactComponent<SchemaColumnHea
@computed get editableView() {
const { color, fieldProps, pointerEvents } = this.renderProps(this._props);
- return (
- <div
- className="schema-column-edit-wrapper"
- onPointerUp={() => {
- SchemaColumnHeader.isDefaultField(this.fieldKey) && this.openKeyDropdown();
- this._props.schemaView.deselectAllCells();
+ return <div className='schema-column-edit-wrapper' onPointerUp={() => {
+ SchemaColumnHeader.isDefaultField(this.fieldKey) && this.openKeyDropdown();
+ this._props.schemaView.deselectAllCells();
+ }}
+ style={{
+ color,
+ width: '100%',
+ pointerEvents,
+ }}>
+ <EditableView
+ ref={r => {this._inputRef = r; this._props.autoFocus && r?.setIsFocused(true)}}
+ oneLine={true}
+ allowCRs={false}
+ contents={''}
+ onClick={this.openKeyDropdown}
+ fieldContents={fieldProps}
+ editing={undefined}
+ placeholder={'Add key'}
+ updateAlt={this.updateAlt} // alternate title to display
+ updateSearch={this.updateKeyDropdown}
+ inputString={true}
+ inputStringPlaceholder={'Add key'}
+ GetValue={() => {
+ if (SchemaColumnHeader.isDefaultField(this.fieldKey)) return '';
+ else if (this._altTitle) return this._altTitle;
+ else return this.fieldKey;
}}
- style={{
- color,
- width: '100%',
- pointerEvents,
- }}>
- <EditableView
- ref={r => {
- this._inputRef = r;
- this._props.autoFocus && r?.setIsFocused(true);
- }}
- oneLine={true}
- allowCRs={false}
- contents={''}
- onClick={this.openKeyDropdown}
- fieldContents={fieldProps}
- editing={undefined}
- placeholder={'Add key'}
- updateAlt={this.updateAlt} // alternate title to display
- updateSearch={this.updateKeyDropdown}
- schemaFieldType={SchemaFieldType.Header}
- GetValue={() => {
- if (SchemaColumnHeader.isDefaultField(this.fieldKey)) return '';
- else if (this._altTitle) return this._altTitle;
- else return this.fieldKey;
- }}
- SetValue={undoable((value: string, shiftKey?: boolean, enterKey?: boolean) => {
- if (enterKey) {
- // if shift & enter, set value of each cell in column
- this.setColumnValues(value, '');
- this._altTitle = undefined;
- this._props.finishEdit?.();
- return true;
- }
+ SetValue={undoable((value: string, shiftKey?: boolean, enterKey?: boolean) => {
+ if (enterKey) {
+ // if shift & enter, set value of each cell in column
+ this.setColumnValues(value, '');
+ this._altTitle = undefined;
this._props.finishEdit?.();
return true;
- }, 'edit column header')}
- />
+ }
+ this._props.finishEdit?.();
+ return true;
+ }, 'edit column header')}/>
</div>
- );
}
public static isDefaultField = (key: string) => {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
index 05bedfcdc..6c649bde3 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
@@ -37,782 +37,9 @@ export enum LayoutType {
Column = 'column',
Custom = 'custom',
}
-export interface DataVizTemplateInfo {
- doc: Doc;
- layout: { type: LayoutType; xMargin: number; yMargin: number; repeat: number };
- columns: number;
- referencePos: { x: number; y: number };
-}
-
-export interface DataVizTemplateLayout {
- template: Doc;
- docsNumList: number[];
- layout: { type: LayoutType; xMargin: number; yMargin: number; repeat: number };
- columns: number;
- rows: number;
-}
-
-export enum TemplateFieldType {
- TEXT = 'text',
- VISUAL = 'visual',
- UNSET = 'unset',
-}
-
-export enum TemplateFieldSize {
- TINY = 'tiny',
- SMALL = 'small',
- MEDIUM = 'medium',
- LARGE = 'large',
- HUGE = 'huge',
-}
-
-export type Col = {
- sizes: TemplateFieldSize[];
- desc: string;
- title: string;
- type: TemplateFieldType;
- defaultContent?: string;
-};
-export interface FieldOpts {
- backgroundColor?: string;
- color?: string;
- cornerRounding?: number;
- borderWidth?: string;
- borderColor?: string;
- contentXCentering?: 'h-left' | 'h-center' | 'h-right';
- contentYCentering?: 'top' | 'center' | 'bottom';
- opacity?: number;
- rotation?: number;
- //animation?: boolean;
- fontBold?: boolean;
- fontTransform?: 'uppercase' | 'lowercase';
- fieldViewType?: 'freeform' | 'stacked';
-}
-
-type Field = {
- tl: [number, number];
- br: [number, number];
- opts: FieldOpts;
- subfields?: Field[];
- types?: TemplateFieldType[];
- sizes?: TemplateFieldSize[];
- isDecoration?: boolean;
- description?: string;
-};
-
-// class ContentField implements Field {
-// tl: [number, number];
-// br: [number, number];
-// opts: FieldOpts;
-// subfields?: Field[];
-// types?: TemplateFieldType[];
-// sizes?: TemplateFieldSize[];
-// description?: string;
-
-// constructor( tl: [number, number], br: [number, number],
-// opts: FieldOpts, subfields?: Field[],
-// types?: TemplateFieldType[],
-// sizes?: TemplateFieldSize[],
-// description?: string) {
-// this.tl = tl;
-// this.br = br;
-// this.opts = opts;
-// this.subfields = subfields;
-// this.types = types;
-// this.sizes = sizes;
-// this.description = description;
-// }
-
-// render = (content: any): Doc => {
-// return new Doc;
-// }
-// }
-
-type DecorationField = Field;
-
-type InkDecoration = {};
-
-type TemplateDecorations = Field | InkDecoration;
-
-interface TemplateOpts extends FieldOpts {}
-
-export interface TemplateDocInfos {
- title: string;
- height: number;
- width: number;
- opts: TemplateOpts;
- fields: Field[];
- decorations: Field[];
-}
-
-export class TemplateLayouts {
- public static get allTemplates(): TemplateDocInfos[] {
- return Object.values(TemplateLayouts).filter(value => typeof value === 'object' && value !== null && 'title' in value) as TemplateDocInfos[];
- }
-
- public static getTemplateByTitle = (title: string): TemplateDocInfos | undefined => {
- switch (title) {
- case 'fourfield1':
- return TemplateLayouts.FourField001;
- case 'fourfield2':
- return TemplateLayouts.FourField002;
- // case 'fourfield3':
- // return TemplateLayouts.FourField003;
- case 'fourfield4':
- return TemplateLayouts.FourField004;
- case 'threefield1':
- return TemplateLayouts.ThreeField001;
- case 'threefield2':
- return TemplateLayouts.ThreeField002;
- default:
- break;
- }
-
- return undefined;
- };
-
- public static FourField001: TemplateDocInfos = {
- title: 'fourfield1',
- width: 416,
- height: 700,
- opts: {
- backgroundColor: '#C0B887',
- cornerRounding: 20,
- borderColor: '#6B461F',
- borderWidth: '12',
- },
- fields: [
- {
- tl: [-0.95, -1],
- br: [0.95, -0.85],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY],
- description: 'A title field for very short text that contextualizes the content.',
- opts: {
- backgroundColor: 'transparent',
- color: '#F1F0E9',
- contentXCentering: 'h-center',
- fontBold: true,
- },
- },
- {
- tl: [-0.87, -0.83],
- br: [0.87, 0.2],
- types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'The main focus of the template; could be an image, long text, etc.',
- opts: {
- cornerRounding: 20,
- borderColor: '#8F5B25',
- borderWidth: '6',
- backgroundColor: '#CECAB9',
- },
- },
- {
- tl: [-0.8, 0.2],
- br: [0.8, 0.3],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- description: 'A caption for field #2, very short to short text that contextualizes the content of field #2',
- opts: {
- backgroundColor: 'transparent',
- contentXCentering: 'h-center',
- color: '#F1F0E9',
- },
- },
- {
- tl: [-0.87, 0.37],
- br: [0.87, 0.96],
- types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'A medium-sized field for medium/long text.',
- opts: {
- cornerRounding: 15,
- borderColor: '#8F5B25',
- borderWidth: '6',
- backgroundColor: '#CECAB9',
- },
- },
- ],
- decorations: [],
- };
-
- public static FourField002: TemplateDocInfos = {
- title: 'fourfield2',
- width: 425,
- height: 778,
- opts: {
- backgroundColor: '#242425',
- },
- fields: [
- {
- tl: [-0.83, -0.95],
- br: [0.83, -0.2],
- types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
- description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus.',
- opts: {
- borderWidth: '8',
- borderColor: '#F8E71C',
- },
- },
- {
- tl: [-0.65, -0.2],
- br: [0.65, -0.02],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY],
- description: 'A tiny field for just a word or two of plain text.',
- opts: {
- backgroundColor: 'transparent',
- color: 'white',
- contentXCentering: 'h-center',
- fontTransform: 'uppercase',
- },
- },
- {
- tl: [-0.65, 0],
- br: [0.65, 0.18],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY],
- description: 'A tiny field for just a word or two of plain text.',
- opts: {
- backgroundColor: 'transparent',
- color: 'white',
- contentXCentering: 'h-center',
- fontTransform: 'uppercase',
- },
- },
- {
- tl: [-0.83, 0.2],
- br: [0.83, 0.95],
- types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus, or share focus with field 1.',
- opts: {
- borderWidth: '8',
- borderColor: '#F8E71C',
- color: 'white',
- backgroundColor: '#242425',
- },
- },
- ],
- decorations: [
- {
- tl: [-0.8, -0.075],
- br: [-0.525, 0.075],
- opts: {
- backgroundColor: '#F8E71C',
- rotation: 45,
- },
- },
- {
- tl: [-0.3075, -0.0245],
- br: [-0.2175, 0.0245],
- opts: {
- backgroundColor: '#F8E71C',
- rotation: 45,
- },
- },
- {
- tl: [-0.045, -0.0245],
- br: [0.045, 0.0245],
- opts: {
- backgroundColor: '#F8E71C',
- rotation: 45,
- },
- },
- {
- tl: [0.2175, -0.0245],
- br: [0.3075, 0.0245],
- opts: {
- backgroundColor: '#F8E71C',
- rotation: 45,
- },
- },
- {
- tl: [0.525, -0.075],
- br: [0.8, 0.075],
- opts: {
- backgroundColor: '#F8E71C',
- rotation: 45,
- },
- },
- ],
- };
-
- // public static FourField003: TemplateDocInfos = {
- // title: 'fourfield3',
- // width: 477,
- // height: 662,
- // opts: {
- // backgroundColor: '#9E9C95'
- // },
- // fields: [{
- // tl: [-.875, -.9],
- // br: [.875, .7],
- // types: [TemplateFieldType.VISUAL],
- // sizes: [TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- // description: '',
- // opts: {
- // borderWidth: '15',
- // borderColor: '#E0E0DA',
- // }
- // }, {
- // tl: [-.95, .8],
- // br: [-.1, .95],
- // types: [TemplateFieldType.TEXT],
- // sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- // description: '',
- // opts: {
- // backgroundColor: 'transparent',
- // color: 'white',
- // contentXCentering: 'h-right',
- // }
- // }, {
- // tl: [.1, .8],
- // br: [.95, .95],
- // types: [TemplateFieldType.TEXT],
- // sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- // description: '',
- // opts: {
- // backgroundColor: 'transparent',
- // color: 'red',
- // fontTransform: 'uppercase',
- // contentXCentering: 'h-left'
- // }
- // }, {
- // tl: [0, -.9],
- // br: [.85, -.66],
- // types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
- // sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- // description: '',
- // opts: {
- // backgroundColor: 'transparent',
- // contentXCentering: 'h-right'
- // }
- // }],
- // decorations: [{
- // tl: [-.025, .8],
- // br: [.025, .95],
- // opts: {
- // backgroundColor: '#E0E0DA',
- // }
- // }]
- // };
-
- public static FourField004: TemplateDocInfos = {
- title: 'fourfield4',
- width: 414,
- height: 583,
- opts: {
- backgroundColor: '#6CCAF0',
- borderColor: '#1088C3',
- borderWidth: '10',
- },
- fields: [
- {
- tl: [-0.86, -0.92],
- br: [-0.075, -0.77],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY],
- description: 'A tiny field for just a word or two of plain text.',
- opts: {
- backgroundColor: '#E2B4F5',
- borderWidth: '9',
- borderColor: '#9222F1',
- contentXCentering: 'h-center',
- },
- },
- {
- tl: [0.075, -0.92],
- br: [0.86, -0.77],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY],
- description: 'A tiny field for just a word or two of plain text.',
- opts: {
- backgroundColor: '#F5B4DD',
- borderWidth: '9',
- borderColor: '#E260F3',
- contentXCentering: 'h-center',
- },
- },
- {
- tl: [-0.81, -0.64],
- br: [0.81, 0.48],
- types: [TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'A large to huge field for visual content that is the main content of the template.',
- opts: {
- borderWidth: '16',
- borderColor: '#A2BD77',
- },
- },
- {
- tl: [-0.86, 0.6],
- br: [0.86, 0.92],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
- description: 'A medium to large field for text that describes the visual content above',
- opts: {
- borderWidth: '9',
- borderColor: '#F0D601',
- backgroundColor: '#F3F57D',
- },
- },
- ],
- decorations: [
- {
- tl: [-0.852, -0.67],
- br: [0.852, 0.51],
- opts: {
- backgroundColor: 'transparent',
- borderColor: '#007C0C',
- borderWidth: '10',
- },
- },
- ],
- };
-
- public static ThreeField001: TemplateDocInfos = {
- title: 'threefield1',
- width: 575,
- height: 770,
- opts: {
- backgroundColor: '#DDD3A9',
- },
- fields: [
- {
- tl: [-0.66, -0.747],
- br: [0.66, 0.247],
- types: [TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'A medium to large field for visual content that is the central focus.',
- opts: {
- borderColor: 'yellow',
- borderWidth: '8',
- rotation: 45,
- },
- },
- {
- tl: [-0.7, 0.2],
- br: [0.7, 0.46],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- description: 'A very small text field for one to a few words. A good caption for the image.',
- opts: {
- backgroundColor: 'transparent',
- contentXCentering: 'h-center',
- },
- },
- {
- tl: [-0.95, 0.5],
- br: [0.95, 0.95],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
- description: 'A medium to large text field for a thorough description of the image. ',
- opts: {
- backgroundColor: 'transparent',
- color: 'white',
- },
- },
- ],
- decorations: [
- {
- tl: [0.2, -1.32],
- br: [1.8, -0.66],
- opts: {
- backgroundColor: '#CEB155',
- rotation: 45,
- },
- },
- {
- tl: [-1.8, -1.32],
- br: [-0.2, -0.66],
- opts: {
- backgroundColor: '#CEB155',
- rotation: 135,
- },
- },
- {
- tl: [0.33, 0.75],
- br: [1.66, 1.25],
- opts: {
- backgroundColor: '#CEB155',
- rotation: 135,
- },
- },
- {
- tl: [-1.66, 0.75],
- br: [-0.33, 1.25],
- opts: {
- backgroundColor: '#CEB155',
- rotation: 45,
- },
- },
- ],
- };
-
- public static ThreeField002: TemplateDocInfos = {
- title: 'threefield2',
- width: 477,
- height: 662,
- opts: {
- backgroundColor: '#9E9C95',
- },
- fields: [
- {
- tl: [-0.875, -0.9],
- br: [0.875, 0.7],
- types: [TemplateFieldType.VISUAL],
- sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
- description: 'A medium to large visual field for the main content of the template',
- opts: {
- borderWidth: '15',
- borderColor: '#E0E0DA',
- },
- },
- {
- tl: [0.1, 0.775],
- br: [0.95, 0.975],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- description: 'A very small text field for one to a few words. The content should represent a general categorization of the image.',
- opts: {
- backgroundColor: 'transparent',
- color: '#AF0D0D',
- fontTransform: 'uppercase',
- fontBold: true,
- contentXCentering: 'h-left',
- },
- },
- {
- tl: [-0.95, 0.775],
- br: [-0.1, 0.975],
- types: [TemplateFieldType.TEXT],
- sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
- description: 'A very small text field for one to a few words. The content should contextualize field 2.',
- opts: {
- backgroundColor: 'transparent',
- color: 'black',
- contentXCentering: 'h-right',
- },
- },
- ],
- decorations: [
- {
- tl: [-0.025, 0.8],
- br: [0.025, 0.95],
- opts: {
- backgroundColor: '#E0E0DA',
- },
- },
- ],
- };
-}
-
-export class FieldUtils {
- public static contentFields = (fields: Field[]) => {
- let toRet: Field[] = [];
- fields.forEach(field => {
- if (!field.isDecoration) {
- toRet.push(field);
- }
- toRet = toRet.concat(FieldUtils.contentFields(field.subfields ?? []));
- });
-
- return toRet;
- };
-
- public static calculateFontSize = (contWidth: number, contHeight: number, text: string, uppercase: boolean): number => {
- const words: string[] = text.split(/\s+/).filter(Boolean);
-
- let currFontSize = 1;
- let rowsCount = 1;
- let currTextHeight = currFontSize * rowsCount * 2;
-
- while (currTextHeight <= contHeight) {
- let wordIndex = 0;
- let currentRowWidth = 0;
- let wordsInCurrRow = 0;
- rowsCount = 1;
-
- while (wordIndex < words.length) {
- const word = words[wordIndex];
- const wordWidth = word.length * currFontSize * 0.5;
- //console.log(wordWidth)
-
- if (currentRowWidth + wordWidth <= contWidth) {
- currentRowWidth += wordWidth;
- ++wordsInCurrRow;
- } else {
- if (words.length !== 1 && words.length > wordsInCurrRow) {
- rowsCount++;
- currentRowWidth = wordWidth;
- wordsInCurrRow = 1;
- } else {
- break;
- }
- }
-
- wordIndex++;
- }
-
- currTextHeight = rowsCount * currFontSize * 2;
- //console.log(rowsCount, currFontSize, currTextHeight)
-
- currFontSize += 1;
- }
-
- return currFontSize - 1;
- };
-
- private static getDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number): { width: number; height: number; coord: { x: number; y: number } } => {
- const l = (coords.tl[0] * parentHeight) / 2;
- const t = coords.tl[1] * parentWidth / 2; //prettier-ignore
- const r = (coords.br[0] * parentHeight) / 2;
- const b = coords.br[1] * parentWidth / 2; //prettier-ignore
- const width = r - l;
- const height = b - t;
- const coord = { x: l, y: t };
- //console.log(coords, parentWidth, parentHeight, height);
- return { width, height, coord };
- };
-
- public static FreeformField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
- const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
-
- const docWithBasicOpts = Docs.Create.FreeformDocument([], {
- isDefaultTemplateDoc: true,
- _height: height,
- _width: width,
- title: title,
- x: coord.x,
- y: coord.y,
- backgroundColor: opts.backgroundColor ?? '',
- _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
- borderColor: opts.borderColor,
- borderWidth: opts.borderWidth,
- opacity: opts.opacity,
- hCentering: opts.contentXCentering,
- _rotation: opts.rotation,
- });
-
- return docWithBasicOpts;
- };
-
- public static TextField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
- const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
-
- const docWithBasicOpts = Docs.Create.TextDocument(content, {
- isDefaultTemplateDoc: true,
- _height: height,
- _width: width,
- title: title,
- x: coord.x,
- y: coord.y,
- _text_fontSize: `${FieldUtils.calculateFontSize(width, height, content, true)}`,
- backgroundColor: opts.backgroundColor ?? '',
- text_fontColor: opts.color,
- contentBold: opts.fontBold,
- textTransform: opts.fontTransform,
- color: opts.color,
- _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
- borderColor: opts.borderColor,
- borderWidth: opts.borderWidth,
- opacity: opts.opacity,
- hCentering: opts.contentXCentering,
- _rotation: opts.rotation,
- });
-
- docWithBasicOpts._layout_hideScroll = true;
-
- return docWithBasicOpts;
- };
-
- public static ImageField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
- const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
-
- const doc = Docs.Create.ImageDocument(content, {
- isDefaultTemplateDoc: true,
- _height: height,
- _width: width,
- title: title,
- x: coord.x,
- y: coord.y,
- _layout_fitWidth: false,
- backgroundColor: opts.backgroundColor ?? '',
- _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
- borderColor: opts.borderColor,
- borderWidth: opts.borderWidth,
- opacity: opts.opacity,
- _rotation: opts.rotation,
- });
-
- //setTimeout(() => {doc._height = height; doc._width = width}, 10);
-
- return doc;
- };
-
- public static CarouselField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, fields: Doc[]) => {
- const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
-
- const doc = Docs.Create.Carousel3DDocument(fields, { _height: height, _width: width, title: title, x: coord.x, y: coord.y, _text_fontSize: `${height / 2}` });
-
- return doc;
- };
-}
-
-// public static FourField002: TemplateDocInfos = {
-// width: 450,
-// height: 600,
-// fields: [{
-// tl: [-.6, -.9],
-// br: [.6, -.8],
-// types: [FieldType.TEXT],
-// sizes: [FieldSize.TINY]
-// }, {
-// tl: [-.9, -.7],
-// br: [.9, .2],
-// types: [FieldType.TEXT, FieldType.VISUAL],
-// sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE]
-// }, {
-// tl: [-.9, .3],
-// br: [-.05, .9],
-// types: [FieldType.TEXT],
-// sizes: [FieldSize.TINY]
-// }, {
-// tl: [.05, .3],
-// br: [.9, .9],
-// types: [FieldType.TEXT, FieldType.VISUAL],
-// sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE]
-// }]
-// };
-
-// public static TwoFieldPlusCarousel: TemplateDocInfos = {
-// width: 500,
-// height: 600,
-// fields: [{
-// tl: [-.9, -.99],
-// br: [.9, -.7],
-// types: [FieldType.TEXT],
-// sizes: [FieldSize.TINY]
-// }, {
-// tl: [-.9, -.65],
-// br: [.9, .35],
-// types: [],
-// sizes: []
-// }, {
-// tl: [-.9, .4],
-// br: [.9, .95],
-// types: [FieldType.TEXT],
-// sizes: [FieldSize.TINY]
-// }]
-// };
-// }
@observer
export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
- // eslint-disable-next-line no-use-before-define
static Instance: DocCreatorMenu;
private _disposers: { [name: string]: IDisposer } = {};
@@ -851,8 +78,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
@observable _dragging: boolean = false;
@observable _draggingIndicator: boolean = false;
@observable _dataViz?: DataVizBox;
- @observable _interactionLock?: boolean;
- @observable _snapPt: { x: number; y: number } = { x: 0, y: 0 };
+ @observable _interactionLock: any;
+ @observable _snapPt: any;
@observable _resizeHdlId: string = '';
@observable _resizing: boolean = false;
@observable _offset: { x: number; y: number } = { x: 0, y: 0 };
@@ -861,7 +88,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
@observable _menuDimensions: { width: number; height: number } = { width: 400, height: 400 };
@observable _editing: boolean = false;
- constructor(props: FieldViewProps) {
+ constructor(props: any) {
super(props);
makeObservable(this);
DocCreatorMenu.Instance = this;
@@ -946,7 +173,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
return bounds;
}
- setUpButtonClick = (e: React.PointerEvent, func: () => void) => {
+ setUpButtonClick = (e: any, func: Function) => {
setupMoveUpEvents(
this,
e,
@@ -1017,7 +244,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
}
updateIcons = (docs: Doc[]) => {
- console.log('called');
+ console.log('called')
docs.map(this.getIcon);
};
@@ -1050,13 +277,13 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
@action
- onResizePointerDown = (e: React.PointerEvent<HTMLDivElement>): void => {
+ onResizePointerDown = (e: React.PointerEvent): void => {
this._resizing = true;
document.addEventListener('pointermove', this.onResize);
SnappingManager.SetIsResizing(DocumentView.Selected().lastElement()?.Document[Id]); // turns off pointer events on things like youtube videos and web pages so that dragging doesn't get "stuck" when cursor moves over them
e.stopPropagation();
const id = (this._resizeHdlId = e.currentTarget.className);
- const pad = id.includes('Left') || id.includes('Right') ? Number(getComputedStyle(e.target as Element).width.replace('px', '')) / 2 : 0;
+ const pad = id.includes('Left') || id.includes('Right') ? Number(getComputedStyle(e.target as any).width.replace('px', '')) / 2 : 0;
const bounds = e.currentTarget.getBoundingClientRect();
this._offset = {
x: id.toLowerCase().includes('left') ? bounds.right - e.clientX - pad : bounds.left - e.clientX + pad, //
@@ -1067,7 +294,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
@action
- onResize = (e: PointerEvent): boolean => {
+ onResize = (e: any): boolean => {
const dragHdl = this._resizeHdlId.split(' ')[1];
const thisPt = DragManager.snapDrag(e, -this._offset.x, -this._offset.y, this._offset.x, this._offset.y);
@@ -1076,13 +303,13 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
this._interactionLock = true;
const scaleAspect = {x: scale.x, y: scale.y};
this.resizeView(refPt, scaleAspect, transl); // prettier-ignore
- await new Promise<boolean|undefined>(res => { setTimeout(() => { res(this._interactionLock = undefined)})});
+ await new Promise<any>(res => { setTimeout(() => { res(this._interactionLock = undefined)})});
}); // prettier-ignore
return true;
};
@action
- onDrag = (e: PointerEvent): boolean => {
+ onDrag = (e: any): boolean => {
this._pageX = e.pageX - (this._startPos?.x ?? 0);
this._pageY = e.pageY - (this._startPos?.y ?? 0);
this._initDimensions.x = this._pageX;
@@ -1109,6 +336,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
resizeView = (refPt: number[], scale: { x: number; y: number }, translation: { x: number; y: number }) => {
+ const refCent = [refPt[0], refPt[1]]; // fixed reference point for resize (ie, a point that doesn't move)
if (this._initDimensions.x === undefined) this._initDimensions.x = this._pageX;
if (this._initDimensions.y === undefined) this._initDimensions.y = this._pageY;
const { height, width, x, y } = this._initDimensions;
@@ -1367,7 +595,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
findValidTemplates = (cols: Col[], templates: TemplateDocInfos[]) => {
- const validTemplates: string[] = [];
+ let validTemplates: any[] = [];
templates.forEach(template => {
const numFields = template.fields.length;
if (!(numFields === cols.length)) return;
@@ -1377,10 +605,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
}
});
- return validTemplates
- .map(title => TemplateLayouts.getTemplateByTitle(title))
- .filter(t => t)
- .map(t => t!);
+ validTemplates = validTemplates.map(title => TemplateLayouts.getTemplateByTitle(title));
+
+ return validTemplates;
};
// createColumnField = (template: TemplateDocInfos, field: Field, column: Col): Doc => {
@@ -1412,33 +639,23 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
* @returns a doc containing the fully rendered template
*/
fillPresetTemplate = async (template: TemplateDocInfos, assignments: { [field: string]: Col }): Promise<Doc> => {
- const fields: Doc[] = [];
const wordLimit = (size: TemplateFieldSize) => {
switch (size) {
- case TemplateFieldSize.TINY: return 2;
- case TemplateFieldSize.SMALL: return 5;
- case TemplateFieldSize.MEDIUM: return 20;
- case TemplateFieldSize.LARGE: return 50;
- case TemplateFieldSize.HUGE: return 100;
- default: return 10;
- } // prettier-ignore
- };
- const stringifyGPTInfo = (calls: [string, Col][]): string => {
- let string: string = '*** COLUMN INFO:';
- calls.forEach(([fieldNum, col]) => {
- string += `--- title: ${col.title}, prompt: ${col.desc}, word limit: ${wordLimit(col.sizes[0])} words, assigned field: ${fieldNum} ---`;
- });
- return (string += ' ***');
+ case TemplateFieldSize.TINY:
+ return 2;
+ case TemplateFieldSize.SMALL:
+ return 5;
+ case TemplateFieldSize.MEDIUM:
+ return 20;
+ case TemplateFieldSize.LARGE:
+ return 50;
+ case TemplateFieldSize.HUGE:
+ return 100;
+ default:
+ return 10;
+ }
};
- const GPTAssignments = Object.entries(assignments).filter(([f, col]) => this._columns.includes(col));
- const nonGPTAssignments: [string, Col][] = Object.entries(assignments).filter(a => !GPTAssignments.includes(a));
- const GPTTextCalls = GPTAssignments.filter(([str, col]) => col.type === TemplateFieldType.TEXT);
- const GPTIMGCalls = GPTAssignments.filter(([str, col]) => col.type === TemplateFieldType.VISUAL);
- const GPTTextAssignment = stringifyGPTInfo(GPTTextCalls);
-
- let fieldContent: string = '';
-
const renderTextCalls = async (): Promise<Doc[]> => {
const rendered: Doc[] = [];
@@ -1449,9 +666,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
const res = await gptAPICall(prompt, GPTCallType.FILL);
if (res) {
- const asngs: { [title: string]: { number: string; content: string } } = JSON.parse(res);
+ const assignments: { [title: string]: { number: string; content: string } } = JSON.parse(res);
//console.log('assignments', GPTAssignments, 'assignment string', GPTAssignmentString, 'field content', fieldContent, 'response', res, 'assignments', assignments);
- Object.entries(asngs).forEach(([title, info]) => {
+ Object.entries(assignments).forEach(([title, info]) => {
const field: Field = template.fields[Number(info.number)];
const col = this.getColByTitle(title);
@@ -1527,6 +744,25 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
return rendered;
};
+ const fields: Doc[] = [];
+
+ const GPTAssignments = Object.entries(assignments).filter(([f, col]) => this._columns.includes(col));
+ const nonGPTAssignments: [string, Col][] = Object.entries(assignments).filter(a => !GPTAssignments.includes(a));
+ const GPTTextCalls = GPTAssignments.filter(([str, col]) => col.type === TemplateFieldType.TEXT);
+ const GPTIMGCalls = GPTAssignments.filter(([str, col]) => col.type === TemplateFieldType.VISUAL);
+
+ const stringifyGPTInfo = (calls: [string, Col][]): string => {
+ let string: string = '*** COLUMN INFO:';
+ calls.forEach(([fieldNum, col]) => {
+ string += `--- title: ${col.title}, prompt: ${col.desc}, word limit: ${wordLimit(col.sizes[0])} words, assigned field: ${fieldNum} ---`;
+ });
+ return (string += ' ***');
+ };
+
+ const GPTTextAssignment = stringifyGPTInfo(GPTTextCalls);
+
+ let fieldContent: string = '';
+
Object.entries(nonGPTAssignments).forEach(([f, strCol]) => {
const field: Field = template.fields[Number(f)];
const col = strCol[1];
@@ -1570,7 +806,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
_width: template.width,
title: template.title,
backgroundColor: template.opts.backgroundColor,
- _layout_borderRounding: `${template.opts.cornerRounding ?? 0}px`,
+ _layout_borderRounding: `${template.opts.cornerRounding}px` ?? '0px',
borderWidth: template.opts.borderWidth,
borderColor: template.opts.borderColor,
x: 40000,
@@ -1629,7 +865,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
++this._callCount;
const origCount = this._callCount;
- const prompt: string = `(${origCount}) ${inputText}`;
+ let prompt: string = `(${origCount}) ${inputText}`;
this._GPTLoading = true;
@@ -1669,7 +905,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
const assignments: [TemplateDocInfos, { [field: number]: Col }][] = await this.assignColsToFields(templates, cols);
- const renderedTemplatePromises: Promise<Doc>[] = assignments.map(([template, asgns]) => this.fillPresetTemplate(template, asgns));
+ const renderedTemplatePromises: Promise<Doc>[] = assignments.map(([template, assignments]) => this.fillPresetTemplate(template, assignments));
const renderedTemplates: Doc[] = await Promise.all(renderedTemplatePromises);
@@ -1682,17 +918,17 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
@action setExpandedView = (info: { icon: ImageField; doc: Doc } | undefined) => {
if (info) {
const doc = info.doc;
- const wrapper: Doc = Docs.Create.FreeformDocument([info.doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: '' });
- const newInfo = { icon: new ImageField(''), doc: wrapper };
+ const wrapper: Doc = Docs.Create.FreeformDocument([info.doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''});
+ const newInfo = {icon: new ImageField(''), doc: wrapper}
this._expandedPreview = newInfo;
} else {
this._expandedPreview = info;
}
};
- get editingWindow() {
+ get editingWindow(){
const doc = this._expandedPreview?.doc ?? new Doc();
- const rendered = (
+ const rendered =
<div className="docCreatorMenu-expanded-template-preview">
<CollectionFreeFormView
Document={this._expandedPreview!.doc}
@@ -1708,13 +944,14 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
removeDocument={returnFalse}
PanelWidth={() => this._menuDimensions.width - 10}
PanelHeight={() => this._menuDimensions.height - 60}
- ScreenToLocalTransform={Transform.Identity}
+ ScreenToLocalTransform={() => new Transform(-this._pageX,-this._pageY, 1)}
renderDepth={5}
whenChildContentsActiveChanged={emptyFunction}
focus={emptyFunction}
styleProvider={DefaultStyleProvider}
addDocTab={this._props.addDocTab}
- pinToPres={emptyFunction}
+ // eslint-disable-next-line no-use-before-define
+ pinToPres={() => undefined}
childFilters={returnEmptyFilter}
childFiltersByRanges={returnEmptyFilter}
searchFilterDocs={returnEmptyDoclist}
@@ -1723,21 +960,14 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
yPadding={0}
/>
</div>
- );
+
return (
<div className="docCreatorMenu-expanded-template-preview">
- <div className="top-panel" />
+ <div className="top-panel"/>
{rendered}
<div className="right-buttons-panel">
- <button
- className="docCreatorMenu-menu-button section-reveal-options top-right"
- onPointerDown={e =>
- this.setUpButtonClick(e, () => {
- this._expandedPreview && this.updateIcons(this._suggestedTemplates.slice());
- this.setExpandedView(undefined);
- })
- }>
+ <button className="docCreatorMenu-menu-button section-reveal-options top-right" onPointerDown={e => this.setUpButtonClick(e, () => {this._expandedPreview && this.updateIcons(this._suggestedTemplates.slice()); this.setExpandedView(undefined)})}>
<FontAwesomeIcon icon="minimize" />
</button>
<button className="docCreatorMenu-menu-button section-reveal-options top-right-lower" onPointerDown={e => this.setUpButtonClick(e, () => this._expandedPreview && this._templateDocs.push(this._expandedPreview.doc))}>
@@ -1745,6 +975,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
</button>
</div>
</div>
+
);
}
@@ -1779,7 +1010,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
.filter(info => info.icon && info.doc)
.map(info => (
<div
- key={info.doc[Id]}
className="docCreatorMenu-preview-window"
style={{
border: this._selectedTemplate === info.doc ? `solid 3px ${Colors.MEDIUM_BLUE}` : '',
@@ -1821,7 +1051,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
</button>
</div>
<div className="docCreatorMenu-templates-preview-window" style={{ justifyContent: this._menuDimensions.width > 400 ? 'center' : '' }}>
- <div className="docCreatorMenu-preview-window empty" onPointerDown={() => this.testTemplate()}>
+ <div className="docCreatorMenu-preview-window empty" onPointerDown={e => this.testTemplate()}>
<FontAwesomeIcon icon="plus" color="rgb(160, 160, 160)" />
</div>
{this._templateDocs
@@ -1832,7 +1062,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
renderedTemplates.push(info.doc);
return (
<div
- key={info.doc[Id]}
className="docCreatorMenu-preview-window"
style={{
border: this._selectedTemplate === info.doc ? `solid 3px ${Colors.MEDIUM_BLUE}` : '',
@@ -1874,7 +1103,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
<div className="docCreatorMenu-preview-container">
{this._savedLayouts.map((layout, index) => (
<div
- key={layout.template[Id]}
className="docCreatorMenu-preview-window"
style={{
border: this.isSelectedLayout(layout) ? `solid 3px ${Colors.MEDIUM_BLUE}` : '',
@@ -1899,11 +1127,11 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
get layoutConfigOptions() {
- const optionInput = (icon: string, func: (arg: string) => void, def?: number, key?: string, noMargin?: boolean) => {
+ const optionInput = (icon: string, func: Function, def?: number, key?: string, noMargin?: boolean) => {
return (
<div className="docCreatorMenu-option-container small no-margin" key={key} style={{ marginTop: noMargin ? '0px' : '' }}>
<div className="docCreatorMenu-option-title config layout-config">
- <FontAwesomeIcon icon={icon as IconProp} />
+ <FontAwesomeIcon icon={icon as any} />
</div>
<input defaultValue={def} onInput={e => func(e.currentTarget.value)} className="docCreatorMenu-input config layout-config" />
</div>
@@ -1976,7 +1204,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
// {null}
// </CollectionFreeFormView>
// </div>
- <div className="docCreatorMenu-layout-preview-window-wrapper" id={String(id)}>
+ <div className="docCreatorMenu-layout-preview-window-wrapper" id={String(id) ?? undefined}>
<div className="docCreatorMenu-zoom-button-container">
<button className="docCreatorMenu-zoom-button" onPointerDown={e => this.setUpButtonClick(e, () => runInAction(() => (this._layoutPreviewScale *= 1.25)))}>
<FontAwesomeIcon icon={'minus'} />
@@ -1992,7 +1220,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
</div>
{
<div
- id={String(id)}
+ id={String(id) ?? undefined}
className={`docCreatorMenu-layout-preview-window ${small ? 'small' : ''}`}
style={{
gridTemplateColumns: `repeat(${altLayout ? altLayout.columns : this.columnsCount}, ${scaledDown(docWidth)}px`,
@@ -2014,7 +1242,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
) : (
this.docsToRender.map(num => (
<div
- key={num}
onMouseEnter={() => this._dataViz?.setSpecialHighlightedRow(num)}
onMouseLeave={() => this._dataViz?.setSpecialHighlightedRow(undefined)}
className="docCreatorMenu-layout-preview-item"
@@ -2036,7 +1263,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
get optionsMenuContents() {
const layoutEquals = (layout: DataVizTemplateLayout) => {}; //TODO: ADD LATER
- const layoutOption = (option: LayoutType, optStyle?: object, specialFunc?: () => void) => {
+ const layoutOption = (option: LayoutType, optStyle?: {}, specialFunc?: Function) => {
return (
<div
className="docCreatorMenu-dropdown-option"
@@ -2056,7 +1283,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
return (
<div className="docCreatorMenu-option-container">
<div className={`docCreatorMenu-option-title config ${specClass}`} style={{ width: width * 0.4, height: height }}>
- <FontAwesomeIcon icon={icon as IconProp} />
+ <FontAwesomeIcon icon={icon as any} />
</div>
{manual ? (
<input className={`docCreatorMenu-input config ${specClass}`} style={{ width: width * 0.6, height: height }} />
@@ -2097,7 +1324,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
20,
'repeat',
undefined,
- repeatOptions.map(num => <option key={num} onPointerDown={() => (this._layout.repeat = num)}>{`${num}x`}</option>)
+ repeatOptions.map(num => <option onPointerDown={e => (this._layout.repeat = num)}>{`${num}x`}</option>)
)}
<hr className="docCreatorMenu-option-divider" />
<div className="docCreatorMenu-general-options-container">
@@ -2265,19 +1492,19 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
const width: number = ref?.width ?? 0;
return [
- <div key={1} className='docCreatorMenu-resizer top' onPointerDown={this.onResizePointerDown} style={{width: width, left: 0, top: -7}}/>,
- <div key={2} className='docCreatorMenu-resizer right' onPointerDown={this.onResizePointerDown} style={{height: height, left: width - 3, top: 0}}/>,
- <div key={3} className='docCreatorMenu-resizer bottom' onPointerDown={this.onResizePointerDown} style={{width: width, left: 0, top: height - 3}}/>,
- <div key={4} className='docCreatorMenu-resizer left' onPointerDown={this.onResizePointerDown} style={{height: height, left: -7, top: 0}}/>,
- <div key={5} className='docCreatorMenu-resizer topRight' onPointerDown={this.onResizePointerDown} style={{left: width - 5, top: -10, cursor: 'nesw-resize'}}/>,
- <div key={6} className='docCreatorMenu-resizer topLeft' onPointerDown={this.onResizePointerDown} style={{left: -10, top: -10, cursor: 'nwse-resize'}}/>,
- <div key={7} className='docCreatorMenu-resizer bottomRight' onPointerDown={this.onResizePointerDown} style={{left: width - 5, top: height - 5, cursor: 'nwse-resize'}}/>,
- <div key={8} className='docCreatorMenu-resizer bottomLeft' onPointerDown={this.onResizePointerDown} style={{left: -10, top: height - 5, cursor: 'nesw-resize'}}/>
+ <div className='docCreatorMenu-resizer top' onPointerDown={this.onResizePointerDown} style={{width: width, left: 0, top: -7}}/>,
+ <div className='docCreatorMenu-resizer right' onPointerDown={this.onResizePointerDown} style={{height: height, left: width - 3, top: 0}}/>,
+ <div className='docCreatorMenu-resizer bottom' onPointerDown={this.onResizePointerDown} style={{width: width, left: 0, top: height - 3}}/>,
+ <div className='docCreatorMenu-resizer left' onPointerDown={this.onResizePointerDown} style={{height: height, left: -7, top: 0}}/>,
+ <div className='docCreatorMenu-resizer topRight' onPointerDown={this.onResizePointerDown} style={{left: width - 5, top: -10, cursor: 'nesw-resize'}}/>,
+ <div className='docCreatorMenu-resizer topLeft' onPointerDown={this.onResizePointerDown} style={{left: -10, top: -10, cursor: 'nwse-resize'}}/>,
+ <div className='docCreatorMenu-resizer bottomRight' onPointerDown={this.onResizePointerDown} style={{left: width - 5, top: height - 5, cursor: 'nwse-resize'}}/>,
+ <div className='docCreatorMenu-resizer bottomLeft' onPointerDown={this.onResizePointerDown} style={{left: -10, top: height - 5, cursor: 'nesw-resize'}}/>
]; //prettier-ignore
}
render() {
- const topButton = (icon: string, opt: string, func: () => void, tag: string) => {
+ const topButton = (icon: string, opt: string, func: Function, tag: string) => {
return (
<div className={`top-button-container ${tag} ${opt === this._menuContent ? 'selected' : ''}`}>
<div
@@ -2289,7 +1516,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
})
)
}>
- <FontAwesomeIcon icon={icon as IconProp} />
+ <FontAwesomeIcon icon={icon as any} />
</div>
</div>
);
@@ -2328,11 +1555,11 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
setupMoveUpEvents(
this,
e,
- moveEv => {
+ e => {
this._dragging = true;
this._startPos = { x: 0, y: 0 };
- this._startPos.x = moveEv.pageX - (this._ref?.getBoundingClientRect().left ?? 0);
- this._startPos.y = moveEv.pageY - (this._ref?.getBoundingClientRect().top ?? 0);
+ this._startPos.x = e.pageX - (this._ref?.getBoundingClientRect().left ?? 0);
+ this._startPos.y = e.pageY - (this._ref?.getBoundingClientRect().top ?? 0);
document.addEventListener('pointermove', this.onDrag);
return true;
},
@@ -2359,6 +1586,776 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
}
}
-// export class ContentField extends Field {
+export interface DataVizTemplateInfo {
+ doc: Doc;
+ layout: { type: LayoutType; xMargin: number; yMargin: number; repeat: number };
+ columns: number;
+ referencePos: { x: number; y: number };
+}
+
+export interface DataVizTemplateLayout {
+ template: Doc;
+ docsNumList: number[];
+ layout: { type: LayoutType; xMargin: number; yMargin: number; repeat: number };
+ columns: number;
+ rows: number;
+}
+
+export enum TemplateFieldType {
+ TEXT = 'text',
+ VISUAL = 'visual',
+ UNSET = 'unset',
+}
+
+export enum TemplateFieldSize {
+ TINY = 'tiny',
+ SMALL = 'small',
+ MEDIUM = 'medium',
+ LARGE = 'large',
+ HUGE = 'huge',
+}
+
+export type Col = {
+ sizes: TemplateFieldSize[];
+ desc: string;
+ title: string;
+ type: TemplateFieldType;
+ defaultContent?: string;
+};
+export interface FieldOpts {
+ backgroundColor?: string;
+ color?: string;
+ cornerRounding?: number;
+ borderWidth?: string;
+ borderColor?: string;
+ contentXCentering?: 'h-left' | 'h-center' | 'h-right';
+ contentYCentering?: 'top' | 'center' | 'bottom';
+ opacity?: number;
+ rotation?: number;
+ //animation?: boolean;
+ fontBold?: boolean;
+ fontTransform?: 'uppercase' | 'lowercase';
+ fieldViewType?: 'freeform' | 'stacked';
+}
+
+type Field = {
+ tl: [number, number];
+ br: [number, number];
+ opts: FieldOpts;
+ subfields?: Field[];
+ types?: TemplateFieldType[];
+ sizes?: TemplateFieldSize[];
+ isDecoration?: boolean;
+ description?: string;
+};
+
+// class ContentField implements Field {
+// tl: [number, number];
+// br: [number, number];
+// opts: FieldOpts;
+// subfields?: Field[];
+// types?: TemplateFieldType[];
+// sizes?: TemplateFieldSize[];
+// description?: string;
+// constructor( tl: [number, number], br: [number, number],
+// opts: FieldOpts, subfields?: Field[],
+// types?: TemplateFieldType[],
+// sizes?: TemplateFieldSize[],
+// description?: string) {
+// this.tl = tl;
+// this.br = br;
+// this.opts = opts;
+// this.subfields = subfields;
+// this.types = types;
+// this.sizes = sizes;
+// this.description = description;
+// }
+
+// render = (content: any): Doc => {
+// return new Doc;
+// }
// }
+
+type DecorationField = Field;
+
+type InkDecoration = {};
+
+type TemplateDecorations = Field | InkDecoration;
+
+interface TemplateOpts extends FieldOpts {}
+
+export interface TemplateDocInfos {
+ title: string;
+ height: number;
+ width: number;
+ opts: TemplateOpts;
+ fields: Field[];
+ decorations: Field[];
+}
+
+export class TemplateLayouts {
+ public static get allTemplates(): TemplateDocInfos[] {
+ return Object.values(TemplateLayouts).filter(value => typeof value === 'object' && value !== null && 'title' in value) as TemplateDocInfos[];
+ }
+
+ public static getTemplateByTitle = (title: string): TemplateDocInfos | undefined => {
+ switch (title) {
+ case 'fourfield1':
+ return TemplateLayouts.FourField001;
+ case 'fourfield2':
+ return TemplateLayouts.FourField002;
+ // case 'fourfield3':
+ // return TemplateLayouts.FourField003;
+ case 'fourfield4':
+ return TemplateLayouts.FourField004;
+ case 'threefield1':
+ return TemplateLayouts.ThreeField001;
+ case 'threefield2':
+ return TemplateLayouts.ThreeField002;
+ default:
+ break;
+ }
+
+ return undefined;
+ };
+
+ public static FourField001: TemplateDocInfos = {
+ title: 'fourfield1',
+ width: 416,
+ height: 700,
+ opts: {
+ backgroundColor: '#C0B887',
+ cornerRounding: 20,
+ borderColor: '#6B461F',
+ borderWidth: '12',
+ },
+ fields: [
+ {
+ tl: [-0.95, -1],
+ br: [0.95, -0.85],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY],
+ description: 'A title field for very short text that contextualizes the content.',
+ opts: {
+ backgroundColor: 'transparent',
+ color: '#F1F0E9',
+ contentXCentering: 'h-center',
+ fontBold: true,
+ },
+ },
+ {
+ tl: [-0.87, -0.83],
+ br: [0.87, 0.2],
+ types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'The main focus of the template; could be an image, long text, etc.',
+ opts: {
+ cornerRounding: 20,
+ borderColor: '#8F5B25',
+ borderWidth: '6',
+ backgroundColor: '#CECAB9',
+ },
+ },
+ {
+ tl: [-0.8, 0.2],
+ br: [0.8, 0.3],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ description: 'A caption for field #2, very short to short text that contextualizes the content of field #2',
+ opts: {
+ backgroundColor: 'transparent',
+ contentXCentering: 'h-center',
+ color: '#F1F0E9',
+ },
+ },
+ {
+ tl: [-0.87, 0.37],
+ br: [0.87, 0.96],
+ types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'A medium-sized field for medium/long text.',
+ opts: {
+ cornerRounding: 15,
+ borderColor: '#8F5B25',
+ borderWidth: '6',
+ backgroundColor: '#CECAB9',
+ },
+ },
+ ],
+ decorations: [],
+ };
+
+ public static FourField002: TemplateDocInfos = {
+ title: 'fourfield2',
+ width: 425,
+ height: 778,
+ opts: {
+ backgroundColor: '#242425',
+ },
+ fields: [
+ {
+ tl: [-0.83, -0.95],
+ br: [0.83, -0.2],
+ types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+ description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus.',
+ opts: {
+ borderWidth: '8',
+ borderColor: '#F8E71C',
+ },
+ },
+ {
+ tl: [-0.65, -0.2],
+ br: [0.65, -0.02],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY],
+ description: 'A tiny field for just a word or two of plain text.',
+ opts: {
+ backgroundColor: 'transparent',
+ color: 'white',
+ contentXCentering: 'h-center',
+ fontTransform: 'uppercase',
+ },
+ },
+ {
+ tl: [-0.65, 0],
+ br: [0.65, 0.18],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY],
+ description: 'A tiny field for just a word or two of plain text.',
+ opts: {
+ backgroundColor: 'transparent',
+ color: 'white',
+ contentXCentering: 'h-center',
+ fontTransform: 'uppercase',
+ },
+ },
+ {
+ tl: [-0.83, 0.2],
+ br: [0.83, 0.95],
+ types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus, or share focus with field 1.',
+ opts: {
+ borderWidth: '8',
+ borderColor: '#F8E71C',
+ color: 'white',
+ backgroundColor: '#242425',
+ },
+ },
+ ],
+ decorations: [
+ {
+ tl: [-0.8, -0.075],
+ br: [-0.525, 0.075],
+ opts: {
+ backgroundColor: '#F8E71C',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [-0.3075, -0.0245],
+ br: [-0.2175, 0.0245],
+ opts: {
+ backgroundColor: '#F8E71C',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [-0.045, -0.0245],
+ br: [0.045, 0.0245],
+ opts: {
+ backgroundColor: '#F8E71C',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [0.2175, -0.0245],
+ br: [0.3075, 0.0245],
+ opts: {
+ backgroundColor: '#F8E71C',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [0.525, -0.075],
+ br: [0.8, 0.075],
+ opts: {
+ backgroundColor: '#F8E71C',
+ rotation: 45,
+ },
+ },
+ ],
+ };
+
+ // public static FourField003: TemplateDocInfos = {
+ // title: 'fourfield3',
+ // width: 477,
+ // height: 662,
+ // opts: {
+ // backgroundColor: '#9E9C95'
+ // },
+ // fields: [{
+ // tl: [-.875, -.9],
+ // br: [.875, .7],
+ // types: [TemplateFieldType.VISUAL],
+ // sizes: [TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ // description: '',
+ // opts: {
+ // borderWidth: '15',
+ // borderColor: '#E0E0DA',
+ // }
+ // }, {
+ // tl: [-.95, .8],
+ // br: [-.1, .95],
+ // types: [TemplateFieldType.TEXT],
+ // sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ // description: '',
+ // opts: {
+ // backgroundColor: 'transparent',
+ // color: 'white',
+ // contentXCentering: 'h-right',
+ // }
+ // }, {
+ // tl: [.1, .8],
+ // br: [.95, .95],
+ // types: [TemplateFieldType.TEXT],
+ // sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ // description: '',
+ // opts: {
+ // backgroundColor: 'transparent',
+ // color: 'red',
+ // fontTransform: 'uppercase',
+ // contentXCentering: 'h-left'
+ // }
+ // }, {
+ // tl: [0, -.9],
+ // br: [.85, -.66],
+ // types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+ // sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ // description: '',
+ // opts: {
+ // backgroundColor: 'transparent',
+ // contentXCentering: 'h-right'
+ // }
+ // }],
+ // decorations: [{
+ // tl: [-.025, .8],
+ // br: [.025, .95],
+ // opts: {
+ // backgroundColor: '#E0E0DA',
+ // }
+ // }]
+ // };
+
+ public static FourField004: TemplateDocInfos = {
+ title: 'fourfield4',
+ width: 414,
+ height: 583,
+ opts: {
+ backgroundColor: '#6CCAF0',
+ borderColor: '#1088C3',
+ borderWidth: '10',
+ },
+ fields: [
+ {
+ tl: [-0.86, -0.92],
+ br: [-0.075, -0.77],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY],
+ description: 'A tiny field for just a word or two of plain text.',
+ opts: {
+ backgroundColor: '#E2B4F5',
+ borderWidth: '9',
+ borderColor: '#9222F1',
+ contentXCentering: 'h-center',
+ },
+ },
+ {
+ tl: [0.075, -0.92],
+ br: [0.86, -0.77],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY],
+ description: 'A tiny field for just a word or two of plain text.',
+ opts: {
+ backgroundColor: '#F5B4DD',
+ borderWidth: '9',
+ borderColor: '#E260F3',
+ contentXCentering: 'h-center',
+ },
+ },
+ {
+ tl: [-0.81, -0.64],
+ br: [0.81, 0.48],
+ types: [TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'A large to huge field for visual content that is the main content of the template.',
+ opts: {
+ borderWidth: '16',
+ borderColor: '#A2BD77',
+ },
+ },
+ {
+ tl: [-0.86, 0.6],
+ br: [0.86, 0.92],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+ description: 'A medium to large field for text that describes the visual content above',
+ opts: {
+ borderWidth: '9',
+ borderColor: '#F0D601',
+ backgroundColor: '#F3F57D',
+ },
+ },
+ ],
+ decorations: [
+ {
+ tl: [-0.852, -0.67],
+ br: [0.852, 0.51],
+ opts: {
+ backgroundColor: 'transparent',
+ borderColor: '#007C0C',
+ borderWidth: '10',
+ },
+ },
+ ],
+ };
+
+ public static ThreeField001: TemplateDocInfos = {
+ title: 'threefield1',
+ width: 575,
+ height: 770,
+ opts: {
+ backgroundColor: '#DDD3A9',
+ },
+ fields: [
+ {
+ tl: [-0.66, -0.747],
+ br: [0.66, 0.247],
+ types: [TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'A medium to large field for visual content that is the central focus.',
+ opts: {
+ borderColor: 'yellow',
+ borderWidth: '8',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [-0.7, 0.2],
+ br: [0.7, 0.46],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ description: 'A very small text field for one to a few words. A good caption for the image.',
+ opts: {
+ backgroundColor: 'transparent',
+ contentXCentering: 'h-center',
+ },
+ },
+ {
+ tl: [-0.95, 0.5],
+ br: [0.95, 0.95],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+ description: 'A medium to large text field for a thorough description of the image. ',
+ opts: {
+ backgroundColor: 'transparent',
+ color: 'white',
+ },
+ },
+ ],
+ decorations: [
+ {
+ tl: [0.2, -1.32],
+ br: [1.8, -0.66],
+ opts: {
+ backgroundColor: '#CEB155',
+ rotation: 45,
+ },
+ },
+ {
+ tl: [-1.8, -1.32],
+ br: [-0.2, -0.66],
+ opts: {
+ backgroundColor: '#CEB155',
+ rotation: 135,
+ },
+ },
+ {
+ tl: [0.33, 0.75],
+ br: [1.66, 1.25],
+ opts: {
+ backgroundColor: '#CEB155',
+ rotation: 135,
+ },
+ },
+ {
+ tl: [-1.66, 0.75],
+ br: [-0.33, 1.25],
+ opts: {
+ backgroundColor: '#CEB155',
+ rotation: 45,
+ },
+ },
+ ],
+ };
+
+ public static ThreeField002: TemplateDocInfos = {
+ title: 'threefield2',
+ width: 477,
+ height: 662,
+ opts: {
+ backgroundColor: '#9E9C95',
+ },
+ fields: [
+ {
+ tl: [-0.875, -0.9],
+ br: [0.875, 0.7],
+ types: [TemplateFieldType.VISUAL],
+ sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+ description: 'A medium to large visual field for the main content of the template',
+ opts: {
+ borderWidth: '15',
+ borderColor: '#E0E0DA',
+ },
+ },
+ {
+ tl: [0.1, 0.775],
+ br: [0.95, 0.975],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ description: 'A very small text field for one to a few words. The content should represent a general categorization of the image.',
+ opts: {
+ backgroundColor: 'transparent',
+ color: '#AF0D0D',
+ fontTransform: 'uppercase',
+ fontBold: true,
+ contentXCentering: 'h-left',
+ },
+ },
+ {
+ tl: [-0.95, 0.775],
+ br: [-0.1, 0.975],
+ types: [TemplateFieldType.TEXT],
+ sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+ description: 'A very small text field for one to a few words. The content should contextualize field 2.',
+ opts: {
+ backgroundColor: 'transparent',
+ color: 'black',
+ contentXCentering: 'h-right',
+ },
+ },
+ ],
+ decorations: [
+ {
+ tl: [-0.025, 0.8],
+ br: [0.025, 0.95],
+ opts: {
+ backgroundColor: '#E0E0DA',
+ },
+ },
+ ],
+ };
+}
+
+export class FieldUtils {
+ public static contentFields = (fields: Field[]) => {
+ let toRet: Field[] = [];
+ fields.forEach(field => {
+ if (!field.isDecoration) {
+ toRet.push(field);
+ }
+ toRet = toRet.concat(FieldUtils.contentFields(field.subfields ?? []));
+ });
+
+ return toRet;
+ };
+
+ public static calculateFontSize = (contWidth: number, contHeight: number, text: string, uppercase: boolean): number => {
+ const words: string[] = text.split(/\s+/).filter(Boolean);
+
+ let currFontSize = 1;
+ let rowsCount = 1;
+ let currTextHeight = currFontSize * rowsCount * 2;
+
+ while (currTextHeight <= contHeight) {
+ let wordIndex = 0;
+ let currentRowWidth = 0;
+ let wordsInCurrRow = 0;
+ rowsCount = 1;
+
+ while (wordIndex < words.length) {
+ const word = words[wordIndex];
+ const wordWidth = word.length * currFontSize * 0.5;
+ //console.log(wordWidth)
+
+ if (currentRowWidth + wordWidth <= contWidth) {
+ currentRowWidth += wordWidth;
+ ++wordsInCurrRow;
+ } else {
+ if (words.length !== 1 && words.length > wordsInCurrRow) {
+ rowsCount++;
+ currentRowWidth = wordWidth;
+ wordsInCurrRow = 1;
+ } else {
+ break;
+ }
+ }
+
+ wordIndex++;
+ }
+
+ currTextHeight = rowsCount * currFontSize * 2;
+ //console.log(rowsCount, currFontSize, currTextHeight)
+
+ currFontSize += 1;
+ }
+
+ return currFontSize - 1;
+ };
+
+ private static getDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number): { width: number; height: number; coord: { x: number; y: number } } => {
+ const l = (coords.tl[0] * parentHeight) / 2;
+ const t = coords.tl[1] * parentWidth / 2; //prettier-ignore
+ const r = (coords.br[0] * parentHeight) / 2;
+ const b = coords.br[1] * parentWidth / 2; //prettier-ignore
+ const width = r - l;
+ const height = b - t;
+ const coord = { x: l, y: t };
+ //console.log(coords, parentWidth, parentHeight, height);
+ return { width, height, coord };
+ };
+
+ public static FreeformField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
+ const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
+
+ const docWithBasicOpts = Docs.Create.FreeformDocument([], {
+ isDefaultTemplateDoc: true,
+ _height: height,
+ _width: width,
+ title: title,
+ x: coord.x,
+ y: coord.y,
+ backgroundColor: opts.backgroundColor ?? '',
+ _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
+ borderColor: opts.borderColor,
+ borderWidth: opts.borderWidth,
+ opacity: opts.opacity,
+ hCentering: opts.contentXCentering,
+ _rotation: opts.rotation,
+ });
+
+ return docWithBasicOpts;
+ };
+
+ public static TextField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
+ const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
+
+ const docWithBasicOpts = Docs.Create.TextDocument(content, {
+ isDefaultTemplateDoc: true,
+ _height: height,
+ _width: width,
+ title: title,
+ x: coord.x,
+ y: coord.y,
+ _text_fontSize: `${FieldUtils.calculateFontSize(width, height, content, true)}`,
+ backgroundColor: opts.backgroundColor ?? '',
+ text_fontColor: opts.color,
+ contentBold: opts.fontBold,
+ textTransform: opts.fontTransform,
+ color: opts.color,
+ _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
+ borderColor: opts.borderColor,
+ borderWidth: opts.borderWidth,
+ opacity: opts.opacity,
+ hCentering: opts.contentXCentering,
+ _rotation: opts.rotation,
+ });
+
+ docWithBasicOpts._layout_hideScroll = true;
+
+ return docWithBasicOpts;
+ };
+
+ public static ImageField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, content: string, opts: FieldOpts) => {
+ const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
+
+ const doc = Docs.Create.ImageDocument(content, {
+ isDefaultTemplateDoc: true,
+ _height: height,
+ _width: width,
+ title: title,
+ x: coord.x,
+ y: coord.y,
+ _layout_fitWidth: false,
+ backgroundColor: opts.backgroundColor ?? '',
+ _layout_borderRounding: `${opts.cornerRounding ?? 0}px`,
+ borderColor: opts.borderColor,
+ borderWidth: opts.borderWidth,
+ opacity: opts.opacity,
+ _rotation: opts.rotation,
+ });
+
+ //setTimeout(() => {doc._height = height; doc._width = width}, 10);
+
+ return doc;
+ };
+
+ public static CarouselField = (coords: { tl: [number, number]; br: [number, number] }, parentWidth: number, parentHeight: number, title: string, fields: Doc[]) => {
+ const { width, height, coord } = FieldUtils.getDimensions(coords, parentWidth, parentHeight);
+
+ const doc = Docs.Create.Carousel3DDocument(fields, { _height: height, _width: width, title: title, x: coord.x, y: coord.y, _text_fontSize: `${height / 2}` });
+
+ return doc;
+ };
+}
+
+// public static FourField002: TemplateDocInfos = {
+// width: 450,
+// height: 600,
+// fields: [{
+// tl: [-.6, -.9],
+// br: [.6, -.8],
+// types: [FieldType.TEXT],
+// sizes: [FieldSize.TINY]
+// }, {
+// tl: [-.9, -.7],
+// br: [.9, .2],
+// types: [FieldType.TEXT, FieldType.VISUAL],
+// sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE]
+// }, {
+// tl: [-.9, .3],
+// br: [-.05, .9],
+// types: [FieldType.TEXT],
+// sizes: [FieldSize.TINY]
+// }, {
+// tl: [.05, .3],
+// br: [.9, .9],
+// types: [FieldType.TEXT, FieldType.VISUAL],
+// sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE]
+// }]
+// };
+
+// public static TwoFieldPlusCarousel: TemplateDocInfos = {
+// width: 500,
+// height: 600,
+// fields: [{
+// tl: [-.9, -.99],
+// br: [.9, -.7],
+// types: [FieldType.TEXT],
+// sizes: [FieldSize.TINY]
+// }, {
+// tl: [-.9, -.65],
+// br: [.9, .35],
+// types: [],
+// sizes: []
+// }, {
+// tl: [-.9, .4],
+// br: [.9, .95],
+// types: [FieldType.TEXT],
+// sizes: [FieldSize.TINY]
+// }]
+// };
+// }
+
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 226fad977..c156c80e4 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -124,15 +124,15 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
{ fireImmediately: true, delay: 1000 }
);
const { layoutDoc } = this;
- // this._disposers.path = reaction(
- // () => ({ nativeSize: this.nativeSize, width: NumCast(this.layoutDoc._width) }),
- // ({ nativeSize, width }) => {
- // if (layoutDoc === this.layoutDoc || !this.layoutDoc._height) {
- // this.layoutDoc._height = (width * nativeSize.nativeHeight) / nativeSize.nativeWidth;
- // }
- // },
- // { fireImmediately: true }
- // );
+ this._disposers.path = reaction(
+ () => ({ nativeSize: this.nativeSize, width: NumCast(this.layoutDoc._width) }),
+ ({ nativeSize, width }) => {
+ if (layoutDoc === this.layoutDoc || !this.layoutDoc._height) {
+ this.layoutDoc._height = (width * nativeSize.nativeHeight) / nativeSize.nativeWidth;
+ }
+ },
+ { fireImmediately: true }
+ );
this._disposers.scroll = reaction(
() => this.layoutDoc.layout_scrollTop,
sTop => {