@gxpl/sdk 0.0.54 → 0.0.57

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.
Files changed (34) hide show
  1. package/lib/sdk/schemas/article/ItemBase.schema.d.ts +180 -10
  2. package/lib/sdk/schemas/article/ItemBase.schema.js +26 -8
  3. package/lib/sdk/schemas/article/RichTextItem.schema.d.ts +76 -6
  4. package/lib/sdk/schemas/project/Project.schema.d.ts +46 -11
  5. package/lib/sdk/schemas/project/Project.schema.js +14 -3
  6. package/lib/sdk/transitions/transitionMachine.d.ts +104 -0
  7. package/lib/sdk/transitions/transitionMachine.js +19 -17
  8. package/lib/sdk/transitions/utils/getInstantTransitionParams.d.ts +36 -0
  9. package/lib/sdk/transitions/utils/getInstantTransitionParams.js +29 -0
  10. package/lib/sdk/transitions/utils/getScenesOnEnd.d.ts +13 -0
  11. package/lib/sdk/transitions/utils/getScenesOnEnd.js +22 -0
  12. package/lib/sdk/transitions/utils/getScenesOnInstantTransition.js +26 -3
  13. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.d.ts +13 -0
  14. package/lib/sdk/transitions/utils/getScenesOnProgressUpdate.js +7 -0
  15. package/lib/sdk/transitions/utils/getScenesOnStart.d.ts +1 -0
  16. package/lib/sdk/transitions/utils/getScenesOnStart.js +24 -4
  17. package/lib/sdk/transitions/utils/getTransitionFromLink.d.ts +23 -0
  18. package/lib/sdk/transitions/utils/getTransitionFromLink.js +31 -0
  19. package/lib/sdk/transitions/utils/getTransitionFromRelation.d.ts +17 -0
  20. package/lib/sdk/transitions/utils/getTransitionFromRelation.js +26 -0
  21. package/lib/sdk/transitions/utils/getTransitionParams.d.ts +20 -0
  22. package/lib/sdk/transitions/utils/getTransitionParams.js +29 -0
  23. package/lib/sdk/transitions/utils/types.d.ts +56 -14
  24. package/lib/sdk/types/article/Item.d.ts +16 -3
  25. package/lib/sdk/types/project/Relation.d.ts +19 -4
  26. package/lib/sdk-nextjs/components/Preview/Preview.js +4 -7
  27. package/lib/sdk-nextjs/components/Preview/PreviewListener.js +2 -8
  28. package/lib/sdk-nextjs/components/Scene.d.ts +1 -0
  29. package/lib/sdk-nextjs/components/Scene.js +8 -5
  30. package/lib/sdk-nextjs/components/items/LinkWrapper.js +3 -7
  31. package/lib/sdk-nextjs/provider/TransitionMachineContext.d.ts +384 -0
  32. package/lib/sdk-nextjs/utils/RichTextConverter/RichTextConverter.d.ts +1 -0
  33. package/lib/sdk-nextjs/utils/RichTextConverter/RichTextConverter.js +31 -8
  34. package/package.json +1 -1
@@ -0,0 +1,20 @@
1
+ import { Relation } from './types';
2
+ export declare function getTransitionParamsFromRelation(relation: Relation): {
3
+ type: "slide";
4
+ from: string;
5
+ to: string;
6
+ offset?: undefined;
7
+ mode?: undefined;
8
+ } | {
9
+ offset: number;
10
+ mode: "normal" | "reverse";
11
+ type: "reveal";
12
+ from: string;
13
+ to: string;
14
+ } | {
15
+ type: "fade";
16
+ from: string;
17
+ to: string;
18
+ offset?: undefined;
19
+ mode?: undefined;
20
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransitionParamsFromRelation = getTransitionParamsFromRelation;
4
+ function getTransitionParamsFromRelation(relation) {
5
+ if (relation.type === 'slide') {
6
+ return {
7
+ type: relation.type,
8
+ from: relation.from,
9
+ to: relation.to,
10
+ };
11
+ }
12
+ if (relation.type === 'reveal') {
13
+ return {
14
+ offset: relation.offset,
15
+ mode: relation.mode,
16
+ type: relation.type,
17
+ from: relation.from,
18
+ to: relation.to,
19
+ };
20
+ }
21
+ if (relation.type === 'fade') {
22
+ return {
23
+ type: relation.type,
24
+ from: relation.from,
25
+ to: relation.to,
26
+ };
27
+ }
28
+ throw new Error(`Unknown transition type`);
29
+ }
@@ -1,43 +1,83 @@
1
- export type Relation = {
2
- type: 'slide' | 'fade';
1
+ export type Direction = 'north' | 'east' | 'south' | 'west';
2
+ type SlideRelation = {
3
+ to: string;
4
+ type: 'slide';
5
+ direction: Direction;
3
6
  from: string;
7
+ };
8
+ type FadeRelation = {
4
9
  to: string;
10
+ type: 'fade';
5
11
  direction: Direction;
12
+ from: string;
6
13
  };
7
- export type Direction = 'north' | 'east' | 'south' | 'west';
14
+ type RevealRelation = {
15
+ to: string;
16
+ type: 'reveal';
17
+ direction: Direction;
18
+ offset: number;
19
+ mode: 'normal' | 'reverse';
20
+ from: string;
21
+ };
22
+ export type Relation = SlideRelation | FadeRelation | RevealRelation;
8
23
  export type Transition = PreparingTransition | ActiveTransition | InstantTransition | SettlingTransition;
9
24
  export type PreparingTransition = {
10
25
  stage: 'preparing';
11
26
  startX: number;
12
27
  startY: number;
13
28
  };
14
- export type ActiveTransition = {
29
+ type ActiveTransitionBase = {
15
30
  stage: 'active';
16
- direction: Direction;
17
- duration?: number;
18
- type: 'slide' | 'fade';
19
- from: string;
20
- to: string;
21
31
  startX: number;
22
32
  startY: number;
23
33
  currentX: number;
24
34
  currentY: number;
35
+ duration?: number;
36
+ from: string;
37
+ to: string;
38
+ };
39
+ type ActiveSlideTransition = ActiveTransitionBase & {
40
+ type: 'slide';
41
+ direction: Direction;
42
+ };
43
+ type ActiveFadeTransition = ActiveTransitionBase & {
44
+ type: 'fade';
45
+ direction: Direction;
46
+ };
47
+ type ActiveRevealTransition = ActiveTransitionBase & {
48
+ type: 'reveal';
49
+ direction: Direction;
50
+ offset: number;
51
+ mode: 'normal' | 'reverse';
25
52
  };
53
+ export type ActiveTransition = ActiveSlideTransition | ActiveFadeTransition | ActiveRevealTransition;
26
54
  export type SettlingTransition = {
27
55
  stage: 'settling';
28
- type: 'slide' | 'fade';
56
+ type: 'slide' | 'fade' | 'reveal';
29
57
  success: boolean;
30
58
  from: string;
31
59
  to: string;
32
60
  };
33
- export type InstantTransition = {
61
+ type InstantTransitionBase = {
34
62
  stage: 'active';
35
- type: 'slide' | 'fade';
36
63
  from: string;
37
64
  to: string;
38
- direction?: Direction;
39
- duration?: number;
65
+ duration: number;
66
+ };
67
+ export type InstantSlideTransition = {
68
+ type: 'slide';
69
+ direction: Direction;
70
+ };
71
+ export type InstantFadeTransition = {
72
+ type: 'fade';
73
+ };
74
+ export type InstantRevealTransition = {
75
+ type: 'reveal';
76
+ direction: Direction;
77
+ offset: number;
78
+ mode: 'normal' | 'reverse';
40
79
  };
80
+ export type InstantTransition = InstantTransitionBase & (InstantSlideTransition | InstantFadeTransition | InstantRevealTransition);
41
81
  export type TransitionScene = {
42
82
  id: string;
43
83
  styles: TransitionSceneStyle;
@@ -48,4 +88,6 @@ export type TransitionSceneStyle = {
48
88
  x: number;
49
89
  y: number;
50
90
  opacity: number;
91
+ zIndex?: number;
51
92
  };
93
+ export {};
@@ -198,12 +198,25 @@ interface UrlLink {
198
198
  url: string;
199
199
  target: string;
200
200
  }
201
- interface ClickLink {
202
- value: string;
203
- animation: 'fade' | 'slide' | 'reveal';
201
+ interface ClickTransitionBase {
202
+ type: 'scene';
204
203
  duration: number;
204
+ value: string;
205
+ }
206
+ interface SlideLinkTransition extends ClickTransitionBase {
207
+ animation: 'slide';
208
+ direction: 'north' | 'west' | 'south' | 'east';
209
+ }
210
+ interface FadeLinkTransition extends ClickTransitionBase {
211
+ animation: 'fade';
212
+ }
213
+ interface RevealLinkTransition extends ClickTransitionBase {
214
+ animation: 'reveal';
205
215
  direction: 'north' | 'west' | 'south' | 'east';
216
+ offset: number;
217
+ mode: 'normal' | 'reverse';
206
218
  }
219
+ export type ClickLink = SlideLinkTransition | FadeLinkTransition | RevealLinkTransition;
207
220
  export type VideoItem = Item<ArticleItemType.Video>;
208
221
  export type RectangleItem = Item<ArticleItemType.Rectangle>;
209
222
  export type ImageItem = Item<ArticleItemType.Image>;
@@ -1,8 +1,23 @@
1
- export interface Relation {
1
+ type ArticleId = string;
2
+ export type SlideRelation = {
3
+ to: ArticleId;
4
+ type: 'slide';
2
5
  from: ArticleId;
6
+ direction: 'north' | 'east' | 'south' | 'west';
7
+ };
8
+ export type FadeRelation = {
3
9
  to: ArticleId;
4
- type: 'slide' | 'fade';
10
+ type: 'fade';
5
11
  direction: 'north' | 'east' | 'south' | 'west';
6
- }
7
- type ArticleId = string;
12
+ from: ArticleId;
13
+ };
14
+ export type RevealRelation = {
15
+ to: ArticleId;
16
+ type: 'reveal';
17
+ from: ArticleId;
18
+ direction: 'north' | 'east' | 'south' | 'west';
19
+ offset: number;
20
+ mode: 'normal' | 'reverse';
21
+ };
22
+ export type Relation = SlideRelation | FadeRelation | RevealRelation;
8
23
  export {};
@@ -12,6 +12,7 @@ const getAvailableTransitions_1 = require("../../../sdk/transitions/utils/getAva
12
12
  const style_1 = __importDefault(require("styled-jsx/style"));
13
13
  const ChevronIcon_1 = require("./ChevronIcon");
14
14
  const IframePreviewWindowContext_1 = require("./IframePreviewWindowContext");
15
+ const getTransitionFromRelation_1 = require("../../../sdk/transitions/utils/getTransitionFromRelation");
15
16
  const Preview = ({ children, relations, startScene }) => {
16
17
  const id = (0, react_1.useId)();
17
18
  const [iframeRef, setIframeRef] = (0, react_1.useState)(null);
@@ -22,14 +23,10 @@ const Preview = ({ children, relations, startScene }) => {
22
23
  if (!iframeRef || !iframeRef.contentWindow || !iframeRef.contentDocument)
23
24
  return;
24
25
  setIsTransitioning(true);
25
- const transition = (0, findRelation_1.findRelation)(relations, activeScene, direction);
26
+ const relation = (0, findRelation_1.findRelation)(relations, activeScene, direction);
26
27
  const targetWindow = iframeRef.contentWindow;
27
- const message = {
28
- type: "TRANSITION_TRIGGER",
29
- direction,
30
- to: transition.to,
31
- transitionType: transition.type,
32
- };
28
+ const transition = (0, getTransitionFromRelation_1.getTransitionFromRelation)(relation);
29
+ const message = Object.assign({ type: "TRANSITION_TRIGGER", direction }, transition);
33
30
  targetWindow.postMessage(message, "*");
34
31
  };
35
32
  (0, react_1.useEffect)(() => {
@@ -16,14 +16,8 @@ const PreviewListener = () => {
16
16
  const handleMessage = (e) => {
17
17
  var _a;
18
18
  if (((_a = e.data) === null || _a === void 0 ? void 0 : _a.type) === "TRANSITION_TRIGGER") {
19
- const { direction, to, transitionType } = e.data;
20
- actorRef.send({
21
- type: 'TRANSITION_TRIGGER',
22
- transition: transitionType,
23
- duration: 250,
24
- to,
25
- direction
26
- });
19
+ const { direction, to, transition, offset, mode } = e.data;
20
+ actorRef.send(Object.assign(Object.assign({ type: 'TRANSITION_TRIGGER', transition, duration: 250, to }, (transition === 'reveal' || transition === 'slide' ? { direction } : {})), (transition === 'reveal' ? { offset, mode } : {})));
27
21
  }
28
22
  };
29
23
  iframePreviewWindow.addEventListener("message", handleMessage);
@@ -6,6 +6,7 @@ interface Props {
6
6
  x: number;
7
7
  y: number;
8
8
  opacity: number;
9
+ zIndex?: number;
9
10
  startX: number;
10
11
  startY: number;
11
12
  } | undefined;
@@ -7,7 +7,7 @@ const useLayoutDeviation_1 = require("../common/useLayoutDeviation");
7
7
  const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
8
8
  const InteractionsContext_1 = require("../provider/InteractionsContext");
9
9
  const Scene = ({ children, id, styles: sceneStyles, elRef }) => {
10
- var _a;
10
+ var _a, _b;
11
11
  const { layoutDeviation } = (0, useLayoutDeviation_1.useLayoutDeviation)();
12
12
  const interactionsRegistry = (0, InteractionsContext_1.useInteractionsRegistry)();
13
13
  const layoutDeviationStyle = { '--layout-deviation': layoutDeviation };
@@ -119,7 +119,7 @@ const Scene = ({ children, id, styles: sceneStyles, elRef }) => {
119
119
  throw new Error('Transition not found');
120
120
  }
121
121
  const { type } = transition;
122
- const propType = type === 'slide' ? 'transform' : 'opacity';
122
+ const propType = type === 'slide' || type === 'reveal' ? 'transform' : 'opacity';
123
123
  if (e.propertyName !== propType)
124
124
  return;
125
125
  actorRef.send({
@@ -140,7 +140,10 @@ const Scene = ({ children, id, styles: sceneStyles, elRef }) => {
140
140
  const { transition } = context;
141
141
  if (!transition || transition.stage !== 'active')
142
142
  return;
143
- const { to, direction } = transition;
143
+ const { to, type } = transition;
144
+ if (type === 'fade')
145
+ return;
146
+ const { direction } = transition;
144
147
  if (direction === 'north' && to === id) {
145
148
  scene.scrollTo({ top: scene.scrollHeight });
146
149
  }
@@ -172,8 +175,8 @@ const Scene = ({ children, id, styles: sceneStyles, elRef }) => {
172
175
  }
173
176
  }, [isSettling, actorRef, interactionsRegistry]);
174
177
  const isFixed = isControlledTransitioning || isSettling || isInstantTransitioning;
175
- const transitionStyle = type === 'slide' ? 'transform' : 'opacity';
176
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { ref: elRef, className: "article-wrapper", style: Object.assign(Object.assign({}, layoutDeviationStyle), { width: '100vw', height: '100%', zIndex: 1, position: isFixed ? 'fixed' : 'absolute', transform: sceneStyles && (sceneStyles.x !== 0 || sceneStyles.y !== 0) ? `translate(${sceneStyles.x}px, ${sceneStyles.y}px)` : 'none', transition: isSettling || isInstantTransitioning ? `${transitionStyle} ${duration !== null && duration !== void 0 ? duration : 250}ms ease-out` : 'none', overflowY: isFixed ? 'hidden' : 'scroll', overflowX: 'clip', opacity: (_a = sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.opacity) !== null && _a !== void 0 ? _a : 1, 'WebkitOverflowScrolling': 'touch' // prevent glitch on Safari (fast scroll to top/bottom sides)
178
+ const transitionStyle = type === 'slide' || type === 'reveal' ? 'transform' : 'opacity';
179
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { ref: elRef, className: "article-wrapper", style: Object.assign(Object.assign({}, layoutDeviationStyle), { width: '100vw', height: '100%', zIndex: (_a = sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.zIndex) !== null && _a !== void 0 ? _a : 1, position: isFixed ? 'fixed' : 'absolute', transform: sceneStyles && (sceneStyles.x !== 0 || sceneStyles.y !== 0) ? `translate(${sceneStyles.x}px, ${sceneStyles.y}px)` : 'none', transition: isSettling || isInstantTransitioning ? `${transitionStyle} ${duration !== null && duration !== void 0 ? duration : 250}ms ease-out` : 'none', overflowY: isFixed ? 'hidden' : 'scroll', overflowX: 'clip', opacity: (_b = sceneStyles === null || sceneStyles === void 0 ? void 0 : sceneStyles.opacity) !== null && _b !== void 0 ? _b : 1, 'WebkitOverflowScrolling': 'touch' // prevent glitch on Safari (fast scroll to top/bottom sides)
177
180
  }), children: children }) }));
178
181
  };
179
182
  exports.Scene = Scene;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkWrapper = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const TransitionMachineContext_1 = require("../../provider/TransitionMachineContext");
6
+ const getTransitionFromLink_1 = require("../../../sdk/transitions/utils/getTransitionFromLink");
6
7
  const LinkWrapper = ({ link, children }) => {
7
8
  const actorRef = TransitionMachineContext_1.TransitionMachineContext.useActorRef();
8
9
  const validUrl = link && 'url' in link ? buildValidUrl(link.url) : '';
@@ -10,13 +11,8 @@ const LinkWrapper = ({ link, children }) => {
10
11
  const handleGoToScene = () => {
11
12
  if (!actorRef || !link || !('value' in link))
12
13
  return;
13
- actorRef.send({
14
- type: 'TRANSITION_TRIGGER',
15
- transition: link.animation,
16
- duration: link.duration,
17
- to: link.value,
18
- direction: link.direction
19
- });
14
+ const transition = (0, getTransitionFromLink_1.getTransitionFromLink)(link);
15
+ actorRef.send(Object.assign({ type: 'TRANSITION_TRIGGER' }, transition));
20
16
  };
21
17
  if (validUrl) {
22
18
  return ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: validUrl }, targetParams, { children: children })));