Skip to content

Commit f9040e0

Browse files
committed
fix conflicts
2 parents 7dc5f91 + fd8864d commit f9040e0

82 files changed

Lines changed: 2874 additions & 1041 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ about them:
3636
2. `cd matrix-react-sdk`
3737
3. `git checkout develop`
3838
4. `npm install`
39-
5. `npm start` (to start the dev rebuilder)
40-
6. `cd ../vector-web`
41-
7. Link the react sdk package into the example:
39+
5. `npm run build`
40+
6. `npm start` (to start the dev rebuilder)
41+
7. `cd ../vector-web`
42+
8. Link the react sdk package into the example:
4243
`npm link path/to/your/react/sdk`
4344

4445
Similarly, you may need to `npm link path/to/your/js/sdk` in your `matrix-react-sdk`
@@ -53,6 +54,6 @@ about "Cannot resolve module 'source-map-loader'" due to shortcomings in webpack
5354
Deployment
5455
==========
5556

56-
Just run `npm build` and then mount the `vector` directory on your webserver to
57+
Just run `npm run build` and then mount the `vector` directory on your webserver to
5758
actually serve up the app, which is entirely static content.
5859

‎package.json‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
"classnames": "^2.1.2",
2828
"filesize": "^3.1.2",
2929
"flux": "~2.0.3",
30+
"gfm.css": "^1.1.1",
31+
"highlight.js": "^8.9.1",
3032
"linkifyjs": "^2.0.0-beta.4",
33+
"matrix-js-sdk": "https://github.com/matrix-org/matrix-js-sdk.git#develop",
34+
"matrix-react-sdk": "https://github.com/matrix-org/matrix-react-sdk.git#develop",
3135
"modernizr": "^3.1.0",
32-
"matrix-js-sdk": "^0.3.0",
33-
"matrix-react-sdk": "^0.0.2",
3436
"q": "^1.4.1",
35-
"react": "^0.13.3",
36-
"react-loader": "^1.4.0",
37-
"sanitize-html": "^1.11.1"
37+
"react": "^0.14.2",
38+
"react-dnd": "^2.0.2",
39+
"react-dnd-html5-backend": "^2.0.0",
40+
"react-dom": "^0.14.2",
41+
"react-gemini-scrollbar": "^2.0.1",
42+
"sanitize-html": "^1.0.0",
43+
"velocity-animate": "^1.2.3"
3844
},
3945
"devDependencies": {
4046
"babel": "^5.8.23",
@@ -46,6 +52,7 @@
4652
"parallelshell": "^1.2.0",
4753
"rimraf": "^2.4.3",
4854
"source-map-loader": "^0.1.5",
49-
"uglifycss": "0.0.15"
55+
"uglifycss": "0.0.15",
56+
"webpack": "^1.12.6"
5057
}
5158
}

‎src/ContextualMenu.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
'use strict';
1919

2020
var React = require('react');
21+
var ReactDOM = require('react-dom');
2122

2223
// Shamelessly ripped off Modal.js. There's probably a better way
2324
// of doing reusable widgets like dialog boxes & menus where we go and
@@ -42,7 +43,7 @@ module.exports = {
4243
var self = this;
4344

4445
var closeMenu = function() {
45-
React.unmountComponentAtNode(self.getOrCreateContainer());
46+
ReactDOM.unmountComponentAtNode(self.getOrCreateContainer());
4647

4748
if (props && props.onFinished) props.onFinished.apply(null, arguments);
4849
};
@@ -74,7 +75,7 @@ module.exports = {
7475
</div>
7576
);
7677

77-
React.render(menu, this.getOrCreateContainer());
78+
ReactDOM.render(menu, this.getOrCreateContainer());
7879

7980
return {close: closeMenu};
8081
},

