@wix/site-service-interactions 1.0.13 → 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.js.map +1 -1
- package/cjs/build/implementations/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/configEntries.js +4 -6
- package/cjs/build/implementations/configEntries.js.map +1 -1
- package/cjs/build/implementations/coreInteractions.js +1 -1
- 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.js.map +1 -1
- package/cjs/build/implementations/reviveScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/cjs/build/implementations/v2/authoredStyles.js +6 -11
- package/cjs/build/implementations/v2/authoredStyles.js.map +1 -1
- package/cjs/build/implementations/v2/cdnUrls.js.map +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.js.map +1 -1
- package/cjs/build/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/cjs/build/implementations/v2/interactionsScriptContent.js +2 -2
- package/cjs/build/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/cjs/build/implementations/v2/motionPresets.js +1 -1
- package/cjs/build/implementations/v2/motionPresets.js.map +1 -1
- package/cjs/package.json +1 -1
- package/definition/package.json +1 -1
- package/dist/definition/index.js.map +1 -1
- package/dist/implementations/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/configEntries.js +4 -6
- package/dist/implementations/configEntries.js.map +1 -1
- package/dist/implementations/coreInteractions.js +1 -1
- 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.js.map +1 -1
- package/dist/implementations/reviveScriptElement.js.map +1 -1
- package/dist/implementations/v2/InteractionsScriptElement.js.map +1 -1
- package/dist/implementations/v2/authoredStyles.js +6 -11
- package/dist/implementations/v2/authoredStyles.js.map +1 -1
- package/dist/implementations/v2/cdnUrls.js.map +1 -1
- package/dist/implementations/v2/clickTriggerCss.js +1 -1
- package/dist/implementations/v2/clickTriggerCss.js.map +1 -1
- package/dist/implementations/v2/configCss.js.map +1 -1
- package/dist/implementations/v2/configStyleHeadContent.js.map +1 -1
- package/dist/implementations/v2/interactionsScriptContent.js +2 -2
- package/dist/implementations/v2/interactionsScriptContent.js.map +1 -1
- package/dist/implementations/v2/motionPresets.js +1 -1
- package/dist/implementations/v2/motionPresets.js.map +1 -1
- package/implementations/package.json +1 -1
- package/package.json +22 -22
- package/src/definition/index.ts +11 -11
- package/src/implementations/InteractionsScriptElement.tsx +16 -16
- package/src/implementations/configEntries.ts +61 -63
- package/src/implementations/coreInteractions.ts +86 -86
- 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 +21 -26
- package/src/implementations/v2/authoredStyles.ts +74 -79
- package/src/implementations/v2/cdnUrls.ts +1 -1
- package/src/implementations/v2/clickTriggerCss.ts +25 -25
- package/src/implementations/v2/configCss.ts +3 -3
- package/src/implementations/v2/configStyleHeadContent.ts +3 -3
- package/src/implementations/v2/interactionsScriptContent.ts +31 -31
- package/src/implementations/v2/motionPresets.ts +27 -27
- package/types/package.json +1 -1
|
@@ -7,9 +7,9 @@ const STYLE_END_TAG = /<\/style(?=[\t\n\f\r />])/i
|
|
|
7
7
|
const SCRIPT_LIKE = /<script/gi
|
|
8
8
|
|
|
9
9
|
const sanitizeCssForStyleElement = (css: string): string => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const styleEndTagIndex = css.search(STYLE_END_TAG)
|
|
11
|
+
const withoutStyleBreakout = styleEndTagIndex === -1 ? css : css.slice(0, styleEndTagIndex)
|
|
12
|
+
return withoutStyleBreakout.replace(SCRIPT_LIKE, '\\3c script')
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const getV2ConfigStyleHeadContent = (css: string): string => `<style>${sanitizeCssForStyleElement(css)}</style>`
|
|
@@ -11,36 +11,36 @@ const MODULE_IMPORT_URLS = [INTERACT_V2_IMPORT_URL, LEGACY_WIX_MOTION_PRESETS_IM
|
|
|
11
11
|
* would download each module twice.
|
|
12
12
|
*/
|
|
13
13
|
export const getV2ModulePreloadHeadContent = (): string =>
|
|
14
|
-
|
|
14
|
+
MODULE_IMPORT_URLS.map((url) => `<link rel="modulepreload" href="${url}">`).join('')
|
|
15
15
|
|
|
16
16
|
export const getV2InteractionsScriptContent = (configId: string, isReducedMotion: boolean): string =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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')
|
|
@@ -3,9 +3,9 @@ import * as allPresets from '@wix/motion-presets'
|
|
|
3
3
|
import type { Effect, EffectRef, InteractConfig } from '@wix/interact-v2'
|
|
4
4
|
|
|
5
5
|
type EffectModule = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
web: unknown
|
|
7
|
+
style?: unknown
|
|
8
|
+
getNames: unknown
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type NamedEffect = { type: string } & Record<string, unknown>
|
|
@@ -13,48 +13,48 @@ type NamedEffect = { type: string } & Record<string, unknown>
|
|
|
13
13
|
export const LEGACY_PREFIX = 'LEGACY_'
|
|
14
14
|
|
|
15
15
|
const isEffectModule = (value: unknown): value is EffectModule =>
|
|
16
|
-
|
|
16
|
+
typeof value === 'object' && value !== null && 'web' in value && 'getNames' in value
|
|
17
17
|
|
|
18
18
|
const getPresetModules = (namespace: object, prefix: string = ''): Record<string, EffectModule> =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
Object.fromEntries(
|
|
20
|
+
Object.entries(namespace)
|
|
21
|
+
.filter(([, value]) => isEffectModule(value))
|
|
22
|
+
.map(([name, value]) => [`${prefix}${name}`, value as EffectModule])
|
|
23
|
+
)
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Both preset packages under one registry, mirroring what the client loader registers. The legacy
|
|
27
27
|
* names carry the prefix so a preset published by both packages doesn't shadow its counterpart.
|
|
28
28
|
*/
|
|
29
29
|
export const motionPresets: Record<string, EffectModule> = {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
...getPresetModules(allPresets),
|
|
31
|
+
...getPresetModules(allLegacyPresets, LEGACY_PREFIX),
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const aliasEffect = <T extends object>(effect: T): T => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
40
|
}
|
|
41
41
|
|
|
42
42
|
const aliasSequence = <T extends object>(sequence: T): T => {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const { effects } = sequence as { effects?: (Effect | EffectRef)[] }
|
|
44
|
+
return effects ? { ...sequence, effects: effects.map(aliasEffect) } : sequence
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const mapRecord = <T>(record: Record<string, T>, map: (value: T) => T): Record<string, T> =>
|
|
48
|
-
|
|
48
|
+
Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]))
|
|
49
49
|
|
|
50
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
51
|
export const aliasLegacyNamedEffects = (interact: InteractConfig): InteractConfig => ({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
60
|
})
|
package/types/package.json
CHANGED