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
Typescript: Convert story editor utils #12737
Conversation
# Conflicts: # packages/story-editor/src/utils/getSessionStorageKey.ts # packages/story-editor/src/utils/useRefreshPostEditURL.ts # packages/story-editor/tsconfig.json
Plugin builds for 6fd2808 are ready 🛎️!
|
Size Change: +121 B (0%) Total Size: 2.71 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and sorely needed in many tickets. 🧨
@@ -23,15 +23,20 @@ import { useRef, useCallback } from '@googleforcreators/react'; | |||
*/ | |||
import { requestIdleCallback, cancelIdleCallback } from './idleCallback'; | |||
|
|||
interface Task { | |||
taskId: string | null; | |||
task: number | null | (() => Promise<void>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can task be a number? What would that be used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it changes from a promise to idleCallbackId
, which is an int. That int is then passed to clearQueuedTask
which expects an int.
Really hard to follow, I know, took me a while to understand.
if (activeElement) { | ||
const { tagName, type, contentEditable } = activeElement as | ||
| HTMLInputElement | ||
| HTMLAnchorElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why anchor elements? contentEditable
can be applied to any element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommended by @miina
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacedmonkey The idea was that previously you had created a custom interface to support tagName, type, contentEditable
, however, I mentioned there are existing default types already. I did not look into it thoroughly though, so there might be some missing.
@barklund I don't think that contentEditable
and type
both exists on Element
/ HTMLElement
so this needs more precision. In this particular case, we are trying to detect if native copy-paste should take over or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typing is hard here. It can be multiple types, that is valid. Not all types have the same props, some have contentEditable and other have type. Not sure what to do here other than what as been done. Maybe a custom type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from the few open suggestions that need resolving
Co-authored-by: Morten Barklund <morten.barklund@xwp.co>
Context
Summary
Covert the simple utils in story editor to use type script.
Relevant Technical Choices
The following files were not converted, for these reasons.
To-do
User-facing changes
Testing Instructions
This PR can be tested by following these steps:
Reviews
Does this PR have a security-related impact?
Does this PR change what data or activity we track or use?
Does this PR have a legal-related impact?
Checklist
Type: XYZ
label to the PRFixes #12740