DEPLOYED!
This commit is contained in:
parent
7ea8bb96b2
commit
ac5d5ce29f
|
|
@ -5,7 +5,7 @@ import { AgentButton } from "./components/AgentButton";
|
|||
import { SocialShapeUtil } from "./SocialShapeUtil";
|
||||
import { SocialShapeTool } from "./SocialShapeTool";
|
||||
import { CustomToolbar, overrides } from "./ui";
|
||||
import { getDocumentMeta, getUserId, getUsersInRoom, setDocumentMeta } from "./storeUtils";
|
||||
// import { getDocumentMeta, getUserId, getUsersInRoom, setDocumentMeta } from "./storeUtils";
|
||||
import { registerDefaultPropagators } from "./propagators/ScopedPropagators";
|
||||
|
||||
const shapeUtils = [SocialShapeUtil];
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
TLOnResizeHandler,
|
||||
TLShapeId,
|
||||
resizeBox,
|
||||
toDomPrecision,
|
||||
} from 'tldraw'
|
||||
import { getUserId } from './storeUtils'
|
||||
|
||||
|
|
@ -90,7 +89,11 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
|
|||
return (
|
||||
<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)} />
|
||||
<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>
|
||||
)
|
||||
}
|
||||
|
|
@ -110,6 +113,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
|
|||
return (vals as number[]).reduce((acc, val) => acc + val, 0)
|
||||
}
|
||||
if (valueType === 'BOOLEAN') {
|
||||
//@ts-ignore
|
||||
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
|
||||
}
|
||||
if (valueType === 'BOOLEAN') {
|
||||
//@ts-ignore
|
||||
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) {
|
||||
case 'BOOLEAN':
|
||||
return <>
|
||||
<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' }} />
|
||||
{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 }} />
|
||||
|
|
@ -166,11 +171,11 @@ function ValueInterface({ type, value, values, onChange }: { type: ValueType; va
|
|||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={value ?? 0}
|
||||
value={value as number ?? 0}
|
||||
onChange={(e) => onChange(parseFloat(e.target.value))}
|
||||
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' }} />
|
||||
{Object.values(values).map((val, i) => (
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//@ts-nocheck
|
||||
import { SpatialIndex } from "./SpatialIndex"
|
||||
import { Editor, TLShape, TLShapeId, VecLike, polygonsIntersect } from "tldraw"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//@ts-nocheck
|
||||
import { DeltaTime } from "./DeltaTime"
|
||||
import { Geo } from "./Geo"
|
||||
import { Edge, getArrowsFromShape, getEdge } from "./tlgraph"
|
||||
|
|
@ -30,7 +31,7 @@ class ArrowFunctionCache {
|
|||
private cache: Map<string, Function | null> = new Map<string, Function | null>()
|
||||
|
||||
/** 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)) {
|
||||
return this.cache.get(edge.arrowId)
|
||||
}
|
||||
|
|
@ -75,8 +76,9 @@ const packShape = (shape: TLShape) => {
|
|||
|
||||
const unpackShape = (shape: any) => {
|
||||
const { id, type, x, y, rotation, m, ...props } = shape
|
||||
const cast = (prop: any, constructor: (value: any) => any) => {
|
||||
return prop !== undefined ? constructor(prop) : undefined;
|
||||
//@ts-ignore
|
||||
const cast = (prop: any, ctor: (value: any) => any) => {
|
||||
return prop !== undefined ? ctor(prop) : undefined;
|
||||
};
|
||||
return {
|
||||
id,
|
||||
|
|
@ -87,6 +89,14 @@ const unpackShape = (shape: any) => {
|
|||
props: {
|
||||
...props,
|
||||
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,
|
||||
}
|
||||
|
|
@ -161,7 +171,7 @@ export abstract class Propagator {
|
|||
protected arrowFunctionCache: ArrowFunctionCache = new ArrowFunctionCache()
|
||||
protected editor: Editor
|
||||
protected geo: Geo
|
||||
protected validateOnArrowChange: boolean = false
|
||||
protected validateOnArrowChange = false
|
||||
|
||||
constructor(editor: Editor) {
|
||||
this.editor = editor
|
||||
|
|
@ -234,6 +244,7 @@ export abstract class Propagator {
|
|||
/** called after every shape change */
|
||||
afterChangeHandler?(editor: Editor, next: TLShape): void
|
||||
/** called on every editor event */
|
||||
//@ts-ignore
|
||||
eventHandler?(event: any): void
|
||||
/** called every tick */
|
||||
tickHandler?(): void
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//@ts-nocheck
|
||||
import { RESET_VALUE, computed, isUninitialized } from '@tldraw/state'
|
||||
import { TLPageId, TLShapeId, isShape, isShapeId } from '@tldraw/tlschema'
|
||||
import RBush from 'rbush'
|
||||
|
|
|
|||
Loading…
Reference in New Issue