From ef5101b1f2aceba883cdf0208fb6de36c8fee485 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 22 Jul 2017 18:37:10 +0200 Subject: [PATCH] feat: export angular module --- build/join-module-css.js | 15 ++++++++++++++ build/webpack.dev.js | 1 - build/webpack.prod.js | 2 +- lib/components/Redoc/redoc.scss | 2 +- lib/polyfills.ts | 32 ----------------------------- lib/redoc.module.ts | 2 ++ lib/vendor.ts | 36 ++++++++++++++++++++++++++------- package.json | 6 +++--- tsconfig.aot.json | 2 -- 9 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 build/join-module-css.js diff --git a/build/join-module-css.js b/build/join-module-css.js new file mode 100644 index 0000000000..c41e2b259f --- /dev/null +++ b/build/join-module-css.js @@ -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') diff --git a/build/webpack.dev.js b/build/webpack.dev.js index 1811124433..6c54410284 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -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: { diff --git a/build/webpack.prod.js b/build/webpack.prod.js index 1d2bec9386..aaf8e90462 100644 --- a/build/webpack.prod.js +++ b/build/webpack.prod.js @@ -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: { diff --git a/lib/components/Redoc/redoc.scss b/lib/components/Redoc/redoc.scss index 38c6b3f3b6..abf2326e4f 100644 --- a/lib/components/Redoc/redoc.scss +++ b/lib/components/Redoc/redoc.scss @@ -283,7 +283,7 @@ footer { &:before, &:after { letter-spacing: -0.2em; - content: "\00a0"; + //content: "\00a0"; } } diff --git a/lib/polyfills.ts b/lib/polyfills.ts index 7f830a8f6c..e3f69e1454 100644 --- a/lib/polyfills.ts +++ b/lib/polyfills.ts @@ -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 (!(Element).prototype.scrollIntoViewIfNeeded) { - (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); - } - }; -} diff --git a/lib/redoc.module.ts b/lib/redoc.module.ts index 4e48104b00..8fd0372a00 100644 --- a/lib/redoc.module.ts +++ b/lib/redoc.module.ts @@ -1,3 +1,5 @@ +import './vendor'; + import { NgModule, ErrorHandler, APP_ID } from '@angular/core'; import { CommonModule } from '@angular/common'; diff --git a/lib/vendor.ts b/lib/vendor.ts index edbd866949..2aef3234b7 100644 --- a/lib/vendor.ts +++ b/lib/vendor.ts @@ -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 (!(Element).prototype.scrollIntoViewIfNeeded) { + (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); + } + }; } diff --git a/package.json b/package.json index da7f9aab1b..0bf4ad6d70 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } } diff --git a/tsconfig.aot.json b/tsconfig.aot.json index 988ce7e262..f8bce4b4a2 100644 --- a/tsconfig.aot.json +++ b/tsconfig.aot.json @@ -7,7 +7,6 @@ "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "sourceMap": true, - "noEmitHelpers": true, "outDir": "./dist", "strictNullChecks": false, "typeRoots": [ "./node_modules/@types" ], @@ -24,7 +23,6 @@ }, "files": [ "custom.d.ts", - ".tmp/lib/vendor.ts", ".tmp/lib/polyfills.ts", ".tmp/lib/redoc.module.ts" ],