@wix/site-service-interactions 1.0.12 → 1.0.14
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/cjs/build/definition/index.d.ts +19 -3
- package/cjs/build/definition/index.js.map +1 -1
- package/cjs/build/implementations/InteractionsScriptElement.d.ts +1 -1
- package/cjs/build/implementations/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/configEntries.d.ts +13 -0
- package/cjs/build/implementations/configEntries.js +78 -0
- package/cjs/build/implementations/configEntries.js.map +1 -0
- package/cjs/build/implementations/coreInteractions.d.ts +2 -2
- package/cjs/build/implementations/coreInteractions.js +50 -23
- package/cjs/build/implementations/coreInteractions.js.map +1 -1
- package/cjs/build/implementations/interactions.js +1 -1
- package/cjs/build/implementations/interactions.js.map +1 -1
- package/cjs/build/implementations/interactionsExternal.js +1 -1
- package/cjs/build/implementations/interactionsExternal.js.map +1 -1
- package/cjs/build/implementations/interactionsService.d.ts +5 -4
- package/cjs/build/implementations/interactionsService.js.map +1 -1
- package/cjs/build/implementations/reviveScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/InteractionsScriptElement.d.ts +2 -2
- package/cjs/build/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/authoredStyles.d.ts +2 -0
- package/cjs/build/implementations/v2/authoredStyles.js +90 -0
- package/cjs/build/implementations/v2/authoredStyles.js.map +1 -0
- package/cjs/build/implementations/v2/cdnUrls.d.ts +2 -1
- package/cjs/build/implementations/v2/cdnUrls.js +3 -2
- package/cjs/build/implementations/v2/cdnUrls.js.map +1 -1
- package/cjs/build/implementations/v2/clickTriggerCss.d.ts +1 -1
- package/cjs/build/implementations/v2/clickTriggerCss.js +1 -1
- package/cjs/build/implementations/v2/clickTriggerCss.js.map +1 -1
- package/cjs/build/implementations/v2/configCss.d.ts +1 -1
- package/cjs/build/implementations/v2/configCss.js +3 -36
- package/cjs/build/implementations/v2/configCss.js.map +1 -1
- package/cjs/build/implementations/v2/configStyleHeadContent.js +8 -6
- package/cjs/build/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/cjs/build/implementations/v2/interactionsScriptContent.js +18 -7
- package/cjs/build/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/cjs/build/implementations/v2/motionPresets.d.ts +14 -0
- package/cjs/build/implementations/v2/motionPresets.js +76 -0
- package/cjs/build/implementations/v2/motionPresets.js.map +1 -0
- package/cjs/build/service.d.ts +1 -1
- package/cjs/build/types/index.d.ts +1 -1
- package/cjs/package.json +1 -1
- package/definition/package.json +1 -1
- package/dist/definition/index.d.ts +19 -3
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/InteractionsScriptElement.d.ts +1 -1
- package/dist/implementations/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/configEntries.d.ts +13 -0
- package/dist/implementations/configEntries.js +71 -0
- package/dist/implementations/configEntries.js.map +1 -0
- package/dist/implementations/coreInteractions.d.ts +2 -2
- package/dist/implementations/coreInteractions.js +50 -23
- package/dist/implementations/coreInteractions.js.map +1 -1
- package/dist/implementations/interactions.js +1 -1
- package/dist/implementations/interactions.js.map +1 -1
- package/dist/implementations/interactionsExternal.js +1 -1
- package/dist/implementations/interactionsExternal.js.map +1 -1
- package/dist/implementations/interactionsService.d.ts +5 -4
- package/dist/implementations/interactionsService.js.map +1 -1
- package/dist/implementations/reviveScriptElement.js.map +1 -1
- package/dist/implementations/v2/InteractionsScriptElement.d.ts +2 -2
- package/dist/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/v2/authoredStyles.d.ts +2 -0
- package/dist/implementations/v2/authoredStyles.js +86 -0
- package/dist/implementations/v2/authoredStyles.js.map +1 -0
- package/dist/implementations/v2/cdnUrls.d.ts +2 -1
- package/dist/implementations/v2/cdnUrls.js +2 -1
- package/dist/implementations/v2/cdnUrls.js.map +1 -1
- package/dist/implementations/v2/clickTriggerCss.d.ts +1 -1
- package/dist/implementations/v2/clickTriggerCss.js +1 -1
- package/dist/implementations/v2/clickTriggerCss.js.map +1 -1
- package/dist/implementations/v2/configCss.d.ts +1 -1
- package/dist/implementations/v2/configCss.js +2 -2
- package/dist/implementations/v2/configCss.js.map +1 -1
- package/dist/implementations/v2/configStyleHeadContent.js +8 -6
- package/dist/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/dist/implementations/v2/interactionsScriptContent.js +19 -8
- package/dist/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/dist/implementations/v2/motionPresets.d.ts +14 -0
- package/dist/implementations/v2/motionPresets.js +39 -0
- package/dist/implementations/v2/motionPresets.js.map +1 -0
- package/dist/service.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/implementations/package.json +1 -1
- package/package.json +24 -23
- package/src/definition/index.ts +21 -4
- package/src/implementations/InteractionsScriptElement.tsx +17 -17
- package/src/implementations/configEntries.ts +103 -0
- package/src/implementations/coreInteractions.ts +102 -68
- package/src/implementations/interactions.ts +8 -8
- package/src/implementations/interactionsExternal.ts +11 -11
- package/src/implementations/interactionsService.ts +8 -8
- package/src/implementations/reviveScriptElement.ts +8 -8
- package/src/implementations/v2/InteractionsScriptElement.tsx +23 -28
- package/src/implementations/v2/authoredStyles.ts +103 -0
- package/src/implementations/v2/cdnUrls.ts +4 -1
- package/src/implementations/v2/clickTriggerCss.ts +26 -26
- package/src/implementations/v2/configCss.ts +6 -7
- package/src/implementations/v2/configStyleHeadContent.ts +9 -6
- package/src/implementations/v2/interactionsScriptContent.ts +36 -24
- package/src/implementations/v2/motionPresets.ts +60 -0
- package/src/types/index.ts +1 -1
- package/types/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { INTERACT_V2_IMPORT_URL,
|
|
1
|
+
import { INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IMPORT_URL, MOTION_PRESETS_IMPORT_URL } from './cdnUrls'
|
|
2
|
+
import { LEGACY_PREFIX } from './motionPresets'
|
|
3
|
+
|
|
4
|
+
/** The loader destructures `Promise.all` in this order. */
|
|
5
|
+
const MODULE_IMPORT_URLS = [INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IMPORT_URL, MOTION_PRESETS_IMPORT_URL]
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* The loader reaches these modules through dynamic `import()`, which the preload scanner cannot
|
|
@@ -7,28 +11,36 @@ import { INTERACT_V2_IMPORT_URL, WIX_MOTION_PRESETS_IMPORT_URL } from './cdnUrls
|
|
|
7
11
|
* would download each module twice.
|
|
8
12
|
*/
|
|
9
13
|
export const getV2ModulePreloadHeadContent = (): string =>
|
|
10
|
-
|
|
14
|
+
MODULE_IMPORT_URLS.map((url) => `<link rel="modulepreload" href="${url}">`).join('')
|
|
11
15
|
|
|
12
16
|
export const getV2InteractionsScriptContent = (configId: string, isReducedMotion: boolean): string =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
[
|
|
18
|
+
`const configElement = document.getElementById(\`${configId}\`)`,
|
|
19
|
+
'if (configElement) {',
|
|
20
|
+
' const parsedConfig = JSON.parse(configElement.textContent)',
|
|
21
|
+
' const configs = Array.isArray(parsedConfig) ? parsedConfig : [parsedConfig]',
|
|
22
|
+
' const [{ Interact }, legacyPresets, presets] = await Promise.all([',
|
|
23
|
+
...MODULE_IMPORT_URLS.map((url) => ` import(\`${url}\`),`),
|
|
24
|
+
' ])',
|
|
25
|
+
// Reactions configs carry the prefix on their named effect types, so the two packages can
|
|
26
|
+
// both export a preset under the same name without one shadowing the other.
|
|
27
|
+
' const aliasedLegacyPresets = {}',
|
|
28
|
+
' for (const name of Object.keys(legacyPresets)) {',
|
|
29
|
+
` aliasedLegacyPresets[\`${LEGACY_PREFIX}\` + name] = legacyPresets[name]`,
|
|
30
|
+
' }',
|
|
31
|
+
' Interact.registerEffects({ ...presets, ...aliasedLegacyPresets })',
|
|
32
|
+
` Interact.forceReducedMotion = ${isReducedMotion}`,
|
|
33
|
+
' Interact.setup({',
|
|
34
|
+
' scrollOptionsGetter: function () {',
|
|
35
|
+
' return document.getElementById(`site-root`)',
|
|
36
|
+
' },',
|
|
37
|
+
' allowA11yTriggers: true,',
|
|
38
|
+
' viewEnter: {',
|
|
39
|
+
' useSafeViewEnter: true,',
|
|
40
|
+
' },',
|
|
41
|
+
' })',
|
|
42
|
+
' for (const config of configs) {',
|
|
43
|
+
' Interact.create(config)',
|
|
44
|
+
' }',
|
|
45
|
+
'}',
|
|
46
|
+
].join('\n')
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as allLegacyPresets from '@wix/wix-motion-presets'
|
|
2
|
+
import * as allPresets from '@wix/motion-presets'
|
|
3
|
+
import type { Effect, EffectRef, InteractConfig } from '@wix/interact-v2'
|
|
4
|
+
|
|
5
|
+
type EffectModule = {
|
|
6
|
+
web: unknown
|
|
7
|
+
style?: unknown
|
|
8
|
+
getNames: unknown
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type NamedEffect = { type: string } & Record<string, unknown>
|
|
12
|
+
|
|
13
|
+
export const LEGACY_PREFIX = 'LEGACY_'
|
|
14
|
+
|
|
15
|
+
const isEffectModule = (value: unknown): value is EffectModule =>
|
|
16
|
+
typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value
|
|
17
|
+
|
|
18
|
+
const getPresetModules = (namespace: object, prefix: string = ''): Record<string, EffectModule> =>
|
|
19
|
+
Object.fromEntries(
|
|
20
|
+
Object.entries(namespace)
|
|
21
|
+
.filter(([, value]) => isEffectModule(value))
|
|
22
|
+
.map(([name, value]) => [`${prefix}${name}`, value as EffectModule])
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Both preset packages under one registry, mirroring what the client loader registers. The legacy
|
|
27
|
+
* names carry the prefix so a preset published by both packages doesn't shadow its counterpart.
|
|
28
|
+
*/
|
|
29
|
+
export const motionPresets: Record<string, EffectModule> = {
|
|
30
|
+
...getPresetModules(allPresets),
|
|
31
|
+
...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const aliasEffect = <T extends object>(effect: T): T => {
|
|
35
|
+
const { namedEffect } = effect as { namedEffect?: NamedEffect }
|
|
36
|
+
if (!namedEffect?.type) {
|
|
37
|
+
return effect
|
|
38
|
+
}
|
|
39
|
+
return { ...effect, namedEffect: { ...namedEffect, type: `${LEGACY_PREFIX}${namedEffect.type}` } }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const aliasSequence = <T extends object>(sequence: T): T => {
|
|
43
|
+
const { effects } = sequence as { effects?: (Effect | EffectRef)[] }
|
|
44
|
+
return effects ? { ...sequence, effects: effects.map(aliasEffect) } : sequence
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const mapRecord = <T>(record: Record<string, T>, map: (value: T) => T): Record<string, T> =>
|
|
48
|
+
Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]))
|
|
49
|
+
|
|
50
|
+
// TODO(ameerf): make this implementation simpler without so many copies of the config object. The current implementation is a direct translation of the v1 code, which was written to avoid mutating the config object.
|
|
51
|
+
export const aliasLegacyNamedEffects = (interact: InteractConfig): InteractConfig => ({
|
|
52
|
+
...interact,
|
|
53
|
+
...(interact.effects && { effects: mapRecord(interact.effects, aliasEffect) }),
|
|
54
|
+
...(interact.sequences && { sequences: mapRecord(interact.sequences, aliasSequence) }),
|
|
55
|
+
interactions: interact.interactions.map((interaction) => ({
|
|
56
|
+
...interaction,
|
|
57
|
+
...(interaction.effects && { effects: interaction.effects.map(aliasEffect) }),
|
|
58
|
+
...(interaction.sequences && { sequences: interaction.sequences.map(aliasSequence) }),
|
|
59
|
+
})),
|
|
60
|
+
})
|
package/src/types/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { IInteractionsService, IInteractionsServiceConfig, IInteractionsDefinition } from '../definition'
|
|
2
|
-
export type { InteractConfig } from '@wix/interact'
|
|
2
|
+
export type { InteractConfig } from '@wix/interact-v2'
|
package/types/package.json
CHANGED