-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Move to layer page when selecting a layer
fix #89
- Loading branch information
Michele
committed
Aug 29, 2019
1 parent
91a1228
commit d6e91cb
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ export enum LayerType { | |
shapePath = 'ShapePath', | ||
text = 'Text', | ||
shape = 'Shape', | ||
} | ||
document = 'Document', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import { Layer } from 'sketch'; | ||
import {getPage} from './get-page'; | ||
import { LayerType } from '../../resources/app/enums/layer-type.enum'; | ||
|
||
describe('getPage', () => { | ||
test('should return the layer if is a page', () => { | ||
const layer = { | ||
type: LayerType.page | ||
} | ||
|
||
expect(getPage(layer as Layer)).toBe(layer); | ||
}); | ||
|
||
test('should return the first parent page', () => { | ||
const page = { | ||
type: LayerType.page, | ||
parent: { | ||
type: LayerType.document | ||
} | ||
} | ||
const layer = { | ||
type: LayerType.shapePath, | ||
parent: { | ||
type: LayerType.artboard, | ||
parent: page | ||
} | ||
} | ||
|
||
expect(getPage(layer as Layer)).toBe(page); | ||
}); | ||
|
||
test('should throw an error if the layer has no parent page', () => { | ||
const layer = { | ||
type: LayerType.shapePath | ||
} | ||
|
||
expect(() => getPage(layer as Layer)).toThrow() | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Page, Layer } from 'sketch'; | ||
import { LayerType } from '../../resources/app/enums/layer-type.enum'; | ||
|
||
export const getPage = (layer: Layer): Page => { | ||
if (layer.type === LayerType.page) { | ||
return layer; | ||
} | ||
|
||
if (!layer.parent) { | ||
throw new Error(`Layer is not child on any page! ${JSON.stringify(layer, null, 2)}`); | ||
} | ||
|
||
return getPage(layer.parent as Layer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters