Skip to content

Splittext integration#260

Open
ameerf-wix wants to merge 4 commits into
masterfrom
splittext_integration
Open

Splittext integration#260
ameerf-wix wants to merge 4 commits into
masterfrom
splittext_integration

Conversation

@ameerf-wix

Copy link
Copy Markdown
Contributor

Description

Related Issue

Checklist

  • I have read the Contributing Guide
  • I have added/updated tests for my changes (if applicable)
  • I have updated documentation/rules/skills (if applicable)

Screenshots / Demos

Additional Notes

@ydaniv ydaniv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole idea of pluggable resolvers, or plugins, is that the core is not aware of them and doesn't implement anything specific to them.
It should only iterate registered plugins on init or maybe on add, and then apply the plugins' transformers on the DOM.

// split the heading into characters on connect …
splitText: { container: '.headline', type: 'chars', hide: true },
// … then stagger an entrance across the generated spans
effects: [{ key: 'hero', selector: '.split-c', effectId: 'fade-in' }],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
effects: [{ key: 'hero', selector: '.split-c', effectId: 'fade-in' }],
sequences: [{
offset: 80,
effects: [{ selector: '.split-c', effectId: 'fade-in' }],
},

```

`hide: true` opts into the FOUC guard: the container is hidden (via the
`data-text-split` attribute + a generated CSS rule) until splitting completes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`data-text-split` attribute + a generated CSS rule) until splitting completes.
`data-split-text` attribute + a generated CSS rule) until splitting completes.


## Use with @wix/interact

The `@wix/splittext/interact` entry point exposes a resolver that lets you wire

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it should say an "Interact plugin"? "resolver" is somewhat technical.

*/
export const splitTextResolver: SplitTextResolver = {
resolve(root, config, context) {
const container = root.querySelector(config.container) as HTMLElement | null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allow querySelectorAll()? Almost all other selectors do. Is there a problem allowing that?

Comment on lines +45 to +50
type: config.type,
wrapperClass: config.wrapperClass,
wrapperStyle: config.wrapperStyle as Partial<CSSStyleDeclaration> | undefined,
wrapperAttrs: config.wrapperAttrs,
autoSplit: config.autoSplit,
aria: config.aria,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply:

Suggested change
type: config.type,
wrapperClass: config.wrapperClass,
wrapperStyle: config.wrapperStyle as Partial<CSSStyleDeclaration> | undefined,
wrapperAttrs: config.wrapperAttrs,
autoSplit: config.autoSplit,
aria: config.aria,
...config,

?

import { getInterpolatedKey } from './utilities';
import { effectToAnimationOptions } from '../handlers/utilities';
import { Interact, getSelector } from './Interact';
import { applySplitText } from './splitText';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the core should be agnostic to specific plugins.

* are intentionally NOT cleared by `Interact.destroy()`, mirroring how
* `registerEffects` registrations persist across configs.
*/
private static resolvers = new Map<string, unknown>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static resolvers = new Map<string, unknown>();
private static plugins = new Map<string, unknown>();

?

effects: {},
sequences: {},
conditions: {},
splitText: {},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core should not be aware of the plugins. It could be extended dynamically with the keys of resolvers (or plugins if we prefer)


function parseConfig(config: InteractConfig, useCustomElement: boolean = false): InteractCache {
const { effects: effectMap = {}, sequences: sequenceMap = {}, conditions = {} } = config;
const {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsing should take care of also parsing registered plugins.

this.listInteractionsCache = {};
this.controllers.clear();
this.dataCache = { effects: {}, sequences: {}, conditions: {}, interactions: {} };
this.dataCache = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably inside init() after parsing we want to check plugins and apply them. But there should be a generic logic that does that, nothing specific to splitText.

@ydaniv ydaniv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could revisit the plan first, correct all the issues found below inside the plan, review again, and then we could re-implement from scratch on the corrected plan, because it took a direction that is completely off course.


---

## 6. Split execution hook — `src/core/add.ts`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is where it got it wrong


---

## 7. New module — `src/core/splitText.ts`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is also in the wrong direction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants