Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add local test file and support html parsing #8

Merged
merged 4 commits into from Mar 8, 2022
Merged

Conversation

spencerc99
Copy link
Collaborator

@spencerc99 spencerc99 commented Mar 5, 2022

Add textMode parameter which has text as the default param and uses normal behavior and offers html for custom HTML to give control to the end-user on how to render things and interact.

Also added a local-test.html file for local testing that is set up to pull from the locally built lib. Imagining we can add a list of both examples and test cases for new functionality there

Screen.Recording.2022-03-05.at.1.36.12.PM.mov

}

const DefaultConfig: Config = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i moved these into individual defaults because otherwise you wouldn't get the proper default if you passed in a partial config

src/index.ts Outdated
}

case TextMode.Html:
const newNode = document.createElement("span");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

by default wrapped this in a span 🤷 I guess could be an additional customization to specify what the default wrapping element is too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's a bit weird to enforce a wrapping element in the input which is why I added this in the first place (i.e. i want to pass in - hello <b>with bold</b> rather than having to do - <span> I'm wrapping my text in a span </span>

Copy link
Owner

Choose a reason for hiding this comment

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

wish we had fragments in regular HTML 😔 looks like span can only have these as children: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content

this seems comprehensive enough for now? thoughts on adding an HTML class to this span so people can style it?

Copy link
Collaborator Author

@spencerc99 spencerc99 Mar 8, 2022

Choose a reason for hiding this comment

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

yeah it's not ideal :( I think ideally we'd try to interpret it as HTML and then fall back to a default element (that defaults to span but could be configured) if not present (so then you could put whatever you wanted as the wrapper) but i wasn't sure how to do that optimistic determinatio well.

re: class hmm i think we should avoid adding new classes as much as possible and have them style via targeted styling i.e. #telescope span...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i can update with being able to specify a default element tag

@@ -105,30 +151,22 @@ function _hydrate(line: Content, node: any, shouldExpandOnMouseOver: boolean = f
}
} else {
// otherwise, this is a leaf node
if (lineText.includes("@Q ")) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this got moved up into the helper function. Side effect here is that it doesn't just act on leaf nodes anymore

lib/index.d.ts Outdated
}
declare const DefaultConfig: Config;
declare type CreateTelescopicTextConfig = Pick<Config, "shouldExpandOnMouseOver" | "textMode">;
Copy link
Owner

Choose a reason for hiding this comment

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

Pick<T> is so big brain here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🧠 🧠

README.md Outdated Show resolved Hide resolved
src/index.ts Outdated
}

case TextMode.Html:
const newNode = document.createElement("span");
Copy link
Owner

Choose a reason for hiding this comment

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

wish we had fragments in regular HTML 😔 looks like span can only have these as children: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content

this seems comprehensive enough for now? thoughts on adding an HTML class to this span so people can style it?

`
const config = { textMode: TextMode.Html };
const poemContent = createTelescopicTextFromBulletedList(content, config);
```

Copy link
Owner

Choose a reason for hiding this comment

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

might be good to have a disclaimer somewhere about potential dangers of using TextMode.Html as it does a .innerHTML under the hood

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yeah sure i can add in the readme / docs. Theoretically should be fine unless you're using someone elses code haha

spencerc99 and others added 2 commits March 7, 2022 16:56
Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
@spencerc99
Copy link
Collaborator Author

@jackyzha0 updated!

@jackyzha0
Copy link
Owner

🔥

@jackyzha0 jackyzha0 merged commit 87e9cc8 into main Mar 8, 2022
@jackyzha0 jackyzha0 deleted the support-html branch March 8, 2022 02:20
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.

None yet

2 participants