Skip to content

Commit

Permalink
feat: init first slide for toolset
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 26, 2020
1 parent 2f62b1a commit bd2ce8c
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ import { ToolsetComponent } from './shared/toolset/toolset.component';
ResourcesComponent,
ReporterComponent,
AwesomeToolComponent,
MobileComponent,
ToolsetComponent
MobileComponent
],
imports: [
SharedModule,
Expand All @@ -62,6 +61,7 @@ import { ToolsetComponent } from './shared/toolset/toolset.component';
DragulaModule.forRoot(),
],
providers: [Title],
exports: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

<markdown class="markdown" [data]="data" *ngIf="data"></markdown>
<mat-spinner *ngIf="loading" class="loading" color="accent"></mat-spinner>

<div *ngFor="let tool of toolsets">
<div class="toolset-render"><toolset [option]="tool"></toolset></div>
</div>

</mat-drawer-content>
</mat-drawer-container>
</div>
Expand All @@ -21,6 +26,11 @@
(load)="endLoading()"
></markdown>
<mat-spinner *ngIf="loading" class="loading" color="accent"></mat-spinner>

<div *ngFor="let tool of toolsets">
<div class="toolset-render"><toolset [option]="tool"></toolset></div>
</div>

</div>

<!--Scroll to top-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:host {
position: relative;
}

.markdown-toc {
min-height: 600px;
height: calc(100vh - 66px);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
private webComponentsIndex = 0;
private webComponentsData = [];

private toolsetId = 0;
toolsets: ToolsetOption[] = [];

constructor(private markdownService: MarkdownService,
private tocify: Tocify,
private location: Location,
Expand Down Expand Up @@ -108,11 +111,13 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
this.chartIndex = 0;
this.webComponentsIndex = 0;
this.mermaidIndex = 0;
this.toolsetId = 0;

this.chartInfos = [];
this.mermaidData = [];
this.graphvizData = [];
this.webComponentsData = [];
this.toolsets = [];
}
}

Expand Down Expand Up @@ -257,6 +262,8 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
return this.buildEchartsData(code);
case 'webcomponents':
return this.buildWebComponents(code);
case 'toolset':
return this.buildToolsets(code);
default:
return this.buildNormalCode(options, code, lang, escaped);
}
Expand Down Expand Up @@ -653,4 +660,21 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
this.renderer2.appendChild(this.document.body, script);
}
}

private buildToolsets(code: any) {
this.toolsetId++;

const id = 'toolset-' + this.webComponentsIndex;
const tokens = marked.lexer(code);
let items: any;
items = MarkdownHelper.markdownToJSON(tokens, items);

this.toolsets.push({
id,
data: items,
type: items.config.type
});

return `<div class="toolset-placeholder" id="${id}"></div>`;
}
}
6 changes: 6 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { MarkdownReporterComponent } from './components/markdown-reporter/markdo
import { MarkdownChartComponent } from './components/markdown-chart/markdown-chart.component';
import { MarkdownTreeComponent } from './components/markdown-tree/markdown-tree.component';
import Tocify from './components/markdown-render/tocify';
import { MobileComponent } from '../presentation/mobile/mobile.component';
import { ToolsetComponent } from './toolset/toolset.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -50,6 +52,8 @@ import Tocify from './components/markdown-render/tocify';
MarkdownReporterComponent,
MarkdownChartComponent,
MarkdownTreeComponent,

ToolsetComponent
],
providers: [
Tocify,
Expand All @@ -63,6 +67,8 @@ import Tocify from './components/markdown-render/tocify';
MarkdownReporterComponent,
MarkdownChartComponent,
MarkdownTreeComponent,

ToolsetComponent
],
entryComponents: []
})
Expand Down
14 changes: 8 additions & 6 deletions src/app/shared/toolset/toolset.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div *ngIf="option" [ngSwitch]="option.type">
<div *ngSwitchCase>

</div>
<div *ngSwitchDefault>
it works
<div *ngIf="option">
<div [ngSwitch]="true" [ngStyle]="buildStyle(option)">
<div *ngSwitchCase="option.type === 'slider'" >
<mat-slider step="4" tickInterval="3"></mat-slider>
</div>
<div *ngSwitchDefault>
<h1>it works</h1>
</div>
</div>
</div>
16 changes: 14 additions & 2 deletions src/app/shared/toolset/toolset.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { Component, Input, OnInit } from '@angular/core';

@Component({
selector: 'app-toolset',
selector: 'toolset',
templateUrl: './toolset.component.html',
styleUrls: ['./toolset.component.scss']
})
export class ToolsetComponent implements OnInit {

@Input()
option: ToolsetOption;

constructor() { }

ngOnInit(): void {
console.log(this.option);
}

buildStyle(option: ToolsetOption) {
const element = document.getElementById(option.id);
if (element == null) {
return;
}

return {
zIndex: 999,
top: element.offsetTop + 'px',
position: 'absolute'
};
}
}
7 changes: 4 additions & 3 deletions src/app/shared/toolset/toolset.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface ToolsetOption {
id: string;
type: string; // slider
offsetHeight: string;
height: string;
type?: string; // slider
data: any[];
offsetHeight?: string;
height?: string;
}
8 changes: 8 additions & 0 deletions src/assets/docs/tool.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 工具

```toolset
- hello
- world
- a
config: {"type": "slider"}
```

## 架构

### 权衡滑块
Expand Down
6 changes: 6 additions & 0 deletions src/styles/_markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,9 @@
width: 600px;
height: 400px;
}

.toolset-placeholder {
width: auto;
display: block;
height: 600px;
}

0 comments on commit bd2ce8c

Please sign in to comment.