@gxpl/sdk 0.0.20 → 0.0.21
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/lib/index.d.ts +0 -1
- package/lib/sdk/schemas/article/Article.schema.d.ts +6 -6
- package/lib/sdk/schemas/article/ItemBase.schema.d.ts +44 -4
- package/lib/sdk/schemas/article/ItemBase.schema.js +8 -1
- package/lib/sdk/schemas/article/RichTextItem.schema.d.ts +27 -2
- package/lib/sdk/schemas/article/Section.schema.d.ts +6 -6
- package/lib/sdk/schemas/project/Project.schema.d.ts +4 -1102
- package/lib/sdk/schemas/project/Project.schema.js +2 -27
- package/lib/sdk/types/article/Item.d.ts +0 -4
- package/lib/sdk/types/project/Project.d.ts +0 -3
- package/lib/sdk-nextjs/components/Page.js +2 -3
- package/lib/sdk-nextjs/components/items/CompoundItem/CompoundChild.d.ts +0 -1
- package/lib/sdk-nextjs/components/items/CompoundItem/CompoundChild.js +2 -2
- package/lib/sdk-nextjs/components/items/GroupItem/GroupItem.js +2 -2
- package/lib/sdk-nextjs/components/items/Item.d.ts +0 -2
- package/lib/sdk-nextjs/components/items/Item.js +3 -3
- package/lib/sdk-nextjs/interactions/useItemInteractionCtrl.d.ts +1 -1
- package/lib/sdk-nextjs/interactions/useItemInteractionCtrl.js +2 -5
- package/package.json +1 -1
- package/lib/sdk/types/project/FixedLayer.d.ts +0 -27
- package/lib/sdk/types/project/FixedLayer.js +0 -2
- package/lib/sdk-nextjs/components/fixedLayers/FixedLayer.d.ts +0 -8
- package/lib/sdk-nextjs/components/fixedLayers/FixedLayer.js +0 -34
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsProvider.d.ts +0 -10
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsProvider.js +0 -41
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsRegistry.d.ts +0 -38
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsRegistry.js +0 -164
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectSchema =
|
|
3
|
+
exports.ProjectSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const Fonts_1 = require("../../types/project/Fonts");
|
|
6
|
-
const Item_schema_1 = require("../article/Item.schema");
|
|
7
|
-
const Section_schema_1 = require("../article/Section.schema");
|
|
8
|
-
const Interaction_schema_1 = require("../article/Interaction.schema");
|
|
9
|
-
const FixedLayerTransitionSchema = zod_1.z.object({
|
|
10
|
-
from: zod_1.z.string(),
|
|
11
|
-
to: zod_1.z.string(),
|
|
12
|
-
itemsTransitions: zod_1.z.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.object({
|
|
13
|
-
timing: zod_1.z.string(),
|
|
14
|
-
duration: zod_1.z.number(),
|
|
15
|
-
delay: zod_1.z.number()
|
|
16
|
-
}))),
|
|
17
|
-
id: zod_1.z.string()
|
|
18
|
-
});
|
|
19
|
-
exports.FixedLayerSchema = zod_1.z.object({
|
|
20
|
-
id: zod_1.z.string().min(1),
|
|
21
|
-
items: zod_1.z.array(Item_schema_1.ItemSchema),
|
|
22
|
-
name: zod_1.z.string().optional(),
|
|
23
|
-
hidden: zod_1.z.boolean(),
|
|
24
|
-
color: zod_1.z.nullable(zod_1.z.string()),
|
|
25
|
-
media: Section_schema_1.SectionMediaSchema.optional(),
|
|
26
|
-
interactions: zod_1.z.array(Interaction_schema_1.InteractionSchema),
|
|
27
|
-
transitions: zod_1.z.array(FixedLayerTransitionSchema),
|
|
28
|
-
});
|
|
29
6
|
exports.ProjectSchema = zod_1.z.object({
|
|
30
7
|
id: zod_1.z.string().min(1),
|
|
31
8
|
html: zod_1.z.object({
|
|
@@ -63,7 +40,5 @@ exports.ProjectSchema = zod_1.z.object({
|
|
|
63
40
|
to: zod_1.z.string().min(1),
|
|
64
41
|
type: zod_1.z.enum(['slide', 'fade']),
|
|
65
42
|
direction: zod_1.z.enum(['north', 'east', 'south', 'west'])
|
|
66
|
-
}))
|
|
67
|
-
foreground: exports.FixedLayerSchema,
|
|
68
|
-
background: exports.FixedLayerSchema
|
|
43
|
+
}))
|
|
69
44
|
});
|
|
@@ -2,7 +2,6 @@ import { Relation } from './Relation';
|
|
|
2
2
|
import { Fonts } from './Fonts';
|
|
3
3
|
import { Meta } from './Meta';
|
|
4
4
|
import { Page } from './Page';
|
|
5
|
-
import { TFixedLayer } from './FixedLayer';
|
|
6
5
|
export interface AdditionalHTML {
|
|
7
6
|
head: string;
|
|
8
7
|
afterBodyOpen: string;
|
|
@@ -16,6 +15,4 @@ export interface Project {
|
|
|
16
15
|
pages: Page[];
|
|
17
16
|
fonts: Fonts;
|
|
18
17
|
relations: Relation[];
|
|
19
|
-
foreground: TFixedLayer;
|
|
20
|
-
background: TFixedLayer;
|
|
21
18
|
}
|
|
@@ -9,19 +9,18 @@ const html_react_parser_1 = __importDefault(require("html-react-parser"));
|
|
|
9
9
|
const Head_1 = require("./Head");
|
|
10
10
|
const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
|
|
11
11
|
const Scenes_1 = require("./Scenes/Scenes");
|
|
12
|
-
const FixedLayer_1 = require("./fixedLayers/FixedLayer");
|
|
13
12
|
const Page = ({ project, articlesData }) => {
|
|
14
13
|
const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
|
|
15
14
|
const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
|
|
16
15
|
const startScene = Object.keys(articlesData)[0];
|
|
17
16
|
const scenes = Object.values(articlesData).map(({ article }) => ({ id: article.id }));
|
|
18
17
|
const { relations } = project;
|
|
19
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project }), afterBodyOpen, (0, jsx_runtime_1.
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project }), afterBodyOpen, (0, jsx_runtime_1.jsx)(TransitionMachineContext_1.TransitionMachineContext.Provider, { options: {
|
|
20
19
|
input: {
|
|
21
20
|
startScene,
|
|
22
21
|
relations,
|
|
23
22
|
scenes,
|
|
24
23
|
}
|
|
25
|
-
}, children:
|
|
24
|
+
}, children: (0, jsx_runtime_1.jsx)(Scenes_1.Scenes, { articlesData: articlesData }) }), beforeBodyClose] }));
|
|
26
25
|
};
|
|
27
26
|
exports.Page = Page;
|
|
@@ -21,7 +21,7 @@ const useItemPointerEvents_1 = require("../useItemPointerEvents");
|
|
|
21
21
|
const useItemArea_1 = require("../useItemArea");
|
|
22
22
|
const ArticleItemType_1 = require("../../../../sdk/types/article/ArticleItemType");
|
|
23
23
|
const noop = () => null;
|
|
24
|
-
const CompoundChild = ({ item, sectionId, isParentVisible = true
|
|
24
|
+
const CompoundChild = ({ item, sectionId, isParentVisible = true }) => {
|
|
25
25
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
26
26
|
const id = (0, react_1.useId)();
|
|
27
27
|
const exemplary = (0, useExemplary_1.useExemplary)();
|
|
@@ -71,7 +71,7 @@ const CompoundChild = ({ item, sectionId, isParentVisible = true, isInFixedLayer
|
|
|
71
71
|
} }, triggers, { children: [(0, jsx_runtime_1.jsx)("div", { className: `item-${item.id}-inner`, style: {
|
|
72
72
|
transition: (_l = innerStateProps === null || innerStateProps === void 0 ? void 0 : innerStateProps.transition) !== null && _l !== void 0 ? _l : 'none',
|
|
73
73
|
transform: `scale(${scale})`,
|
|
74
|
-
}, children: (0, jsx_runtime_1.jsx)(RichTextWrapper_1.RichTextWrapper, { isRichText: isRichText, transformOrigin: transformOrigin, children: (0, jsx_runtime_1.jsx)(ItemComponent, {
|
|
74
|
+
}, children: (0, jsx_runtime_1.jsx)(RichTextWrapper_1.RichTextWrapper, { isRichText: isRichText, transformOrigin: transformOrigin, children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, interactionCtrl: interactionCtrl, onVisibilityChange: handleVisibilityChange, isInCompound: true }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
75
75
|
.item-${item.id}-inner {
|
|
76
76
|
width: 100%;
|
|
77
77
|
height: 100%;
|
|
@@ -14,7 +14,7 @@ const useItemAngle_1 = require("../useItemAngle");
|
|
|
14
14
|
const useGroupItem_1 = require("./useGroupItem");
|
|
15
15
|
const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromItemStateAndParams");
|
|
16
16
|
const CompoundChild_1 = require("../CompoundItem/CompoundChild");
|
|
17
|
-
const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange, isInCompound
|
|
17
|
+
const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange, isInCompound }) => {
|
|
18
18
|
var _a, _b, _c, _d;
|
|
19
19
|
const id = (0, react_1.useId)();
|
|
20
20
|
const { items } = item;
|
|
@@ -30,7 +30,7 @@ const GroupItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityCha
|
|
|
30
30
|
(0, react_1.useEffect)(() => {
|
|
31
31
|
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
32
32
|
}, [isInteractive, onVisibilityChange]);
|
|
33
|
-
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { link: item.link, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_d = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _d !== void 0 ? _d : 'none', willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset' }), children: items && items.map(item => isInCompound ? ((0, jsx_runtime_1.jsx)(CompoundChild_1.CompoundChild, {
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { link: item.link, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `group-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_d = stateParams === null || stateParams === void 0 ? void 0 : stateParams.transition) !== null && _d !== void 0 ? _d : 'none', willChange: blur !== 0 && blur !== undefined ? 'transform' : 'unset' }), children: items && items.map(item => isInCompound ? ((0, jsx_runtime_1.jsx)(CompoundChild_1.CompoundChild, { item: item, sectionId: sectionId, isParentVisible: isInteractive }, item.id)) : ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, isParentVisible: isInteractive, isInGroup: true }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
34
34
|
.group-${item.id} {
|
|
35
35
|
position: absolute;
|
|
36
36
|
width: 100%;
|
|
@@ -9,14 +9,12 @@ export interface ItemProps<I extends ItemAny> {
|
|
|
9
9
|
interactionCtrl?: ReturnType<typeof useItemInteractionCtrl>;
|
|
10
10
|
onVisibilityChange: (isVisible: boolean) => void;
|
|
11
11
|
isInCompound?: boolean;
|
|
12
|
-
isInFixedLayer?: boolean;
|
|
13
12
|
}
|
|
14
13
|
export interface ItemWrapperProps {
|
|
15
14
|
item: ItemAny;
|
|
16
15
|
sectionId: string;
|
|
17
16
|
articleHeight?: number;
|
|
18
17
|
isInGroup?: boolean;
|
|
19
|
-
isInFixedLayer?: boolean;
|
|
20
18
|
isParentVisible?: boolean;
|
|
21
19
|
}
|
|
22
20
|
export declare const Item: FC<ItemWrapperProps>;
|
|
@@ -31,7 +31,7 @@ const stickyFix = `
|
|
|
31
31
|
transform: translate3d(0, 0, 0);
|
|
32
32
|
`;
|
|
33
33
|
const noop = () => null;
|
|
34
|
-
const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGroup = false
|
|
34
|
+
const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGroup = false }) => {
|
|
35
35
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
36
36
|
const itemWrapperRef = (0, react_1.useRef)(null);
|
|
37
37
|
const itemInnerRef = (0, react_1.useRef)(null);
|
|
@@ -42,7 +42,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
42
42
|
const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
|
|
43
43
|
const [itemHeight, setItemHeight] = (0, react_1.useState)(undefined);
|
|
44
44
|
const itemScale = (0, useItemScale_1.useItemScale)(item, sectionId);
|
|
45
|
-
const interactionCtrl = (0, useItemInteractionCtrl_1.useItemInteractionCtrl)(item.id
|
|
45
|
+
const interactionCtrl = (0, useItemInteractionCtrl_1.useItemInteractionCtrl)(item.id);
|
|
46
46
|
const triggers = (0, useItemTriggers_1.useItemTriggers)(interactionCtrl);
|
|
47
47
|
const [position, setPosition] = (0, react_1.useState)({ x: 0, y: 0 });
|
|
48
48
|
const [isDraggingActive, setIsDraggingActive] = (0, react_1.useState)(false);
|
|
@@ -118,7 +118,7 @@ const Item = ({ item, sectionId, articleHeight, isParentVisible = true, isInGrou
|
|
|
118
118
|
? 'grab'
|
|
119
119
|
: hasClickTriggers
|
|
120
120
|
? 'pointer'
|
|
121
|
-
: 'unset', pointerEvents: allowPointerEvents ? 'auto' : 'none', userSelect: isDraggable ? 'none' : 'unset', WebkitUserSelect: isDraggable ? 'none' : 'unset', MozUserSelect: isDraggable ? 'none' : 'unset', msUserSelect: isDraggable ? 'none' : 'unset' }) }, triggers, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight,
|
|
121
|
+
: 'unset', pointerEvents: allowPointerEvents ? 'auto' : 'none', userSelect: isDraggable ? 'none' : 'unset', WebkitUserSelect: isDraggable ? 'none' : 'unset', MozUserSelect: isDraggable ? 'none' : 'unset', msUserSelect: isDraggable ? 'none' : 'unset' }) }, triggers, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight, interactionCtrl: interactionCtrl, onVisibilityChange: handleVisibilityChange }) })) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
122
122
|
.item-${item.id} {
|
|
123
123
|
position: ${item.sticky ? 'sticky' : 'absolute'};
|
|
124
124
|
top: ${item.sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(item.area.top - item.sticky.from, sectionHeight, item.area.anchorSide)}` : 0};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ItemInteractionCtrl } from './types';
|
|
2
|
-
export declare function useItemInteractionCtrl(itemId: string
|
|
2
|
+
export declare function useItemInteractionCtrl(itemId: string): ItemInteractionCtrl | undefined;
|
|
@@ -4,12 +4,9 @@ exports.useItemInteractionCtrl = useItemInteractionCtrl;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const ItemInteractionCtrl_1 = require("./ItemInteractionCtrl");
|
|
6
6
|
const InteractionsContext_1 = require("../provider/InteractionsContext");
|
|
7
|
-
|
|
8
|
-
function useItemInteractionCtrl(itemId, isInFixedLayer = false) {
|
|
7
|
+
function useItemInteractionCtrl(itemId) {
|
|
9
8
|
const [_, triggerRender] = (0, react_1.useState)(0);
|
|
10
|
-
const
|
|
11
|
-
const fixedLayerTransitionsRegistry = (0, FixedLayerTransitionsProvider_1.useFixedLayerTransitionsRegistry)();
|
|
12
|
-
const registry = isInFixedLayer ? fixedLayerTransitionsRegistry : interactionsRegistry;
|
|
9
|
+
const registry = (0, InteractionsContext_1.useInteractionsRegistry)();
|
|
13
10
|
const ctrl = (0, react_1.useMemo)(() => {
|
|
14
11
|
if (!registry)
|
|
15
12
|
return;
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Interaction } from '../article/Interaction';
|
|
2
|
-
import { ItemAny } from '../article/Item';
|
|
3
|
-
import { SectionMedia } from '../article/Section';
|
|
4
|
-
type ItemIdentifier = string;
|
|
5
|
-
type PropertyName = string;
|
|
6
|
-
export type TransitionTiming = {
|
|
7
|
-
timing: string;
|
|
8
|
-
duration: number;
|
|
9
|
-
delay: number;
|
|
10
|
-
};
|
|
11
|
-
export type FixedLayerTransition = {
|
|
12
|
-
from: string;
|
|
13
|
-
to: string;
|
|
14
|
-
itemsTransitions: Record<ItemIdentifier, Record<PropertyName, TransitionTiming>>;
|
|
15
|
-
id: string;
|
|
16
|
-
};
|
|
17
|
-
export interface TFixedLayer {
|
|
18
|
-
id: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
hidden: boolean;
|
|
21
|
-
items: ItemAny[];
|
|
22
|
-
color: string | null;
|
|
23
|
-
media?: SectionMedia;
|
|
24
|
-
transitions: FixedLayerTransition[];
|
|
25
|
-
interactions: Interaction[];
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FixedLayer = void 0;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
const ArticleRectContext_1 = require("../../provider/ArticleRectContext");
|
|
10
|
-
const useArticleRectObserver_1 = require("../../utils/ArticleRectManager/useArticleRectObserver");
|
|
11
|
-
const WebGLContextManagerContext_1 = require("../../provider/WebGLContextManagerContext");
|
|
12
|
-
const effects_1 = require("@cntrl-site/effects");
|
|
13
|
-
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
14
|
-
const Item_1 = require("../items/Item");
|
|
15
|
-
const FixedLayerTransitionsProvider_1 = require("../../fixedLayers/FixedLayerTransitionsProvider");
|
|
16
|
-
const FixedLayer = ({ layer, type }) => {
|
|
17
|
-
const fixedLayerRef = (0, react_1.useRef)(null);
|
|
18
|
-
const id = (0, react_1.useId)();
|
|
19
|
-
const articleRectObserver = (0, useArticleRectObserver_1.useArticleRectObserver)(fixedLayerRef.current);
|
|
20
|
-
const webglContextManager = (0, react_1.useMemo)(() => new effects_1.WebGLContextManager(), []);
|
|
21
|
-
return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsx)(FixedLayerTransitionsProvider_1.FixedLayerTransitionsProvider, { fixedLayer: layer, children: (0, jsx_runtime_1.jsxs)(WebGLContextManagerContext_1.WebglContextManagerContext.Provider, { value: webglContextManager, children: [(0, jsx_runtime_1.jsx)("div", { className: `fixed-layer-${type}`, ref: fixedLayerRef, children: layer.items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { isInFixedLayer: true, item: item, sectionId: layer.id }, item.id))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
22
|
-
.fixed-layer-${type} {
|
|
23
|
-
position: fixed;
|
|
24
|
-
top: 0;
|
|
25
|
-
pointer-events: none;
|
|
26
|
-
left: 0;
|
|
27
|
-
width: 100%;
|
|
28
|
-
height: 100%;
|
|
29
|
-
overflow: clip;
|
|
30
|
-
${type === 'foreground' ? 'z-index: 1;' : 'z-index: -1;'}
|
|
31
|
-
}
|
|
32
|
-
` })] }) }) }));
|
|
33
|
-
};
|
|
34
|
-
exports.FixedLayer = FixedLayer;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
import { TFixedLayer } from '../../sdk/types/project/FixedLayer';
|
|
3
|
-
import { FixedLayerTransitionsRegistry } from './FixedLayerTransitionsRegistry';
|
|
4
|
-
export declare const FixedLayerTransitionsContext: import("react").Context<FixedLayerTransitionsRegistry | undefined>;
|
|
5
|
-
interface Props {
|
|
6
|
-
fixedLayer: TFixedLayer;
|
|
7
|
-
}
|
|
8
|
-
export declare const FixedLayerTransitionsProvider: FC<PropsWithChildren<Props>>;
|
|
9
|
-
export declare function useFixedLayerTransitionsRegistry(): FixedLayerTransitionsRegistry | undefined;
|
|
10
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FixedLayerTransitionsProvider = exports.FixedLayerTransitionsContext = void 0;
|
|
4
|
-
exports.useFixedLayerTransitionsRegistry = useFixedLayerTransitionsRegistry;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
|
|
8
|
-
const FixedLayerTransitionsRegistry_1 = require("./FixedLayerTransitionsRegistry");
|
|
9
|
-
exports.FixedLayerTransitionsContext = (0, react_1.createContext)(undefined);
|
|
10
|
-
const FixedLayerTransitionsProvider = ({ fixedLayer, children }) => {
|
|
11
|
-
const actorRef = TransitionMachineContext_1.TransitionMachineContext.useActorRef();
|
|
12
|
-
const { isSettling, isActive, startScene } = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => ({
|
|
13
|
-
startScene: state.context.input.startScene,
|
|
14
|
-
isSettling: state.matches('settling'),
|
|
15
|
-
isActive: state.matches('active'),
|
|
16
|
-
}));
|
|
17
|
-
const transitionsRegistry = (0, react_1.useMemo)(() => new FixedLayerTransitionsRegistry_1.FixedLayerTransitionsRegistry(fixedLayer, startScene), [fixedLayer, startScene]);
|
|
18
|
-
(0, react_1.useEffect)(() => {
|
|
19
|
-
if (isSettling && actorRef) {
|
|
20
|
-
const { context } = actorRef.getSnapshot();
|
|
21
|
-
const { transition } = context;
|
|
22
|
-
if (!transition || transition.stage !== 'settling')
|
|
23
|
-
return;
|
|
24
|
-
transitionsRegistry.notifyPrepareTransition(transition.to);
|
|
25
|
-
}
|
|
26
|
-
}, [isSettling, actorRef, transitionsRegistry]);
|
|
27
|
-
(0, react_1.useEffect)(() => {
|
|
28
|
-
if (isActive && actorRef) {
|
|
29
|
-
const { context } = actorRef.getSnapshot();
|
|
30
|
-
const { scenes } = context;
|
|
31
|
-
const [activeScene] = scenes;
|
|
32
|
-
transitionsRegistry.notifyOnActiveSceneChange(activeScene.id);
|
|
33
|
-
}
|
|
34
|
-
}, [isActive, actorRef, transitionsRegistry]);
|
|
35
|
-
return ((0, jsx_runtime_1.jsx)(exports.FixedLayerTransitionsContext.Provider, { value: transitionsRegistry, children: children }));
|
|
36
|
-
};
|
|
37
|
-
exports.FixedLayerTransitionsProvider = FixedLayerTransitionsProvider;
|
|
38
|
-
function useFixedLayerTransitionsRegistry() {
|
|
39
|
-
const registry = (0, react_1.useContext)(exports.FixedLayerTransitionsContext);
|
|
40
|
-
return registry;
|
|
41
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { InteractionItemTrigger } from '../../sdk/types/article/Interaction';
|
|
2
|
-
import { TFixedLayer } from '../../sdk/types/project/FixedLayer';
|
|
3
|
-
import { InteractionsRegistryPort, ItemInteractionCtrl } from '../interactions/types';
|
|
4
|
-
export declare class FixedLayerTransitionsRegistry implements InteractionsRegistryPort {
|
|
5
|
-
private items;
|
|
6
|
-
private ctrls;
|
|
7
|
-
private interactions;
|
|
8
|
-
private transitions;
|
|
9
|
-
private activeSceneId;
|
|
10
|
-
private activeTransition;
|
|
11
|
-
private itemsStages;
|
|
12
|
-
constructor(fixedLayer: TFixedLayer, startSceneId: string);
|
|
13
|
-
register(itemId: ItemId, ctrl: ItemInteractionCtrl): void;
|
|
14
|
-
getStatePropsForItem(itemId: string): StateProps;
|
|
15
|
-
private getTransitionDetails;
|
|
16
|
-
getItemAvailableTriggers(itemId: string): Set<TriggerType>;
|
|
17
|
-
private unpackItems;
|
|
18
|
-
private getNestedItems;
|
|
19
|
-
private getDefaultItemStages;
|
|
20
|
-
notifyItemTrigger(itemId: string, triggerType: TriggerType): void;
|
|
21
|
-
notifyOnActiveSceneChange(sceneId: SceneId): void;
|
|
22
|
-
notifyPrepareTransition(to: SceneId): void;
|
|
23
|
-
notifyTransitionStartForItems(activeStateId: string): void;
|
|
24
|
-
notifyTransitionEnd(itemId: string): void;
|
|
25
|
-
private notifyItemCtrlsChange;
|
|
26
|
-
}
|
|
27
|
-
type TriggerType = InteractionItemTrigger['type'];
|
|
28
|
-
type SceneId = string;
|
|
29
|
-
type ItemId = string;
|
|
30
|
-
type StateProps = Record<string, {
|
|
31
|
-
value?: string | number;
|
|
32
|
-
transition?: {
|
|
33
|
-
timing: string;
|
|
34
|
-
duration: number;
|
|
35
|
-
delay: number;
|
|
36
|
-
};
|
|
37
|
-
}>;
|
|
38
|
-
export {};
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FixedLayerTransitionsRegistry = void 0;
|
|
4
|
-
const ArticleItemType_1 = require("../../sdk/types/article/ArticleItemType");
|
|
5
|
-
const isItemType_1 = require("../utils/isItemType");
|
|
6
|
-
const defaultTransitionDetails = {
|
|
7
|
-
timing: 'ease-in-out',
|
|
8
|
-
duration: 300,
|
|
9
|
-
delay: 0
|
|
10
|
-
};
|
|
11
|
-
class FixedLayerTransitionsRegistry {
|
|
12
|
-
constructor(fixedLayer, startSceneId) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
this.ctrls = new Map();
|
|
15
|
-
this.items = this.unpackItems(fixedLayer);
|
|
16
|
-
const interactions = (_a = fixedLayer.interactions) !== null && _a !== void 0 ? _a : [];
|
|
17
|
-
this.interactions = interactions;
|
|
18
|
-
this.transitions = (_b = fixedLayer.transitions) !== null && _b !== void 0 ? _b : [];
|
|
19
|
-
this.activeSceneId = startSceneId;
|
|
20
|
-
this.itemsStages = this.getDefaultItemStages();
|
|
21
|
-
}
|
|
22
|
-
register(itemId, ctrl) {
|
|
23
|
-
this.ctrls.set(itemId, ctrl);
|
|
24
|
-
}
|
|
25
|
-
getStatePropsForItem(itemId) {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const { items } = this;
|
|
28
|
-
const item = items.find((item) => item.id === itemId);
|
|
29
|
-
const itemStages = this.itemsStages.filter((stage) => stage.itemId === itemId);
|
|
30
|
-
itemStages.sort((a, b) => a.updated - b.updated);
|
|
31
|
-
const itemStyles = {};
|
|
32
|
-
for (const stage of itemStages) {
|
|
33
|
-
if (stage.type === 'active') {
|
|
34
|
-
const params = (_a = item.state[stage.sceneId]) !== null && _a !== void 0 ? _a : {};
|
|
35
|
-
for (const [key, stateDetails] of Object.entries(params)) {
|
|
36
|
-
itemStyles[key] = {
|
|
37
|
-
value: stateDetails.value
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (stage.type === 'transitioning') {
|
|
42
|
-
const activeStateId = stage.to;
|
|
43
|
-
const params = (_b = item.state[activeStateId]) !== null && _b !== void 0 ? _b : {};
|
|
44
|
-
for (const [key, stateDetails] of Object.entries(params)) {
|
|
45
|
-
const transitionDetails = this.getTransitionDetails(itemId, key);
|
|
46
|
-
if (!transitionDetails)
|
|
47
|
-
continue;
|
|
48
|
-
itemStyles[key] = {
|
|
49
|
-
value: stateDetails.value,
|
|
50
|
-
transition: {
|
|
51
|
-
timing: transitionDetails.timing,
|
|
52
|
-
duration: transitionDetails.duration,
|
|
53
|
-
delay: transitionDetails.delay
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return itemStyles;
|
|
60
|
-
}
|
|
61
|
-
getTransitionDetails(itemId, key) {
|
|
62
|
-
var _a;
|
|
63
|
-
if (!this.activeTransition)
|
|
64
|
-
return defaultTransitionDetails;
|
|
65
|
-
this.activeTransition;
|
|
66
|
-
const itemTransitions = this.activeTransition.itemsTransitions[itemId];
|
|
67
|
-
if (!itemTransitions)
|
|
68
|
-
return defaultTransitionDetails;
|
|
69
|
-
return (_a = itemTransitions[key]) !== null && _a !== void 0 ? _a : defaultTransitionDetails;
|
|
70
|
-
}
|
|
71
|
-
getItemAvailableTriggers(itemId) {
|
|
72
|
-
return new Set();
|
|
73
|
-
}
|
|
74
|
-
unpackItems(layer) {
|
|
75
|
-
const items = this.getNestedItems(layer.items);
|
|
76
|
-
return items;
|
|
77
|
-
}
|
|
78
|
-
getNestedItems(items) {
|
|
79
|
-
var _a;
|
|
80
|
-
const allItems = [];
|
|
81
|
-
for (const item of items) {
|
|
82
|
-
if ((0, isItemType_1.isItemType)(item, ArticleItemType_1.ArticleItemType.Group) || (0, isItemType_1.isItemType)(item, ArticleItemType_1.ArticleItemType.Compound)) {
|
|
83
|
-
const groupChildren = (_a = item === null || item === void 0 ? void 0 : item.items) !== null && _a !== void 0 ? _a : [];
|
|
84
|
-
const nestedItems = this.getNestedItems(groupChildren);
|
|
85
|
-
allItems.push(...nestedItems);
|
|
86
|
-
}
|
|
87
|
-
allItems.push(item);
|
|
88
|
-
}
|
|
89
|
-
return allItems;
|
|
90
|
-
}
|
|
91
|
-
getDefaultItemStages() {
|
|
92
|
-
const timestamp = Date.now();
|
|
93
|
-
const { items } = this;
|
|
94
|
-
const stages = [];
|
|
95
|
-
for (const item of items) {
|
|
96
|
-
const itemStatesMap = item.state;
|
|
97
|
-
if (!itemStatesMap)
|
|
98
|
-
continue;
|
|
99
|
-
const itemSceneState = item.state[this.activeSceneId];
|
|
100
|
-
if (!itemSceneState)
|
|
101
|
-
continue;
|
|
102
|
-
stages.push({
|
|
103
|
-
itemId: item.id,
|
|
104
|
-
type: 'active',
|
|
105
|
-
sceneId: this.activeSceneId,
|
|
106
|
-
updated: timestamp
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return stages;
|
|
110
|
-
}
|
|
111
|
-
notifyItemTrigger(itemId, triggerType) {
|
|
112
|
-
throw new Error('Not implemented');
|
|
113
|
-
}
|
|
114
|
-
notifyOnActiveSceneChange(sceneId) {
|
|
115
|
-
this.itemsStages = this.itemsStages.map((stage) => {
|
|
116
|
-
return {
|
|
117
|
-
itemId: stage.itemId,
|
|
118
|
-
type: 'transitioning',
|
|
119
|
-
from: this.activeSceneId,
|
|
120
|
-
to: sceneId,
|
|
121
|
-
updated: Date.now()
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
const items = this.itemsStages.map((stage) => stage.itemId);
|
|
125
|
-
this.notifyItemCtrlsChange(items);
|
|
126
|
-
this.notifyTransitionStartForItems(sceneId);
|
|
127
|
-
this.activeSceneId = sceneId;
|
|
128
|
-
}
|
|
129
|
-
notifyPrepareTransition(to) {
|
|
130
|
-
this.activeTransition = this.transitions.find((transition) => transition.to === to && transition.from === this.activeSceneId);
|
|
131
|
-
}
|
|
132
|
-
notifyTransitionStartForItems(activeStateId) {
|
|
133
|
-
var _a, _b;
|
|
134
|
-
const itemsIds = this.itemsStages.map((stage) => stage.itemId);
|
|
135
|
-
for (const itemId of itemsIds) {
|
|
136
|
-
const ctrl = this.ctrls.get(itemId);
|
|
137
|
-
const item = this.items.find((item) => item.id === itemId);
|
|
138
|
-
const keys = Object.keys((_a = item.state[activeStateId]) !== null && _a !== void 0 ? _a : {});
|
|
139
|
-
(_b = ctrl === null || ctrl === void 0 ? void 0 : ctrl.handleTransitionStart) === null || _b === void 0 ? void 0 : _b.call(ctrl, keys);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
notifyTransitionEnd(itemId) {
|
|
143
|
-
var _a;
|
|
144
|
-
const timestamp = Date.now();
|
|
145
|
-
this.itemsStages = this.itemsStages.map((stage) => {
|
|
146
|
-
if (stage.itemId !== itemId || stage.type !== 'transitioning')
|
|
147
|
-
return stage;
|
|
148
|
-
return {
|
|
149
|
-
itemId,
|
|
150
|
-
type: 'active',
|
|
151
|
-
sceneId: stage.to,
|
|
152
|
-
updated: timestamp
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
156
|
-
}
|
|
157
|
-
notifyItemCtrlsChange(itemsIds) {
|
|
158
|
-
var _a;
|
|
159
|
-
for (const itemId of itemsIds) {
|
|
160
|
-
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.FixedLayerTransitionsRegistry = FixedLayerTransitionsRegistry;
|