diff --git a/README.md b/README.md index acd732c..80faa02 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ngx-simplemde -Angular for [simplemde](https://simplemde.com/). +Angular for [simplemde](https://simplemde.com/), better use [ng-zorro-antd](https://ng.ant.design/) components. [![NPM version](https://img.shields.io/npm/v/ngx-simplemde.svg)](https://www.npmjs.com/package/ngx-simplemde) [![Build Status](https://travis-ci.org/cipchk/ngx-simplemde.svg?branch=master)](https://travis-ci.org/cipchk/ngx-simplemde) @@ -31,25 +31,18 @@ import { SimplemdeModule } from 'ngx-simplemde'; export class AppModule { } ``` -3. Add `simplemde.min.js` to `angular.json`. +3. Add `simplemde-antd.min.js` and styles to `angular.json`. ``` "styles": [ - "node_modules/simplemde/dist/simplemde.min.css", + "node_modules/ngx-simplemde/src/index.css", "src/styles.css" ], "scripts": [ - "node_modules/simplemde/dist/simplemde.min.js" + "node_modules/simplemde-antd/dist/simplemde.min.js" ] ``` -or using cdn in `index.html`. - -```html - - -``` - 4. Happy coding. ```html diff --git a/angular.json b/angular.json index e2fba84..e9029c3 100644 --- a/angular.json +++ b/angular.json @@ -18,10 +18,11 @@ "polyfills": "src/polyfills.ts", "assets": ["src/assets"], "styles": [ - "node_modules/simplemde/dist/simplemde.min.css", + "node_modules/ng-zorro-antd/src/ng-zorro-antd.css", + "lib/index.less", "src/styles.less" ], - "scripts": ["node_modules/simplemde/dist/simplemde.min.js"] + "scripts": ["node_modules/simplemde-antd/dist/simplemde.min.js"] }, "configurations": { "production": { @@ -67,7 +68,7 @@ "tsConfig": "lib/tsconfig.spec.json", "karmaConfig": "karma.conf.js", "polyfills": "src/polyfills.ts", - "scripts": ["node_modules/simplemde/dist/simplemde.min.js"], + "scripts": ["node_modules/simplemde-antd/dist/simplemde.min.js"], "styles": [], "assets": ["src/assets"] } diff --git a/build.sh b/build.sh index e47bd39..a4255a7 100644 --- a/build.sh +++ b/build.sh @@ -53,3 +53,6 @@ cp package.json publish/package.json echo 'Copying README.md' cp README.md publish/README.md + +echo 'Copying less' +node ./scripts/generate-style.js diff --git a/lib/index.less b/lib/index.less new file mode 100644 index 0000000..5e9b761 --- /dev/null +++ b/lib/index.less @@ -0,0 +1,5 @@ +@import './styles/_var.less'; +@import './styles/icon.less'; +@import './styles/codemirror.less'; +@import './styles/antd.less'; +@import './styles/fix.less'; diff --git a/lib/src/component.ts b/lib/src/component.ts index f356ba1..9c02594 100644 --- a/lib/src/component.ts +++ b/lib/src/component.ts @@ -44,19 +44,44 @@ export class SimplemdeComponent private onTouched: () => void; @Input() options: any; + /** 风格,默认:`antd` */ + @Input() style: 'default' | 'antd'; + /** 延迟初始化 */ + @Input() delay: number; constructor( private cog: SimplemdeConfig, private cd: ChangeDetectorRef, private zone: NgZone, - ) {} + ) { + this.style = cog.style; + this.delay = cog.delay || 0; + } + + private initDelay() { + if (this.delay > 0) { + setTimeout(() => this.init(), this.delay); + } else { + this.init(); + } + } private init() { if (typeof SimpleMDE === 'undefined') { throw new Error(`Could not find SimpleMDE object.`); } this.destroy(); - const config = { ...this.cog, ...this.options }; + const config = Object.assign( + {}, + this.cog, + this.options, + this.style === 'antd' + ? { + spellChecker: false, + autoDownloadFontAwesome: false, + } + : {}, + ); config.element = this.con.nativeElement; this.zone.runOutsideAngular(() => { this.instance = new SimpleMDE(config); @@ -78,13 +103,13 @@ export class SimplemdeComponent } ngAfterViewInit(): void { - this.init(); + this.initDelay(); } ngOnChanges( changes: { [P in keyof this]?: SimpleChange } & SimpleChanges, ): void { - if (!changes.options.firstChange) this.init(); + if (!changes.options.firstChange) this.initDelay(); } /** @@ -102,7 +127,7 @@ export class SimplemdeComponent // reuse-tab: http://ng-alain.com/components/reuse-tab#%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F _onReuseInit() { - this.init(); + this.initDelay(); } writeValue(value: string): void { diff --git a/lib/src/config.ts b/lib/src/config.ts index 22620f7..9b49c9d 100644 --- a/lib/src/config.ts +++ b/lib/src/config.ts @@ -1,3 +1,12 @@ export class SimplemdeConfig { - [key: string]: any; + /** + * 风格,默认:`antd` + */ + style?: 'default' | 'antd' = 'antd'; + /** + * 延迟初始化 + */ + delay?: number; + /** 全局 `options` */ + options?: { [key: string]: any }; } diff --git a/lib/styles/_var.less b/lib/styles/_var.less new file mode 100644 index 0000000..e2a23f9 --- /dev/null +++ b/lib/styles/_var.less @@ -0,0 +1,8 @@ +@simplemde-icon-url: '//at.alicdn.com/t/font_700857_mnodkd1cp9l766r'; +@simplemde-zindex: 3000; +@simplemde-min-height: 200px; + +@simplemde-statusbar-lines: '行数:'; +@simplemde-statusbar-words: '字符:'; +@simplemde-statusbar-characters: '字符:'; +@simplemde-statusbar-counts: '字数:'; diff --git a/lib/styles/antd.less b/lib/styles/antd.less new file mode 100644 index 0000000..904e5ea --- /dev/null +++ b/lib/styles/antd.less @@ -0,0 +1,325 @@ +.CodeMirror { + height: auto; + min-height: @simplemde-min-height; + border: 1px solid #ddd; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + padding: 10px; + font: inherit; + z-index: 1; +} + +.CodeMirror-scroll { + min-height: @simplemde-min-height; +} + +.CodeMirror-fullscreen { + background: #fff; + position: fixed !important; + top: 50px; + left: 0; + right: 0; + bottom: 0; + height: auto; + z-index: @simplemde-zindex; +} + +.CodeMirror-sided { + width: 50% !important; +} + +.editor-toolbar { + position: relative; + opacity: 0.6; + user-select: none; + padding: 0 10px; + border: 1px solid #bbb; + border-bottom: none; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} + +.editor-toolbar:after, +.editor-toolbar:before { + display: block; + content: ' '; + height: 1px; +} + +.editor-toolbar:before { + margin-bottom: 8px; +} + +.editor-toolbar:after { + margin-top: 8px; +} + +.editor-toolbar:hover, +.editor-wrapper input.title:focus, +.editor-wrapper input.title:hover { + opacity: 0.8; +} + +.editor-toolbar.fullscreen { + width: 100%; + height: 50px; + overflow-x: auto; + overflow-y: hidden; + white-space: nowrap; + padding-top: 10px; + padding-bottom: 10px; + box-sizing: border-box; + background: #fff; + border: 0; + position: fixed; + top: 0; + left: 0; + opacity: 1; + z-index: @simplemde-zindex; +} + +.editor-toolbar.fullscreen::before { + width: 20px; + height: 50px; + background: linear-gradient( + to right, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); + position: fixed; + top: 0; + left: 0; + margin: 0; + padding: 0; +} + +.editor-toolbar.fullscreen::after { + width: 20px; + height: 50px; + background: linear-gradient( + to right, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); + position: fixed; + top: 0; + right: 0; + margin: 0; + padding: 0; +} + +.editor-toolbar a { + display: inline-block; + text-align: center; + text-decoration: none !important; + color: #2c3e50 !important; + width: 30px; + height: 30px; + margin: 0; + border: 1px solid transparent; + border-radius: 3px; + cursor: pointer; +} + +.editor-toolbar a.active, +.editor-toolbar a:hover { + background: #fcfcfc; + border-color: #95a5a6; +} + +.editor-toolbar a:before { + line-height: 30px; +} + +.editor-toolbar i.separator { + display: inline-block; + width: 0; + border-left: 1px solid #d9d9d9; + border-right: 1px solid #fff; + color: transparent; + text-indent: -10px; + margin: 0 6px; +} + +.editor-toolbar a.fa-header-x:after { + font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; + font-size: 65%; + vertical-align: text-bottom; + position: relative; + top: 2px; +} + +.editor-toolbar a.fa-header-1:after { + content: '1'; +} + +.editor-toolbar a.fa-header-2:after { + content: '2'; +} + +.editor-toolbar a.fa-header-3:after { + content: '3'; +} + +.editor-toolbar a.fa-header-bigger:after { + content: '▲'; +} + +.editor-toolbar a.fa-header-smaller:after { + content: '▼'; +} + +.editor-toolbar.disabled-for-preview a:not(.no-disable) { + pointer-events: none; + background: #fff; + border-color: transparent; + text-shadow: inherit; +} + +@media only screen and (max-width: 700px) { + .editor-toolbar a.no-mobile { + display: none; + } +} + +.editor-statusbar { + padding: 8px 10px; + font-size: 12px; + color: #959694; + text-align: right; +} + +.editor-statusbar span { + display: inline-block; + min-width: 4em; + margin-left: 1em; +} + +.editor-statusbar .lines:before { + content: @simplemde-statusbar-lines; +} + +.editor-statusbar .words:before { + content: @simplemde-statusbar-words; +} + +.editor-statusbar .characters:before { + content: @simplemde-statusbar-characters; +} + +.editor-statusbar .counts:before { + content: @simplemde-statusbar-counts; +} + +.editor-preview { + padding: 10px; + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; + background: #fafafa; + z-index: 7; + overflow: auto; + display: none; + box-sizing: border-box; +} + +.editor-preview-side { + padding: 10px; + position: fixed; + bottom: 0; + width: 50%; + top: 50px; + right: 0; + background: #fafafa; + z-index: @simplemde-zindex; + overflow: auto; + display: none; + box-sizing: border-box; + border: 1px solid #ddd; +} + +.editor-preview-active-side { + display: block; +} + +.editor-preview-active { + display: block; +} + +.editor-preview > p, +.editor-preview-side > p { + margin-top: 0; +} + +.editor-preview pre, +.editor-preview-side pre { + background: #eee; + margin-bottom: 10px; +} + +.editor-preview table td, +.editor-preview table th, +.editor-preview-side table td, +.editor-preview-side table th { + border: 1px solid #ddd; + padding: 5px; +} + +.CodeMirror .CodeMirror-code .cm-tag { + color: #63a35c; +} + +.CodeMirror .CodeMirror-code .cm-attribute { + color: #795da3; +} + +.CodeMirror .CodeMirror-code .cm-string { + color: #183691; +} + +.CodeMirror .CodeMirror-selected { + background: #d9d9d9; +} + +.CodeMirror .CodeMirror-code .cm-header-1 { + font-size: 200%; + line-height: 200%; +} + +.CodeMirror .CodeMirror-code .cm-header-2 { + font-size: 160%; + line-height: 160%; +} + +.CodeMirror .CodeMirror-code .cm-header-3 { + font-size: 125%; + line-height: 125%; +} + +.CodeMirror .CodeMirror-code .cm-header-4 { + font-size: 110%; + line-height: 110%; +} + +.CodeMirror .CodeMirror-code .cm-comment { + background: rgba(0, 0, 0, 0.05); + border-radius: 2px; +} + +.CodeMirror .CodeMirror-code .cm-link { + color: #7f8c8d; +} + +.CodeMirror .CodeMirror-code .cm-url { + color: #aab2b3; +} + +.CodeMirror .CodeMirror-code .cm-strikethrough { + text-decoration: line-through; +} + +.CodeMirror .CodeMirror-placeholder { + opacity: 0.5; +} diff --git a/lib/styles/codemirror.less b/lib/styles/codemirror.less new file mode 100644 index 0000000..c7a8ae7 --- /dev/null +++ b/lib/styles/codemirror.less @@ -0,0 +1,346 @@ +/* BASICS */ + +.CodeMirror { + /* Set height, width, borders, and global font properties here */ + font-family: monospace; + height: 300px; + color: black; + direction: ltr; +} + +/* PADDING */ + +.CodeMirror-lines { + padding: 4px 0; /* Vertical padding around content */ +} +.CodeMirror pre { + padding: 0 4px; /* Horizontal padding of content */ +} + +.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { + background-color: white; /* The little square between H and V scrollbars */ +} + +/* GUTTER */ + +.CodeMirror-gutters { + border-right: 1px solid #ddd; + background-color: #f7f7f7; + white-space: nowrap; +} +.CodeMirror-linenumbers {} +.CodeMirror-linenumber { + padding: 0 3px 0 5px; + min-width: 20px; + text-align: right; + color: #999; + white-space: nowrap; +} + +.CodeMirror-guttermarker { color: black; } +.CodeMirror-guttermarker-subtle { color: #999; } + +/* CURSOR */ + +.CodeMirror-cursor { + border-left: 1px solid black; + border-right: none; + width: 0; +} +/* Shown when moving in bi-directional text */ +.CodeMirror div.CodeMirror-secondarycursor { + border-left: 1px solid silver; +} +.cm-fat-cursor .CodeMirror-cursor { + width: auto; + border: 0 !important; + background: #7e7; +} +.cm-fat-cursor div.CodeMirror-cursors { + z-index: 1; +} +.cm-fat-cursor-mark { + background-color: rgba(20, 255, 20, 0.5); + -webkit-animation: blink 1.06s steps(1) infinite; + -moz-animation: blink 1.06s steps(1) infinite; + animation: blink 1.06s steps(1) infinite; +} +.cm-animate-fat-cursor { + width: auto; + border: 0; + -webkit-animation: blink 1.06s steps(1) infinite; + -moz-animation: blink 1.06s steps(1) infinite; + animation: blink 1.06s steps(1) infinite; + background-color: #7e7; +} +@-moz-keyframes blink { + 0% {} + 50% { background-color: transparent; } + 100% {} +} +@-webkit-keyframes blink { + 0% {} + 50% { background-color: transparent; } + 100% {} +} +@keyframes blink { + 0% {} + 50% { background-color: transparent; } + 100% {} +} + +/* Can style cursor different in overwrite (non-insert) mode */ +.CodeMirror-overwrite .CodeMirror-cursor {} + +.cm-tab { display: inline-block; text-decoration: inherit; } + +.CodeMirror-rulers { + position: absolute; + left: 0; right: 0; top: -50px; bottom: -20px; + overflow: hidden; +} +.CodeMirror-ruler { + border-left: 1px solid #ccc; + top: 0; bottom: 0; + position: absolute; +} + +/* DEFAULT THEME */ + +.cm-s-default .cm-header {color: blue;} +.cm-s-default .cm-quote {color: #090;} +.cm-negative {color: #d44;} +.cm-positive {color: #292;} +.cm-header, .cm-strong {font-weight: bold;} +.cm-em {font-style: italic;} +.cm-link {text-decoration: underline;} +.cm-strikethrough {text-decoration: line-through;} + +.cm-s-default .cm-keyword {color: #708;} +.cm-s-default .cm-atom {color: #219;} +.cm-s-default .cm-number {color: #164;} +.cm-s-default .cm-def {color: #00f;} +.cm-s-default .cm-variable, +.cm-s-default .cm-punctuation, +.cm-s-default .cm-property, +.cm-s-default .cm-operator {} +.cm-s-default .cm-variable-2 {color: #05a;} +.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;} +.cm-s-default .cm-comment {color: #a50;} +.cm-s-default .cm-string {color: #a11;} +.cm-s-default .cm-string-2 {color: #f50;} +.cm-s-default .cm-meta {color: #555;} +.cm-s-default .cm-qualifier {color: #555;} +.cm-s-default .cm-builtin {color: #30a;} +.cm-s-default .cm-bracket {color: #997;} +.cm-s-default .cm-tag {color: #170;} +.cm-s-default .cm-attribute {color: #00c;} +.cm-s-default .cm-hr {color: #999;} +.cm-s-default .cm-link {color: #00c;} + +.cm-s-default .cm-error {color: #f00;} +.cm-invalidchar {color: #f00;} + +.CodeMirror-composing { border-bottom: 2px solid; } + +/* Default styles for common addons */ + +div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;} +div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;} +.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } +.CodeMirror-activeline-background {background: #e8f2ff;} + +/* STOP */ + +/* The rest of this file contains styles related to the mechanics of + the editor. You probably shouldn't touch them. */ + +.CodeMirror { + position: relative; + overflow: hidden; + background: white; +} + +.CodeMirror-scroll { + overflow: scroll !important; /* Things will break if this is overridden */ + /* 30px is the magic margin used to hide the element's real scrollbars */ + /* See overflow: hidden in .CodeMirror */ + margin-bottom: -30px; margin-right: -30px; + padding-bottom: 30px; + height: 100%; + outline: none; /* Prevent dragging from highlighting the element */ + position: relative; +} +.CodeMirror-sizer { + position: relative; + border-right: 30px solid transparent; +} + +/* The fake, visible scrollbars. Used to force redraw during scrolling + before actual scrolling happens, thus preventing shaking and + flickering artifacts. */ +.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { + position: absolute; + z-index: 6; + display: none; +} +.CodeMirror-vscrollbar { + right: 0; top: 0; + overflow-x: hidden; + overflow-y: scroll; +} +.CodeMirror-hscrollbar { + bottom: 0; left: 0; + overflow-y: hidden; + overflow-x: scroll; +} +.CodeMirror-scrollbar-filler { + right: 0; bottom: 0; +} +.CodeMirror-gutter-filler { + left: 0; bottom: 0; +} + +.CodeMirror-gutters { + position: absolute; left: 0; top: 0; + min-height: 100%; + z-index: 3; +} +.CodeMirror-gutter { + white-space: normal; + height: 100%; + display: inline-block; + vertical-align: top; + margin-bottom: -30px; +} +.CodeMirror-gutter-wrapper { + position: absolute; + z-index: 4; + background: none !important; + border: none !important; +} +.CodeMirror-gutter-background { + position: absolute; + top: 0; bottom: 0; + z-index: 4; +} +.CodeMirror-gutter-elt { + position: absolute; + cursor: default; + z-index: 4; +} +.CodeMirror-gutter-wrapper ::selection { background-color: transparent } +.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent } + +.CodeMirror-lines { + cursor: text; + min-height: 1px; /* prevents collapsing before first draw */ +} +.CodeMirror pre { + /* Reset some styles that the rest of the page might have set */ + -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; + border-width: 0; + background: transparent; + font-family: inherit; + font-size: inherit; + margin: 0; + white-space: pre; + word-wrap: normal; + line-height: inherit; + color: inherit; + z-index: 2; + position: relative; + overflow: visible; + -webkit-tap-highlight-color: transparent; + -webkit-font-variant-ligatures: contextual; + font-variant-ligatures: contextual; +} +.CodeMirror-wrap pre { + word-wrap: break-word; + white-space: pre-wrap; + word-break: normal; +} + +.CodeMirror-linebackground { + position: absolute; + left: 0; right: 0; top: 0; bottom: 0; + z-index: 0; +} + +.CodeMirror-linewidget { + position: relative; + z-index: 2; + padding: 0.1px; /* Force widget margins to stay inside of the container */ +} + +.CodeMirror-widget {} + +.CodeMirror-rtl pre { direction: rtl; } + +.CodeMirror-code { + outline: none; +} + +/* Force content-box sizing for the elements where we expect it */ +.CodeMirror-scroll, +.CodeMirror-sizer, +.CodeMirror-gutter, +.CodeMirror-gutters, +.CodeMirror-linenumber { + -moz-box-sizing: content-box; + box-sizing: content-box; +} + +.CodeMirror-measure { + position: absolute; + width: 100%; + height: 0; + overflow: hidden; + visibility: hidden; +} + +.CodeMirror-cursor { + position: absolute; + pointer-events: none; +} +.CodeMirror-measure pre { position: static; } + +div.CodeMirror-cursors { + visibility: hidden; + position: relative; + z-index: 3; +} +div.CodeMirror-dragcursors { + visibility: visible; +} + +.CodeMirror-focused div.CodeMirror-cursors { + visibility: visible; +} + +.CodeMirror-selected { background: #d9d9d9; } +.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } +.CodeMirror-crosshair { cursor: crosshair; } +.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; } +.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } + +.cm-searching { + background-color: #ffa; + background-color: rgba(255, 255, 0, .4); +} + +/* Used to force a border model for a node */ +.cm-force-border { padding-right: .1px; } + +@media print { + /* Hide the cursor when printing */ + .CodeMirror div.CodeMirror-cursors { + visibility: hidden; + } +} + +/* See issue #2901 */ +.cm-tab-wrap-hack:after { content: ''; } + +/* Help users use markselection to safely style text background */ +span.CodeMirror-selectedtext { background: none; } diff --git a/lib/styles/fix.less b/lib/styles/fix.less new file mode 100644 index 0000000..5304a62 --- /dev/null +++ b/lib/styles/fix.less @@ -0,0 +1,4 @@ +simplemde { + display: block; + line-height: initial; +} diff --git a/lib/styles/icon.less b/lib/styles/icon.less new file mode 100644 index 0000000..6ff66eb --- /dev/null +++ b/lib/styles/icon.less @@ -0,0 +1,55 @@ +@font-face { + font-family: 'simplemde-icon'; /* project id 700857 */ + src: url('@{simplemde-icon-url}.eot'); + src: url('@{simplemde-icon-url}.eot?#iefix') format('embedded-opentype'), + url('@{simplemde-icon-url}.woff') format('woff'), + url('@{simplemde-icon-url}.ttf') format('truetype'), + url('@{simplemde-icon-url}.svg#simplemde-icon') format('svg'); +} + +.smdi { + font-family:"simplemde-icon" !important; + font-size:16px; + font-style:normal; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.smdi-eraser:before { content: "\e89c"; } + +.smdi-quote-left:before { content: "\e605"; } + +.smdi-undo:before { content: "\e787"; } + +.smdi-redo:before { content: "\e788"; } + +.smdi-eye:before { content: "\e78f"; } + +.smdi-image:before { content: "\e7de"; } + +.smdi-table:before { content: "\e7df"; } + +.smdi-link:before { content: "\e7e2"; } + +.smdi-fullscreen:before { content: "\e7ec"; } + +.smdi-list-ul:before { content: "\e7f4"; } + +.smdi-list-ol:before { content: "\e7f5"; } + +.smdi-bold:before { content: "\e7f7"; } + +.smdi-strikethrough:before { content: "\e7f9"; } + +.smdi-header:before { content: "\e7f8"; } + +.smdi-italic:before { content: "\e7fb"; } + +.smdi-code:before { content: "\e7fc"; } + +.smdi-columns:before { content: "\e7fd"; } + +.smdi-line:before { content: "\e7ff"; } + +.smdi-question:before { content: "\e7fe"; } + diff --git a/package.json b/package.json index 1155968..660c03c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-simplemde", - "version": "1.0.0", + "version": "1.1.1", "main": "./bundles/simplemde.umd.js", "module": "./esm5/simplemde.js", "es2015": "./esm2015/simplemde.js", @@ -29,39 +29,34 @@ "lint": "tslint -p tsconfig.json -c tslint.json 'lib/*/*.ts'", "test": "ng test --code-coverage --watch=false", "site:build": "ng build --prod --build-optimizer", - "site:gh": - "ng build --prod --build-optimizer --base-href /ngx-simplemde/ && gh-pages -d ./dist", + "site:gh": "ng build --prod --build-optimizer --base-href /ngx-simplemde/ && gh-pages -d ./dist", "build": "bash ./build.sh", - "release:next": - "bash ./build.sh && cd publish && npm publish --access public --tag next", + "release:next": "bash ./build.sh && cd publish && npm publish --access public --tag next", "release": "bash ./build.sh && cd publish && npm publish --access public" }, "dependencies": { - "simplemde": "^1.11.2" + "simplemde-antd": "^1.0.0" }, "devDependencies": { + "@angular-devkit/build-angular": "~0.6.0", "@angular/animations": "^6.0.0", + "@angular/cli": "~6.0.0", "@angular/common": "^6.0.0", "@angular/compiler": "^6.0.0", + "@angular/compiler-cli": "^6.0.0", "@angular/core": "^6.0.0", "@angular/forms": "^6.0.0", "@angular/http": "^6.0.0", + "@angular/language-service": "^6.0.0", "@angular/platform-browser": "^6.0.0", "@angular/platform-browser-dynamic": "^6.0.0", "@angular/router": "^6.0.0", - "core-js": "^2.5.4", - "rxjs": "^6.0.0", - "zone.js": "^0.8.26", - "ngx-highlight-js": "^2.0.0", - "@angular-devkit/build-angular": "~0.6.0", - "@angular/cli": "~6.0.0", - "@angular/compiler-cli": "^6.0.0", - "@angular/language-service": "^6.0.0", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codecov": "^3.0.0", "codelyzer": "~4.2.1", + "core-js": "^2.5.4", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", @@ -69,14 +64,21 @@ "karma-coverage-istanbul-reporter": "~1.4.2", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", + "ngx-highlight-js": "^2.0.0", "protractor": "~5.3.0", "rollup": "^0.49.2", "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-replace": "^2.0.0", "rollup-plugin-sourcemaps": "^0.4.2", "rollup-plugin-uglify": "^2.0.1", + "rxjs": "^6.0.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", - "typescript": "~2.7.2" + "typescript": "~2.7.2", + "zone.js": "^0.8.26", + "fs-extra": "^6.0.1", + "less-plugin-clean-css": "^1.5.1", + "ng-zorro-antd": "^0.7.1", + "rxjs-compat": "^6.2.0" } } diff --git a/rollup.config.js b/rollup.config.js index ebcf141..e79ced6 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -37,12 +37,12 @@ switch (target) { } export default { - exports: "named", - name: "NgxSimplemde", plugins, external: Object.keys(globals), - globals, output: { + exports: "named", + name: "NgxSimplemde", + globals, sourcemap: true } }; diff --git a/scripts/generate-style.js b/scripts/generate-style.js new file mode 100644 index 0000000..ec548a7 --- /dev/null +++ b/scripts/generate-style.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const fse = require('fs-extra'); +const path = require('path'); +const less = require('less'); +const LessPluginCleanCSS = require('less-plugin-clean-css'); + +function compileLess(content, savePath, min) { + return new Promise((resolve, reject) => { + const plugins = []; + if (min) { + const cleanCSSPlugin = new LessPluginCleanCSS({advanced: true}); + plugins.push(cleanCSSPlugin); + } + return less.render + .call(less, content, { plugins }) + .then(({ css }) => { + fs.writeFileSync(savePath, css); + resolve(); + }) + .catch(err => reject(err)); + }); +} + +const sourcePath = path.resolve(__dirname, '../lib'); +const targetPath = path.resolve(__dirname, '../publish/src'); + +fse.copySync(`${sourcePath}/index.less`, `${targetPath}/index.less`); +fse.copySync(`${sourcePath}/styles`, `${targetPath}/styles`); + +const lessContent = `@import "${targetPath}/index.less";`; +compileLess(lessContent, path.join(targetPath, 'index.css'), false), +compileLess(lessContent, path.join(targetPath, 'index.min.css'), true) diff --git a/src/app/app.component.html b/src/app/app.component.html index 3fd9a30..c1d4c11 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,6 +2,7 @@

ngx-simplemde

Angular for simplemde

Demo

+

Customize toolbar

@@ -9,3 +10,6 @@

Autosaving

Hidden toolbar and status bar

+ + + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 553821d..631ec7d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -19,6 +19,8 @@ You can also choose to hide the statusbar and/or toolbar for a simple and clean }, }; + isVisible = false; + constructor(private http: HttpClient) { http .get('./assets/demo.md', { responseType: 'text' }) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5c20492..5d605c8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,7 +4,7 @@ import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; -import { HighlightJsModule } from 'ngx-highlight-js'; +import { NgZorroAntdModule } from 'ng-zorro-antd'; import { SimplemdeModule } from 'ngx-simplemde'; import { AppComponent } from './app.component'; @@ -15,9 +15,9 @@ import { AppComponent } from './app.component'; FormsModule, CommonModule, HttpClientModule, - HighlightJsModule, SimplemdeModule.forRoot({}), + NgZorroAntdModule.forRoot() ], declarations: [AppComponent], bootstrap: [AppComponent], diff --git a/src/index.html b/src/index.html index cdaba54..5725216 100644 --- a/src/index.html +++ b/src/index.html @@ -6,8 +6,6 @@ NgxSimplemde | Angular for simplemde - diff --git a/src/styles.less b/src/styles.less index 806b844..328ebaa 100644 --- a/src/styles.less +++ b/src/styles.less @@ -1,11 +1,13 @@ -pre { - padding: .8rem; - margin-top: 0; - margin-bottom: 1rem; - font: 1rem Consolas,liberation mono,Menlo,Courier,monospace; - color: #567482; - word-wrap: normal; - background-color: #f3f6fa; - border: solid 1px #dce6f0; - border-radius: .3rem +.editor-preview-side { + pre { + padding: 0.8rem; + margin-top: 0; + margin-bottom: 1rem; + font: 1rem Consolas, liberation mono, Menlo, Courier, monospace; + color: #567482; + word-wrap: normal; + background-color: #f3f6fa; + border: solid 1px #dce6f0; + border-radius: 0.3rem; + } }