Skip to content

Commit

Permalink
fix overrides and images on nodejs (#413)
Browse files Browse the repository at this point in the history
* fix overrides and images on nodejs

* Fix Border-radius clipping incorrectly calculated (#279)

* fix setting text override

* version 3.0.0-beta-3
  • Loading branch information
mathieudutour authored Feb 12, 2019
1 parent 42291a6 commit 19173f4
Show file tree
Hide file tree
Showing 27 changed files with 677 additions and 622 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This project adheres to [Semantic Versioning](http://semver.org/). Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/airbnb/react-sketchapp/releases) page.

## Version 3.0.0-beta.3

- Fix setting overrides (#409)
- Fix images on NodeJS
- Fix Border-radius clipping incorrectly calculated (#279)

## Version 3.0.0-beta.1

- Fix ShapeGroup on nodejs (#387)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Quick-start 🏃‍

First, make sure you have installed [Sketch](http://sketchapp.com) version 43+, & a recent [npm](https://nodejs.org/en/download/).
First, make sure you have installed [Sketch](http://sketchapp.com) version 50+, & a recent [npm](https://nodejs.org/en/download/).

Open a new Sketch file, then in a terminal:

Expand Down
5 changes: 4 additions & 1 deletion __tests__/jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ let ReactSketch;
describe('public API', () => {
beforeEach(() => {
// jest.resetModules();
jest.mock('../../src/jsonUtils/hacksForJSONImpl');
jest.mock('../../src/jsonUtils/sketchImpl/createStringMeasurer');
jest.mock('../../src/jsonUtils/sketchImpl/findFontName');
jest.mock('../../src/jsonUtils/sketchImpl/makeImageDataFromUrl');
jest.mock('../../src/jsonUtils/sketchImpl/makeSvgLayer');
ReactSketch = require('../../src');
});

Expand Down
15 changes: 0 additions & 15 deletions __tests__/jest/jsonUtils/hacksForJSONImpl.js

This file was deleted.

7 changes: 5 additions & 2 deletions __tests__/jest/sharedStyles/TextStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ beforeEach(() => {
}));

jest.mock('../../../src/utils/getSketchVersion.js', () => ({
default: jest.fn(() => 47),
default: jest.fn(() => 51),
}));

TextStyles = require('../../../src/sharedStyles/TextStyles');
Expand All @@ -21,7 +21,10 @@ beforeEach(() => {

jest.mock('../../../src/wrappers/sharedTextStyles');

jest.mock('../../../src/jsonUtils/hacksForJSONImpl');
jest.mock('../../../src/jsonUtils/sketchImpl/createStringMeasurer');
jest.mock('../../../src/jsonUtils/sketchImpl/findFontName');
jest.mock('../../../src/jsonUtils/sketchImpl/makeImageDataFromUrl');
jest.mock('../../../src/jsonUtils/sketchImpl/makeSvgLayer');

TextStyles = TextStyles.default;
sharedTextStyles = sharedTextStyles.default;
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-sketchapp",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"description": "A React renderer for Sketch.app",
"main": "lib/index.js",
"license": "MIT",
Expand Down Expand Up @@ -44,6 +44,7 @@
"airbnb-prop-types": "^2.10.0",
"error-stack-parser": "^2.0.0",
"invariant": "^2.2.2",
"js-sha1": "^0.6.0",
"murmur2js": "^1.0.0",
"normalize-css-color": "^1.0.1",
"pegjs": "^0.10.0",
Expand Down Expand Up @@ -118,7 +119,7 @@
"react": "^16.3.2",
"react-test-renderer": "^16.3.2",
"rimraf": "^2.5.4",
"sketchapp-json-flow-types": "^0.3.4"
"sketchapp-json-flow-types": "^0.3.5"
},
"skpm": {
"test": {
Expand Down
13 changes: 12 additions & 1 deletion src/jsonUtils/borders.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ export const createBorders = (
isEnabled: true,
color: makeColorFromCSS(borderTopColor),
fillType: FillType.Solid,
position: BorderPosition.Inside,
position: BorderPosition.Outside,
thickness: borderTopWidth,
},
];
const backingLayer = content.layers ? content.layers[0] : undefined;
if (backingLayer) {
// $FlowFixMe
backingLayer.frame.x += borderTopWidth;
// $FlowFixMe
backingLayer.frame.y += borderTopWidth;
// $FlowFixMe
backingLayer.frame.width -= borderTopWidth * 2;
// $FlowFixMe
backingLayer.frame.height -= borderTopWidth * 2;
}
}

return [content];
Expand Down
179 changes: 0 additions & 179 deletions src/jsonUtils/hacksForJSONImpl.js

This file was deleted.

24 changes: 17 additions & 7 deletions src/jsonUtils/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,33 @@ export const makeRect = (x: number, y: number, width: number, height: number): S
height,
});

export const makeJSONDataReference = (image: MSImageData): SJImageDataReference => ({
export const makeJSONDataReference = (image: {
data: string,
sha1: string,
}): SJImageDataReference => ({
_class: 'MSJSONOriginalDataReference',
_ref: `images/${generateID()}`,
_ref_class: 'MSImageData',
data: {
_data: image
.data()
.base64EncodedStringWithOptions(NSDataBase64EncodingEndLineWithCarriageReturn),
_data: image.data,
// TODO(gold): can I just declare this as a var instead of using Cocoa?
},
sha1: {
_data: image
.sha1()
.base64EncodedStringWithOptions(NSDataBase64EncodingEndLineWithCarriageReturn),
_data: image.sha1,
},
});

export const makeOverride = (
path: string,
type: 'symbolID' | 'stringValue' | 'layerStyle' | 'textStyle' | 'flowDestination' | 'image',
value: string | SJImageDataReference,
) => ({
_class: 'overrideValue',
do_objectID: generateID(),
overrideName: `${path}_${type}`,
value,
});

export const makeSymbolInstance = (
frame: SJRect,
symbolID: string,
Expand Down
Loading

0 comments on commit 19173f4

Please sign in to comment.