@nascentdigital/funnel-core 4.5.7 → 4.6.1
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/dist/schema/Collection.d.ts +41 -10
- package/dist/schema/Collection.js +13 -0
- package/dist/schema/CollectionModel.d.ts +3 -3
- package/dist/schema/CollectionSnapshot.d.ts +1 -1
- package/dist/schema/LinkedCollectionModel.d.ts +1 -1
- package/dist/schema/LinkedData.d.ts +33 -14
- package/dist/schema/LinkedData.js +130 -76
- package/dist/schema/LinkedPage.d.ts +37 -0
- package/dist/schema/LinkedPage.js +103 -0
- package/dist/schema/Page.d.ts +55 -17
- package/dist/schema/Page.js +9 -0
- package/dist/schema/PageModel.d.ts +1 -1
- package/dist/schema/PageModel.js +1 -1
- package/dist/schema/PageSnapshot.d.ts +1 -1
- package/dist/schema/field/base/CollectionField.d.ts +1 -1
- package/dist/schema/field/base/DynamicPagesField.d.ts +7 -5
- package/dist/schema/field/base/DynamicPagesField.js +18 -2
- package/dist/schema/field/base/PageField.d.ts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/types/TrackedValue.d.ts +8 -0
- package/dist/types/TrackedValue.js +18 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/ui/Placement.d.ts +5 -2
- package/dist/ui/Placement.js +103 -91
- package/dist/utils/ObjectUtils.js +0 -1
- package/package.json +2 -2
- package/dist/schema/LinkedPageModel.d.ts +0 -11
- package/dist/schema/LinkedPageModel.js +0 -26
package/dist/ui/Placement.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Placement = void 0;
|
|
4
|
+
const TrackedValue_1 = require("../types/TrackedValue");
|
|
4
5
|
// extension
|
|
5
6
|
var Placement;
|
|
6
7
|
(function (Placement) {
|
|
@@ -15,119 +16,130 @@ var Placement;
|
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
Placement.getComponents = getComponents;
|
|
18
|
-
function forContent({ containerRect, containerPadding = 0, anchorRect, anchorOffset = 0, placement, contentSize }) {
|
|
19
|
+
function forContent({ containerRect, containerPadding = 0, anchorRect, anchorOffset = 0, placement, contentSize: trackedContentSize, viewportSize: trackedViewportSize, previousFrame }) {
|
|
20
|
+
// compute boundaries
|
|
19
21
|
const containerInsets = typeof containerPadding === 'number'
|
|
20
22
|
? { left: containerPadding, right: containerPadding, top: containerPadding, bottom: containerPadding }
|
|
21
23
|
: containerPadding;
|
|
22
|
-
|
|
24
|
+
const { previous: previousContentSize, current: contentSize } = TrackedValue_1.TrackedValue.filter(trackedContentSize)
|
|
25
|
+
? trackedContentSize
|
|
26
|
+
: { previous: trackedContentSize, current: trackedContentSize };
|
|
27
|
+
const { changed: viewportSizeChanged, previous: previousViewportSize, current: viewportSize } = TrackedValue_1.TrackedValue.filter(trackedViewportSize)
|
|
28
|
+
? trackedViewportSize
|
|
29
|
+
: { changed: false, previous: trackedViewportSize, current: trackedViewportSize };
|
|
23
30
|
const { width: contentWidth, height: contentHeight } = contentSize;
|
|
24
31
|
const { side: anchorSide, anchor: anchorPlacement } = getComponents(placement);
|
|
32
|
+
// reset frame if there's no previous value OR if the viewport size changed
|
|
25
33
|
const popupFrame = {};
|
|
26
|
-
if (
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (viewportSizeChanged || !previousFrame) {
|
|
35
|
+
// horizontal layout if left/right
|
|
36
|
+
if (anchorSide === 'left' || anchorSide === 'right') {
|
|
37
|
+
// determine space to left/right
|
|
38
|
+
const spaceLeft = Math.max(0, anchorRect.left - containerRect.left - anchorOffset - containerInsets.left);
|
|
39
|
+
const spaceRight = Math.max(0, containerRect.right - anchorRect.right - anchorOffset - containerInsets.right);
|
|
40
|
+
// place left if it fits or if it fits better than on the right
|
|
41
|
+
if ((anchorSide === 'left' && (spaceLeft >= contentWidth || spaceLeft > spaceRight))
|
|
42
|
+
|| (anchorSide === 'right' && spaceRight < contentWidth && spaceRight < spaceLeft)) {
|
|
43
|
+
// force over anchor if there's no room
|
|
44
|
+
if (spaceLeft < contentWidth) {
|
|
45
|
+
popupFrame.left = containerRect.left + containerInsets.left;
|
|
46
|
+
popupFrame.right = Math.min(popupFrame.left + contentWidth, containerRect.right - containerInsets.right);
|
|
47
|
+
}
|
|
48
|
+
// or squeeze left
|
|
49
|
+
else {
|
|
50
|
+
popupFrame.right = containerRect.right - anchorRect.left + anchorOffset;
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
|
-
// or
|
|
53
|
+
// or place right
|
|
39
54
|
else {
|
|
40
|
-
|
|
55
|
+
// force over anchor if there's no room
|
|
56
|
+
if (spaceRight < contentWidth) {
|
|
57
|
+
popupFrame.right = containerRect.right - containerInsets.right;
|
|
58
|
+
popupFrame.left = Math.max(popupFrame.right - contentWidth, containerRect.left + containerInsets.left);
|
|
59
|
+
}
|
|
60
|
+
// or squeeze right
|
|
61
|
+
else {
|
|
62
|
+
popupFrame.left = anchorRect.right + anchorOffset;
|
|
63
|
+
}
|
|
41
64
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// force over anchor if there's no room
|
|
46
|
-
if (spaceRight < contentWidth) {
|
|
47
|
-
popupFrame.right = containerRect.right - containerInsets.right;
|
|
48
|
-
popupFrame.left = Math.max(popupFrame.right - contentWidth, containerRect.left + containerInsets.left);
|
|
49
|
-
}
|
|
50
|
-
// or squeeze right
|
|
51
|
-
else {
|
|
52
|
-
popupFrame.left = anchorRect.right + anchorOffset;
|
|
65
|
+
// top-align on start
|
|
66
|
+
if (anchorPlacement === 'start') {
|
|
67
|
+
popupFrame.top = anchorRect.top + containerInsets.top;
|
|
53
68
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
popupFrame.top = anchorRect.top + containerInsets.top;
|
|
58
|
-
}
|
|
59
|
-
// bottom-align on end
|
|
60
|
-
else if (anchorPlacement === 'end') {
|
|
61
|
-
popupFrame.bottom = containerRect.bottom - containerInsets.bottom;
|
|
62
|
-
}
|
|
63
|
-
// match height
|
|
64
|
-
else if (anchorPlacement === 'match') {
|
|
65
|
-
popupFrame.top = anchorRect.top + containerInsets.top;
|
|
66
|
-
popupFrame.height = anchorRect.height;
|
|
67
|
-
}
|
|
68
|
-
// or center against anchor
|
|
69
|
-
else {
|
|
70
|
-
// set top bounds so it's centered
|
|
71
|
-
popupFrame.top = Math.max(anchorRect.top + (anchorRect.height - contentHeight) / 2, containerRect.top + containerInsets.top);
|
|
72
|
-
// offset if the bottom is bleeding over
|
|
73
|
-
if (popupFrame.top + contentHeight > containerRect.bottom + containerInsets.bottom) {
|
|
74
|
-
popupFrame.top -= popupFrame.top + contentHeight - containerRect.bottom - containerInsets.bottom;
|
|
69
|
+
// bottom-align on end
|
|
70
|
+
else if (anchorPlacement === 'end') {
|
|
71
|
+
popupFrame.bottom = containerRect.bottom - containerInsets.bottom;
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// determine space to top/bottom
|
|
81
|
-
const spaceTop = Math.max(0, anchorRect.top - containerRect.top - anchorOffset - containerInsets.top);
|
|
82
|
-
const spaceBottom = Math.max(0, containerRect.bottom - anchorRect.bottom - anchorOffset - containerInsets.bottom);
|
|
83
|
-
// place above if it fits or if it fits better than on the right
|
|
84
|
-
if ((anchorSide === 'top' && (spaceTop >= contentHeight || spaceBottom < spaceTop))
|
|
85
|
-
|| (anchorSide === 'bottom' && spaceBottom < contentHeight && spaceBottom < spaceTop)) {
|
|
86
|
-
// force over anchor if there's no room
|
|
87
|
-
if (spaceTop < contentHeight) {
|
|
88
|
-
popupFrame.top = containerRect.top + containerInsets.top;
|
|
89
|
-
popupFrame.bottom = Math.min(popupFrame.top + contentHeight, containerRect.bottom - containerInsets.bottom);
|
|
73
|
+
// match height
|
|
74
|
+
else if (anchorPlacement === 'match') {
|
|
75
|
+
popupFrame.top = anchorRect.top + containerInsets.top;
|
|
76
|
+
popupFrame.height = anchorRect.height;
|
|
90
77
|
}
|
|
91
|
-
// or
|
|
78
|
+
// or center against anchor
|
|
92
79
|
else {
|
|
93
|
-
|
|
80
|
+
// set top bounds so it's centered
|
|
81
|
+
popupFrame.top = Math.max(anchorRect.top + (anchorRect.height - contentHeight) / 2, containerRect.top + containerInsets.top);
|
|
82
|
+
// offset if the bottom is bleeding over
|
|
83
|
+
if (popupFrame.top + contentHeight > containerRect.bottom + containerInsets.bottom) {
|
|
84
|
+
popupFrame.top -= popupFrame.top + contentHeight - containerRect.bottom - containerInsets.bottom;
|
|
85
|
+
}
|
|
94
86
|
}
|
|
95
87
|
}
|
|
96
|
-
// or
|
|
88
|
+
// or standard vertical layout
|
|
97
89
|
else {
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
// determine space to top/bottom
|
|
91
|
+
const spaceTop = Math.max(0, anchorRect.top - containerRect.top - anchorOffset - containerInsets.top);
|
|
92
|
+
const spaceBottom = Math.max(0, containerRect.bottom - anchorRect.bottom - anchorOffset - containerInsets.bottom);
|
|
93
|
+
// place above if it fits or if it fits better than on the right
|
|
94
|
+
if ((anchorSide === 'top' && (spaceTop >= contentHeight || spaceBottom < spaceTop))
|
|
95
|
+
|| (anchorSide === 'bottom' && spaceBottom < contentHeight && spaceBottom < spaceTop)) {
|
|
96
|
+
// force over anchor if there's no room
|
|
97
|
+
if (spaceTop < contentHeight) {
|
|
98
|
+
popupFrame.top = containerRect.top + containerInsets.top;
|
|
99
|
+
popupFrame.bottom = Math.min(popupFrame.top + contentHeight, containerRect.bottom - containerInsets.bottom);
|
|
100
|
+
}
|
|
101
|
+
// or squeeze above
|
|
102
|
+
else {
|
|
103
|
+
popupFrame.bottom = containerRect.bottom - anchorRect.top + anchorOffset;
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
|
-
// or
|
|
106
|
+
// or place below
|
|
104
107
|
else {
|
|
105
|
-
|
|
108
|
+
// force over anchor if there's no room
|
|
109
|
+
if (spaceBottom < contentHeight) {
|
|
110
|
+
popupFrame.bottom = containerRect.bottom - containerInsets.bottom;
|
|
111
|
+
popupFrame.top = Math.max(popupFrame.bottom - contentHeight, containerRect.top + containerInsets.top);
|
|
112
|
+
}
|
|
113
|
+
// or squeeze right
|
|
114
|
+
else {
|
|
115
|
+
popupFrame.top = anchorRect.bottom + anchorOffset;
|
|
116
|
+
}
|
|
106
117
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
// left-align on start
|
|
119
|
+
if (anchorPlacement === 'start') {
|
|
120
|
+
popupFrame.left = anchorRect.left;
|
|
121
|
+
}
|
|
122
|
+
// right-align on end
|
|
123
|
+
else if (anchorPlacement === 'end') {
|
|
124
|
+
popupFrame.right = containerRect.right - anchorRect.right;
|
|
125
|
+
}
|
|
126
|
+
// match width
|
|
127
|
+
else if (anchorPlacement === 'match') {
|
|
128
|
+
popupFrame.left = anchorRect.left;
|
|
129
|
+
popupFrame.width = anchorRect.width;
|
|
130
|
+
}
|
|
131
|
+
// or center against anchor
|
|
132
|
+
else {
|
|
133
|
+
// set left bounds so it's centered
|
|
134
|
+
popupFrame.left = Math.max(anchorRect.left + (anchorRect.width - contentWidth) / 2, containerRect.left);
|
|
135
|
+
// offset if the right is bleeding over
|
|
136
|
+
if (popupFrame.left + contentWidth > containerRect.right) {
|
|
137
|
+
popupFrame.left -= popupFrame.left + contentWidth - containerRect.right;
|
|
138
|
+
}
|
|
128
139
|
}
|
|
129
140
|
}
|
|
130
141
|
}
|
|
142
|
+
// or
|
|
131
143
|
// return position insets
|
|
132
144
|
return popupFrame;
|
|
133
145
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "git+https://github.com/nascentdigital/funnel.git",
|
|
6
6
|
"directory": "libs/core"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"jest-tsd": "^0.2.2",
|
|
66
66
|
"ts-jest": "^29.3.2"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "4a1d18f6f87148196b5e820c0ada8f2a8111b9f6"
|
|
69
69
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LinkedData } from './LinkedData';
|
|
2
|
-
import { Page } from './Page';
|
|
3
|
-
/**
|
|
4
|
-
* Page model with refs resolved to values
|
|
5
|
-
*/
|
|
6
|
-
export declare class LinkedPageModel<TPage extends Page> {
|
|
7
|
-
readonly data: Page.LinkedData<TPage>;
|
|
8
|
-
constructor(data: Page.LinkedData<TPage>);
|
|
9
|
-
get seo(): import("./Seo").Seo.LinkedData;
|
|
10
|
-
static fromPageData<TPage extends Page>(unlinkedData: Page.Data<TPage> | Page.Data.AsPreview<TPage>, resolvers: LinkedData.DynamicResolvers): Promise<LinkedPageModel<TPage>>;
|
|
11
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkedPageModel = void 0;
|
|
4
|
-
const LinkedData_1 = require("./LinkedData");
|
|
5
|
-
/**
|
|
6
|
-
* Page model with refs resolved to values
|
|
7
|
-
*/
|
|
8
|
-
class LinkedPageModel {
|
|
9
|
-
constructor(data) {
|
|
10
|
-
this.data = data;
|
|
11
|
-
}
|
|
12
|
-
get seo() {
|
|
13
|
-
var _a;
|
|
14
|
-
return (_a = this.data.discover) === null || _a === void 0 ? void 0 : _a.seo;
|
|
15
|
-
}
|
|
16
|
-
static async fromPageData(unlinkedData, resolvers) {
|
|
17
|
-
// transform
|
|
18
|
-
const linkedData = await LinkedData_1.LinkedData.resolve({
|
|
19
|
-
unlinkedData,
|
|
20
|
-
resolvers
|
|
21
|
-
});
|
|
22
|
-
// return linked page model
|
|
23
|
-
return new LinkedPageModel(linkedData);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.LinkedPageModel = LinkedPageModel;
|