@wix/site-service-interactions 1.0.5
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/README.md +1 -0
- package/cjs/build/definition/index.d.ts +12 -0
- package/cjs/build/definition/index.js +6 -0
- package/cjs/build/definition/index.js.map +1 -0
- package/cjs/build/implementations/InteractionsScriptElement.d.ts +3 -0
- package/cjs/build/implementations/InteractionsScriptElement.js +17 -0
- package/cjs/build/implementations/InteractionsScriptElement.js.map +1 -0
- package/cjs/build/implementations/coreInteractions.d.ts +5 -0
- package/cjs/build/implementations/coreInteractions.js +67 -0
- package/cjs/build/implementations/coreInteractions.js.map +1 -0
- package/cjs/build/implementations/index.d.ts +1 -0
- package/cjs/build/implementations/index.js +7 -0
- package/cjs/build/implementations/index.js.map +1 -0
- package/cjs/build/implementations/interactions.d.ts +3 -0
- package/cjs/build/implementations/interactions.js +14 -0
- package/cjs/build/implementations/interactions.js.map +1 -0
- package/cjs/build/implementations/interactionsExternal.d.ts +3 -0
- package/cjs/build/implementations/interactionsExternal.js +19 -0
- package/cjs/build/implementations/interactionsExternal.js.map +1 -0
- package/cjs/build/implementations/interactionsScriptContent.d.ts +1 -0
- package/cjs/build/implementations/interactionsScriptContent.js +26 -0
- package/cjs/build/implementations/interactionsScriptContent.js.map +1 -0
- package/cjs/build/implementations/interactionsService.d.ts +10 -0
- package/cjs/build/implementations/interactionsService.js +14 -0
- package/cjs/build/implementations/interactionsService.js.map +1 -0
- package/cjs/build/implementations/stylesToAdd.d.ts +2 -0
- package/cjs/build/implementations/stylesToAdd.js +14 -0
- package/cjs/build/implementations/stylesToAdd.js.map +1 -0
- package/cjs/build/index.d.ts +2 -0
- package/cjs/build/index.js +19 -0
- package/cjs/build/index.js.map +1 -0
- package/cjs/build/service.d.ts +7 -0
- package/cjs/build/service.js +8 -0
- package/cjs/build/service.js.map +1 -0
- package/cjs/build/types/index.d.ts +2 -0
- package/cjs/build/types/index.js +3 -0
- package/cjs/build/types/index.js.map +1 -0
- package/cjs/package.json +3 -0
- package/definition/package.json +3 -0
- package/dist/definition/index.d.ts +12 -0
- package/dist/definition/index.js +3 -0
- package/dist/definition/index.js.map +1 -0
- package/dist/implementations/InteractionsScriptElement.d.ts +3 -0
- package/dist/implementations/InteractionsScriptElement.js +10 -0
- package/dist/implementations/InteractionsScriptElement.js.map +1 -0
- package/dist/implementations/coreInteractions.d.ts +5 -0
- package/dist/implementations/coreInteractions.js +63 -0
- package/dist/implementations/coreInteractions.js.map +1 -0
- package/dist/implementations/index.d.ts +1 -0
- package/dist/implementations/index.js +2 -0
- package/dist/implementations/index.js.map +1 -0
- package/dist/implementations/interactions.d.ts +3 -0
- package/dist/implementations/interactions.js +10 -0
- package/dist/implementations/interactions.js.map +1 -0
- package/dist/implementations/interactionsExternal.d.ts +3 -0
- package/dist/implementations/interactionsExternal.js +15 -0
- package/dist/implementations/interactionsExternal.js.map +1 -0
- package/dist/implementations/interactionsScriptContent.d.ts +1 -0
- package/dist/implementations/interactionsScriptContent.js +22 -0
- package/dist/implementations/interactionsScriptContent.js.map +1 -0
- package/dist/implementations/interactionsService.d.ts +10 -0
- package/dist/implementations/interactionsService.js +11 -0
- package/dist/implementations/interactionsService.js.map +1 -0
- package/dist/implementations/stylesToAdd.d.ts +2 -0
- package/dist/implementations/stylesToAdd.js +11 -0
- package/dist/implementations/stylesToAdd.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/service.d.ts +7 -0
- package/dist/service.js +5 -0
- package/dist/service.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/implementations/package.json +3 -0
- package/package.json +94 -0
- package/src/definition/index.ts +15 -0
- package/src/implementations/InteractionsScriptElement.tsx +22 -0
- package/src/implementations/coreInteractions.ts +80 -0
- package/src/implementations/index.ts +1 -0
- package/src/implementations/interactions.ts +18 -0
- package/src/implementations/interactionsExternal.ts +25 -0
- package/src/implementations/interactionsScriptContent.ts +21 -0
- package/src/implementations/interactionsService.ts +20 -0
- package/src/implementations/stylesToAdd.ts +11 -0
- package/src/index.ts +2 -0
- package/src/service.ts +5 -0
- package/src/types/index.ts +2 -0
- package/types/package.json +3 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
> ⚠️ **No API stability guarantee.** This package is published to support Wix products and is provided as-is. Its API may change or be removed at any time without notice, and it does not follow semver compatibility guarantees. Use at your own risk.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StaticServiceDefinition } from '@wix/static-service';
|
|
2
|
+
import type { InteractConfig } from '@wix/interact';
|
|
3
|
+
export type IInteractionsServiceConfig = InteractConfig;
|
|
4
|
+
export interface IInteractionsService {
|
|
5
|
+
hasInteractions: (path: string) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export type IInteractionsDefinition = StaticServiceDefinition<IInteractionsService, IInteractionsServiceConfig>;
|
|
8
|
+
export declare const InteractionsDefinition: string & {
|
|
9
|
+
__api: IInteractionsService;
|
|
10
|
+
__config: InteractConfig;
|
|
11
|
+
isServiceDefinition?: boolean;
|
|
12
|
+
} & IInteractionsService;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionsDefinition = void 0;
|
|
4
|
+
const static_service_1 = require("@wix/static-service");
|
|
5
|
+
exports.InteractionsDefinition = (0, static_service_1.defineStaticService)('@wix/site-service-interactions');
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,wDAAyD;AAY5C,QAAA,sBAAsB,GAAG,IAAA,oCAAmB,EACrD,gCAAgC,CACnC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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.createInteractionsScriptElement = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const interactionsScriptContent_1 = require("./interactionsScriptContent");
|
|
9
|
+
const createInteractionsScriptElement = (config, isReducedMotion, pageId) => () => {
|
|
10
|
+
const configId = `interactions-config-${pageId}`;
|
|
11
|
+
const interactionsScriptContent = (0, interactionsScriptContent_1.getInteractionsScriptContent)(configId, isReducedMotion);
|
|
12
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
13
|
+
react_1.default.createElement("script", { type: "application/json", id: configId }, encodeURIComponent(JSON.stringify(config))),
|
|
14
|
+
react_1.default.createElement("script", { type: "module", id: `interactions-loader-${pageId}` }, interactionsScriptContent)));
|
|
15
|
+
};
|
|
16
|
+
exports.createInteractionsScriptElement = createInteractionsScriptElement;
|
|
17
|
+
//# sourceMappingURL=InteractionsScriptElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractionsScriptElement.js","sourceRoot":"","sources":["../../../src/implementations/InteractionsScriptElement.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAGzB,2EAA0E;AAEnE,MAAM,+BAA+B,GACxC,CAAC,MAAsB,EAAE,eAAwB,EAAE,MAAc,EAAqB,EAAE,CACxF,GAAG,EAAE;IACD,MAAM,QAAQ,GAAG,uBAAuB,MAAM,EAAE,CAAA;IAChD,MAAM,yBAAyB,GAAG,IAAA,wDAA4B,EAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IAEzF,OAAO,CACH;QACI,0CAAQ,IAAI,EAAC,kBAAkB,EAAC,EAAE,EAAE,QAAQ,IACvC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CACtC;QACT,0CAAQ,IAAI,EAAC,QAAQ,EAAC,EAAE,EAAE,uBAAuB,MAAM,EAAE,IACpD,yBAAyB,CACrB,CACV,CACN,CAAA;AACL,CAAC,CAAA;AAhBQ,QAAA,+BAA+B,mCAgBvC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InteractConfig } from '@wix/interact';
|
|
2
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
3
|
+
export declare const coreInteractions: (config: InteractConfig, getService: ServicesManager["getService"]) => {
|
|
4
|
+
interactiveComps: Set<string>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coreInteractions = void 0;
|
|
4
|
+
const interact_1 = require("@wix/interact");
|
|
5
|
+
const definition_1 = require("@wix/site-service-device-info/definition");
|
|
6
|
+
const definition_2 = require("@wix/site-service-experiments/definition");
|
|
7
|
+
const definition_3 = require("@wix/site-service-rendering-context/definition");
|
|
8
|
+
const definition_4 = require("@wix/site-service-pages/definition");
|
|
9
|
+
const provide_component_1 = require("@wix/services-manager-react/core-services/provide-component");
|
|
10
|
+
const InteractionsScriptElement_1 = require("./InteractionsScriptElement");
|
|
11
|
+
const initInteract = (config, isReducedMotion) => {
|
|
12
|
+
interact_1.Interact.forceReducedMotion = isReducedMotion;
|
|
13
|
+
interact_1.Interact.setup({
|
|
14
|
+
scrollOptionsGetter: () => globalThis.document.getElementById('site-root'),
|
|
15
|
+
allowA11yTriggers: true,
|
|
16
|
+
});
|
|
17
|
+
interact_1.Interact.create(config);
|
|
18
|
+
};
|
|
19
|
+
const tryInitInteractInSsr = (config, isReducedMotion, getService) => {
|
|
20
|
+
const hasInteractions = config.interactions?.length > 0;
|
|
21
|
+
if (!hasInteractions) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { currentPage } = getService(definition_4.PagesDefinition);
|
|
25
|
+
const pageId = currentPage?.id;
|
|
26
|
+
if (!pageId) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const { addTopComponent } = getService(provide_component_1.ProvideComponentServiceDefinition);
|
|
30
|
+
const ssrScriptElement = (0, InteractionsScriptElement_1.createInteractionsScriptElement)(config, isReducedMotion, pageId);
|
|
31
|
+
addTopComponent(ssrScriptElement);
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const getInteractiveComps = (interactions) => interactions.reduce((acc, { key, effects }) => {
|
|
35
|
+
// add trigger comp
|
|
36
|
+
acc.add(key);
|
|
37
|
+
// add reaction comps
|
|
38
|
+
// there must be a key
|
|
39
|
+
effects.forEach(({ key }) => acc.add(key));
|
|
40
|
+
return acc;
|
|
41
|
+
}, new Set());
|
|
42
|
+
const coreInteractions = (config, getService) => {
|
|
43
|
+
const { reducedMotion: isReducedMotion } = getService(definition_1.DeviceInfoDefinition);
|
|
44
|
+
const { isOpen } = getService(definition_2.ExperimentsDefinition);
|
|
45
|
+
const { SSR } = getService(definition_3.RenderingContextDefinition);
|
|
46
|
+
const isSSRExperimentOpen = isOpen('specs.thunderbolt.interactionsInSsr');
|
|
47
|
+
if (isSSRExperimentOpen) {
|
|
48
|
+
let didInitInteractInSsr = false;
|
|
49
|
+
try {
|
|
50
|
+
didInitInteractInSsr = tryInitInteractInSsr(config, isReducedMotion, getService);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.warn('failed initializing Interact in SSR, falling back to client init:', error);
|
|
54
|
+
}
|
|
55
|
+
if (!didInitInteractInSsr && !SSR) {
|
|
56
|
+
initInteract(config, isReducedMotion);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
initInteract(config, isReducedMotion);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
interactiveComps: getInteractiveComps(config.interactions),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.coreInteractions = coreInteractions;
|
|
67
|
+
//# sourceMappingURL=coreInteractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreInteractions.js","sourceRoot":"","sources":["../../../src/implementations/coreInteractions.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InteractionsService, InteractionsServiceExternal } from './interactionsService';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionsServiceExternal = exports.InteractionsService = void 0;
|
|
4
|
+
var interactionsService_1 = require("./interactionsService");
|
|
5
|
+
Object.defineProperty(exports, "InteractionsService", { enumerable: true, get: function () { return interactionsService_1.InteractionsService; } });
|
|
6
|
+
Object.defineProperty(exports, "InteractionsServiceExternal", { enumerable: true, get: function () { return interactionsService_1.InteractionsServiceExternal; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/implementations/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwF;AAA/E,0HAAA,mBAAmB,OAAA;AAAE,kIAAA,2BAA2B,OAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
2
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition';
|
|
3
|
+
export declare const createInteractions: (config: IInteractionsServiceConfig, getService: ServicesManager["getService"]) => IInteractionsService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInteractions = void 0;
|
|
4
|
+
const coreInteractions_1 = require("./coreInteractions");
|
|
5
|
+
const createInteractions = (config, getService) => {
|
|
6
|
+
const { interactiveComps } = (0, coreInteractions_1.coreInteractions)(config, getService);
|
|
7
|
+
const getConfigPath = (path) => path.replace(/\[[^\]]+]/g, '[]');
|
|
8
|
+
const hasInteractions = path => interactiveComps.has(getConfigPath(path));
|
|
9
|
+
return {
|
|
10
|
+
hasInteractions,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.createInteractions = createInteractions;
|
|
14
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.js","sourceRoot":"","sources":["../../../src/implementations/interactions.ts"],"names":[],"mappings":";;;AAEA,yDAAqD;AAE9C,MAAM,kBAAkB,GAAG,CAC9B,MAAkC,EAClC,UAAyC,EACrB,EAAE;IACtB,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,mCAAgB,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;IAExE,MAAM,eAAe,GAA4C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;IAElH,OAAO;QACH,eAAe;KAClB,CAAA;AACL,CAAC,CAAA;AAbY,QAAA,kBAAkB,sBAa9B"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
2
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition';
|
|
3
|
+
export declare const createInteractionsExternal: (config: IInteractionsServiceConfig, getService: ServicesManager["getService"]) => IInteractionsService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInteractionsExternal = void 0;
|
|
4
|
+
const definition_1 = require("@wix/site-service-provide-css/definition");
|
|
5
|
+
const coreInteractions_1 = require("./coreInteractions");
|
|
6
|
+
const stylesToAdd_1 = require("./stylesToAdd");
|
|
7
|
+
const createInteractionsExternal = (config, getService) => {
|
|
8
|
+
const provideCssService = getService(definition_1.ProvideCssDefinition);
|
|
9
|
+
const styles = [stylesToAdd_1.wixInteractElementCss, stylesToAdd_1.hasClickTriggerCss];
|
|
10
|
+
const cssToAdd = styles.join('\n');
|
|
11
|
+
provideCssService.addStyle(cssToAdd);
|
|
12
|
+
const { interactiveComps } = (0, coreInteractions_1.coreInteractions)(config, getService);
|
|
13
|
+
const hasInteractions = path => interactiveComps.has(path);
|
|
14
|
+
return {
|
|
15
|
+
hasInteractions,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.createInteractionsExternal = createInteractionsExternal;
|
|
19
|
+
//# sourceMappingURL=interactionsExternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsExternal.js","sourceRoot":"","sources":["../../../src/implementations/interactionsExternal.ts"],"names":[],"mappings":";;;AAAA,yEAA+E;AAG/E,yDAAqD;AACrD,+CAAyE;AAElE,MAAM,0BAA0B,GAAG,CACtC,MAAkC,EAClC,UAAyC,EACrB,EAAE;IACtB,MAAM,iBAAiB,GAAG,UAAU,CAAC,iCAAoB,CAAC,CAAA;IAE1D,MAAM,MAAM,GAAG,CAAC,mCAAqB,EAAE,gCAAkB,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAElC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAEpC,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,mCAAgB,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjE,MAAM,eAAe,GAA4C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAEnG,OAAO;QACH,eAAe;KAClB,CAAA;AACL,CAAC,CAAA;AAlBY,QAAA,0BAA0B,8BAkBtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getInteractionsScriptContent: (configId: string, isReducedMotion: boolean) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInteractionsScriptContent = void 0;
|
|
4
|
+
const getInteractionsScriptContent = (configId, isReducedMotion) => `
|
|
5
|
+
await import(\`https://static.parastorage.com/services/interact/dist/interact.umd.min.js\`);
|
|
6
|
+
|
|
7
|
+
const configElement = document.getElementById(\`${configId}\`);
|
|
8
|
+
if (configElement) {
|
|
9
|
+
const Interact = window.interact?.Interact;
|
|
10
|
+
if (!Interact) {
|
|
11
|
+
console.error(\`Interact library is not loaded\`);
|
|
12
|
+
} else {
|
|
13
|
+
const config = JSON.parse(decodeURIComponent(configElement.textContent));
|
|
14
|
+
|
|
15
|
+
Interact.forceReducedMotion = ${isReducedMotion};
|
|
16
|
+
Interact.setup({
|
|
17
|
+
scrollOptionsGetter: function(){ return document.getElementById(\`site-root\`) },
|
|
18
|
+
allowA11yTriggers: true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
Interact.create(config);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
exports.getInteractionsScriptContent = getInteractionsScriptContent;
|
|
26
|
+
//# sourceMappingURL=interactionsScriptContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsScriptContent.js","sourceRoot":"","sources":["../../../src/implementations/interactionsScriptContent.ts"],"names":[],"mappings":";;;AAAO,MAAM,4BAA4B,GAAG,CAAC,QAAgB,EAAE,eAAwB,EAAE,EAAE,CAAC;;;sDAGtC,QAAQ;;;;;;;;4CAQlB,eAAe;;;;;;;;;CAS1D,CAAA;AApBY,QAAA,4BAA4B,gCAoBxC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const InteractionsService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
2
|
+
__api: import("../definition").IInteractionsService;
|
|
3
|
+
__config: import("@wix/interact").InteractConfig;
|
|
4
|
+
isServiceDefinition?: boolean;
|
|
5
|
+
} & import("../definition").IInteractionsService, import("@wix/interact").InteractConfig>;
|
|
6
|
+
export declare const InteractionsServiceExternal: import("@wix/services-definitions").ServiceFactory<string & {
|
|
7
|
+
__api: import("../definition").IInteractionsService;
|
|
8
|
+
__config: import("@wix/interact").InteractConfig;
|
|
9
|
+
isServiceDefinition?: boolean;
|
|
10
|
+
} & import("../definition").IInteractionsService, import("@wix/interact").InteractConfig>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionsServiceExternal = exports.InteractionsService = void 0;
|
|
4
|
+
const static_service_1 = require("@wix/static-service");
|
|
5
|
+
const definition_1 = require("../definition");
|
|
6
|
+
const interactions_1 = require("./interactions");
|
|
7
|
+
const interactionsExternal_1 = require("./interactionsExternal");
|
|
8
|
+
exports.InteractionsService = (0, static_service_1.implementStaticService)(definition_1.InteractionsDefinition, ({ config, getService }) => {
|
|
9
|
+
return (0, interactions_1.createInteractions)(config, getService);
|
|
10
|
+
});
|
|
11
|
+
exports.InteractionsServiceExternal = (0, static_service_1.implementStaticService)(definition_1.InteractionsDefinition, ({ config, getService }) => {
|
|
12
|
+
return (0, interactionsExternal_1.createInteractionsExternal)(config, getService);
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=interactionsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsService.js","sourceRoot":"","sources":["../../../src/implementations/interactionsService.ts"],"names":[],"mappings":";;;AAAA,wDAA4D;AAG5D,8CAAsD;AACtD,iDAAmD;AACnD,iEAAmE;AAEtD,QAAA,mBAAmB,GAAG,IAAA,uCAAsB,EACrD,mCAAsB,EACtB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAwD,EAAE,EAAE;IAC7E,OAAO,IAAA,iCAAkB,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACjD,CAAC,CACJ,CAAA;AAEY,QAAA,2BAA2B,GAAG,IAAA,uCAAsB,EAC7D,mCAAsB,EACtB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAwD,EAAE,EAAE;IAC7E,OAAO,IAAA,iDAA0B,EAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACzD,CAAC,CACJ,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasClickTriggerCss = exports.wixInteractElementCss = void 0;
|
|
4
|
+
exports.wixInteractElementCss = `
|
|
5
|
+
wix-interact-element {
|
|
6
|
+
display: contents;
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
exports.hasClickTriggerCss = `
|
|
10
|
+
.has-click-trigger {
|
|
11
|
+
cursor: pointer;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
//# sourceMappingURL=stylesToAdd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylesToAdd.js","sourceRoot":"","sources":["../../../src/implementations/stylesToAdd.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG;;;;KAIhC,CAAA;AAEQ,QAAA,kBAAkB,GAAG;;;;KAI7B,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./definition"), exports);
|
|
18
|
+
__exportStar(require("./implementations"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,oDAAiC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InteractionsService } from './implementations/interactionsService';
|
|
2
|
+
export declare const definition: string & {
|
|
3
|
+
__api: import("./definition").IInteractionsService;
|
|
4
|
+
__config: import("@wix/interact").InteractConfig;
|
|
5
|
+
isServiceDefinition?: boolean;
|
|
6
|
+
} & import("./definition").IInteractionsService;
|
|
7
|
+
export default InteractionsService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.definition = void 0;
|
|
4
|
+
const definition_1 = require("./definition");
|
|
5
|
+
const interactionsService_1 = require("./implementations/interactionsService");
|
|
6
|
+
exports.definition = definition_1.InteractionsDefinition;
|
|
7
|
+
exports.default = interactionsService_1.InteractionsService;
|
|
8
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,+EAA2E;AAE9D,QAAA,UAAU,GAAG,mCAAsB,CAAA;AAChD,kBAAe,yCAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":""}
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StaticServiceDefinition } from '@wix/static-service';
|
|
2
|
+
import type { InteractConfig } from '@wix/interact';
|
|
3
|
+
export type IInteractionsServiceConfig = InteractConfig;
|
|
4
|
+
export interface IInteractionsService {
|
|
5
|
+
hasInteractions: (path: string) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export type IInteractionsDefinition = StaticServiceDefinition<IInteractionsService, IInteractionsServiceConfig>;
|
|
8
|
+
export declare const InteractionsDefinition: string & {
|
|
9
|
+
__api: IInteractionsService;
|
|
10
|
+
__config: InteractConfig;
|
|
11
|
+
isServiceDefinition?: boolean;
|
|
12
|
+
} & IInteractionsService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAYzD,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CACrD,gCAAgC,CACnC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { getInteractionsScriptContent } from './interactionsScriptContent';
|
|
3
|
+
export const createInteractionsScriptElement = (config, isReducedMotion, pageId) => () => {
|
|
4
|
+
const configId = `interactions-config-${pageId}`;
|
|
5
|
+
const interactionsScriptContent = getInteractionsScriptContent(configId, isReducedMotion);
|
|
6
|
+
return (React.createElement(React.Fragment, null,
|
|
7
|
+
React.createElement("script", { type: "application/json", id: configId }, encodeURIComponent(JSON.stringify(config))),
|
|
8
|
+
React.createElement("script", { type: "module", id: `interactions-loader-${pageId}` }, interactionsScriptContent)));
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=InteractionsScriptElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractionsScriptElement.js","sourceRoot":"","sources":["../../src/implementations/InteractionsScriptElement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AAE1E,MAAM,CAAC,MAAM,+BAA+B,GACxC,CAAC,MAAsB,EAAE,eAAwB,EAAE,MAAc,EAAqB,EAAE,CACxF,GAAG,EAAE;IACD,MAAM,QAAQ,GAAG,uBAAuB,MAAM,EAAE,CAAA;IAChD,MAAM,yBAAyB,GAAG,4BAA4B,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IAEzF,OAAO,CACH;QACI,gCAAQ,IAAI,EAAC,kBAAkB,EAAC,EAAE,EAAE,QAAQ,IACvC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CACtC;QACT,gCAAQ,IAAI,EAAC,QAAQ,EAAC,EAAE,EAAE,uBAAuB,MAAM,EAAE,IACpD,yBAAyB,CACrB,CACV,CACN,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InteractConfig } from '@wix/interact';
|
|
2
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
3
|
+
export declare const coreInteractions: (config: InteractConfig, getService: ServicesManager["getService"]) => {
|
|
4
|
+
interactiveComps: Set<string>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Interact } from '@wix/interact';
|
|
2
|
+
import { DeviceInfoDefinition } from '@wix/site-service-device-info/definition';
|
|
3
|
+
import { ExperimentsDefinition } from '@wix/site-service-experiments/definition';
|
|
4
|
+
import { RenderingContextDefinition } from '@wix/site-service-rendering-context/definition';
|
|
5
|
+
import { PagesDefinition } from '@wix/site-service-pages/definition';
|
|
6
|
+
import { ProvideComponentServiceDefinition } from '@wix/services-manager-react/core-services/provide-component';
|
|
7
|
+
import { createInteractionsScriptElement } from './InteractionsScriptElement';
|
|
8
|
+
const initInteract = (config, isReducedMotion) => {
|
|
9
|
+
Interact.forceReducedMotion = isReducedMotion;
|
|
10
|
+
Interact.setup({
|
|
11
|
+
scrollOptionsGetter: () => globalThis.document.getElementById('site-root'),
|
|
12
|
+
allowA11yTriggers: true,
|
|
13
|
+
});
|
|
14
|
+
Interact.create(config);
|
|
15
|
+
};
|
|
16
|
+
const tryInitInteractInSsr = (config, isReducedMotion, getService) => {
|
|
17
|
+
const hasInteractions = config.interactions?.length > 0;
|
|
18
|
+
if (!hasInteractions) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const { currentPage } = getService(PagesDefinition);
|
|
22
|
+
const pageId = currentPage?.id;
|
|
23
|
+
if (!pageId) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const { addTopComponent } = getService(ProvideComponentServiceDefinition);
|
|
27
|
+
const ssrScriptElement = createInteractionsScriptElement(config, isReducedMotion, pageId);
|
|
28
|
+
addTopComponent(ssrScriptElement);
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
const getInteractiveComps = (interactions) => interactions.reduce((acc, { key, effects }) => {
|
|
32
|
+
// add trigger comp
|
|
33
|
+
acc.add(key);
|
|
34
|
+
// add reaction comps
|
|
35
|
+
// there must be a key
|
|
36
|
+
effects.forEach(({ key }) => acc.add(key));
|
|
37
|
+
return acc;
|
|
38
|
+
}, new Set());
|
|
39
|
+
export const coreInteractions = (config, getService) => {
|
|
40
|
+
const { reducedMotion: isReducedMotion } = getService(DeviceInfoDefinition);
|
|
41
|
+
const { isOpen } = getService(ExperimentsDefinition);
|
|
42
|
+
const { SSR } = getService(RenderingContextDefinition);
|
|
43
|
+
const isSSRExperimentOpen = isOpen('specs.thunderbolt.interactionsInSsr');
|
|
44
|
+
if (isSSRExperimentOpen) {
|
|
45
|
+
let didInitInteractInSsr = false;
|
|
46
|
+
try {
|
|
47
|
+
didInitInteractInSsr = tryInitInteractInSsr(config, isReducedMotion, getService);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.warn('failed initializing Interact in SSR, falling back to client init:', error);
|
|
51
|
+
}
|
|
52
|
+
if (!didInitInteractInSsr && !SSR) {
|
|
53
|
+
initInteract(config, isReducedMotion);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
initInteract(config, isReducedMotion);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
interactiveComps: getInteractiveComps(config.interactions),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=coreInteractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreInteractions.js","sourceRoot":"","sources":["../../src/implementations/coreInteractions.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InteractionsService, InteractionsServiceExternal } from './interactionsService';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/implementations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
2
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition';
|
|
3
|
+
export declare const createInteractions: (config: IInteractionsServiceConfig, getService: ServicesManager["getService"]) => IInteractionsService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { coreInteractions } from './coreInteractions';
|
|
2
|
+
export const createInteractions = (config, getService) => {
|
|
3
|
+
const { interactiveComps } = coreInteractions(config, getService);
|
|
4
|
+
const getConfigPath = (path) => path.replace(/\[[^\]]+]/g, '[]');
|
|
5
|
+
const hasInteractions = path => interactiveComps.has(getConfigPath(path));
|
|
6
|
+
return {
|
|
7
|
+
hasInteractions,
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.js","sourceRoot":"","sources":["../../src/implementations/interactions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,MAAkC,EAClC,UAAyC,EACrB,EAAE;IACtB,MAAM,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;IAExE,MAAM,eAAe,GAA4C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;IAElH,OAAO;QACH,eAAe;KAClB,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ServicesManager } from '@wix/services-manager/types';
|
|
2
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition';
|
|
3
|
+
export declare const createInteractionsExternal: (config: IInteractionsServiceConfig, getService: ServicesManager["getService"]) => IInteractionsService;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProvideCssDefinition } from '@wix/site-service-provide-css/definition';
|
|
2
|
+
import { coreInteractions } from './coreInteractions';
|
|
3
|
+
import { hasClickTriggerCss, wixInteractElementCss } from './stylesToAdd';
|
|
4
|
+
export const createInteractionsExternal = (config, getService) => {
|
|
5
|
+
const provideCssService = getService(ProvideCssDefinition);
|
|
6
|
+
const styles = [wixInteractElementCss, hasClickTriggerCss];
|
|
7
|
+
const cssToAdd = styles.join('\n');
|
|
8
|
+
provideCssService.addStyle(cssToAdd);
|
|
9
|
+
const { interactiveComps } = coreInteractions(config, getService);
|
|
10
|
+
const hasInteractions = path => interactiveComps.has(path);
|
|
11
|
+
return {
|
|
12
|
+
hasInteractions,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=interactionsExternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsExternal.js","sourceRoot":"","sources":["../../src/implementations/interactionsExternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAEzE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACtC,MAAkC,EAClC,UAAyC,EACrB,EAAE;IACtB,MAAM,iBAAiB,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAA;IAE1D,MAAM,MAAM,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAElC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAEpC,MAAM,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjE,MAAM,eAAe,GAA4C,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAEnG,OAAO;QACH,eAAe;KAClB,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getInteractionsScriptContent: (configId: string, isReducedMotion: boolean) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const getInteractionsScriptContent = (configId, isReducedMotion) => `
|
|
2
|
+
await import(\`https://static.parastorage.com/services/interact/dist/interact.umd.min.js\`);
|
|
3
|
+
|
|
4
|
+
const configElement = document.getElementById(\`${configId}\`);
|
|
5
|
+
if (configElement) {
|
|
6
|
+
const Interact = window.interact?.Interact;
|
|
7
|
+
if (!Interact) {
|
|
8
|
+
console.error(\`Interact library is not loaded\`);
|
|
9
|
+
} else {
|
|
10
|
+
const config = JSON.parse(decodeURIComponent(configElement.textContent));
|
|
11
|
+
|
|
12
|
+
Interact.forceReducedMotion = ${isReducedMotion};
|
|
13
|
+
Interact.setup({
|
|
14
|
+
scrollOptionsGetter: function(){ return document.getElementById(\`site-root\`) },
|
|
15
|
+
allowA11yTriggers: true,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
Interact.create(config);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
//# sourceMappingURL=interactionsScriptContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsScriptContent.js","sourceRoot":"","sources":["../../src/implementations/interactionsScriptContent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,QAAgB,EAAE,eAAwB,EAAE,EAAE,CAAC;;;sDAGtC,QAAQ;;;;;;;;4CAQlB,eAAe;;;;;;;;;CAS1D,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const InteractionsService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
2
|
+
__api: import("..").IInteractionsService;
|
|
3
|
+
__config: import("@wix/interact").InteractConfig;
|
|
4
|
+
isServiceDefinition?: boolean;
|
|
5
|
+
} & import("..").IInteractionsService, import("@wix/interact").InteractConfig>;
|
|
6
|
+
export declare const InteractionsServiceExternal: import("@wix/services-definitions").ServiceFactory<string & {
|
|
7
|
+
__api: import("..").IInteractionsService;
|
|
8
|
+
__config: import("@wix/interact").InteractConfig;
|
|
9
|
+
isServiceDefinition?: boolean;
|
|
10
|
+
} & import("..").IInteractionsService, import("@wix/interact").InteractConfig>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { implementStaticService } from '@wix/static-service';
|
|
2
|
+
import { InteractionsDefinition } from '../definition';
|
|
3
|
+
import { createInteractions } from './interactions';
|
|
4
|
+
import { createInteractionsExternal } from './interactionsExternal';
|
|
5
|
+
export const InteractionsService = implementStaticService(InteractionsDefinition, ({ config, getService }) => {
|
|
6
|
+
return createInteractions(config, getService);
|
|
7
|
+
});
|
|
8
|
+
export const InteractionsServiceExternal = implementStaticService(InteractionsDefinition, ({ config, getService }) => {
|
|
9
|
+
return createInteractionsExternal(config, getService);
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=interactionsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionsService.js","sourceRoot":"","sources":["../../src/implementations/interactionsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA;AAEnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CACrD,sBAAsB,EACtB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAwD,EAAE,EAAE;IAC7E,OAAO,kBAAkB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACjD,CAAC,CACJ,CAAA;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAAsB,CAC7D,sBAAsB,EACtB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAwD,EAAE,EAAE;IAC7E,OAAO,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACzD,CAAC,CACJ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylesToAdd.js","sourceRoot":"","sources":["../../src/implementations/stylesToAdd.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;KAIhC,CAAA;AAEL,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;KAI7B,CAAA"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InteractionsService } from './implementations/interactionsService';
|
|
2
|
+
export declare const definition: string & {
|
|
3
|
+
__api: import("./definition").IInteractionsService;
|
|
4
|
+
__config: import("@wix/interact").InteractConfig;
|
|
5
|
+
isServiceDefinition?: boolean;
|
|
6
|
+
} & import("./definition").IInteractionsService;
|
|
7
|
+
export default InteractionsService;
|
package/dist/service.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAE3E,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAA;AAChD,eAAe,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wix/site-service-interactions",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"main": "cjs/build/index.js",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "UNLICENSED",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src",
|
|
11
|
+
"cjs",
|
|
12
|
+
"definition",
|
|
13
|
+
"implementations",
|
|
14
|
+
"types",
|
|
15
|
+
"!doc.md",
|
|
16
|
+
"!**/*.tsbuildinfo"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./cjs/build/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./definition": {
|
|
25
|
+
"types": "./dist/definition/index.d.ts",
|
|
26
|
+
"import": "./dist/definition/index.js",
|
|
27
|
+
"require": "./cjs/build/definition/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./implementations": {
|
|
30
|
+
"types": "./dist/implementations/index.d.ts",
|
|
31
|
+
"import": "./dist/implementations/index.js",
|
|
32
|
+
"require": "./cjs/build/implementations/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./types": {
|
|
35
|
+
"types": "./dist/types/index.d.ts",
|
|
36
|
+
"import": "./dist/types/index.js",
|
|
37
|
+
"require": "./cjs/build/types/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./service": {
|
|
40
|
+
"types": "./dist/service.d.ts",
|
|
41
|
+
"import": "./dist/service.js",
|
|
42
|
+
"require": "./cjs/build/service.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@wix/interact": "^1.103.0",
|
|
47
|
+
"@wix/services-manager": "^0.2.20",
|
|
48
|
+
"@wix/services-manager-react": "^0.1.26",
|
|
49
|
+
"@wix/site-service-device-info": "1.0.2",
|
|
50
|
+
"@wix/site-service-experiments": "1.0.3",
|
|
51
|
+
"@wix/site-service-pages": "1.0.2",
|
|
52
|
+
"@wix/site-service-provide-css": "1.0.1",
|
|
53
|
+
"@wix/site-service-rendering-context": "1.0.1",
|
|
54
|
+
"@wix/static-service": "1.0.19"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/react": "^18.3.1",
|
|
58
|
+
"react": "^18.3.1",
|
|
59
|
+
"typescript": "^5.3.3",
|
|
60
|
+
"vitest": "4.1.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"react": "^18.3.1"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -b . --force && tsc --project tsconfig.cjs.json",
|
|
67
|
+
"lint": "yarn run -T lint:package $npm_package_name",
|
|
68
|
+
"test": "vitest --run && yarn test-type-check",
|
|
69
|
+
"test-type-check": "echo 'validating typescript in test files' && tsc --project tsconfig.test.json && echo 'Finished validating typescript in test files successfully'"
|
|
70
|
+
},
|
|
71
|
+
"publishUnscoped": false,
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"registry": "https://registry.npmjs.org/",
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"sideEffects": false,
|
|
77
|
+
"wix": {
|
|
78
|
+
"artifact": {
|
|
79
|
+
"groupId": "com.wixpress.npm",
|
|
80
|
+
"artifactId": "site-service-interactions",
|
|
81
|
+
"targets": {
|
|
82
|
+
"static": false,
|
|
83
|
+
"docker": false
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"validations": {
|
|
87
|
+
"postBuild": [
|
|
88
|
+
"test",
|
|
89
|
+
"lint"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"falconPackageHash": "85715af7584a4dbc47ae9ac967a02031c2f86152811a4c1c9155471a"
|
|
94
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineStaticService } from '@wix/static-service'
|
|
2
|
+
import type { StaticServiceDefinition } from '@wix/static-service'
|
|
3
|
+
import type { InteractConfig } from '@wix/interact'
|
|
4
|
+
|
|
5
|
+
export type IInteractionsServiceConfig = InteractConfig
|
|
6
|
+
|
|
7
|
+
export interface IInteractionsService {
|
|
8
|
+
hasInteractions: (path: string) => boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type IInteractionsDefinition = StaticServiceDefinition<IInteractionsService, IInteractionsServiceConfig>
|
|
12
|
+
|
|
13
|
+
export const InteractionsDefinition = defineStaticService<IInteractionsService, IInteractionsServiceConfig>(
|
|
14
|
+
'@wix/site-service-interactions'
|
|
15
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { FunctionComponent } from 'react'
|
|
3
|
+
import type { InteractConfig } from '@wix/interact'
|
|
4
|
+
import { getInteractionsScriptContent } from './interactionsScriptContent'
|
|
5
|
+
|
|
6
|
+
export const createInteractionsScriptElement =
|
|
7
|
+
(config: InteractConfig, isReducedMotion: boolean, pageId: string): FunctionComponent =>
|
|
8
|
+
() => {
|
|
9
|
+
const configId = `interactions-config-${pageId}`
|
|
10
|
+
const interactionsScriptContent = getInteractionsScriptContent(configId, isReducedMotion)
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<script type="application/json" id={configId}>
|
|
15
|
+
{encodeURIComponent(JSON.stringify(config))}
|
|
16
|
+
</script>
|
|
17
|
+
<script type="module" id={`interactions-loader-${pageId}`}>
|
|
18
|
+
{interactionsScriptContent}
|
|
19
|
+
</script>
|
|
20
|
+
</>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Interact } from '@wix/interact'
|
|
2
|
+
import type { InteractConfig } from '@wix/interact'
|
|
3
|
+
import { DeviceInfoDefinition } from '@wix/site-service-device-info/definition'
|
|
4
|
+
import { ExperimentsDefinition } from '@wix/site-service-experiments/definition'
|
|
5
|
+
import { RenderingContextDefinition } from '@wix/site-service-rendering-context/definition'
|
|
6
|
+
import { PagesDefinition } from '@wix/site-service-pages/definition'
|
|
7
|
+
import { ProvideComponentServiceDefinition } from '@wix/services-manager-react/core-services/provide-component'
|
|
8
|
+
import type { ServicesManager } from '@wix/services-manager/types'
|
|
9
|
+
import { createInteractionsScriptElement } from './InteractionsScriptElement'
|
|
10
|
+
|
|
11
|
+
const initInteract = (config: InteractConfig, isReducedMotion: boolean) => {
|
|
12
|
+
Interact.forceReducedMotion = isReducedMotion
|
|
13
|
+
Interact.setup({
|
|
14
|
+
scrollOptionsGetter: () => globalThis.document.getElementById('site-root'),
|
|
15
|
+
allowA11yTriggers: true,
|
|
16
|
+
})
|
|
17
|
+
Interact.create(config)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const tryInitInteractInSsr = (
|
|
21
|
+
config: InteractConfig,
|
|
22
|
+
isReducedMotion: boolean,
|
|
23
|
+
getService: ServicesManager['getService']
|
|
24
|
+
) => {
|
|
25
|
+
const hasInteractions = config.interactions?.length > 0
|
|
26
|
+
if (!hasInteractions) {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { currentPage } = getService(PagesDefinition)
|
|
31
|
+
const pageId = currentPage?.id
|
|
32
|
+
|
|
33
|
+
if (!pageId) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { addTopComponent } = getService(ProvideComponentServiceDefinition)
|
|
38
|
+
const ssrScriptElement = createInteractionsScriptElement(config, isReducedMotion, pageId)
|
|
39
|
+
addTopComponent(ssrScriptElement)
|
|
40
|
+
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const getInteractiveComps = (interactions: InteractConfig['interactions']) =>
|
|
45
|
+
interactions.reduce((acc, { key, effects }) => {
|
|
46
|
+
// add trigger comp
|
|
47
|
+
acc.add(key)
|
|
48
|
+
// add reaction comps
|
|
49
|
+
// there must be a key
|
|
50
|
+
effects.forEach(({ key }) => acc.add(key!))
|
|
51
|
+
|
|
52
|
+
return acc
|
|
53
|
+
}, new Set<string>())
|
|
54
|
+
|
|
55
|
+
export const coreInteractions = (config: InteractConfig, getService: ServicesManager['getService']) => {
|
|
56
|
+
const { reducedMotion: isReducedMotion } = getService(DeviceInfoDefinition)
|
|
57
|
+
const { isOpen } = getService(ExperimentsDefinition)
|
|
58
|
+
const { SSR } = getService(RenderingContextDefinition)
|
|
59
|
+
|
|
60
|
+
const isSSRExperimentOpen = isOpen('specs.thunderbolt.interactionsInSsr')
|
|
61
|
+
if (isSSRExperimentOpen) {
|
|
62
|
+
let didInitInteractInSsr = false
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
didInitInteractInSsr = tryInitInteractInSsr(config, isReducedMotion, getService)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn('failed initializing Interact in SSR, falling back to client init:', error)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!didInitInteractInSsr && !SSR) {
|
|
71
|
+
initInteract(config, isReducedMotion)
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
initInteract(config, isReducedMotion)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
interactiveComps: getInteractiveComps(config.interactions),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InteractionsService, InteractionsServiceExternal } from './interactionsService'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ServicesManager } from '@wix/services-manager/types'
|
|
2
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition'
|
|
3
|
+
import { coreInteractions } from './coreInteractions'
|
|
4
|
+
|
|
5
|
+
export const createInteractions = (
|
|
6
|
+
config: IInteractionsServiceConfig,
|
|
7
|
+
getService: ServicesManager['getService']
|
|
8
|
+
): IInteractionsService => {
|
|
9
|
+
const { interactiveComps } = coreInteractions(config, getService)
|
|
10
|
+
|
|
11
|
+
const getConfigPath = (path: string) => path.replace(/\[[^\]]+]/g, '[]')
|
|
12
|
+
|
|
13
|
+
const hasInteractions: IInteractionsService['hasInteractions'] = path => interactiveComps.has(getConfigPath(path))
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
hasInteractions,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ProvideCssDefinition } from '@wix/site-service-provide-css/definition'
|
|
2
|
+
import type { ServicesManager } from '@wix/services-manager/types'
|
|
3
|
+
import type { IInteractionsService, IInteractionsServiceConfig } from '../definition'
|
|
4
|
+
import { coreInteractions } from './coreInteractions'
|
|
5
|
+
import { hasClickTriggerCss, wixInteractElementCss } from './stylesToAdd'
|
|
6
|
+
|
|
7
|
+
export const createInteractionsExternal = (
|
|
8
|
+
config: IInteractionsServiceConfig,
|
|
9
|
+
getService: ServicesManager['getService']
|
|
10
|
+
): IInteractionsService => {
|
|
11
|
+
const provideCssService = getService(ProvideCssDefinition)
|
|
12
|
+
|
|
13
|
+
const styles = [wixInteractElementCss, hasClickTriggerCss]
|
|
14
|
+
const cssToAdd = styles.join('\n')
|
|
15
|
+
|
|
16
|
+
provideCssService.addStyle(cssToAdd)
|
|
17
|
+
|
|
18
|
+
const { interactiveComps } = coreInteractions(config, getService)
|
|
19
|
+
|
|
20
|
+
const hasInteractions: IInteractionsService['hasInteractions'] = path => interactiveComps.has(path)
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
hasInteractions,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const getInteractionsScriptContent = (configId: string, isReducedMotion: boolean) => `
|
|
2
|
+
await import(\`https://static.parastorage.com/services/interact/dist/interact.umd.min.js\`);
|
|
3
|
+
|
|
4
|
+
const configElement = document.getElementById(\`${configId}\`);
|
|
5
|
+
if (configElement) {
|
|
6
|
+
const Interact = window.interact?.Interact;
|
|
7
|
+
if (!Interact) {
|
|
8
|
+
console.error(\`Interact library is not loaded\`);
|
|
9
|
+
} else {
|
|
10
|
+
const config = JSON.parse(decodeURIComponent(configElement.textContent));
|
|
11
|
+
|
|
12
|
+
Interact.forceReducedMotion = ${isReducedMotion};
|
|
13
|
+
Interact.setup({
|
|
14
|
+
scrollOptionsGetter: function(){ return document.getElementById(\`site-root\`) },
|
|
15
|
+
allowA11yTriggers: true,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
Interact.create(config);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { implementStaticService } from '@wix/static-service'
|
|
2
|
+
import type { StaticServiceFactoryOpts } from '@wix/static-service'
|
|
3
|
+
import type { IInteractionsServiceConfig } from '../definition'
|
|
4
|
+
import { InteractionsDefinition } from '../definition'
|
|
5
|
+
import { createInteractions } from './interactions'
|
|
6
|
+
import { createInteractionsExternal } from './interactionsExternal'
|
|
7
|
+
|
|
8
|
+
export const InteractionsService = implementStaticService(
|
|
9
|
+
InteractionsDefinition,
|
|
10
|
+
({ config, getService }: StaticServiceFactoryOpts<IInteractionsServiceConfig>) => {
|
|
11
|
+
return createInteractions(config, getService)
|
|
12
|
+
}
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
export const InteractionsServiceExternal = implementStaticService(
|
|
16
|
+
InteractionsDefinition,
|
|
17
|
+
({ config, getService }: StaticServiceFactoryOpts<IInteractionsServiceConfig>) => {
|
|
18
|
+
return createInteractionsExternal(config, getService)
|
|
19
|
+
}
|
|
20
|
+
)
|
package/src/index.ts
ADDED
package/src/service.ts
ADDED