‎src/HtmlUtils.js‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
var sanitizeHtml = require('sanitize-html');
21+
var highlight = require('highlight.js');
22+
23+
var sanitizeHtmlParams = {
24+
allowedTags: [
25+
'font', // custom to matrix. deliberately no h1/h2 to stop people shouting.
26+
'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol',
27+
'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
28+
'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre'
29+
],
30+
allowedAttributes: {
31+
// custom ones first:
32+
font: [ 'color' ], // custom to matrix
33+
a: [ 'href', 'name', 'target' ], // remote target: custom to matrix
34+
// We don't currently allow img itself by default, but this
35+
// would make sense if we did
36+
img: [ 'src' ],
37+
},
38+
// Lots of these won't come up by default because we don't allow them
39+
selfClosing: [ 'img', 'br', 'hr', 'area', 'base', 'basefont', 'input', 'link', 'meta' ],
40+
// URL schemes we permit
41+
allowedSchemes: [ 'http', 'https', 'ftp', 'mailto' ],
42+
allowedSchemesByTag: {},
43+
44+
transformTags: { // custom to matrix
45+
// add blank targets to all hyperlinks
46+
'a': sanitizeHtml.simpleTransform('a', { target: '_blank'} )
47+
},
48+
};
49+
50+
module.exports = {
51+
bodyToHtml: function(content, searchTerm) {
52+
var originalBody = content.body;
53+
var body;
54+
55+
if (searchTerm) {
56+
var lastOffset = 0;
57+
var bodyList = [];
58+
var k = 0;
59+
var offset;
60+
61+
// XXX: rather than searching for the search term in the body,
62+
// we should be looking at the match delimiters returned by the FTS engine
63+
if (content.format === "org.matrix.custom.html") {
64+
65+
var safeBody = sanitizeHtml(content.formatted_body, sanitizeHtmlParams);
66+
var safeSearchTerm = sanitizeHtml(searchTerm, sanitizeHtmlParams);
67+
while ((offset = safeBody.indexOf(safeSearchTerm, lastOffset)) >= 0) {
68+
// FIXME: we need to apply the search highlighting to only the text elements of HTML, which means
69+
// hooking into the sanitizer parser rather than treating it as a string. Otherwise
70+
// the act of highlighting a <b/> or whatever will break the HTML badly.
71+
bodyList.push(<span key={ k++ } dangerouslySetInnerHTML={{ __html: safeBody.substring(lastOffset, offset) }} />);
72+
bodyList.push(<span key={ k++ } dangerouslySetInnerHTML={{ __html: safeSearchTerm }} className="mx_MessageTile_searchHighlight" />);
73+
lastOffset = offset + safeSearchTerm.length;
74+
}
75+
bodyList.push(<span className="markdown-body" key={ k++ } dangerouslySetInnerHTML={{ __html: safeBody.substring(lastOffset) }} />);
76+
}
77+
else {
78+
while ((offset = originalBody.indexOf(searchTerm, lastOffset)) >= 0) {
79+
bodyList.push(<span key={ k++ } >{ originalBody.substring(lastOffset, offset) }</span>);
80+
bodyList.push(<span key={ k++ } className="mx_MessageTile_searchHighlight">{ searchTerm }</span>);
81+
lastOffset = offset + searchTerm.length;
82+
}
83+
bodyList.push(<span key={ k++ }>{ originalBody.substring(lastOffset) }</span>);
84+
}
85+
body = bodyList;
86+
}
87+
else {
88+
if (content.format === "org.matrix.custom.html") {
89+
var safeBody = sanitizeHtml(content.formatted_body, sanitizeHtmlParams);
90+
body = <span className="markdown-body" dangerouslySetInnerHTML={{ __html: safeBody }} />;
91+
}
92+
else {
93+
body = originalBody;
94+
}
95+
}
96+
97+
return body;
98+
},
99+
100+
highlightDom: function(element) {
101+
var blocks = element.getElementsByTagName("code");
102+
for (var i = 0; i < blocks.length; i++) {
103+
highlight.highlightBlock(blocks[i]);
104+
}
105+
},
106+
107+
}
108+

‎src/Resend.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg');
2+
var dis = require('matrix-react-sdk/lib/dispatcher');
3+
4+
module.exports = {
5+
resend: function(event) {
6+
MatrixClientPeg.get().resendEvent(
7+
event, MatrixClientPeg.get().getRoom(event.getRoomId())
8+
).done(function() {
9+
dis.dispatch({
10+
action: 'message_sent',
11+
event: event
12+
});
13+
}, function() {
14+
dis.dispatch({
15+
action: 'message_send_failed',
16+
event: event
17+
});
18+
});
19+
dis.dispatch({
20+
action: 'message_resend_started',
21+
event: event
22+
});
23+
},
24+
};

