Skip to content

Commit

Permalink
Merge pull request #764 from stupiduglyfool/master
Browse files Browse the repository at this point in the history
Universal server side rendering
  • Loading branch information
amcdnl authored Jun 1, 2017
2 parents 2163626 + a3974a9 commit f9e7bc7
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"build:aot": "ngc",
"build:sass": "node-sass -r build/ -o build/",
"build:css": "postcss --use autoprefixer dist/*.css -d dist/",
"copy:build": "cpx 'src/**/*' 'build'",
"copy:styles": "cpx 'build/**/*.css' 'release'",
"copy:build": "cpx -v \"src/**/*\" \"build\"",
"copy:styles": "cpx -v \"build/**/*.css\" \"release\"",
"watch": "webpack --display-error-details --watch",
"start": "webpack-dev-server",
"start:hmr": "webpack-dev-server --env.HMR",
Expand Down
1 change: 1 addition & 0 deletions src/components/body/body-cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { Keys } from '../../utils';
import { SortDirection } from '../../types';
import { TableColumn } from '../../types/table-column.type';
import { MouseEvent, KeyboardEvent } from '../../events';

@Component({
selector: 'datatable-body-cell',
Expand Down
1 change: 1 addition & 0 deletions src/components/body/body-row-wrapper.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Component, Input, Output, EventEmitter, HostListener
} from '@angular/core';
import { MouseEvent } from '../../events';

@Component({
selector: 'datatable-row-wrapper',
Expand Down
1 change: 1 addition & 0 deletions src/components/body/body-row.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
columnsByPin, columnGroupWidths, columnsByPinArr, translateXY, Keys
} from '../../utils';
import { ScrollbarHelper } from '../../services';
import { MouseEvent, KeyboardEvent } from '../../events';

@Component({
selector: 'datatable-body-row',
Expand Down
1 change: 1 addition & 0 deletions src/components/body/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import { translateXY, columnsByPin, columnGroupWidths, RowHeightCache } from '../../utils';
import { SelectionType } from '../../types';
import { ScrollerComponent } from './scroller.component';
import { MouseEvent } from '../../events';

@Component({
selector: 'datatable-body',
Expand Down
2 changes: 2 additions & 0 deletions src/components/body/scroller.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
OnInit, OnDestroy, HostBinding
} from '@angular/core';

import { MouseEvent } from '../../events';

@Component({
selector: 'datatable-scroller',
template: `
Expand Down
1 change: 1 addition & 0 deletions src/components/body/selection.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Keys, selectRows, selectRowsBetween } from '../../utils';
import { SelectionType } from '../../types';
import { MouseEvent, KeyboardEvent } from '../../events';

export interface Model {
type: string;
Expand Down
1 change: 1 addition & 0 deletions src/components/datatable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DataTableBodyComponent } from './body';
import { DataTableColumnDirective } from './columns';
import { DatatableRowDetailDirective } from './row-detail';
import { DatatableFooterDirective } from './footer';
import { MouseEvent } from '../events';

@Component({
selector: 'ngx-datatable',
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/header-cell.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Component, Input, EventEmitter, Output, HostBinding, HostListener
} from '@angular/core';

import { SortDirection, SortType, SelectionType, TableColumn } from '../../types';
import { nextSortDir } from '../../utils';
import { MouseEvent } from '../../events';

@Component({
selector: 'datatable-header-cell',
Expand Down
1 change: 1 addition & 0 deletions src/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import { SortType, SelectionType } from '../../types';
import { columnsByPin, columnGroupWidths, columnsByPinArr, translateXY } from '../../utils';
import { DataTableColumnDirective } from '../columns';
import { MouseEvent } from '../../events';

@Component({
selector: 'datatable-header',
Expand Down
1 change: 1 addition & 0 deletions src/directives/draggable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/takeUntil';
import { MouseEvent } from '../events';

/**
* Draggable Directive for Angular2
Expand Down
1 change: 1 addition & 0 deletions src/directives/long-press.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/takeUntil';
import { MouseEvent } from './../events';

@Directive({ selector: '[long-press]' })
export class LongPressDirective implements OnDestroy {
Expand Down
1 change: 1 addition & 0 deletions src/directives/resizeable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { MouseEvent } from '../events';
import 'rxjs/add/operator/takeUntil';

@Directive({
Expand Down
4 changes: 4 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare let global:any;

export const MouseEvent = (global as any).MouseEvent as MouseEvent;
export const KeyboardEvent = (global as any).KeyboardEvent as KeyboardEvent;
4 changes: 3 additions & 1 deletion src/utils/elm-from-point.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (!document.elementsFromPoint) {
if (document !== undefined && !document.elementsFromPoint) {
document.elementsFromPoint = elementsFromPoint;
}

Expand All @@ -22,6 +22,8 @@ export function elementsFromPoint(x: number, y: number) {
let i;
let d;

//if (document === undefined) return elements;

// get all elements via elementFromPoint, and remove them from hit-testing in order
while ((current = document.elementFromPoint(x, y)) && elements.indexOf(current) === -1 && current != null) {

Expand Down
18 changes: 10 additions & 8 deletions src/utils/prefixes.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { camelCase } from './camel-case';

const cache = {};
const testStyle = document.createElement('div').style;
const testStyle = document !== undefined ? document.createElement('div').style : undefined;

// Get Prefix
// http://davidwalsh.name/vendor-prefix
const prefix = (function() {
const styles = window.getComputedStyle(document.documentElement, '');
const pre = (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/))[1];
const dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1];
const styles = window !== undefined ? window.getComputedStyle(document.documentElement, '') : undefined;
const pre = styles !== undefined ? (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/))[1] : undefined;
const dom = pre !== undefined ? ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1] : undefined;

return {
return dom ? {
dom,
lowercase: pre,
css: `-${pre}-`,
js: pre[0].toUpperCase() + pre.substr(1)
};
} : undefined;
})();

export function getVendorPrefixedName(property: string) {
const name = camelCase(property);

if(!cache[name]) {
if(testStyle[prefix.css + property] !== undefined) {

if(!cache[name]) {
if(prefix !== undefined && testStyle[prefix.css + property] !== undefined) {
cache[name] = prefix.css + property;
} else if(testStyle[property] !== undefined) {
cache[name] = property;
}

}

return cache[name];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const transform = getVendorPrefixedName('transform');
const backfaceVisibility = getVendorPrefixedName('backfaceVisibility');
const hasCSSTransforms = !!getVendorPrefixedName('transform');
const hasCSS3DTransforms = !!getVendorPrefixedName('perspective');
const ua = window.navigator.userAgent;
const ua = window ? window.navigator.userAgent : "Chrome";
const isSafari = (/Safari\//).test(ua) && !(/Chrome\//).test(ua);

export function translateXY(styles: any, x: number, y: number) {
Expand Down

0 comments on commit f9e7bc7

Please sign in to comment.