-
Notifications
You must be signed in to change notification settings - Fork 1
fix: refactor constants #28
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # Allonsh.js Constants Documentation | ||
|
|
||
| This document provides a detailed reference for the constants defined in `src/constants.js` for the Allonsh.js project. These constants centralize configuration and hardcoded values used throughout the library, ensuring consistency and maintainability. | ||
|
|
||
| ## Z_INDEX | ||
|
|
||
| Defines z-index values for various UI elements to control stacking order: | ||
|
|
||
| - `GHOST`: 999 — Used for ghost elements during drag operations. | ||
| - `DRAGGING`: 1000 — Active dragging element. | ||
| - `DROPPED`: 9999 — Element after being dropped. | ||
| - `HEADER`: 10 — Header bar. | ||
| - `THEME_TOGGLE`: 9 — Theme toggle button. | ||
| - `CONTROL_PANEL`: 5 — Control panel UI. | ||
| - `FREEMODE_TITLE`: 5 — Title in freemode. | ||
|
|
||
| ## DEFAULTS | ||
|
|
||
| Default configuration values for stack layout and direction: | ||
|
|
||
| - `STACK_SPACING`: 5 — Default spacing between stack items. | ||
| - `STACK_SPACING_DEMO`: 10 — Spacing for demo mode. | ||
| - `STACK_DIRECTION`: 'horizontal' — Default stack direction. | ||
| - `STACK_DIRECTION_VERTICAL`: 'vertical' — Vertical stack direction. | ||
| - `STACK_DIRECTION_HORIZONTAL`: 'horizontal' — Horizontal stack direction. | ||
|
|
||
| ## CSS_CLASSES | ||
|
|
||
| CSS class names used for styling and DOM selection: | ||
|
|
||
| - `DROPZONE`: 'allonsh-dropzone' — Dropzone area. | ||
| - `HIGHLIGHT`: 'allonsh-highlight' — Highlighted element. | ||
| - `DRAGGABLE`: 'allonsh-draggable' — Draggable element. | ||
| - `RESTRICTED`: 'restricted' — Restricted area or element. | ||
|
|
||
| ## CSS_POSITIONS | ||
|
|
||
| CSS position values: | ||
|
|
||
| - `RELATIVE`: 'relative' | ||
| - `ABSOLUTE`: 'absolute' | ||
|
|
||
| ## CSS_CURSORS | ||
|
|
||
| Cursor styles for drag-and-drop interactions: | ||
|
|
||
| - `GRAB`: 'grab' | ||
| - `GRABBING`: 'grabbing' | ||
|
|
||
| ## OPACITY | ||
|
|
||
| Opacity values for UI elements: | ||
|
|
||
| - `GHOST`: '0.3' — Semi-transparent ghost element. | ||
| - `FULL`: '1' — Fully opaque element. | ||
|
|
||
| ## EVENTS | ||
|
|
||
| Custom DOM event names for drag-and-drop lifecycle: | ||
|
|
||
| - `DRAG_START`: 'allonsh-dragstart' | ||
| - `DROP`: 'allonsh-drop' | ||
| - `DRAG_ENTER`: 'allonsh-dragenter' | ||
| - `DRAG_LEAVE`: 'allonsh-dragleave' | ||
|
|
||
| ## FLEX_DIRECTIONS | ||
|
|
||
| Flexbox direction values: | ||
|
|
||
| - `ROW`: 'row' | ||
| - `COLUMN`: 'column' | ||
|
|
||
| ## FLEX_WRAP | ||
|
|
||
| Flexbox wrap mode: | ||
|
|
||
| - `'wrap'` | ||
|
|
||
| ## DISPLAY_MODES | ||
|
|
||
| Display property values: | ||
|
|
||
| - `FLEX`: 'flex' | ||
| - `NONE`: 'none' | ||
|
|
||
| ## POINTER_EVENTS | ||
|
|
||
| Pointer event values: | ||
|
|
||
| - `NONE`: 'none' — Disables pointer events. | ||
| - `AUTO`: 'auto' — Enables pointer events. | ||
|
|
||
| ## Usage | ||
|
|
||
| Below are examples of how constants from `src/constants.js` are used throughout the Allonsh.js project: | ||
|
|
||
| ### Importing Constants | ||
|
|
||
| In the main source file (`src/allonsh.js`): | ||
|
|
||
| ```js | ||
| import { | ||
| Z_INDEX, | ||
| DEFAULTS, | ||
| CSS_CLASSES, | ||
| CSS_POSITIONS, | ||
| CSS_CURSORS, | ||
| OPACITY, | ||
| EVENTS, | ||
| FLEX_DIRECTIONS, | ||
| FLEX_WRAP, | ||
| DISPLAY_MODES, | ||
| POINTER_EVENTS, | ||
| } from './constants.js'; | ||
| ``` | ||
|
|
||
| ### Using Constants in the Library | ||
|
|
||
| - **Default values:** | ||
| ```js | ||
| stackDirection = DEFAULTS.STACK_DIRECTION; | ||
| stackSpacing = DEFAULTS.STACK_SPACING; | ||
| ``` | ||
| - **Styling elements:** | ||
| ```js | ||
| element.style.cursor = CSS_CURSORS.GRAB; | ||
| element.style.position = CSS_POSITIONS.RELATIVE; | ||
| element.style.zIndex = Z_INDEX.DRAGGING; | ||
| element.style.opacity = OPACITY.GHOST; | ||
| dropzone.classList.add(CSS_CLASSES.DROPZONE); | ||
| dropzone.classList.remove(CSS_CLASSES.HIGHLIGHT); | ||
| ``` | ||
| - **Flexbox and display:** | ||
| ```js | ||
| dropzone.style.display = DISPLAY_MODES.FLEX; | ||
| dropzone.style.flexDirection = FLEX_DIRECTIONS.ROW; | ||
| dropzone.style.flexWrap = FLEX_WRAP; | ||
| ``` | ||
| - **Pointer events:** | ||
| ```js | ||
| element.style.pointerEvents = POINTER_EVENTS.NONE; | ||
| ``` | ||
| - **Custom events:** | ||
| ```js | ||
| element.dispatchEvent(new CustomEvent(EVENTS.DRAG_START, { detail: { ... } })); | ||
| dropzone.dispatchEvent(new CustomEvent(EVENTS.DROP, { detail: { ... } })); | ||
| ``` | ||
|
|
||
| ### Usage in Tests | ||
|
|
||
| In `test/allonsh.test.js`: | ||
|
|
||
| ```js | ||
| import { EVENTS } from '../src/constants.js'; | ||
|
|
||
| // Example: Listening for custom drop event | ||
| const dropHandler = vi.fn(); | ||
| dropzone.addEventListener(EVENTS.DROP, dropHandler); | ||
| ``` | ||
|
|
||
| ### Usage in Demo | ||
|
|
||
| In `demo/js/script.js`, constants are used indirectly via the Allonsh class, which applies them for styling, event handling, and configuration. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Ensure
allonsh/constantsis exported by the package.If not present in package.json exports, these import examples will break for consumers.
Run:
🏁 Script executed:
Length of output: 208
Add missing
./constantsexport in package.jsonThe current
exportsfield is defined as a string ("src/allonsh.js") and does not include a subpath forconstants. As a result, consumers will be unable to import from'allonsh/constants'. Please update your package’s exports to expose the constants entry.• In package.json, modify the
exportssection:"exports": { - ".": "./src/allonsh.js" + ".": "./src/allonsh.js", + "./constants": "./src/constants.js" }📝 Committable suggestion
🤖 Prompt for AI Agents