-
Notifications
You must be signed in to change notification settings - Fork 129
Code Review: Add support for slices in SketchAPI (#16184) #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f6b26f
add support for slices
mathieudutour 3c7f964
remove some properties where they should not be
mathieudutour 105fd08
bump test-runner version
mathieudutour c7f4bdb
add some docs
mathieudutour a918a8d
update changelog
mathieudutour 56c6fb6
Update CHANGELOG.json
bomberstudios ef880ce
fix conflicts
mathieudutour 9d4656e
Merge branch 'feature/16184' of github.com:BohemianCoding/SketchAPI i…
mathieudutour 1af3043
fix changelog
mathieudutour f459ba4
Merge branch 'develop' into feature/16184
mathieudutour d12c7ea
s/resizeToFitChildrenWithOption/fixGeometryWithOptions
mathieudutour a9b8545
fix conflicts
mathieudutour 212e217
fix test
mathieudutour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
import { DefinedPropertiesKey } from '../WrappedObject' | ||
import { Layer } from './Layer' | ||
import { Rectangle } from '../models/Rectangle' | ||
import { Types } from '../enums' | ||
import { Factory } from '../Factory' | ||
|
||
/** | ||
* Represents a slice. | ||
*/ | ||
export class Slice extends Layer { | ||
constructor(group = {}) { | ||
if (!group.sketchObject) { | ||
// eslint-disable-next-line no-param-reassign | ||
group.sketchObject = Factory.createNative(Slice) | ||
.alloc() | ||
.initWithFrame(new Rectangle(0, 0, 100, 100).asCGRect()) | ||
} | ||
|
||
super(group) | ||
} | ||
} | ||
|
||
Slice.type = Types.Slice | ||
Slice[DefinedPropertiesKey] = { ...Layer[DefinedPropertiesKey] } | ||
Factory.registerClass(Slice, MSSliceLayer) | ||
Factory.registerClass(Slice, MSImmutableSliceLayer) | ||
|
||
delete Slice[DefinedPropertiesKey].flow |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
/* globals expect, test */ | ||
|
||
import { Slice } from '../..' | ||
|
||
test('should create an slice', () => { | ||
const slice = new Slice({ name: 'Test' }) | ||
// check that an artboard can be logged | ||
log(slice) | ||
expect(slice.type).toBe('Slice') | ||
}) |
This file contains hidden or 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 hidden or 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,109 @@ | ||
import { DefinedPropertiesKey, WrappedObject } from '../WrappedObject' | ||
import { Types } from '../enums' | ||
import { Factory } from '../Factory' | ||
|
||
/** | ||
* An MSExportFormat. This is not exposed, only used by the exportOptions of the Layer | ||
*/ | ||
export class ExportFormat extends WrappedObject { | ||
constructor(exportFormat = {}) { | ||
if (!exportFormat.sketchObject) { | ||
// eslint-disable-next-line no-param-reassign | ||
exportFormat.sketchObject = MSExportFormat.formatWithScale_name_fileFormat( | ||
1, | ||
'', | ||
'png' | ||
) | ||
} | ||
|
||
super(exportFormat) | ||
} | ||
} | ||
|
||
ExportFormat.type = Types.ExportFormat | ||
ExportFormat[DefinedPropertiesKey] = { ...WrappedObject[DefinedPropertiesKey] } | ||
Factory.registerClass(ExportFormat, MSExportFormat) | ||
|
||
delete ExportFormat[DefinedPropertiesKey].id | ||
|
||
ExportFormat.define('fileFormat', { | ||
get() { | ||
return String(this._object.fileFormat()) | ||
}, | ||
set(fileFormat) { | ||
if (!MSExportFormat.validFormats().containsObject(fileFormat)) { | ||
throw new Error('File format not supported') | ||
} | ||
|
||
this._object.setFileFormat(fileFormat) | ||
}, | ||
}) | ||
|
||
ExportFormat.define('prefix', { | ||
get() { | ||
if (this._object.namingScheme() == 0) { | ||
// we have a suffix | ||
return undefined | ||
} | ||
return String(this._object.name()) | ||
}, | ||
set(name) { | ||
this._object.setNamingScheme(1) | ||
this._object.setName(name) | ||
}, | ||
}) | ||
|
||
ExportFormat.define('suffix', { | ||
get() { | ||
if (this._object.namingScheme() == 1) { | ||
// we have a prefix | ||
return undefined | ||
} | ||
return String(this._object.name()) | ||
}, | ||
set(name) { | ||
this._object.setNamingScheme(0) | ||
this._object.setName(name) | ||
}, | ||
}) | ||
|
||
ExportFormat.define('size', { | ||
get() { | ||
switch (this._object.visibleScaleType()) { | ||
case 0: | ||
return `${this._object.scale()}x` | ||
case 1: | ||
return `${this._object.absoluteSize()}w` | ||
case 2: | ||
return `${this._object.absoluteSize()}h` | ||
default: | ||
throw new Error('unknown visibleScaleType') | ||
} | ||
}, | ||
set(_size) { | ||
const size = String(_size) | ||
if ( | ||
size.endsWith('w') || | ||
size.endsWith('width') || | ||
(size.endsWith('px') && this._object.visibleScaleType() == 1) | ||
) { | ||
this._object.setVisibleScaleType(1) | ||
this._object.setScale(0) | ||
this._object.setAbsoluteSize(parseInt(size, 10)) | ||
} else if ( | ||
size.endsWith('h') || | ||
size.endsWith('height') || | ||
(size.endsWith('px') && this._object.visibleScaleType() == 2) | ||
) { | ||
this._object.setVisibleScaleType(2) | ||
this._object.setScale(0) | ||
this._object.setAbsoluteSize(parseInt(size, 10)) | ||
} else if (size.endsWith('x')) { | ||
this._object.setVisibleScaleType(0) | ||
this._object.setScale(parseInt(size, 10)) | ||
this._object.setAbsoluteSize(0) | ||
} else { | ||
throw new Error('could not parse the size') | ||
} | ||
}, | ||
}) |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use
[MSExportOptions nextMostAppropriateExportFormatToAdd:]
here, so as not to hardcode the values for the initial exportFormat?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum I'm not sure. I get why we want that in the UI but IMO it would be weird to have a different fileformat depending on which one was added before