Skip to content
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a69b850
Transpile to ES2017 to avoid regenerator-runtime for now
lordofthelake Jan 20, 2020
042fdae
Use weakRequire instead of ad-hoc evals
lordofthelake Jan 20, 2020
22b7f60
Make everything async
lordofthelake Jan 20, 2020
2968a64
Add getImageDataFromURL() implementation using fetch
lordofthelake Jan 20, 2020
1ad2d17
Split the bridges in their own objects
lordofthelake Jan 21, 2020
dfd88c9
Change the interface of getSketchVersion()
lordofthelake Jan 21, 2020
08d1a2e
Use strong imports in NodeMacOSBridge
lordofthelake Jan 21, 2020
f9c83a9
Add PlatformBridge injection everywhere
lordofthelake Jan 21, 2020
67fc4ce
Group together files by method instead than by implementation
lordofthelake Jan 21, 2020
6d6c801
Rename the *SJSON functions
lordofthelake Jan 21, 2020
5bae926
Don't use the console in prodution
lordofthelake Jan 21, 2020
d849c9b
Reorganize exports
lordofthelake Jan 22, 2020
b8bc142
Split entrypoints by platform
lordofthelake Jan 22, 2020
2d063e6
Change the bridge injection for TextStyles
lordofthelake Jan 22, 2020
0dbd5b0
Use a dynamic import instead of weakRequire
lordofthelake Jan 22, 2020
12dd68c
Fix compilation errors
lordofthelake Jan 22, 2020
435bce2
Move back StyleSheet -> stylesheet
lordofthelake Jan 22, 2020
65e011d
Fix the test suite
lordofthelake Jan 22, 2020
9c82687
Add multiple entrypoints in package.json
lordofthelake Jan 22, 2020
b267fcd
Add the node-fetch dependency
lordofthelake Jan 22, 2020
8e6b485
Revert targeting es5
lordofthelake Jan 22, 2020
7bacf27
Update @skpm/builder everywhere
lordofthelake Jan 22, 2020
48766e4
Add implementation to read from file: protocol
lordofthelake Jan 23, 2020
8d6d1ff
Add TODO about moving the bridge out
lordofthelake Jan 23, 2020
414c845
Merge branch 'master' of github.com:compositive/react-sketchapp into …
lordofthelake Jan 23, 2020
a0a9012
Fix types to work with strict
lordofthelake Jan 23, 2020
87b175a
Use static platform switching
lordofthelake Jan 23, 2020
13ee09d
Don't account for skpm-fetch peculiarities
lordofthelake Jan 23, 2020
f88bd56
Add npm build to Travis to check whether the types work
lordofthelake Jan 23, 2020
f143562
Add sideEffects flag to allow tree shaking
lordofthelake Jan 23, 2020
87ff628
Revert changes to getSketchVersion()
lordofthelake Jan 25, 2020
5adf6b5
Revert changes to logging
lordofthelake Jan 25, 2020
a6ddb65
Revert adding extra scripts to examples/profile-cards
lordofthelake Jan 25, 2020
7c41cf6
Revert renaming the *SJON functions
lordofthelake Jan 25, 2020
d5a3f26
Start documenting changes
lordofthelake Jul 11, 2020
215adec
Update TypeScript version
lordofthelake Jul 11, 2020
7c6c02f
Merge branch 'master' of github.com:airbnb/react-sketchapp into pure-…
lordofthelake Jan 6, 2021
cadae33
Fix the TypeScript errors
lordofthelake Jan 6, 2021
bc20d9d
Update API docs
lordofthelake Jan 6, 2021
c0b681d
Clean up left-overs of refactors already implemented
lordofthelake Jan 6, 2021
8708fc2
Correct the link to the `PlatformBridge` type
lordofthelake Jan 6, 2021
55b2c3d
Disable node_modules cache
lordofthelake Jan 6, 2021
9cbae7b
Forcibly clean the cached node_modules
lordofthelake Jan 6, 2021
8b02a46
Remove footnote in `API.md`
lordofthelake Jan 6, 2021
79fec51
Merge branch 'master' into pure-make-image-from-url-implementation
lordofthelake Mar 30, 2021
21e52ee
Update Travis config and npm
lordofthelake Apr 8, 2021
451cadb
Merge branch 'pure-make-image-from-url-implementation' of github.com:…
lordofthelake Apr 8, 2021
7c6da8e
Change the compile target to `es2017` in tsconfig.json
lordofthelake Apr 8, 2021
abffbba
Don't use the npm cache
lordofthelake Apr 8, 2021
2bc1bf6
Add libraries for retrocompatibility
lordofthelake Apr 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ node_js:
before_script:
- npm prune
script:
- npm run build # smoke-test that everything transpiles correctly
- npm run test:ci
# - npm run test:e2e -- --app=/Applications/Sketch.app
# after_script:
Expand Down
6 changes: 3 additions & 3 deletions __tests__/jest/components/nodeImpl/Svg.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import ReactSketch from '../../../../src';
import * as ReactSketch from '../../../../src';
import Svg from '../../../../src/components/Svg';

