Trims default false boolean props

This should reduce the size of files / saves, for example.
This commit is contained in:
Steve Ruiz 2021-07-04 09:47:37 +01:00
parent 17940d82d6
commit 48c659a68a
26 changed files with 24 additions and 155 deletions

View file

@ -17,10 +17,7 @@ Array [
Object {
"childIndex": 1,
"id": "test-draw",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test draw",
"parentId": "page1",
"point": Array [
@ -58,10 +55,7 @@ Array [
Object {
"childIndex": 1,
"id": "test-rectangle",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test Rectangle",
"parentId": "page1",
"point": Array [
@ -90,10 +84,7 @@ Array [
Object {
"childIndex": 1,
"id": "test-text",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test text",
"parentId": "page1",
"point": Array [
@ -151,10 +142,7 @@ Array [
},
},
"id": "test-draw",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test draw",
"parentId": "page1",
"point": Array [
@ -192,10 +180,7 @@ Array [
Object {
"childIndex": 1,
"id": "test-ellipse",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test ellipse",
"parentId": "page1",
"point": Array [
@ -221,10 +206,7 @@ Array [
Object {
"childIndex": 1,
"id": "test-rectangle",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test Rectangle",
"parentId": "page1",
"point": Array [
@ -274,10 +256,7 @@ exports[`selection updates a code control: rectangle in state after changing cod
Object {
"childIndex": 1,
"id": "test-rectangle",
"isAspectRatioLocked": false,
"isGenerated": true,
"isHidden": false,
"isLocked": false,
"name": "Test Rectangle",
"parentId": "page1",
"point": Array [

View file

@ -74,7 +74,6 @@ interface BaseShape {
type: ShapeType
parentId: string
childIndex: number
isGenerated: boolean
name: string
point: number[]
style: ShapeStyles
@ -82,9 +81,11 @@ interface BaseShape {
children?: string[]
bindings?: Record<string, ShapeBinding>
handles?: Record<string, ShapeHandle>
isLocked: boolean
isHidden: boolean
isAspectRatioLocked: boolean
isLocked?: boolean
isHidden?: boolean
isEditing?: boolean
isGenerated?: boolean
isAspectRatioLocked?: boolean
}
interface DotShape extends BaseShape {
@ -641,7 +642,6 @@ interface BaseShape {
type: ShapeType
parentId: string
childIndex: number
isGenerated: boolean
name: string
point: number[]
style: ShapeStyles
@ -649,9 +649,11 @@ interface BaseShape {
children?: string[]
bindings?: Record<string, ShapeBinding>
handles?: Record<string, ShapeHandle>
isLocked: boolean
isHidden: boolean
isAspectRatioLocked: boolean
isLocked?: boolean
isHidden?: boolean
isEditing?: boolean
isGenerated?: boolean
isAspectRatioLocked?: boolean
}
interface DotShape extends BaseShape {
@ -1497,7 +1499,7 @@ type RequiredKeys<T> = {
}
static round = (a: number[], d = 5): number[] => {
return a.map((v) => Number(v.toPrecision(d)))
return a.map((v) => +v.toPrecision(d))
}
/**
@ -2816,7 +2818,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<DotShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Dot,
isGenerated: true,
@ -2824,9 +2825,6 @@ type RequiredKeys<T> = {
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,
@ -2853,9 +2851,6 @@ type RequiredKeys<T> = {
radiusX: 50,
radiusY: 50,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: { ...defaultStyle, ...props.style },
})
@ -2903,7 +2898,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<LineShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Line,
isGenerated: true,
@ -2912,9 +2906,6 @@ type RequiredKeys<T> = {
point: [0, 0],
direction: [-0.5, 0.5],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,
@ -2948,7 +2939,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<PolylineShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Polyline,
isGenerated: true,
@ -2957,9 +2947,6 @@ type RequiredKeys<T> = {
point: [0, 0],
points: [[0, 0]],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,
@ -3005,7 +2992,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<RayShape>) {
super({
id: uniqueId(),
type: ShapeType.Ray,
isGenerated: true,
name: 'Ray',
@ -3014,9 +3000,6 @@ type RequiredKeys<T> = {
point: [0, 0],
direction: [0, 1],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,
@ -3050,7 +3033,7 @@ type RequiredKeys<T> = {
constructor(
props = {} as ShapeProps<ArrowShape> & { start: number[]; end: number[] }
) {
const { start = [0, 0], end = [0, 0] } = props
const { start = [0, 0], end = [100, 100] } = props
const {
point = [0, 0],
@ -3075,17 +3058,12 @@ type RequiredKeys<T> = {
super({
id: uniqueId(),
type: ShapeType.Arrow,
isGenerated: false,
name: 'Arrow',
parentId: 'page1',
childIndex: 0,
point,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
bend: 0,
handles,
decorations: {
@ -3171,18 +3149,13 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<DrawShape>) {
super({
id: uniqueId(),
type: ShapeType.Draw,
isGenerated: false,
parentId: (window as any).currentPageId,
name: 'Draw',
childIndex: 0,
point: [0, 0],
points: [],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,
@ -3228,7 +3201,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<TextShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Text,
isGenerated: true,
@ -3236,9 +3208,6 @@ type RequiredKeys<T> = {
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
text: 'Text',
scale: 1,
...props,
@ -3291,7 +3260,6 @@ type RequiredKeys<T> = {
constructor(props = {} as ShapeProps<RectangleShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Rectangle,
isGenerated: true,
@ -3301,9 +3269,6 @@ type RequiredKeys<T> = {
size: [100, 100],
rotation: 0,
radius: 2,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -11,7 +11,7 @@ export default class Arrow extends CodeShape<ArrowShape> {
constructor(
props = {} as ShapeProps<ArrowShape> & { start: number[]; end: number[] }
) {
const { start = [0, 0], end = [0, 0] } = props
const { start = [0, 0], end = [100, 100] } = props
const {
point = [0, 0],
@ -36,17 +36,12 @@ export default class Arrow extends CodeShape<ArrowShape> {
super({
id: uniqueId(),
type: ShapeType.Arrow,
isGenerated: false,
name: 'Arrow',
parentId: 'page1',
childIndex: 0,
point,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
bend: 0,
handles,
decorations: {

View file

@ -9,7 +9,6 @@ export default class Dot extends CodeShape<DotShape> {
constructor(props = {} as ShapeProps<DotShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Dot,
isGenerated: true,
@ -17,9 +16,6 @@ export default class Dot extends CodeShape<DotShape> {
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -9,18 +9,13 @@ export default class Draw extends CodeShape<DrawShape> {
constructor(props = {} as ShapeProps<DrawShape>) {
super({
id: uniqueId(),
type: ShapeType.Draw,
isGenerated: false,
parentId: (window as any).currentPageId,
name: 'Draw',
childIndex: 0,
point: [0, 0],
points: [],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -18,9 +18,6 @@ export default class Ellipse extends CodeShape<EllipseShape> {
radiusX: 50,
radiusY: 50,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: { ...defaultStyle, ...props.style },
})

View file

@ -9,7 +9,6 @@ export default class Line extends CodeShape<LineShape> {
constructor(props = {} as ShapeProps<LineShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Line,
isGenerated: true,
@ -18,9 +17,6 @@ export default class Line extends CodeShape<LineShape> {
point: [0, 0],
direction: [-0.5, 0.5],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -9,7 +9,6 @@ export default class Polyline extends CodeShape<PolylineShape> {
constructor(props = {} as ShapeProps<PolylineShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Polyline,
isGenerated: true,
@ -18,9 +17,6 @@ export default class Polyline extends CodeShape<PolylineShape> {
point: [0, 0],
points: [[0, 0]],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -9,7 +9,6 @@ export default class Ray extends CodeShape<RayShape> {
constructor(props = {} as ShapeProps<RayShape>) {
super({
id: uniqueId(),
type: ShapeType.Ray,
isGenerated: true,
name: 'Ray',
@ -18,9 +17,6 @@ export default class Ray extends CodeShape<RayShape> {
point: [0, 0],
direction: [0, 1],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -10,7 +10,6 @@ export default class Rectangle extends CodeShape<RectangleShape> {
constructor(props = {} as ShapeProps<RectangleShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Rectangle,
isGenerated: true,
@ -20,9 +19,6 @@ export default class Rectangle extends CodeShape<RectangleShape> {
size: [100, 100],
rotation: 0,
radius: 2,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
...props,
style: {
...defaultStyle,

View file

@ -10,7 +10,6 @@ export default class Text extends CodeShape<TextShape> {
constructor(props = {} as ShapeProps<TextShape>) {
super({
id: uniqueId(),
parentId: (window as any).currentPageId,
type: ShapeType.Text,
isGenerated: true,
@ -18,9 +17,6 @@ export default class Text extends CodeShape<TextShape> {
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
text: 'Text',
scale: 1,
...props,

View file

@ -16,7 +16,6 @@ export default function duplicateCommand(data: Data): void {
shape.point,
vec.div([16, 16], tld.getCurrentCamera(data).zoom)
),
isGenerated: false,
}))
history.execute(

View file

@ -52,7 +52,6 @@ export default function pasteCommand(data: Data, initialShapes: Shape[]): void {
parentId: oldSelectedIds[shape.parentId] || data.currentPageId,
childIndex: childIndex++,
point: vec.add(topLeft, topLeftOffset),
isGenerated: false,
}
}

View file

@ -39,7 +39,9 @@ export default class TransformSingleSession extends BaseSession {
transformType,
vec.vec(this.origin, point),
shape.rotation,
isAspectRatioLocked || !getShapeUtils(initialShape).canChangeAspectRatio
isAspectRatioLocked ||
shape.isAspectRatioLocked ||
!getShapeUtils(initialShape).canChangeAspectRatio
)
this.scaleX = newBoundingBox.scaleX

View file

@ -208,7 +208,6 @@ export function getTranslateSnapshot(data: Data) {
id: uniqueId(),
parentId: shape.parentId,
childIndex: tld.getChildIndexAbove(data, shape.id),
isGenerated: false,
}
return clone

View file

@ -42,15 +42,13 @@ const arrow = registerShapeUtils<ArrowShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Arrow,
isGenerated: false,
name: 'Arrow',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
bend: 0,
handles: {
start: {

View file

@ -11,15 +11,11 @@ const dot = registerShapeUtils<DotShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Dot,
isGenerated: false,
name: 'Dot',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -26,16 +26,13 @@ const draw = registerShapeUtils<DrawShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Draw,
isGenerated: false,
name: 'Draw',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
points: [],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -24,7 +24,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Ellipse,
isGenerated: false,
name: 'Ellipse',
parentId: 'page1',
childIndex: 0,
@ -32,9 +31,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
radiusX: 1,
radiusY: 1,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -15,16 +15,12 @@ const group = registerShapeUtils<GroupShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Group,
isGenerated: false,
name: 'Group',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
size: [1, 1],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
children: [],
},

View file

@ -13,16 +13,12 @@ const line = registerShapeUtils<LineShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Line,
isGenerated: false,
name: 'Line',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
direction: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -16,16 +16,12 @@ const polyline = registerShapeUtils<PolylineShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Polyline,
isGenerated: false,
name: 'Polyline',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
points: [[0, 0]],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -13,16 +13,12 @@ const ray = registerShapeUtils<RayShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Ray,
isGenerated: false,
name: 'Ray',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
direction: [0, 1],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -13,9 +13,7 @@ const rectangle = registerShapeUtils<RectangleShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Rectangle,
isGenerated: false,
name: 'Rectangle',
parentId: 'page1',
childIndex: 0,
@ -23,9 +21,6 @@ const rectangle = registerShapeUtils<RectangleShape>({
size: [1, 1],
radius: 2,
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
},

View file

@ -56,15 +56,11 @@ const text = registerShapeUtils<TextShape>({
defaultProps: {
id: uniqueId(),
type: ShapeType.Text,
isGenerated: false,
name: 'Text',
parentId: 'page1',
childIndex: 0,
point: [0, 0],
rotation: 0,
isAspectRatioLocked: false,
isLocked: false,
isHidden: false,
style: defaultStyle,
text: '',
scale: 1,

View file

@ -133,7 +133,6 @@ export interface BaseShape {
type: ShapeType
parentId: string
childIndex: number
isGenerated: boolean
name: string
point: number[]
style: ShapeStyles
@ -141,9 +140,11 @@ export interface BaseShape {
children?: string[]
bindings?: Record<string, ShapeBinding>
handles?: Record<string, ShapeHandle>
isLocked: boolean
isHidden: boolean
isAspectRatioLocked: boolean
isLocked?: boolean
isHidden?: boolean
isEditing?: boolean
isGenerated?: boolean
isAspectRatioLocked?: boolean
}
export interface DotShape extends BaseShape {