@dotcms/angular 0.0.1-alpha.37 → 0.0.1-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +18 -0
- package/README.md +128 -78
- package/jest.config.ts +22 -0
- package/ng-package.json +7 -0
- package/package.json +4 -21
- package/project.json +33 -0
- package/{index.d.ts → src/index.ts} +0 -1
- package/src/lib/components/dot-editable-text/dot-editable-text.component.css +4 -0
- package/src/lib/components/dot-editable-text/dot-editable-text.component.html +8 -0
- package/src/lib/components/dot-editable-text/dot-editable-text.component.spec.ts +424 -0
- package/src/lib/components/dot-editable-text/dot-editable-text.component.ts +269 -0
- package/src/lib/components/dot-editable-text/utils.ts +51 -0
- package/src/lib/components/no-component/no-component.component.css +3 -0
- package/src/lib/components/no-component/no-component.component.spec.ts +24 -0
- package/src/lib/components/no-component/no-component.component.ts +31 -0
- package/src/lib/layout/column/column.component.css +99 -0
- package/src/lib/layout/column/column.component.spec.ts +33 -0
- package/src/lib/layout/column/column.component.ts +49 -0
- package/src/lib/layout/container/container.component.css +9 -0
- package/src/lib/layout/container/container.component.html +26 -0
- package/src/lib/layout/container/container.component.spec.ts +205 -0
- package/src/lib/layout/container/container.component.ts +140 -0
- package/src/lib/layout/contentlet/contentlet.component.spec.ts +22 -0
- package/src/lib/layout/contentlet/contentlet.component.ts +101 -0
- package/src/lib/layout/dotcms-layout/dotcms-layout.component.css +3 -0
- package/src/lib/layout/dotcms-layout/dotcms-layout.component.spec.ts +195 -0
- package/src/lib/layout/dotcms-layout/dotcms-layout.component.ts +150 -0
- package/src/lib/layout/row/row.component.css +6 -0
- package/src/lib/layout/row/row.component.spec.ts +28 -0
- package/src/lib/layout/row/row.component.ts +32 -0
- package/{lib/models/dotcms.model.d.ts → src/lib/models/dotcms.model.ts} +21 -3
- package/src/lib/models/index.ts +47 -0
- package/{lib/services/dotcms-context/page-context.service.d.ts → src/lib/services/dotcms-context/page-context.service.ts} +41 -12
- package/src/lib/services/dotcms-context/page-context.spec.ts +80 -0
- package/src/lib/utils/index.ts +92 -0
- package/src/lib/utils/testing.utils.ts +1019 -0
- package/src/test-setup.ts +8 -0
- package/tsconfig.json +29 -0
- package/tsconfig.lib.json +12 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +11 -0
- package/dotcms-angular.d.ts.map +0 -1
- package/esm2022/dotcms-angular.mjs +0 -5
- package/esm2022/index.mjs +0 -5
- package/esm2022/lib/components/dot-editable-text/dot-editable-text.component.mjs +0 -225
- package/esm2022/lib/components/dot-editable-text/utils.mjs +0 -43
- package/esm2022/lib/components/no-component/no-component.component.mjs +0 -27
- package/esm2022/lib/layout/column/column.component.mjs +0 -33
- package/esm2022/lib/layout/container/container.component.mjs +0 -78
- package/esm2022/lib/layout/contentlet/contentlet.component.mjs +0 -65
- package/esm2022/lib/layout/dotcms-layout/dotcms-layout.component.mjs +0 -87
- package/esm2022/lib/layout/row/row.component.mjs +0 -23
- package/esm2022/lib/models/dotcms.model.mjs +0 -3
- package/esm2022/lib/models/index.mjs +0 -3
- package/esm2022/lib/services/dotcms-context/page-context.service.mjs +0 -75
- package/esm2022/lib/utils/index.mjs +0 -57
- package/fesm2022/dotcms-angular.mjs +0 -697
- package/fesm2022/dotcms-angular.mjs.map +0 -1
- package/index.d.ts.map +0 -1
- package/lib/components/dot-editable-text/dot-editable-text.component.d.ts +0 -129
- package/lib/components/dot-editable-text/dot-editable-text.component.d.ts.map +0 -1
- package/lib/components/dot-editable-text/utils.d.ts +0 -7
- package/lib/components/dot-editable-text/utils.d.ts.map +0 -1
- package/lib/components/no-component/no-component.component.d.ts +0 -13
- package/lib/components/no-component/no-component.component.d.ts.map +0 -1
- package/lib/layout/column/column.component.d.ts +0 -11
- package/lib/layout/column/column.component.d.ts.map +0 -1
- package/lib/layout/container/container.component.d.ts +0 -34
- package/lib/layout/container/container.component.d.ts.map +0 -1
- package/lib/layout/contentlet/contentlet.component.d.ts +0 -19
- package/lib/layout/contentlet/contentlet.component.d.ts.map +0 -1
- package/lib/layout/dotcms-layout/dotcms-layout.component.d.ts +0 -54
- package/lib/layout/dotcms-layout/dotcms-layout.component.d.ts.map +0 -1
- package/lib/layout/row/row.component.d.ts +0 -8
- package/lib/layout/row/row.component.d.ts.map +0 -1
- package/lib/models/dotcms.model.d.ts.map +0 -1
- package/lib/models/index.d.ts +0 -11
- package/lib/models/index.d.ts.map +0 -1
- package/lib/services/dotcms-context/page-context.service.d.ts.map +0 -1
- package/lib/utils/index.d.ts +0 -49
- package/lib/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
export * from './dotcms.model';
|
|
3
|
+
|
|
4
|
+
import { Type } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
import { DotCMSPageAsset } from './dotcms.model';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents a dynamic component entity.
|
|
10
|
+
* @typedef {Promise<Type<any>>} DynamicComponentEntity
|
|
11
|
+
* @memberof @dotcms/angular
|
|
12
|
+
*/
|
|
13
|
+
export type DynamicComponentEntity = Promise<Type<any>>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the context of a DotCMS page.
|
|
17
|
+
*/
|
|
18
|
+
export interface DotCMSPageContext {
|
|
19
|
+
/**
|
|
20
|
+
* Represents the DotCMS page asset.
|
|
21
|
+
* @type {DotCMSPageAsset}
|
|
22
|
+
* @memberof DotCMSPageContext
|
|
23
|
+
*/
|
|
24
|
+
pageAsset: DotCMSPageAsset;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Represents the dynamic components of the page for each Content Type.
|
|
28
|
+
* @type {DotCMSPageComponent}
|
|
29
|
+
* @memberof DotCMSPageContext
|
|
30
|
+
*/
|
|
31
|
+
components: DotCMSPageComponent;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Indicates whether the page is being viewed inside the editor.
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @memberof DotCMSPageContext
|
|
37
|
+
*/
|
|
38
|
+
isInsideEditor: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents a DotCMS page component.
|
|
43
|
+
* Used to store the dynamic components of a DotCMS page.
|
|
44
|
+
* @typedef {Record<string, DynamicComponentEntity>} DotCMSPageComponent
|
|
45
|
+
* @memberof @dotcms/angular
|
|
46
|
+
*/
|
|
47
|
+
export type DotCMSPageComponent = Record<string, DynamicComponentEntity>;
|
|
@@ -1,49 +1,78 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
1
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
import { Injectable } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
import { map } from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
import { isInsideEditor } from '@dotcms/client';
|
|
8
|
+
|
|
2
9
|
import { DotCMSPageComponent, DotCMSPageContext } from '../../models';
|
|
3
10
|
import { DotCMSPageAsset } from '../../models/dotcms.model';
|
|
4
|
-
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* @author dotCMS
|
|
7
14
|
* @description This service is responsible for managing the page context.
|
|
8
15
|
* @export
|
|
9
16
|
* @class PageContextService
|
|
10
17
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
@Injectable({
|
|
19
|
+
providedIn: 'root'
|
|
20
|
+
})
|
|
21
|
+
export class PageContextService {
|
|
22
|
+
private context$ = new BehaviorSubject<DotCMSPageContext | null>(null);
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* @description Get the context
|
|
15
26
|
* @readonly
|
|
16
27
|
* @type {DotCMSPageContext}
|
|
17
28
|
* @memberof PageContextService
|
|
18
29
|
*/
|
|
19
|
-
get context(): DotCMSPageContext
|
|
30
|
+
get context(): DotCMSPageContext {
|
|
31
|
+
return this.context$.getValue() as DotCMSPageContext;
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
/**
|
|
21
35
|
* @description Get the context as an observable
|
|
22
36
|
* @readonly
|
|
23
37
|
* @memberof PageContextService
|
|
24
38
|
*/
|
|
25
|
-
get contextObs$()
|
|
39
|
+
get contextObs$() {
|
|
40
|
+
return this.context$.asObservable();
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
/**
|
|
27
44
|
* @description Get the current page asset
|
|
28
45
|
* @readonly
|
|
29
46
|
* @type {(Observable<DotCMSPageAsset | null>)}
|
|
30
47
|
* @memberof PageContextService
|
|
31
48
|
*/
|
|
32
|
-
get currentPage$(): Observable<DotCMSPageAsset | null
|
|
49
|
+
get currentPage$(): Observable<DotCMSPageAsset | null> {
|
|
50
|
+
return this.contextObs$.pipe(map((context) => context?.pageAsset || null));
|
|
51
|
+
}
|
|
52
|
+
|
|
33
53
|
/**
|
|
34
54
|
*
|
|
35
55
|
* @description Set the context
|
|
36
56
|
* @param {DotCMSPageAsset} value
|
|
37
57
|
* @memberof DotcmsContextService
|
|
38
58
|
*/
|
|
39
|
-
setContext(pageAsset: DotCMSPageAsset, components: DotCMSPageComponent)
|
|
59
|
+
setContext(pageAsset: DotCMSPageAsset, components: DotCMSPageComponent) {
|
|
60
|
+
this.context$.next({
|
|
61
|
+
pageAsset,
|
|
62
|
+
components,
|
|
63
|
+
isInsideEditor: isInsideEditor()
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
40
67
|
/**
|
|
41
68
|
* @description Set the page asset in the context
|
|
42
69
|
* @param {DotCMSPageAsset} pageAsset
|
|
43
70
|
* @memberof PageContextService
|
|
44
71
|
*/
|
|
45
|
-
setPageAsset(pageAsset: DotCMSPageAsset)
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
setPageAsset(pageAsset: DotCMSPageAsset) {
|
|
73
|
+
this.context$.next({
|
|
74
|
+
...this.context,
|
|
75
|
+
pageAsset
|
|
76
|
+
});
|
|
77
|
+
}
|
|
48
78
|
}
|
|
49
|
-
//# sourceMappingURL=page-context.service.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { SpectatorService, createServiceFactory } from '@ngneat/spectator';
|
|
2
|
+
|
|
3
|
+
import { TestBed } from '@angular/core/testing';
|
|
4
|
+
|
|
5
|
+
import { PageContextService } from './page-context.service';
|
|
6
|
+
|
|
7
|
+
import { DotCMSPageAsset, DotCMSPageComponent } from '../../models';
|
|
8
|
+
import { PageResponseMock } from '../../utils/testing.utils';
|
|
9
|
+
|
|
10
|
+
const initialPageAssetMock = {} as DotCMSPageAsset;
|
|
11
|
+
const initialComponentsMock = {} as DotCMSPageComponent;
|
|
12
|
+
|
|
13
|
+
describe('PageContextService', () => {
|
|
14
|
+
let spectator: SpectatorService<PageContextService>;
|
|
15
|
+
let service: PageContextService;
|
|
16
|
+
|
|
17
|
+
const createService = createServiceFactory(PageContextService);
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
TestBed.configureTestingModule({});
|
|
21
|
+
spectator = createService();
|
|
22
|
+
service = spectator.service;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should set the context', () => {
|
|
26
|
+
service.setContext(initialPageAssetMock, initialComponentsMock);
|
|
27
|
+
|
|
28
|
+
expect(service.context).toEqual({
|
|
29
|
+
components: initialComponentsMock,
|
|
30
|
+
pageAsset: initialPageAssetMock,
|
|
31
|
+
isInsideEditor: false
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should set the page asset in the context', () => {
|
|
36
|
+
service.setContext(initialPageAssetMock, initialComponentsMock);
|
|
37
|
+
|
|
38
|
+
const newPageAssetMock = PageResponseMock as unknown as DotCMSPageAsset;
|
|
39
|
+
|
|
40
|
+
service.setPageAsset(newPageAssetMock);
|
|
41
|
+
|
|
42
|
+
expect(service.context).toEqual({
|
|
43
|
+
components: initialComponentsMock,
|
|
44
|
+
pageAsset: newPageAssetMock,
|
|
45
|
+
isInsideEditor: false
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return the context', () => {
|
|
50
|
+
service.setContext(initialPageAssetMock, initialComponentsMock);
|
|
51
|
+
|
|
52
|
+
expect(service.context).toEqual({
|
|
53
|
+
components: initialComponentsMock,
|
|
54
|
+
pageAsset: initialPageAssetMock,
|
|
55
|
+
isInsideEditor: false
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should return the context as an observable', (done) => {
|
|
60
|
+
service.setContext(initialPageAssetMock, initialComponentsMock);
|
|
61
|
+
|
|
62
|
+
service.contextObs$.subscribe((context) => {
|
|
63
|
+
expect(context).toEqual({
|
|
64
|
+
components: initialComponentsMock,
|
|
65
|
+
pageAsset: initialPageAssetMock,
|
|
66
|
+
isInsideEditor: false
|
|
67
|
+
});
|
|
68
|
+
done();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should return the page asset as an observable', (done) => {
|
|
73
|
+
service.setContext(initialPageAssetMock, initialComponentsMock);
|
|
74
|
+
|
|
75
|
+
service.currentPage$.subscribe((pageAsset) => {
|
|
76
|
+
expect(pageAsset).toEqual(initialPageAssetMock);
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DotCMSContainer, DotCMSPageAssetContainer } from '../models/dotcms.model';
|
|
2
|
+
|
|
3
|
+
//Changed the type, to avoid SQ issue.
|
|
4
|
+
//This should be put inside a lib
|
|
5
|
+
/**
|
|
6
|
+
* Represents a mapping of numbers to corresponding CSS class names for column end values.
|
|
7
|
+
* @typedef {Record<number, string | null>} EndClassMap
|
|
8
|
+
*/
|
|
9
|
+
const endClassMap: Record<number, string | null> = {
|
|
10
|
+
1: 'col-end-1',
|
|
11
|
+
2: 'col-end-2',
|
|
12
|
+
3: 'col-end-3',
|
|
13
|
+
4: 'col-end-4',
|
|
14
|
+
5: 'col-end-5',
|
|
15
|
+
6: 'col-end-6',
|
|
16
|
+
7: 'col-end-7',
|
|
17
|
+
8: 'col-end-8',
|
|
18
|
+
9: 'col-end-9',
|
|
19
|
+
10: 'col-end-10',
|
|
20
|
+
11: 'col-end-11',
|
|
21
|
+
12: 'col-end-12',
|
|
22
|
+
13: 'col-end-13'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//Changed the type, to avoid SQ issue.
|
|
26
|
+
//This should be put inside a lib
|
|
27
|
+
/**
|
|
28
|
+
* Represents a mapping of numbers to CSS class names for starting columns.
|
|
29
|
+
* @typedef {Record<number, string | null>} StartClassMap
|
|
30
|
+
*/
|
|
31
|
+
const startClassMap: Record<number, string | null> = {
|
|
32
|
+
1: 'col-start-1',
|
|
33
|
+
2: 'col-start-2',
|
|
34
|
+
3: 'col-start-3',
|
|
35
|
+
4: 'col-start-4',
|
|
36
|
+
5: 'col-start-5',
|
|
37
|
+
6: 'col-start-6',
|
|
38
|
+
7: 'col-start-7',
|
|
39
|
+
8: 'col-start-8',
|
|
40
|
+
9: 'col-start-9',
|
|
41
|
+
10: 'col-start-10',
|
|
42
|
+
11: 'col-start-11',
|
|
43
|
+
12: 'col-start-12'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the data for a set of containers.
|
|
48
|
+
*
|
|
49
|
+
* @param containers - The DotCMSPageAssetContainer object containing the containers.
|
|
50
|
+
* @param containerRef - The DotCMSContainer object representing the container reference.
|
|
51
|
+
* @returns An object containing the container data, accept types, contentlets, and variant ID.
|
|
52
|
+
*/
|
|
53
|
+
export const getContainersData = (
|
|
54
|
+
containers: DotCMSPageAssetContainer,
|
|
55
|
+
containerRef: DotCMSContainer
|
|
56
|
+
) => {
|
|
57
|
+
const { identifier, uuid } = containerRef;
|
|
58
|
+
|
|
59
|
+
const { containerStructures, container } = containers[identifier];
|
|
60
|
+
|
|
61
|
+
const { variantId } = container?.parentPermissionable || {};
|
|
62
|
+
|
|
63
|
+
const acceptTypes: string = containerStructures
|
|
64
|
+
.map((structure) => structure.contentTypeVar)
|
|
65
|
+
.join(',');
|
|
66
|
+
|
|
67
|
+
const contentlets = containers[identifier].contentlets[`uuid-${uuid}`];
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
...containers[identifier].container,
|
|
71
|
+
acceptTypes,
|
|
72
|
+
contentlets,
|
|
73
|
+
variantId
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns the position style classes based on the start and end values.
|
|
79
|
+
* Used to set the grid column start and end values.
|
|
80
|
+
* @param start - The start value.
|
|
81
|
+
* @param end - The end value.
|
|
82
|
+
* @returns An object containing the startClass and endClass.
|
|
83
|
+
*/
|
|
84
|
+
export const getPositionStyleClasses = (start: number, end: number) => {
|
|
85
|
+
const startClass = startClassMap[start];
|
|
86
|
+
const endClass = endClassMap[end];
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
startClass,
|
|
90
|
+
endClass
|
|
91
|
+
};
|
|
92
|
+
};
|