Skip to content

Commit 3d186f3

Browse files
zuiceCompuIves
authored andcommitted
Add emmet support (codesandbox#32)
* Add emmet support * Change name of Emmet configuration, and move emmet wrapper outside * Add @Vueu as a contributor
1 parent ee1c67b commit 3d186f3

File tree

6 files changed

+168
-3
lines changed

6 files changed

+168
-3
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
"contributions": [
3535
"code"
3636
]
37+
},
38+
{
39+
"login": "vueu",
40+
"name": "Jeff Allen",
41+
"avatar_url": "https://avatars0.githubusercontent.com/u/5266810?v=3",
42+
"profile": "http://www.jeffallen.io/",
43+
"contributions": [
44+
"code"
45+
]
3746
}
3847
]
3948
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [CodeSandbox](https://codesandbox.io)
2-
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
2+
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
33
[![Build Status](https://travis-ci.org/CompuIves/codesandbox-client.svg?branch=master)](https://travis-ci.org/CompuIves/codesandbox-client)
44

55
An online code editor with a focus on React.
@@ -36,8 +36,8 @@ yarn start
3636
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
3737

3838
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
39-
| [<img src="https://avatars0.githubusercontent.com/u/587016?v=3" width="100px;"/><br /><sub>Ives van Hoorne</sub>](http://ivesvh.com)<br />[💬](#question-CompuIves "Answering Questions") [📝](#blog-CompuIves "Blogposts") [🐛](https://github.com/CompuIves/CodeSandbox/issues?q=author%3ACompuIves "Bug reports") [💻](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Code") [🎨](#design-CompuIves "Design") [📖](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Documentation") [💡](#example-CompuIves "Examples") [🚇](#infra-CompuIves "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-CompuIves "Reviewed Pull Requests") [⚠️](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Tests") [🔧](#tool-CompuIves "Tools") | [<img src="https://avatars0.githubusercontent.com/u/887639?v=3" width="100px;"/><br /><sub>Donavon West</sub>](http://donavon.com)<br />[💻](https://github.com/CompuIves/CodeSandbox/commits?author=donavon "Code") |
40-
| :---: | :---: |
39+
| [<img src="https://avatars0.githubusercontent.com/u/587016?v=3" width="100px;"/><br /><sub>Ives van Hoorne</sub>](http://ivesvh.com)<br />[💬](#question-CompuIves "Answering Questions") [📝](#blog-CompuIves "Blogposts") [🐛](https://github.com/CompuIves/CodeSandbox/issues?q=author%3ACompuIves "Bug reports") [💻](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Code") [🎨](#design-CompuIves "Design") [📖](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Documentation") [💡](#example-CompuIves "Examples") [🚇](#infra-CompuIves "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-CompuIves "Reviewed Pull Requests") [⚠️](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Tests") [🔧](#tool-CompuIves "Tools") | [<img src="https://avatars0.githubusercontent.com/u/887639?v=3" width="100px;"/><br /><sub>Donavon West</sub>](http://donavon.com)<br />[💻](https://github.com/CompuIves/CodeSandbox/commits?author=donavon "Code") | [<img src="https://avatars0.githubusercontent.com/u/5266810?v=3" width="100px;"/><br /><sub>Jeff Allen</sub>](http://www.jeffallen.io/)<br />[💻](https://github.com/CompuIves/CodeSandbox/commits?author=vueu "Code") |
40+
| :---: | :---: | :---: |
4141
<!-- ALL-CONTRIBUTORS-LIST:END -->
4242

4343
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"whatwg-fetch": "^2.0.3"
7070
},
7171
"dependencies": {
72+
"@emmetio/codemirror-plugin": "^0.3.5",
7273
"axios": "^0.16.2",
7374
"babel-plugin-system-import": "^1.1.5",
7475
"babel-plugin-system-import-transformer": "3.1.0",

src/app/components/sandbox/CodeEditor/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export default class CodeEditor extends React.PureComponent {
136136
if (this.props.preferences !== prevProps.preferences) {
137137
this.setCodeMirrorPreferences();
138138
}
139+
140+
this.configureEmmet();
139141
}
140142
}
141143

@@ -244,8 +246,10 @@ export default class CodeEditor extends React.PureComponent {
244246
} else {
245247
const spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
246248
cm.replaceSelection(spaces, 'end', '+input');
249+
cm.execCommand('emmetExpandAbbreviation');
247250
}
248251
},
252+
Enter: 'emmetInsertLineBreak',
249253
...defaultKeys,
250254
});
251255
} else {
@@ -308,6 +312,19 @@ export default class CodeEditor extends React.PureComponent {
308312
saveCode();
309313
};
310314

315+
configureEmmet = async () => {
316+
const { title } = this.props;
317+
const mode = await this.getMode(title);
318+
319+
const newMode = mode === 'htmlmixed' ? 'html' : mode;
320+
const addon = newMode === 'jsx' ? { jsx: true } : null;
321+
322+
this.codemirror.setOption('emmet', {
323+
addons: addon,
324+
syntax: newMode,
325+
});
326+
}
327+
311328
codemirror: typeof CodeMirror;
312329
server: typeof CodeMirror.TernServer;
313330

src/app/utils/codemirror.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CodeMirror from 'codemirror';
2+
import emmet from '@emmetio/codemirror-plugin';
23
import { injectGlobal, keyframes } from 'styled-components';
34
import theme from 'common/theme';
45

@@ -17,6 +18,8 @@ import 'codemirror/addon/fold/foldcode';
1718
import 'codemirror/addon/fold/foldgutter';
1819
import 'codemirror/addon/fold/brace-fold';
1920

21+
emmet(CodeMirror);
22+
2023
const fadeInAnimation = keyframes`
2124
0% { background-color: #374140; }
2225
100% { background-color: #561011; }

yarn.lock

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,141 @@
22
# yarn lockfile v1
33

44

5+
"@emmetio/abbreviation@^0.6.0", "@emmetio/abbreviation@^0.6.1":
6+
version "0.6.1"
7+
resolved "https://registry.yarnpkg.com/@emmetio/abbreviation/-/abbreviation-0.6.1.tgz#1255b3f468bc610dd6ea9dd2f70f3afa92027c26"
8+
dependencies:
9+
"@emmetio/node" "^0.1.2"
10+
"@emmetio/stream-reader" "^2.0.0"
11+
"@emmetio/stream-reader-utils" "^0.1.0"
12+
13+
"@emmetio/codemirror-plugin@^0.3.5":
14+
version "0.3.5"
15+
resolved "https://registry.yarnpkg.com/@emmetio/codemirror-plugin/-/codemirror-plugin-0.3.5.tgz#579855769166292e1ad25485fe3c569150627efe"
16+
dependencies:
17+
"@emmetio/css-snippets-resolver" "^0.2.5"
18+
"@emmetio/expand-abbreviation" "^0.5.7"
19+
"@emmetio/extract-abbreviation" "^0.1.2"
20+
"@emmetio/html-matcher" "^0.3.2"
21+
"@emmetio/stream-reader" "^2.2.0"
22+
23+
"@emmetio/css-abbreviation@^0.3.1":
24+
version "0.3.1"
25+
resolved "https://registry.yarnpkg.com/@emmetio/css-abbreviation/-/css-abbreviation-0.3.1.tgz#c8ce56318bf5f8d5ab5e3d2760bd50bca2ca8888"
26+
dependencies:
27+
"@emmetio/node" "^0.1.0"
28+
"@emmetio/stream-reader" "^2.0.0"
29+
"@emmetio/stream-reader-utils" "^0.1.0"
30+
31+
"@emmetio/css-snippets-resolver@^0.2.5":
32+
version "0.2.5"
33+
resolved "https://registry.yarnpkg.com/@emmetio/css-snippets-resolver/-/css-snippets-resolver-0.2.5.tgz#e67b8278212b4621b2d3556922c46dad2f4f0c8d"
34+
35+
"@emmetio/expand-abbreviation@^0.5.7":
36+
version "0.5.8"
37+
resolved "https://registry.yarnpkg.com/@emmetio/expand-abbreviation/-/expand-abbreviation-0.5.8.tgz#141348314b1f76c0932a41e0c9cc5f93647bea25"
38+
dependencies:
39+
"@emmetio/abbreviation" "^0.6.1"
40+
"@emmetio/css-abbreviation" "^0.3.1"
41+
"@emmetio/css-snippets-resolver" "^0.2.5"
42+
"@emmetio/html-snippets-resolver" "^0.1.4"
43+
"@emmetio/html-transform" "^0.3.2"
44+
"@emmetio/lorem" "^1.0.1"
45+
"@emmetio/markup-formatters" "^0.3.3"
46+
"@emmetio/output-profile" "^0.1.5"
47+
"@emmetio/snippets" "^0.2.3"
48+
"@emmetio/snippets-registry" "^0.3.1"
49+
"@emmetio/stylesheet-formatters" "^0.1.2"
50+
"@emmetio/variable-resolver" "^0.2.1"
51+
52+
"@emmetio/extract-abbreviation@^0.1.2":
53+
version "0.1.2"
54+
resolved "https://registry.yarnpkg.com/@emmetio/extract-abbreviation/-/extract-abbreviation-0.1.2.tgz#e1f1c06349f4b1a00241ba1ba8a719062f9194b0"
55+
56+
"@emmetio/field-parser@^0.3.0":
57+
version "0.3.0"
58+
resolved "https://registry.yarnpkg.com/@emmetio/field-parser/-/field-parser-0.3.0.tgz#7a7cf51c399aea7bae455e0fcf3eb328f8c0c215"
59+
dependencies:
60+
"@emmetio/stream-reader" "^2.0.0"
61+
"@emmetio/stream-reader-utils" "^0.1.0"
62+
63+
"@emmetio/html-matcher@^0.3.2":
64+
version "0.3.2"
65+
resolved "https://registry.yarnpkg.com/@emmetio/html-matcher/-/html-matcher-0.3.2.tgz#efe0023e97191de1639f01fdcf0a198b588d3624"
66+
dependencies:
67+
"@emmetio/stream-reader" "^2.0.0"
68+
"@emmetio/stream-reader-utils" "^0.1.0"
69+
70+
"@emmetio/html-snippets-resolver@^0.1.4":
71+
version "0.1.4"
72+
resolved "https://registry.yarnpkg.com/@emmetio/html-snippets-resolver/-/html-snippets-resolver-0.1.4.tgz#b33ad3fa78fd78d64b94bf88a9fb68b3ad8e8e7e"
73+
dependencies:
74+
"@emmetio/abbreviation" "^0.6.0"
75+
76+
"@emmetio/html-transform@^0.3.2":
77+
version "0.3.2"
78+
resolved "https://registry.yarnpkg.com/@emmetio/html-transform/-/html-transform-0.3.2.tgz#6c50100d687e1a4d9f1e50632fcf24f383b70075"
79+
dependencies:
80+
"@emmetio/implicit-tag" "^1.0.0"
81+
82+
"@emmetio/implicit-tag@^1.0.0":
83+
version "1.0.0"
84+
resolved "https://registry.yarnpkg.com/@emmetio/implicit-tag/-/implicit-tag-1.0.0.tgz#f826d4e1fc51da39434c2326b6f6d0e2b2e7b419"
85+
86+
"@emmetio/lorem@^1.0.1":
87+
version "1.0.1"
88+
resolved "https://registry.yarnpkg.com/@emmetio/lorem/-/lorem-1.0.1.tgz#4f5e0b43b9e01fe2a9e5cdc248700884a1cab95a"
89+
dependencies:
90+
"@emmetio/implicit-tag" "^1.0.0"
91+
92+
"@emmetio/markup-formatters@^0.3.3":
93+
version "0.3.3"
94+
resolved "https://registry.yarnpkg.com/@emmetio/markup-formatters/-/markup-formatters-0.3.3.tgz#b686c05a9786d4896be64764ff23a5e40daf63dc"
95+
dependencies:
96+
"@emmetio/field-parser" "^0.3.0"
97+
"@emmetio/output-renderer" "^0.1.0"
98+
99+
"@emmetio/node@^0.1.0", "@emmetio/node@^0.1.2":
100+
version "0.1.2"
101+
resolved "https://registry.yarnpkg.com/@emmetio/node/-/node-0.1.2.tgz#4231d538c45481a51835fc2aba3f5d9fc129634c"
102+
103+
"@emmetio/output-profile@^0.1.5":
104+
version "0.1.5"
105+
resolved "https://registry.yarnpkg.com/@emmetio/output-profile/-/output-profile-0.1.5.tgz#52893a73c1924ee4b4154a9f8d9772b89c4f61dd"
106+
107+
"@emmetio/output-renderer@^0.1.0", "@emmetio/output-renderer@^0.1.1":
108+
version "0.1.1"
109+
resolved "https://registry.yarnpkg.com/@emmetio/output-renderer/-/output-renderer-0.1.1.tgz#a4d58554a21200a9191dd799a73177879ca5d7d6"
110+
dependencies:
111+
"@emmetio/field-parser" "^0.3.0"
112+
113+
"@emmetio/snippets-registry@^0.3.1":
114+
version "0.3.1"
115+
resolved "https://registry.yarnpkg.com/@emmetio/snippets-registry/-/snippets-registry-0.3.1.tgz#ec0e8a122fe9683659ce69a22396f4136b940d20"
116+
117+
"@emmetio/snippets@^0.2.3":
118+
version "0.2.3"
119+
resolved "https://registry.yarnpkg.com/@emmetio/snippets/-/snippets-0.2.3.tgz#73e209fc036dbb9f7c9aa1050038cc68ad082c1a"
120+
121+
"@emmetio/stream-reader-utils@^0.1.0":
122+
version "0.1.0"
123+
resolved "https://registry.yarnpkg.com/@emmetio/stream-reader-utils/-/stream-reader-utils-0.1.0.tgz#244cb02c77ec2e74f78a9bd318218abc9c500a61"
124+
125+
"@emmetio/stream-reader@^2.0.0", "@emmetio/stream-reader@^2.2.0":
126+
version "2.2.0"
127+
resolved "https://registry.yarnpkg.com/@emmetio/stream-reader/-/stream-reader-2.2.0.tgz#46cffea119a0a003312a21c2d9b5628cb5fcd442"
128+
129+
"@emmetio/stylesheet-formatters@^0.1.2":
130+
version "0.1.2"
131+
resolved "https://registry.yarnpkg.com/@emmetio/stylesheet-formatters/-/stylesheet-formatters-0.1.2.tgz#3036ed6d8c1e40345e673044b75c3f14986022cf"
132+
dependencies:
133+
"@emmetio/field-parser" "^0.3.0"
134+
"@emmetio/output-renderer" "^0.1.1"
135+
136+
"@emmetio/variable-resolver@^0.2.1":
137+
version "0.2.1"
138+
resolved "https://registry.yarnpkg.com/@emmetio/variable-resolver/-/variable-resolver-0.2.1.tgz#ce11b51584669a340986690cf0ec269e44c63fba"
139+
5140
abab@^1.0.3:
6141
version "1.0.3"
7142
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"

0 commit comments

Comments
 (0)