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

added api page for CSSNestedDeclaration and the style peroperty and a… #36430

Conversation

dletorey
Copy link
Contributor

@dletorey dletorey commented Oct 21, 2024

Description

  • Added API page for CSSNestedDeclarations
  • Added property page for CSSNestedDeclarations.style
  • Added link from CSSOM page to CSSNestedDeclarations page
  • Added link from CSSRule page to CSSNestedDeclarations page
  • Added explanation of CSSNestedDeclarations on Using CSS Nesting

Motivation

Related issues and pull requests

…dded explanation of The Nested Declaration rule on the nesting page
@dletorey dletorey requested review from a team as code owners October 21, 2024 16:19
@dletorey dletorey requested review from sideshowbarker and bsmth and removed request for a team October 21, 2024 16:19
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs Content:WebAPI Web API docs labels Oct 21, 2024
@dletorey dletorey requested a review from dipikabh October 21, 2024 16:20
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Oct 21, 2024
@dletorey dletorey removed the request for review from sideshowbarker October 21, 2024 16:20
Copy link
Contributor

github-actions bot commented Oct 21, 2024

Preview URLs

Flaws (2)

Note! 4 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/API/CSS_Object_Model
Title: CSS Object Model (CSSOM)
Flaw count: 2

  • macros:
    • /en-US/docs/Web/API/CSSFontFeatureValuesMap does not exist
    • /en-US/docs/Web/API/CSSMarginRule does not exist
External URLs (1)

URL: /en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting
Title: Using CSS nesting

(comment last updated: 2024-11-11 16:00:38)

@dipikabh
Copy link
Contributor

Hi Hamish, could you review this PR?

@dipikabh dipikabh requested a review from hamishwillee October 25, 2024 16:42
With `CSSNestedDeclarations` the CSS is is parsed correctly.

```js
let myRules = document.styleSheets[0].cssRules;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above, this really doesn't tell me anything because I don't see what the types are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

See my response #36430 (comment)

What do you think a reader can learn from this? I don't particularly might what you show, but it has to show something related to the API we are demonstrating, and really this does not.

If I had to do this I would either have a live example that shows the structure, or add pseudo code. Assuming the second, then something like.


Consider the following

.foo {
  background-color: silver;
  @media (screen) {
    color: tomato;
  }
  color: black;
}

This would be parsed into a structure similar to the one shown below. Note that blah blah.

[Note, that I am not sure this is correct - I just copied it from your original. Probably it isn't - ie. I don't think the last declaration is nested]

↳ CSSStyleRule
  .style
    - background-color: silver
  ↳ CSSMediaRule
    ↳ CSSNestedDeclarations
      .style (CSSStyleDeclaration, 1) =
      - color: tomato
  ↳ CSSNestedDeclarations
    .style (CSSStyleDeclaration, 1) =
      - color: black

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is, as this is how the order of the rules are retained.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think a reader can learn from this? I don't particularly might what you show, but it has to show something related to the API we are demonstrating, and really this does not.

Still not answered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I would do here is write code that creates this structure. I'd do it for you but your repo is locked for edits. So something like:


This example shows how to construct the following stylesheet using the CSSDOM API.

.foo {
  background-color: silver;
  @media (screen) {
    color: tomato;
  }
  color: black;
}

[Insert the code here]

Note that in order to preserve the parsing order, all the rules before nesting are handled as top-level CSSRules, while any top level rules after nesting are represented as CSSNestedDeclarations.
That's why the color-black is inside a nested declaration even though it is a top level declaration in the original document.


Note that point at the end that you gave me in the other note - this is relevant to usage of this API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure that this is correct, either.
The CSSNestedDeclarations API only returns that the there is an object of type CSSNestedDeclarations which in turn are cssRules with styles
https://codepen.io/CodeRedDigital/pen/vYozyrG?editors=0112

Although I believe I has managed to explain this better now

↳ CSSNestedDeclarations
.style (CSSStyleDeclaration, 1) =
- color: tomato
↳ CSSNestedDeclarations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this nested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment
All the rules before nesting or at-properties are added at the top-level CSSRules anything after nesting or at-properties are added as nested declarations as that is how the order is preserved. Before CSSNestedDeclarations rules at the same level were hoisted up to the top with other rules whcih changed the order and effected the cascade.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's really useful thanks! Reading that I think it is more before and after nesting, and the at-rules is just a form of nesting right?

Anyway, if I can have this misunderstanding others can, so I have added proposals https://github.com/mdn/content/pull/36430/files#r1828495475 , https://github.com/mdn/content/pull/36430/files#r1828504825, #36430 (comment)

@dipikabh dipikabh removed their request for review November 4, 2024 13:12
@dletorey dletorey requested a review from hamishwillee November 5, 2024 15:30
Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

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

Thanks very much @dletorey ! All done.

@hamishwillee hamishwillee merged commit 5e3cb7c into mdn:main Nov 12, 2024
8 checks passed
@dletorey dletorey deleted the 36115-Implement-the-nested-declarations-rule branch November 12, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants