Skip to content

Commit

Permalink
refactor(*): refactor dependencies (#616)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `DelonACLModule` muse be using `forRoot()`
  • Loading branch information
cipchk committed Jun 21, 2019
1 parent 7ebef13 commit 34db1dd
Show file tree
Hide file tree
Showing 30 changed files with 149 additions and 92 deletions.
1 change: 1 addition & 0 deletions packages/abc/edit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"entryFile": "public_api.ts",
"umdModuleIds": {
"ng-zorro-antd/tooltip": "ng-zorro-antd/tooltip",
"ng-zorro-antd/icon": "ng-zorro-antd/icon",
"@delon/theme": "delon.theme",
"@delon/util": "delon.util"
}
Expand Down
24 changes: 13 additions & 11 deletions packages/abc/ellipsis/ellipsis.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,47 +153,49 @@ export class EllipsisComponent implements AfterViewInit, OnChanges {
if (el.children.length > 0) {
throw new Error('Ellipsis content must be string.');
}
const text = el.textContent!;
const textLength = fullWidthRecognition ? this.getStrFullLength(text) : text.length;
const lengthText = el.textContent!;
const textLength = fullWidthRecognition
? this.getStrFullLength(lengthText)
: lengthText.length;
if (textLength <= length || length < 0) {
this.text = text;
this.text = lengthText;
} else {
let displayText: string;
if (length - tail.length <= 0) {
displayText = '';
} else {
displayText = fullWidthRecognition
? this.cutStrByFullLength(text, length)
: text.slice(0, length);
? this.cutStrByFullLength(lengthText, length)
: lengthText.slice(0, length);
}
this.text = displayText + tail;
}
cdr.detectChanges();
} else if (type === 'line') {
const { shadowOrgEl, shadowTextEl } = this;
const orgNode = shadowOrgEl.nativeElement as HTMLElement;
const text = orgNode.innerText || orgNode.textContent!;
const lineText = orgNode.innerText || orgNode.textContent!;
const lineHeight = parseInt(getComputedStyle(this.getEl('.ellipsis')).lineHeight!, 10);
const targetHeight = lines * lineHeight;
this.getEl('.ellipsis__handle').style.height = `${targetHeight}px`;

if (orgNode.offsetHeight <= targetHeight) {
this.text = text;
this.targetCount = text.length;
this.text = lineText;
this.targetCount = lineText.length;
} else {
// bisection
const len = text.length;
const len = lineText.length;
const mid = Math.ceil(len / 2);

const count = this.bisection(
targetHeight,
mid,
0,
len,
text,
lineText,
shadowTextEl.nativeElement.firstChild,
);
this.text = text;
this.text = lineText;
this.targetCount = count;
}
cdr.detectChanges();
Expand Down
7 changes: 5 additions & 2 deletions packages/abc/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"entryFile": "public_api.ts"
},
"whitelistedNonPeerDependencies": [
"tslib",
"tslib",
"file-saver",
"date-fns",
"qrious",
"ngx-countdown"
"ngx-countdown",
"@delon/theme",
"@delon/util",
"@delon/acl"
]
}
4 changes: 1 addition & 3 deletions packages/abc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
],
"dependencies": {
"file-saver": "^1.3.3",
"ngx-countdown": "^3.0.0"
},
"peerDependencies": {
"ngx-countdown": "^3.0.0",
"qrious": "^4.0.2",
"@delon/theme": "PEER-0.0.0-PLACEHOLDER",
"@delon/util": "PEER-0.0.0-PLACEHOLDER",
Expand Down
38 changes: 22 additions & 16 deletions packages/abc/page-header/page-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import { merge, Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

import { ReuseTabService } from '@delon/abc/reuse-tab';
import { AlainI18NService, ALAIN_I18N_TOKEN, Menu, MenuService, SettingsService, TitleService } from '@delon/theme';
import {
AlainI18NService,
ALAIN_I18N_TOKEN,
Menu,
MenuService,
SettingsService,
TitleService,
} from '@delon/theme';
import { isEmpty, InputBoolean, InputNumber } from '@delon/util';

import { PageHeaderConfig } from './page-header.config';
Expand All @@ -42,17 +49,18 @@ interface PageHeaderPath {
export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit, OnDestroy {
private inited = false;
private unsubscribe$ = new Subject<void>();
@ViewChild('conTpl', { static: false })
private conTpl: ElementRef;
@ViewChild('affix', { static: false })
private affix: NzAffixComponent;
@ViewChild('conTpl', { static: false }) private conTpl: ElementRef;
@ViewChild('affix', { static: false }) private affix: NzAffixComponent;
private _menus: Menu[] | null;

private get menus() {
if (this._menus) {
return this._menus;
}
this._menus = this.menuSrv.getPathByUrl(this.router.url.split('?')[0], this.recursiveBreadcrumb);
this._menus = this.menuSrv.getPathByUrl(
this.router.url.split('?')[0],
this.recursiveBreadcrumb,
);

return this._menus;
}
Expand Down Expand Up @@ -102,15 +110,9 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit, On
private renderer: Renderer2,
private router: Router,
private menuSrv: MenuService,
@Optional()
@Inject(ALAIN_I18N_TOKEN)
private i18nSrv: AlainI18NService,
@Optional()
@Inject(TitleService)
private titleSrv: TitleService,
@Optional()
@Inject(ReuseTabService)
private reuseSrv: ReuseTabService,
@Optional() @Inject(ALAIN_I18N_TOKEN) private i18nSrv: AlainI18NService,
@Optional() @Inject(TitleService) private titleSrv: TitleService,
@Optional() @Inject(ReuseTabService) private reuseSrv: ReuseTabService,
private cdr: ChangeDetectorRef,
) {
Object.assign(this, { ...new PageHeaderConfig(), ...cog });
Expand All @@ -121,7 +123,11 @@ export class PageHeaderComponent implements OnInit, OnChanges, AfterViewInit, On
)
.subscribe(() => this.affix.updatePosition({} as any));

merge(menuSrv.change.pipe(filter(() => this.inited)), router.events.pipe(filter(e => e instanceof NavigationEnd)), i18nSrv.change)
merge(
menuSrv.change.pipe(filter(() => this.inited)),
router.events.pipe(filter(e => e instanceof NavigationEnd)),
i18nSrv.change,
)
.pipe(takeUntil(this.unsubscribe$))
.subscribe(() => {
this._menus = null;
Expand Down
1 change: 1 addition & 0 deletions packages/abc/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ng-zorro-antd/radio": "ng-zorro-antd/radio",
"ng-zorro-antd/table": "ng-zorro-antd/table",
"ng-zorro-antd/tag": "ng-zorro-antd/tag",
"ng-zorro-antd/input": "ng-zorro-antd/input",
"@delon/abc/xlsx": "delon.abc.xlsx",
"@delon/theme": "delon.theme",
"@delon/acl": "delon.acl",
Expand Down
2 changes: 2 additions & 0 deletions packages/abc/view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"entryFile": "public_api.ts",
"umdModuleIds": {
"@angular/cdk/observers": "ng.cdk.observers",
"ng-zorro-antd/tooltip": "ng-zorro-antd/tooltip",
"ng-zorro-antd/icon": "ng-zorro-antd/icon",
"@delon/theme": "delon.theme",
"@delon/util": "delon.util"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/acl/docs/getting-started.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DelonACLModule } from '@delon/acl';

@NgModule({
imports: [
DelonACLModule
DelonACLModule.forRoot()
]
})
export class AppModule { }
Expand Down
2 changes: 1 addition & 1 deletion packages/acl/docs/getting-started.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DelonACLModule } from '@delon/acl';

@NgModule({
imports: [
DelonACLModule
DelonACLModule.forRoot()
]
})
export class AppModule { }
Expand Down
5 changes: 4 additions & 1 deletion packages/acl/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"umdModuleIds": {
"@delon/util": "delon.util"
}
}
},
"whitelistedNonPeerDependencies": [
"tslib", "angular", "@delon/util"
]
}
2 changes: 1 addition & 1 deletion packages/acl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"angular",
"component"
],
"peerDependencies": {
"dependencies": {
"@delon/util": "PEER-0.0.0-PLACEHOLDER"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/acl/src/acl-guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('acl: guard', () => {

beforeEach(() => {
injector = TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([]), DelonACLModule],
imports: [RouterTestingModule.withRoutes([]), DelonACLModule.forRoot()],
});
srv = injector.get<ACLGuard>(ACLGuard);
acl = injector.get<ACLService>(ACLService);
Expand Down
2 changes: 1 addition & 1 deletion packages/acl/src/acl-if.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('acl-if: directive', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [DelonACLModule],
imports: [DelonACLModule.forRoot()],
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }],
});
fixture = TestBed.createComponent(TestComponent);
Expand Down
2 changes: 1 addition & 1 deletion packages/acl/src/acl.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('acl: directive', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [DelonACLModule],
imports: [DelonACLModule.forRoot()],
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }],
});
fixture = TestBed.createComponent(TestComponent);
Expand Down
12 changes: 10 additions & 2 deletions packages/acl/src/acl.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { DelonUtilModule } from '@delon/util';

import { ACLIfDirective } from './acl-if.directive';
import { ACLDirective } from './acl.directive';
import { ACLService } from './acl.service';

const COMPONENTS = [ACLDirective, ACLIfDirective];

Expand All @@ -12,4 +13,11 @@ const COMPONENTS = [ACLDirective, ACLIfDirective];
declarations: [...COMPONENTS],
exports: [...COMPONENTS],
})
export class DelonACLModule {}
export class DelonACLModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: DelonACLModule,
providers: [ACLService],
};
}
}
2 changes: 1 addition & 1 deletion packages/acl/src/acl.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ACLCanType, ACLType } from './acl.type';
/**
* 访问控制服务
*/
@Injectable({ providedIn: 'root' })
@Injectable()
export class ACLService {
private roles: string[] = [];
private abilities: Array<number | string> = [];
Expand Down
7 changes: 6 additions & 1 deletion packages/chart/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"@delon/theme": "delon.theme",
"@delon/util": "delon.util"
}
}
},
"whitelistedNonPeerDependencies": [
"tslib",
"@delon/theme",
"@delon/util"
]
}
2 changes: 1 addition & 1 deletion packages/chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"angular",
"component"
],
"peerDependencies": {
"dependencies": {
"@delon/util": "PEER-0.0.0-PLACEHOLDER",
"@delon/theme": "PEER-0.0.0-PLACEHOLDER"
},
Expand Down
8 changes: 7 additions & 1 deletion packages/form/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@
"@delon/acl": "delon.acl",
"@delon/util": "delon.util"
}
}
},
"whitelistedNonPeerDependencies": [
"tslib",
"@delon/theme",
"@delon/util",
"@delon/acl"
]
}
2 changes: 1 addition & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"angular",
"component"
],
"peerDependencies": {
"dependencies": {
"@delon/theme": "PEER-0.0.0-PLACEHOLDER",
"@delon/acl": "PEER-0.0.0-PLACEHOLDER",
"@delon/util": "PEER-0.0.0-PLACEHOLDER"
Expand Down
Loading

0 comments on commit 34db1dd

Please sign in to comment.