jest.mock('../../../../src/jsonUtils/models', () => ({
Expand All @@ -9,7 +9,7 @@ jest.mock('../../../../src/jsonUtils/models', () => ({
}));

describe('node <Svg />', () => {
it('generates the json for an svg', () => {
it('generates the json for an svg', async () => {
class SVGElement extends React.Component {
render() {
return (
Expand All @@ -25,6 +25,6 @@ describe('node <Svg />', () => {
}
}

expect(ReactSketch.renderToJSON(<SVGElement />)).toMatchSnapshot();
expect(await ReactSketch.renderToJSON(<SVGElement />)).toMatchSnapshot();
});
});
6 changes: 1 addition & 5 deletions __tests__/jest/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import ReactSketch from '../../src';
jest.mock('../../src/jsonUtils/sketchImpl/createStringMeasurer');
jest.mock('../../src/jsonUtils/sketchImpl/findFontName');
jest.mock('../../src/jsonUtils/sketchImpl/makeImageDataFromUrl');
jest.mock('../../src/jsonUtils/sketchImpl/makeSvgLayer');
import * as ReactSketch from '../../src';

describe('public API', () => {
it('exports render', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/jest/jsonUtils/computeYogaNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import yoga from 'yoga-layout-prebuilt';
import computeYogaNode from '../../../src/jsonUtils/computeYogaNode';
import Context from '../../../src/utils/Context';
import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge';

const widthAndHeightStylesStub = {
width: 10,
Expand Down Expand Up @@ -33,7 +34,7 @@ const createYogaNodes = (
styles.forEach(style => {
const treeNode = createTreeNode(style);
const ctx = new Context();
const { node } = computeYogaNode(treeNode, ctx);
const { node } = computeYogaNode(treeNode, ctx, NodeMacOSBridge);
node.calculateLayout(
containerWidth || undefined,
containerHeight || undefined,
Expand Down
5 changes: 3 additions & 2 deletions __tests__/jest/jsonUtils/computeYogaTree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import yoga from 'yoga-layout-prebuilt';
import computeYogaTree from '../../../src/jsonUtils/computeYogaTree';
import Context from '../../../src/utils/Context';
import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge';

const treeRootStub = {
type: 'artboard',
Expand Down Expand Up @@ -36,11 +37,11 @@ const treeRootStub = {
],
};

computeYogaTree(treeRootStub, new Context());
computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge);

describe('Compute Yoga Tree', () => {
it('correctly create yoga nodes into layout tree', () => {
const yogaTree = computeYogaTree(treeRootStub, new Context());
const yogaTree = computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge);
yogaTree.calculateLayout(undefined, undefined, yoga.DIRECTION_LTR);
expect(yogaTree.getComputedLayout()).toEqual({
bottom: 0,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/jest/reactTreeToFlexTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import yoga from 'yoga-layout-prebuilt';
import computeYogaTree from '../../src/jsonUtils/computeYogaTree';
import Context from '../../src/utils/Context';
import { reactTreeToFlexTree } from '../../src/buildTree';
import NodeMacOSBridge from '../../src/platformBridges/NodeMacOSBridge';

const treeRootStub = {
type: 'artboard',
Expand Down Expand Up @@ -58,7 +59,7 @@ const treeRootStub = {

describe('Compute Flex Tree', () => {
it('correctly creates flex tree', () => {
const yogaNode = computeYogaTree(treeRootStub, new Context());
const yogaNode = computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge);
yogaNode.calculateLayout(undefined, undefined, yoga.DIRECTION_LTR);
const tree = reactTreeToFlexTree(treeRootStub, yogaNode, new Context());

Expand Down
58 changes: 23 additions & 35 deletions __tests__/jest/sharedStyles/TextStyles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge';

let TextStyles;
let doc;
let sharedTextStyles;
Expand All @@ -15,12 +17,7 @@ beforeEach(() => {

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

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;
TextStyles = TextStyles.default(() => NodeMacOSBridge);
sharedTextStyles = sharedTextStyles.default;

sharedTextStyles.setDocument = jest.fn(doc => {
Expand Down Expand Up @@ -114,41 +111,32 @@ describe('create', () => {
});

it('only stores text attributes', () => {
const whitelist = [
'color',
'fontFamily',
'fontSize',
'fontStyle',
'fontWeight',
'textShadowOffset',
'textShadowRadius',
'textShadowColor',
'textTransform',
'letterSpacing',
'lineHeight',
'textAlign',
'writingDirection',
];

const blacklist = ['foo', 'bar', 'baz'];

const input = [...whitelist, ...blacklist].reduce(
(acc, key) => ({
...acc,
[key]: true,
}),
{},
);
const whitelist = {
color: 'red',
fontFamily: 'Helvetica',
fontSize: 14,
fontStyle: 'italic',
fontWeight: 'bold',
textShadowOffset: 2,
textShadowRadius: 1,
textShadowColor: 'black',
textTransform: 'uppercase',
letterSpacing: 1,
lineHeight: 18,
textAlign: 'left',
writingDirection: 'ltr',
};

const res = TextStyles.create({ foo: input }, { document: doc });
const blacklist = { foo: 1, bar: 2, baz: 3 };

const res = TextStyles.create({ foo: { ...whitelist, ...blacklist } }, { document: doc });
const firstStoredStyle = res[Object.keys(res)[0]].cssStyle;

whitelist.forEach(key => {
expect(firstStoredStyle).toHaveProperty(key, true);
Object.keys(whitelist).forEach(key => {
expect(firstStoredStyle).toHaveProperty(key, whitelist[key]);
});

blacklist.forEach(key => {
Object.keys(blacklist).forEach(key => {
expect(firstStoredStyle).not.toHaveProperty(key);
});
});
Expand Down
19 changes: 14 additions & 5 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- [`Symbols`](#symbols)
- [`makeSymbol`](#makesymbolnode-name)

### `render(element, container)`
### `async render(element, container?, bridge?)`

Returns the top-level rendered Sketch object or an array of Sketch objects if you use `<Page>` components.

Expand Down Expand Up @@ -57,6 +57,10 @@ The element to render into - will be replaced. Should either be a Sketch [Docume

Example: `sketch.getSelectedDocument().selectedPage`.

##### `bridge` (optional)

An object implementing the [Platform Bridge API](/docs/PlatformBridges.md). When not specified, it will attempt to load the most suitable one for the platform in use among the ones bundled with the package.

#### Returns

The top-most rendered native Sketch layer.
Expand All @@ -73,12 +77,12 @@ const Document = props => (
</View>
);

export default () => {
render(<Document />, sketch.getSelectedDocument().selectedPage);
export default async () => {
await render(<Document />, sketch.getSelectedDocument().selectedPage);
};
```

### `renderToJSON(element)`
### `async renderToJSON(element, bridge?)`

Returns a Sketch JSON object for further consumption - doesn't add to the page.

Expand All @@ -88,6 +92,10 @@ Returns a Sketch JSON object for further consumption - doesn't add to the page.

Top-level React component that defines your Sketch document.

##### `bridge` (optional)

An object implementing the [Platform Bridge API](/docs/PlatformBridges.md). When not specified, it will attempt to load the most suitable one for the platform in use among the ones bundled with the package.

#### Returns

The top-most Sketch layer as JSON.
Expand Down Expand Up @@ -625,7 +633,7 @@ Reset the registered styles.

An interface to Sketch's symbols. Create symbols and optionally inject them into the symbols page.

### `makeSymbol(node, props, document)`
### `makeSymbol(node, props, document, bridge?)`

Creates a new symbol and injects it into the `Symbols` page. The name of the symbol can be optionally provided and will default to the display name of the component.

Expand All @@ -640,6 +648,7 @@ Returns a react component which is an can be used to render instances of the sym
| `props.name` | `String` | The node name | Optional name for the symbol, string can include backslashes to organize these symbols with Sketch. For example `squares/blue` |
| `props.style` | [`Style`](/docs/styling.md) | | |
| `document` | `Object` | The current document | The Sketch document to make the symbol in |
| `bridge` | `Object` | _platform-dependent_ | An object implementing the [Platform Bridge API](/docs/PlatformBridges.md). |

### `getSymbolComponentByName(name)`

Expand Down
3 changes: 3 additions & 0 deletions docs/PlatformBridges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Platform Bridge API

_TODO_
2 changes: 1 addition & 1 deletion examples/basic-setup-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"author": "Jon Gold <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.0",
"@skpm/builder": "^0.7.5",
"@types/chroma-js": "^1.3.3",
"typescript": "^3.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Jon Gold <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.7.4"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"chroma-js": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-svg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Jon Gold <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"prop-types": "^15.5.8",
Expand Down
2 changes: 1 addition & 1 deletion examples/colors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"webpack-shell-plugin": "^0.5.0"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Nitin Tulswani <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.3"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"emotion-primitives": "^1.0.0-beta.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/form-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"devDependencies": {
"extract-text-webpack-plugin": "^2.1.0",
"nwb": "^0.15.6",
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/foursquare-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/glamorous/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Nitin Tulswani <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"chroma-js": "^1.3.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/profile-cards-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/profile-cards-primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/profile-cards-react-with-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"react-with-styles": "^1.4.0"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/profile-cards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/styled-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Mathieu Dutour <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"chroma-js": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/styleguide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
2 changes: 1 addition & 1 deletion examples/symbols/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Jon Gold <[email protected]>",
"license": "MIT",
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
},
"dependencies": {
"react": "^16.3.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/timeline-airtable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"react-test-renderer": "^16.3.2"
},
"devDependencies": {
"@skpm/builder": "^0.4.0"
"@skpm/builder": "^0.7.5"
}
}
Loading