Write tests, slight tweaks to build / packages
This commit is contained in:
parent
146eb87fb1
commit
183f9cd798
11 changed files with 37 additions and 37 deletions
|
@ -21,7 +21,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start:pre": "node scripts/pre-dev && yarn types:pre",
|
"start:pre": "node scripts/pre-dev && yarn types:pre",
|
||||||
"start": "node scripts/dev & yarn types:dev",
|
"start": "node scripts/dev & yarn types:dev",
|
||||||
"build": "yarn clean && node scripts/build && yarn types:build",
|
"build": "node scripts/build && yarn types:build",
|
||||||
"types:pre": "tsc",
|
"types:pre": "tsc",
|
||||||
"types:dev": "tsc --watch ",
|
"types:dev": "tsc --watch ",
|
||||||
"types:build": "tsc --project tsconfig.build.json",
|
"types:build": "tsc --project tsconfig.build.json",
|
||||||
|
@ -58,4 +58,4 @@
|
||||||
"deepmerge": "^4.2.2",
|
"deepmerge": "^4.2.2",
|
||||||
"react-use-gesture": "^9.1.3"
|
"react-use-gesture": "^9.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,8 +5,12 @@ const esbuild = require('esbuild')
|
||||||
const name = process.env.npm_package_name || ''
|
const name = process.env.npm_package_name || ''
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!fs.existsSync('./dist')) {
|
if (fs.existsSync('./dist')) {
|
||||||
fs.mkdirSync('./dist')
|
fs.rmSync('./dist', { recursive: true }, (e) => {
|
||||||
|
if (e) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,12 +11,6 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.mkdir('./dist', (e) => {
|
|
||||||
if (e) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
esbuild.build({
|
esbuild.build({
|
||||||
entryPoints: ['./src/index.ts'],
|
entryPoints: ['./src/index.ts'],
|
||||||
outdir: 'dist/cjs',
|
outdir: 'dist/cjs',
|
||||||
|
|
|
@ -11,10 +11,9 @@
|
||||||
"docs"
|
"docs"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"composite": false,
|
||||||
"incremental": false,
|
"incremental": false,
|
||||||
"emitDeclarationOnly": true,
|
|
||||||
"declarationMap": false,
|
"declarationMap": false,
|
||||||
"sourceMap": false,
|
"sourceMap": false
|
||||||
"outDir": "./dist/types"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { TLDraw, TLDrawShapeType, TLDrawState } from '@tldraw/tldraw'
|
import { TLDraw, TLDrawState } from '@tldraw/tldraw'
|
||||||
|
|
||||||
export default function Editor(): JSX.Element {
|
export default function Editor(): JSX.Element {
|
||||||
const rTLDrawState = React.useRef<TLDrawState>()
|
const rTLDrawState = React.useRef<TLDrawState>()
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start:pre": "node scripts/pre-dev && yarn types:pre",
|
"start:pre": "node scripts/pre-dev && yarn types:pre",
|
||||||
"start": "node scripts/dev & yarn types:dev",
|
"start": "node scripts/dev & yarn types:dev",
|
||||||
"build": "yarn clean && node scripts/build && yarn types:build",
|
"build": "node scripts/build && yarn types:build",
|
||||||
"types:pre": "tsc",
|
"types:pre": "tsc",
|
||||||
"types:dev": "tsc --watch",
|
"types:dev": "tsc --watch",
|
||||||
"types:build": "tsc --project tsconfig.build.json",
|
"types:build": "tsc --project tsconfig.build.json",
|
||||||
|
|
|
@ -5,8 +5,12 @@ const esbuild = require('esbuild')
|
||||||
const name = process.env.npm_package_name || ''
|
const name = process.env.npm_package_name || ''
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!fs.existsSync('./dist')) {
|
if (fs.existsSync('./dist')) {
|
||||||
fs.mkdirSync('./dist')
|
fs.rmSync('./dist', { recursive: true }, (e) => {
|
||||||
|
if (e) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,12 +11,6 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.mkdir('./dist', (e) => {
|
|
||||||
if (e) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
esbuild.build({
|
esbuild.build({
|
||||||
entryPoints: ['./src/index.ts'],
|
entryPoints: ['./src/index.ts'],
|
||||||
outdir: 'dist/cjs',
|
outdir: 'dist/cjs',
|
||||||
|
|
|
@ -254,13 +254,14 @@ export class Text extends TLDrawShapeUtil<TextShape> {
|
||||||
const bounds = Utils.getFromCache(this.boundsCache, shape, () => {
|
const bounds = Utils.getFromCache(this.boundsCache, shape, () => {
|
||||||
if (!melm) {
|
if (!melm) {
|
||||||
// We're in SSR
|
// We're in SSR
|
||||||
return { minX: 0, minY: 0, maxX: 10, maxY: 0, width: 0, height: 0 }
|
return { minX: 0, minY: 0, maxX: 10, maxY: 10, width: 10, height: 10 }
|
||||||
}
|
}
|
||||||
|
|
||||||
melm.innerHTML = `${shape.text}‍`
|
melm.innerHTML = `${shape.text}‍`
|
||||||
melm.style.font = getFontStyle(shape.style)
|
melm.style.font = getFontStyle(shape.style)
|
||||||
|
|
||||||
const [width, height] = [melm.offsetWidth, melm.offsetHeight]
|
// In tests, offsetWidth and offsetHeight will be 0
|
||||||
|
const [width, height] = [melm.offsetWidth || 1, melm.offsetHeight || 1]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
minX: 0,
|
minX: 0,
|
||||||
|
|
|
@ -41,18 +41,23 @@ describe('Reset bounds command', () => {
|
||||||
|
|
||||||
tlstate.resetBounds(['text1'])
|
tlstate.resetBounds(['text1'])
|
||||||
|
|
||||||
const newScale = tlstate.getShape('text1').style.scale
|
// The scale should be back to 1
|
||||||
const newBounds = TLDR.getBounds(tlstate.getShape('text1'))
|
expect(tlstate.getShape('text1').style.scale).toBe(1)
|
||||||
const newCenter = Utils.getBoundsCenter(newBounds)
|
// The centers should be the same
|
||||||
|
expect(Utils.getBoundsCenter(TLDR.getBounds(tlstate.getShape('text1')))).toStrictEqual(center)
|
||||||
console.log(newScale)
|
|
||||||
|
|
||||||
expect(newScale).toBe(1)
|
|
||||||
|
|
||||||
expect(newCenter).toStrictEqual(center) // The centers should be the same
|
|
||||||
|
|
||||||
tlstate.undo()
|
tlstate.undo()
|
||||||
|
|
||||||
|
// The scale should be what it was before
|
||||||
|
expect(tlstate.getShape('text1').style.scale).not.toBe(1)
|
||||||
|
// The centers should be the same
|
||||||
|
expect(Utils.getBoundsCenter(TLDR.getBounds(tlstate.getShape('text1')))).toStrictEqual(center)
|
||||||
|
|
||||||
tlstate.redo()
|
tlstate.redo()
|
||||||
|
|
||||||
|
// The scale should be back to 1
|
||||||
|
expect(tlstate.getShape('text1').style.scale).toBe(1)
|
||||||
|
// The centers should be the same
|
||||||
|
expect(Utils.getBoundsCenter(TLDR.getBounds(tlstate.getShape('text1')))).toStrictEqual(center)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,10 +11,9 @@
|
||||||
"docs"
|
"docs"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"composite": false,
|
||||||
"incremental": false,
|
"incremental": false,
|
||||||
"sourceMap": false,
|
|
||||||
"emitDeclarationOnly": true,
|
|
||||||
"declarationMap": false,
|
"declarationMap": false,
|
||||||
"outDir": "./dist/types"
|
"sourceMap": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue