mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-19 09:43:29 +00:00
load preact from node_modules
This commit is contained in:
parent
655ea4f8e9
commit
1c9f6ce838
@ -27,15 +27,16 @@
|
||||
"sirv-cli": "1.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"preact": "^10.3.2",
|
||||
"preact-render-to-string": "^5.1.4",
|
||||
"preact-router": "^3.2.1",
|
||||
"@zxing/library": "^0.18.5",
|
||||
"autolinker": "^3.14.3",
|
||||
"gun": "^0.2020.1232",
|
||||
"iris-lib": "https://github.com/irislib/iris-lib",
|
||||
"jquery": "^3.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"preact": "^10.3.2",
|
||||
"preact-render-to-string": "^5.1.4",
|
||||
"preact-router": "^3.2.1",
|
||||
"preact-scroll-viewport": "^0.2.0",
|
||||
"webtorrent": "^0.118.0"
|
||||
},
|
||||
"jest": {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Session from './Session.js';
|
||||
import {translate as t} from './Translation.js';
|
||||
import {createElement} from './lib/preact.js';
|
||||
import {createElement} from 'preact';
|
||||
import htm from './lib/htm.module.js';
|
||||
import { route } from './lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import $ from 'jquery';
|
||||
import _ from 'lodash';
|
||||
import iris from 'iris-lib';
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { render } from './lib/preact.js';
|
||||
import { Router } from './lib/preact-router.es.js';
|
||||
import { Component } from './lib/preact.js';
|
||||
import { Link } from './lib/preact.match.js';
|
||||
import { Component } from 'preact';
|
||||
import { Router } from 'preact-router';
|
||||
import { Link } from 'preact-router/match';
|
||||
import iris from 'iris-lib';
|
||||
|
||||
import Helpers from './Helpers.js';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Helpers from './Helpers.js';
|
||||
import Session from './Session.js';
|
||||
import { route } from './lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import State from './State.js';
|
||||
import _ from 'lodash';
|
||||
import iris from 'iris-lib';
|
||||
|
@ -2,7 +2,7 @@ import State from './State.js';
|
||||
import Notifications from './Notifications.js';
|
||||
import Helpers from './Helpers.js';
|
||||
import PeerManager from './PeerManager.js';
|
||||
import { route } from './lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import iris from 'iris-lib';
|
||||
import _ from 'lodash';
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { Component } from '../lib/preact.js';import { html } from '../Helpers.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { translate as t } from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
import ChatListItem from './ChatListItem.js';
|
||||
import Helpers from '../Helpers.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import Notifications from '../Notifications.js';
|
||||
import ScrollViewport from '../lib/preact-scroll-viewport.js';
|
||||
import ScrollViewport from 'preact-scroll-viewport';
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import { translate as t } from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { translate as t } from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import {html} from '../Helpers.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import Helpers from '../Helpers.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import {html} from '../Helpers.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import Session from '../Session.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { translate as t } from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import Identicon from './Identicon.js';
|
||||
import SearchBox from './SearchBox.js';
|
||||
import Icons from '../Icons.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import SafeImg from './SafeImg.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import {html} from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Icons from '../Icons.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import Helpers from '../Helpers.js';
|
||||
import Session from '../Session.js';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import Helpers, { html } from '../Helpers.js';
|
||||
import PublicMessage from './PublicMessage.js';
|
||||
import ScrollViewport from '../lib/preact-scroll-viewport.js';
|
||||
import ScrollViewport from 'preact-scroll-viewport';
|
||||
import State from '../State.js';
|
||||
|
||||
class MessageFeed extends Component {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import State from '../State.js';
|
||||
|
||||
class Name extends Component {
|
||||
|
@ -5,8 +5,8 @@ import Helpers from '../Helpers.js';
|
||||
import QRScanner from '../QRScanner.js';
|
||||
import Session from '../Session.js';
|
||||
import CopyButton from './CopyButton.js';
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { Component } from 'preact';
|
||||
import { route } from 'preact-router';
|
||||
import $ from 'jquery';
|
||||
import QRCode from '../lib/qrcode.min.js';
|
||||
import iris from 'iris-lib';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import {html} from '../Helpers.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import Helpers from '../Helpers.js';
|
||||
|
@ -3,7 +3,7 @@ import Helpers from '../Helpers.js';
|
||||
import Identicon from './Identicon.js';
|
||||
import PublicMessageForm from './PublicMessageForm.js';
|
||||
import State from '../State.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import Message from './Message.js';
|
||||
import Session from '../Session.js';
|
||||
import Torrent from './Torrent.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { translate as t } from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { Component } from 'preact';
|
||||
import { route } from 'preact-router';
|
||||
import Helpers, { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Identicon from './Identicon.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import Helpers, {html} from '../Helpers.js';
|
||||
import Session from "../Session.js";
|
||||
import { translate as tr } from '../Translation.js';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import { html } from '../Helpers.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
|
||||
import {translate as t} from '../Translation.js';
|
||||
import Session from '../Session.js';
|
||||
|
@ -1,361 +0,0 @@
|
||||
import { Component, cloneElement, createElement, toChildArray } from './preact.js';
|
||||
|
||||
var EMPTY$1 = {};
|
||||
|
||||
function assign(obj, props) {
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (var i in props) {
|
||||
obj[i] = props[i];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function exec(url, route, opts) {
|
||||
var reg = /(?:\?([^#]*))?(#.*)?$/,
|
||||
c = url.match(reg),
|
||||
matches = {},
|
||||
ret;
|
||||
if (c && c[1]) {
|
||||
var p = c[1].split('&');
|
||||
for (var i=0; i<p.length; i++) {
|
||||
var r = p[i].split('=');
|
||||
matches[decodeURIComponent(r[0])] = decodeURIComponent(r.slice(1).join('='));
|
||||
}
|
||||
}
|
||||
url = segmentize(url.replace(reg, ''));
|
||||
route = segmentize(route || '');
|
||||
var max = Math.max(url.length, route.length);
|
||||
for (var i$1=0; i$1<max; i$1++) {
|
||||
if (route[i$1] && route[i$1].charAt(0)===':') {
|
||||
var param = route[i$1].replace(/(^:|[+*?]+$)/g, ''),
|
||||
flags = (route[i$1].match(/[+*?]+$/) || EMPTY$1)[0] || '',
|
||||
plus = ~flags.indexOf('+'),
|
||||
star = ~flags.indexOf('*'),
|
||||
val = url[i$1] || '';
|
||||
if (!val && !star && (flags.indexOf('?')<0 || plus)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
matches[param] = decodeURIComponent(val);
|
||||
if (plus || star) {
|
||||
matches[param] = url.slice(i$1).map(decodeURIComponent).join('/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (route[i$1]!==url[i$1]) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (opts.default!==true && ret===false) { return false; }
|
||||
return matches;
|
||||
}
|
||||
|
||||
function pathRankSort(a, b) {
|
||||
return (
|
||||
(a.rank < b.rank) ? 1 :
|
||||
(a.rank > b.rank) ? -1 :
|
||||
(a.index - b.index)
|
||||
);
|
||||
}
|
||||
|
||||
// filter out VNodes without attributes (which are unrankeable), and add `index`/`rank` properties to be used in sorting.
|
||||
function prepareVNodeForRanking(vnode, index) {
|
||||
vnode.index = index;
|
||||
vnode.rank = rankChild(vnode);
|
||||
return vnode.props;
|
||||
}
|
||||
|
||||
function segmentize(url) {
|
||||
return url.replace(/(^\/+|\/+$)/g, '').split('/');
|
||||
}
|
||||
|
||||
function rankSegment(segment) {
|
||||
return segment.charAt(0)==':' ? (1 + '*+?'.indexOf(segment.charAt(segment.length-1))) || 4 : 5;
|
||||
}
|
||||
|
||||
function rank(path) {
|
||||
return segmentize(path).map(rankSegment).join('');
|
||||
}
|
||||
|
||||
function rankChild(vnode) {
|
||||
return vnode.props.default ? 0 : rank(vnode.props.path);
|
||||
}
|
||||
|
||||
var customHistory = null;
|
||||
|
||||
var ROUTERS = [];
|
||||
|
||||
var subscribers = [];
|
||||
|
||||
var EMPTY = {};
|
||||
|
||||
function setUrl(url, type) {
|
||||
if ( type === void 0 ) type='push';
|
||||
|
||||
if (customHistory && customHistory[type]) {
|
||||
customHistory[type](url);
|
||||
}
|
||||
else if (typeof history!=='undefined' && history[type+'State']) {
|
||||
history[type+'State'](null, null, url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getCurrentUrl() {
|
||||
var url;
|
||||
if (customHistory && customHistory.location) {
|
||||
url = customHistory.location;
|
||||
}
|
||||
else if (customHistory && customHistory.getCurrentLocation) {
|
||||
url = customHistory.getCurrentLocation();
|
||||
}
|
||||
else {
|
||||
url = typeof location!=='undefined' ? location : EMPTY;
|
||||
}
|
||||
return ("" + (url.pathname || '') + (url.search || ''));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function route(url, replace) {
|
||||
if ( replace === void 0 ) replace=false;
|
||||
|
||||
if (typeof url!=='string' && url.url) {
|
||||
replace = url.replace;
|
||||
url = url.url;
|
||||
}
|
||||
|
||||
// only push URL into history if we can handle it
|
||||
if (canRoute(url)) {
|
||||
setUrl(url, replace ? 'replace' : 'push');
|
||||
}
|
||||
|
||||
return routeTo(url);
|
||||
}
|
||||
|
||||
|
||||
/** Check if the given URL can be handled by any router instances. */
|
||||
function canRoute(url) {
|
||||
for (var i=ROUTERS.length; i--; ) {
|
||||
if (ROUTERS[i].canRoute(url)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Tell all router instances to handle the given URL. */
|
||||
function routeTo(url) {
|
||||
var didRoute = false;
|
||||
for (var i=0; i<ROUTERS.length; i++) {
|
||||
if (ROUTERS[i].routeTo(url)===true) {
|
||||
didRoute = true;
|
||||
}
|
||||
}
|
||||
for (var i$1=subscribers.length; i$1--; ) {
|
||||
subscribers[i$1](url);
|
||||
}
|
||||
return didRoute;
|
||||
}
|
||||
|
||||
|
||||
function routeFromLink(node) {
|
||||
// only valid elements
|
||||
if (!node || !node.getAttribute) { return; }
|
||||
|
||||
var href = node.getAttribute('href'),
|
||||
target = node.getAttribute('target');
|
||||
|
||||
// ignore links with targets and non-path URLs
|
||||
if (!href || !href.match(/^\//g) || (target && !target.match(/^_?self$/i))) { return; }
|
||||
|
||||
// attempt to route, if no match simply cede control to browser
|
||||
return route(href);
|
||||
}
|
||||
|
||||
|
||||
function handleLinkClick(e) {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button!==0) { return; }
|
||||
routeFromLink(e.currentTarget || e.target || this);
|
||||
return prevent(e);
|
||||
}
|
||||
|
||||
|
||||
function prevent(e) {
|
||||
if (e) {
|
||||
if (e.stopImmediatePropagation) { e.stopImmediatePropagation(); }
|
||||
if (e.stopPropagation) { e.stopPropagation(); }
|
||||
e.preventDefault();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function delegateLinkHandler(e) {
|
||||
// ignore events the browser takes care of already:
|
||||
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button!==0) { return; }
|
||||
|
||||
var t = e.target;
|
||||
do {
|
||||
if (String(t.nodeName).toUpperCase()==='A' && t.getAttribute('href')) {
|
||||
if (t.hasAttribute('native')) { return; }
|
||||
// if link is handled by the router, prevent browser defaults
|
||||
if (routeFromLink(t)) {
|
||||
return prevent(e);
|
||||
}
|
||||
}
|
||||
} while ((t=t.parentNode));
|
||||
}
|
||||
|
||||
|
||||
var eventListenersInitialized = false;
|
||||
|
||||
function initEventListeners() {
|
||||
if (eventListenersInitialized) { return; }
|
||||
|
||||
if (typeof addEventListener==='function') {
|
||||
if (!customHistory) {
|
||||
addEventListener('popstate', function () {
|
||||
routeTo(getCurrentUrl());
|
||||
});
|
||||
}
|
||||
addEventListener('click', delegateLinkHandler);
|
||||
}
|
||||
eventListenersInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
var Router = (function (Component$$1) {
|
||||
function Router(props) {
|
||||
Component$$1.call(this, props);
|
||||
if (props.history) {
|
||||
customHistory = props.history;
|
||||
}
|
||||
|
||||
this.state = {
|
||||
url: props.url || getCurrentUrl()
|
||||
};
|
||||
|
||||
initEventListeners();
|
||||
}
|
||||
|
||||
if ( Component$$1 ) Router.__proto__ = Component$$1;
|
||||
Router.prototype = Object.create( Component$$1 && Component$$1.prototype );
|
||||
Router.prototype.constructor = Router;
|
||||
|
||||
Router.prototype.shouldComponentUpdate = function shouldComponentUpdate (props) {
|
||||
if (props.static!==true) { return true; }
|
||||
return props.url!==this.props.url || props.onChange!==this.props.onChange;
|
||||
};
|
||||
|
||||
/** Check if the given URL can be matched against any children */
|
||||
Router.prototype.canRoute = function canRoute (url) {
|
||||
var children = toChildArray(this.props.children);
|
||||
return this.getMatchingChildren(children, url, false).length > 0;
|
||||
};
|
||||
|
||||
/** Re-render children with a new URL to match against. */
|
||||
Router.prototype.routeTo = function routeTo (url) {
|
||||
this.setState({ url: url });
|
||||
|
||||
var didRoute = this.canRoute(url);
|
||||
|
||||
// trigger a manual re-route if we're not in the middle of an update:
|
||||
if (!this.updating) { this.forceUpdate(); }
|
||||
|
||||
return didRoute;
|
||||
};
|
||||
|
||||
Router.prototype.componentWillMount = function componentWillMount () {
|
||||
ROUTERS.push(this);
|
||||
this.updating = true;
|
||||
};
|
||||
|
||||
Router.prototype.componentDidMount = function componentDidMount () {
|
||||
var this$1 = this;
|
||||
|
||||
if (customHistory) {
|
||||
this.unlisten = customHistory.listen(function (location) {
|
||||
this$1.routeTo(("" + (location.pathname || '') + (location.search || '')));
|
||||
});
|
||||
}
|
||||
this.updating = false;
|
||||
};
|
||||
|
||||
Router.prototype.componentWillUnmount = function componentWillUnmount () {
|
||||
if (typeof this.unlisten==='function') { this.unlisten(); }
|
||||
ROUTERS.splice(ROUTERS.indexOf(this), 1);
|
||||
};
|
||||
|
||||
Router.prototype.componentWillUpdate = function componentWillUpdate () {
|
||||
this.updating = true;
|
||||
};
|
||||
|
||||
Router.prototype.componentDidUpdate = function componentDidUpdate () {
|
||||
this.updating = false;
|
||||
};
|
||||
|
||||
Router.prototype.getMatchingChildren = function getMatchingChildren (children, url, invoke) {
|
||||
return children
|
||||
.filter(prepareVNodeForRanking)
|
||||
.sort(pathRankSort)
|
||||
.map( function (vnode) {
|
||||
var matches = exec(url, vnode.props.path, vnode.props);
|
||||
if (matches) {
|
||||
if (invoke !== false) {
|
||||
var newProps = { url: url, matches: matches };
|
||||
assign(newProps, matches);
|
||||
delete newProps.ref;
|
||||
delete newProps.key;
|
||||
return cloneElement(vnode, newProps);
|
||||
}
|
||||
return vnode;
|
||||
}
|
||||
}).filter(Boolean);
|
||||
};
|
||||
|
||||
Router.prototype.render = function render (ref, ref$1) {
|
||||
var children = ref.children;
|
||||
var onChange = ref.onChange;
|
||||
var url = ref$1.url;
|
||||
|
||||
var active = this.getMatchingChildren(toChildArray(children), url, true);
|
||||
|
||||
var current = active[0] || null;
|
||||
|
||||
var previous = this.previousUrl;
|
||||
if (url!==previous) {
|
||||
this.previousUrl = url;
|
||||
if (typeof onChange==='function') {
|
||||
onChange({
|
||||
router: this,
|
||||
url: url,
|
||||
previous: previous,
|
||||
active: active,
|
||||
current: current
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
};
|
||||
|
||||
return Router;
|
||||
}(Component));
|
||||
|
||||
var Link = function (props) { return (
|
||||
createElement('a', assign({ onClick: handleLinkClick }, props))
|
||||
); };
|
||||
|
||||
var Route = function (props) { return createElement(props.component, props); };
|
||||
|
||||
Router.subscribers = subscribers;
|
||||
Router.getCurrentUrl = getCurrentUrl;
|
||||
Router.route = route;
|
||||
Router.Router = Router;
|
||||
Router.Route = Route;
|
||||
Router.Link = Link;
|
||||
Router.exec = exec;
|
||||
|
||||
export { subscribers, getCurrentUrl, route, Router, Route, Link, exec };export default Router;
|
||||
//# sourceMappingURL=preact-router.es.js.map
|
@ -1,101 +0,0 @@
|
||||
import { Component } from './preact.js';
|
||||
import {html} from '../Helpers.js';
|
||||
|
||||
const EVENT_OPTS = {
|
||||
passive: true,
|
||||
capture: true
|
||||
};
|
||||
|
||||
/** Virtual list, renders only visible items.
|
||||
* @param {Number} rowHeight Use a static height value for each row. Prevents relayout.
|
||||
* @param {Number} defaultRowHeight Initial row height, used prior to height being calculated from first item
|
||||
* @param {Number} [overscan=10] Amount of rows to render above and below visible area of the list
|
||||
* @param {Boolean} [sync=false] true forces synchronous rendering
|
||||
* @example
|
||||
* <ScrollViewport
|
||||
* rowHeight={22}
|
||||
* defaultRowHeight={22}
|
||||
* sync
|
||||
* />
|
||||
*/
|
||||
export default class ScrollViewport extends Component {
|
||||
resized = () => {
|
||||
let height = window.innerHeight || document.documentElement.offsetHeight;
|
||||
if (height!==this.state.height) {
|
||||
this.setState({ height });
|
||||
}
|
||||
};
|
||||
|
||||
scrolled = () => {
|
||||
let offset = Math.max(0, this.base && -this.base.getBoundingClientRect().top || 0);
|
||||
this.setState({ offset });
|
||||
if (this.props.sync) this.forceUpdate();
|
||||
};
|
||||
|
||||
computeRowHeight() {
|
||||
if (this._height) return this._height;
|
||||
let first = this.base && this.base.firstElementChild && this.base.firstElementChild.firstElementChild;
|
||||
return this._height = (first && first.offsetHeight || 0);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
this.resized();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.resized();
|
||||
this.scrolled();
|
||||
addEventListener('resize', this.resized, EVENT_OPTS);
|
||||
addEventListener('scroll', this.scrolled, EVENT_OPTS);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
removeEventListener('resize', this.resized, EVENT_OPTS);
|
||||
removeEventListener('scroll', this.scrolled, EVENT_OPTS);
|
||||
}
|
||||
|
||||
render({ overscan=10, rowHeight, defaultRowHeight, children, ...props }, { offset=0, height=0 }) {
|
||||
rowHeight = rowHeight || this.computeRowHeight() || defaultRowHeight || 100;
|
||||
|
||||
// compute estimated height based on first item height and number of items:
|
||||
let estimatedHeight = rowHeight * children.length;
|
||||
if (typeof props.style==='string') {
|
||||
props.style += ' height:'+estimatedHeight+'px;';
|
||||
}
|
||||
else {
|
||||
(props.style || (props.style={})).height = estimatedHeight.toExponential() + 'px';
|
||||
}
|
||||
|
||||
let start = 0,
|
||||
visibleRowCount = 1;
|
||||
|
||||
if (rowHeight) {
|
||||
// first visible row index
|
||||
start = (offset / rowHeight)|0;
|
||||
|
||||
// actual number of visible rows (without overscan)
|
||||
visibleRowCount = (height / rowHeight)|0;
|
||||
|
||||
// Overscan: render blocks of rows modulo an overscan row count
|
||||
// This dramatically reduces DOM writes during scrolling
|
||||
if (overscan) {
|
||||
start = Math.max(0, start - (start % overscan));
|
||||
visibleRowCount += overscan;
|
||||
}
|
||||
}
|
||||
|
||||
// last visible + overscan row index
|
||||
let end = start + 1 + visibleRowCount;
|
||||
|
||||
// children currently in viewport plus overscan items
|
||||
let visible = children.slice(start, end);
|
||||
|
||||
return html`
|
||||
<div ${{...props}}>
|
||||
<div class=${this.props.class||''} style=${{ position: 'relative', top: start*rowHeight }}>
|
||||
${visible}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
2
src/js/lib/preact-scroll-viewport.min.js
vendored
2
src/js/lib/preact-scroll-viewport.min.js
vendored
@ -1,2 +0,0 @@
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("preact")):"function"==typeof define&&define.amd?define(["preact"],t):e.ScrollViewport=t(e.preact)}(this,function(e){function t(e,t){var o={};for(var i in e)t.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(e,i)&&(o[i]=e[i]);return o}function o(e,t){if(e)return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){"function"!=typeof t&&null!==t||(e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t))}var n={passive:!0,capture:!0};return function(r){function s(){for(var e,t,i,n=arguments.length,s=Array(n),c=0;c<n;c++)s[c]=arguments[c];return e=t=o(this,r.call.apply(r,[this].concat(s))),t.resized=function(){var e=window.innerHeight||document.documentElement.offsetHeight;e!==t.state.height&&t.setState({height:e})},t.scrolled=function(){var e=Math.max(0,t.base&&-t.base.getBoundingClientRect().top||0);t.setState({offset:e}),t.props.sync&&t.forceUpdate()},i=e,o(t,i)}return i(s,r),s.prototype.computeRowHeight=function(){if(this._height)return this._height;var e=this.base&&this.base.firstElementChild&&this.base.firstElementChild.firstElementChild;return this._height=e&&e.offsetHeight||0},s.prototype.componentDidUpdate=function(){this.resized()},s.prototype.componentDidMount=function(){this.resized(),this.scrolled(),addEventListener("resize",this.resized,n),addEventListener("scroll",this.scrolled,n)},s.prototype.componentWillUnmount=function(){removeEventListener("resize",this.resized,n),removeEventListener("scroll",this.scrolled,n)},s.prototype.render=function(o,i){var n=i.offset,r=void 0===n?0:n,s=i.height,c=void 0===s?0:s,h=o.overscan,p=void 0===h?10:h,l=o.rowHeight,a=o.defaultRowHeight,f=o.children,u=t(o,["overscan","rowHeight","defaultRowHeight","children"]);l=l||this.computeRowHeight()||a||100;var d=l*f.length;"string"==typeof u.style?u.style+=" height:"+d+"px;":(u.style||(u.style={})).height=d.toExponential()+"px";var v=0,y=1;l&&(v=r/l|0,y=c/l|0,p&&(v=Math.max(0,v-v%p),y+=p));var g=v+1+y,m=f.slice(v,g);return e.h("div",u,e.h("div",{style:{position:"relative",top:v*l}},m))},s}(e.Component)});
|
||||
//# sourceMappingURL=preact-scroll-viewport.min.js.map
|
File diff suppressed because one or more lines are too long
@ -1,37 +0,0 @@
|
||||
import { Component } from './preact.js';
|
||||
import { subscribers, getCurrentUrl, Link as StaticLink, exec } from './preact-router.es.js';
|
||||
import { html } from '../Helpers.js';
|
||||
|
||||
export class Match extends Component {
|
||||
update = url => {
|
||||
this.nextUrl = url;
|
||||
this.setState({});
|
||||
};
|
||||
componentDidMount() {
|
||||
subscribers.push(this.update);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
subscribers.splice(subscribers.indexOf(this.update)>>>0, 1);
|
||||
}
|
||||
render(props) {
|
||||
let url = this.nextUrl || getCurrentUrl(),
|
||||
path = url.replace(/\?.+$/,'');
|
||||
this.nextUrl = null;
|
||||
return props.children({
|
||||
url,
|
||||
path,
|
||||
matches: exec(path, props.path, {}) !== false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const Link = ({ activeClassName, path, ...props }) => html`
|
||||
<${Match} path=${path || props.href}>
|
||||
${ ({ matches }) =>
|
||||
html`<${StaticLink} ...${props} class=${[props.class || props.className, matches && activeClassName].filter(Boolean).join(' ')} />`
|
||||
}
|
||||
<//>
|
||||
`;
|
||||
|
||||
export default Match;
|
||||
Match.Link = Link;
|
@ -1,7 +1,7 @@
|
||||
import { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import SafeImg from '../components/SafeImg.js';
|
||||
import Store from './Store.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
|
@ -6,7 +6,7 @@ import FollowButton from '../components/FollowButton.js';
|
||||
import Name from '../components/Name.js';
|
||||
import View from './View.js';
|
||||
import Session from '../Session.js';
|
||||
import ScrollViewport from '../lib/preact-scroll-viewport.js';
|
||||
import ScrollViewport from 'preact-scroll-viewport';
|
||||
|
||||
class Contacts extends View {
|
||||
constructor() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import View from './View.js';
|
||||
|
||||
const hashRegex = /^(?:[A-Za-z0-9+/]{4}){10}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)+$/;
|
||||
|
@ -3,7 +3,7 @@ import {translate as tr} from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import ProfilePhotoPicker from '../components/ProfilePhotoPicker.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import SafeImg from '../components/SafeImg.js';
|
||||
import CopyButton from '../components/CopyButton.js';
|
||||
import Identicon from '../components/Identicon.js';
|
||||
|
@ -4,7 +4,7 @@ import { translate as t } from '../Translation.js';
|
||||
import LanguageSelector from '../components/LanguageSelector.js';
|
||||
import QRScanner from '../QRScanner.js';
|
||||
import Session from '../Session.js';
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import Helpers from '../Helpers.js';
|
||||
|
||||
import logo from '../../img/android-chrome-192x192.png';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { html } from '../Helpers.js';
|
||||
import Session from '../Session.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
|
||||
const LogoutConfirmation = () => html`<div class="main-view" id="logout-confirmation">
|
||||
<div class="centered-container">
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { html } from '../Helpers.js';
|
||||
import PublicMessage from '../components/PublicMessage.js';
|
||||
import PublicMessageForm from '../components/PublicMessageForm.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import View from './View.js';
|
||||
|
||||
class Message extends View {
|
||||
|
@ -2,7 +2,7 @@ import { html } from '../Helpers.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import {translate as t} from '../Translation.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import StoreView from './Store.js';
|
||||
|
||||
class Product extends StoreView {
|
||||
|
@ -5,7 +5,7 @@ import Session from '../Session.js';
|
||||
import Helpers from '../Helpers.js';
|
||||
import PublicMessageForm from '../components/PublicMessageForm.js';
|
||||
import ProfilePhotoPicker from '../components/ProfilePhotoPicker.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import SafeImg from '../components/SafeImg.js';
|
||||
import CopyButton from '../components/CopyButton.js';
|
||||
import FollowButton from '../components/FollowButton.js';
|
||||
@ -13,7 +13,7 @@ import BlockButton from '../components/BlockButton.js';
|
||||
import MessageFeed from '../components/MessageFeed.js';
|
||||
import Identicon from '../components/Identicon.js';
|
||||
import View from './View.js';
|
||||
import { Link } from '../lib/preact.match.js';
|
||||
import { Link } from 'preact-router/match';
|
||||
import $ from 'jquery';
|
||||
import QRCode from '../lib/qrcode.min.js';
|
||||
|
||||
|
@ -8,7 +8,7 @@ import PeerManager from '../PeerManager.js';
|
||||
import {setRTCConfig, getRTCConfig, DEFAULT_RTC_CONFIG} from '../components/VideoCall.js';
|
||||
import CopyButton from '../components/CopyButton.js';
|
||||
import View from './View.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import {ExistingAccountLogin} from './Login.js';
|
||||
import Notifications from '../Notifications.js';
|
||||
import iris from 'iris-lib';
|
||||
|
@ -3,7 +3,7 @@ import {translate as t} from '../Translation.js';
|
||||
import State from '../State.js';
|
||||
import Session from '../Session.js';
|
||||
import ProfilePhotoPicker from '../components/ProfilePhotoPicker.js';
|
||||
import { route } from '../lib/preact-router.es.js';
|
||||
import { route } from 'preact-router';
|
||||
import SafeImg from '../components/SafeImg.js';
|
||||
import CopyButton from '../components/CopyButton.js';
|
||||
import FollowButton from '../components/FollowButton.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '../lib/preact.js';
|
||||
import { Component } from 'preact';
|
||||
import Header from '../components/Header.js';
|
||||
import { html } from '../Helpers.js';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user