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

[SuperEditor] Add list item customization via stylesheet (Resolves #1912) #2017

Merged
merged 3 commits into from
May 22, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor] Add list item customization via stylesheet. Resolves #1912

This PR adds the ability to customize list items using stylesheets.

Customization for unordered list items:

  • Dot size
  • Dot shape
  • Dot color

Customization for ordered list items:

  • Numeral style, which can be:
    • Arabic (the default)
    • Lowercase roman numbers
    • Uppercase roman numbers
    • Lowercase alpha
    • Uppercase alpha

For roman numbers, we support until 3999 and them switch to arabic. I tried the w3 playground in https://www.w3schools.com/css/tryit.asp?filename=trycss_list-style-type_ex and it seems that html lists also work like that.

CSS list style references: https://www.w3schools.com/css/css_list.asp

super_editor/lib/src/default_editor/list_items.dart Outdated Show resolved Hide resolved
@@ -189,6 +194,10 @@ class ListItemComponentViewModel extends SingleColumnLayoutComponentViewModel wi
required this.type,
this.ordinalValue,
required this.indent,
this.dotColor,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm noticing that these properties are the first situation where this view model doesn't apply equally to both types of list items. Looks like we should split this view model into two - one for ordered list items and one for unordered list items.

It might make sense to create a shared superclass that has everything but those dot and numeral styles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

super_editor/lib/src/default_editor/list_items.dart Outdated Show resolved Hide resolved
if (node.type == ListItemType.unordered) {
return UnorderedListItemComponentViewModel(
nodeId: node.id,
indent: node.indent,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be initializing these with default dot and numeral choices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The constructor already have default values for that, so I think we could omit them.

@@ -385,6 +534,10 @@ Widget _defaultUnorderedListItemDotBuilder(BuildContext context, UnorderedListIt
final attributions = component.text.getAllAttributionsAt(0).toSet();
final textStyle = component.styleBuilder(attributions);

final dotColor = component.dotStyle?.color ?? textStyle.color;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason that these values aren't set inline within the widget tree? Do we need variables for them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For the dot size I think it makes sense because we need access both width and height. I removed the others.

super_editor/lib/src/default_editor/list_items.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

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

LGTM

@matthew-carroll matthew-carroll merged commit 77d5177 into main May 22, 2024
8 of 11 checks passed
@matthew-carroll matthew-carroll deleted the 1912_list-marker-customization branch May 22, 2024 03:54
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.

[SuperEditor] Expose dot size and color for unordered lists
2 participants