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

feat: Migrate all attributes to lowercase ('smushedcase'). #537

Merged
merged 10 commits into from
Apr 18, 2023

Conversation

cjpillsbury
Copy link
Collaborator

@cjpillsbury cjpillsbury commented Apr 17, 2023

Migrates all well-defined attributes in Media Chrome elements from kebab-case to lowercase (aka "smushedcase").

@vercel
Copy link

vercel bot commented Apr 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
media-chrome ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2023 7:51pm
media-chrome-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2023 7:51pm

@@ -1,31 +1,16 @@
import type { NextPage } from 'next';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: Need to revert this. Hold over from presentation testing.

@@ -0,0 +1,200 @@
export * as constants from "./constants.js";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: Going to drop this in this PR, but this was the quick fix solution to get all of the TypeScript types in place for React. We should instead just completely revamp how the React wrappers work in our v1.0 effort.

@@ -129,14 +129,14 @@ class MediaChromeButton extends window.HTMLElement {
enable() {
this.addEventListener('click', this.#clickListener);
this.addEventListener('keydown', this.#keydownListener);
this.setAttribute('tabindex', '0');
this.tabIndex = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: Moving to using the tabIndex prop instead for forward-looking dreams.

* if gestures are disabled, don't accept pointer-events
*/ ''
}
:host(:not([${Attributes.AUDIO}])[${
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oof formatter really did a number on this one. Will unmangle.

Copy link
Contributor

Choose a reason for hiding this comment

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

can this be formatted similar to how it was?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yessir!

Copy link
Contributor

Choose a reason for hiding this comment

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

which formatter did this? yarn format?

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 was some default prettier line length creeping in? Haven't investigated.

}
:host([${Attributes.USER_INACTIVE}]:not([${
MediaUIAttributes.MEDIA_PAUSED
}]):not([${MediaUIAttributes.MEDIA_IS_CASTING}]):not([${
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same for this uggo.

Copy link
Contributor

Choose a reason for hiding this comment

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

yup

@@ -12,8 +19,8 @@ const ButtonPressedKeys = ['Enter', ' '];
const DEFAULT_TIMES_SEP = ' / ';

const formatTimesLabel = (el, { timesSep = DEFAULT_TIMES_SEP } = {}) => {
const showRemaining = el.getAttribute('remaining') != null;
const showDuration = el.getAttribute('show-duration') != null;
const showRemaining = el.showRemaining;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: This feels like scope creep for this round. Hoping for a gut check from others if you think I should drop it (still around in other branches).

@@ -102,7 +102,7 @@ template.innerHTML = /*html*/`
align-items: start;
}

:host([control-bar-place$="end"]) media-control-bar {
:host([controlbarplace$="end"]) media-control-bar {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: Should discuss - normalize so official attrs for official themes are also lowercase/"smushedcase" (See below for at least one particular friction point/tradeoff).

@@ -440,7 +440,7 @@ template.innerHTML = /*html*/`
</template>

<media-controller
style="--_control-bar-place-self:{{controlBarPlace ?? 'unset'}}"
style="--_control-bar-place-self:{{controlbarplace ?? 'unset'}}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: Because we use JS to translate attr -> prop, using all lowercase/"smushedcase" here doesn't allow us to use camelCase to translate (since there are no delimiters to match against with the new names).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We may want to treat this as a separate effort and descope it for this initial round of changes.

];
}

/** @type number[] | undefined */
#_rates;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we leave the underscore, use #rates instead?

don't really see a reason for an added underscore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup we can def drop the underscore. ❤️

/** @type boolean | undefined */
#_showDuration;
/** @type boolean | undefined */
#_remaining;
Copy link
Contributor

Choose a reason for hiding this comment

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

here too the underscores

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will either remove or rename before merging, depending on team decision here.

@@ -60,12 +63,22 @@ class MediaPlaybackRateButton extends MediaChromeButton {
super.attributeChangedCallback(attrName, oldValue, newValue);
}

get rates() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like scope-creep.
This getter should return a DOMTokenList, while the setter should accept an array.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool I agree let's just drop all of the property changes in this PR. @luwes when we re-add we'll be sure to account for your private variable naming convention prefs.

@codecov
Copy link

codecov bot commented Apr 17, 2023

Codecov Report

Merging #537 (c0ffeb6) into main (8671210) will decrease coverage by 0.03%.
The diff coverage is 77.47%.

@@            Coverage Diff             @@
##             main     #537      +/-   ##
==========================================
- Coverage   76.41%   76.38%   -0.03%     
==========================================
  Files          43       43              
  Lines        7056     7141      +85     
==========================================
+ Hits         5392     5455      +63     
- Misses       1664     1686      +22     
Impacted Files Coverage Δ
src/js/media-playback-rate-button.js 33.72% <40.00%> (-12.63%) ⬇️
src/js/media-seek-backward-button.js 52.22% <41.66%> (+2.22%) ⬆️
src/js/media-seek-forward-button.js 54.25% <46.15%> (+2.03%) ⬆️
src/js/controller.js 64.46% <50.00%> (ø)
src/js/media-poster-image.js 62.96% <60.00%> (+2.43%) ⬆️
src/js/media-container.js 80.19% <78.65%> (-0.35%) ⬇️
src/js/media-captions-button.js 53.48% <80.00%> (+1.87%) ⬆️
src/js/media-controller.js 75.07% <80.95%> (+0.37%) ⬆️
src/js/media-loading-indicator.js 89.24% <83.33%> (+0.27%) ⬆️
src/js/media-time-display.js 78.10% <85.18%> (+1.26%) ⬆️
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -25,7 +25,7 @@
"build:iife": "esbuild src/js/index.js --bundle --target=es2019 --format=iife --outdir=dist/iife --minify --sourcemap --global-name=MediaChrome && yarn size",
"build:react": "node ./scripts/react/build.js",
"build:manifest": "npx @custom-elements-manifest/analyzer analyze --config scripts/custom-elements-manifest.config.js",
"build": "yarn build:esm && yarn build:cjs && yarn build:iife && yarn build:react && yarn build:types && yarn build:manifest",
"build": "yarn build:types && yarn build:esm && yarn build:cjs && yarn build:iife && yarn build:react && yarn build:manifest",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NOTE: switch the order to ensure types are available before build (for dev watch behavior/expectations)

Copy link
Contributor

@luwes luwes left a comment

Choose a reason for hiding this comment

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

pre-approving, just need to fix the CSS formatting a little bit

Comment on lines +27 to +29
// NOTE: Adding for TypeScript Errors. Followup should add correct getter/setter & private var (CJP)
/** @type number[] | undefined */
_rates;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this used anywhere?

@@ -35,7 +40,7 @@ const setBackgroundImage = (el, image) => {

class MediaPosterImage extends window.HTMLElement {
static get observedAttributes() {
return ['placeholder-src', 'src'];
return [Attributes.PLACEHOLDER_SRC, Attributes.SRC];
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocker: alternative is to do Object.values(Attributes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

decided to not use values just because that's "incidental" and not "definitional" (aka all of the values in Attributes happen to be observedAttributes, but that could change and isn't inherent to their relationship).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. Worked here incidentally. Wasn't a blocker or necessary anyway.

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.

3 participants