@cntrl-site/sdk-nextjs 1.0.20 → 1.1.0
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/jest.config.js +2 -2
- package/lib/components/Article.js +9 -8
- package/lib/components/Head.js +1 -1
- package/lib/components/Item.js +39 -21
- package/lib/components/items/CodeEmbedItem.js +15 -12
- package/lib/components/items/CustomItem.js +7 -9
- package/lib/components/items/GroupItem.js +15 -12
- package/lib/components/items/ImageItem.js +28 -21
- package/lib/components/items/RectangleItem.js +28 -15
- package/lib/components/items/RichTextItem.js +33 -12
- package/lib/components/items/VideoItem.js +26 -19
- package/lib/components/items/VimeoEmbed.js +22 -20
- package/lib/components/items/YoutubeEmbed.js +20 -18
- package/lib/components/useItemPosition.js +10 -5
- package/lib/interactions/CSSPropertyNameMap.js +38 -0
- package/lib/interactions/InteractionsRegistry.js +220 -0
- package/lib/interactions/ItemInteractionCtrl.js +61 -0
- package/lib/interactions/getTransition.js +21 -0
- package/lib/interactions/types.js +2 -0
- package/lib/interactions/useItemInteractionCtrl.js +17 -0
- package/lib/provider/InteractionsContext.js +23 -0
- package/lib/utils/getStyleFromItemStateAndParams.js +9 -0
- package/package.json +7 -4
- package/src/components/Article.tsx +30 -27
- package/src/components/ArticleWrapper.tsx +1 -2
- package/src/components/Head.tsx +7 -11
- package/src/components/Item.tsx +75 -29
- package/src/components/items/CodeEmbedItem.tsx +15 -11
- package/src/components/items/CustomItem.tsx +9 -11
- package/src/components/items/GroupItem.tsx +17 -13
- package/src/components/items/ImageItem.tsx +35 -20
- package/src/components/items/RectangleItem.tsx +35 -14
- package/src/components/items/RichTextItem.tsx +41 -14
- package/src/components/items/VideoItem.tsx +34 -20
- package/src/components/items/VimeoEmbed.tsx +27 -19
- package/src/components/items/YoutubeEmbed.tsx +20 -18
- package/src/components/useItemPosition.ts +12 -5
- package/src/interactions/CSSPropertyNameMap.ts +38 -0
- package/src/interactions/InteractionsRegistry.ts +244 -0
- package/src/interactions/ItemInteractionCtrl.ts +62 -0
- package/src/interactions/getTransition.ts +27 -0
- package/src/interactions/types.ts +32 -0
- package/src/interactions/useItemInteractionCtrl.ts +18 -0
- package/src/provider/InteractionsContext.old.tsx +65 -0
- package/src/provider/InteractionsContext.test.tsx +97 -0
- package/src/provider/InteractionsContext.tsx +28 -0
- package/src/utils/getStyleFromItemStateAndParams.ts +8 -0
- package/lib/utils/HoverStyles/HoverStyles.js +0 -77
- package/src/utils/HoverStyles/HoverStyles.ts +0 -85
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.InteractionsRegistry = void 0;
|
|
15
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
16
|
+
const Item_1 = require("../components/Item");
|
|
17
|
+
class InteractionsRegistry {
|
|
18
|
+
constructor(article, layoutId) {
|
|
19
|
+
this.layoutId = layoutId;
|
|
20
|
+
this.ctrls = new Map();
|
|
21
|
+
const { interactions } = article;
|
|
22
|
+
this.items = this.unpackItems(article);
|
|
23
|
+
const activeStatesIds = interactions.reduce((map, inter) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const activeStateId = (_a = inter.states.find((state) => state.id !== inter.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
26
|
+
map.push(activeStateId);
|
|
27
|
+
return map;
|
|
28
|
+
}, []);
|
|
29
|
+
const interactionStateMap = interactions.reduce((map, { id, startStateId }) => {
|
|
30
|
+
map[id] = startStateId;
|
|
31
|
+
return map;
|
|
32
|
+
}, {});
|
|
33
|
+
this.activeStateIdInteractionIdMap = interactions.reduce((map, interaction) => {
|
|
34
|
+
const activeState = interaction.states.find((state) => state.id !== interaction.startStateId);
|
|
35
|
+
if (activeState) {
|
|
36
|
+
map[activeState.id] = interaction.id;
|
|
37
|
+
}
|
|
38
|
+
return map;
|
|
39
|
+
}, {});
|
|
40
|
+
const itemStages = this.getDefaultItemStages();
|
|
41
|
+
const stateItemsIdsMap = activeStatesIds.reduce((map, stateId) => {
|
|
42
|
+
map[stateId] = this.items
|
|
43
|
+
.filter((item) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const layoutStates = (_a = item.state[layoutId]) !== null && _a !== void 0 ? _a : {};
|
|
46
|
+
const state = (_b = layoutStates === null || layoutStates === void 0 ? void 0 : layoutStates[stateId]) !== null && _b !== void 0 ? _b : {};
|
|
47
|
+
const hasKeys = Object.keys(state).length !== 0;
|
|
48
|
+
return hasKeys;
|
|
49
|
+
})
|
|
50
|
+
.map((item) => item.id);
|
|
51
|
+
return map;
|
|
52
|
+
}, {});
|
|
53
|
+
this.interactions = interactions;
|
|
54
|
+
this.itemsStages = itemStages;
|
|
55
|
+
this.stateItemsIdsMap = stateItemsIdsMap;
|
|
56
|
+
this.interactionStateMap = interactionStateMap;
|
|
57
|
+
}
|
|
58
|
+
register(itemId, ctrl) {
|
|
59
|
+
this.ctrls.set(itemId, ctrl);
|
|
60
|
+
}
|
|
61
|
+
getStatePropsForItem(itemId) {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
const { items, layoutId } = this;
|
|
64
|
+
const item = items.find((item) => item.id === itemId);
|
|
65
|
+
const itemStages = this.itemsStages.filter((stage) => stage.itemId === itemId);
|
|
66
|
+
itemStages.sort((a, b) => a.updated - b.updated);
|
|
67
|
+
const itemStyles = {};
|
|
68
|
+
for (const stage of itemStages) {
|
|
69
|
+
if (stage.type === 'active') {
|
|
70
|
+
if (stage.isStartState)
|
|
71
|
+
continue;
|
|
72
|
+
const params = (_b = (_a = item.state[layoutId]) === null || _a === void 0 ? void 0 : _a[stage.stateId]) !== null && _b !== void 0 ? _b : {};
|
|
73
|
+
for (const [key, stateDetails] of Object.entries(params)) {
|
|
74
|
+
itemStyles[key] = {
|
|
75
|
+
value: stateDetails.value
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (stage.type === 'transitioning') {
|
|
80
|
+
const activeStateId = stage.direction === 'in' ? stage.to : stage.from;
|
|
81
|
+
const params = (_d = (_c = item.state[layoutId]) === null || _c === void 0 ? void 0 : _c[activeStateId]) !== null && _d !== void 0 ? _d : {};
|
|
82
|
+
for (const [key, stateDetails] of Object.entries(params)) {
|
|
83
|
+
itemStyles[key] = {
|
|
84
|
+
value: stage.direction === 'in' ? stateDetails.value : (_e = itemStyles[key]) === null || _e === void 0 ? void 0 : _e.value,
|
|
85
|
+
transition: {
|
|
86
|
+
timing: stateDetails[stage.direction].timing,
|
|
87
|
+
duration: stateDetails[stage.direction].duration,
|
|
88
|
+
delay: stateDetails[stage.direction].delay
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return itemStyles;
|
|
95
|
+
}
|
|
96
|
+
notifyTrigger(itemId, triggerType) {
|
|
97
|
+
var _a;
|
|
98
|
+
const timestamp = Date.now();
|
|
99
|
+
for (const interaction of this.interactions) {
|
|
100
|
+
const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
|
|
101
|
+
const matchingTrigger = interaction.triggers.find((trigger) => trigger.itemId === itemId
|
|
102
|
+
&& trigger.from === currentStateId
|
|
103
|
+
&& trigger.type === triggerType);
|
|
104
|
+
if (!matchingTrigger)
|
|
105
|
+
continue;
|
|
106
|
+
const activeStateId = this.getActiveInteractionState(interaction.id);
|
|
107
|
+
const isNewStateActive = matchingTrigger.to === activeStateId;
|
|
108
|
+
this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
|
|
109
|
+
const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
|
|
110
|
+
this.itemsStages = this.itemsStages.map((stage) => {
|
|
111
|
+
if (stage.interactionId !== interaction.id)
|
|
112
|
+
return stage;
|
|
113
|
+
return {
|
|
114
|
+
itemId: stage.itemId,
|
|
115
|
+
interactionId: stage.interactionId,
|
|
116
|
+
type: 'transitioning',
|
|
117
|
+
from: stage.type === 'transitioning' ? stage.to : stage.stateId,
|
|
118
|
+
to: matchingTrigger.to,
|
|
119
|
+
direction: isNewStateActive ? 'in' : 'out',
|
|
120
|
+
updated: timestamp
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
this.notifyItemCtrlsChange(transitioningItems);
|
|
124
|
+
this.notifyTransitionStartForItems(transitioningItems, activeStateId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
notifyTransitionStartForItems(itemsIds, activeStateId) {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
for (const itemId of itemsIds) {
|
|
130
|
+
const ctrl = this.ctrls.get(itemId);
|
|
131
|
+
const item = this.items.find((item) => item.id === itemId);
|
|
132
|
+
const keys = Object.keys((_b = (_a = item.state[this.layoutId]) === null || _a === void 0 ? void 0 : _a[activeStateId]) !== null && _b !== void 0 ? _b : {});
|
|
133
|
+
(_c = ctrl === null || ctrl === void 0 ? void 0 : ctrl.handleTransitionStart) === null || _c === void 0 ? void 0 : _c.call(ctrl, keys);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
notifyTransitionEnd(itemId) {
|
|
137
|
+
var _a;
|
|
138
|
+
const timestamp = Date.now();
|
|
139
|
+
this.itemsStages = this.itemsStages.map((stage) => {
|
|
140
|
+
if (stage.itemId !== itemId || stage.type !== 'transitioning')
|
|
141
|
+
return stage;
|
|
142
|
+
return {
|
|
143
|
+
itemId: itemId,
|
|
144
|
+
interactionId: stage.interactionId,
|
|
145
|
+
type: 'active',
|
|
146
|
+
stateId: stage.to,
|
|
147
|
+
isStartState: stage.direction === 'out',
|
|
148
|
+
updated: timestamp
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
152
|
+
}
|
|
153
|
+
getCurrentStateByInteractionId(id) {
|
|
154
|
+
let state;
|
|
155
|
+
for (const interactionId of Object.keys(this.interactionStateMap)) {
|
|
156
|
+
if (id !== interactionId)
|
|
157
|
+
continue;
|
|
158
|
+
state = this.interactionStateMap[interactionId];
|
|
159
|
+
}
|
|
160
|
+
if (!state)
|
|
161
|
+
throw new Error(`Failed to find current state for interaction w/ id="${id}"`);
|
|
162
|
+
return state;
|
|
163
|
+
}
|
|
164
|
+
setCurrentStateForInteraction(interactionId, stateId) {
|
|
165
|
+
this.interactionStateMap = Object.assign(Object.assign({}, this.interactionStateMap), { [interactionId]: stateId });
|
|
166
|
+
}
|
|
167
|
+
getActiveInteractionState(interactionId) {
|
|
168
|
+
var _a;
|
|
169
|
+
const { interactions } = this;
|
|
170
|
+
const interaction = interactions.find((interaction) => interaction.id === interactionId);
|
|
171
|
+
return (_a = interaction.states.find(state => state.id !== interaction.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
172
|
+
}
|
|
173
|
+
notifyItemCtrlsChange(itemsIds) {
|
|
174
|
+
var _a;
|
|
175
|
+
for (const itemId of itemsIds) {
|
|
176
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
unpackItems(article) {
|
|
180
|
+
var _a;
|
|
181
|
+
const itemsArr = [];
|
|
182
|
+
for (const section of article.sections) {
|
|
183
|
+
for (const item of section.items) {
|
|
184
|
+
const { items } = item, itemWithoutChildren = __rest(item, ["items"]);
|
|
185
|
+
itemsArr.push(itemWithoutChildren);
|
|
186
|
+
if (!(0, Item_1.isItemType)(item, sdk_1.ArticleItemType.Group))
|
|
187
|
+
continue;
|
|
188
|
+
const groupChildren = (_a = item === null || item === void 0 ? void 0 : item.items) !== null && _a !== void 0 ? _a : [];
|
|
189
|
+
for (const child of groupChildren) {
|
|
190
|
+
itemsArr.push(child);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return itemsArr;
|
|
195
|
+
}
|
|
196
|
+
getDefaultItemStages() {
|
|
197
|
+
const timestamp = Date.now();
|
|
198
|
+
const { items, layoutId } = this;
|
|
199
|
+
const stages = [];
|
|
200
|
+
for (const item of items) {
|
|
201
|
+
const itemStatesMap = item.state[layoutId];
|
|
202
|
+
if (!itemStatesMap)
|
|
203
|
+
continue;
|
|
204
|
+
for (const stateId of Object.keys(itemStatesMap)) {
|
|
205
|
+
const interactionId = this.activeStateIdInteractionIdMap[stateId];
|
|
206
|
+
if (!interactionId)
|
|
207
|
+
continue;
|
|
208
|
+
stages.push({
|
|
209
|
+
itemId: item.id,
|
|
210
|
+
interactionId,
|
|
211
|
+
type: 'active',
|
|
212
|
+
isStartState: true,
|
|
213
|
+
updated: timestamp
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return stages;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.InteractionsRegistry = InteractionsRegistry;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ItemInteractionController = void 0;
|
|
4
|
+
const getTransition_1 = require("./getTransition");
|
|
5
|
+
const CSSPropertyNameMap_1 = require("./CSSPropertyNameMap");
|
|
6
|
+
class ItemInteractionController {
|
|
7
|
+
constructor(itemId, registry, onChange) {
|
|
8
|
+
this.itemId = itemId;
|
|
9
|
+
this.registry = registry;
|
|
10
|
+
this.onChange = onChange;
|
|
11
|
+
this.transitionsInProgress = new Set();
|
|
12
|
+
this.handleTransitionStart = (types) => {
|
|
13
|
+
this.transitionsInProgress.clear();
|
|
14
|
+
for (const type of types) {
|
|
15
|
+
this.transitionsInProgress.add(type);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
this.handleTransitionEnd = (cssPropKey) => {
|
|
19
|
+
if (cssPropKey.startsWith('border-') && cssPropKey.endsWith('-radius')) {
|
|
20
|
+
cssPropKey = 'border-radius';
|
|
21
|
+
}
|
|
22
|
+
if (cssPropKey.startsWith('border-') && cssPropKey.endsWith('-width')) {
|
|
23
|
+
cssPropKey = 'border-width';
|
|
24
|
+
}
|
|
25
|
+
const styleKeys = (0, CSSPropertyNameMap_1.getStyleKeysFromCSSProperty)(cssPropKey);
|
|
26
|
+
for (const key of styleKeys) {
|
|
27
|
+
const found = this.transitionsInProgress.has(key);
|
|
28
|
+
if (!found)
|
|
29
|
+
continue;
|
|
30
|
+
this.transitionsInProgress.delete(key);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (this.transitionsInProgress.size !== 0)
|
|
34
|
+
return;
|
|
35
|
+
this.registry.notifyTransitionEnd(this.itemId);
|
|
36
|
+
};
|
|
37
|
+
this.registry.register(itemId, this);
|
|
38
|
+
}
|
|
39
|
+
getState(keys) {
|
|
40
|
+
const stateProps = this.registry.getStatePropsForItem(this.itemId);
|
|
41
|
+
const styles = keys.reduce((map, styleKey) => {
|
|
42
|
+
const prop = stateProps[styleKey];
|
|
43
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.value) === undefined)
|
|
44
|
+
return map;
|
|
45
|
+
map[styleKey] = prop.value;
|
|
46
|
+
return map;
|
|
47
|
+
}, {});
|
|
48
|
+
const transition = (0, getTransition_1.getTransition)(stateProps, keys);
|
|
49
|
+
return {
|
|
50
|
+
styles,
|
|
51
|
+
transition
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
sendTrigger(type) {
|
|
55
|
+
this.registry.notifyTrigger(this.itemId, type);
|
|
56
|
+
}
|
|
57
|
+
receiveChange() {
|
|
58
|
+
this.onChange();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ItemInteractionController = ItemInteractionController;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTransition = void 0;
|
|
4
|
+
const CSSPropertyNameMap_1 = require("./CSSPropertyNameMap");
|
|
5
|
+
function getTransition(state, keys) {
|
|
6
|
+
if (Object.keys(state).length === 0)
|
|
7
|
+
return 'none';
|
|
8
|
+
const transitions = [];
|
|
9
|
+
for (const [key, params] of Object.entries(state)) {
|
|
10
|
+
if (!keys.includes(key) || !params.transition)
|
|
11
|
+
continue;
|
|
12
|
+
const { transition: { duration, delay, timing } } = params;
|
|
13
|
+
const cssKey = CSSPropertyNameMap_1.CSSPropertyNameMap[key];
|
|
14
|
+
const nonZeroDuration = Math.max(duration, 0.01);
|
|
15
|
+
transitions.push(`${cssKey} ${nonZeroDuration}ms ${timing} ${delay}ms`);
|
|
16
|
+
}
|
|
17
|
+
return transitions.length > 0
|
|
18
|
+
? transitions.join(', ')
|
|
19
|
+
: 'none';
|
|
20
|
+
}
|
|
21
|
+
exports.getTransition = getTransition;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useItemInteractionCtrl = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ItemInteractionCtrl_1 = require("./ItemInteractionCtrl");
|
|
6
|
+
const InteractionsContext_1 = require("../provider/InteractionsContext");
|
|
7
|
+
function useItemInteractionCtrl(itemId) {
|
|
8
|
+
const [_, triggerRender] = (0, react_1.useState)(0);
|
|
9
|
+
const registry = (0, InteractionsContext_1.useInteractionsRegistry)();
|
|
10
|
+
const ctrl = (0, react_1.useMemo)(() => {
|
|
11
|
+
if (!registry)
|
|
12
|
+
return;
|
|
13
|
+
return new ItemInteractionCtrl_1.ItemInteractionController(itemId, registry, () => triggerRender(prev => prev + 1));
|
|
14
|
+
}, [itemId, registry]);
|
|
15
|
+
return ctrl;
|
|
16
|
+
}
|
|
17
|
+
exports.useItemInteractionCtrl = useItemInteractionCtrl;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInteractionsRegistry = exports.InteractionsProvider = exports.InteractionsContext = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const InteractionsRegistry_1 = require("../interactions/InteractionsRegistry");
|
|
7
|
+
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
8
|
+
exports.InteractionsContext = (0, react_1.createContext)(undefined);
|
|
9
|
+
const InteractionsProvider = ({ article, children }) => {
|
|
10
|
+
const { layoutId } = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
11
|
+
const registry = (0, react_1.useMemo)(() => {
|
|
12
|
+
if (!layoutId)
|
|
13
|
+
return;
|
|
14
|
+
return new InteractionsRegistry_1.InteractionsRegistry(article, layoutId);
|
|
15
|
+
}, [layoutId]);
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(exports.InteractionsContext.Provider, { value: registry, children: children }));
|
|
17
|
+
};
|
|
18
|
+
exports.InteractionsProvider = InteractionsProvider;
|
|
19
|
+
function useInteractionsRegistry() {
|
|
20
|
+
const registry = (0, react_1.useContext)(exports.InteractionsContext);
|
|
21
|
+
return registry;
|
|
22
|
+
}
|
|
23
|
+
exports.useInteractionsRegistry = useInteractionsRegistry;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyleFromItemStateAndParams = void 0;
|
|
4
|
+
function getStyleFromItemStateAndParams(stateValue, paramsValue) {
|
|
5
|
+
return stateValue !== undefined
|
|
6
|
+
? stateValue
|
|
7
|
+
: paramsValue;
|
|
8
|
+
}
|
|
9
|
+
exports.getStyleFromItemStateAndParams = getStyleFromItemStateAndParams;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cntrl-site/color": "^1.0.0",
|
|
25
25
|
"@cntrl-site/effects": "^1.2.0",
|
|
26
|
-
"@cntrl-site/sdk": "^1.12.
|
|
26
|
+
"@cntrl-site/sdk": "^1.12.4-alpha.8",
|
|
27
27
|
"@types/vimeo__player": "^2.18.0",
|
|
28
28
|
"@vimeo/player": "^2.20.1",
|
|
29
29
|
"html-react-parser": "^3.0.1",
|
|
@@ -38,12 +38,15 @@
|
|
|
38
38
|
"react-dom": "^18.3.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"@testing-library/jest-dom": "^6.4.8",
|
|
42
|
+
"@testing-library/react": "^16.0.0",
|
|
41
43
|
"@tsconfig/node16": "^1.0.3",
|
|
42
44
|
"@tsconfig/recommended": "^1.0.1",
|
|
43
|
-
"@types/jest": "^29.
|
|
45
|
+
"@types/jest": "^29.5.12",
|
|
44
46
|
"@types/node": "^18.11.7",
|
|
45
47
|
"@types/react": "^18.0.15",
|
|
46
|
-
"jest": "^29.
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
47
50
|
"ts-jest": "^29.0.3",
|
|
48
51
|
"typescript": "^5.2.2"
|
|
49
52
|
},
|
|
@@ -6,6 +6,7 @@ import { Item } from './Item';
|
|
|
6
6
|
import { useArticleRectObserver } from '../utils/ArticleRectManager/useArticleRectObserver';
|
|
7
7
|
import { ArticleRectContext } from '../provider/ArticleRectContext';
|
|
8
8
|
import { ArticleWrapper } from './ArticleWrapper';
|
|
9
|
+
import { InteractionsProvider } from '../provider/InteractionsContext';
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
11
12
|
article: TArticle;
|
|
@@ -27,35 +28,37 @@ export const Article: FC<Props> = ({ article, sectionData }) => {
|
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
30
|
<ArticleRectContext.Provider value={articleRectObserver}>
|
|
30
|
-
<
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
<InteractionsProvider article={article}>
|
|
32
|
+
<ArticleWrapper>
|
|
33
|
+
<div className="article" ref={articleRef}>
|
|
34
|
+
{article.sections.map((section, i) => {
|
|
35
|
+
const data = section.name ? sectionData[section.name] : {};
|
|
36
|
+
return (
|
|
37
|
+
<Section
|
|
38
|
+
section={section}
|
|
39
|
+
key={section.id}
|
|
40
|
+
data={data}
|
|
41
|
+
>
|
|
42
|
+
{article.sections[i].items.map(item => (
|
|
43
|
+
<Item
|
|
44
|
+
item={item}
|
|
45
|
+
key={item.id}
|
|
46
|
+
sectionId={section.id}
|
|
47
|
+
articleHeight={articleHeight}
|
|
48
|
+
/>
|
|
49
|
+
))}
|
|
50
|
+
</Section>
|
|
51
|
+
);
|
|
52
|
+
})}
|
|
53
|
+
</div>
|
|
54
|
+
</ArticleWrapper>
|
|
55
|
+
<JSXStyle id={id}>{`
|
|
54
56
|
.article {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
position: relative;
|
|
58
|
+
overflow: clip;
|
|
59
|
+
}
|
|
58
60
|
`}</JSXStyle>
|
|
61
|
+
</InteractionsProvider>
|
|
59
62
|
</ArticleRectContext.Provider>
|
|
60
63
|
);
|
|
61
64
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties, FC, PropsWithChildren
|
|
2
|
-
import JSXStyle from 'styled-jsx/style';
|
|
1
|
+
import React, { CSSProperties, FC, PropsWithChildren } from 'react';
|
|
3
2
|
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
4
3
|
import { LayoutContext } from '../provider/LayoutContext';
|
|
5
4
|
|
package/src/components/Head.tsx
CHANGED
|
@@ -30,17 +30,13 @@ export const CNTRLHead: FC<Props> = ({ meta, project }) => {
|
|
|
30
30
|
return (
|
|
31
31
|
<Head>
|
|
32
32
|
<title>{meta.title}</title>
|
|
33
|
-
<meta name="description" content={meta.description}/>
|
|
34
|
-
<meta name="
|
|
35
|
-
<meta name="
|
|
36
|
-
<meta name="
|
|
37
|
-
<meta name="og:
|
|
38
|
-
<meta name="
|
|
39
|
-
<
|
|
40
|
-
<meta name="twitter:description" content={meta.description}/>
|
|
41
|
-
<meta property="twitter:card" content="summary_large_image"/>
|
|
42
|
-
<meta name="generator" content="https://cntrl.site"/>
|
|
43
|
-
<link rel="icon" href={meta.favicon}/>
|
|
33
|
+
<meta name="description" content={meta.description} />
|
|
34
|
+
<meta name="og:description" content={meta.description} />
|
|
35
|
+
<meta name="twitter:description" content={meta.description} />
|
|
36
|
+
<meta name="keywords" content={meta.keywords} />
|
|
37
|
+
<meta name="og:image" content={meta.opengraphThumbnail} />
|
|
38
|
+
<meta name="generator" content="https://cntrl.site" />
|
|
39
|
+
<link rel="icon" href={meta.favicon} />
|
|
44
40
|
{customFonts.length > 0 && (
|
|
45
41
|
<style
|
|
46
42
|
dangerouslySetInnerHTML={{
|