@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.
@@ -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
- // horizontal layout if left/right
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 (anchorSide === 'left' || anchorSide === 'right') {
27
- // determine space to left/right
28
- const spaceLeft = Math.max(0, anchorRect.left - containerRect.left - anchorOffset - containerInsets.left);
29
- const spaceRight = Math.max(0, containerRect.right - anchorRect.right - anchorOffset - containerInsets.right);
30
- // place left if it fits or if it fits better than on the right
31
- if ((anchorSide === 'left' && (spaceLeft >= contentWidth || spaceLeft > spaceRight))
32
- || (anchorSide === 'right' && spaceRight < contentWidth && spaceRight < spaceLeft)) {
33
- // force over anchor if there's no room
34
- if (spaceLeft < contentWidth) {
35
- popupFrame.left = containerRect.left + containerInsets.left;
36
- popupFrame.right = Math.min(popupFrame.left + contentWidth, containerRect.right - containerInsets.right);
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 squeeze left
53
+ // or place right
39
54
  else {
40
- popupFrame.right = containerRect.right - anchorRect.left + anchorOffset;
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
- // or place right
44
- else {
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
- // top-align on start
56
- if (anchorPlacement === 'start') {
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
- // or standard vertical layout
79
- else {
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 squeeze above
78
+ // or center against anchor
92
79
  else {
93
- popupFrame.bottom = containerRect.bottom - anchorRect.top + anchorOffset;
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 place below
88
+ // or standard vertical layout
97
89
  else {
98
- // force over anchor if there's no room
99
- if (spaceBottom < contentHeight) {
100
- popupFrame.bottom = containerRect.bottom - containerInsets.bottom;
101
- popupFrame.top = Math.max(popupFrame.bottom - contentHeight, containerRect.top + containerInsets.top);
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 squeeze right
106
+ // or place below
104
107
  else {
105
- popupFrame.top = anchorRect.bottom + anchorOffset;
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
- // left-align on start
109
- if (anchorPlacement === 'start') {
110
- popupFrame.left = anchorRect.left;
111
- }
112
- // right-align on end
113
- else if (anchorPlacement === 'end') {
114
- popupFrame.right = containerRect.right - anchorRect.right;
115
- }
116
- // match width
117
- else if (anchorPlacement === 'match') {
118
- popupFrame.left = anchorRect.left;
119
- popupFrame.width = anchorRect.width;
120
- }
121
- // or center against anchor
122
- else {
123
- // set left bounds so it's centered
124
- popupFrame.left = Math.max(anchorRect.left + (anchorRect.width - contentWidth) / 2, containerRect.left);
125
- // offset if the right is bleeding over
126
- if (popupFrame.left + contentWidth > containerRect.right) {
127
- popupFrame.left -= popupFrame.left + contentWidth - containerRect.right;
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
  }
@@ -30,7 +30,6 @@ var ObjectUtils;
30
30
  }
31
31
  ObjectUtils.createSeries = createSeries;
32
32
  function splitProps(mixedProps, keys) {
33
- console.debug('[splitProps] splitting', { mixedProps, keys });
34
33
  // split props
35
34
  const splitProps = {};
36
35
  const props = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-core",
3
- "version": "4.5.7",
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": "aa14b53e99044a968b850c4f426e40d312a9306a"
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;