nice-select2 icon indicating copy to clipboard operation
nice-select2 copied to clipboard

update dependencies, fix sass build deprated warnings, upgrade to mod…

Open mohammadbaghaei opened this issue 10 months ago • 5 comments

…ern javascript and sass syntax, optimize bundle size and overall performance

Summary by Sourcery

Update project dependencies, fix deprecated SASS build warnings, and upgrade to modern JavaScript and SASS syntax. Optimize for bundle size and overall performance.

New Features:

  • Add support for extra content in dropdown items using the data-extra attribute.
  • Implement placeholder, search text, and selected text customization through attributes or configuration options.

Enhancements:

  • Refactor event triggering logic in nice-select2.js for better code organization and maintainability.
  • Improve the NiceSelect class by adding input validation, default options for placeholder, search text, and selected text.
  • Add a new update method to the NiceSelect class to refresh the dropdown when the original select element changes.
  • Add new methods setValue, getValue, updateSelectValue, and resetSelectValue to provide better control over select element values.
  • Implement a search feature within the dropdown with enhanced keyboard navigation.

Tests:

  • Add tests for new features and methods.

mohammadbaghaei avatar Feb 05 '25 04:02 mohammadbaghaei

Reviewer's Guide by Sourcery

This pull request updates the Nice Select 2 library to use modern JavaScript syntax, improves performance, and adds new features. The changes include refactoring the event triggering logic, adding new options, and updating dependencies.

Sequence diagram for the new event handling system

sequenceDiagram
    participant User
    participant NiceSelect
    participant EventSystem
    participant DOM

    User->>NiceSelect: Interact with dropdown
    NiceSelect->>EventSystem: triggerEvent(element, type, init)
    Note over EventSystem: Unified event handling
    EventSystem->>DOM: Create appropriate event
    alt Click Event
        EventSystem->>DOM: new MouseEvent
    else Change Event
        EventSystem->>DOM: new Event
    else Focus Event
        EventSystem->>DOM: new FocusEvent
    else UI Event
        EventSystem->>DOM: new UIEvent
    end
    DOM-->>NiceSelect: Event dispatched
    NiceSelect-->>User: Update UI

Class diagram showing the updated NiceSelect class structure

classDiagram
    class NiceSelect {
        -el: Element
        -config: Object
        -data: Array
        -selectedOptions: Array
        -placeholder: string
        -searchtext: string
        -selectedtext: string
        -dropdown: Element
        -multiple: boolean
        -disabled: boolean
        +constructor(element, options)
        +create()
        +processData(data)
        +extractData()
        +renderDropdown()
        -_renderSelectedItems()
        -_renderItems()
        -_renderItem(option)
        -_renderItemExtra(content)
        +update()
        +disable()
        +enable()
        +clear()
        +destroy()
        +bindEvent()
        -_bindSearchEvent()
        -_onClicked(e)
        -_onItemClicked(option, e)
        +setValue(value)
        +getValue()
        +updateSelectValue()
        +resetSelectValue()
        -_onClickedOutside(e)
        -_onKeyPressed(e)
        -_findNext(el)
        -_findPrev(el)
        -_onSearchChanged(e)
        -_triggerValidationMessage(type)
    }
    note for NiceSelect "Refactored to use modern JS class syntax
and improved event handling"

State diagram for the dropdown component

stateDiagram-v2
    [*] --> Closed
    Closed --> Open: click/keypress
    Open --> Closed: click outside/escape

    state Open {
        [*] --> Normal
        Normal --> Searching: type in search
        Searching --> Normal: clear search
        Normal --> Selected: click option
        Selected --> Normal: clear selection
    }

    Open --> Invalid: validation fails
    Invalid --> Open: fix validation

    state Closed {
        [*] --> Enabled
        Enabled --> Disabled: disable()
        Disabled --> Enabled: enable()
    }

File-Level Changes

Change Details Files
Refactor event triggering logic to use a single function.
  • Replaced individual trigger functions with a single triggerEvent function.
  • Updated event listeners to use the new triggerEvent function.
src/js/nice-select2.js
Update project dependencies and upgrade to modern JavaScript and SASS syntax.
  • Updated dependencies in package.json.
  • Configured webpack to use source maps.
  • Updated SASS syntax to use @use instead of @import.
  • Removed deprecated SASS functions.
package.json
webpack.config.js
src/scss/nice-select2.scss
src/scss/style.scss
Add new features such as default placeholder, search text, and selected text options.
  • Added default placeholder, searchtext, and selectedtext options to the defaultOptions object.
  • Updated the constructor to use the new options.
  • Added a public clear() method to reset the selected options.
  • Added support for the data-extra attribute on options.
  • Added validation message triggers for invalid selections.
src/js/nice-select2.js
Optimize bundle size and overall performance.
  • Replaced utility functions with concise alternatives.
  • Used more efficient DOM manipulation methods.
  • Removed unused code.
src/js/nice-select2.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Feb 05 '25 05:02 sourcery-ai[bot]

@sourcery-ai review

mohammadbaghaei avatar Feb 05 '25 05:02 mohammadbaghaei

@sourcery-ai review

mohammadbaghaei avatar Feb 05 '25 05:02 mohammadbaghaei

@sourcery-ai review

mohammadbaghaei avatar Feb 05 '25 05:02 mohammadbaghaei

@sourcery-ai review

mohammadbaghaei avatar Feb 05 '25 05:02 mohammadbaghaei

sorry I did not see this sooner

Can you resolve the merge conflicts?

Tsjippy avatar Jul 22 '25 05:07 Tsjippy