Skip to content

Commit

Permalink
feat: export angular module <not stable yet>
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jul 22, 2017
1 parent cb2de97 commit ef5101b
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 47 deletions.
15 changes: 15 additions & 0 deletions build/join-module-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
'use strict';
require('shelljs/global');

set('-e');
set('-v');


cat([
'lib/components/Redoc/redoc-initial-styles.css',
'node_modules/perfect-scrollbar/dist/css/perfect-scrollbar.css',
'node_modules/dropkickjs/build/css/dropkick.css',
'node_modules/prismjs/themes/prism-dark.css',
'node_modules/hint.css/hint.base.css'
]).to('dist/redoc.css')
1 change: 0 additions & 1 deletion build/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = webpackMerge(commonConfig({
devtool: '#inline-source-map',
entry: {
'polyfills': './lib/polyfills.ts',
'vendor': './lib/vendor.ts',
'redoc': './lib/index.ts',
},
devServer: {
Expand Down
2 changes: 1 addition & 1 deletion build/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const config = webpackMerge(commonConfig({
devtool: 'source-map',

entry: {
'redoc': IS_MODULE ? ['./lib/vendor.ts', './lib/redoc.module.ts'] : ['./lib/polyfills.ts', './lib/vendor.ts', './lib/index.ts']
'redoc': IS_MODULE ? ['./lib/redoc.module.ts'] : ['./lib/polyfills.ts', './lib/index.ts']
},

output: {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Redoc/redoc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ footer {

&:before, &:after {
letter-spacing: -0.2em;
content: "\00a0";
//content: "\00a0";
}
}

Expand Down
32 changes: 0 additions & 32 deletions lib/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,3 @@ if (!IS_PRODUCTION) {
Error.stackTraceLimit = Infinity;
require('zone.js/dist/long-stack-trace-zone');
}

interface Element {
scrollIntoViewIfNeeded(centerIfNeeded?: boolean): void;
};

if (!(<any>Element).prototype.scrollIntoViewIfNeeded) {
(<any>Element).prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;

var parent = this.parentNode,
parentComputedStyle = window.getComputedStyle(parent, null),
parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width')),
parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width')),
overTop = this.offsetTop - parent.offsetTop < parent.scrollTop,
overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight),
overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft,
overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth),
alignWithTop = overTop && !overBottom;

if ((overTop || overBottom) && centerIfNeeded) {
parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;
}

if ((overLeft || overRight) && centerIfNeeded) {
parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;
}

if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
this.scrollIntoView(alignWithTop);
}
};
}
2 changes: 2 additions & 0 deletions lib/redoc.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './vendor';

import { NgModule, ErrorHandler, APP_ID } from '@angular/core';
import { CommonModule } from '@angular/common';

Expand Down
36 changes: 29 additions & 7 deletions lib/vendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,34 @@ import 'dropkickjs/build/css/dropkick.css';
import 'prismjs/themes/prism-dark.css';
import 'hint.css/hint.base.css';

if (!IS_PRODUCTION) {
require('@angular/platform-browser');
require('@angular/platform-browser-dynamic');
require('@angular/core');
require('@angular/common');
interface Element {
scrollIntoViewIfNeeded(centerIfNeeded?: boolean): void;
};

// RxJS
require('rxjs/Rx');
if (!(<any>Element).prototype.scrollIntoViewIfNeeded) {
(<any>Element).prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;

var parent = this.parentNode,
parentComputedStyle = window.getComputedStyle(parent, null),
parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width')),
parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width')),
overTop = this.offsetTop - parent.offsetTop < parent.scrollTop,
overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight),
overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft,
overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth),
alignWithTop = overTop && !overBottom;

if ((overTop || overBottom) && centerIfNeeded) {
parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;
}

if ((overLeft || overRight) && centerIfNeeded) {
parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;
}

if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
this.scrollIntoView(alignWithTop);
}
};
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
"clean": "rimraf dist .tmp compiled lib/**/*.css",
"ngc": "ngc -p tsconfig.json",
"inline": "ng2-inline -o .tmp -r --compress \"lib/**/*.ts\"",
"build:aot": "npm run build:sass && npm run inline && ngc -p tsconfig.aot.json",
"build:module": "npm run build:sass && npm run inline && ngc -p tsconfig.aot.json && npm run module:css",
"module:css": "node build/join-module-css.js",
"webpack:prod": "webpack --config build/webpack.prod.js --profile --bail",
"build:sass": "node-sass -q -o lib lib",
"build:prod": "npm run build:sass && npm run ngc && npm run webpack:prod",
"build-dist": "npm run build:prod",
"build:all": "npm run clean && npm run build:prod && npm run build:aot",
"build:all": "npm run clean && npm run build:prod && npm run build:module",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
"stats": "webpack --config build/webpack.prod.js --json > stats.json"
},
Expand Down Expand Up @@ -141,7 +142,6 @@
"scrollparent": "^2.0.1",
"slugify": "^1.0.2",
"stream-http": "^2.6.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.8.14"
}
}
2 changes: 0 additions & 2 deletions tsconfig.aot.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmitHelpers": true,
"outDir": "./dist",
"strictNullChecks": false,
"typeRoots": [ "./node_modules/@types" ],
Expand All @@ -24,7 +23,6 @@
},
"files": [
"custom.d.ts",
".tmp/lib/vendor.ts",
".tmp/lib/polyfills.ts",
".tmp/lib/redoc.module.ts"
],
Expand Down

0 comments on commit ef5101b

Please sign in to comment.