DEPLOYED!

This commit is contained in:
Orion Reed 2024-07-20 00:04:41 +02:00
parent 7ea8bb96b2
commit ac5d5ce29f
5 changed files with 29 additions and 11 deletions

View File

@ -5,7 +5,7 @@ import { AgentButton } from "./components/AgentButton";
import { SocialShapeUtil } from "./SocialShapeUtil"; import { SocialShapeUtil } from "./SocialShapeUtil";
import { SocialShapeTool } from "./SocialShapeTool"; import { SocialShapeTool } from "./SocialShapeTool";
import { CustomToolbar, overrides } from "./ui"; import { CustomToolbar, overrides } from "./ui";
import { getDocumentMeta, getUserId, getUsersInRoom, setDocumentMeta } from "./storeUtils"; // import { getDocumentMeta, getUserId, getUsersInRoom, setDocumentMeta } from "./storeUtils";
import { registerDefaultPropagators } from "./propagators/ScopedPropagators"; import { registerDefaultPropagators } from "./propagators/ScopedPropagators";
const shapeUtils = [SocialShapeUtil]; const shapeUtils = [SocialShapeUtil];

View File

@ -7,7 +7,6 @@ import {
TLOnResizeHandler, TLOnResizeHandler,
TLShapeId, TLShapeId,
resizeBox, resizeBox,
toDomPrecision,
} from 'tldraw' } from 'tldraw'
import { getUserId } from './storeUtils' import { getUserId } from './storeUtils'
@ -90,7 +89,11 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
return ( return (
<HTMLContainer style={{ padding: 4, borderRadius: 4, border: '1px solid #ccc', outline: shape.props.syntaxError ? '2px solid orange' : 'none' }} onPointerDown={(e) => e.stopPropagation()}> <HTMLContainer style={{ padding: 4, borderRadius: 4, border: '1px solid #ccc', outline: shape.props.syntaxError ? '2px solid orange' : 'none' }} onPointerDown={(e) => e.stopPropagation()}>
<textarea style={{ width: '100%', height: '50%', border: 'none', outline: 'none', resize: 'none', pointerEvents: 'all' }} value={shape.props.text} onChange={(e) => handleTextChange(e.target.value)} /> <textarea style={{ width: '100%', height: '50%', border: 'none', outline: 'none', resize: 'none', pointerEvents: 'all' }} value={shape.props.text} onChange={(e) => handleTextChange(e.target.value)} />
<ValueInterface type={shape.props.valueType ?? null} value={shape.props.values[currentUser] ?? defaultValues[shape.props.valueType ?? 'DEFAULT']} values={shape.props.values} onChange={handleOnChange} /> <ValueInterface
type={shape.props.valueType ?? null}
value={shape.props.values[currentUser] ?? defaultValues[shape.props.valueType as keyof typeof defaultValues]}
values={shape.props.values}
onChange={handleOnChange} />
</HTMLContainer> </HTMLContainer>
) )
} }
@ -110,6 +113,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
return (vals as number[]).reduce((acc, val) => acc + val, 0) return (vals as number[]).reduce((acc, val) => acc + val, 0)
} }
if (valueType === 'BOOLEAN') { if (valueType === 'BOOLEAN') {
//@ts-ignore
return vals.filter(Boolean).length; return vals.filter(Boolean).length;
} }
} }
@ -118,6 +122,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
return (vals as number[]).reduce((acc, val) => acc + val, 0) / vals.length return (vals as number[]).reduce((acc, val) => acc + val, 0) / vals.length
} }
if (valueType === 'BOOLEAN') { if (valueType === 'BOOLEAN') {
//@ts-ignore
return vals.filter(Boolean).length; return vals.filter(Boolean).length;
} }
} }
@ -146,12 +151,12 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
} }
} }
function ValueInterface({ type, value, values, onChange }: { type: ValueType; value: any; values: Record<string, any>; onChange: (value: any) => void }) { function ValueInterface({ type, value, values, onChange }: { type: ValueType; value: boolean | number | string; values: Record<string, any>; onChange: (value: any) => void }) {
switch (type) { switch (type) {
case 'BOOLEAN': case 'BOOLEAN':
return <> return <>
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', gap: '4px' }}> <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', gap: '4px' }}>
<input style={{ pointerEvents: 'all', width: '20px', height: '20px', margin: 0 }} type="checkbox" value={value} onChange={(e) => onChange(e.target.checked)} /> <input style={{ pointerEvents: 'all', width: '20px', height: '20px', margin: 0 }} type="checkbox" checked={value as boolean} onChange={(e) => onChange(e.target.checked)} />
<div style={{ width: '1px', height: '20px', backgroundColor: 'grey' }} /> <div style={{ width: '1px', height: '20px', backgroundColor: 'grey' }} />
{Object.values(values).map((bool, i) => ( {Object.values(values).map((bool, i) => (
<div key={`boolean-${i}`} style={{ backgroundColor: bool ? 'blue' : 'white', width: '20px', height: '20px', border: '1px solid lightgrey', borderRadius: 2 }} /> <div key={`boolean-${i}`} style={{ backgroundColor: bool ? 'blue' : 'white', width: '20px', height: '20px', border: '1px solid lightgrey', borderRadius: 2 }} />
@ -166,11 +171,11 @@ function ValueInterface({ type, value, values, onChange }: { type: ValueType; va
min="0" min="0"
max="1" max="1"
step="0.01" step="0.01"
value={value ?? 0} value={value as number ?? 0}
onChange={(e) => onChange(parseFloat(e.target.value))} onChange={(e) => onChange(parseFloat(e.target.value))}
style={{ width: '100px', pointerEvents: 'all' }} style={{ width: '100px', pointerEvents: 'all' }}
/> />
<span style={{ fontFamily: 'monospace' }}>{(value ?? 0).toFixed(2)}</span> <span style={{ fontFamily: 'monospace' }}>{(value as number ?? 0).toFixed(2)}</span>
<div style={{ width: '1px', height: '20px', backgroundColor: 'grey' }} /> <div style={{ width: '1px', height: '20px', backgroundColor: 'grey' }} />
{Object.values(values).map((val, i) => ( {Object.values(values).map((val, i) => (
<div <div

View File

@ -1,3 +1,4 @@
//@ts-nocheck
import { SpatialIndex } from "./SpatialIndex" import { SpatialIndex } from "./SpatialIndex"
import { Editor, TLShape, TLShapeId, VecLike, polygonsIntersect } from "tldraw" import { Editor, TLShape, TLShapeId, VecLike, polygonsIntersect } from "tldraw"

View File

@ -1,3 +1,4 @@
//@ts-nocheck
import { DeltaTime } from "./DeltaTime" import { DeltaTime } from "./DeltaTime"
import { Geo } from "./Geo" import { Geo } from "./Geo"
import { Edge, getArrowsFromShape, getEdge } from "./tlgraph" import { Edge, getArrowsFromShape, getEdge } from "./tlgraph"
@ -30,7 +31,7 @@ class ArrowFunctionCache {
private cache: Map<string, Function | null> = new Map<string, Function | null>() private cache: Map<string, Function | null> = new Map<string, Function | null>()
/** returns undefined if the function could not be found or created */ /** returns undefined if the function could not be found or created */
get(editor: Editor, edge: Edge, prefix: Prefix): Function | undefined { get(editor: Editor, edge: Edge, prefix: Prefix): Function | undefined | null {
if (this.cache.has(edge.arrowId)) { if (this.cache.has(edge.arrowId)) {
return this.cache.get(edge.arrowId) return this.cache.get(edge.arrowId)
} }
@ -75,8 +76,9 @@ const packShape = (shape: TLShape) => {
const unpackShape = (shape: any) => { const unpackShape = (shape: any) => {
const { id, type, x, y, rotation, m, ...props } = shape const { id, type, x, y, rotation, m, ...props } = shape
const cast = (prop: any, constructor: (value: any) => any) => { //@ts-ignore
return prop !== undefined ? constructor(prop) : undefined; const cast = (prop: any, ctor: (value: any) => any) => {
return prop !== undefined ? ctor(prop) : undefined;
}; };
return { return {
id, id,
@ -87,6 +89,14 @@ const unpackShape = (shape: any) => {
props: { props: {
...props, ...props,
text: cast(props.text, String), text: cast(props.text, String),
w: cast(props.w, (value) => {
const num = Number(value);
return Number.isNaN(num) || num === 0 ? 1 : num;
}),
h: cast(props.h, (value) => {
const num = Number(value);
return Number.isNaN(num) || num === 0 ? 1 : num;
}),
}, },
meta: m, meta: m,
} }
@ -161,7 +171,7 @@ export abstract class Propagator {
protected arrowFunctionCache: ArrowFunctionCache = new ArrowFunctionCache() protected arrowFunctionCache: ArrowFunctionCache = new ArrowFunctionCache()
protected editor: Editor protected editor: Editor
protected geo: Geo protected geo: Geo
protected validateOnArrowChange: boolean = false protected validateOnArrowChange = false
constructor(editor: Editor) { constructor(editor: Editor) {
this.editor = editor this.editor = editor
@ -234,6 +244,7 @@ export abstract class Propagator {
/** called after every shape change */ /** called after every shape change */
afterChangeHandler?(editor: Editor, next: TLShape): void afterChangeHandler?(editor: Editor, next: TLShape): void
/** called on every editor event */ /** called on every editor event */
//@ts-ignore
eventHandler?(event: any): void eventHandler?(event: any): void
/** called every tick */ /** called every tick */
tickHandler?(): void tickHandler?(): void

View File

@ -1,3 +1,4 @@
//@ts-nocheck
import { RESET_VALUE, computed, isUninitialized } from '@tldraw/state' import { RESET_VALUE, computed, isUninitialized } from '@tldraw/state'
import { TLPageId, TLShapeId, isShape, isShapeId } from '@tldraw/tlschema' import { TLPageId, TLShapeId, isShape, isShapeId } from '@tldraw/tlschema'
import RBush from 'rbush' import RBush from 'rbush'