‎src/Velociraptor.js‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
var React = require('react');
2+
var ReactDom = require('react-dom');
3+
var Velocity = require('velocity-animate');
4+
5+
/**
6+
* The Velociraptor contains components and animates transitions with velocity.
7+
* It will only pick up direct changes to properties ('left', currently), and so
8+
* will not work for animating positional changes where the position is implicit
9+
* from DOM order. This makes it a lot simpler and lighter: if you need fully
10+
* automatic positional animation, look at react-shuffle or similar libraries.
11+
*/
12+
module.exports = React.createClass({
13+
displayName: 'Velociraptor',
14+
15+
propTypes: {
16+
children: React.PropTypes.array,
17+
transition: React.PropTypes.object,
18+
container: React.PropTypes.string
19+
},
20+
21+
componentWillMount: function() {
22+
this.children = {};
23+
this.nodes = {};
24+
var self = this;
25+
React.Children.map(this.props.children, function(c) {
26+
self.children[c.key] = c;
27+
});
28+
},
29+
30+
componentWillReceiveProps: function(nextProps) {
31+
var self = this;
32+
var oldChildren = this.children;
33+
this.children = {};
34+
React.Children.map(nextProps.children, function(c) {
35+
if (oldChildren[c.key]) {
36+
var old = oldChildren[c.key];
37+
var oldNode = ReactDom.findDOMNode(self.nodes[old.key]);
38+
39+
if (oldNode.style.left != c.props.style.left) {
40+
Velocity(oldNode, { left: c.props.style.left }, self.props.transition).then(function() {
41+
// special case visibility because it's nonsensical to animate an invisible element
42+
// so we always hidden->visible pre-transition and visible->hidden after
43+
if (oldNode.style.visibility == 'visible' && c.props.style.visibility == 'hidden') {
44+
oldNode.style.visibility = c.props.style.visibility;
45+
}
46+
});
47+
if (oldNode.style.visibility == 'hidden' && c.props.style.visibility == 'visible') {
48+
oldNode.style.visibility = c.props.style.visibility;
49+
}
50+
//console.log("translation: "+oldNode.style.left+" -> "+c.props.style.left);
51+
}
52+
self.children[c.key] = old;
53+
} else {
54+
// new element. If it has a startStyle, use that as the style and go through
55+
// the enter animations
56+
var newProps = {
57+
ref: self.collectNode.bind(self, c.key)
58+
};
59+
if (c.props.startStyle && Object.keys(c.props.startStyle).length) {
60+
var startStyle = c.props.startStyle;
61+
if (Array.isArray(startStyle)) {
62+
startStyle = startStyle[0];
63+
}
64+
newProps._restingStyle = c.props.style;
65+
newProps.style = startStyle;
66+
//console.log("mounted@startstyle0: "+JSON.stringify(startStyle));
67+
// apply the enter animations once it's mounted
68+
}
69+
self.children[c.key] = React.cloneElement(c, newProps);
70+
}
71+
});
72+
},
73+
74+
collectNode: function(k, node) {
75+
if (
76+
this.nodes[k] === undefined &&
77+
node.props.startStyle &&
78+
Object.keys(node.props.startStyle).length
79+
) {
80+
var domNode = ReactDom.findDOMNode(node);
81+
var startStyles = node.props.startStyle;
82+
var transitionOpts = node.props.enterTransitionOpts;
83+
if (!Array.isArray(startStyles)) {
84+
startStyles = [ startStyles ];
85+
transitionOpts = [ transitionOpts ];
86+
}
87+
// start from startStyle 1: 0 is the one we gave it
88+
// to start with, so now we animate 1 etc.
89+
for (var i = 1; i < startStyles.length; ++i) {
90+
Velocity(domNode, startStyles[i], transitionOpts[i-1]);
91+
//console.log("start: "+JSON.stringify(startStyles[i]));
92+
}
93+
// and then we animate to the resting state
94+
Velocity(domNode, node.props._restingStyle, transitionOpts[i-1]);
95+
//console.log("enter: "+JSON.stringify(node.props._restingStyle));
96+
}
97+
this.nodes[k] = node;
98+
},
99+
100+
render: function() {
101+
var self = this;
102+
var childList = Object.keys(this.children).map(function(k) {
103+
return React.cloneElement(self.children[k], {
104+
ref: self.collectNode.bind(self, self.children[k].key)
105+
});
106+
});
107+
return (
108+
<span>
109+
{childList}
110+
</span>
111+
);
112+
},
113+
});

‎src/VelocityBounce.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var Velocity = require('velocity-animate');
2+
3+
// courtesy of https://github.com/julianshapiro/velocity/issues/283
4+
// We only use easeOutBounce (easeInBounce is just sort of nonsensical)
5+
function bounce( p ) {
6+
var pow2,
7+
bounce = 4;
8+
9+
while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
10+
return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
11+
}
12+
13+
Velocity.Easings.easeOutBounce = function(p) {
14+
return 1 - bounce(1 - p);
15+
}

0 commit comments

Comments
 (0)