Compare commits
62 Commits
Author | SHA1 | Date | |
---|---|---|---|
639672358a | |||
671fb7dc66 | |||
b92966ef28 | |||
c1102634f3 | |||
ee470775b2 | |||
ba0f1602a1 | |||
682955212e | |||
0410f6c196 | |||
24aa7588c5 | |||
b46fe8fe93 | |||
b47c2053b5 | |||
16bf8001ae | |||
792e77f824 | |||
9b39196195 | |||
ad59e3d334 | |||
0de4283fae | |||
6f9c92a866 | |||
0ec2f2aebb | |||
cd22106597 | |||
a212536cfa | |||
18297d54c4 | |||
f790ca38d0 | |||
ce2b42ecd5 | |||
09e299bc2e | |||
bbc7dfe29a | |||
49b9e833e8 | |||
f739bb608e | |||
286a6f9088 | |||
e32b9589a5 | |||
6427510c98 | |||
cf92a423cf | |||
3f3677ebaa | |||
edc15a727c | |||
960085145d | |||
7fdb4f19a8 | |||
e21fb79731 | |||
05f669a7bd | |||
8137d79e18 | |||
3b474b7dcc | |||
e449b413d1 | |||
8918dc94bd | |||
2c595bf803 | |||
75f31a6cec | |||
b211c0d068 | |||
911159ee55 | |||
c0dbc3c0d0 | |||
7eea21c9d4 | |||
2f17dea480 | |||
ce33aff843 | |||
09eea844d7 | |||
956edf0d63 | |||
1db74177b3 | |||
1c25554c38 | |||
7d1e06701b | |||
aae4427281 | |||
911c51d078 | |||
2c12c22666 | |||
60a811fd18 | |||
9a9aea56da | |||
49ad998b2c | |||
5066681b3a | |||
ee22879c00 |
1
.serena/.gitignore
vendored
Normal file
1
.serena/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/cache
|
6
.serena/memories/done_checklist.md
Normal file
6
.serena/memories/done_checklist.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Before finishing a task:
|
||||||
|
- Run `pnpm run build` to ensure TypeScript compile + bundling succeed.
|
||||||
|
- Verify `dist_ts_web/` and `dist_bundle/bundle.js` updated.
|
||||||
|
- Optionally run `pnpm run test` and inspect failures.
|
||||||
|
- Avoid changing public APIs unless required; keep changes scoped.
|
||||||
|
- Update readme or inline docs only if user-facing behavior changes.
|
11
.serena/memories/project_overview.md
Normal file
11
.serena/memories/project_overview.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
Project: @design.estate/dees-catalog
|
||||||
|
Purpose: A component library of dynamic Web Components (TypeScript) for building modern web apps.
|
||||||
|
Tech stack: TypeScript (ES2022, NodeNext), decorators, custom elements via @design.estate/dees-element (Lit-style), bundling with esbuild via @git.zone/tsbundle, TypeScript building via @git.zone/tsbuild (tsfolders), tests with @git.zone/tstest, various UI libs (tiptap, apexcharts, monaco-editor runtime via CDN), DOM helpers via @design.estate/dees-domtools.
|
||||||
|
Structure:
|
||||||
|
- ts_web/: source of web components and pages
|
||||||
|
- dist_ts_web/: transpiled TS output
|
||||||
|
- dist_bundle/: production bundle (bundle.js + map)
|
||||||
|
- test/: tests
|
||||||
|
- html/: static demo assets
|
||||||
|
Key configs: tsconfig.json sets ES2022, NodeNext module/resolution, decorators enabled, skipLibCheck enabled to avoid third-party d.ts issues.
|
||||||
|
Entrypoints: ts_web/index.ts for bundling; custom elements annotated with @customElement.
|
5
.serena/memories/style_and_conventions.md
Normal file
5
.serena/memories/style_and_conventions.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Language: TypeScript, ES2022 target, NodeNext module + resolution.
|
||||||
|
Patterns: Web Components with @customElement decorators; class-based components extending DeesElement; styles via css/cssManager; template render via html tagged literal.
|
||||||
|
Typing: Prefer explicit types where practical; tolerate `any` for external browser-injected libs (e.g., monaco) to keep build healthy.
|
||||||
|
Config: skipLibCheck enabled to avoid third-party d.ts breakages; exclude built declaration outputs.
|
||||||
|
Formatting/Linting: Not explicitly configured; follow existing style (2-space indents, single quotes often, semicolons present).
|
6
.serena/memories/suggested_commands.md
Normal file
6
.serena/memories/suggested_commands.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Build: pnpm run build
|
||||||
|
Watch: pnpm run watch
|
||||||
|
Test: pnpm run test
|
||||||
|
Docs: pnpm run buildDocs
|
||||||
|
Inspect bundle size: ls -lh dist_bundle/bundle.js
|
||||||
|
Open demo (if applicable): serve static `html/` with any web server
|
67
.serena/project.yml
Normal file
67
.serena/project.yml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
|
||||||
|
# * For C, use cpp
|
||||||
|
# * For JavaScript, use typescript
|
||||||
|
# Special requirements:
|
||||||
|
# * csharp: Requires the presence of a .sln file in the project folder.
|
||||||
|
language: typescript
|
||||||
|
|
||||||
|
# whether to use the project's gitignore file to ignore files
|
||||||
|
# Added on 2025-04-07
|
||||||
|
ignore_all_files_in_gitignore: true
|
||||||
|
# list of additional paths to ignore
|
||||||
|
# same syntax as gitignore, so you can use * and **
|
||||||
|
# Was previously called `ignored_dirs`, please update your config if you are using that.
|
||||||
|
# Added (renamed) on 2025-04-07
|
||||||
|
ignored_paths: []
|
||||||
|
|
||||||
|
# whether the project is in read-only mode
|
||||||
|
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
||||||
|
# Added on 2025-04-18
|
||||||
|
read_only: false
|
||||||
|
|
||||||
|
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
|
||||||
|
# Below is the complete list of tools for convenience.
|
||||||
|
# To make sure you have the latest list of tools, and to view their descriptions,
|
||||||
|
# execute `uv run scripts/print_tool_overview.py`.
|
||||||
|
#
|
||||||
|
# * `activate_project`: Activates a project by name.
|
||||||
|
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
|
||||||
|
# * `create_text_file`: Creates/overwrites a file in the project directory.
|
||||||
|
# * `delete_lines`: Deletes a range of lines within a file.
|
||||||
|
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
|
||||||
|
# * `execute_shell_command`: Executes a shell command.
|
||||||
|
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
|
||||||
|
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
|
||||||
|
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
|
||||||
|
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
|
||||||
|
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
|
||||||
|
# * `initial_instructions`: Gets the initial instructions for the current project.
|
||||||
|
# Should only be used in settings where the system prompt cannot be set,
|
||||||
|
# e.g. in clients you have no control over, like Claude Desktop.
|
||||||
|
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
|
||||||
|
# * `insert_at_line`: Inserts content at a given line in a file.
|
||||||
|
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
|
||||||
|
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
|
||||||
|
# * `list_memories`: Lists memories in Serena's project-specific memory store.
|
||||||
|
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
|
||||||
|
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
|
||||||
|
# * `read_file`: Reads a file within the project directory.
|
||||||
|
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
|
||||||
|
# * `remove_project`: Removes a project from the Serena configuration.
|
||||||
|
# * `replace_lines`: Replaces a range of lines within a file with new content.
|
||||||
|
# * `replace_symbol_body`: Replaces the full definition of a symbol.
|
||||||
|
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
|
||||||
|
# * `search_for_pattern`: Performs a search for a pattern in the project.
|
||||||
|
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
|
||||||
|
# * `switch_modes`: Activates modes by providing a list of their names
|
||||||
|
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
|
||||||
|
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
|
||||||
|
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
|
||||||
|
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
|
||||||
|
excluded_tools: []
|
||||||
|
|
||||||
|
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
||||||
|
# (contrary to the memories, which are loaded on demand).
|
||||||
|
initial_prompt: ""
|
||||||
|
|
||||||
|
project_name: "dees-catalog"
|
174
CLAUDE.md
174
CLAUDE.md
@@ -1,174 +0,0 @@
|
|||||||
# CLAUDE.md
|
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Project Overview
|
|
||||||
|
|
||||||
@design.estate/dees-catalog is a comprehensive web components library built with TypeScript and LitElement. It provides a large collection of UI components for building modern web applications with consistent design and behavior.
|
|
||||||
|
|
||||||
## Build and Development Commands
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Install dependencies
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
# Build the project
|
|
||||||
pnpm run build
|
|
||||||
# This runs: tsbuild tsfolders --allowimplicitany && tsbundle element --production --bundler esbuild
|
|
||||||
|
|
||||||
# Run development watch mode
|
|
||||||
pnpm run watch
|
|
||||||
# This runs: tswatch element
|
|
||||||
|
|
||||||
# Run tests (browser tests)
|
|
||||||
pnpm test
|
|
||||||
# This runs: tstest test/ --web --verbose --timeout 30 --logfile
|
|
||||||
|
|
||||||
# Run a specific test file
|
|
||||||
tsx test/test.wysiwyg-basic.browser.ts --verbose
|
|
||||||
|
|
||||||
# Build documentation
|
|
||||||
pnpm run buildDocs
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing Notes
|
|
||||||
- Test files follow the pattern: `test.*.browser.ts`, `test.*.node.ts`, or `test.*.both.ts`
|
|
||||||
- Browser tests run in a headless browser environment
|
|
||||||
- Use `--logfile` option to store logs in `.nogit/testlogs/`
|
|
||||||
- For debugging, create files in `.nogit/debug/` and run with `tsx`
|
|
||||||
|
|
||||||
## Architecture Overview
|
|
||||||
|
|
||||||
### Component Structure
|
|
||||||
The library is organized into several categories:
|
|
||||||
|
|
||||||
1. **Core UI Components** (`dees-button`, `dees-badge`, `dees-icon`, etc.)
|
|
||||||
- Basic building blocks with consistent theming
|
|
||||||
- All support light/dark themes via `cssManager.bdTheme()`
|
|
||||||
|
|
||||||
2. **Form Components** (`dees-form`, `dees-input-*`)
|
|
||||||
- Complete form system with validation
|
|
||||||
- Base class `DeesInputBase` provides common functionality
|
|
||||||
- Form data collection via `DeesForm` container
|
|
||||||
|
|
||||||
3. **Layout Components** (`dees-appui-*`)
|
|
||||||
- Application shell components
|
|
||||||
- `DeesAppuiBase` orchestrates the entire layout
|
|
||||||
- Grid-based responsive design
|
|
||||||
|
|
||||||
4. **Data Display** (`dees-table`, `dees-dataview-*`, `dees-statsgrid`)
|
|
||||||
- Complex data visualization components
|
|
||||||
- Interactive tables with sorting/filtering
|
|
||||||
- Chart components using ApexCharts
|
|
||||||
|
|
||||||
5. **Overlays** (`dees-modal`, `dees-contextmenu`, `dees-toast`)
|
|
||||||
- Managed by central z-index registry
|
|
||||||
- Window layer system for proper stacking
|
|
||||||
|
|
||||||
### Key Architectural Patterns
|
|
||||||
|
|
||||||
#### Z-Index Management
|
|
||||||
All overlay components use a centralized z-index registry system:
|
|
||||||
- Definition in `ts_web/elements/00zindex.ts`
|
|
||||||
- Dynamic z-index assignment via `ZIndexRegistry` class
|
|
||||||
- Components get z-index from registry when showing
|
|
||||||
- Ensures proper stacking order (dropdowns above modals, etc.)
|
|
||||||
|
|
||||||
#### Theme System
|
|
||||||
- All components support light/dark themes
|
|
||||||
- Use `cssManager.bdTheme(lightValue, darkValue)` for theme-aware colors
|
|
||||||
- Consistent color palette defined in `00colors.ts`
|
|
||||||
|
|
||||||
#### Component Demo System
|
|
||||||
- Each component has a static `demo` property
|
|
||||||
- Demo functions in separate `.demo.ts` files
|
|
||||||
- Showcase pages aggregate demos (e.g., `input-showcase.ts`)
|
|
||||||
|
|
||||||
#### WYSIWYG Editor Architecture
|
|
||||||
The WYSIWYG editor uses a sophisticated architecture with separated concerns:
|
|
||||||
- **Main Component**: `dees-input-wysiwyg.ts` - Orchestrates the editor
|
|
||||||
- **Handler Classes**:
|
|
||||||
- `WysiwygInputHandler` - Handles text input and block transformations
|
|
||||||
- `WysiwygKeyboardHandler` - Manages keyboard shortcuts and navigation
|
|
||||||
- `WysiwygDragDropHandler` - Manages block reordering
|
|
||||||
- `WysiwygModalManager` - Shows configuration modals
|
|
||||||
- `WysiwygBlockOperations` - Core block manipulation logic
|
|
||||||
- **Global Menus**:
|
|
||||||
- `DeesSlashMenu` and `DeesFormattingMenu` render globally to avoid focus issues
|
|
||||||
- Singleton pattern ensures single instance
|
|
||||||
- **Programmatic Rendering**: Uses manual DOM manipulation to prevent focus loss
|
|
||||||
|
|
||||||
### Component Communication
|
|
||||||
- Custom events for parent-child communication
|
|
||||||
- Form components emit standardized events (`change`, `blur`, etc.)
|
|
||||||
- Complex components like `DeesAppuiBase` re-emit child events
|
|
||||||
|
|
||||||
### Build System
|
|
||||||
- TypeScript compilation with decorators support
|
|
||||||
- Web component bundling with esbuild
|
|
||||||
- Element exports in `ts_web/elements/index.ts`
|
|
||||||
- Distribution builds in `dist_ts_web/`
|
|
||||||
|
|
||||||
## Important Implementation Details
|
|
||||||
|
|
||||||
### When Creating New Components
|
|
||||||
1. Extend `DeesElement` from `@design.estate/dees-element`
|
|
||||||
2. Use `@customElement('dees-componentname')` decorator
|
|
||||||
3. Implement theme support with `cssManager.bdTheme()`
|
|
||||||
4. Create a demo function in a separate `.demo.ts` file
|
|
||||||
5. Export from `elements/index.ts`
|
|
||||||
|
|
||||||
### Form Input Components
|
|
||||||
1. Extend `DeesInputBase` for form inputs
|
|
||||||
2. Implement `getValue()` and `setValue()` methods
|
|
||||||
3. Use `changeSubject.next(this)` to emit changes
|
|
||||||
4. Support `disabled` and `required` properties
|
|
||||||
|
|
||||||
### Overlay Components
|
|
||||||
1. Import z-index from `00zindex.ts`
|
|
||||||
2. Get z-index from registry when showing: `zIndexRegistry.getNextZIndex()`
|
|
||||||
3. Register/unregister with the registry
|
|
||||||
4. Use `DeesWindowLayer` for backdrop if needed
|
|
||||||
|
|
||||||
### Testing Components
|
|
||||||
1. Create test files in `test/` directory
|
|
||||||
2. Use `@git.zone/tstest` with tap-bundle
|
|
||||||
3. Test in browser environment for web components
|
|
||||||
4. Use proper async/await for component lifecycle
|
|
||||||
|
|
||||||
## Common Patterns and Pitfalls
|
|
||||||
|
|
||||||
### Focus Management
|
|
||||||
- WYSIWYG editor uses programmatic rendering to prevent focus loss
|
|
||||||
- Use `requestAnimationFrame` for timing-sensitive focus operations
|
|
||||||
- Avoid reactive re-renders during user input
|
|
||||||
|
|
||||||
### Event Handling
|
|
||||||
- Prevent event bubbling in nested interactive components
|
|
||||||
- Use `pointer-events: none/auto` for click-through behavior
|
|
||||||
- Handle both mouse and keyboard events for accessibility
|
|
||||||
|
|
||||||
### Performance Considerations
|
|
||||||
- Large components (editor, terminal) use lazy loading
|
|
||||||
- Charts use debounced resize observers
|
|
||||||
- Tables implement virtual scrolling for large datasets
|
|
||||||
|
|
||||||
## File Organization
|
|
||||||
```
|
|
||||||
ts_web/
|
|
||||||
├── elements/ # All component files
|
|
||||||
│ ├── 00*.ts # Shared utilities (colors, z-index, plugins)
|
|
||||||
│ ├── dees-*.ts # Component implementations
|
|
||||||
│ ├── dees-*.demo.ts # Component demos
|
|
||||||
│ ├── interfaces/ # Shared TypeScript interfaces
|
|
||||||
│ ├── helperclasses/ # Utility classes (FormController)
|
|
||||||
│ └── wysiwyg/ # WYSIWYG editor subsystem
|
|
||||||
├── pages/ # Demo showcase pages
|
|
||||||
└── index.ts # Main export file
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recent Major Changes
|
|
||||||
- Z-Index Registry System (2025-12-24): Dynamic stacking order management
|
|
||||||
- WYSIWYG Refactoring (2025-06-24): Complete architecture overhaul with separated concerns
|
|
||||||
- Form System Enhancement: Unified validation and data collection
|
|
||||||
- Theme System: Consistent light/dark theme support across all components
|
|
136
changelog.md
136
changelog.md
@@ -1,5 +1,139 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-09-18 - 1.12.1 - fix(ci)
|
||||||
|
Add local settings to allow running pnpm scripts and enable dev chat permission
|
||||||
|
|
||||||
|
- Add a repository-local settings file granting permission to run pnpm scripts (Bash(pnpm run:*)) for development tooling.
|
||||||
|
- Enable the mcp__zen__chat permission for local dev workflows.
|
||||||
|
|
||||||
|
## 2025-09-18 - 1.12.0 - feat(dees-stepper)
|
||||||
|
Revamp dees-stepper: modern styling, new steps and improved navigation/validation
|
||||||
|
|
||||||
|
- Visual refresh for dees-stepper: updated card shapes, shadows, refined borders and stronger selected-state visuals for a modern shadcn-inspired look
|
||||||
|
- Improved transitions and animations (transform, box-shadow, filter) for smoother step selection and show/hide behavior
|
||||||
|
- Expanded default/demo steps: replaced small sample with a richer multi-step flow (Account Setup, Profile Details, Contact Information, Team Size, Goals, Brand Preferences, Integrations, Review & Launch)
|
||||||
|
- Enhanced step interactions: safer goNext/goBack handling with boundary checks and reset of validation flags to avoid stale validation state
|
||||||
|
- Better toolbar/controls placement for stepper demo (spacing, counters, accessible back control) and improved keyboard/UX affordances
|
||||||
|
- Minor documentation and meta updates: readme.plan.md extended with dees-stepper plan items and added .claude/settings.local.json
|
||||||
|
|
||||||
|
## 2025-09-18 - 1.11.8 - fix(ci)
|
||||||
|
Add local tool permissions config to allow running pnpm scripts and enable mcp__zen__chat
|
||||||
|
|
||||||
|
- Add local settings file to grant permission to run pnpm scripts (Bash(pnpm run:*))
|
||||||
|
- Enable mcp__zen__chat permission in local tool settings
|
||||||
|
|
||||||
|
## 2025-09-16 - 1.11.7 - fix(readme)
|
||||||
|
Expand README with comprehensive component documentation, examples and developer guide; add local Claude settings
|
||||||
|
|
||||||
|
- Expanded README substantially: installation, component overview, detailed component docs, usage examples, demos and developer guidance
|
||||||
|
- Updated many example snippets and API usage examples (icons, inputs, editor, forms, overlays, charts, etc.) to be more explicit and consistent
|
||||||
|
- Added .claude/settings.local.json to configure local Claude permissions for repository tooling
|
||||||
|
- No runtime or library code changes — documentation and demo content only
|
||||||
|
|
||||||
|
## 2025-09-16 - 1.11.6 - fix(dees-table)
|
||||||
|
Improve Lucene range comparisons, pin monaco-editor to 0.52.2, and add local dev metadata
|
||||||
|
|
||||||
|
- Fix lucene inRange behavior to correctly compare homogeneous types (strings, numbers, dates) and fall back to string comparison when needed (ts_web/elements/dees-table/lucene.ts).
|
||||||
|
- Pin monaco-editor to 0.52.2 in package.json to avoid a breaking upgrade regression observed with ^0.53.0.
|
||||||
|
- Add local development/tooling metadata and conveniences: .claude/settings.local.json (tool permissions) and .serena/ memory files (done_checklist, project_overview, style_and_conventions, suggested_commands).
|
||||||
|
- Minor housekeeping: update project dev docs / memories to capture build/test/checklist guidance.
|
||||||
|
|
||||||
|
## 2025-09-16 - 1.11.5 - fix(ci)
|
||||||
|
Add local Claude agent settings for CI tooling
|
||||||
|
|
||||||
|
- Add .claude/settings.local.json to configure local Claude agent permissions
|
||||||
|
- Allow Bash commands matching pnpm run:* and the mcp__zen__chat permission for development tooling
|
||||||
|
|
||||||
|
## 2025-09-10 - 1.11.4 - fix(readme)
|
||||||
|
Rewrite and expand README with Quick Start, feature highlights, demos and usage examples; add local Claude settings file
|
||||||
|
|
||||||
|
- Completely rewritten and reorganized README: added Quick Start, component highlights, usage examples, demos, development workflow, troubleshooting and links.
|
||||||
|
- Added .claude/settings.local.json with local Claude permission configuration.
|
||||||
|
|
||||||
|
## 2025-09-08 - 1.11.3 - fix(dees-input-list)
|
||||||
|
Prevent list animations from affecting scroll bounds and fix content-visibility issues in dees-input-list; add local developer settings
|
||||||
|
|
||||||
|
- dees-input-list: add overflow:hidden to list items to prevent animations from altering scroll bounds and causing visual/scroll glitches
|
||||||
|
- dees-input-list: force content-visibility/contain to visible/none to avoid unexpected scrolling/layout issues when items animate
|
||||||
|
- Add .claude/settings.local.json with local developer permissions (allows running pnpm scripts via Claude-local tooling)
|
||||||
|
|
||||||
|
## 2025-09-07 - 1.11.2 - fix(DeesFormSubmit)
|
||||||
|
Make form submit robust by locating nearest dees-form via closest(); add local CLAUDE settings
|
||||||
|
|
||||||
|
- Fix: DeesFormSubmit.submit now walks up the DOM with closest('dees-form') to find and call gatherAndDispatch on the parent form. This fixes cases where the submit button is slotted or not a direct child of the form.
|
||||||
|
- Chore: Add .claude/settings.local.json to permit running pnpm scripts in the local CLAUDE environment (allows Bash(pnpm run:*)).
|
||||||
|
|
||||||
|
## 2025-09-06 - 1.11.1 - fix(dees-input-text)
|
||||||
|
Normalize Lucide icon names for password toggle
|
||||||
|
|
||||||
|
- Updated password visibility toggle icons in dees-input-text from 'lucide:eye'/'lucide:eye-off' to 'lucide:Eye'/'lucide:EyeOff' to match Lucide exports and avoid missing icon rendering.
|
||||||
|
|
||||||
|
## 2025-09-05 - 1.11.0 - feat(dees-icon)
|
||||||
|
Add full icon list and improve dees-icon demo with copy-all functionality and UI tweaks
|
||||||
|
|
||||||
|
- Added readme.icons.md containing 1900+ icon identifiers (FontAwesome + Lucide) for easy reference and tooling
|
||||||
|
- Enhanced ts_web/elements/dees-icon.demo.ts: added a 'Copy All Icon Names' button that copies prefixed icon names (fa:..., lucide:...) to the clipboard and shows temporary feedback
|
||||||
|
- Updated demo presentation: prefixed displayed icon names (fa: / lucide:), improved search-container spacing and added button styling for better UX
|
||||||
|
- Changes are documentation/demo only — no production runtime component logic changed
|
||||||
|
|
||||||
|
## 2025-09-05 - 1.10.12 - fix(dees-simple-appdash)
|
||||||
|
Fix icon rendering in dees-simple-appdash to respect provided icon strings
|
||||||
|
|
||||||
|
- dees-simple-appdash: stop forcing a 'lucide:' prefix when rendering view icons — use the icon string as provided.
|
||||||
|
- Prevents incorrect/missing icons when the iconName already includes a library prefix (e.g. 'fa:' or 'lucide:').
|
||||||
|
|
||||||
|
## 2025-09-05 - 1.10.11 - fix(dees-simple-appdash)
|
||||||
|
Bump deps and fix dees-simple-appdash icon binding and terminal sizing
|
||||||
|
|
||||||
|
- Updated runtime dependencies: @design.estate/dees-element -> ^2.1.2, @design.estate/dees-wcctools -> ^1.1.1, @fortawesome/* -> ^7.0.1, apexcharts -> ^5.3.4, lucide -> ^0.542.0 (compatibility/security/stability updates)
|
||||||
|
- Updated dev tooling: @git.zone/tsbuild -> ^2.6.8, @git.zone/tstest -> ^2.3.6, @git.zone/tswatch -> ^2.2.1
|
||||||
|
- Fix: dees-simple-appdash — use proper string interpolation for lucide icon properties (prevents incorrect icon rendering)
|
||||||
|
- Fix: dees-simple-appdash — enforce terminal maxWidth/maxHeight to avoid overflow and improve layout stability
|
||||||
|
- Cosmetic: small style/behavior tweaks to dees-simple-appdash (logout/terminal/wifi icon bindings corrected)
|
||||||
|
|
||||||
|
## 2025-06-29 - 1.10.10 - improve(dees-dashboardgrid, dees-input-wysiwyg)
|
||||||
|
Enhanced dashboard grid component with advanced spacing and layout features inspired by gridstack.js
|
||||||
|
|
||||||
|
Dashboard Grid improvements:
|
||||||
|
- Improved margin system supporting uniform or individual margins (top, right, bottom, left)
|
||||||
|
- Added collision detection to prevent widget overlap during drag operations
|
||||||
|
- Implemented auto-positioning for new widgets to find first available space
|
||||||
|
- Added compact() method to eliminate gaps and compress layout vertically or horizontally
|
||||||
|
- Enhanced resize constraints with minW, maxW, minH, maxH support
|
||||||
|
- Added optional grid lines visualization for better layout understanding
|
||||||
|
- Improved resize handles with better visibility and hover states
|
||||||
|
- Added RTL (right-to-left) layout support
|
||||||
|
- Implemented cellHeightUnit option supporting 'px', 'em', 'rem', or 'auto' (square cells)
|
||||||
|
- Added configurable animation with enableAnimation property
|
||||||
|
- Enhanced demo with interactive controls for testing all features
|
||||||
|
- Better calculation of widget positions accounting for margins between cells
|
||||||
|
- Added findAvailablePosition() for intelligent widget placement
|
||||||
|
- Improved drag and resize calculations for pixel-perfect positioning
|
||||||
|
|
||||||
|
WYSIWYG editor drag and drop fixes:
|
||||||
|
- Fixed drop indicator positioning to properly account for block margins
|
||||||
|
- Added defensive checks in drag event handlers to prevent potential crashes
|
||||||
|
- Improved updateBlockPositions with null checks and error handling
|
||||||
|
- Updated drop indicator calculation to use simplified margin approach
|
||||||
|
- Fixed drop indicator height to match the exact space occupied by dragged blocks
|
||||||
|
- Improved drop indicator positioning algorithm to accurately show where blocks will land
|
||||||
|
- Simplified visual block position calculations accounting for CSS transforms
|
||||||
|
- Enhanced margin calculation to use correct values based on block type (16px for paragraphs, 24px for headings, 20px for code/quotes)
|
||||||
|
- Fixed index calculation issue when dragging blocks downward by adjusting target index for excluded dragged block
|
||||||
|
|
||||||
|
## 2025-06-28 - 1.10.9 - feat(dees-dashboardgrid)
|
||||||
|
Add new dashboard grid component with drag-and-drop and resize capabilities
|
||||||
|
|
||||||
|
- Created dees-dashboardgrid component for building flexible dashboard layouts
|
||||||
|
- Features drag-and-drop functionality for rearranging widgets
|
||||||
|
- Includes resize handles for adjusting widget dimensions
|
||||||
|
- Supports configurable grid properties (columns, cell height, gap)
|
||||||
|
- Provides widget locking and editable mode controls
|
||||||
|
- Styled with shadcn design principles
|
||||||
|
- No external dependencies - built with native browser APIs
|
||||||
|
- Emits events for widget movements and resizes
|
||||||
|
- Includes comprehensive demo with sample dashboard widgets
|
||||||
|
|
||||||
## 2025-06-27 - 1.10.8 - feat(ui-components)
|
## 2025-06-27 - 1.10.8 - feat(ui-components)
|
||||||
Update multiple components with shadcn-aligned styling and improved animations
|
Update multiple components with shadcn-aligned styling and improved animations
|
||||||
|
|
||||||
@@ -103,7 +237,7 @@ Add dees-searchbar component with live search and filter demo
|
|||||||
## 2025-04-22 - 1.6.0 - feat(documentation/dees-heading)
|
## 2025-04-22 - 1.6.0 - feat(documentation/dees-heading)
|
||||||
Add codex documentation overview and dees-heading component demo
|
Add codex documentation overview and dees-heading component demo
|
||||||
|
|
||||||
- Introduce 'codex.md' to provide a high-level overview of project layout, component patterns, and build workflow
|
- Introduce contributor overview doc (`codex.md`, now consolidated into `readme.info.md`) to provide a high-level overview of project layout, component patterns, and build workflow
|
||||||
- Add and update dees-heading component with demo to support multiple heading levels and horizontal rule styles
|
- Add and update dees-heading component with demo to support multiple heading levels and horizontal rule styles
|
||||||
- Update component export index to include dees-heading
|
- Update component export index to include dees-heading
|
||||||
|
|
||||||
|
43
codex.md
43
codex.md
@@ -1,43 +0,0 @@
|
|||||||
# Codex: Project Overview and Codebase Structure
|
|
||||||
|
|
||||||
## Project Overview
|
|
||||||
- Package: `@design.estate/dees-catalog`
|
|
||||||
- Focus: Web Components library providing UI elements and layouts for modern web apps.
|
|
||||||
|
|
||||||
## Directory Layout
|
|
||||||
- ts_web/: TypeScript source files
|
|
||||||
- elements/: Individual Web Component definitions
|
|
||||||
- pages/: Page-level templates for composite layouts
|
|
||||||
- html/: Demo/app entry point loading the bundled scripts
|
|
||||||
- dist_bundle/: Bundled browser JS and source maps
|
|
||||||
- dist_ts_web/: ES module outputs for TypeScript/web consumers
|
|
||||||
- dist_watch/: Watch-mode development bundle with live reload
|
|
||||||
- test/: Browser-based tests using `@push.rocks/tapbundle`
|
|
||||||
|
|
||||||
## Component Patterns
|
|
||||||
- Each component in ts_web/elements/:
|
|
||||||
- Decorated with `@customElement('tag-name')`
|
|
||||||
- Extends `DeesElement` from `@design.estate/dees-element`
|
|
||||||
- Uses `@property` for reactive, reflected attributes
|
|
||||||
- Defines `static styles = [cssManager.defaultStyles, css`...`]`
|
|
||||||
- Implements `render()` returning a Lit `html` template with slots or markup
|
|
||||||
- Exposes a demo via `public static demo` linking to `.demo.ts` files
|
|
||||||
|
|
||||||
## Build & Development Workflow
|
|
||||||
- Install dependencies: `npm install` or `pnpm install`
|
|
||||||
- Build production bundle: `npm run build`
|
|
||||||
- Start dev watch mode: `npm run watch`
|
|
||||||
- Run tests: `npm test` (launches browser fixtures)
|
|
||||||
|
|
||||||
## Theming & Utilities
|
|
||||||
- Default global styles via `cssManager.defaultStyles`
|
|
||||||
- Theme-aware values with `cssManager.bdTheme(light, dark)`
|
|
||||||
- DOM utilities set up in `html/index.ts` using `@design.estate/dees-domtools`
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
- `readme.md` provides an overview of all components and basic usage
|
|
||||||
- Live examples in `.demo.ts` files
|
|
||||||
accessible via component `demo` static property
|
|
||||||
|
|
||||||
## Updates to this file
|
|
||||||
If you have pattern insisights or general changes to the codebase, please update this file.
|
|
31
package.json
31
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@design.estate/dees-catalog",
|
"name": "@design.estate/dees-catalog",
|
||||||
"version": "1.10.9",
|
"version": "1.12.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
|
"description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
|
||||||
"main": "dist_ts_web/index.js",
|
"main": "dist_ts_web/index.js",
|
||||||
@@ -10,21 +10,22 @@
|
|||||||
"test": "tstest test/ --web --verbose --timeout 30 --logfile",
|
"test": "tstest test/ --web --verbose --timeout 30 --logfile",
|
||||||
"build": "tsbuild tsfolders --allowimplicitany && tsbundle element --production --bundler esbuild",
|
"build": "tsbuild tsfolders --allowimplicitany && tsbundle element --production --bundler esbuild",
|
||||||
"watch": "tswatch element",
|
"watch": "tswatch element",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc",
|
||||||
|
"postinstall": "node scripts/update-monaco-version.cjs"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@design.estate/dees-domtools": "^2.3.3",
|
"@design.estate/dees-domtools": "^2.3.3",
|
||||||
"@design.estate/dees-element": "^2.0.45",
|
"@design.estate/dees-element": "^2.1.2",
|
||||||
"@design.estate/dees-wcctools": "^1.1.0",
|
"@design.estate/dees-wcctools": "^1.1.1",
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
"@fortawesome/fontawesome-svg-core": "^7.0.1",
|
||||||
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
"@fortawesome/free-brands-svg-icons": "^7.0.1",
|
||||||
"@fortawesome/free-regular-svg-icons": "^6.7.2",
|
"@fortawesome/free-regular-svg-icons": "^7.0.1",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
"@fortawesome/free-solid-svg-icons": "^7.0.1",
|
||||||
"@push.rocks/smarti18n": "^1.0.4",
|
"@push.rocks/smarti18n": "^1.0.4",
|
||||||
"@push.rocks/smartpromise": "^4.2.0",
|
"@push.rocks/smartpromise": "^4.2.0",
|
||||||
"@push.rocks/smartstring": "^4.0.15",
|
"@push.rocks/smartstring": "^4.1.0",
|
||||||
"@tiptap/core": "^2.23.0",
|
"@tiptap/core": "^2.23.0",
|
||||||
"@tiptap/extension-link": "^2.23.0",
|
"@tiptap/extension-link": "^2.23.0",
|
||||||
"@tiptap/extension-text-align": "^2.23.0",
|
"@tiptap/extension-text-align": "^2.23.0",
|
||||||
@@ -33,20 +34,20 @@
|
|||||||
"@tiptap/starter-kit": "^2.23.0",
|
"@tiptap/starter-kit": "^2.23.0",
|
||||||
"@tsclass/tsclass": "^9.2.0",
|
"@tsclass/tsclass": "^9.2.0",
|
||||||
"@webcontainer/api": "1.2.0",
|
"@webcontainer/api": "1.2.0",
|
||||||
"apexcharts": "^4.7.0",
|
"apexcharts": "^5.3.5",
|
||||||
"highlight.js": "11.11.1",
|
"highlight.js": "11.11.1",
|
||||||
"ibantools": "^4.5.1",
|
"ibantools": "^4.5.1",
|
||||||
"lucide": "^0.525.0",
|
"lucide": "^0.544.0",
|
||||||
"monaco-editor": "^0.52.2",
|
"monaco-editor": "0.52.2",
|
||||||
"pdfjs-dist": "^4.10.38",
|
"pdfjs-dist": "^4.10.38",
|
||||||
"xterm": "^5.3.0",
|
"xterm": "^5.3.0",
|
||||||
"xterm-addon-fit": "^0.8.0"
|
"xterm-addon-fit": "^0.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.6.4",
|
"@git.zone/tsbuild": "^2.6.8",
|
||||||
"@git.zone/tsbundle": "^2.5.1",
|
"@git.zone/tsbundle": "^2.5.1",
|
||||||
"@git.zone/tstest": "^2.3.1",
|
"@git.zone/tstest": "^2.3.8",
|
||||||
"@git.zone/tswatch": "^2.1.2",
|
"@git.zone/tswatch": "^2.2.1",
|
||||||
"@push.rocks/projectinfo": "^5.0.2",
|
"@push.rocks/projectinfo": "^5.0.2",
|
||||||
"@push.rocks/tapbundle": "^6.0.3",
|
"@push.rocks/tapbundle": "^6.0.3",
|
||||||
"@types/node": "^22.0.0"
|
"@types/node": "^22.0.0"
|
||||||
|
3326
pnpm-lock.yaml
generated
3326
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
2
pnpm-workspace.yaml
Normal file
2
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
onlyBuiltDependencies:
|
||||||
|
- puppeteer
|
@@ -1,513 +0,0 @@
|
|||||||
# Building Applications with dees-appui Architecture
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
The dees-appui system provides a comprehensive framework for building desktop-style web applications with a consistent layout, navigation, and view management system. This document outlines the architecture and best practices for building applications using these components.
|
|
||||||
|
|
||||||
## Core Architecture
|
|
||||||
|
|
||||||
### Component Hierarchy
|
|
||||||
|
|
||||||
```
|
|
||||||
dees-appui-base
|
|
||||||
├── dees-appui-appbar (top menu bar)
|
|
||||||
├── dees-appui-mainmenu (left sidebar - primary navigation)
|
|
||||||
├── dees-appui-mainselector (second sidebar - contextual navigation)
|
|
||||||
├── dees-appui-maincontent (main content area)
|
|
||||||
│ └── dees-appui-view (view container)
|
|
||||||
│ └── dees-appui-tabs (tab navigation within views)
|
|
||||||
└── dees-appui-activitylog (right sidebar - optional)
|
|
||||||
```
|
|
||||||
|
|
||||||
### View-Based Architecture
|
|
||||||
|
|
||||||
The system is built around the concept of **Views** - self-contained modules that represent different sections of your application. Each view can have:
|
|
||||||
|
|
||||||
- Its own tabs for sub-navigation
|
|
||||||
- Menu items for the selector (contextual navigation)
|
|
||||||
- Content areas with dynamic loading
|
|
||||||
- State management
|
|
||||||
- Event handling
|
|
||||||
|
|
||||||
## Implementation Plan
|
|
||||||
|
|
||||||
### Phase 1: Application Shell Setup
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// app-shell.ts
|
|
||||||
import { LitElement, html, css } from 'lit';
|
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
|
||||||
import type { IAppView } from '@design.estate/dees-catalog';
|
|
||||||
|
|
||||||
@customElement('my-app-shell')
|
|
||||||
export class MyAppShell extends LitElement {
|
|
||||||
@property({ type: Array })
|
|
||||||
views: IAppView[] = [];
|
|
||||||
|
|
||||||
@property({ type: String })
|
|
||||||
activeViewId: string = '';
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const activeView = this.views.find(v => v.id === this.activeViewId);
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<dees-appui-base
|
|
||||||
.appbarMenuItems=${this.getAppBarMenuItems()}
|
|
||||||
.appbarBreadcrumbs=${this.getBreadcrumbs()}
|
|
||||||
.appbarTheme=${'dark'}
|
|
||||||
.appbarUser=${{ name: 'User', status: 'online' }}
|
|
||||||
.mainmenuTabs=${this.getMainMenuTabs()}
|
|
||||||
.mainselectorOptions=${activeView?.menuItems || []}
|
|
||||||
@mainmenu-tab-select=${this.handleMainMenuSelect}
|
|
||||||
@mainselector-option-select=${this.handleSelectorSelect}
|
|
||||||
>
|
|
||||||
<dees-appui-view
|
|
||||||
slot="maincontent"
|
|
||||||
.viewConfig=${activeView}
|
|
||||||
@view-tab-select=${this.handleViewTabSelect}
|
|
||||||
></dees-appui-view>
|
|
||||||
</dees-appui-base>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Phase 2: View Definition
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// views/dashboard-view.ts
|
|
||||||
export const dashboardView: IAppView = {
|
|
||||||
id: 'dashboard',
|
|
||||||
name: 'Dashboard',
|
|
||||||
description: 'System overview and metrics',
|
|
||||||
iconName: 'home',
|
|
||||||
tabs: [
|
|
||||||
{
|
|
||||||
key: 'overview',
|
|
||||||
iconName: 'chart-line',
|
|
||||||
action: () => console.log('Overview selected'),
|
|
||||||
content: () => html`
|
|
||||||
<dashboard-overview></dashboard-overview>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'metrics',
|
|
||||||
iconName: 'tachometer-alt',
|
|
||||||
action: () => console.log('Metrics selected'),
|
|
||||||
content: () => html`
|
|
||||||
<dashboard-metrics></dashboard-metrics>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'alerts',
|
|
||||||
iconName: 'bell',
|
|
||||||
action: () => console.log('Alerts selected'),
|
|
||||||
content: () => html`
|
|
||||||
<dashboard-alerts></dashboard-alerts>
|
|
||||||
`
|
|
||||||
}
|
|
||||||
],
|
|
||||||
menuItems: [
|
|
||||||
{ key: 'Time Range', action: () => showTimeRangeSelector() },
|
|
||||||
{ key: 'Refresh Rate', action: () => showRefreshSettings() },
|
|
||||||
{ key: 'Export Data', action: () => exportDashboardData() }
|
|
||||||
]
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
### Phase 3: View Management System
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// services/view-manager.ts
|
|
||||||
export class ViewManager {
|
|
||||||
private views: Map<string, IAppView> = new Map();
|
|
||||||
private activeView: IAppView | null = null;
|
|
||||||
private viewCache: Map<string, any> = new Map();
|
|
||||||
|
|
||||||
registerView(view: IAppView) {
|
|
||||||
this.views.set(view.id, view);
|
|
||||||
}
|
|
||||||
|
|
||||||
async activateView(viewId: string) {
|
|
||||||
const view = this.views.get(viewId);
|
|
||||||
if (!view) throw new Error(`View ${viewId} not found`);
|
|
||||||
|
|
||||||
// Deactivate current view
|
|
||||||
if (this.activeView) {
|
|
||||||
await this.deactivateView(this.activeView.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activate new view
|
|
||||||
this.activeView = view;
|
|
||||||
|
|
||||||
// Update navigation
|
|
||||||
this.updateMainSelector(view.menuItems);
|
|
||||||
this.updateBreadcrumbs(view);
|
|
||||||
|
|
||||||
// Load view data if needed
|
|
||||||
if (!this.viewCache.has(viewId)) {
|
|
||||||
await this.loadViewData(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async loadViewData(view: IAppView) {
|
|
||||||
// Implement lazy loading of view data
|
|
||||||
const viewData = await import(`./views/${view.id}/data.js`);
|
|
||||||
this.viewCache.set(view.id, viewData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Phase 4: Navigation Integration
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// navigation/app-navigation.ts
|
|
||||||
export class AppNavigation {
|
|
||||||
constructor(
|
|
||||||
private viewManager: ViewManager,
|
|
||||||
private appShell: MyAppShell
|
|
||||||
) {}
|
|
||||||
|
|
||||||
setupMainMenu(): ITab[] {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
key: 'dashboard',
|
|
||||||
iconName: 'home',
|
|
||||||
action: () => this.navigateToView('dashboard')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'projects',
|
|
||||||
iconName: 'folder',
|
|
||||||
action: () => this.navigateToView('projects')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'analytics',
|
|
||||||
iconName: 'chart-bar',
|
|
||||||
action: () => this.navigateToView('analytics')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'settings',
|
|
||||||
iconName: 'cog',
|
|
||||||
action: () => this.navigateToView('settings')
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
async navigateToView(viewId: string) {
|
|
||||||
const view = await this.viewManager.activateView(viewId);
|
|
||||||
this.appShell.activeViewId = viewId;
|
|
||||||
|
|
||||||
// Update URL
|
|
||||||
window.history.pushState(
|
|
||||||
{ viewId },
|
|
||||||
view.name,
|
|
||||||
`/${viewId}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleBrowserNavigation() {
|
|
||||||
window.addEventListener('popstate', (event) => {
|
|
||||||
if (event.state?.viewId) {
|
|
||||||
this.navigateToView(event.state.viewId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Phase 5: Dynamic View Loading
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// views/view-loader.ts
|
|
||||||
export class ViewLoader {
|
|
||||||
private loadedViews: Set<string> = new Set();
|
|
||||||
|
|
||||||
async loadView(viewId: string): Promise<IAppView> {
|
|
||||||
if (this.loadedViews.has(viewId)) {
|
|
||||||
return this.getViewConfig(viewId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamic import
|
|
||||||
const viewModule = await import(`./views/${viewId}/index.js`);
|
|
||||||
const viewConfig = viewModule.default as IAppView;
|
|
||||||
|
|
||||||
// Register custom elements if needed
|
|
||||||
if (viewModule.registerElements) {
|
|
||||||
await viewModule.registerElements();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loadedViews.add(viewId);
|
|
||||||
return viewConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
async preloadViews(viewIds: string[]) {
|
|
||||||
const promises = viewIds.map(id => this.loadView(id));
|
|
||||||
await Promise.all(promises);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Best Practices
|
|
||||||
|
|
||||||
### 1. View Organization
|
|
||||||
|
|
||||||
```
|
|
||||||
src/
|
|
||||||
├── views/
|
|
||||||
│ ├── dashboard/
|
|
||||||
│ │ ├── index.ts # View configuration
|
|
||||||
│ │ ├── data.ts # Data fetching/management
|
|
||||||
│ │ ├── components/ # View-specific components
|
|
||||||
│ │ │ ├── dashboard-overview.ts
|
|
||||||
│ │ │ ├── dashboard-metrics.ts
|
|
||||||
│ │ │ └── dashboard-alerts.ts
|
|
||||||
│ │ └── styles.ts # View-specific styles
|
|
||||||
│ ├── projects/
|
|
||||||
│ │ └── ...
|
|
||||||
│ └── settings/
|
|
||||||
│ └── ...
|
|
||||||
├── services/
|
|
||||||
│ ├── view-manager.ts
|
|
||||||
│ ├── navigation.ts
|
|
||||||
│ └── state-manager.ts
|
|
||||||
└── app-shell.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. State Management
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// services/state-manager.ts
|
|
||||||
export class StateManager {
|
|
||||||
private viewStates: Map<string, any> = new Map();
|
|
||||||
|
|
||||||
saveViewState(viewId: string, state: any) {
|
|
||||||
this.viewStates.set(viewId, {
|
|
||||||
...this.getViewState(viewId),
|
|
||||||
...state,
|
|
||||||
lastUpdated: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getViewState(viewId: string): any {
|
|
||||||
return this.viewStates.get(viewId) || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Persist to localStorage
|
|
||||||
persistState() {
|
|
||||||
const serialized = JSON.stringify(
|
|
||||||
Array.from(this.viewStates.entries())
|
|
||||||
);
|
|
||||||
localStorage.setItem('app-state', serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
restoreState() {
|
|
||||||
const saved = localStorage.getItem('app-state');
|
|
||||||
if (saved) {
|
|
||||||
const entries = JSON.parse(saved);
|
|
||||||
this.viewStates = new Map(entries);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. View Communication
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// events/view-events.ts
|
|
||||||
export class ViewEventBus {
|
|
||||||
private eventTarget = new EventTarget();
|
|
||||||
|
|
||||||
emit(eventName: string, detail: any) {
|
|
||||||
this.eventTarget.dispatchEvent(
|
|
||||||
new CustomEvent(eventName, { detail })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
on(eventName: string, handler: (detail: any) => void) {
|
|
||||||
this.eventTarget.addEventListener(eventName, (e: CustomEvent) => {
|
|
||||||
handler(e.detail);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cross-view communication
|
|
||||||
sendMessage(fromView: string, toView: string, message: any) {
|
|
||||||
this.emit('view-message', {
|
|
||||||
from: fromView,
|
|
||||||
to: toView,
|
|
||||||
message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Responsive Design
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// views/responsive-view.ts
|
|
||||||
export const createResponsiveView = (config: IAppView): IAppView => {
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
tabs: config.tabs.map(tab => ({
|
|
||||||
...tab,
|
|
||||||
content: () => html`
|
|
||||||
<div class="view-content ${getDeviceClass()}">
|
|
||||||
${tab.content()}
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
function getDeviceClass(): string {
|
|
||||||
const width = window.innerWidth;
|
|
||||||
if (width < 768) return 'mobile';
|
|
||||||
if (width < 1024) return 'tablet';
|
|
||||||
return 'desktop';
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. Performance Optimization
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// optimization/lazy-components.ts
|
|
||||||
export const lazyComponent = (
|
|
||||||
importFn: () => Promise<any>,
|
|
||||||
componentName: string
|
|
||||||
) => {
|
|
||||||
let loaded = false;
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (!loaded) {
|
|
||||||
importFn().then(() => {
|
|
||||||
loaded = true;
|
|
||||||
});
|
|
||||||
return html`<dees-spinner></dees-spinner>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return html`<${componentName}></${componentName}>`;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Usage in view
|
|
||||||
tabs: [
|
|
||||||
{
|
|
||||||
key: 'heavy-component',
|
|
||||||
content: lazyComponent(
|
|
||||||
() => import('./components/heavy-component.js'),
|
|
||||||
'heavy-component'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Advanced Features
|
|
||||||
|
|
||||||
### 1. View Permissions
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface IAppViewWithPermissions extends IAppView {
|
|
||||||
requiredPermissions?: string[];
|
|
||||||
visibleTo?: (user: User) => boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PermissionManager {
|
|
||||||
canAccessView(view: IAppViewWithPermissions, user: User): boolean {
|
|
||||||
if (view.visibleTo) {
|
|
||||||
return view.visibleTo(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (view.requiredPermissions) {
|
|
||||||
return view.requiredPermissions.every(
|
|
||||||
perm => user.permissions.includes(perm)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. View Lifecycle Hooks
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface IAppViewLifecycle extends IAppView {
|
|
||||||
onActivate?: () => Promise<void>;
|
|
||||||
onDeactivate?: () => Promise<void>;
|
|
||||||
onTabChange?: (oldTab: string, newTab: string) => void;
|
|
||||||
onDestroy?: () => void;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Dynamic Menu Generation
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class DynamicMenuBuilder {
|
|
||||||
buildMainMenu(views: IAppView[], user: User): ITab[] {
|
|
||||||
return views
|
|
||||||
.filter(view => this.canShowInMenu(view, user))
|
|
||||||
.map(view => ({
|
|
||||||
key: view.id,
|
|
||||||
iconName: view.iconName || 'file',
|
|
||||||
action: () => this.navigation.navigateToView(view.id)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
buildSelectorMenu(view: IAppView, context: any): ISelectionOption[] {
|
|
||||||
const baseItems = view.menuItems || [];
|
|
||||||
const contextItems = this.getContextualItems(view, context);
|
|
||||||
|
|
||||||
return [...baseItems, ...contextItems];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Migration Strategy
|
|
||||||
|
|
||||||
For existing applications:
|
|
||||||
|
|
||||||
1. **Identify Views**: Map existing routes/pages to views
|
|
||||||
2. **Extract Components**: Move page-specific components into view folders
|
|
||||||
3. **Define View Configs**: Create IAppView configurations
|
|
||||||
4. **Update Navigation**: Replace existing routing with view navigation
|
|
||||||
5. **Migrate State**: Move page state to ViewManager
|
|
||||||
6. **Test & Optimize**: Ensure smooth transitions and performance
|
|
||||||
|
|
||||||
## Example Application Structure
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// main.ts
|
|
||||||
import { ViewManager } from './services/view-manager.js';
|
|
||||||
import { AppNavigation } from './services/navigation.js';
|
|
||||||
import { dashboardView } from './views/dashboard/index.js';
|
|
||||||
import { projectsView } from './views/projects/index.js';
|
|
||||||
import { settingsView } from './views/settings/index.js';
|
|
||||||
|
|
||||||
const app = new MyAppShell();
|
|
||||||
const viewManager = new ViewManager();
|
|
||||||
const navigation = new AppNavigation(viewManager, app);
|
|
||||||
|
|
||||||
// Register views
|
|
||||||
viewManager.registerView(dashboardView);
|
|
||||||
viewManager.registerView(projectsView);
|
|
||||||
viewManager.registerView(settingsView);
|
|
||||||
|
|
||||||
// Setup navigation
|
|
||||||
app.views = [dashboardView, projectsView, settingsView];
|
|
||||||
navigation.setupMainMenu();
|
|
||||||
navigation.handleBrowserNavigation();
|
|
||||||
|
|
||||||
// Initial navigation
|
|
||||||
navigation.navigateToView('dashboard');
|
|
||||||
|
|
||||||
document.body.appendChild(app);
|
|
||||||
```
|
|
||||||
|
|
||||||
This architecture provides:
|
|
||||||
- **Modularity**: Each view is self-contained
|
|
||||||
- **Scalability**: Easy to add new views
|
|
||||||
- **Performance**: Lazy loading and caching
|
|
||||||
- **Consistency**: Unified navigation and layout
|
|
||||||
- **Flexibility**: Customizable per view
|
|
||||||
- **Maintainability**: Clear separation of concerns
|
|
1906
readme.icons.md
Normal file
1906
readme.icons.md
Normal file
File diff suppressed because it is too large
Load Diff
80
readme.info.md
Normal file
80
readme.info.md
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# Contributor Information
|
||||||
|
|
||||||
|
This reference consolidates the helper notes previously split across `codex.md` and `CLAUDE.md`. Use it to get oriented quickly when working on `@design.estate/dees-catalog`, a TypeScript/Lit web-components library that ships themed UI building blocks for modern web applications.
|
||||||
|
|
||||||
|
## Project Snapshot
|
||||||
|
- Package: `@design.estate/dees-catalog`
|
||||||
|
- Description: Comprehensive catalog of reusable web components with cohesive design, advanced form inputs, data displays, and layout scaffolding.
|
||||||
|
- Entry points: builds ship to `dist_ts_web/` (ES modules) and `dist_bundle/` (browser bundle); demos live in `html/`.
|
||||||
|
- Type system: strict TypeScript targeting modern browsers (see `tsconfig.json`).
|
||||||
|
|
||||||
|
## Repository Layout
|
||||||
|
- `ts_web/` – TypeScript source
|
||||||
|
- `elements/` – component implementations (`00*.ts` shared utilities, `dees-*.ts` components, `*.demo.ts` demos)
|
||||||
|
- `pages/` – showcase pages aggregating demos
|
||||||
|
- `index.ts` – main export surface
|
||||||
|
- `html/` – demo entry point bootstrapping bundles
|
||||||
|
- `dist_bundle/`, `dist_ts_web/`, `dist_watch/` – build outputs (production, module, and watch bundles)
|
||||||
|
- `test/` – browser/node tests powered by `@push.rocks/tapbundle`
|
||||||
|
- `scripts/` – maintenance utilities (e.g., Monaco version sync postinstall)
|
||||||
|
|
||||||
|
## Build & Development Commands
|
||||||
|
All workflows use pnpm (see `package.json`).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install # install dependencies
|
||||||
|
pnpm run build # tsbuild tsfolders --allowimplicitany && tsbundle element --production --bundler esbuild
|
||||||
|
pnpm run watch # tswatch element (development watch/dev server)
|
||||||
|
pnpm test # tstest test/ --web --verbose --timeout 30 --logfile
|
||||||
|
pnpm run buildDocs # tsdoc (generates docs)
|
||||||
|
tsx test/test.file.ts # run a specific test file (file must be named test.*)
|
||||||
|
```
|
||||||
|
|
||||||
|
`postinstall` runs `node scripts/update-monaco-version.cjs` to sync the Monaco editor version, so keep the script intact when updating dependencies.
|
||||||
|
|
||||||
|
## Testing Guidelines
|
||||||
|
- Framework: `@push.rocks/tapbundle` with smartexpect assertions. Always review https://code.foss.global/push.rocks/smartexpect/raw/branch/master/readme.md when adding tests.
|
||||||
|
- Import pattern:
|
||||||
|
```typescript
|
||||||
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
|
```
|
||||||
|
- Test naming: `test.*.both.ts` for dual runtime, `.node.ts` for Node-only, `.browser.ts` for browser-only suites.
|
||||||
|
- Prefer `pnpm test` for full runs; use `tsx` for focused debugging. Type-check failing tests with `tsc --noEmit`.
|
||||||
|
- Logs live under `.nogit/testlogs/`; put ad-hoc debug artefacts in `.nogit/debug/`.
|
||||||
|
|
||||||
|
## Component Architecture
|
||||||
|
- **Base pattern**: Components extend `DeesElement` from `@design.estate/dees-element`, use Lit decorators (`@customElement`, `@property`), and combine `cssManager.defaultStyles` with component styles. Rendering happens via Lit `html` templates; demos sit on a static `demo` property referencing a `.demo.ts` module.
|
||||||
|
- **Theming**: `cssManager.bdTheme(light, dark)` selects theme-aware values. Shared palettes live in `ts_web/elements/00colors.ts`.
|
||||||
|
- **Z-index management**: Overlays consult the registry in `ts_web/elements/00zindex.ts` (`ZIndexRegistry`) to coordinate stacking.
|
||||||
|
- **Component families**:
|
||||||
|
- Core UI (`dees-button`, `dees-badge`, `dees-icon`, …) focus on consistent theming and interactions.
|
||||||
|
- Form inputs (`dees-form`, `dees-input-*`) build on `DeesInputBase` and communicate through subjects/events for validation.
|
||||||
|
- Layout shells (`dees-appui-*`) orchestrate responsive app frames with centralized event rebroadcasts.
|
||||||
|
- Data views (`dees-table`, `dees-dataview-*`, `dees-statsgrid`) handle large datasets with virtualisation and chart integrations.
|
||||||
|
- Overlays (`dees-modal`, `dees-contextmenu`, `dees-toast`) respect the z-index registry and use shared window-layer utilities.
|
||||||
|
- **WYSIWYG editor**: `dees-input-wysiwyg` coordinates specialized handler classes (`WysiwygInputHandler`, `WysiwygKeyboardHandler`, drag/drop & modal managers) and global menus (`DeesSlashMenu`, `DeesFormattingMenu`). Rendering is imperative to preserve caret focus.
|
||||||
|
|
||||||
|
## Implementation Guidelines
|
||||||
|
- Import external modules through `ts_web/elements/00plugins.ts`: `import * as plugins from './plugins.ts';` then reference `plugins.moduleName`.
|
||||||
|
- When creating new components:
|
||||||
|
1. Extend `DeesElement` and decorate with `@customElement('dees-component')`.
|
||||||
|
2. Support theming, slots, and accessibility; provide meaningful default styles.
|
||||||
|
3. Expose a `.demo.ts` for the component and re-export via `elements/index.ts`.
|
||||||
|
- Form components must implement `getValue()` / `setValue()` and emit through `changeSubject` while honoring `disabled` and `required` states.
|
||||||
|
- Overlay components retrieve z-indices from the registry, register/unregister on show/hide, and use `DeesWindowLayer` for backdrops when appropriate.
|
||||||
|
- Avoid simplifying away functionality; prefer small, targeted changes and keep compatibility with existing APIs.
|
||||||
|
|
||||||
|
## Common Patterns & Pitfalls
|
||||||
|
- Focus management: schedule DOM updates with `requestAnimationFrame` inside interactive editors to avoid focus loss.
|
||||||
|
- Event handling: stop propagation where nested interactive elements coexist; mix pointer and keyboard handling for accessibility.
|
||||||
|
- Performance: heavy blocks/components may load lazily; charts use debounced observers, tables rely on virtual scrolling. Watch bundle size when adding dependencies.
|
||||||
|
|
||||||
|
## Documentation & Demos
|
||||||
|
- `readme.md` surfaces component overviews; demos in `.demo.ts` illustrate real usage.
|
||||||
|
- Update this `readme.info.md` when architectural patterns or workflows change so contributors stay in sync.
|
||||||
|
|
||||||
|
## Recent Highlights
|
||||||
|
- Z-index registry overhaul enables dynamic stacking control across overlays.
|
||||||
|
- WYSIWYG refactor separated block handlers for maintainability.
|
||||||
|
- Dashboard grid enhancements added live drag-and-drop previews and overlap fixes.
|
||||||
|
- Monaco editor integration now reads the installed version at build time.
|
834
readme.md
834
readme.md
@@ -1,5 +1,8 @@
|
|||||||
# @design.estate/dees-catalog
|
# @design.estate/dees-catalog
|
||||||
An extensive library for building modern web applications with dynamic components using Web Components, JavaScript, and TypeScript.
|
A comprehensive web components library built with TypeScript and LitElement, providing 75+ UI components for building modern web applications with consistent design and behavior.
|
||||||
|
|
||||||
|
## Development Guide
|
||||||
|
For developers working on this library, please refer to the [UI Components Playbook](readme.playbook.md) for comprehensive patterns, best practices, and architectural guidelines.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
To install the `@design.estate/dees-catalog` library, you can use npm or any other compatible JavaScript package manager:
|
To install the `@design.estate/dees-catalog` library, you can use npm or any other compatible JavaScript package manager:
|
||||||
@@ -12,15 +15,16 @@ npm install @design.estate/dees-catalog
|
|||||||
|
|
||||||
| Category | Components |
|
| Category | Components |
|
||||||
|----------|------------|
|
|----------|------------|
|
||||||
| Core UI | `DeesButton`, `DeesButtonExit`, `DeesButtonGroup`, `DeesBadge`, `DeesChips`, `DeesHeading`, `DeesHint`, `DeesIcon`, `DeesLabel`, `DeesPanel`, `DeesSearchbar`, `DeesSpinner`, `DeesToast`, `DeesWindowcontrols` |
|
| Core UI | [`DeesButton`](#deesbutton), [`DeesButtonExit`](#deesbuttonexit), [`DeesButtonGroup`](#deesbuttongroup), [`DeesBadge`](#deesbadge), [`DeesChips`](#deeschips), [`DeesHeading`](#deesheading), [`DeesHint`](#deeshint), [`DeesIcon`](#deesicon), [`DeesLabel`](#deeslabel), [`DeesPanel`](#deespanel), [`DeesSearchbar`](#deessearchbar), [`DeesSpinner`](#deesspinner), [`DeesToast`](#deestoast), [`DeesWindowcontrols`](#deeswindowcontrols) |
|
||||||
| Forms | `DeesForm`, `DeesInputText`, `DeesInputCheckbox`, `DeesInputDropdown`, `DeesInputRadiogroup`, `DeesInputFileupload`, `DeesInputIban`, `DeesInputPhone`, `DeesInputQuantitySelector`, `DeesInputMultitoggle`, `DeesInputTags`, `DeesInputTypelist`, `DeesInputRichtext`, `DeesInputWysiwyg`, `DeesFormSubmit` |
|
| Forms | [`DeesForm`](#deesform), [`DeesInputText`](#deesinputtext), [`DeesInputCheckbox`](#deesinputcheckbox), [`DeesInputDropdown`](#deesinputdropdown), [`DeesInputRadiogroup`](#deesinputradiogroup), [`DeesInputFileupload`](#deesinputfileupload), [`DeesInputIban`](#deesinputiban), [`DeesInputPhone`](#deesinputphone), [`DeesInputQuantitySelector`](#deesinputquantityselector), [`DeesInputMultitoggle`](#deesinputmultitoggle), [`DeesInputTags`](#deesinputtags), [`DeesInputTypelist`](#deesinputtypelist), [`DeesInputRichtext`](#deesinputrichtext), [`DeesInputWysiwyg`](#deesinputwysiwyg), [`DeesInputDatepicker`](#deesinputdatepicker), [`DeesInputSearchselect`](#deesinputsearchselect), [`DeesFormSubmit`](#deesformsubmit) |
|
||||||
| Layout | `DeesAppuiBase`, `DeesAppuiMainmenu`, `DeesAppuiMainselector`, `DeesAppuiMaincontent`, `DeesAppuiAppbar`, `DeesAppuiActivitylog`, `DeesAppuiProfiledropdown`, `DeesAppuiTabs`, `DeesAppuiView`, `DeesMobileNavigation` |
|
| Layout | [`DeesAppuiBase`](#deesappuibase), [`DeesAppuiMainmenu`](#deesappuimainmenu), [`DeesAppuiMainselector`](#deesappuimainselector), [`DeesAppuiMaincontent`](#deesappuimaincontent), [`DeesAppuiAppbar`](#deesappuiappbar), [`DeesAppuiActivitylog`](#deesappuiactivitylog), [`DeesAppuiProfiledropdown`](#deesappuiprofiledropdown), [`DeesAppuiTabs`](#deesappuitabs), [`DeesAppuiView`](#deesappuiview), [`DeesMobileNavigation`](#deesmobilenavigation), [`DeesDashboardGrid`](#deesdashboardgrid) |
|
||||||
| Data Display | `DeesTable`, `DeesDataviewCodebox`, `DeesDataviewStatusobject`, `DeesPdf`, `DeesStatsGrid`, `DeesPagination` |
|
| Data Display | [`DeesTable`](#deestable), [`DeesDataviewCodebox`](#deesdataviewcodebox), [`DeesDataviewStatusobject`](#deesdataviewstatusobject), [`DeesPdf`](#deespdf), [`DeesStatsGrid`](#deesstatsgrid), [`DeesPagination`](#deespagination) |
|
||||||
| Visualization | `DeesChartArea`, `DeesChartLog` |
|
| Visualization | [`DeesChartArea`](#deeschartarea), [`DeesChartLog`](#deeschartlog) |
|
||||||
| Dialogs & Overlays | `DeesModal`, `DeesContextmenu`, `DeesSpeechbubble`, `DeesWindowlayer` |
|
| Dialogs & Overlays | [`DeesModal`](#deesmodal), [`DeesContextmenu`](#deescontextmenu), [`DeesSpeechbubble`](#deesspeechbubble), [`DeesWindowlayer`](#deeswindowlayer) |
|
||||||
| Navigation | `DeesStepper`, `DeesProgressbar`, `DeesMobileNavigation` |
|
| Navigation | [`DeesStepper`](#deesstepper), [`DeesProgressbar`](#deesprogressbar) |
|
||||||
| Development | `DeesEditor`, `DeesEditorMarkdown`, `DeesEditorMarkdownoutlet`, `DeesTerminal`, `DeesUpdater` |
|
| Development | [`DeesEditor`](#deeseditor), [`DeesEditorMarkdown`](#deeseditormarkdown), [`DeesEditorMarkdownoutlet`](#deeseditormarkdownoutlet), [`DeesTerminal`](#deesterminal), [`DeesUpdater`](#deesupdater) |
|
||||||
| Auth & Utilities | `DeesSimpleAppdash`, `DeesSimpleLogin` |
|
| Auth & Utilities | [`DeesSimpleAppdash`](#deessimpleappdash), [`DeesSimpleLogin`](#deessimplelogin) |
|
||||||
|
| Shopping | [`DeesShoppingProductcard`](#deesshoppingproductcard) |
|
||||||
|
|
||||||
## Detailed Component Documentation
|
## Detailed Component Documentation
|
||||||
|
|
||||||
@@ -70,14 +74,27 @@ Interactive chips/tags with selection capabilities.
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### `DeesIcon`
|
#### `DeesIcon`
|
||||||
Display icons from various icon sets including FontAwesome.
|
Display icons from FontAwesome and Lucide icon libraries with library prefixes.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
// FontAwesome icons - use 'fa:' prefix
|
||||||
<dees-icon
|
<dees-icon
|
||||||
icon="home" // FontAwesome icon name
|
icon="fa:check" // FontAwesome icon with fa: prefix
|
||||||
type="solid" // Options: solid, regular, brands
|
iconSize="24" // Size in pixels
|
||||||
size="1.5rem" // Optional: custom size
|
color="#22c55e" // Optional: custom color
|
||||||
|
></dees-icon>
|
||||||
|
|
||||||
|
// Lucide icons - use 'lucide:' prefix
|
||||||
|
<dees-icon
|
||||||
|
icon="lucide:menu" // Lucide icon with lucide: prefix
|
||||||
|
iconSize="24" // Size in pixels
|
||||||
color="#007bff" // Optional: custom color
|
color="#007bff" // Optional: custom color
|
||||||
|
strokeWidth="2" // Optional: stroke width for Lucide icons
|
||||||
|
></dees-icon>
|
||||||
|
|
||||||
|
// Legacy API (deprecated but still supported)
|
||||||
|
<dees-icon
|
||||||
|
iconFA="check" // Without prefix - assumes FontAwesome
|
||||||
></dees-icon>
|
></dees-icon>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -431,6 +448,78 @@ Dynamic list input for managing arrays of typed values.
|
|||||||
></dees-input-typelist>
|
></dees-input-typelist>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `DeesInputDatepicker`
|
||||||
|
Date and time picker component with calendar interface and manual typing support.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
<dees-input-datepicker
|
||||||
|
key="eventDate"
|
||||||
|
label="Event Date"
|
||||||
|
placeholder="YYYY-MM-DD"
|
||||||
|
value="2025-01-15T14:30:00Z" // ISO string format
|
||||||
|
dateFormat="YYYY-MM-DD" // Display format (default: YYYY-MM-DD)
|
||||||
|
enableTime={true} // Enable time selection
|
||||||
|
timeFormat="24h" // Options: 24h, 12h
|
||||||
|
minuteIncrement={15} // Time step in minutes
|
||||||
|
minDate="2025-01-01" // Minimum selectable date
|
||||||
|
maxDate="2025-12-31" // Maximum selectable date
|
||||||
|
.disabledDates=${[ // Array of disabled dates
|
||||||
|
'2025-01-10',
|
||||||
|
'2025-01-11'
|
||||||
|
]}
|
||||||
|
weekStartsOn={1} // 0 = Sunday, 1 = Monday
|
||||||
|
required
|
||||||
|
@change=${handleDateChange}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
```
|
||||||
|
|
||||||
|
Key Features:
|
||||||
|
- Interactive calendar popup
|
||||||
|
- Manual date typing with multiple formats
|
||||||
|
- Optional time selection
|
||||||
|
- Configurable date format
|
||||||
|
- Min/max date constraints
|
||||||
|
- Disable specific dates
|
||||||
|
- Keyboard navigation
|
||||||
|
- Today button
|
||||||
|
- Clear functionality
|
||||||
|
- 12/24 hour time formats
|
||||||
|
- Theme-aware styling
|
||||||
|
- Live parsing and validation
|
||||||
|
|
||||||
|
Manual Input Formats:
|
||||||
|
```typescript
|
||||||
|
// Date formats supported
|
||||||
|
"2023-12-20" // ISO format (YYYY-MM-DD)
|
||||||
|
"20.12.2023" // European format (DD.MM.YYYY)
|
||||||
|
"12/20/2023" // US format (MM/DD/YYYY)
|
||||||
|
|
||||||
|
// Date with time (add space and time after any date format)
|
||||||
|
"2023-12-20 14:30"
|
||||||
|
"20.12.2023 9:45"
|
||||||
|
"12/20/2023 16:00"
|
||||||
|
```
|
||||||
|
|
||||||
|
The component automatically parses and validates input as you type, updating the internal date value when a valid date is recognized.
|
||||||
|
|
||||||
|
#### `DeesInputSearchselect`
|
||||||
|
Search-enabled dropdown selection component.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
<dees-input-searchselect
|
||||||
|
key="category"
|
||||||
|
label="Select Category"
|
||||||
|
placeholder="Search categories..."
|
||||||
|
.options=${[
|
||||||
|
{ key: 'tech', label: 'Technology' },
|
||||||
|
{ key: 'health', label: 'Healthcare' },
|
||||||
|
{ key: 'finance', label: 'Finance' }
|
||||||
|
]}
|
||||||
|
required
|
||||||
|
@change=${handleCategoryChange}
|
||||||
|
></dees-input-searchselect>
|
||||||
|
```
|
||||||
|
|
||||||
#### `DeesInputRichtext`
|
#### `DeesInputRichtext`
|
||||||
Rich text editor with formatting toolbar powered by TipTap.
|
Rich text editor with formatting toolbar powered by TipTap.
|
||||||
|
|
||||||
@@ -501,10 +590,10 @@ Base container component for application layout structure with integrated appbar
|
|||||||
.appbarMenuItems=${[
|
.appbarMenuItems=${[
|
||||||
{
|
{
|
||||||
name: 'File',
|
name: 'File',
|
||||||
action: async () => {},
|
action: async () => {}, // No-op for parent menu items
|
||||||
submenu: [
|
submenu: [
|
||||||
{ name: 'New', shortcut: 'Cmd+N', iconName: 'file-plus', action: async () => {} },
|
{ name: 'New File', shortcut: 'Cmd+N', iconName: 'file-plus', action: async () => {} },
|
||||||
{ name: 'Open', shortcut: 'Cmd+O', iconName: 'folder-open', action: async () => {} },
|
{ name: 'Open...', shortcut: 'Cmd+O', iconName: 'folder-open', action: async () => {} },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ name: 'Save', shortcut: 'Cmd+S', iconName: 'save', action: async () => {} }
|
{ name: 'Save', shortcut: 'Cmd+S', iconName: 'save', action: async () => {} }
|
||||||
]
|
]
|
||||||
@@ -520,10 +609,7 @@ Base container component for application layout structure with integrated appbar
|
|||||||
]}
|
]}
|
||||||
.appbarBreadcrumbs=${'Dashboard > Overview'}
|
.appbarBreadcrumbs=${'Dashboard > Overview'}
|
||||||
.appbarTheme=${'dark'}
|
.appbarTheme=${'dark'}
|
||||||
.appbarUser=${{
|
.appbarUser=${{ name: 'John Doe', status: 'online' }}
|
||||||
name: 'John Doe',
|
|
||||||
status: 'online'
|
|
||||||
}}
|
|
||||||
.appbarShowSearch=${true}
|
.appbarShowSearch=${true}
|
||||||
.appbarShowWindowControls=${true}
|
.appbarShowWindowControls=${true}
|
||||||
|
|
||||||
@@ -569,43 +655,6 @@ Key Features:
|
|||||||
- **Responsive Grid**: Uses CSS Grid for flexible, responsive layout
|
- **Responsive Grid**: Uses CSS Grid for flexible, responsive layout
|
||||||
- **Slot Support**: Main content area supports custom content via slots
|
- **Slot Support**: Main content area supports custom content via slots
|
||||||
|
|
||||||
Layout Structure:
|
|
||||||
```
|
|
||||||
┌─────────────────────────────────────────────────┐
|
|
||||||
│ AppBar │
|
|
||||||
├────┬──────────────┬─────────────────┬──────────┤
|
|
||||||
│ │ │ │ │
|
|
||||||
│ M │ Selector │ Main Content │ Activity │
|
|
||||||
│ e │ │ │ Log │
|
|
||||||
│ n │ │ │ │
|
|
||||||
│ u │ │ │ │
|
|
||||||
│ │ │ │ │
|
|
||||||
└────┴──────────────┴─────────────────┴──────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
Grid Configuration:
|
|
||||||
- Main Menu: 60px width
|
|
||||||
- Selector: 240px width
|
|
||||||
- Main Content: Flexible (1fr)
|
|
||||||
- Activity Log: 240px width
|
|
||||||
|
|
||||||
Child Component Access:
|
|
||||||
```typescript
|
|
||||||
// Access child components after firstUpdated
|
|
||||||
const base = document.querySelector('dees-appui-base');
|
|
||||||
base.appbar; // DeesAppuiAppbar instance
|
|
||||||
base.mainmenu; // DeesAppuiMainmenu instance
|
|
||||||
base.mainselector; // DeesAppuiMainselector instance
|
|
||||||
base.maincontent; // DeesAppuiMaincontent instance
|
|
||||||
base.activitylog; // DeesAppuiActivitylog instance
|
|
||||||
```
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
1. **Configuration**: Set all properties on the base component for consistency
|
|
||||||
2. **Event Handling**: Listen to events on the base component rather than child components
|
|
||||||
3. **Content**: Use the `maincontent` slot for your application's primary interface
|
|
||||||
4. **State Management**: Manage selected tabs and options at the base component level
|
|
||||||
|
|
||||||
#### `DeesAppuiMainmenu`
|
#### `DeesAppuiMainmenu`
|
||||||
Main navigation menu component for application-wide navigation.
|
Main navigation menu component for application-wide navigation.
|
||||||
|
|
||||||
@@ -762,163 +811,6 @@ Key Features:
|
|||||||
- Focus management
|
- Focus management
|
||||||
- Screen reader compatible
|
- Screen reader compatible
|
||||||
|
|
||||||
Menu Item Interface:
|
|
||||||
```typescript
|
|
||||||
// Regular menu item
|
|
||||||
interface IAppBarMenuItemRegular {
|
|
||||||
name: string; // Display text
|
|
||||||
action: () => Promise<any>; // Click handler
|
|
||||||
iconName?: string; // Optional icon (for dropdown items)
|
|
||||||
shortcut?: string; // Keyboard shortcut display
|
|
||||||
submenu?: IAppBarMenuItem[]; // Nested menu items
|
|
||||||
disabled?: boolean; // Disabled state
|
|
||||||
checked?: boolean; // For checkbox menu items
|
|
||||||
radioGroup?: string; // For radio button menu items
|
|
||||||
}
|
|
||||||
|
|
||||||
// Divider item
|
|
||||||
interface IAppBarMenuDivider {
|
|
||||||
divider: true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Combined type
|
|
||||||
type IAppBarMenuItem = IAppBarMenuItemRegular | IAppBarMenuDivider;
|
|
||||||
```
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
1. **Menu Structure**
|
|
||||||
- Keep top-level menus text-only (no icons)
|
|
||||||
- Use icons in dropdown items for visual clarity
|
|
||||||
- Group related actions with dividers
|
|
||||||
- Provide keyboard shortcuts for common actions
|
|
||||||
|
|
||||||
2. **Navigation**
|
|
||||||
- Use breadcrumbs for deep navigation hierarchies
|
|
||||||
- Keep breadcrumb labels concise
|
|
||||||
- Provide meaningful navigation events
|
|
||||||
|
|
||||||
3. **User Experience**
|
|
||||||
- Show user status when relevant
|
|
||||||
- Provide clear visual feedback
|
|
||||||
- Ensure smooth transitions
|
|
||||||
- Handle edge cases (long menus, small screens)
|
|
||||||
|
|
||||||
4. **Accessibility**
|
|
||||||
- Always provide text labels
|
|
||||||
- Ensure keyboard navigation works
|
|
||||||
- Test with screen readers
|
|
||||||
- Maintain focus management
|
|
||||||
|
|
||||||
#### `DeesAppuiActivitylog`
|
|
||||||
Activity log component for displaying system events and user actions.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<dees-appui-activitylog
|
|
||||||
.entries=${[
|
|
||||||
{
|
|
||||||
timestamp: new Date(),
|
|
||||||
type: 'info',
|
|
||||||
message: 'User logged in',
|
|
||||||
details: { userId: '123' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamp: new Date(),
|
|
||||||
type: 'error',
|
|
||||||
message: 'Failed to save document',
|
|
||||||
details: { error: 'Network error' }
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
maxEntries={100} // Maximum entries to display
|
|
||||||
@entry-click=${handleEntryClick}
|
|
||||||
></dees-appui-activitylog>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `DeesAppuiProfiledropdown`
|
|
||||||
User profile dropdown component with status and menu options.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<dees-appui-profiledropdown
|
|
||||||
.user=${{
|
|
||||||
name: 'John Doe',
|
|
||||||
email: 'john@example.com',
|
|
||||||
avatar: '/path/to/avatar.jpg',
|
|
||||||
status: 'online' // Options: online, offline, busy, away
|
|
||||||
}}
|
|
||||||
.menuItems=${[
|
|
||||||
{ name: 'Profile', iconName: 'user', action: async () => {} },
|
|
||||||
{ name: 'Settings', iconName: 'settings', action: async () => {} },
|
|
||||||
{ divider: true },
|
|
||||||
{ name: 'Logout', iconName: 'logOut', action: async () => {} }
|
|
||||||
]}
|
|
||||||
@status-change=${handleStatusChange}
|
|
||||||
></dees-appui-profiledropdown>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `DeesAppuiTabs`
|
|
||||||
Tab navigation component for organizing content sections.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<dees-appui-tabs
|
|
||||||
.tabs=${[
|
|
||||||
{
|
|
||||||
key: 'overview',
|
|
||||||
label: 'Overview',
|
|
||||||
icon: 'home',
|
|
||||||
content: html`<div>Overview content</div>`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'details',
|
|
||||||
label: 'Details',
|
|
||||||
icon: 'info',
|
|
||||||
content: html`<div>Details content</div>`
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
selectedTab="overview"
|
|
||||||
@tab-change=${handleTabChange}
|
|
||||||
></dees-appui-tabs>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `DeesAppuiView`
|
|
||||||
View container component for consistent page layouts.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<dees-appui-view
|
|
||||||
viewTitle="Dashboard"
|
|
||||||
viewSubtitle="System Overview"
|
|
||||||
.headerActions=${[
|
|
||||||
{ icon: 'refresh', action: handleRefresh },
|
|
||||||
{ icon: 'settings', action: handleSettings }
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<!-- View content -->
|
|
||||||
</dees-appui-view>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `DeesMobileNavigation`
|
|
||||||
Responsive navigation component for mobile devices.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<dees-mobile-navigation
|
|
||||||
.menuItems=${[
|
|
||||||
{
|
|
||||||
key: 'home',
|
|
||||||
label: 'Home',
|
|
||||||
icon: 'home',
|
|
||||||
action: () => navigate('home')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'profile',
|
|
||||||
label: 'Profile',
|
|
||||||
icon: 'user',
|
|
||||||
action: () => navigate('profile')
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
activeKey="home" // Currently active item
|
|
||||||
position="bottom" // Options: bottom, top
|
|
||||||
@item-click=${handleNavigationClick}
|
|
||||||
></dees-mobile-navigation>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Data Display Components
|
### Data Display Components
|
||||||
|
|
||||||
#### `DeesTable`
|
#### `DeesTable`
|
||||||
@@ -953,6 +845,19 @@ Advanced table component with sorting, filtering, and action support.
|
|||||||
></dees-table>
|
></dees-table>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### DeesTable (Updated)
|
||||||
|
|
||||||
|
Newer features available in `dees-table`:
|
||||||
|
- Schema-first columns or `displayFunction` rendering
|
||||||
|
- Sorting via header clicks with `aria-sort` + `sortChange`
|
||||||
|
- Global search with Lucene-like syntax; modes: `table`, `data`, `server`
|
||||||
|
- Per-column quick filters row; `showColumnFilters` and `column.filterable=false`
|
||||||
|
- Selection: `none` | `single` | `multi`, with select-all and `selectionChange`
|
||||||
|
- Sticky header + internal scroll (`stickyHeader`, `--table-max-height`)
|
||||||
|
- Rich actions: header/in-row/contextmenu/footer/doubleClick; pinned Actions column
|
||||||
|
- Editable cells via `editableFields`
|
||||||
|
- Drag & drop files onto rows
|
||||||
|
|
||||||
#### `DeesDataviewCodebox`
|
#### `DeesDataviewCodebox`
|
||||||
Code display component with syntax highlighting and line numbers.
|
Code display component with syntax highlighting and line numbers.
|
||||||
|
|
||||||
@@ -963,7 +868,7 @@ Code display component with syntax highlighting and line numbers.
|
|||||||
import { html } from '@design.estate/dees-element';
|
import { html } from '@design.estate/dees-element';
|
||||||
|
|
||||||
export const myComponent = () => {
|
export const myComponent = () => {
|
||||||
return html\`<div>Hello World</div>\`;
|
return html`<div>Hello World</div>`;
|
||||||
};
|
};
|
||||||
`}
|
`}
|
||||||
></dees-dataview-codebox>
|
></dees-dataview-codebox>
|
||||||
@@ -1016,37 +921,6 @@ PDF viewer component with navigation and zoom controls.
|
|||||||
></dees-pdf>
|
></dees-pdf>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- `DeesTable`:
|
|
||||||
- Sortable columns
|
|
||||||
- Searchable content
|
|
||||||
- Customizable row actions
|
|
||||||
- Selection support
|
|
||||||
- Form compatibility
|
|
||||||
- Custom display formatting
|
|
||||||
|
|
||||||
- `DeesDataviewCodebox`:
|
|
||||||
- Syntax highlighting for multiple languages
|
|
||||||
- Line numbering
|
|
||||||
- Copy to clipboard functionality
|
|
||||||
- Custom theme support
|
|
||||||
- Window-like appearance with controls
|
|
||||||
|
|
||||||
- `DeesDataviewStatusobject`:
|
|
||||||
- Hierarchical status display
|
|
||||||
- Color-coded status indicators
|
|
||||||
- Expandable details
|
|
||||||
- JSON export capability
|
|
||||||
- Customizable styling
|
|
||||||
|
|
||||||
- `DeesPdf`:
|
|
||||||
- Page navigation
|
|
||||||
- Zoom controls
|
|
||||||
- Download support
|
|
||||||
- Print functionality
|
|
||||||
- Responsive layout
|
|
||||||
- Loading states
|
|
||||||
|
|
||||||
#### `DeesStatsGrid`
|
#### `DeesStatsGrid`
|
||||||
A responsive grid component for displaying statistical data with various visualization types including numbers, gauges, percentages, and trends.
|
A responsive grid component for displaying statistical data with various visualization types including numbers, gauges, percentages, and trends.
|
||||||
|
|
||||||
@@ -1144,116 +1018,6 @@ A responsive grid component for displaying statistical data with various visuali
|
|||||||
></dees-statsgrid>
|
></dees-statsgrid>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Auto-responsive grid layout with configurable minimum tile width
|
|
||||||
- Multiple tile types for different data visualizations
|
|
||||||
- Full theme support (light/dark mode)
|
|
||||||
- Interactive tiles with action support
|
|
||||||
- Grid-level and tile-level actions
|
|
||||||
- Smooth animations and transitions
|
|
||||||
- Icon support for visual hierarchy
|
|
||||||
|
|
||||||
Tile Types:
|
|
||||||
1. **`number`** - Display numeric values with optional units
|
|
||||||
- Large, prominent value display
|
|
||||||
- Optional unit display
|
|
||||||
- Custom color support
|
|
||||||
- Description text
|
|
||||||
|
|
||||||
2. **`gauge`** - Circular gauge visualization
|
|
||||||
- Min/max value configuration
|
|
||||||
- Color thresholds for visual alerts
|
|
||||||
- Animated value transitions
|
|
||||||
- Compact circular design
|
|
||||||
|
|
||||||
3. **`percentage`** - Progress bar visualization
|
|
||||||
- Horizontal progress bar
|
|
||||||
- Percentage display overlay
|
|
||||||
- Custom color support
|
|
||||||
- Ideal for capacity metrics
|
|
||||||
|
|
||||||
4. **`trend`** - Mini sparkline chart
|
|
||||||
- Array of numeric values for trend data
|
|
||||||
- Area chart visualization
|
|
||||||
- Current value display
|
|
||||||
- Responsive SVG rendering
|
|
||||||
|
|
||||||
5. **`text`** - Simple text display
|
|
||||||
- Flexible text content
|
|
||||||
- Custom color support
|
|
||||||
- Ideal for status messages
|
|
||||||
|
|
||||||
Action System:
|
|
||||||
- **Grid Actions**: Displayed as buttons in the grid header
|
|
||||||
- Apply to the entire stats grid
|
|
||||||
- Use standard `dees-button` components
|
|
||||||
- Support icons and text
|
|
||||||
|
|
||||||
- **Tile Actions**: Context-specific actions per tile
|
|
||||||
- Single action: Direct click on tile
|
|
||||||
- Multiple actions: Right-click context menu
|
|
||||||
- Actions access tile data through closures
|
|
||||||
- Consistent with other library components
|
|
||||||
|
|
||||||
Configuration Options:
|
|
||||||
- `tiles`: Array of `IStatsTile` objects defining the grid content
|
|
||||||
- `gridActions`: Array of actions for the entire grid
|
|
||||||
- `minTileWidth`: Minimum width for tiles (default: 250px)
|
|
||||||
- `gap`: Space between tiles (default: 16px)
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
1. **Data Organization**
|
|
||||||
- Group related metrics together
|
|
||||||
- Use consistent units and scales
|
|
||||||
- Provide meaningful descriptions
|
|
||||||
- Choose appropriate tile types for data
|
|
||||||
|
|
||||||
2. **Visual Hierarchy**
|
|
||||||
- Use colors strategically for alerts
|
|
||||||
- Include relevant icons
|
|
||||||
- Keep titles concise
|
|
||||||
- Balance tile types for visual interest
|
|
||||||
|
|
||||||
3. **Interactivity**
|
|
||||||
- Provide relevant actions for detailed views
|
|
||||||
- Use tile actions for item-specific operations
|
|
||||||
- Use grid actions for global operations
|
|
||||||
- Keep action names clear and concise
|
|
||||||
|
|
||||||
4. **Performance**
|
|
||||||
- Update only changed tiles
|
|
||||||
- Use reasonable update intervals
|
|
||||||
- Batch updates when possible
|
|
||||||
- Consider data volume for trends
|
|
||||||
|
|
||||||
Common Use Cases:
|
|
||||||
- System monitoring dashboards
|
|
||||||
- Business intelligence displays
|
|
||||||
- Performance metrics
|
|
||||||
- Resource utilization
|
|
||||||
- Real-time statistics
|
|
||||||
- KPI tracking
|
|
||||||
|
|
||||||
Integration Example:
|
|
||||||
```typescript
|
|
||||||
// Real-time updates
|
|
||||||
setInterval(() => {
|
|
||||||
const grid = document.querySelector('dees-statsgrid');
|
|
||||||
const updatedTiles = [...grid.tiles];
|
|
||||||
|
|
||||||
// Update specific tile
|
|
||||||
const cpuTile = updatedTiles.find(t => t.id === 'cpu');
|
|
||||||
cpuTile.value = Math.round(Math.random() * 100);
|
|
||||||
|
|
||||||
// Update trend data
|
|
||||||
const trendTile = updatedTiles.find(t => t.id === 'requests');
|
|
||||||
trendTile.trendData = [...trendTile.trendData.slice(1),
|
|
||||||
Math.round(Math.random() * 100)];
|
|
||||||
|
|
||||||
grid.tiles = updatedTiles;
|
|
||||||
}, 3000);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `DeesPagination`
|
#### `DeesPagination`
|
||||||
Pagination component for navigating through large datasets.
|
Pagination component for navigating through large datasets.
|
||||||
|
|
||||||
@@ -1267,14 +1031,6 @@ Pagination component for navigating through large datasets.
|
|||||||
></dees-pagination>
|
></dees-pagination>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Page number navigation
|
|
||||||
- Previous/next buttons
|
|
||||||
- Jump to first/last page
|
|
||||||
- Configurable items per page
|
|
||||||
- Responsive design
|
|
||||||
- Keyboard navigation support
|
|
||||||
|
|
||||||
### Visualization Components
|
### Visualization Components
|
||||||
|
|
||||||
#### `DeesChartArea`
|
#### `DeesChartArea`
|
||||||
@@ -1304,22 +1060,6 @@ Area chart component built on ApexCharts for visualizing time-series data.
|
|||||||
></dees-chart-area>
|
></dees-chart-area>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Responsive design with automatic resizing
|
|
||||||
- Gradient fill support
|
|
||||||
- Interactive tooltips
|
|
||||||
- Grid customization
|
|
||||||
- Multiple series support
|
|
||||||
- Time-based x-axis
|
|
||||||
- Customizable styling
|
|
||||||
|
|
||||||
Configuration Options:
|
|
||||||
- Series data format: `{ x: timestamp, y: value }`
|
|
||||||
- Tooltip customization with datetime formatting
|
|
||||||
- Grid line styling and colors
|
|
||||||
- Gradient fill properties
|
|
||||||
- Chart dimensions and responsiveness
|
|
||||||
|
|
||||||
#### `DeesChartLog`
|
#### `DeesChartLog`
|
||||||
Specialized chart component for visualizing log data and events.
|
Specialized chart component for visualizing log data and events.
|
||||||
|
|
||||||
@@ -1343,44 +1083,6 @@ Specialized chart component for visualizing log data and events.
|
|||||||
></dees-chart-log>
|
></dees-chart-log>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Event timeline visualization
|
|
||||||
- Color-coded event types
|
|
||||||
- Interactive event details
|
|
||||||
- Filtering capabilities
|
|
||||||
- Zoom and pan support
|
|
||||||
- Time-based navigation
|
|
||||||
- Event clustering
|
|
||||||
|
|
||||||
Common Use Cases:
|
|
||||||
- System monitoring
|
|
||||||
- Performance tracking
|
|
||||||
- Resource utilization
|
|
||||||
- Event logging
|
|
||||||
- Time-series analysis
|
|
||||||
- Trend visualization
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
1. Data Formatting
|
|
||||||
- Use consistent timestamp formats
|
|
||||||
- Provide meaningful series names
|
|
||||||
- Include appropriate data points
|
|
||||||
|
|
||||||
2. Responsiveness
|
|
||||||
- Charts automatically adjust to container size
|
|
||||||
- Consider mobile viewports
|
|
||||||
- Set appropriate min/max dimensions
|
|
||||||
|
|
||||||
3. Interaction
|
|
||||||
- Enable relevant tooltips
|
|
||||||
- Configure meaningful click handlers
|
|
||||||
- Implement appropriate zoom levels
|
|
||||||
|
|
||||||
4. Styling
|
|
||||||
- Use consistent color schemes
|
|
||||||
- Configure appropriate grid lines
|
|
||||||
- Set readable font sizes
|
|
||||||
|
|
||||||
### Dialogs & Overlays Components
|
### Dialogs & Overlays Components
|
||||||
|
|
||||||
#### `DeesModal`
|
#### `DeesModal`
|
||||||
@@ -1424,14 +1126,6 @@ DeesModal.createAndShow({
|
|||||||
></dees-modal>
|
></dees-modal>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Backdrop blur effect
|
|
||||||
- Customizable content using HTML templates
|
|
||||||
- Flexible action buttons
|
|
||||||
- Outside click handling
|
|
||||||
- Animated transitions
|
|
||||||
- Automatic window layer management
|
|
||||||
|
|
||||||
#### `DeesContextmenu`
|
#### `DeesContextmenu`
|
||||||
Context menu component for right-click actions.
|
Context menu component for right-click actions.
|
||||||
|
|
||||||
@@ -1471,13 +1165,6 @@ const bubble = await DeesSpeechbubble.createAndShow(
|
|||||||
></dees-speechbubble>
|
></dees-speechbubble>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Automatic positioning
|
|
||||||
- Non-intrusive overlay
|
|
||||||
- Animated appearance
|
|
||||||
- Reference element tracking
|
|
||||||
- Custom styling options
|
|
||||||
|
|
||||||
#### `DeesWindowlayer`
|
#### `DeesWindowlayer`
|
||||||
Base overlay component used by modal dialogs and other overlay components.
|
Base overlay component used by modal dialogs and other overlay components.
|
||||||
|
|
||||||
@@ -1500,43 +1187,6 @@ const layer = await DeesWindowLayer.createAndShow({
|
|||||||
</dees-windowlayer>
|
</dees-windowlayer>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Backdrop blur support
|
|
||||||
- Click event handling
|
|
||||||
- Z-index management
|
|
||||||
- Animated transitions
|
|
||||||
- Flexible content container
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
|
|
||||||
1. Modal Dialogs
|
|
||||||
- Use for important user interactions
|
|
||||||
- Provide clear action buttons
|
|
||||||
- Include close/cancel options
|
|
||||||
- Handle outside clicks appropriately
|
|
||||||
- Use meaningful headings
|
|
||||||
|
|
||||||
2. Context Menus
|
|
||||||
- Group related actions
|
|
||||||
- Use consistent icons
|
|
||||||
- Provide keyboard shortcuts
|
|
||||||
- Consider position constraints
|
|
||||||
- Handle menu item states
|
|
||||||
|
|
||||||
3. Speech Bubbles
|
|
||||||
- Keep content concise
|
|
||||||
- Position strategically
|
|
||||||
- Avoid overlapping
|
|
||||||
- Consider mobile viewports
|
|
||||||
- Use appropriate timing
|
|
||||||
|
|
||||||
4. Window Layers
|
|
||||||
- Manage z-index carefully
|
|
||||||
- Handle backdrop interactions
|
|
||||||
- Consider performance impact
|
|
||||||
- Implement proper cleanup
|
|
||||||
- Manage multiple layers
|
|
||||||
|
|
||||||
### Navigation Components
|
### Navigation Components
|
||||||
|
|
||||||
#### `DeesStepper`
|
#### `DeesStepper`
|
||||||
@@ -1569,14 +1219,6 @@ Multi-step navigation component for guided user flows.
|
|||||||
></dees-stepper>
|
></dees-stepper>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Linear or non-linear progression
|
|
||||||
- Step validation
|
|
||||||
- Progress tracking
|
|
||||||
- Customizable step content
|
|
||||||
- Navigation controls
|
|
||||||
- Step completion indicators
|
|
||||||
|
|
||||||
#### `DeesProgressbar`
|
#### `DeesProgressbar`
|
||||||
Progress indicator component for tracking completion status.
|
Progress indicator component for tracking completion status.
|
||||||
|
|
||||||
@@ -1591,53 +1233,6 @@ Progress indicator component for tracking completion status.
|
|||||||
></dees-progressbar>
|
></dees-progressbar>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Determinate and indeterminate states
|
|
||||||
- Percentage display
|
|
||||||
- Custom styling options
|
|
||||||
- Status indicators
|
|
||||||
- Animation support
|
|
||||||
- Accessibility features
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
|
|
||||||
1. Stepper Implementation
|
|
||||||
- Clear step labels
|
|
||||||
- Validation feedback
|
|
||||||
- Progress indication
|
|
||||||
- Error handling
|
|
||||||
- Consistent navigation
|
|
||||||
|
|
||||||
2. Progress Tracking
|
|
||||||
- Accurate progress calculation
|
|
||||||
- Clear visual feedback
|
|
||||||
- Status communication
|
|
||||||
- Performance monitoring
|
|
||||||
- Error state handling
|
|
||||||
|
|
||||||
Common Use Cases:
|
|
||||||
|
|
||||||
1. Stepper
|
|
||||||
- Multi-step forms
|
|
||||||
- User onboarding
|
|
||||||
- Checkout processes
|
|
||||||
- Setup wizards
|
|
||||||
- Tutorial flows
|
|
||||||
|
|
||||||
2. Progress Bar
|
|
||||||
- File uploads
|
|
||||||
- Process tracking
|
|
||||||
- Loading indicators
|
|
||||||
- Task completion
|
|
||||||
- Step progression
|
|
||||||
|
|
||||||
Accessibility Considerations:
|
|
||||||
- Keyboard navigation support
|
|
||||||
- ARIA labels and roles
|
|
||||||
- Focus management
|
|
||||||
- Screen reader compatibility
|
|
||||||
- Color contrast compliance
|
|
||||||
|
|
||||||
### Development Components
|
### Development Components
|
||||||
|
|
||||||
#### `DeesEditor`
|
#### `DeesEditor`
|
||||||
@@ -1657,17 +1252,6 @@ Code editor component with syntax highlighting and code completion, powered by M
|
|||||||
></dees-editor>
|
></dees-editor>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Syntax highlighting for multiple languages
|
|
||||||
- Code completion
|
|
||||||
- Line numbers
|
|
||||||
- Minimap navigation
|
|
||||||
- Customizable options
|
|
||||||
- Theme support
|
|
||||||
- Search and replace
|
|
||||||
- Multiple cursors
|
|
||||||
- Code folding
|
|
||||||
|
|
||||||
#### `DeesEditorMarkdown`
|
#### `DeesEditorMarkdown`
|
||||||
Markdown editor component with live preview.
|
Markdown editor component with live preview.
|
||||||
|
|
||||||
@@ -1684,16 +1268,6 @@ Markdown editor component with live preview.
|
|||||||
></dees-editor-markdown>
|
></dees-editor-markdown>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Live preview
|
|
||||||
- Toolbar for common formatting
|
|
||||||
- Markdown syntax highlighting
|
|
||||||
- Image upload support
|
|
||||||
- Table editor
|
|
||||||
- Customizable preview styles
|
|
||||||
- Spellcheck integration
|
|
||||||
- Auto-save functionality
|
|
||||||
|
|
||||||
#### `DeesEditorMarkdownoutlet`
|
#### `DeesEditorMarkdownoutlet`
|
||||||
Markdown preview component for rendering markdown content.
|
Markdown preview component for rendering markdown content.
|
||||||
|
|
||||||
@@ -1706,14 +1280,6 @@ Markdown preview component for rendering markdown content.
|
|||||||
></dees-editor-markdownoutlet>
|
></dees-editor-markdownoutlet>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Safe markdown rendering
|
|
||||||
- Multiple themes
|
|
||||||
- Plugin support (mermaid diagrams, syntax highlighting)
|
|
||||||
- XSS protection
|
|
||||||
- Custom CSS injection
|
|
||||||
- Responsive images
|
|
||||||
|
|
||||||
#### `DeesTerminal`
|
#### `DeesTerminal`
|
||||||
Terminal emulator component for command-line interface.
|
Terminal emulator component for command-line interface.
|
||||||
|
|
||||||
@@ -1730,16 +1296,6 @@ Terminal emulator component for command-line interface.
|
|||||||
></dees-terminal>
|
></dees-terminal>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Command history
|
|
||||||
- Custom commands
|
|
||||||
- Auto-completion
|
|
||||||
- Copy/paste support
|
|
||||||
- ANSI color support
|
|
||||||
- Scrollback buffer
|
|
||||||
- Keyboard shortcuts
|
|
||||||
- Command aliases
|
|
||||||
|
|
||||||
#### `DeesUpdater`
|
#### `DeesUpdater`
|
||||||
Component for managing application updates and version control.
|
Component for managing application updates and version control.
|
||||||
|
|
||||||
@@ -1753,112 +1309,6 @@ Component for managing application updates and version control.
|
|||||||
></dees-updater>
|
></dees-updater>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Version checking
|
|
||||||
- Update notifications
|
|
||||||
- Progress tracking
|
|
||||||
- Automatic updates
|
|
||||||
- Rollback support
|
|
||||||
- Update scheduling
|
|
||||||
- Dependency management
|
|
||||||
|
|
||||||
Best Practices:
|
|
||||||
|
|
||||||
1. Code Editor Usage
|
|
||||||
- Configure appropriate language
|
|
||||||
- Set reasonable defaults
|
|
||||||
- Handle content changes
|
|
||||||
- Manage undo/redo stack
|
|
||||||
- Consider performance
|
|
||||||
|
|
||||||
2. Markdown Editing
|
|
||||||
- Provide clear toolbar
|
|
||||||
- Show live preview
|
|
||||||
- Handle image uploads
|
|
||||||
- Support shortcuts
|
|
||||||
- Maintain consistent styling
|
|
||||||
|
|
||||||
3. Terminal Implementation
|
|
||||||
- Clear command documentation
|
|
||||||
- Handle errors gracefully
|
|
||||||
- Provide command history
|
|
||||||
- Support common shortcuts
|
|
||||||
- Implement auto-completion
|
|
||||||
|
|
||||||
4. Update Management
|
|
||||||
- Regular version checks
|
|
||||||
- Clear update messaging
|
|
||||||
- Progress indication
|
|
||||||
- Error recovery
|
|
||||||
- User confirmation
|
|
||||||
|
|
||||||
Common Use Cases:
|
|
||||||
|
|
||||||
1. Code Editor
|
|
||||||
- Configuration editing
|
|
||||||
- Script development
|
|
||||||
- Code snippets
|
|
||||||
- Documentation
|
|
||||||
- Teaching tools
|
|
||||||
|
|
||||||
2. Markdown Editor
|
|
||||||
- Documentation
|
|
||||||
- Content creation
|
|
||||||
- README files
|
|
||||||
- Blog posts
|
|
||||||
- Release notes
|
|
||||||
|
|
||||||
3. Terminal
|
|
||||||
- Command execution
|
|
||||||
- System monitoring
|
|
||||||
- Development tools
|
|
||||||
- Debugging
|
|
||||||
- Training environments
|
|
||||||
|
|
||||||
4. Updater
|
|
||||||
- Application updates
|
|
||||||
- Plugin management
|
|
||||||
- Feature deployment
|
|
||||||
- Security patches
|
|
||||||
- Configuration updates
|
|
||||||
|
|
||||||
Integration Examples:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// Combining components for a development environment
|
|
||||||
<dees-form>
|
|
||||||
<dees-editor
|
|
||||||
.language=${'javascript'}
|
|
||||||
.value=${code}
|
|
||||||
@change=${updatePreview}
|
|
||||||
></dees-editor>
|
|
||||||
|
|
||||||
<dees-terminal
|
|
||||||
.commands=${devCommands}
|
|
||||||
@command=${executeCommand}
|
|
||||||
></dees-terminal>
|
|
||||||
|
|
||||||
<dees-updater
|
|
||||||
.currentVersion=${appVersion}
|
|
||||||
@update-available=${notifyUser}
|
|
||||||
></dees-updater>
|
|
||||||
</dees-form>
|
|
||||||
```
|
|
||||||
|
|
||||||
Performance Considerations:
|
|
||||||
- Lazy loading of heavy components
|
|
||||||
- Memory management
|
|
||||||
- Resource cleanup
|
|
||||||
- Event handling optimization
|
|
||||||
- Efficient updates
|
|
||||||
|
|
||||||
Accessibility Features:
|
|
||||||
- Keyboard navigation
|
|
||||||
- Screen reader support
|
|
||||||
- High contrast themes
|
|
||||||
- Focus management
|
|
||||||
- ARIA attributes
|
|
||||||
|
|
||||||
### Auth & Utilities Components
|
### Auth & Utilities Components
|
||||||
|
|
||||||
#### `DeesSimpleAppdash`
|
#### `DeesSimpleAppdash`
|
||||||
@@ -1881,13 +1331,6 @@ Simple application dashboard component for quick prototyping.
|
|||||||
</dees-simple-appdash>
|
</dees-simple-appdash>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
|
||||||
- Quick setup dashboard layout
|
|
||||||
- Built-in navigation
|
|
||||||
- User profile section
|
|
||||||
- Responsive design
|
|
||||||
- Minimal configuration
|
|
||||||
|
|
||||||
#### `DeesSimpleLogin`
|
#### `DeesSimpleLogin`
|
||||||
Simple login form component with validation and customization.
|
Simple login form component with validation and customization.
|
||||||
|
|
||||||
@@ -1904,14 +1347,33 @@ Simple login form component with validation and customization.
|
|||||||
></dees-simple-login>
|
></dees-simple-login>
|
||||||
```
|
```
|
||||||
|
|
||||||
Key Features:
|
### Shopping Components
|
||||||
- Customizable fields
|
|
||||||
- Built-in validation
|
#### `DeesShoppingProductcard`
|
||||||
- Remember me option
|
Product card component for e-commerce applications.
|
||||||
- Forgot password link
|
|
||||||
- Custom branding
|
```typescript
|
||||||
- Responsive layout
|
<dees-shopping-productcard
|
||||||
- Loading states
|
.productData=${{
|
||||||
|
name: 'Premium Headphones',
|
||||||
|
category: 'Electronics',
|
||||||
|
description: 'High-quality wireless headphones with noise cancellation',
|
||||||
|
price: 199.99,
|
||||||
|
originalPrice: 249.99, // Shows strikethrough price
|
||||||
|
currency: '$',
|
||||||
|
inStock: true,
|
||||||
|
stockText: 'In Stock', // Custom stock text
|
||||||
|
imageUrl: '/images/headphones.jpg',
|
||||||
|
iconName: 'lucide:headphones' // Fallback icon if no image
|
||||||
|
}}
|
||||||
|
quantity={1} // Current quantity
|
||||||
|
showQuantitySelector={true} // Show quantity selector
|
||||||
|
selectable={false} // Enable selection mode
|
||||||
|
selected={false} // Selection state
|
||||||
|
@quantityChange=${(e) => handleQuantityChange(e.detail)}
|
||||||
|
@selectionChange=${(e) => handleSelectionChange(e.detail)}
|
||||||
|
></dees-shopping-productcard>
|
||||||
|
```
|
||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
|
BIN
readme.plan.md
BIN
readme.plan.md
Binary file not shown.
784
readme.playbook.md
Normal file
784
readme.playbook.md
Normal file
@@ -0,0 +1,784 @@
|
|||||||
|
# UI Components Playbook
|
||||||
|
|
||||||
|
This playbook provides comprehensive guidance for creating and maintaining UI components in the @design.estate/dees-catalog library. Follow these patterns and best practices to ensure consistency, maintainability, and quality.
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
1. [Component Creation Checklist](#component-creation-checklist)
|
||||||
|
2. [Architectural Patterns](#architectural-patterns)
|
||||||
|
3. [Component Types and Base Classes](#component-types-and-base-classes)
|
||||||
|
4. [Theming System](#theming-system)
|
||||||
|
5. [Event Handling](#event-handling)
|
||||||
|
6. [State Management](#state-management)
|
||||||
|
7. [Form Components](#form-components)
|
||||||
|
8. [Overlay Components](#overlay-components)
|
||||||
|
9. [Complex Components](#complex-components)
|
||||||
|
10. [Performance Optimization](#performance-optimization)
|
||||||
|
11. [Focus Management](#focus-management)
|
||||||
|
12. [Demo System](#demo-system)
|
||||||
|
13. [Common Pitfalls and Anti-patterns](#common-pitfalls-and-anti-patterns)
|
||||||
|
14. [Code Examples](#code-examples)
|
||||||
|
|
||||||
|
## Component Creation Checklist
|
||||||
|
|
||||||
|
When creating a new component, follow this checklist:
|
||||||
|
|
||||||
|
- [ ] Choose the appropriate base class (`DeesElement` or `DeesInputBase`)
|
||||||
|
- [ ] Use `@customElement('dees-componentname')` decorator
|
||||||
|
- [ ] Implement consistent theming with `cssManager.bdTheme()`
|
||||||
|
- [ ] Create demo function in separate `.demo.ts` file
|
||||||
|
- [ ] Export component from `ts_web/elements/index.ts`
|
||||||
|
- [ ] Use proper TypeScript types and interfaces (prefix with `I` for interfaces, `T` for types)
|
||||||
|
- [ ] Implement proper event handling with bubbling and composition
|
||||||
|
- [ ] Consider mobile responsiveness
|
||||||
|
- [ ] Add focus states for accessibility
|
||||||
|
- [ ] Clean up resources in `destroy()` method
|
||||||
|
- [ ] Follow lowercase naming convention for files
|
||||||
|
- [ ] Add z-index registry support if it's an overlay component
|
||||||
|
|
||||||
|
## Architectural Patterns
|
||||||
|
|
||||||
|
### Base Component Structure
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { customElement, property, state, css, TemplateResult, html } from '@design.estate/dees-element';
|
||||||
|
import { DeesElement } from '@design.estate/dees-element';
|
||||||
|
import * as cssManager from './00colors.js';
|
||||||
|
import * as demoFunc from './dees-componentname.demo.js';
|
||||||
|
|
||||||
|
@customElement('dees-componentname')
|
||||||
|
export class DeesComponentName extends DeesElement {
|
||||||
|
// Static demo reference
|
||||||
|
public static demo = demoFunc.demoFunc;
|
||||||
|
|
||||||
|
// Public properties (reactive, can be set via attributes)
|
||||||
|
@property({ type: String })
|
||||||
|
public label: string = '';
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public disabled: boolean = false;
|
||||||
|
|
||||||
|
// Internal state (reactive, but not exposed as attributes)
|
||||||
|
@state()
|
||||||
|
private internalState: string = '';
|
||||||
|
|
||||||
|
// Static styles with theme support
|
||||||
|
public static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
||||||
|
}
|
||||||
|
`
|
||||||
|
];
|
||||||
|
|
||||||
|
// Render method
|
||||||
|
public render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
<div class="main-container">
|
||||||
|
<!-- Component content -->
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lifecycle methods
|
||||||
|
public connectedCallback() {
|
||||||
|
super.connectedCallback();
|
||||||
|
// Setup that needs DOM access
|
||||||
|
}
|
||||||
|
|
||||||
|
public async firstUpdated() {
|
||||||
|
// One-time initialization after first render
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
public destroy() {
|
||||||
|
// Clean up listeners, observers, registrations
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Patterns
|
||||||
|
|
||||||
|
#### 1. Separation of Concerns (Complex Components)
|
||||||
|
|
||||||
|
For complex components like WYSIWYG editors, separate concerns into handler classes:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export class DeesComplexComponent extends DeesElement {
|
||||||
|
// Orchestrator pattern - main component coordinates handlers
|
||||||
|
private inputHandler: InputHandler;
|
||||||
|
private stateHandler: StateHandler;
|
||||||
|
private renderHandler: RenderHandler;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.inputHandler = new InputHandler(this);
|
||||||
|
this.stateHandler = new StateHandler(this);
|
||||||
|
this.renderHandler = new RenderHandler(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Singleton Pattern (Global Components)
|
||||||
|
|
||||||
|
For global UI elements like menus:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export class DeesGlobalMenu extends DeesElement {
|
||||||
|
private static instance: DeesGlobalMenu;
|
||||||
|
|
||||||
|
public static getInstance(): DeesGlobalMenu {
|
||||||
|
if (!DeesGlobalMenu.instance) {
|
||||||
|
DeesGlobalMenu.instance = new DeesGlobalMenu();
|
||||||
|
document.body.appendChild(DeesGlobalMenu.instance);
|
||||||
|
}
|
||||||
|
return DeesGlobalMenu.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Registry Pattern (Z-Index Management)
|
||||||
|
|
||||||
|
Use centralized registries for global state:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class ComponentRegistry {
|
||||||
|
private static instance: ComponentRegistry;
|
||||||
|
private registry = new WeakMap<HTMLElement, number>();
|
||||||
|
|
||||||
|
public register(element: HTMLElement, value: number) {
|
||||||
|
this.registry.set(element, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unregister(element: HTMLElement) {
|
||||||
|
this.registry.delete(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Component Types and Base Classes
|
||||||
|
|
||||||
|
### Standard Component (extends DeesElement)
|
||||||
|
|
||||||
|
Use for most UI components:
|
||||||
|
- Buttons, badges, icons
|
||||||
|
- Layout components
|
||||||
|
- Data display components
|
||||||
|
- Overlay components
|
||||||
|
|
||||||
|
### Form Input Component (extends DeesInputBase)
|
||||||
|
|
||||||
|
Use for all form inputs:
|
||||||
|
- Text inputs, dropdowns, checkboxes
|
||||||
|
- Date pickers, file uploads
|
||||||
|
- Rich text editors
|
||||||
|
|
||||||
|
**Required implementations:**
|
||||||
|
```typescript
|
||||||
|
export class DeesInputCustom extends DeesInputBase<ValueType> {
|
||||||
|
// Required: Get current value
|
||||||
|
public getValue(): ValueType {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required: Set value programmatically
|
||||||
|
public setValue(value: ValueType): void {
|
||||||
|
this.value = value;
|
||||||
|
this.changeSubject.next(this); // Notify form
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: Custom validation
|
||||||
|
public async validate(): Promise<boolean> {
|
||||||
|
// Custom validation logic
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Theming System
|
||||||
|
|
||||||
|
### DO: Use Theme Functions
|
||||||
|
|
||||||
|
Always use `cssManager.bdTheme()` for colors that change between themes:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT
|
||||||
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
||||||
|
color: ${cssManager.bdTheme('#000000', '#ffffff')};
|
||||||
|
border: 1px solid ${cssManager.bdTheme('#e5e5e5', '#333333')};
|
||||||
|
|
||||||
|
// ❌ INCORRECT
|
||||||
|
background: #ffffff; // Hard-coded color
|
||||||
|
color: var(--custom-color); // Custom CSS variable
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Use Consistent Color Values
|
||||||
|
|
||||||
|
Reference shared color constants when possible:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// From 00colors.ts
|
||||||
|
background: ${cssManager.bdTheme(colors.bright.background, colors.dark.background)};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Event Handling
|
||||||
|
|
||||||
|
### DO: Dispatch Custom Events Properly
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT - Events bubble and cross shadow DOM
|
||||||
|
this.dispatchEvent(new CustomEvent('dees-componentname-change', {
|
||||||
|
detail: { value: this.value },
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ❌ INCORRECT - Event won't propagate properly
|
||||||
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
detail: { value: this.value }
|
||||||
|
// Missing bubbles and composed
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Use Event Delegation
|
||||||
|
|
||||||
|
For dynamic content, use event delegation:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT - Single listener for all items
|
||||||
|
this.addEventListener('click', (e: MouseEvent) => {
|
||||||
|
const item = (e.target as HTMLElement).closest('.item');
|
||||||
|
if (item) {
|
||||||
|
this.handleItemClick(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ❌ INCORRECT - Multiple listeners
|
||||||
|
this.items.forEach(item => {
|
||||||
|
item.addEventListener('click', () => this.handleItemClick(item));
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## State Management
|
||||||
|
|
||||||
|
### DO: Use Appropriate Property Decorators
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Public API - use @property
|
||||||
|
@property({ type: String })
|
||||||
|
public label: string;
|
||||||
|
|
||||||
|
// Internal state - use @state
|
||||||
|
@state()
|
||||||
|
private isLoading: boolean = false;
|
||||||
|
|
||||||
|
// Reflect to attribute when needed
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public disabled: boolean = false;
|
||||||
|
```
|
||||||
|
|
||||||
|
### DON'T: Manipulate State in Render
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ INCORRECT - Side effects in render
|
||||||
|
public render() {
|
||||||
|
this.counter++; // Don't modify state
|
||||||
|
return html`<div>${this.counter}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ CORRECT - Pure render function
|
||||||
|
public render() {
|
||||||
|
return html`<div>${this.counter}</div>`;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Form Components
|
||||||
|
|
||||||
|
### DO: Extend DeesInputBase
|
||||||
|
|
||||||
|
All form inputs must extend the base class:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export class DeesInputNew extends DeesInputBase<string> {
|
||||||
|
// Inherits: key, label, value, required, disabled, validationState
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Emit Changes Consistently
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
private handleInput(e: Event) {
|
||||||
|
this.value = (e.target as HTMLInputElement).value;
|
||||||
|
this.changeSubject.next(this); // Notify form system
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Support Standard Form Properties
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// All form inputs should support:
|
||||||
|
@property() public key: string;
|
||||||
|
@property() public label: string;
|
||||||
|
@property() public required: boolean = false;
|
||||||
|
@property() public disabled: boolean = false;
|
||||||
|
@property() public validationState: 'valid' | 'warn' | 'invalid';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Overlay Components
|
||||||
|
|
||||||
|
### DO: Use Z-Index Registry
|
||||||
|
|
||||||
|
Never hardcode z-index values:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT
|
||||||
|
import { zIndexRegistry } from './00zindex.js';
|
||||||
|
|
||||||
|
public async show() {
|
||||||
|
this.modalZIndex = zIndexRegistry.getNextZIndex();
|
||||||
|
zIndexRegistry.register(this, this.modalZIndex);
|
||||||
|
this.style.zIndex = `${this.modalZIndex}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async hide() {
|
||||||
|
zIndexRegistry.unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❌ INCORRECT
|
||||||
|
public async show() {
|
||||||
|
this.style.zIndex = '9999'; // Hardcoded z-index
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Use Window Layers
|
||||||
|
|
||||||
|
For modal backdrops:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { DeesWindowLayer } from './dees-windowlayer.js';
|
||||||
|
|
||||||
|
private windowLayer: DeesWindowLayer;
|
||||||
|
|
||||||
|
public async show() {
|
||||||
|
this.windowLayer = new DeesWindowLayer();
|
||||||
|
this.windowLayer.zIndex = zIndexRegistry.getNextZIndex();
|
||||||
|
document.body.append(this.windowLayer);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Complex Components
|
||||||
|
|
||||||
|
### DO: Use Handler Classes
|
||||||
|
|
||||||
|
For complex logic, separate into specialized handlers:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// wysiwyg/handlers/input.handler.ts
|
||||||
|
export class InputHandler {
|
||||||
|
constructor(private component: DeesInputWysiwyg) {}
|
||||||
|
|
||||||
|
public handleInput(event: InputEvent) {
|
||||||
|
// Specialized input handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main component orchestrates
|
||||||
|
export class DeesInputWysiwyg extends DeesInputBase {
|
||||||
|
private inputHandler = new InputHandler(this);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Use Programmatic Rendering
|
||||||
|
|
||||||
|
For performance-critical updates that shouldn't trigger re-renders:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT - Direct DOM manipulation when needed
|
||||||
|
private updateBlockContent(blockId: string, content: string) {
|
||||||
|
const blockElement = this.shadowRoot.querySelector(`#${blockId}`);
|
||||||
|
if (blockElement) {
|
||||||
|
blockElement.textContent = content; // Direct update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❌ INCORRECT - Triggering full re-render
|
||||||
|
private updateBlockContent(blockId: string, content: string) {
|
||||||
|
this.blocks.find(b => b.id === blockId).content = content;
|
||||||
|
this.requestUpdate(); // Unnecessary re-render
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Performance Optimization
|
||||||
|
|
||||||
|
### DO: Debounce Expensive Operations
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
private resizeTimeout: number;
|
||||||
|
|
||||||
|
private handleResize = () => {
|
||||||
|
clearTimeout(this.resizeTimeout);
|
||||||
|
this.resizeTimeout = window.setTimeout(() => {
|
||||||
|
this.updateLayout();
|
||||||
|
}, 250);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Use Observers Efficiently
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Clean up observers
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
this.resizeObserver?.disconnect();
|
||||||
|
this.mutationObserver?.disconnect();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Implement Virtual Scrolling
|
||||||
|
|
||||||
|
For large lists:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Only render visible items
|
||||||
|
private getVisibleItems() {
|
||||||
|
const scrollTop = this.scrollContainer.scrollTop;
|
||||||
|
const containerHeight = this.scrollContainer.clientHeight;
|
||||||
|
const itemHeight = 50;
|
||||||
|
|
||||||
|
const startIndex = Math.floor(scrollTop / itemHeight);
|
||||||
|
const endIndex = Math.ceil((scrollTop + containerHeight) / itemHeight);
|
||||||
|
|
||||||
|
return this.items.slice(startIndex, endIndex);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Focus Management
|
||||||
|
|
||||||
|
### DO: Handle Focus Timing
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ✅ CORRECT - Wait for render
|
||||||
|
async focusInput() {
|
||||||
|
await this.updateComplete;
|
||||||
|
await new Promise(resolve => requestAnimationFrame(resolve));
|
||||||
|
this.inputElement?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❌ INCORRECT - Focus too early
|
||||||
|
focusInput() {
|
||||||
|
this.inputElement?.focus(); // Element might not exist
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Prevent Focus Loss
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// For global menus
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
// Prevent focus loss when clicking menu
|
||||||
|
this.addEventListener('mousedown', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Implement Blur Debouncing
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
private blurTimeout: number;
|
||||||
|
|
||||||
|
private handleBlur = () => {
|
||||||
|
clearTimeout(this.blurTimeout);
|
||||||
|
this.blurTimeout = window.setTimeout(() => {
|
||||||
|
// Check if truly blurred
|
||||||
|
if (!this.contains(document.activeElement)) {
|
||||||
|
this.handleTrueBlur();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Demo System
|
||||||
|
|
||||||
|
### DO: Create Comprehensive Demos
|
||||||
|
|
||||||
|
Every component needs a demo:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// dees-button.demo.ts
|
||||||
|
import { html } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
export const demoFunc = () => html`
|
||||||
|
<dees-button>Default Button</dees-button>
|
||||||
|
<dees-button type="primary">Primary Button</dees-button>
|
||||||
|
<dees-button type="danger" disabled>Disabled Danger</dees-button>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// In component file
|
||||||
|
import * as demoFunc from './dees-button.demo.js';
|
||||||
|
|
||||||
|
export class DeesButton extends DeesElement {
|
||||||
|
public static demo = demoFunc.demoFunc;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### DO: Include All Variants
|
||||||
|
|
||||||
|
Show all component states and variations in demos:
|
||||||
|
- Default state
|
||||||
|
- Different types/variants
|
||||||
|
- Disabled state
|
||||||
|
- Loading state
|
||||||
|
- Error states
|
||||||
|
- Edge cases (long text, empty content)
|
||||||
|
|
||||||
|
## Common Pitfalls and Anti-patterns
|
||||||
|
|
||||||
|
### ❌ DON'T: Hardcode Z-Index Values
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
this.style.zIndex = '9999';
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
this.style.zIndex = `${zIndexRegistry.getNextZIndex()}`;
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Skip Base Classes
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG - Form input without base class
|
||||||
|
export class DeesInputCustom extends DeesElement {
|
||||||
|
// Missing standard form functionality
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
export class DeesInputCustom extends DeesInputBase<string> {
|
||||||
|
// Inherits all form functionality
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Forget Theme Support
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
background-color: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
||||||
|
color: ${cssManager.bdTheme('#000000', '#ffffff')};
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Create Components Without Demos
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
export class DeesComponent extends DeesElement {
|
||||||
|
// No demo property
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
export class DeesComponent extends DeesElement {
|
||||||
|
public static demo = demoFunc.demoFunc;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Emit Non-Bubbling Events
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
detail: this.value
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
detail: this.value,
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Skip Cleanup
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
public connectedCallback() {
|
||||||
|
window.addEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
public connectedCallback() {
|
||||||
|
super.connectedCallback();
|
||||||
|
window.addEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public disconnectedCallback() {
|
||||||
|
super.disconnectedCallback();
|
||||||
|
window.removeEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Use Inline Styles for Theming
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
<div style="background-color: ${this.darkMode ? '#000' : '#fff'}">
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
<div class="themed-container">
|
||||||
|
// In styles:
|
||||||
|
.themed-container {
|
||||||
|
background-color: ${cssManager.bdTheme('#ffffff', '#000000')};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ DON'T: Forget Mobile Responsiveness
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// ❌ WRONG
|
||||||
|
:host {
|
||||||
|
width: 800px; // Fixed width
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ CORRECT
|
||||||
|
:host {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 800px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
:host {
|
||||||
|
/* Mobile adjustments */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code Examples
|
||||||
|
|
||||||
|
### Example: Creating a New Button Variant
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// dees-special-button.ts
|
||||||
|
import { customElement, property, css, html } from '@design.estate/dees-element';
|
||||||
|
import { DeesElement } from '@design.estate/dees-element';
|
||||||
|
import * as cssManager from './00colors.js';
|
||||||
|
import * as demoFunc from './dees-special-button.demo.js';
|
||||||
|
|
||||||
|
@customElement('dees-special-button')
|
||||||
|
export class DeesSpecialButton extends DeesElement {
|
||||||
|
public static demo = demoFunc.demoFunc;
|
||||||
|
|
||||||
|
@property({ type: String })
|
||||||
|
public text: string = 'Click me';
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public loading: boolean = false;
|
||||||
|
|
||||||
|
public static styles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: ${cssManager.bdTheme('#0066ff', '#0044cc')};
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 8px ${cssManager.bdTheme('rgba(0,0,0,0.1)', 'rgba(0,0,0,0.3)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([loading]) .button {
|
||||||
|
opacity: 0.7;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
];
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
return html`
|
||||||
|
<button class="button" ?disabled=${this.loading} @click=${this.handleClick}>
|
||||||
|
${this.loading ? html`<dees-spinner size="small"></dees-spinner>` : this.text}
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleClick() {
|
||||||
|
this.dispatchEvent(new CustomEvent('special-click', {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example: Creating a Form Input
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// dees-input-special.ts
|
||||||
|
export class DeesInputSpecial extends DeesInputBase<string> {
|
||||||
|
public static demo = demoFunc.demoFunc;
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
return html`
|
||||||
|
<dees-label .label=${this.label} .required=${this.required}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
.value=${this.value || ''}
|
||||||
|
?disabled=${this.disabled}
|
||||||
|
@input=${this.handleInput}
|
||||||
|
@blur=${this.handleBlur}
|
||||||
|
/>
|
||||||
|
</dees-label>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleInput(e: Event) {
|
||||||
|
this.value = (e.target as HTMLInputElement).value;
|
||||||
|
this.changeSubject.next(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleBlur() {
|
||||||
|
this.dispatchEvent(new CustomEvent('blur', {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public getValue(): string {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setValue(value: string): void {
|
||||||
|
this.value = value;
|
||||||
|
this.changeSubject.next(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This playbook represents the collective wisdom and patterns found in the @design.estate/dees-catalog component library. Following these guidelines will help you create components that are:
|
||||||
|
|
||||||
|
- **Consistent**: Following established patterns
|
||||||
|
- **Maintainable**: Easy to understand and modify
|
||||||
|
- **Performant**: Optimized for real-world use
|
||||||
|
- **Accessible**: Usable by everyone
|
||||||
|
- **Theme-aware**: Supporting light and dark modes
|
||||||
|
- **Well-integrated**: Working seamlessly with the component ecosystem
|
||||||
|
|
||||||
|
Remember: When in doubt, look at existing components for examples. The codebase itself is the best documentation of these patterns in action.
|
@@ -1,138 +0,0 @@
|
|||||||
# WYSIWYG Editor Refactoring Progress Summary
|
|
||||||
|
|
||||||
## Latest Updates
|
|
||||||
|
|
||||||
### Selection Highlighting Fix ✅
|
|
||||||
- **Issue**: "Paragraphs are not highlighted consistently, headings are always highlighted"
|
|
||||||
- **Root Cause**: The `shouldUpdate` method in `dees-wysiwyg-block.ts` was using a generic `.block` selector that would match the first element with that class, not necessarily the correct block element
|
|
||||||
- **Solution**: Changed the selector to be more specific: `.block.${blockType}` which ensures the correct element is found for each block type
|
|
||||||
- **Result**: All block types now highlight consistently when selected
|
|
||||||
|
|
||||||
### Enter Key Block Creation Fix ✅
|
|
||||||
- **Issue**: "When pressing enter and jumping to new block then typing something: The cursor is not at the beginning of the new block and there is content"
|
|
||||||
- **Root Cause**: Block handlers were rendering content with template syntax `${block.content || ''}` in their render methods, which violates the static HTML principle
|
|
||||||
- **Solution**:
|
|
||||||
- Removed all `${block.content}` from render methods in paragraph, heading, quote, and code block handlers
|
|
||||||
- Content is now set programmatically in the setup() method only when needed
|
|
||||||
- Fixed `setCursorToStart` and `setCursorToEnd` to always find elements fresh instead of relying on cached `blockElement`
|
|
||||||
- **Result**: New empty blocks remain truly empty, cursor positioning works correctly
|
|
||||||
|
|
||||||
### Backspace Key Deletion Fix ✅
|
|
||||||
- **Issue**: "After typing in a new block, pressing backspace deletes the whole block instead of just the last character"
|
|
||||||
- **Root Cause**:
|
|
||||||
1. `getCursorPositionInElement` was using `element.contains()` which doesn't work across Shadow DOM boundaries
|
|
||||||
2. The backspace handler was checking `block.content === ''` which only contains the stored content, not the actual DOM content
|
|
||||||
- **Solution**:
|
|
||||||
1. Fixed `getCursorPositionInElement` to use `containsAcrossShadowDOM` for proper Shadow DOM support
|
|
||||||
2. Updated backspace handler to get actual content from DOM using `blockComponent.getContent()` instead of relying on stored `block.content`
|
|
||||||
3. Added debug logging to track cursor position and content state
|
|
||||||
- **Result**: Backspace now correctly deletes individual characters instead of the whole block
|
|
||||||
|
|
||||||
### Arrow Left Navigation Fix ✅
|
|
||||||
- **Issue**: "When jumping to the previous block from the beginning of a block with arrow left, the cursor should be at the end of the previous block, not at the start"
|
|
||||||
- **Root Cause**: Browser's default focus behavior places cursor at the beginning of contenteditable elements, overriding our cursor positioning
|
|
||||||
- **Solution**: For 'end' position, set up the selection range BEFORE focusing the element:
|
|
||||||
1. Create a range pointing to the end of content
|
|
||||||
2. Apply the selection
|
|
||||||
3. Then focus the element (which preserves the existing selection)
|
|
||||||
4. Only use setCursorToEnd for empty blocks
|
|
||||||
- **Result**: Arrow left navigation now correctly places cursor at the end of the previous block
|
|
||||||
|
|
||||||
## Completed Phases
|
|
||||||
|
|
||||||
### Phase 1: Infrastructure ✅
|
|
||||||
- Created modular block handler architecture
|
|
||||||
- Implemented `IBlockHandler` interface and `BaseBlockHandler` class
|
|
||||||
- Created `BlockRegistry` for dynamic block type registration
|
|
||||||
- Set up proper file structure under `blocks/` directory
|
|
||||||
|
|
||||||
### Phase 2: Proof of Concept ✅
|
|
||||||
- Successfully migrated divider block as the simplest example
|
|
||||||
- Validated the architecture works correctly
|
|
||||||
- Established patterns for block migration
|
|
||||||
|
|
||||||
### Phase 3: Text Blocks ✅
|
|
||||||
- **Paragraph Block**: Full editing support with text splitting, selection handling, and cursor tracking
|
|
||||||
- **Heading Blocks**: All three heading levels (h1, h2, h3) with unified handler
|
|
||||||
- **Quote Block**: Italic styling with border, full editing capabilities
|
|
||||||
- **Code Block**: Monospace font, tab handling, plain text paste support
|
|
||||||
- **List Block**: Bullet/numbered lists with proper list item management
|
|
||||||
|
|
||||||
## Key Achievements
|
|
||||||
|
|
||||||
### 1. Preserved Critical Knowledge
|
|
||||||
- **Static Rendering**: Blocks use `innerHTML` in `firstUpdated` to prevent focus loss during typing
|
|
||||||
- **Shadow DOM Selection**: Implemented `containsAcrossShadowDOM` utility for proper selection detection
|
|
||||||
- **Cursor Position Tracking**: All editable blocks track cursor position across multiple events
|
|
||||||
- **Content Splitting**: HTML-aware splitting using Range API preserves formatting
|
|
||||||
- **Focus Management**: Microtask-based focus restoration ensures reliable cursor placement
|
|
||||||
|
|
||||||
### 2. Enhanced Architecture
|
|
||||||
- Each block type is now self-contained in its own file
|
|
||||||
- Block handlers are dynamically registered and loaded
|
|
||||||
- Common functionality is shared through base classes
|
|
||||||
- Styles are co-located with their block handlers
|
|
||||||
|
|
||||||
### 3. Maintained Functionality
|
|
||||||
- All keyboard navigation works (arrows, backspace, delete, enter)
|
|
||||||
- Text selection across Shadow DOM boundaries functions correctly
|
|
||||||
- Block merging and splitting behave as before
|
|
||||||
- IME (Input Method Editor) support is preserved
|
|
||||||
- Formatting shortcuts (Cmd/Ctrl+B/I/U/K) continue to work
|
|
||||||
|
|
||||||
## Code Organization
|
|
||||||
|
|
||||||
```
|
|
||||||
ts_web/elements/wysiwyg/
|
|
||||||
├── dees-wysiwyg-block.ts (simplified main component)
|
|
||||||
├── wysiwyg.selection.ts (Shadow DOM selection utilities)
|
|
||||||
├── wysiwyg.blockregistration.ts (handler registration)
|
|
||||||
└── blocks/
|
|
||||||
├── index.ts (exports and registry)
|
|
||||||
├── block.base.ts (base handler interface)
|
|
||||||
├── decorative/
|
|
||||||
│ └── divider.block.ts
|
|
||||||
└── text/
|
|
||||||
├── paragraph.block.ts
|
|
||||||
├── heading.block.ts
|
|
||||||
├── quote.block.ts
|
|
||||||
├── code.block.ts
|
|
||||||
└── list.block.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
## Next Steps
|
|
||||||
|
|
||||||
### Phase 4: Media Blocks (In Progress)
|
|
||||||
- Image block with upload/drag-drop support
|
|
||||||
- YouTube block with video embedding
|
|
||||||
- Attachment block for file uploads
|
|
||||||
|
|
||||||
### Phase 5: Content Blocks
|
|
||||||
- Markdown block with preview toggle
|
|
||||||
- HTML block with raw HTML editing
|
|
||||||
|
|
||||||
### Phase 6: Cleanup
|
|
||||||
- Remove old code from main component
|
|
||||||
- Optimize bundle size
|
|
||||||
- Update documentation
|
|
||||||
|
|
||||||
## Technical Improvements
|
|
||||||
|
|
||||||
1. **Modularity**: Each block type is now completely self-contained
|
|
||||||
2. **Extensibility**: New blocks can be added by creating a handler and registering it
|
|
||||||
3. **Maintainability**: Files are smaller and focused on single responsibilities
|
|
||||||
4. **Type Safety**: Strong TypeScript interfaces ensure consistent implementation
|
|
||||||
5. **Performance**: No degradation in performance; potential for lazy loading in future
|
|
||||||
|
|
||||||
## Migration Pattern
|
|
||||||
|
|
||||||
For future block migrations, follow this pattern:
|
|
||||||
|
|
||||||
1. Create block handler extending `BaseBlockHandler`
|
|
||||||
2. Implement required methods: `render()`, `setup()`, `getStyles()`
|
|
||||||
3. Add helper methods for cursor/content management
|
|
||||||
4. Handle Shadow DOM selection properly using utilities
|
|
||||||
5. Register handler in `wysiwyg.blockregistration.ts`
|
|
||||||
6. Test all interactions (typing, selection, navigation)
|
|
||||||
|
|
||||||
The refactoring has been successful in making the codebase more maintainable while preserving all the hard-won functionality and edge case handling from the original implementation.
|
|
@@ -1,82 +0,0 @@
|
|||||||
# WYSIWYG Editor Refactoring
|
|
||||||
|
|
||||||
## Summary of Changes
|
|
||||||
|
|
||||||
This refactoring cleaned up the wysiwyg editor implementation to fix focus, cursor position, and selection issues.
|
|
||||||
|
|
||||||
### Phase 1: Code Organization
|
|
||||||
|
|
||||||
#### 1. Removed Duplicate Code
|
|
||||||
- Removed duplicate `handleBlockInput` method from main component (was already in inputHandler)
|
|
||||||
- Removed duplicate `handleBlockKeyDown` method from main component (was already in keyboardHandler)
|
|
||||||
- Consolidated all input handling in the respective handler classes
|
|
||||||
|
|
||||||
#### 2. Simplified Focus Management
|
|
||||||
- Removed complex `updated` lifecycle method that was trying to maintain focus
|
|
||||||
- Simplified `handleBlockBlur` to not immediately close menus
|
|
||||||
- Added `requestAnimationFrame` to focus operations for better timing
|
|
||||||
- Removed `slashMenuOpenTime` tracking which was no longer needed
|
|
||||||
|
|
||||||
#### 3. Fixed Slash Menu Behavior
|
|
||||||
- Changed from `@mousedown` to `@click` events for better UX
|
|
||||||
- Added proper event prevention to avoid focus loss
|
|
||||||
- Menu now closes when clicking outside
|
|
||||||
- Simplified the insertBlock method to close menu first
|
|
||||||
|
|
||||||
### Phase 2: Cursor & Selection Fixes
|
|
||||||
|
|
||||||
#### 4. Enhanced Cursor Position Management
|
|
||||||
- Added `focusWithCursor()` method to block component for precise cursor positioning
|
|
||||||
- Improved `handleSlashCommand` to preserve cursor position when menu opens
|
|
||||||
- Added `getCaretCoordinates()` for accurate menu positioning based on cursor location
|
|
||||||
- Updated `focusBlock()` to support numeric cursor positions
|
|
||||||
|
|
||||||
#### 5. Fixed Selection Across Shadow DOM
|
|
||||||
- Added custom `block-text-selected` event to communicate selections across shadow boundaries
|
|
||||||
- Implemented `handleMouseUp()` in block component to detect selections
|
|
||||||
- Updated main component to listen for selection events from blocks
|
|
||||||
- Selection now works properly even with nested shadow DOMs
|
|
||||||
|
|
||||||
#### 6. Improved Slash Menu Close Behavior
|
|
||||||
- Added optional `clearSlash` parameter to `closeSlashMenu()`
|
|
||||||
- Escape key now properly clears the slash command
|
|
||||||
- Clicking outside clears the slash if menu is open
|
|
||||||
- Selecting an item preserves content and just transforms the block
|
|
||||||
|
|
||||||
### Technical Improvements
|
|
||||||
|
|
||||||
#### Block Component (`dees-wysiwyg-block`)
|
|
||||||
- Better focus management with immediate focus (removed unnecessary requestAnimationFrame)
|
|
||||||
- Added cursor position control methods
|
|
||||||
- Custom event dispatching for cross-shadow-DOM communication
|
|
||||||
- Improved content handling for different block types
|
|
||||||
|
|
||||||
#### Input Handler
|
|
||||||
- Preserves cursor position when showing slash menu
|
|
||||||
- Better caret coordinate calculation for menu positioning
|
|
||||||
- Ensures focus stays in the block when menu appears
|
|
||||||
|
|
||||||
#### Block Operations
|
|
||||||
- Enhanced `focusBlock()` to support start/end/numeric positions
|
|
||||||
- Better timing with requestAnimationFrame for focus operations
|
|
||||||
|
|
||||||
### Key Benefits
|
|
||||||
- Slash menu no longer causes focus or cursor position loss
|
|
||||||
- Text selection works properly across shadow DOM boundaries
|
|
||||||
- Cursor position is preserved when interacting with menus
|
|
||||||
- Cleaner, more maintainable code structure
|
|
||||||
- Better separation of concerns
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
Use the test files in `.nogit/debug/`:
|
|
||||||
- `test-slash-menu.html` - Tests slash menu focus behavior
|
|
||||||
- `test-wysiwyg-formatting.html` - Tests text formatting
|
|
||||||
|
|
||||||
## Known Issues Fixed
|
|
||||||
- Slash menu disappearing immediately on first "/"
|
|
||||||
- Focus lost when slash menu opens
|
|
||||||
- Cursor position lost when typing "/"
|
|
||||||
- Text selection not working properly
|
|
||||||
- Selection events not propagating across shadow DOM
|
|
||||||
- Duplicate event handling causing conflicts
|
|
44
scripts/update-monaco-version.cjs
Executable file
44
scripts/update-monaco-version.cjs
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const projectRoot = path.resolve(__dirname, '..');
|
||||||
|
|
||||||
|
function resolveMonacoPackageJson() {
|
||||||
|
try {
|
||||||
|
const resolvedPath = require.resolve('monaco-editor/package.json', {
|
||||||
|
paths: [projectRoot],
|
||||||
|
});
|
||||||
|
return resolvedPath;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[dees-editor] Unable to resolve monaco-editor/package.json');
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMonacoVersion() {
|
||||||
|
const monacoPackagePath = resolveMonacoPackageJson();
|
||||||
|
const monacoPackage = require(monacoPackagePath);
|
||||||
|
if (!monacoPackage.version) {
|
||||||
|
throw new Error('[dees-editor] monaco-editor/package.json does not expose a version field');
|
||||||
|
}
|
||||||
|
return monacoPackage.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeVersionModule(version) {
|
||||||
|
const targetDir = path.join(projectRoot, 'ts_web', 'elements', 'dees-editor');
|
||||||
|
fs.mkdirSync(targetDir, { recursive: true });
|
||||||
|
const targetFile = path.join(targetDir, 'version.ts');
|
||||||
|
const fileContent = `// Auto-generated by scripts/update-monaco-version.cjs\nexport const MONACO_VERSION = '${version}';\n`;
|
||||||
|
fs.writeFileSync(targetFile, fileContent, 'utf8');
|
||||||
|
console.log(`[dees-editor] Wrote ${path.relative(projectRoot, targetFile)} with monaco-editor@${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const version = getMonacoVersion();
|
||||||
|
writeVersionModule(version);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[dees-editor] Failed to update Monaco version module.');
|
||||||
|
console.error(error instanceof Error ? error.message : error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
@@ -1,72 +0,0 @@
|
|||||||
|
|
||||||
> @design.estate/dees-catalog@1.10.8 test /mnt/data/lossless/design.estate/dees-catalog
|
|
||||||
> tstest test/ --web --verbose --timeout 30 --logfile test/test.tabs-indicator.browser.ts
|
|
||||||
|
|
||||||
[38;5;231m
|
|
||||||
🔍 Test Discovery[0m
|
|
||||||
[38;5;231m Mode: file[0m
|
|
||||||
[38;5;231m Pattern: test/test.tabs-indicator.browser.ts[0m
|
|
||||||
[38;5;113m Found: 1 test file(s)[0m
|
|
||||||
[38;5;33m
|
|
||||||
▶️ test/test.tabs-indicator.browser.ts (1/1)[0m
|
|
||||||
[38;5;231m Runtime: chromium[0m
|
|
||||||
running spawned compilation process
|
|
||||||
=======> ESBUILD
|
|
||||||
{
|
|
||||||
cwd: '/mnt/data/lossless/design.estate/dees-catalog',
|
|
||||||
from: 'test/test.tabs-indicator.browser.ts',
|
|
||||||
to: '/mnt/data/lossless/design.estate/dees-catalog/.nogit/tstest_cache/test__test.tabs-indicator.browser.ts.js',
|
|
||||||
mode: 'test',
|
|
||||||
argv: { bundler: 'esbuild' }
|
|
||||||
}
|
|
||||||
switched to /mnt/data/lossless/design.estate/dees-catalog
|
|
||||||
building for test:
|
|
||||||
Got no SSL certificates. Please ensure encryption using e.g. a reverse proxy
|
|
||||||
"/test" maps to 1 handlers
|
|
||||||
-> GET
|
|
||||||
"*" maps to 1 handlers
|
|
||||||
-> GET
|
|
||||||
now listening on 3007!
|
|
||||||
Launching puppeteer browser with arguments:
|
|
||||||
[]
|
|
||||||
Using executable: /usr/bin/google-chrome
|
|
||||||
added connection. now 1 sockets connected.
|
|
||||||
added connection. now 2 sockets connected.
|
|
||||||
connection ended
|
|
||||||
removed connection. 1 sockets remaining.
|
|
||||||
connection ended
|
|
||||||
removed connection. 0 sockets remaining.
|
|
||||||
added connection. now 1 sockets connected.
|
|
||||||
/favicon.ico
|
|
||||||
could not resolve /mnt/data/lossless/design.estate/dees-catalog/.nogit/tstest_cache/favicon.ico
|
|
||||||
/test__test.tabs-indicator.browser.ts.js
|
|
||||||
[38;5;231m [38;5;116mTest starting: tabs indicator positioning debug[0m[0m
|
|
||||||
[38;5;231m !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![0m
|
|
||||||
[38;5;231m Using globalThis.tapPromise[0m
|
|
||||||
[38;5;231m !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![0m
|
|
||||||
connection ended
|
|
||||||
removed connection. 0 sockets remaining.
|
|
||||||
[38;5;33m=> [0m Stopped [38;5;215mtest/test.tabs-indicator.browser.ts[0m chromium instance and server.
|
|
||||||
[38;5;196m
|
|
||||||
⚠️ Error[0m
|
|
||||||
[38;5;196m Only 0 out of 1 completed![0m
|
|
||||||
[38;5;196m
|
|
||||||
⚠️ Error[0m
|
|
||||||
[38;5;196m The amount of received tests and expectedTests is unequal! Therefore the testfile failed[0m
|
|
||||||
[38;5;196m Summary: -1 passed, 1 failed of 0 tests in 2.7s[0m
|
|
||||||
[38;5;231m
|
|
||||||
📊 Test Summary[0m
|
|
||||||
[38;5;231m┌────────────────────────────────┐[0m
|
|
||||||
[38;5;231m│ Total Files: 1 │[0m
|
|
||||||
[38;5;231m│ Total Tests: 0 │[0m
|
|
||||||
[38;5;113m│ Passed: 0 │[0m
|
|
||||||
[38;5;113m│ Failed: 0 │[0m
|
|
||||||
[38;5;231m│ Duration: 4.2s │[0m
|
|
||||||
[38;5;231m└────────────────────────────────┘[0m
|
|
||||||
[38;5;116m
|
|
||||||
⏱️ Performance Metrics:[0m
|
|
||||||
[38;5;231m Average per test: 0ms[0m
|
|
||||||
[38;5;113m
|
|
||||||
ALL TESTS PASSED! 🎉[0m
|
|
||||||
Exited NOT OK!
|
|
||||||
ELIFECYCLE Test failed. See above for more details.
|
|
28
test/test.dashboardgrid-layout.node.ts
Normal file
28
test/test.dashboardgrid-layout.node.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
|
import {
|
||||||
|
resolveWidgetPlacement,
|
||||||
|
collectCollisions,
|
||||||
|
} from '../ts_web/elements/dees-dashboardgrid/layout.ts';
|
||||||
|
import type { DashboardWidget } from '../ts_web/elements/dees-dashboardgrid/types.ts';
|
||||||
|
|
||||||
|
tap.test('dashboardgrid does not overlap widgets after swap attempt', async () => {
|
||||||
|
const widgets: DashboardWidget[] = [
|
||||||
|
{ id: 'w0', x: 6, y: 5, w: 1, h: 3 },
|
||||||
|
{ id: 'w1', x: 6, y: 1, w: 1, h: 3 },
|
||||||
|
{ id: 'w2', x: 3, y: 0, w: 2, h: 2 },
|
||||||
|
{ id: 'w3', x: 9, y: 0, w: 1, h: 2 },
|
||||||
|
{ id: 'w4', x: 4, y: 3, w: 1, h: 2 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const placement = resolveWidgetPlacement(widgets, 'w0', { x: 6, y: 3 }, 12);
|
||||||
|
expect(placement).toBeTruthy();
|
||||||
|
|
||||||
|
const layout = placement!.widgets;
|
||||||
|
for (const widget of layout) {
|
||||||
|
const collisions = collectCollisions(layout, widget, widget.x, widget.y, widget.w, widget.h);
|
||||||
|
expect(collisions).toBeEmptyArray();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
85
test/test.wysiwyg-blockmovement.browser.ts
Normal file
85
test/test.wysiwyg-blockmovement.browser.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg block movement during drag', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Block 1' },
|
||||||
|
{ id: 'block2', type: 'paragraph', content: 'Block 2' },
|
||||||
|
{ id: 'block3', type: 'paragraph', content: 'Block 3' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
const block1 = editorContent.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
|
||||||
|
// Start dragging block 1
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: () => {},
|
||||||
|
setDragImage: () => {}
|
||||||
|
},
|
||||||
|
clientY: 50,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
|
||||||
|
// Wait for dragging class
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20));
|
||||||
|
|
||||||
|
// Verify drag state
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toEqual('block1');
|
||||||
|
|
||||||
|
// Check that drag height was calculated
|
||||||
|
console.log('Checking drag height...');
|
||||||
|
const dragHandler = element.dragDropHandler as any;
|
||||||
|
console.log('draggedBlockHeight:', dragHandler.draggedBlockHeight);
|
||||||
|
console.log('draggedBlockContentHeight:', dragHandler.draggedBlockContentHeight);
|
||||||
|
|
||||||
|
// Manually call updateBlockPositions to simulate drag movement
|
||||||
|
console.log('Simulating drag movement...');
|
||||||
|
const updateBlockPositions = dragHandler.updateBlockPositions.bind(dragHandler);
|
||||||
|
|
||||||
|
// Simulate dragging down past block 2
|
||||||
|
const block2 = editorContent.querySelector('[data-block-id="block2"]') as HTMLElement;
|
||||||
|
const block2Rect = block2.getBoundingClientRect();
|
||||||
|
const dragToY = block2Rect.bottom + 10;
|
||||||
|
|
||||||
|
console.log('Dragging to Y position:', dragToY);
|
||||||
|
updateBlockPositions(dragToY);
|
||||||
|
|
||||||
|
// Check if blocks have moved
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
|
||||||
|
const blocks = Array.from(editorContent.querySelectorAll('.block-wrapper'));
|
||||||
|
console.log('Block states after drag:');
|
||||||
|
blocks.forEach((block, i) => {
|
||||||
|
const classes = block.className;
|
||||||
|
const offset = (block as HTMLElement).style.getPropertyValue('--drag-offset');
|
||||||
|
console.log(`Block ${i}: classes="${classes}", offset="${offset}"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check that at least one block has move class
|
||||||
|
const movedUpBlocks = editorContent.querySelectorAll('.block-wrapper.move-up');
|
||||||
|
const movedDownBlocks = editorContent.querySelectorAll('.block-wrapper.move-down');
|
||||||
|
console.log('Moved up blocks:', movedUpBlocks.length);
|
||||||
|
console.log('Moved down blocks:', movedDownBlocks.length);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
95
test/test.wysiwyg-dragdrop-simple.browser.ts
Normal file
95
test/test.wysiwyg-dragdrop-simple.browser.ts
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag handler initialization', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
// Wait for element to be ready
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Check that drag handler is initialized
|
||||||
|
expect(element.dragDropHandler).toBeTruthy();
|
||||||
|
|
||||||
|
// Set initial content with multiple blocks
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'First paragraph' },
|
||||||
|
{ id: 'block2', type: 'paragraph', content: 'Second paragraph' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Check that editor content ref exists
|
||||||
|
console.log('editorContentRef:', element.editorContentRef);
|
||||||
|
expect(element.editorContentRef).toBeTruthy();
|
||||||
|
|
||||||
|
// Check that blocks are rendered
|
||||||
|
const blockWrappers = element.shadowRoot!.querySelectorAll('.block-wrapper');
|
||||||
|
console.log('Number of block wrappers:', blockWrappers.length);
|
||||||
|
expect(blockWrappers.length).toEqual(2);
|
||||||
|
|
||||||
|
// Check drag handles
|
||||||
|
const dragHandles = element.shadowRoot!.querySelectorAll('.drag-handle');
|
||||||
|
console.log('Number of drag handles:', dragHandles.length);
|
||||||
|
expect(dragHandles.length).toEqual(2);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag start behavior', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const dragHandle = element.shadowRoot!.querySelector('.drag-handle') as HTMLElement;
|
||||||
|
expect(dragHandle).toBeTruthy();
|
||||||
|
|
||||||
|
// Check that drag handle has draggable attribute
|
||||||
|
console.log('Drag handle draggable:', dragHandle.draggable);
|
||||||
|
expect(dragHandle.draggable).toBeTrue();
|
||||||
|
|
||||||
|
// Test drag handler state before drag
|
||||||
|
console.log('Initial drag state:', element.dragDropHandler.dragState);
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toBeNull();
|
||||||
|
|
||||||
|
// Try to manually call handleDragStart
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: (type: string, data: string) => {
|
||||||
|
console.log('setData called with:', type, data);
|
||||||
|
},
|
||||||
|
setDragImage: (img: any, x: number, y: number) => {
|
||||||
|
console.log('setDragImage called');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clientY: 100,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
|
||||||
|
// Check drag state after drag start
|
||||||
|
console.log('Drag state after start:', element.dragDropHandler.dragState);
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toEqual('block1');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
133
test/test.wysiwyg-dragdrop-visual.browser.ts
Normal file
133
test/test.wysiwyg-dragdrop-visual.browser.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag visual feedback - block movement', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Block 1' },
|
||||||
|
{ id: 'block2', type: 'paragraph', content: 'Block 2' },
|
||||||
|
{ id: 'block3', type: 'paragraph', content: 'Block 3' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
const block1 = editorContent.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
|
||||||
|
// Manually start drag
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: (type: string, data: string) => {},
|
||||||
|
setDragImage: (img: any, x: number, y: number) => {}
|
||||||
|
},
|
||||||
|
clientY: 50,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
|
||||||
|
// Wait for dragging class
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20));
|
||||||
|
|
||||||
|
// Check dragging state
|
||||||
|
console.log('Block 1 classes:', block1.className);
|
||||||
|
console.log('Editor content classes:', editorContent.className);
|
||||||
|
expect(block1.classList.contains('dragging')).toBeTrue();
|
||||||
|
expect(editorContent.classList.contains('dragging')).toBeTrue();
|
||||||
|
|
||||||
|
// Check drop indicator exists
|
||||||
|
const dropIndicator = editorContent.querySelector('.drop-indicator') as HTMLElement;
|
||||||
|
console.log('Drop indicator:', dropIndicator);
|
||||||
|
expect(dropIndicator).toBeTruthy();
|
||||||
|
|
||||||
|
// Test block movement calculation
|
||||||
|
console.log('Testing updateBlockPositions...');
|
||||||
|
|
||||||
|
// Access private method for testing
|
||||||
|
const updateBlockPositions = element.dragDropHandler['updateBlockPositions'].bind(element.dragDropHandler);
|
||||||
|
|
||||||
|
// Simulate dragging to different position
|
||||||
|
updateBlockPositions(150); // Move down
|
||||||
|
|
||||||
|
// Check if blocks have move classes
|
||||||
|
const blocks = Array.from(editorContent.querySelectorAll('.block-wrapper'));
|
||||||
|
console.log('Block classes after move:');
|
||||||
|
blocks.forEach((block, i) => {
|
||||||
|
console.log(`Block ${i}:`, block.className, 'transform:', (block as HTMLElement).style.getPropertyValue('--drag-offset'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('wysiwyg drop indicator positioning', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Paragraph 1' },
|
||||||
|
{ id: 'block2', type: 'heading-2', content: 'Heading 2' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
|
||||||
|
// Start dragging first block
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: (type: string, data: string) => {},
|
||||||
|
setDragImage: (img: any, x: number, y: number) => {}
|
||||||
|
},
|
||||||
|
clientY: 50,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
|
||||||
|
// Wait for initialization
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20));
|
||||||
|
|
||||||
|
// Get drop indicator
|
||||||
|
const dropIndicator = editorContent.querySelector('.drop-indicator') as HTMLElement;
|
||||||
|
expect(dropIndicator).toBeTruthy();
|
||||||
|
|
||||||
|
// Check initial display state
|
||||||
|
console.log('Drop indicator initial display:', dropIndicator.style.display);
|
||||||
|
|
||||||
|
// Trigger updateBlockPositions to see drop indicator
|
||||||
|
const updateBlockPositions = element.dragDropHandler['updateBlockPositions'].bind(element.dragDropHandler);
|
||||||
|
updateBlockPositions(100);
|
||||||
|
|
||||||
|
// Check drop indicator position
|
||||||
|
console.log('Drop indicator after update:');
|
||||||
|
console.log('- display:', dropIndicator.style.display);
|
||||||
|
console.log('- top:', dropIndicator.style.top);
|
||||||
|
console.log('- height:', dropIndicator.style.height);
|
||||||
|
|
||||||
|
expect(dropIndicator.style.display).toEqual('block');
|
||||||
|
expect(dropIndicator.style.top).toBeTruthy();
|
||||||
|
expect(dropIndicator.style.height).toBeTruthy();
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
172
test/test.wysiwyg-dragdrop.browser.ts
Normal file
172
test/test.wysiwyg-dragdrop.browser.ts
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag and drop should work correctly', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
// Wait for element to be ready
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content with multiple blocks
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'First paragraph' },
|
||||||
|
{ id: 'block2', type: 'heading-2', content: 'Test Heading' },
|
||||||
|
{ id: 'block3', type: 'paragraph', content: 'Second paragraph' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Check that blocks are rendered
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
expect(editorContent).toBeTruthy();
|
||||||
|
|
||||||
|
const blockWrappers = editorContent.querySelectorAll('.block-wrapper');
|
||||||
|
expect(blockWrappers.length).toEqual(3);
|
||||||
|
|
||||||
|
// Test drag handles exist for non-divider blocks
|
||||||
|
const dragHandles = editorContent.querySelectorAll('.drag-handle');
|
||||||
|
expect(dragHandles.length).toEqual(3);
|
||||||
|
|
||||||
|
// Get references to specific blocks
|
||||||
|
const firstBlock = editorContent.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
const secondBlock = editorContent.querySelector('[data-block-id="block2"]') as HTMLElement;
|
||||||
|
const firstDragHandle = firstBlock.querySelector('.drag-handle') as HTMLElement;
|
||||||
|
|
||||||
|
expect(firstBlock).toBeTruthy();
|
||||||
|
expect(secondBlock).toBeTruthy();
|
||||||
|
expect(firstDragHandle).toBeTruthy();
|
||||||
|
|
||||||
|
// Test drag initialization
|
||||||
|
console.log('Testing drag initialization...');
|
||||||
|
|
||||||
|
// Create drag event
|
||||||
|
const dragStartEvent = new DragEvent('dragstart', {
|
||||||
|
dataTransfer: new DataTransfer(),
|
||||||
|
clientY: 100,
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Simulate drag start
|
||||||
|
firstDragHandle.dispatchEvent(dragStartEvent);
|
||||||
|
|
||||||
|
// Check that drag state is initialized
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toEqual('block1');
|
||||||
|
|
||||||
|
// Check that dragging class is applied
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20)); // Wait for setTimeout in drag start
|
||||||
|
expect(firstBlock.classList.contains('dragging')).toBeTrue();
|
||||||
|
expect(editorContent.classList.contains('dragging')).toBeTrue();
|
||||||
|
|
||||||
|
// Test drop indicator creation
|
||||||
|
const dropIndicator = editorContent.querySelector('.drop-indicator');
|
||||||
|
expect(dropIndicator).toBeTruthy();
|
||||||
|
|
||||||
|
// Simulate drag over
|
||||||
|
const dragOverEvent = new DragEvent('dragover', {
|
||||||
|
dataTransfer: new DataTransfer(),
|
||||||
|
clientY: 200,
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(dragOverEvent);
|
||||||
|
|
||||||
|
// Check that blocks move out of the way
|
||||||
|
console.log('Checking block movements...');
|
||||||
|
const blocks = Array.from(editorContent.querySelectorAll('.block-wrapper'));
|
||||||
|
const hasMovedBlocks = blocks.some(block =>
|
||||||
|
block.classList.contains('move-up') || block.classList.contains('move-down')
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Blocks with move classes:', blocks.filter(block =>
|
||||||
|
block.classList.contains('move-up') || block.classList.contains('move-down')
|
||||||
|
).length);
|
||||||
|
|
||||||
|
// Test drag end
|
||||||
|
const dragEndEvent = new DragEvent('dragend', {
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
|
||||||
|
document.dispatchEvent(dragEndEvent);
|
||||||
|
|
||||||
|
// Wait for cleanup
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 150));
|
||||||
|
|
||||||
|
// Check that drag state is cleaned up
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toBeNull();
|
||||||
|
expect(firstBlock.classList.contains('dragging')).toBeFalse();
|
||||||
|
expect(editorContent.classList.contains('dragging')).toBeFalse();
|
||||||
|
|
||||||
|
// Check that drop indicator is removed
|
||||||
|
const dropIndicatorAfter = editorContent.querySelector('.drop-indicator');
|
||||||
|
expect(dropIndicatorAfter).toBeFalsy();
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag and drop visual feedback', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Block 1' },
|
||||||
|
{ id: 'block2', type: 'paragraph', content: 'Block 2' },
|
||||||
|
{ id: 'block3', type: 'paragraph', content: 'Block 3' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
const block1 = editorContent.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
const dragHandle1 = block1.querySelector('.drag-handle') as HTMLElement;
|
||||||
|
|
||||||
|
// Start dragging block 1
|
||||||
|
const dragStartEvent = new DragEvent('dragstart', {
|
||||||
|
dataTransfer: new DataTransfer(),
|
||||||
|
clientY: 50,
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
|
||||||
|
dragHandle1.dispatchEvent(dragStartEvent);
|
||||||
|
|
||||||
|
// Wait for dragging class
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20));
|
||||||
|
|
||||||
|
// Simulate dragging down
|
||||||
|
const dragOverEvent = new DragEvent('dragover', {
|
||||||
|
dataTransfer: new DataTransfer(),
|
||||||
|
clientY: 150, // Move down past block 2
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Trigger the global drag over handler
|
||||||
|
element.dragDropHandler['handleGlobalDragOver'](dragOverEvent);
|
||||||
|
|
||||||
|
// Check that transform is applied to dragged block
|
||||||
|
const transform = block1.style.transform;
|
||||||
|
console.log('Dragged block transform:', transform);
|
||||||
|
expect(transform).toContain('translateY');
|
||||||
|
|
||||||
|
// Check drop indicator position
|
||||||
|
const dropIndicator = editorContent.querySelector('.drop-indicator') as HTMLElement;
|
||||||
|
if (dropIndicator) {
|
||||||
|
const indicatorStyle = dropIndicator.style;
|
||||||
|
console.log('Drop indicator position:', indicatorStyle.top, 'display:', indicatorStyle.display);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
124
test/test.wysiwyg-dragissue.browser.ts
Normal file
124
test/test.wysiwyg-dragissue.browser.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag full flow without await', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Mock drag event
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: (type: string, data: string) => {
|
||||||
|
console.log('setData:', type, data);
|
||||||
|
},
|
||||||
|
setDragImage: (img: any, x: number, y: number) => {
|
||||||
|
console.log('setDragImage');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clientY: 100,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
console.log('Starting drag...');
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
console.log('Drag started');
|
||||||
|
|
||||||
|
// Check immediate state
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toEqual('block1');
|
||||||
|
|
||||||
|
// Instead of await with setTimeout, use a done callback
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
console.log('Setting up delayed check...');
|
||||||
|
|
||||||
|
// Use regular setTimeout
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log('In setTimeout callback');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const block1 = element.shadowRoot!.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
|
||||||
|
console.log('Block has dragging class:', block1?.classList.contains('dragging'));
|
||||||
|
console.log('Editor has dragging class:', editorContent?.classList.contains('dragging'));
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in setTimeout:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('identify the crash point', async () => {
|
||||||
|
console.log('Test started');
|
||||||
|
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
console.log('Element created');
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
console.log('Setting blocks');
|
||||||
|
element.blocks = [{ id: 'block1', type: 'paragraph', content: 'Test' }];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
console.log('Waiting for update');
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
console.log('Creating mock event');
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: () => {},
|
||||||
|
setDragImage: () => {}
|
||||||
|
},
|
||||||
|
clientY: 100,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
console.log('Calling handleDragStart');
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
|
||||||
|
console.log('handleDragStart completed');
|
||||||
|
|
||||||
|
// Try different wait methods
|
||||||
|
console.log('About to wait...');
|
||||||
|
|
||||||
|
// Method 1: Direct promise
|
||||||
|
await Promise.resolve();
|
||||||
|
console.log('Promise.resolve completed');
|
||||||
|
|
||||||
|
// Method 2: setTimeout 0
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 0));
|
||||||
|
console.log('setTimeout 0 completed');
|
||||||
|
|
||||||
|
// Method 3: requestAnimationFrame
|
||||||
|
await new Promise(resolve => requestAnimationFrame(() => resolve(undefined)));
|
||||||
|
console.log('requestAnimationFrame completed');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
console.log('Cleanup completed');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
108
test/test.wysiwyg-dropindicator.browser.ts
Normal file
108
test/test.wysiwyg-dropindicator.browser.ts
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg drop indicator creation', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Check editorContentRef
|
||||||
|
console.log('editorContentRef exists:', !!element.editorContentRef);
|
||||||
|
console.log('editorContentRef tagName:', element.editorContentRef?.tagName);
|
||||||
|
expect(element.editorContentRef).toBeTruthy();
|
||||||
|
|
||||||
|
// Check initial state - no drop indicator
|
||||||
|
let dropIndicator = element.shadowRoot!.querySelector('.drop-indicator');
|
||||||
|
console.log('Drop indicator before drag:', dropIndicator);
|
||||||
|
expect(dropIndicator).toBeFalsy();
|
||||||
|
|
||||||
|
// Manually call createDropIndicator
|
||||||
|
try {
|
||||||
|
console.log('Calling createDropIndicator...');
|
||||||
|
element.dragDropHandler['createDropIndicator']();
|
||||||
|
console.log('createDropIndicator succeeded');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating drop indicator:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check drop indicator was created
|
||||||
|
dropIndicator = element.shadowRoot!.querySelector('.drop-indicator');
|
||||||
|
console.log('Drop indicator after creation:', dropIndicator);
|
||||||
|
console.log('Drop indicator parent:', dropIndicator?.parentElement?.className);
|
||||||
|
expect(dropIndicator).toBeTruthy();
|
||||||
|
expect(dropIndicator!.style.display).toEqual('none');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('wysiwyg drag initialization with drop indicator', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Mock drag event
|
||||||
|
const mockDragEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
effectAllowed: '',
|
||||||
|
setData: (type: string, data: string) => {
|
||||||
|
console.log('setData:', type, data);
|
||||||
|
},
|
||||||
|
setDragImage: (img: any, x: number, y: number) => {
|
||||||
|
console.log('setDragImage');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clientY: 100,
|
||||||
|
preventDefault: () => {},
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
console.log('Starting drag...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
element.dragDropHandler.handleDragStart(mockDragEvent, element.blocks[0]);
|
||||||
|
console.log('Drag start succeeded');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during drag start:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for async operations
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 20));
|
||||||
|
|
||||||
|
// Check drop indicator exists
|
||||||
|
const dropIndicator = element.shadowRoot!.querySelector('.drop-indicator');
|
||||||
|
console.log('Drop indicator after drag start:', dropIndicator);
|
||||||
|
expect(dropIndicator).toBeTruthy();
|
||||||
|
|
||||||
|
// Check drag state
|
||||||
|
console.log('Drag state:', element.dragDropHandler.dragState);
|
||||||
|
expect(element.dragDropHandler.dragState.draggedBlockId).toEqual('block1');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
element.dragDropHandler.handleDragEnd();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
114
test/test.wysiwyg-eventlisteners.browser.ts
Normal file
114
test/test.wysiwyg-eventlisteners.browser.ts
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
import { DeesInputWysiwyg } from '../ts_web/elements/wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
|
||||||
|
// Initialize the element
|
||||||
|
DeesInputWysiwyg;
|
||||||
|
|
||||||
|
tap.test('wysiwyg global event listeners', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const block1 = element.shadowRoot!.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
console.log('Block 1 found:', !!block1);
|
||||||
|
|
||||||
|
// Set up drag state manually without using handleDragStart
|
||||||
|
element.dragDropHandler['draggedBlockId'] = 'block1';
|
||||||
|
element.dragDropHandler['draggedBlockElement'] = block1;
|
||||||
|
element.dragDropHandler['initialMouseY'] = 100;
|
||||||
|
|
||||||
|
// Create drop indicator manually
|
||||||
|
element.dragDropHandler['createDropIndicator']();
|
||||||
|
|
||||||
|
// Test adding global event listeners
|
||||||
|
console.log('Adding event listeners...');
|
||||||
|
const handleGlobalDragOver = element.dragDropHandler['handleGlobalDragOver'];
|
||||||
|
const handleGlobalDragEnd = element.dragDropHandler['handleGlobalDragEnd'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
document.addEventListener('dragover', handleGlobalDragOver);
|
||||||
|
console.log('dragover listener added');
|
||||||
|
|
||||||
|
document.addEventListener('dragend', handleGlobalDragEnd);
|
||||||
|
console.log('dragend listener added');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error adding event listeners:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test firing a dragover event
|
||||||
|
console.log('Creating dragover event...');
|
||||||
|
const dragOverEvent = new Event('dragover', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(dragOverEvent, 'clientY', { value: 150 });
|
||||||
|
|
||||||
|
console.log('Dispatching dragover event...');
|
||||||
|
document.dispatchEvent(dragOverEvent);
|
||||||
|
console.log('dragover event dispatched');
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.removeEventListener('dragover', handleGlobalDragOver);
|
||||||
|
document.removeEventListener('dragend', handleGlobalDragEnd);
|
||||||
|
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('wysiwyg setTimeout in drag start', async () => {
|
||||||
|
const element = document.createElement('dees-input-wysiwyg');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
// Set initial content
|
||||||
|
element.blocks = [
|
||||||
|
{ id: 'block1', type: 'paragraph', content: 'Test block' },
|
||||||
|
];
|
||||||
|
element.renderBlocksProgrammatically();
|
||||||
|
|
||||||
|
await element.updateComplete;
|
||||||
|
|
||||||
|
const block1 = element.shadowRoot!.querySelector('[data-block-id="block1"]') as HTMLElement;
|
||||||
|
const editorContent = element.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
|
||||||
|
// Set drag state
|
||||||
|
element.dragDropHandler['draggedBlockId'] = 'block1';
|
||||||
|
element.dragDropHandler['draggedBlockElement'] = block1;
|
||||||
|
|
||||||
|
console.log('Testing setTimeout callback...');
|
||||||
|
|
||||||
|
// Test the setTimeout callback directly
|
||||||
|
try {
|
||||||
|
if (block1) {
|
||||||
|
console.log('Adding dragging class to block...');
|
||||||
|
block1.classList.add('dragging');
|
||||||
|
console.log('Block classes:', block1.className);
|
||||||
|
}
|
||||||
|
if (editorContent) {
|
||||||
|
console.log('Adding dragging class to editor...');
|
||||||
|
editorContent.classList.add('dragging');
|
||||||
|
console.log('Editor classes:', editorContent.className);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in setTimeout callback:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(block1.classList.contains('dragging')).toBeTrue();
|
||||||
|
expect(editorContent.classList.contains('dragging')).toBeTrue();
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@design.estate/dees-catalog',
|
name: '@design.estate/dees-catalog',
|
||||||
version: '1.10.1',
|
version: '1.12.1',
|
||||||
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
||||||
}
|
}
|
||||||
|
@@ -1,83 +1,93 @@
|
|||||||
import { html, css, cssManager } from '@design.estate/dees-element';
|
import { html, css, cssManager, domtools } from '@design.estate/dees-element';
|
||||||
import '@design.estate/dees-wcctools/demotools';
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
import './dees-panel.js';
|
import './dees-panel.js';
|
||||||
import './dees-form.js';
|
import './dees-form.js';
|
||||||
import './dees-form-submit.js';
|
import './dees-form-submit.js';
|
||||||
import './dees-input-text.js';
|
import './dees-input-text.js';
|
||||||
import './dees-icon.js';
|
import './dees-icon.js';
|
||||||
|
import type { DeesButton } from './dees-button.js';
|
||||||
|
|
||||||
export const demoFunc = () => html`
|
export const demoFunc = () => html`
|
||||||
<dees-demowrapper>
|
<style>
|
||||||
<style>
|
${css`
|
||||||
${css`
|
.demo-container {
|
||||||
.demo-container {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
flex-direction: column;
|
gap: 24px;
|
||||||
gap: 24px;
|
padding: 24px;
|
||||||
padding: 24px;
|
max-width: 1200px;
|
||||||
max-width: 1200px;
|
margin: 0 auto;
|
||||||
margin: 0 auto;
|
}
|
||||||
}
|
|
||||||
|
dees-panel {
|
||||||
dees-panel {
|
margin-bottom: 24px;
|
||||||
margin-bottom: 24px;
|
}
|
||||||
}
|
|
||||||
|
dees-panel:last-child {
|
||||||
dees-panel:last-child {
|
margin-bottom: 0;
|
||||||
margin-bottom: 0;
|
}
|
||||||
}
|
|
||||||
|
.button-group {
|
||||||
.button-group {
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
gap: 12px;
|
||||||
gap: 12px;
|
flex-wrap: wrap;
|
||||||
flex-wrap: wrap;
|
}
|
||||||
}
|
|
||||||
|
.vertical-group {
|
||||||
.vertical-group {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
flex-direction: column;
|
gap: 8px;
|
||||||
gap: 8px;
|
max-width: 300px;
|
||||||
max-width: 300px;
|
}
|
||||||
}
|
|
||||||
|
.horizontal-group {
|
||||||
.horizontal-group {
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
gap: 16px;
|
||||||
gap: 16px;
|
flex-wrap: wrap;
|
||||||
flex-wrap: wrap;
|
}
|
||||||
}
|
|
||||||
|
.demo-output {
|
||||||
.demo-output {
|
margin-top: 16px;
|
||||||
margin-top: 16px;
|
padding: 12px;
|
||||||
padding: 12px;
|
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
|
||||||
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
|
border-radius: 6px;
|
||||||
border-radius: 6px;
|
font-size: 14px;
|
||||||
font-size: 14px;
|
font-family: monospace;
|
||||||
font-family: monospace;
|
color: ${cssManager.bdTheme('hsl(215.3 25% 8.8%)', 'hsl(210 40% 98%)')};
|
||||||
color: ${cssManager.bdTheme('hsl(215.3 25% 8.8%)', 'hsl(210 40% 98%)')};
|
}
|
||||||
}
|
|
||||||
|
.icon-row {
|
||||||
.icon-row {
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
gap: 12px;
|
||||||
gap: 12px;
|
margin: 8px 0;
|
||||||
margin: 8px 0;
|
}
|
||||||
}
|
|
||||||
|
.code-snippet {
|
||||||
.code-snippet {
|
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 11.8%)')};
|
||||||
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 11.8%)')};
|
padding: 8px 12px;
|
||||||
padding: 8px 12px;
|
border-radius: 4px;
|
||||||
border-radius: 4px;
|
font-family: monospace;
|
||||||
font-family: monospace;
|
font-size: 13px;
|
||||||
font-size: 13px;
|
display: inline-block;
|
||||||
display: inline-block;
|
margin: 4px 0;
|
||||||
margin: 4px 0;
|
}
|
||||||
}
|
`}
|
||||||
`}
|
</style>
|
||||||
</style>
|
|
||||||
|
<div class="demo-container">
|
||||||
<div class="demo-container">
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Log button clicks for demo purposes
|
||||||
|
const buttons = elementArg.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach((button) => {
|
||||||
|
button.addEventListener('clicked', () => {
|
||||||
|
const type = button.getAttribute('type') || 'default';
|
||||||
|
console.log(`Button variant clicked: ${type}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'1. Button Variants'} .subtitle=${'Different visual styles for various use cases'}>
|
<dees-panel .title=${'1. Button Variants'} .subtitle=${'Different visual styles for various use cases'}>
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<dees-button type="default">Default</dees-button>
|
<dees-button type="default">Default</dees-button>
|
||||||
@@ -88,7 +98,18 @@ export const demoFunc = () => html`
|
|||||||
<dees-button type="link">Link Button</dees-button>
|
<dees-button type="link">Link Button</dees-button>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate size differences programmatically
|
||||||
|
const buttons = elementArg.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach((button) => {
|
||||||
|
button.addEventListener('clicked', () => {
|
||||||
|
const size = button.getAttribute('size') || 'default';
|
||||||
|
console.log(`Button size: ${size}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'2. Button Sizes'} .subtitle=${'Multiple sizes for different contexts and use cases'}>
|
<dees-panel .title=${'2. Button Sizes'} .subtitle=${'Multiple sizes for different contexts and use cases'}>
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<dees-button size="sm">Small Button</dees-button>
|
<dees-button size="sm">Small Button</dees-button>
|
||||||
@@ -103,7 +124,21 @@ export const demoFunc = () => html`
|
|||||||
<dees-button size="lg" type="outline">Large Outline</dees-button>
|
<dees-button size="lg" type="outline">Large Outline</dees-button>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Track icon button clicks
|
||||||
|
const iconButtons = elementArg.querySelectorAll('dees-button');
|
||||||
|
iconButtons.forEach((button) => {
|
||||||
|
button.addEventListener('clicked', () => {
|
||||||
|
const hasIcon = button.querySelector('dees-icon');
|
||||||
|
if (hasIcon) {
|
||||||
|
const iconName = hasIcon.getAttribute('iconFA') || 'unknown';
|
||||||
|
console.log(`Icon button clicked: ${iconName}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'3. Buttons with Icons'} .subtitle=${'Combining icons with text for enhanced visual communication'}>
|
<dees-panel .title=${'3. Buttons with Icons'} .subtitle=${'Combining icons with text for enhanced visual communication'}>
|
||||||
<div class="icon-row">
|
<div class="icon-row">
|
||||||
<dees-button>
|
<dees-button>
|
||||||
@@ -153,7 +188,33 @@ export const demoFunc = () => html`
|
|||||||
</dees-button>
|
</dees-button>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate status changes
|
||||||
|
const pendingButton = elementArg.querySelector('dees-button[status="pending"]');
|
||||||
|
const successButton = elementArg.querySelector('dees-button[status="success"]');
|
||||||
|
const errorButton = elementArg.querySelector('dees-button[status="error"]');
|
||||||
|
|
||||||
|
// Simulate status changes
|
||||||
|
if (pendingButton) {
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log('Pending button is showing loading state');
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successButton) {
|
||||||
|
successButton.addEventListener('clicked', () => {
|
||||||
|
console.log('Success state button clicked');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorButton) {
|
||||||
|
errorButton.addEventListener('clicked', () => {
|
||||||
|
console.log('Error state button clicked');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'4. Button States'} .subtitle=${'Different states to indicate button status and loading conditions'}>
|
<dees-panel .title=${'4. Button States'} .subtitle=${'Different states to indicate button status and loading conditions'}>
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<dees-button status="normal">Normal</dees-button>
|
<dees-button status="normal">Normal</dees-button>
|
||||||
@@ -169,61 +230,81 @@ export const demoFunc = () => html`
|
|||||||
<dees-button type="destructive" status="pending" size="lg">Large Loading</dees-button>
|
<dees-button type="destructive" status="pending" size="lg">Large Loading</dees-button>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Set up click handlers with the output element
|
||||||
|
const output = elementArg.querySelector('#click-output');
|
||||||
|
|
||||||
|
const clickMeBtn = elementArg.querySelector('dees-button:first-of-type');
|
||||||
|
const dataBtn = elementArg.querySelector('dees-button[type="secondary"]');
|
||||||
|
const asyncBtn = elementArg.querySelector('dees-button[type="destructive"]');
|
||||||
|
|
||||||
|
if (clickMeBtn && output) {
|
||||||
|
clickMeBtn.addEventListener('clicked', () => {
|
||||||
|
output.textContent = `Clicked: Default button at ${new Date().toLocaleTimeString()}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataBtn && output) {
|
||||||
|
dataBtn.addEventListener('clicked', (e: CustomEvent) => {
|
||||||
|
output.textContent = `Clicked: Secondary button with data: ${e.detail.data}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asyncBtn && output) {
|
||||||
|
asyncBtn.addEventListener('clicked', async () => {
|
||||||
|
output.textContent = 'Processing...';
|
||||||
|
await domtools.plugins.smartdelay.delayFor(2000);
|
||||||
|
output.textContent = 'Action completed!';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'5. Event Handling'} .subtitle=${'Interactive examples with click event handling'}>
|
<dees-panel .title=${'5. Event Handling'} .subtitle=${'Interactive examples with click event handling'}>
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<dees-button
|
<dees-button>Click Me</dees-button>
|
||||||
@clicked=${() => {
|
<dees-button type="secondary" .eventDetailData=${'custom-data-123'}>
|
||||||
const output = document.querySelector('#click-output');
|
|
||||||
if (output) {
|
|
||||||
output.textContent = `Clicked: Default button at ${new Date().toLocaleTimeString()}`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Click Me
|
|
||||||
</dees-button>
|
|
||||||
|
|
||||||
<dees-button
|
|
||||||
type="secondary"
|
|
||||||
.eventDetailData=${'custom-data-123'}
|
|
||||||
@clicked=${(e: CustomEvent) => {
|
|
||||||
const output = document.querySelector('#click-output');
|
|
||||||
if (output) {
|
|
||||||
output.textContent = `Clicked: Secondary button with data: ${e.detail.data}`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Click with Data
|
Click with Data
|
||||||
</dees-button>
|
</dees-button>
|
||||||
|
<dees-button type="destructive">Async Action</dees-button>
|
||||||
<dees-button
|
|
||||||
type="destructive"
|
|
||||||
@clicked=${async () => {
|
|
||||||
const output = document.querySelector('#click-output');
|
|
||||||
if (output) {
|
|
||||||
output.textContent = 'Processing...';
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
output.textContent = 'Action completed!';
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Async Action
|
|
||||||
</dees-button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="click-output" class="demo-output">
|
<div id="click-output" class="demo-output">
|
||||||
<em>Click a button to see the result...</em>
|
<em>Click a button to see the result...</em>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Set up form submission handling
|
||||||
|
const form = elementArg.querySelector('dees-form');
|
||||||
|
const output = elementArg.querySelector('#form-output');
|
||||||
|
|
||||||
|
if (form && output) {
|
||||||
|
form.addEventListener('formData', (e: CustomEvent) => {
|
||||||
|
output.innerHTML = '<strong>Form submitted with data:</strong><br>' +
|
||||||
|
JSON.stringify(e.detail.data, null, 2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track non-submit button clicks
|
||||||
|
const draftBtn = elementArg.querySelector('dees-button[type="secondary"]');
|
||||||
|
const cancelBtn = elementArg.querySelector('dees-button[type="ghost"]');
|
||||||
|
|
||||||
|
if (draftBtn) {
|
||||||
|
draftBtn.addEventListener('clicked', () => {
|
||||||
|
console.log('Save Draft clicked');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelBtn) {
|
||||||
|
cancelBtn.addEventListener('clicked', () => {
|
||||||
|
console.log('Cancel clicked');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'6. Form Integration'} .subtitle=${'Buttons working within forms with automatic spacing'}>
|
<dees-panel .title=${'6. Form Integration'} .subtitle=${'Buttons working within forms with automatic spacing'}>
|
||||||
<dees-form @formData=${(e: CustomEvent) => {
|
<dees-form>
|
||||||
const output = document.querySelector('#form-output');
|
|
||||||
if (output) {
|
|
||||||
output.innerHTML = '<strong>Form submitted with data:</strong><br>' +
|
|
||||||
JSON.stringify(e.detail.data, null, 2);
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
<dees-input-text label="Name" key="name" required></dees-input-text>
|
<dees-input-text label="Name" key="name" required></dees-input-text>
|
||||||
<dees-input-text label="Email" key="email" type="email" required></dees-input-text>
|
<dees-input-text label="Email" key="email" type="email" required></dees-input-text>
|
||||||
<dees-input-text label="Message" key="message" isMultiline></dees-input-text>
|
<dees-input-text label="Message" key="message" isMultiline></dees-input-text>
|
||||||
@@ -237,7 +318,18 @@ export const demoFunc = () => html`
|
|||||||
<em>Submit the form to see the data...</em>
|
<em>Submit the form to see the data...</em>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Log legacy type mappings
|
||||||
|
const buttons = elementArg.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach((button) => {
|
||||||
|
const type = button.getAttribute('type');
|
||||||
|
if (type) {
|
||||||
|
console.log(`Legacy type "${type}" is supported for backward compatibility`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'7. Backward Compatibility'} .subtitle=${'Old button types are automatically mapped to new variants'}>
|
<dees-panel .title=${'7. Backward Compatibility'} .subtitle=${'Old button types are automatically mapped to new variants'}>
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<dees-button type="normal">Normal → Default</dees-button>
|
<dees-button type="normal">Normal → Default</dees-button>
|
||||||
@@ -250,7 +342,35 @@ export const demoFunc = () => html`
|
|||||||
These legacy type values are maintained for backward compatibility but we recommend using the new variant system.
|
These legacy type values are maintained for backward compatibility but we recommend using the new variant system.
|
||||||
</p>
|
</p>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Track action group clicks
|
||||||
|
const actionGroup = elementArg.querySelectorAll('.vertical-group')[0];
|
||||||
|
const dangerGroup = elementArg.querySelectorAll('.vertical-group')[1];
|
||||||
|
|
||||||
|
if (actionGroup) {
|
||||||
|
const buttons = actionGroup.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach((button, index) => {
|
||||||
|
button.addEventListener('clicked', () => {
|
||||||
|
const action = ['Save Changes', 'Discard', 'Help'][index];
|
||||||
|
console.log(`Action group: ${action} clicked`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dangerGroup) {
|
||||||
|
const buttons = dangerGroup.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach((button, index) => {
|
||||||
|
button.addEventListener('clicked', () => {
|
||||||
|
const action = ['Delete Account', 'Archive Data', 'Not Available'][index];
|
||||||
|
if (index !== 2) { // Skip disabled button
|
||||||
|
console.log(`Danger zone: ${action} clicked`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'8. Advanced Examples'} .subtitle=${'Complex button configurations and real-world use cases'}>
|
<dees-panel .title=${'8. Advanced Examples'} .subtitle=${'Complex button configurations and real-world use cases'}>
|
||||||
<div class="horizontal-group">
|
<div class="horizontal-group">
|
||||||
<div class="vertical-group">
|
<div class="vertical-group">
|
||||||
@@ -296,6 +416,6 @@ export const demoFunc = () => html`
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
</div>
|
</dees-demowrapper>
|
||||||
</dees-demowrapper>
|
</div>
|
||||||
`;
|
`;
|
@@ -168,7 +168,7 @@ export class DeesChips extends DeesElement {
|
|||||||
event.stopPropagation(); // prevent the selectChip event from being triggered
|
event.stopPropagation(); // prevent the selectChip event from being triggered
|
||||||
this.removeChip(chip);
|
this.removeChip(chip);
|
||||||
}}
|
}}
|
||||||
.iconFA=${'xmark'}
|
.icon=${'fa:xmark'}
|
||||||
></dees-icon>
|
></dees-icon>
|
||||||
`
|
`
|
||||||
: html``}
|
: html``}
|
||||||
|
47
ts_web/elements/dees-dashboardgrid/README.md
Normal file
47
ts_web/elements/dees-dashboardgrid/README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# dees-dashboardgrid
|
||||||
|
|
||||||
|
`<dees-dashboardgrid>` renders a configurable dashboard layout with draggable and resizable tiles. The component is now grouped in its own folder alongside supporting utilities and styles.
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
- Pointer-driven drag and resize interactions with keyboard fallbacks (arrow keys to move, `Shift` + arrows to resize).
|
||||||
|
- Collision-aware placement that swaps compatible tiles or displaces blocking tiles into the next free slot.
|
||||||
|
- Context menu (right-click on a tile header) that exposes destructive actions such as tile removal via `dees-contextmenu`.
|
||||||
|
- Layout persistence helpers via `getLayout()`, `setLayout(...)`, and the `layout-change` event.
|
||||||
|
- Responsive presets through the `layouts` map and `applyBreakpointLayout(...)` helper to hydrate per-breakpoint arrangements.
|
||||||
|
|
||||||
|
## Public API Highlights
|
||||||
|
|
||||||
|
| Property | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `widgets` | Array of tile descriptors (`DashboardWidget`). |
|
||||||
|
| `columns` | Number of grid columns. |
|
||||||
|
| `layouts` | Optional record of named layout definitions. |
|
||||||
|
| `activeBreakpoint` | Name of the currently applied breakpoint layout. |
|
||||||
|
| `editable` | Toggles drag/resize affordances. |
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `addWidget(widget, autoPosition?)` | Adds a tile, optionally auto-placing it into the next free slot. |
|
||||||
|
| `removeWidget(id)` | Removes a tile and emits `widget-remove`. |
|
||||||
|
| `applyBreakpointLayout(name)` | Applies a layout from the `layouts` map. |
|
||||||
|
| `getLayout()` / `setLayout(layout)` | Retrieve or apply persisted layouts. |
|
||||||
|
| `compact(direction?)` | Densifies the grid vertically (default) or horizontally. |
|
||||||
|
|
||||||
|
| Event | Detail payload |
|
||||||
|
| --- | --- |
|
||||||
|
| `widget-move` | `{ widget, displaced, swappedWith }` |
|
||||||
|
| `widget-resize` | `{ widget, displaced, swappedWith }` |
|
||||||
|
| `widget-remove` | `{ widget }` |
|
||||||
|
| `layout-change` | `{ layout }` |
|
||||||
|
|
||||||
|
## Usage Notes
|
||||||
|
|
||||||
|
- **Right-click** a tile header to open the contextual menu and delete the tile.
|
||||||
|
- When resizing, blocking tiles will automatically reflow into free space once the interaction completes.
|
||||||
|
- Listen to `layout-change` to persist layouts to storage; rehydrate using `setLayout` or the `layouts` map.
|
||||||
|
- For responsive dashboards, populate `grid.layouts = { base: [...], mobile: [...] }` and call `applyBreakpointLayout` based on your own breakpoint logic (see the co-located demo for an example).
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
The updated `dees-dashboardgrid.demo.ts` showcases live breakpoint switching, layout persistence, and the context menu. Run the demo gallery to explore the interactions end-to-end.
|
29
ts_web/elements/dees-dashboardgrid/contextmenu.ts
Normal file
29
ts_web/elements/dees-dashboardgrid/contextmenu.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import type { DashboardWidget } from './types.js';
|
||||||
|
import { DeesContextmenu } from '../dees-contextmenu.js';
|
||||||
|
import type { DeesDashboardgrid } from './dees-dashboardgrid.js';
|
||||||
|
import * as plugins from '../00plugins.js';
|
||||||
|
|
||||||
|
export interface WidgetContextMenuOptions {
|
||||||
|
widget: DashboardWidget;
|
||||||
|
host: DeesDashboardgrid;
|
||||||
|
event: MouseEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const openWidgetContextMenu = ({
|
||||||
|
widget,
|
||||||
|
host,
|
||||||
|
event,
|
||||||
|
}: WidgetContextMenuOptions) => {
|
||||||
|
const items: (plugins.tsclass.website.IMenuItem | { divider: true })[] = [
|
||||||
|
{
|
||||||
|
name: 'Delete tile',
|
||||||
|
iconName: 'lucide:trash2' as any,
|
||||||
|
action: async () => {
|
||||||
|
host.removeWidget(widget.id);
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
DeesContextmenu.openContextMenuWithOptions(event, items as any);
|
||||||
|
};
|
405
ts_web/elements/dees-dashboardgrid/dees-dashboardgrid.demo.ts
Normal file
405
ts_web/elements/dees-dashboardgrid/dees-dashboardgrid.demo.ts
Normal file
@@ -0,0 +1,405 @@
|
|||||||
|
import { html, css, cssManager } from '@design.estate/dees-element';
|
||||||
|
import type { DeesDashboardgrid } from './dees-dashboardgrid.js';
|
||||||
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
|
|
||||||
|
export const demoFunc = () => {
|
||||||
|
return html`
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
const grid = elementArg.querySelector('#dashboardGrid') as DeesDashboardgrid;
|
||||||
|
|
||||||
|
const seedWidgets = [
|
||||||
|
{
|
||||||
|
id: 'metrics1',
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
w: 3,
|
||||||
|
h: 2,
|
||||||
|
title: 'Revenue',
|
||||||
|
icon: 'lucide:dollarSign',
|
||||||
|
content: html`
|
||||||
|
<div style="padding: 20px;">
|
||||||
|
<div style="font-size: 32px; font-weight: 700; color: ${cssManager.bdTheme('#09090b', '#fafafa')};">$124,563</div>
|
||||||
|
<div style="color: #22c55e; font-size: 14px; margin-top: 8px;">↑ 12.5% from last month</div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'metrics2',
|
||||||
|
x: 3,
|
||||||
|
y: 0,
|
||||||
|
w: 3,
|
||||||
|
h: 2,
|
||||||
|
title: 'Users',
|
||||||
|
icon: 'lucide:users',
|
||||||
|
content: html`
|
||||||
|
<div style="padding: 20px;">
|
||||||
|
<div style="font-size: 32px; font-weight: 700; color: ${cssManager.bdTheme('#09090b', '#fafafa')};">8,234</div>
|
||||||
|
<div style="color: #3b82f6; font-size: 14px; margin-top: 8px;">↑ 5.2% from last week</div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'chart1',
|
||||||
|
x: 6,
|
||||||
|
y: 0,
|
||||||
|
w: 6,
|
||||||
|
h: 4,
|
||||||
|
title: 'Analytics',
|
||||||
|
icon: 'lucide:lineChart',
|
||||||
|
content: html`
|
||||||
|
<div style="padding: 20px; height: 100%; display: flex; align-items: center; justify-content: center;">
|
||||||
|
<div style="text-align: center; color: #71717a;">
|
||||||
|
<dees-icon .icon=${'lucide:lineChart'} style="font-size: 48px; margin-bottom: 16px;"></dees-icon>
|
||||||
|
<div>Chart visualization area</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
grid.widgets = seedWidgets.map(widget => ({ ...widget }));
|
||||||
|
grid.cellHeight = 80;
|
||||||
|
grid.margin = { top: 10, right: 10, bottom: 10, left: 10 };
|
||||||
|
grid.enableAnimation = true;
|
||||||
|
grid.showGridLines = false;
|
||||||
|
|
||||||
|
const baseLayout = grid.getLayout().map(item => ({ ...item }));
|
||||||
|
const mobileLayout = grid.widgets.map((widget, index) => ({
|
||||||
|
id: widget.id,
|
||||||
|
x: 0,
|
||||||
|
y: index === 0 ? 0 : grid.widgets.slice(0, index).reduce((acc, prev) => acc + prev.h, 0),
|
||||||
|
w: grid.columns,
|
||||||
|
h: widget.h,
|
||||||
|
}));
|
||||||
|
|
||||||
|
grid.layouts = {
|
||||||
|
base: baseLayout,
|
||||||
|
mobile: mobileLayout,
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusEl = elementArg.querySelector('#dashboardLayoutStatus') as HTMLElement;
|
||||||
|
const updateStatus = () => {
|
||||||
|
const layout = grid.getLayout();
|
||||||
|
statusEl.textContent = `Active breakpoint: ${grid.activeBreakpoint} • Tiles: ${layout.length}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const mediaQuery = window.matchMedia('(max-width: 768px)');
|
||||||
|
const handleBreakpoint = () => {
|
||||||
|
const target = mediaQuery.matches ? 'mobile' : 'base';
|
||||||
|
grid.applyBreakpointLayout(target);
|
||||||
|
updateStatus();
|
||||||
|
};
|
||||||
|
if (typeof mediaQuery.addEventListener === 'function') {
|
||||||
|
mediaQuery.addEventListener('change', handleBreakpoint);
|
||||||
|
} else {
|
||||||
|
(mediaQuery as MediaQueryList & {
|
||||||
|
addListener?: (listener: (this: MediaQueryList, ev: MediaQueryListEvent) => void) => void;
|
||||||
|
}).addListener?.(handleBreakpoint);
|
||||||
|
}
|
||||||
|
handleBreakpoint();
|
||||||
|
|
||||||
|
let widgetCounter = 4;
|
||||||
|
|
||||||
|
const buttons = elementArg.querySelectorAll('dees-button');
|
||||||
|
buttons.forEach(button => {
|
||||||
|
const text = button.textContent?.trim();
|
||||||
|
|
||||||
|
switch (text) {
|
||||||
|
case 'Toggle Animation':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
grid.enableAnimation = !grid.enableAnimation;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'Toggle Grid Lines':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
grid.showGridLines = !grid.showGridLines;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'Add Widget':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
const newWidget = {
|
||||||
|
id: `widget${widgetCounter++}`,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
w: 3,
|
||||||
|
h: 2,
|
||||||
|
autoPosition: true,
|
||||||
|
title: `Widget ${widgetCounter - 1}`,
|
||||||
|
icon: 'lucide:package',
|
||||||
|
content: html`
|
||||||
|
<div style="padding: 20px; text-align: center;">
|
||||||
|
<div style="color: #71717a;">New widget content</div>
|
||||||
|
<div style="margin-top: 8px; font-size: 24px; font-weight: 600; color: ${cssManager.bdTheme('#09090b', '#fafafa')};">${Math.floor(
|
||||||
|
Math.random() * 1000,
|
||||||
|
)}</div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
grid.addWidget(newWidget, true);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'Compact Grid':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
grid.compact();
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'Toggle Edit Mode':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
grid.editable = !grid.editable;
|
||||||
|
button.textContent = grid.editable ? 'Lock Grid' : 'Unlock Grid';
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'Reset Layout':
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
grid.applyBreakpointLayout(grid.activeBreakpoint);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enhanced logging for reflow events
|
||||||
|
let lastPlaceholderPosition = null;
|
||||||
|
let moveEventCounter = 0;
|
||||||
|
|
||||||
|
// Helper function to log grid state
|
||||||
|
const logGridState = (eventName: string, details?: any) => {
|
||||||
|
const layout = grid.getLayout();
|
||||||
|
console.group(`🔄 ${eventName} [Event #${++moveEventCounter}]`);
|
||||||
|
console.log('Timestamp:', new Date().toISOString());
|
||||||
|
console.log('Grid Configuration:', {
|
||||||
|
columns: grid.columns,
|
||||||
|
cellHeight: grid.cellHeight,
|
||||||
|
margin: grid.margin,
|
||||||
|
editable: grid.editable,
|
||||||
|
activeBreakpoint: grid.activeBreakpoint
|
||||||
|
});
|
||||||
|
console.log('Current Layout:', layout);
|
||||||
|
console.log('Widget Count:', layout.length);
|
||||||
|
console.log('Grid Bounds:', {
|
||||||
|
totalWidgets: grid.widgets.length,
|
||||||
|
maxY: Math.max(...layout.map(w => w.y + w.h)),
|
||||||
|
occupied: layout.map(w => `${w.id}: (${w.x},${w.y}) ${w.w}x${w.h}`).join(', ')
|
||||||
|
});
|
||||||
|
if (details) {
|
||||||
|
console.log('Event Details:', details);
|
||||||
|
}
|
||||||
|
console.groupEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Monitor placeholder position changes using MutationObserver
|
||||||
|
const placeholderObserver = new MutationObserver(() => {
|
||||||
|
const placeholder = grid.shadowRoot?.querySelector('.placeholder') as HTMLElement;
|
||||||
|
if (placeholder) {
|
||||||
|
const currentPosition = {
|
||||||
|
left: placeholder.style.left,
|
||||||
|
top: placeholder.style.top,
|
||||||
|
width: placeholder.style.width,
|
||||||
|
height: placeholder.style.height
|
||||||
|
};
|
||||||
|
|
||||||
|
if (JSON.stringify(currentPosition) !== JSON.stringify(lastPlaceholderPosition)) {
|
||||||
|
console.group('📍 Placeholder Position Changed');
|
||||||
|
console.log('Previous:', lastPlaceholderPosition);
|
||||||
|
console.log('Current:', currentPosition);
|
||||||
|
|
||||||
|
// Extract grid coordinates from style
|
||||||
|
const gridInfo = grid.shadowRoot?.querySelector('.grid-container');
|
||||||
|
if (gridInfo) {
|
||||||
|
console.log('Grid Container Dimensions:', {
|
||||||
|
width: gridInfo.clientWidth,
|
||||||
|
height: gridInfo.clientHeight
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.groupEnd();
|
||||||
|
lastPlaceholderPosition = currentPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start observing the shadow DOM for placeholder changes
|
||||||
|
if (grid.shadowRoot) {
|
||||||
|
placeholderObserver.observe(grid.shadowRoot, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['style']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log initial state
|
||||||
|
logGridState('Initial Grid State');
|
||||||
|
|
||||||
|
grid.addEventListener('widget-move', (e: CustomEvent) => {
|
||||||
|
logGridState('Widget Move', {
|
||||||
|
widget: e.detail.widget,
|
||||||
|
displaced: e.detail.displaced,
|
||||||
|
swappedWith: e.detail.swappedWith
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
grid.addEventListener('widget-resize', (e: CustomEvent) => {
|
||||||
|
logGridState('Widget Resize', {
|
||||||
|
widget: e.detail.widget,
|
||||||
|
displaced: e.detail.displaced,
|
||||||
|
swappedWith: e.detail.swappedWith
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
grid.addEventListener('widget-remove', (e: CustomEvent) => {
|
||||||
|
logGridState('Widget Remove', {
|
||||||
|
removedWidget: e.detail.widget
|
||||||
|
});
|
||||||
|
updateStatus();
|
||||||
|
});
|
||||||
|
|
||||||
|
grid.addEventListener('layout-change', () => {
|
||||||
|
logGridState('Layout Change');
|
||||||
|
updateStatus();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Monitor during drag/resize operations using pointer events
|
||||||
|
grid.addEventListener('pointerdown', (e: PointerEvent) => {
|
||||||
|
const isHeader = (e.target as HTMLElement).closest('.widget-header');
|
||||||
|
const isResizeHandle = (e.target as HTMLElement).closest('.resize-handle');
|
||||||
|
|
||||||
|
if (isHeader || isResizeHandle) {
|
||||||
|
console.group(`🎯 Interaction Started: ${isHeader ? 'Drag' : 'Resize'}`);
|
||||||
|
console.log('Target Widget:', (e.target as HTMLElement).closest('.widget')?.getAttribute('data-widget-id'));
|
||||||
|
console.log('Pointer Position:', { x: e.clientX, y: e.clientY });
|
||||||
|
console.groupEnd();
|
||||||
|
|
||||||
|
// Track pointer move during interaction
|
||||||
|
const handlePointerMove = (moveEvent: PointerEvent) => {
|
||||||
|
const widget = (e.target as HTMLElement).closest('.widget');
|
||||||
|
if (widget) {
|
||||||
|
console.log(`↔️ Pointer Move:`, {
|
||||||
|
widgetId: widget.getAttribute('data-widget-id'),
|
||||||
|
position: { x: moveEvent.clientX, y: moveEvent.clientY },
|
||||||
|
delta: {
|
||||||
|
x: moveEvent.clientX - e.clientX,
|
||||||
|
y: moveEvent.clientY - e.clientY
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePointerUp = () => {
|
||||||
|
console.group('🏁 Interaction Ended');
|
||||||
|
logGridState('Final State After Interaction');
|
||||||
|
console.groupEnd();
|
||||||
|
document.removeEventListener('pointermove', handlePointerMove);
|
||||||
|
document.removeEventListener('pointerup', handlePointerUp);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('pointermove', handlePointerMove);
|
||||||
|
document.addEventListener('pointerup', handlePointerUp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log when widgets are added
|
||||||
|
const originalAddWidget = grid.addWidget.bind(grid);
|
||||||
|
grid.addWidget = (widget: any, autoPosition?: boolean) => {
|
||||||
|
console.group('➕ Adding Widget');
|
||||||
|
console.log('New Widget:', widget);
|
||||||
|
console.log('Auto Position:', autoPosition);
|
||||||
|
const result = originalAddWidget(widget, autoPosition);
|
||||||
|
logGridState('After Widget Added');
|
||||||
|
console.groupEnd();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Log compact operations
|
||||||
|
const originalCompact = grid.compact.bind(grid);
|
||||||
|
grid.compact = (direction?: string) => {
|
||||||
|
console.group('🗜️ Compacting Grid');
|
||||||
|
console.log('Direction:', direction || 'vertical');
|
||||||
|
logGridState('Before Compact');
|
||||||
|
const result = originalCompact(direction);
|
||||||
|
logGridState('After Compact');
|
||||||
|
console.groupEnd();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
updateStatus();
|
||||||
|
}}>
|
||||||
|
<style>
|
||||||
|
${css`
|
||||||
|
.demoBox {
|
||||||
|
position: relative;
|
||||||
|
background: ${cssManager.bdTheme('#f4f4f5', '#09090b')};
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 40px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.demo-controls {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.demo-controls dees-button {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-container-wrapper {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 600px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
color: ${cssManager.bdTheme('#71717a', '#71717a')};
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: 'Geist Sans', sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dashboardLayoutStatus {
|
||||||
|
font-weight: 600;
|
||||||
|
color: ${cssManager.bdTheme('#3b82f6', '#60a5fa')};
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
<div class="demoBox">
|
||||||
|
<div class="demo-controls">
|
||||||
|
<dees-button-group label="Animation:">
|
||||||
|
<dees-button>Toggle Animation</dees-button>
|
||||||
|
</dees-button-group>
|
||||||
|
|
||||||
|
<dees-button-group label="Display:">
|
||||||
|
<dees-button>Toggle Grid Lines</dees-button>
|
||||||
|
</dees-button-group>
|
||||||
|
|
||||||
|
<dees-button-group label="Actions:">
|
||||||
|
<dees-button>Add Widget</dees-button>
|
||||||
|
<dees-button>Compact Grid</dees-button>
|
||||||
|
<dees-button>Reset Layout</dees-button>
|
||||||
|
</dees-button-group>
|
||||||
|
|
||||||
|
<dees-button-group label="Mode:">
|
||||||
|
<dees-button>Toggle Edit Mode</dees-button>
|
||||||
|
</dees-button-group>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid-container-wrapper">
|
||||||
|
<dees-dashboardgrid id="dashboardGrid"></dees-dashboardgrid>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="info">
|
||||||
|
<div>Drag to reposition, resize from handles, or right-click a header to delete a tile.</div>
|
||||||
|
<div id="dashboardLayoutStatus"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dees-demowrapper>
|
||||||
|
`;
|
||||||
|
};
|
796
ts_web/elements/dees-dashboardgrid/dees-dashboardgrid.ts
Normal file
796
ts_web/elements/dees-dashboardgrid/dees-dashboardgrid.ts
Normal file
@@ -0,0 +1,796 @@
|
|||||||
|
import {
|
||||||
|
DeesElement,
|
||||||
|
customElement,
|
||||||
|
property,
|
||||||
|
state,
|
||||||
|
html,
|
||||||
|
type TemplateResult,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
import '../dees-icon.js';
|
||||||
|
import '../dees-contextmenu.js';
|
||||||
|
import { demoFunc } from './dees-dashboardgrid.demo.js';
|
||||||
|
import { dashboardGridStyles } from './styles.js';
|
||||||
|
import {
|
||||||
|
resolveMargins,
|
||||||
|
calculateCellMetrics,
|
||||||
|
calculateGridHeight,
|
||||||
|
findAvailablePosition,
|
||||||
|
compactLayout,
|
||||||
|
applyLayout,
|
||||||
|
resolveWidgetPlacement,
|
||||||
|
type PlacementResult,
|
||||||
|
} from './layout.js';
|
||||||
|
import {
|
||||||
|
computeGridCoordinates,
|
||||||
|
computeResizeDimensions,
|
||||||
|
type PointerPosition,
|
||||||
|
} from './interaction.js';
|
||||||
|
import { openWidgetContextMenu } from './contextmenu.js';
|
||||||
|
import type {
|
||||||
|
DashboardWidget,
|
||||||
|
DashboardMargin,
|
||||||
|
DashboardResolvedMargins,
|
||||||
|
GridCellMetrics,
|
||||||
|
DashboardLayoutItem,
|
||||||
|
LayoutDirection,
|
||||||
|
CellHeightUnit,
|
||||||
|
} from './types.js';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'dees-dashboardgrid': DeesDashboardgrid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DragState = {
|
||||||
|
widgetId: string;
|
||||||
|
pointerId: number;
|
||||||
|
offsetX: number;
|
||||||
|
offsetY: number;
|
||||||
|
start: DashboardLayoutItem;
|
||||||
|
previousPosition: DashboardLayoutItem;
|
||||||
|
currentPointer: PointerPosition;
|
||||||
|
lastPlacement: PlacementResult | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ResizeState = {
|
||||||
|
widgetId: string;
|
||||||
|
pointerId: number;
|
||||||
|
handler: 'e' | 's' | 'se';
|
||||||
|
startPointer: PointerPosition;
|
||||||
|
start: DashboardLayoutItem;
|
||||||
|
startWidth: number;
|
||||||
|
startHeight: number;
|
||||||
|
lastPlacement: PlacementResult | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
@customElement('dees-dashboardgrid')
|
||||||
|
export class DeesDashboardgrid extends DeesElement {
|
||||||
|
public static demo = demoFunc;
|
||||||
|
public static styles = dashboardGridStyles;
|
||||||
|
|
||||||
|
@property({ type: Array })
|
||||||
|
public widgets: DashboardWidget[] = [];
|
||||||
|
|
||||||
|
@property({ type: Number })
|
||||||
|
public cellHeight: number = 80;
|
||||||
|
|
||||||
|
@property({ type: Object })
|
||||||
|
public margin: DashboardMargin = 10;
|
||||||
|
|
||||||
|
@property({ type: Number })
|
||||||
|
public columns: number = 12;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public editable: boolean = true;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public enableAnimation: boolean = true;
|
||||||
|
|
||||||
|
@property({ type: String })
|
||||||
|
public cellHeightUnit: CellHeightUnit = 'px';
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public rtl: boolean = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public showGridLines: boolean = false;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
public layouts?: Record<string, DashboardLayoutItem[]>;
|
||||||
|
|
||||||
|
@property({ type: String })
|
||||||
|
public activeBreakpoint: string = 'base';
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private placeholderPosition: DashboardLayoutItem | null = null;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private metrics: GridCellMetrics | null = null;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private resolvedMargins: DashboardResolvedMargins | null = null;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private previewWidgets: DashboardWidget[] | null = null;
|
||||||
|
|
||||||
|
private containerBounds: DOMRect | null = null;
|
||||||
|
private dragState: DragState | null = null;
|
||||||
|
private resizeState: ResizeState | null = null;
|
||||||
|
private resizeObserver?: ResizeObserver;
|
||||||
|
private interactionActive = false;
|
||||||
|
|
||||||
|
public override async connectedCallback(): Promise<void> {
|
||||||
|
await super.connectedCallback();
|
||||||
|
this.computeMetrics();
|
||||||
|
this.observeResize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async disconnectedCallback(): Promise<void> {
|
||||||
|
await super.disconnectedCallback();
|
||||||
|
this.disconnectResizeObserver();
|
||||||
|
this.releasePointerEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updated(changed: Map<string, unknown>): void {
|
||||||
|
if (
|
||||||
|
changed.has('margin') ||
|
||||||
|
changed.has('columns') ||
|
||||||
|
changed.has('cellHeight') ||
|
||||||
|
changed.has('cellHeightUnit')
|
||||||
|
) {
|
||||||
|
this.computeMetrics();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed.has('widgets') && !this.interactionActive) {
|
||||||
|
this.notifyLayoutChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): TemplateResult {
|
||||||
|
const baseWidgets = this.widgets;
|
||||||
|
if (baseWidgets.length === 0) {
|
||||||
|
return html`
|
||||||
|
<div class="empty-state">
|
||||||
|
<dees-icon .icon=${'lucide:layoutGrid'}></dees-icon>
|
||||||
|
<div>No widgets configured</div>
|
||||||
|
<div style="font-size: 14px; margin-top: 8px;">Add widgets to populate the dashboard</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const metrics = this.ensureMetrics();
|
||||||
|
const margins = this.resolvedMargins ?? resolveMargins(this.margin);
|
||||||
|
const cellHeight = metrics.cellHeightPx;
|
||||||
|
const layoutForHeight = this.previewWidgets ?? this.widgets;
|
||||||
|
const gridHeight = calculateGridHeight(layoutForHeight, margins, cellHeight);
|
||||||
|
const previewMap = this.previewWidgets ? new Map(this.previewWidgets.map(widget => [widget.id, widget])) : null;
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="grid-container" style="height: ${gridHeight}px;">
|
||||||
|
${this.showGridLines ? this.renderGridLines(metrics, gridHeight) : null}
|
||||||
|
${baseWidgets.map(widget => this.renderWidget(widget, metrics, margins, previewMap))}
|
||||||
|
${this.placeholderPosition ? this.renderPlaceholder(metrics, margins) : null}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderGridLines(metrics: GridCellMetrics, gridHeight: number): TemplateResult {
|
||||||
|
const vertical: TemplateResult[] = [];
|
||||||
|
const horizontal: TemplateResult[] = [];
|
||||||
|
const cellPlusMarginX = metrics.cellWidthPx + metrics.marginHorizontalPx;
|
||||||
|
const cellPlusMarginY = metrics.cellHeightPx + metrics.marginVerticalPx;
|
||||||
|
|
||||||
|
for (let i = 0; i <= this.columns; i++) {
|
||||||
|
const leftPx = i * cellPlusMarginX + metrics.marginHorizontalPx;
|
||||||
|
const leftPercent = this.pxToPercent(leftPx, metrics.containerWidth);
|
||||||
|
vertical.push(html`<div class="grid-line-vertical" style="left: ${leftPercent}%;"></div>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = Math.ceil(gridHeight / cellPlusMarginY);
|
||||||
|
for (let row = 0; row <= rows; row++) {
|
||||||
|
const top = row * cellPlusMarginY;
|
||||||
|
horizontal.push(html`<div class="grid-line-horizontal" style="top: ${top}px;"></div>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="grid-lines">
|
||||||
|
${vertical}
|
||||||
|
${horizontal}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderWidget(
|
||||||
|
widget: DashboardWidget,
|
||||||
|
metrics: GridCellMetrics,
|
||||||
|
margins: DashboardResolvedMargins,
|
||||||
|
previewMap: Map<string, DashboardWidget> | null,
|
||||||
|
): TemplateResult {
|
||||||
|
const isDragging = this.dragState?.widgetId === widget.id;
|
||||||
|
const isResizing = this.resizeState?.widgetId === widget.id;
|
||||||
|
const isLocked = widget.locked || !this.editable;
|
||||||
|
const previewWidget = previewMap?.get(widget.id) ?? null;
|
||||||
|
const layoutForRender = isDragging ? widget : previewWidget ?? widget;
|
||||||
|
const rect = this.computeWidgetRect(layoutForRender, metrics, margins);
|
||||||
|
|
||||||
|
const sideProperty = this.rtl ? 'right' : 'left';
|
||||||
|
const sideValue = this.pxToPercent(rect.left, metrics.containerWidth);
|
||||||
|
const widthPercent = this.pxToPercent(rect.width, metrics.containerWidth);
|
||||||
|
|
||||||
|
let transform = '';
|
||||||
|
if (isDragging && this.dragState?.currentPointer) {
|
||||||
|
const pointer = this.dragState.currentPointer;
|
||||||
|
const bounds = this.containerBounds ?? this.getBoundingClientRect();
|
||||||
|
const translateX = pointer.clientX - bounds.left - this.dragState.offsetX - rect.left;
|
||||||
|
const translateY = pointer.clientY - bounds.top - this.dragState.offsetY - rect.top;
|
||||||
|
transform = `transform: translate(${translateX}px, ${translateY}px);`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div
|
||||||
|
class="grid-widget ${isDragging ? 'dragging' : ''} ${isResizing ? 'resizing' : ''}"
|
||||||
|
style="
|
||||||
|
${sideProperty}: ${sideValue}%;
|
||||||
|
top: ${rect.top}px;
|
||||||
|
width: ${widthPercent}%;
|
||||||
|
height: ${rect.height}px;
|
||||||
|
${transform}
|
||||||
|
"
|
||||||
|
data-widget-id=${widget.id}
|
||||||
|
>
|
||||||
|
<div class="widget-content">
|
||||||
|
${widget.title
|
||||||
|
? html`
|
||||||
|
<div
|
||||||
|
class="widget-header ${isLocked ? 'locked' : ''}"
|
||||||
|
@pointerdown=${!isLocked && !widget.noMove
|
||||||
|
? (evt: PointerEvent) => this.startDrag(evt, widget)
|
||||||
|
: null}
|
||||||
|
@contextmenu=${(evt: MouseEvent) => this.handleWidgetContextMenu(evt, widget)}
|
||||||
|
tabindex=${!isLocked && !widget.noMove ? 0 : -1}
|
||||||
|
@keydown=${(evt: KeyboardEvent) => this.handleHeaderKeydown(evt, widget)}
|
||||||
|
>
|
||||||
|
${widget.icon ? html`<dees-icon .icon=${widget.icon}></dees-icon>` : null}
|
||||||
|
${widget.title}
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: null}
|
||||||
|
<div class="widget-body ${widget.title ? 'has-header' : ''}">
|
||||||
|
${widget.content}
|
||||||
|
</div>
|
||||||
|
${!isLocked && !widget.noResize
|
||||||
|
? html`
|
||||||
|
<div
|
||||||
|
class="resize-handle resize-handle-e"
|
||||||
|
@pointerdown=${(evt: PointerEvent) => this.startResize(evt, widget, 'e')}
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="resize-handle resize-handle-s"
|
||||||
|
@pointerdown=${(evt: PointerEvent) => this.startResize(evt, widget, 's')}
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="resize-handle resize-handle-se"
|
||||||
|
@pointerdown=${(evt: PointerEvent) => this.startResize(evt, widget, 'se')}
|
||||||
|
></div>
|
||||||
|
`
|
||||||
|
: null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private renderPlaceholder(
|
||||||
|
metrics: GridCellMetrics,
|
||||||
|
margins: DashboardResolvedMargins,
|
||||||
|
): TemplateResult {
|
||||||
|
if (!this.placeholderPosition) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rect = this.computeWidgetRect(this.placeholderPosition, metrics, margins);
|
||||||
|
const sideProperty = this.rtl ? 'right' : 'left';
|
||||||
|
const sideValue = this.pxToPercent(rect.left, metrics.containerWidth);
|
||||||
|
const widthPercent = this.pxToPercent(rect.width, metrics.containerWidth);
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div
|
||||||
|
class="grid-widget placeholder"
|
||||||
|
style="
|
||||||
|
${sideProperty}: ${sideValue}%;
|
||||||
|
top: ${rect.top}px;
|
||||||
|
width: ${widthPercent}%;
|
||||||
|
height: ${rect.height}px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div class="widget-content"></div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private startDrag(event: PointerEvent, widget: DashboardWidget): void {
|
||||||
|
if (!this.editable || widget.noMove || widget.locked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
const widgetElement = (event.currentTarget as HTMLElement).closest('.grid-widget') as HTMLElement | null;
|
||||||
|
if (!widgetElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const widgetRect = widgetElement.getBoundingClientRect();
|
||||||
|
this.containerBounds = this.getBoundingClientRect();
|
||||||
|
this.ensureMetrics();
|
||||||
|
|
||||||
|
this.dragState = {
|
||||||
|
widgetId: widget.id,
|
||||||
|
pointerId: event.pointerId,
|
||||||
|
offsetX: event.clientX - widgetRect.left,
|
||||||
|
offsetY: event.clientY - widgetRect.top,
|
||||||
|
start: { id: widget.id, x: widget.x, y: widget.y, w: widget.w, h: widget.h },
|
||||||
|
previousPosition: { id: widget.id, x: widget.x, y: widget.y, w: widget.w, h: widget.h },
|
||||||
|
currentPointer: { clientX: event.clientX, clientY: event.clientY },
|
||||||
|
lastPlacement: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.interactionActive = true;
|
||||||
|
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
||||||
|
document.addEventListener('pointermove', this.handleDragMove);
|
||||||
|
document.addEventListener('pointerup', this.handleDragEnd);
|
||||||
|
|
||||||
|
this.placeholderPosition = { id: widget.id, x: widget.x, y: widget.y, w: widget.w, h: widget.h };
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleDragMove = (event: PointerEvent): void => {
|
||||||
|
if (!this.dragState) return;
|
||||||
|
const metrics = this.ensureMetrics();
|
||||||
|
const activeWidgets = this.widgets;
|
||||||
|
const widget = activeWidgets.find(item => item.id === this.dragState!.widgetId);
|
||||||
|
if (!widget) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const previousPosition = this.dragState.previousPosition;
|
||||||
|
|
||||||
|
const coords = computeGridCoordinates({
|
||||||
|
pointer: { clientX: event.clientX, clientY: event.clientY },
|
||||||
|
containerRect: this.containerBounds ?? this.getBoundingClientRect(),
|
||||||
|
metrics,
|
||||||
|
columns: this.columns,
|
||||||
|
widget,
|
||||||
|
rtl: this.rtl,
|
||||||
|
dragOffsetX: this.dragState.offsetX,
|
||||||
|
dragOffsetY: this.dragState.offsetY,
|
||||||
|
});
|
||||||
|
|
||||||
|
const placement = resolveWidgetPlacement(
|
||||||
|
activeWidgets,
|
||||||
|
widget.id,
|
||||||
|
{ x: coords.x, y: coords.y },
|
||||||
|
this.columns,
|
||||||
|
previousPosition,
|
||||||
|
);
|
||||||
|
if (placement) {
|
||||||
|
const updatedWidget = placement.widgets.find(item => item.id === widget.id);
|
||||||
|
this.dragState = {
|
||||||
|
...this.dragState,
|
||||||
|
currentPointer: { clientX: event.clientX, clientY: event.clientY },
|
||||||
|
lastPlacement: placement,
|
||||||
|
previousPosition: updatedWidget
|
||||||
|
? { id: updatedWidget.id, x: updatedWidget.x, y: updatedWidget.y, w: updatedWidget.w, h: updatedWidget.h }
|
||||||
|
: { id: widget.id, x: coords.x, y: coords.y, w: widget.w, h: widget.h },
|
||||||
|
};
|
||||||
|
this.previewWidgets = placement.widgets;
|
||||||
|
const previewWidget = placement.widgets.find(item => item.id === widget.id);
|
||||||
|
if (previewWidget) {
|
||||||
|
this.placeholderPosition = {
|
||||||
|
id: previewWidget.id,
|
||||||
|
x: previewWidget.x,
|
||||||
|
y: previewWidget.y,
|
||||||
|
w: previewWidget.w,
|
||||||
|
h: previewWidget.h,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.placeholderPosition = { id: widget.id, x: coords.x, y: coords.y, w: widget.w, h: widget.h };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.previewWidgets = null;
|
||||||
|
this.placeholderPosition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.requestUpdate();
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleDragEnd = (event: PointerEvent): void => {
|
||||||
|
const dragState = this.dragState;
|
||||||
|
if (!dragState || event.pointerId !== dragState.pointerId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutSource = this.widgets;
|
||||||
|
this.previewWidgets = null;
|
||||||
|
|
||||||
|
// Always validate the final position, don't rely on lastPlacement from drag
|
||||||
|
const target = this.placeholderPosition ?? dragState.start;
|
||||||
|
const placement = resolveWidgetPlacement(
|
||||||
|
layoutSource,
|
||||||
|
dragState.widgetId,
|
||||||
|
{ x: target.x, y: target.y },
|
||||||
|
this.columns,
|
||||||
|
dragState.previousPosition,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (placement) {
|
||||||
|
// Verify that the placement doesn't result in overlapping widgets
|
||||||
|
const finalWidget = placement.widgets.find(w => w.id === dragState.widgetId);
|
||||||
|
if (finalWidget) {
|
||||||
|
const hasOverlap = placement.widgets.some(w => {
|
||||||
|
if (w.id === dragState.widgetId) return false;
|
||||||
|
return (
|
||||||
|
finalWidget.x < w.x + w.w &&
|
||||||
|
finalWidget.x + finalWidget.w > w.x &&
|
||||||
|
finalWidget.y < w.y + w.h &&
|
||||||
|
finalWidget.y + finalWidget.h > w.y
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasOverlap) {
|
||||||
|
this.commitPlacement(placement, dragState.widgetId, 'widget-move');
|
||||||
|
} else {
|
||||||
|
// Return to start position if overlap detected
|
||||||
|
this.widgets = this.widgets.map(widget =>
|
||||||
|
widget.id === dragState.widgetId ? { ...widget, x: dragState.start.x, y: dragState.start.y } : widget,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Return to start position if no valid placement
|
||||||
|
this.widgets = this.widgets.map(widget =>
|
||||||
|
widget.id === dragState.widgetId ? { ...widget, x: dragState.start.x, y: dragState.start.y } : widget,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.placeholderPosition = null;
|
||||||
|
this.dragState = null;
|
||||||
|
this.interactionActive = false;
|
||||||
|
this.releasePointerEvents();
|
||||||
|
};
|
||||||
|
|
||||||
|
private startResize(event: PointerEvent, widget: DashboardWidget, handler: 'e' | 's' | 'se'): void {
|
||||||
|
if (!this.editable || widget.noResize || widget.locked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
this.ensureMetrics();
|
||||||
|
|
||||||
|
this.resizeState = {
|
||||||
|
widgetId: widget.id,
|
||||||
|
pointerId: event.pointerId,
|
||||||
|
handler,
|
||||||
|
startPointer: { clientX: event.clientX, clientY: event.clientY },
|
||||||
|
start: { id: widget.id, x: widget.x, y: widget.y, w: widget.w, h: widget.h },
|
||||||
|
startWidth: widget.w,
|
||||||
|
startHeight: widget.h,
|
||||||
|
lastPlacement: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.interactionActive = true;
|
||||||
|
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
||||||
|
document.addEventListener('pointermove', this.handleResizeMove);
|
||||||
|
document.addEventListener('pointerup', this.handleResizeEnd);
|
||||||
|
|
||||||
|
this.placeholderPosition = { id: widget.id, x: widget.x, y: widget.y, w: widget.w, h: widget.h };
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleResizeMove = (event: PointerEvent): void => {
|
||||||
|
if (!this.resizeState) return;
|
||||||
|
const metrics = this.ensureMetrics();
|
||||||
|
const activeWidgets = this.widgets;
|
||||||
|
const widget = activeWidgets.find(item => item.id === this.resizeState!.widgetId);
|
||||||
|
if (!widget) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const nextSize = computeResizeDimensions({
|
||||||
|
pointer: { clientX: event.clientX, clientY: event.clientY },
|
||||||
|
containerRect: this.containerBounds ?? this.getBoundingClientRect(),
|
||||||
|
metrics,
|
||||||
|
startWidth: this.resizeState.startWidth,
|
||||||
|
startHeight: this.resizeState.startHeight,
|
||||||
|
startPointer: this.resizeState.startPointer,
|
||||||
|
handler: this.resizeState.handler,
|
||||||
|
widget,
|
||||||
|
columns: this.columns,
|
||||||
|
});
|
||||||
|
|
||||||
|
const placement = resolveWidgetPlacement(
|
||||||
|
activeWidgets,
|
||||||
|
widget.id,
|
||||||
|
{ x: widget.x, y: widget.y, w: nextSize.width, h: nextSize.height },
|
||||||
|
this.columns,
|
||||||
|
this.resizeState.start,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (placement) {
|
||||||
|
this.resizeState = { ...this.resizeState, lastPlacement: placement };
|
||||||
|
this.previewWidgets = placement.widgets;
|
||||||
|
const previewWidget = placement.widgets.find(item => item.id === widget.id);
|
||||||
|
if (previewWidget) {
|
||||||
|
this.placeholderPosition = {
|
||||||
|
id: previewWidget.id,
|
||||||
|
x: previewWidget.x,
|
||||||
|
y: previewWidget.y,
|
||||||
|
w: previewWidget.w,
|
||||||
|
h: previewWidget.h,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.placeholderPosition = {
|
||||||
|
id: widget.id,
|
||||||
|
x: widget.x,
|
||||||
|
y: widget.y,
|
||||||
|
w: nextSize.width,
|
||||||
|
h: nextSize.height,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.previewWidgets = null;
|
||||||
|
this.placeholderPosition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.requestUpdate();
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleResizeEnd = (event: PointerEvent): void => {
|
||||||
|
const resizeState = this.resizeState;
|
||||||
|
if (!resizeState || event.pointerId !== resizeState.pointerId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutSource = this.widgets;
|
||||||
|
this.previewWidgets = null;
|
||||||
|
const placement =
|
||||||
|
resizeState.lastPlacement ??
|
||||||
|
resolveWidgetPlacement(
|
||||||
|
layoutSource,
|
||||||
|
resizeState.widgetId,
|
||||||
|
{
|
||||||
|
x: this.placeholderPosition?.x ?? resizeState.start.x,
|
||||||
|
y: this.placeholderPosition?.y ?? resizeState.start.y,
|
||||||
|
w: this.placeholderPosition?.w ?? resizeState.start.w,
|
||||||
|
h: this.placeholderPosition?.h ?? resizeState.start.h,
|
||||||
|
},
|
||||||
|
this.columns,
|
||||||
|
resizeState.start,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (placement) {
|
||||||
|
this.commitPlacement(placement, resizeState.widgetId, 'widget-resize');
|
||||||
|
} else {
|
||||||
|
this.widgets = this.widgets.map(widget =>
|
||||||
|
widget.id === resizeState.widgetId ? { ...widget, w: resizeState.start.w, h: resizeState.start.h } : widget,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.placeholderPosition = null;
|
||||||
|
this.resizeState = null;
|
||||||
|
this.interactionActive = false;
|
||||||
|
this.releasePointerEvents();
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleHeaderKeydown(event: KeyboardEvent, widget: DashboardWidget): void {
|
||||||
|
if (!this.editable || widget.noMove || widget.locked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = event.key;
|
||||||
|
const isResize = event.shiftKey;
|
||||||
|
let placement: PlacementResult | null = null;
|
||||||
|
|
||||||
|
if (isResize && ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(key)) {
|
||||||
|
event.preventDefault();
|
||||||
|
const delta = key === 'ArrowRight' || key === 'ArrowDown' ? 1 : -1;
|
||||||
|
|
||||||
|
if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
||||||
|
const maxWidth = widget.maxW ?? this.columns - widget.x;
|
||||||
|
const nextWidth = Math.max(widget.minW ?? 1, Math.min(maxWidth, widget.w + delta));
|
||||||
|
placement = resolveWidgetPlacement(
|
||||||
|
this.widgets,
|
||||||
|
widget.id,
|
||||||
|
{ x: widget.x, y: widget.y, w: nextWidth, h: widget.h },
|
||||||
|
this.columns,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const maxHeight = widget.maxH ?? Number.POSITIVE_INFINITY;
|
||||||
|
const nextHeight = Math.max(widget.minH ?? 1, Math.min(maxHeight, widget.h + delta));
|
||||||
|
placement = resolveWidgetPlacement(
|
||||||
|
this.widgets,
|
||||||
|
widget.id,
|
||||||
|
{ x: widget.x, y: widget.y, w: widget.w, h: nextHeight },
|
||||||
|
this.columns,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placement) {
|
||||||
|
this.commitPlacement(placement, widget.id, 'widget-resize');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const moveMap: Record<string, { dx: number; dy: number }> = {
|
||||||
|
ArrowLeft: { dx: -1, dy: 0 },
|
||||||
|
ArrowRight: { dx: 1, dy: 0 },
|
||||||
|
ArrowUp: { dx: 0, dy: -1 },
|
||||||
|
ArrowDown: { dx: 0, dy: 1 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const delta = moveMap[key];
|
||||||
|
if (!delta) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
const targetX = Math.max(0, Math.min(this.columns - widget.w, widget.x + delta.dx));
|
||||||
|
const targetY = Math.max(0, widget.y + delta.dy);
|
||||||
|
|
||||||
|
placement = resolveWidgetPlacement(this.widgets, widget.id, { x: targetX, y: targetY }, this.columns);
|
||||||
|
if (placement) {
|
||||||
|
this.commitPlacement(placement, widget.id, 'widget-move');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleWidgetContextMenu(event: MouseEvent, widget: DashboardWidget): void {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
openWidgetContextMenu({ widget, host: this, event });
|
||||||
|
}
|
||||||
|
|
||||||
|
private commitPlacement(result: PlacementResult, widgetId: string, type: 'widget-move' | 'widget-resize'): void {
|
||||||
|
this.previewWidgets = null;
|
||||||
|
this.widgets = result.widgets;
|
||||||
|
const subject = this.widgets.find(item => item.id === widgetId);
|
||||||
|
if (subject) {
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent(type, {
|
||||||
|
detail: {
|
||||||
|
widget: subject,
|
||||||
|
displaced: result.movedWidgets.filter(id => id !== widgetId),
|
||||||
|
swappedWith: result.swappedWith,
|
||||||
|
},
|
||||||
|
bubbles: true,
|
||||||
|
composed: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeWidget(widgetId: string): void {
|
||||||
|
const target = this.widgets.find(widget => widget.id === widgetId);
|
||||||
|
if (!target) return;
|
||||||
|
this.widgets = this.widgets.filter(widget => widget.id !== widgetId);
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent('widget-remove', {
|
||||||
|
detail: { widget: target },
|
||||||
|
bubbles: true,
|
||||||
|
composed: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateWidget(widgetId: string, updates: Partial<DashboardWidget>): void {
|
||||||
|
this.widgets = this.widgets.map(widget => (widget.id === widgetId ? { ...widget, ...updates } : widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLayout(): DashboardLayoutItem[] {
|
||||||
|
return this.widgets.map(({ id, x, y, w, h }) => ({ id, x, y, w, h }));
|
||||||
|
}
|
||||||
|
|
||||||
|
public setLayout(layout: DashboardLayoutItem[]): void {
|
||||||
|
this.widgets = applyLayout(this.widgets, layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public lockGrid(): void {
|
||||||
|
this.editable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unlockGrid(): void {
|
||||||
|
this.editable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addWidget(widget: DashboardWidget, autoPosition = false): void {
|
||||||
|
const nextWidget = { ...widget };
|
||||||
|
if (autoPosition || nextWidget.autoPosition) {
|
||||||
|
const position = findAvailablePosition(this.widgets, nextWidget.w, nextWidget.h, this.columns);
|
||||||
|
nextWidget.x = position.x;
|
||||||
|
nextWidget.y = position.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.widgets = [...this.widgets, nextWidget];
|
||||||
|
}
|
||||||
|
|
||||||
|
public compact(direction: LayoutDirection = 'vertical'): void {
|
||||||
|
const nextWidgets = this.widgets.map(widget => ({ ...widget }));
|
||||||
|
compactLayout(nextWidgets, direction);
|
||||||
|
this.widgets = nextWidgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public applyBreakpointLayout(breakpoint: string): void {
|
||||||
|
this.activeBreakpoint = breakpoint;
|
||||||
|
const layout = this.layouts?.[breakpoint];
|
||||||
|
if (layout) {
|
||||||
|
this.setLayout(layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public notifyLayoutChange(): void {
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent('layout-change', {
|
||||||
|
detail: { layout: this.getLayout() },
|
||||||
|
bubbles: true,
|
||||||
|
composed: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ensureMetrics(): GridCellMetrics {
|
||||||
|
if (!this.metrics) {
|
||||||
|
this.computeMetrics();
|
||||||
|
}
|
||||||
|
return this.metrics!;
|
||||||
|
}
|
||||||
|
|
||||||
|
private computeMetrics(): void {
|
||||||
|
if (!this.isConnected) return;
|
||||||
|
const bounds = this.getBoundingClientRect();
|
||||||
|
this.containerBounds = bounds;
|
||||||
|
const margins = resolveMargins(this.margin);
|
||||||
|
this.resolvedMargins = margins;
|
||||||
|
this.metrics = calculateCellMetrics(bounds.width, this.columns, margins, this.cellHeight, this.cellHeightUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private observeResize(): void {
|
||||||
|
if (this.resizeObserver) return;
|
||||||
|
this.resizeObserver = new ResizeObserver(() => {
|
||||||
|
this.computeMetrics();
|
||||||
|
});
|
||||||
|
this.resizeObserver.observe(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private disconnectResizeObserver(): void {
|
||||||
|
this.resizeObserver?.disconnect();
|
||||||
|
this.resizeObserver = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private releasePointerEvents(): void {
|
||||||
|
document.removeEventListener('pointermove', this.handleDragMove);
|
||||||
|
document.removeEventListener('pointerup', this.handleDragEnd);
|
||||||
|
document.removeEventListener('pointermove', this.handleResizeMove);
|
||||||
|
document.removeEventListener('pointerup', this.handleResizeEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private pxToPercent(value: number, container: number): number {
|
||||||
|
if (!container) return 0;
|
||||||
|
return Number(((value / container) * 100).toFixed(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
private computeWidgetRect(
|
||||||
|
widget: Pick<DashboardWidget, 'x' | 'y' | 'w' | 'h'>,
|
||||||
|
metrics: GridCellMetrics,
|
||||||
|
margins: DashboardResolvedMargins,
|
||||||
|
) {
|
||||||
|
const cellWidth = metrics.cellWidthPx;
|
||||||
|
const cellHeight = metrics.cellHeightPx;
|
||||||
|
const left = widget.x * (cellWidth + margins.horizontal) + margins.horizontal;
|
||||||
|
const top = widget.y * (cellHeight + margins.vertical) + margins.vertical;
|
||||||
|
const width = widget.w * cellWidth + Math.max(0, widget.w - 1) * margins.horizontal;
|
||||||
|
const height = widget.h * cellHeight + Math.max(0, widget.h - 1) * margins.vertical;
|
||||||
|
|
||||||
|
return { left, top, width, height };
|
||||||
|
}
|
||||||
|
}
|
2
ts_web/elements/dees-dashboardgrid/index.ts
Normal file
2
ts_web/elements/dees-dashboardgrid/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './dees-dashboardgrid.js';
|
||||||
|
export * from './types.js';
|
105
ts_web/elements/dees-dashboardgrid/interaction.ts
Normal file
105
ts_web/elements/dees-dashboardgrid/interaction.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import type { DashboardWidget, GridCellMetrics } from './types.js';
|
||||||
|
|
||||||
|
export interface PointerPosition {
|
||||||
|
clientX: number;
|
||||||
|
clientY: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DragComputationArgs {
|
||||||
|
pointer: PointerPosition;
|
||||||
|
containerRect: DOMRect;
|
||||||
|
metrics: GridCellMetrics;
|
||||||
|
columns: number;
|
||||||
|
widget: DashboardWidget;
|
||||||
|
rtl: boolean;
|
||||||
|
dragOffsetX?: number;
|
||||||
|
dragOffsetY?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const computeGridCoordinates = ({
|
||||||
|
pointer,
|
||||||
|
containerRect,
|
||||||
|
metrics,
|
||||||
|
columns,
|
||||||
|
widget,
|
||||||
|
rtl,
|
||||||
|
dragOffsetX = 0,
|
||||||
|
dragOffsetY = 0,
|
||||||
|
}: DragComputationArgs): { x: number; y: number } => {
|
||||||
|
const relativeX = pointer.clientX - containerRect.left - dragOffsetX;
|
||||||
|
const relativeY = pointer.clientY - containerRect.top - dragOffsetY;
|
||||||
|
|
||||||
|
const marginX = metrics.marginHorizontalPx;
|
||||||
|
const marginY = metrics.marginVerticalPx;
|
||||||
|
const cellWidth = metrics.cellWidthPx;
|
||||||
|
const cellHeight = metrics.cellHeightPx;
|
||||||
|
|
||||||
|
const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value));
|
||||||
|
|
||||||
|
const adjustedX = clamp(relativeX - marginX, 0, containerRect.width - marginX);
|
||||||
|
const adjustedY = clamp(relativeY - marginY, 0, Number.POSITIVE_INFINITY);
|
||||||
|
|
||||||
|
const cellPlusMarginX = cellWidth + marginX;
|
||||||
|
const cellPlusMarginY = cellHeight + marginY;
|
||||||
|
|
||||||
|
let gridX = Math.round(adjustedX / cellPlusMarginX);
|
||||||
|
if (rtl) {
|
||||||
|
gridX = columns - widget.w - gridX;
|
||||||
|
}
|
||||||
|
gridX = clamp(gridX, 0, columns - widget.w);
|
||||||
|
|
||||||
|
const gridY = clamp(Math.round(adjustedY / cellPlusMarginY), 0, Number.MAX_SAFE_INTEGER);
|
||||||
|
|
||||||
|
return { x: gridX, y: gridY };
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface ResizeComputationArgs {
|
||||||
|
pointer: PointerPosition;
|
||||||
|
containerRect: DOMRect;
|
||||||
|
metrics: GridCellMetrics;
|
||||||
|
startWidth: number;
|
||||||
|
startHeight: number;
|
||||||
|
startPointer: PointerPosition;
|
||||||
|
handler: 'e' | 's' | 'se';
|
||||||
|
widget: DashboardWidget;
|
||||||
|
columns: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const computeResizeDimensions = ({
|
||||||
|
pointer,
|
||||||
|
containerRect,
|
||||||
|
metrics,
|
||||||
|
startWidth,
|
||||||
|
startHeight,
|
||||||
|
startPointer,
|
||||||
|
handler,
|
||||||
|
widget,
|
||||||
|
columns,
|
||||||
|
}: ResizeComputationArgs): { width: number; height: number } => {
|
||||||
|
const deltaX = pointer.clientX - startPointer.clientX;
|
||||||
|
const deltaY = pointer.clientY - startPointer.clientY;
|
||||||
|
|
||||||
|
let width = startWidth;
|
||||||
|
let height = startHeight;
|
||||||
|
|
||||||
|
const cellPlusMarginX = metrics.cellWidthPx + metrics.marginHorizontalPx;
|
||||||
|
const cellPlusMarginY = metrics.cellHeightPx + metrics.marginVerticalPx;
|
||||||
|
|
||||||
|
if (handler.includes('e')) {
|
||||||
|
const deltaCols = Math.round(deltaX / cellPlusMarginX);
|
||||||
|
width = startWidth + deltaCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handler.includes('s')) {
|
||||||
|
const deltaRows = Math.round(deltaY / cellPlusMarginY);
|
||||||
|
height = startHeight + deltaRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clampedWidth = Math.max(widget.minW || 1, Math.min(width, widget.maxW || columns - widget.x));
|
||||||
|
const clampedHeight = Math.max(widget.minH || 1, Math.min(height, widget.maxH || Number.MAX_SAFE_INTEGER));
|
||||||
|
|
||||||
|
return {
|
||||||
|
width: clampedWidth,
|
||||||
|
height: clampedHeight,
|
||||||
|
};
|
||||||
|
};
|
246
ts_web/elements/dees-dashboardgrid/layout.ts
Normal file
246
ts_web/elements/dees-dashboardgrid/layout.ts
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
import type {
|
||||||
|
DashboardResolvedMargins,
|
||||||
|
DashboardMargin,
|
||||||
|
DashboardWidget,
|
||||||
|
DashboardLayoutItem,
|
||||||
|
GridCellMetrics,
|
||||||
|
LayoutDirection,
|
||||||
|
} from './types.js';
|
||||||
|
|
||||||
|
export const DEFAULT_MARGIN = 10;
|
||||||
|
|
||||||
|
export const resolveMargins = (margin: DashboardMargin): DashboardResolvedMargins => {
|
||||||
|
if (typeof margin === 'number') {
|
||||||
|
return {
|
||||||
|
horizontal: margin,
|
||||||
|
vertical: margin,
|
||||||
|
top: margin,
|
||||||
|
right: margin,
|
||||||
|
bottom: margin,
|
||||||
|
left: margin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolved = {
|
||||||
|
top: margin.top ?? DEFAULT_MARGIN,
|
||||||
|
right: margin.right ?? DEFAULT_MARGIN,
|
||||||
|
bottom: margin.bottom ?? DEFAULT_MARGIN,
|
||||||
|
left: margin.left ?? DEFAULT_MARGIN,
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...resolved,
|
||||||
|
horizontal: (resolved.left + resolved.right) / 2,
|
||||||
|
vertical: (resolved.top + resolved.bottom) / 2,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const calculateCellMetrics = (
|
||||||
|
containerWidth: number,
|
||||||
|
columns: number,
|
||||||
|
margins: DashboardResolvedMargins,
|
||||||
|
cellHeight: number,
|
||||||
|
cellHeightUnit: string,
|
||||||
|
): GridCellMetrics => {
|
||||||
|
const totalMarginWidth = margins.horizontal * (columns + 1);
|
||||||
|
const availableWidth = Math.max(containerWidth - totalMarginWidth, 0);
|
||||||
|
const cellWidthPx = columns > 0 ? availableWidth / columns : 0;
|
||||||
|
const cellHeightPx = cellHeightUnit === 'auto' ? cellWidthPx : cellHeight;
|
||||||
|
|
||||||
|
return {
|
||||||
|
containerWidth,
|
||||||
|
cellWidthPx,
|
||||||
|
marginHorizontalPx: margins.horizontal,
|
||||||
|
cellHeightPx,
|
||||||
|
marginVerticalPx: margins.vertical,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const calculateGridHeight = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
margins: DashboardResolvedMargins,
|
||||||
|
cellHeight: number,
|
||||||
|
): number => {
|
||||||
|
if (widgets.length === 0) return 0;
|
||||||
|
const maxY = Math.max(...widgets.map(widget => widget.y + widget.h), 0);
|
||||||
|
return maxY * cellHeight + (maxY + 1) * margins.vertical;
|
||||||
|
};
|
||||||
|
|
||||||
|
const overlaps = (
|
||||||
|
widget: DashboardWidget,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
w: number,
|
||||||
|
h: number,
|
||||||
|
) => x < widget.x + widget.w && x + w > widget.x && y < widget.y + widget.h && y + h > widget.y;
|
||||||
|
|
||||||
|
export const collectCollisions = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
target: DashboardWidget,
|
||||||
|
nextX: number,
|
||||||
|
nextY: number,
|
||||||
|
nextW: number = target.w,
|
||||||
|
nextH: number = target.h,
|
||||||
|
): DashboardWidget[] => {
|
||||||
|
return widgets.filter(widget => {
|
||||||
|
if (widget.id === target.id) return false;
|
||||||
|
return overlaps(widget, nextX, nextY, nextW, nextH);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkCollision = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
target: DashboardWidget,
|
||||||
|
nextX: number,
|
||||||
|
nextY: number,
|
||||||
|
): boolean => collectCollisions(widgets, target, nextX, nextY).length > 0;
|
||||||
|
|
||||||
|
export const cloneWidget = (widget: DashboardWidget): DashboardWidget => ({ ...widget });
|
||||||
|
|
||||||
|
export const cloneWidgets = (widgets: DashboardWidget[]): DashboardWidget[] => widgets.map(cloneWidget);
|
||||||
|
|
||||||
|
export const findAvailablePosition = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
columns: number,
|
||||||
|
): { x: number; y: number } => {
|
||||||
|
for (let y = 0; y < 200; y++) {
|
||||||
|
for (let x = 0; x <= columns - width; x++) {
|
||||||
|
const isFree = !widgets.some(widget => overlaps(widget, x, y, width, height));
|
||||||
|
if (isFree) {
|
||||||
|
return { x, y };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxY = widgets.reduce((acc, widget) => Math.max(acc, widget.y + widget.h), 0);
|
||||||
|
return { x: 0, y: maxY };
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface PlacementResult {
|
||||||
|
widgets: DashboardWidget[];
|
||||||
|
movedWidgets: string[];
|
||||||
|
swappedWith?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const resolveWidgetPlacement = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
widgetId: string,
|
||||||
|
next: { x: number; y: number; w?: number; h?: number },
|
||||||
|
columns: number,
|
||||||
|
previousPosition?: DashboardLayoutItem,
|
||||||
|
): PlacementResult | null => {
|
||||||
|
const sourceWidgets = cloneWidgets(widgets);
|
||||||
|
const moving = sourceWidgets.find(widget => widget.id === widgetId);
|
||||||
|
const original = widgets.find(widget => widget.id === widgetId);
|
||||||
|
if (!moving || !original) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const target = {
|
||||||
|
x: next.x,
|
||||||
|
y: next.y,
|
||||||
|
w: next.w ?? moving.w,
|
||||||
|
h: next.h ?? moving.h,
|
||||||
|
};
|
||||||
|
|
||||||
|
moving.x = target.x;
|
||||||
|
moving.y = target.y;
|
||||||
|
moving.w = target.w;
|
||||||
|
moving.h = target.h;
|
||||||
|
|
||||||
|
const collisions = collectCollisions(sourceWidgets, moving, target.x, target.y, target.w, target.h);
|
||||||
|
|
||||||
|
if (collisions.length === 0) {
|
||||||
|
return { widgets: sourceWidgets, movedWidgets: [moving.id] };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collisions.length === 1) {
|
||||||
|
const other = collisions[0];
|
||||||
|
if (!other.locked && !other.noMove && other.w === moving.w && other.h === moving.h) {
|
||||||
|
const otherClone = sourceWidgets.find(widget => widget.id === other.id);
|
||||||
|
if (otherClone) {
|
||||||
|
// Use the original position of the moving widget for a clean swap
|
||||||
|
// This prevents the "snapping together" issue where both widgets end up at the same position
|
||||||
|
const swapTarget = original;
|
||||||
|
const previousOtherPosition = { x: otherClone.x, y: otherClone.y };
|
||||||
|
otherClone.x = swapTarget.x;
|
||||||
|
otherClone.y = swapTarget.y;
|
||||||
|
|
||||||
|
const swapValid =
|
||||||
|
collectCollisions(sourceWidgets, moving, moving.x, moving.y, moving.w, moving.h).length === 0 &&
|
||||||
|
collectCollisions(sourceWidgets, otherClone, otherClone.x, otherClone.y, otherClone.w, otherClone.h).length === 0;
|
||||||
|
|
||||||
|
if (swapValid) {
|
||||||
|
return { widgets: sourceWidgets, movedWidgets: [moving.id, otherClone.id], swappedWith: otherClone.id };
|
||||||
|
}
|
||||||
|
|
||||||
|
otherClone.x = previousOtherPosition.x;
|
||||||
|
otherClone.y = previousOtherPosition.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt displacement cascade
|
||||||
|
const movedIds = new Set<string>([moving.id]);
|
||||||
|
for (const offending of collisions) {
|
||||||
|
if (offending.locked || offending.noMove) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const clone = sourceWidgets.find(widget => widget.id === offending.id);
|
||||||
|
if (!clone) continue;
|
||||||
|
const remaining = sourceWidgets.filter(widget => widget.id !== offending.id);
|
||||||
|
const position = findAvailablePosition(remaining, clone.w, clone.h, columns);
|
||||||
|
clone.x = position.x;
|
||||||
|
clone.y = position.y;
|
||||||
|
movedIds.add(clone.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// verify no overlaps remain
|
||||||
|
const verify = collectCollisions(sourceWidgets, moving, moving.x, moving.y, moving.w, moving.h);
|
||||||
|
if (verify.length > 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { widgets: sourceWidgets, movedWidgets: Array.from(movedIds) };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const compactLayout = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
direction: LayoutDirection = 'vertical',
|
||||||
|
) => {
|
||||||
|
const sorted = [...widgets].sort((a, b) => {
|
||||||
|
if (direction === 'vertical') {
|
||||||
|
if (a.y !== b.y) return a.y - b.y;
|
||||||
|
return a.x - b.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.x !== b.x) return a.x - b.x;
|
||||||
|
return a.y - b.y;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const widget of sorted) {
|
||||||
|
if (widget.locked || widget.noMove) continue;
|
||||||
|
|
||||||
|
if (direction === 'vertical') {
|
||||||
|
while (widget.y > 0 && !checkCollision(widgets, widget, widget.x, widget.y - 1)) {
|
||||||
|
widget.y -= 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (widget.x > 0 && !checkCollision(widgets, widget, widget.x - 1, widget.y)) {
|
||||||
|
widget.x -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const applyLayout = (
|
||||||
|
widgets: DashboardWidget[],
|
||||||
|
layout: DashboardLayoutItem[],
|
||||||
|
): DashboardWidget[] => {
|
||||||
|
return widgets.map(widget => {
|
||||||
|
const layoutItem = layout.find(item => item.id === widget.id);
|
||||||
|
return layoutItem ? { ...widget, ...layoutItem } : widget;
|
||||||
|
});
|
||||||
|
};
|
249
ts_web/elements/dees-dashboardgrid/styles.ts
Normal file
249
ts_web/elements/dees-dashboardgrid/styles.ts
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
import { css, cssManager } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
export const dashboardGridStyles = [
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 400px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget {
|
||||||
|
position: absolute;
|
||||||
|
will-change: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([enableanimation]) .grid-widget {
|
||||||
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget.dragging {
|
||||||
|
z-index: 1000;
|
||||||
|
transition: none !important;
|
||||||
|
opacity: 0.8;
|
||||||
|
cursor: grabbing;
|
||||||
|
pointer-events: none;
|
||||||
|
will-change: transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget.placeholder {
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget.placeholder .widget-content {
|
||||||
|
background: ${cssManager.bdTheme('rgba(59, 130, 246, 0.1)', 'rgba(59, 130, 246, 0.1)')};
|
||||||
|
border: 2px dashed ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget.resizing {
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-content {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
||||||
|
border: 1px solid ${cssManager.bdTheme('#e5e7eb', '#27272a')};
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: ${cssManager.bdTheme(
|
||||||
|
'0 1px 3px rgba(0, 0, 0, 0.1)',
|
||||||
|
'0 1px 3px rgba(0, 0, 0, 0.3)'
|
||||||
|
)};
|
||||||
|
transition: box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget:hover .widget-content {
|
||||||
|
box-shadow: ${cssManager.bdTheme(
|
||||||
|
'0 4px 12px rgba(0, 0, 0, 0.15)',
|
||||||
|
'0 4px 12px rgba(0, 0, 0, 0.4)'
|
||||||
|
)};
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget.dragging .widget-content {
|
||||||
|
box-shadow: ${cssManager.bdTheme(
|
||||||
|
'0 16px 48px rgba(0, 0, 0, 0.25)',
|
||||||
|
'0 16px 48px rgba(0, 0, 0, 0.6)'
|
||||||
|
)};
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header {
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid ${cssManager.bdTheme('#e5e7eb', '#27272a')};
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: ${cssManager.bdTheme('#09090b', '#fafafa')};
|
||||||
|
background: ${cssManager.bdTheme('#f9fafb', '#0a0a0a')};
|
||||||
|
cursor: grab;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header:hover {
|
||||||
|
background: ${cssManager.bdTheme('#f4f4f5', '#18181b')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header:active {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header.locked {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header.locked:hover {
|
||||||
|
background: ${cssManager.bdTheme('#f9fafb', '#0a0a0a')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-header dees-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
color: ${cssManager.bdTheme('#71717a', '#71717a')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-body {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
overflow: auto;
|
||||||
|
color: ${cssManager.bdTheme('#09090b', '#fafafa')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-body.has-header {
|
||||||
|
top: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle {
|
||||||
|
position: absolute;
|
||||||
|
background: transparent;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle:hover {
|
||||||
|
background: ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-e {
|
||||||
|
cursor: ew-resize;
|
||||||
|
width: 12px;
|
||||||
|
right: -6px;
|
||||||
|
top: 10%;
|
||||||
|
height: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-s {
|
||||||
|
cursor: ns-resize;
|
||||||
|
height: 12px;
|
||||||
|
width: 80%;
|
||||||
|
bottom: -6px;
|
||||||
|
left: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-se {
|
||||||
|
cursor: se-resize;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
right: -2px;
|
||||||
|
bottom: -2px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-se::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
right: 4px;
|
||||||
|
bottom: 4px;
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-right: 2px solid ${cssManager.bdTheme('#71717a', '#71717a')};
|
||||||
|
border-bottom: 2px solid ${cssManager.bdTheme('#71717a', '#71717a')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-widget:hover .resize-handle-se {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-se:hover {
|
||||||
|
opacity: 1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize-handle-se:hover::after {
|
||||||
|
border-color: ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-placeholder {
|
||||||
|
position: absolute;
|
||||||
|
background: ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||||
|
opacity: 0.1;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 2px dashed ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 400px;
|
||||||
|
color: ${cssManager.bdTheme('#71717a', '#71717a')};
|
||||||
|
text-align: center;
|
||||||
|
padding: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state dees-icon {
|
||||||
|
font-size: 48px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-lines {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-line-vertical {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 1px;
|
||||||
|
background: ${cssManager.bdTheme('#e5e7eb', '#27272a')};
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-line-horizontal {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 1px;
|
||||||
|
background: ${cssManager.bdTheme('#e5e7eb', '#27272a')};
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
53
ts_web/elements/dees-dashboardgrid/types.ts
Normal file
53
ts_web/elements/dees-dashboardgrid/types.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import type { TemplateResult } from '@design.estate/dees-element';
|
||||||
|
|
||||||
|
export type CellHeightUnit = 'px' | 'em' | 'rem' | 'auto';
|
||||||
|
|
||||||
|
export interface DashboardMarginObject {
|
||||||
|
top?: number;
|
||||||
|
right?: number;
|
||||||
|
bottom?: number;
|
||||||
|
left?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DashboardMargin = number | DashboardMarginObject;
|
||||||
|
|
||||||
|
export interface DashboardResolvedMargins {
|
||||||
|
horizontal: number;
|
||||||
|
vertical: number;
|
||||||
|
top: number;
|
||||||
|
right: number;
|
||||||
|
bottom: number;
|
||||||
|
left: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DashboardLayoutItem {
|
||||||
|
id: string;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
w: number;
|
||||||
|
h: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DashboardWidget extends DashboardLayoutItem {
|
||||||
|
minW?: number;
|
||||||
|
minH?: number;
|
||||||
|
maxW?: number;
|
||||||
|
maxH?: number;
|
||||||
|
content: TemplateResult | string;
|
||||||
|
title?: string;
|
||||||
|
icon?: string;
|
||||||
|
noMove?: boolean;
|
||||||
|
noResize?: boolean;
|
||||||
|
locked?: boolean;
|
||||||
|
autoPosition?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LayoutDirection = 'vertical' | 'horizontal';
|
||||||
|
|
||||||
|
export interface GridCellMetrics {
|
||||||
|
containerWidth: number;
|
||||||
|
cellWidthPx: number;
|
||||||
|
marginHorizontalPx: number;
|
||||||
|
cellHeightPx: number;
|
||||||
|
marginVerticalPx: number;
|
||||||
|
}
|
@@ -175,21 +175,21 @@ export class DeesDataviewStatusobject extends DeesElement {
|
|||||||
DeesContextmenu.openContextMenuWithOptions(event, [
|
DeesContextmenu.openContextMenuWithOptions(event, [
|
||||||
{
|
{
|
||||||
name: 'Copy Value',
|
name: 'Copy Value',
|
||||||
iconName: 'lucideCopy',
|
iconName: 'lucide:copy',
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await this.copyToClipboard(detailArg.value, 'Value');
|
await this.copyToClipboard(detailArg.value, 'Value');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Copy Key',
|
name: 'Copy Key',
|
||||||
iconName: 'lucideKey',
|
iconName: 'lucide:key',
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await this.copyToClipboard(detailArg.name, 'Key');
|
await this.copyToClipboard(detailArg.name, 'Key');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Copy Key:Value',
|
name: 'Copy Key:Value',
|
||||||
iconName: 'lucideCopyPlus',
|
iconName: 'lucide:copy-plus',
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await this.copyToClipboard(`${detailArg.name}: ${detailArg.value}`, 'Key:Value');
|
await this.copyToClipboard(`${detailArg.name}: ${detailArg.value}`, 'Key:Value');
|
||||||
},
|
},
|
||||||
|
@@ -8,6 +8,7 @@ import {
|
|||||||
cssManager,
|
cssManager,
|
||||||
} from '@design.estate/dees-element';
|
} from '@design.estate/dees-element';
|
||||||
import * as domtools from '@design.estate/dees-domtools';
|
import * as domtools from '@design.estate/dees-domtools';
|
||||||
|
import { MONACO_VERSION } from './version.js';
|
||||||
|
|
||||||
import type * as monaco from 'monaco-editor';
|
import type * as monaco from 'monaco-editor';
|
||||||
|
|
||||||
@@ -80,10 +81,11 @@ export class DeesEditor extends DeesElement {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
super.firstUpdated(_changedProperties);
|
super.firstUpdated(_changedProperties);
|
||||||
const container = this.shadowRoot.getElementById('container');
|
const container = this.shadowRoot.getElementById('container');
|
||||||
|
const monacoCdnBase = `https://cdn.jsdelivr.net/npm/monaco-editor@${MONACO_VERSION}`;
|
||||||
|
|
||||||
if (!DeesEditor.monacoDeferred) {
|
if (!DeesEditor.monacoDeferred) {
|
||||||
DeesEditor.monacoDeferred = domtools.plugins.smartpromise.defer();
|
DeesEditor.monacoDeferred = domtools.plugins.smartpromise.defer();
|
||||||
const scriptUrl = `https://cdn.jsdelivr.net/npm/monaco-editor/min/vs/loader.js`;
|
const scriptUrl = `${monacoCdnBase}/min/vs/loader.js`;
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.src = scriptUrl;
|
script.src = scriptUrl;
|
||||||
script.onload = () => {
|
script.onload = () => {
|
||||||
@@ -94,7 +96,7 @@ export class DeesEditor extends DeesElement {
|
|||||||
await DeesEditor.monacoDeferred.promise;
|
await DeesEditor.monacoDeferred.promise;
|
||||||
|
|
||||||
(window as any).require.config({
|
(window as any).require.config({
|
||||||
paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor/min/vs' },
|
paths: { vs: `${monacoCdnBase}/min/vs` },
|
||||||
});
|
});
|
||||||
(window as any).require(['vs/editor/editor.main'], async () => {
|
(window as any).require(['vs/editor/editor.main'], async () => {
|
||||||
const editor = ((window as any).monaco.editor as typeof monaco.editor).create(container, {
|
const editor = ((window as any).monaco.editor as typeof monaco.editor).create(container, {
|
||||||
@@ -109,7 +111,7 @@ export class DeesEditor extends DeesElement {
|
|||||||
this.editorDeferred.resolve(editor);
|
this.editorDeferred.resolve(editor);
|
||||||
});
|
});
|
||||||
const css = await (
|
const css = await (
|
||||||
await fetch('https://cdn.jsdelivr.net/npm/monaco-editor/min/vs/editor/editor.main.css')
|
await fetch(`${monacoCdnBase}/min/vs/editor/editor.main.css`)
|
||||||
).text();
|
).text();
|
||||||
const styleElement = document.createElement('style');
|
const styleElement = document.createElement('style');
|
||||||
styleElement.textContent = css;
|
styleElement.textContent = css;
|
2
ts_web/elements/dees-editor/index.ts
Normal file
2
ts_web/elements/dees-editor/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './dees-editor.js';
|
||||||
|
export * from './version.js';
|
2
ts_web/elements/dees-editor/version.ts
Normal file
2
ts_web/elements/dees-editor/version.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Auto-generated by scripts/update-monaco-version.cjs
|
||||||
|
export const MONACO_VERSION = '0.52.2';
|
@@ -57,9 +57,10 @@ export class DeesFormSubmit extends DeesElement {
|
|||||||
if (this.disabled) {
|
if (this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parentElement: DeesForm = this.parentElement as DeesForm;
|
// Walk up the DOM tree to find the nearest dees-form element
|
||||||
if (parentElement && parentElement.gatherAndDispatch) {
|
const parentFormElement = this.closest('dees-form') as DeesForm;
|
||||||
parentElement.gatherAndDispatch();
|
if (parentFormElement && parentFormElement.gatherAndDispatch) {
|
||||||
|
parentFormElement.gatherAndDispatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,40 +3,91 @@ import type { DeesForm } from './dees-form.js';
|
|||||||
import '@design.estate/dees-wcctools/demotools';
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
|
|
||||||
export const demoFunc = () => html`
|
export const demoFunc = () => html`
|
||||||
<dees-demowrapper>
|
<style>
|
||||||
<style>
|
${css`
|
||||||
${css`
|
.demo-container {
|
||||||
.demo-container {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
flex-direction: column;
|
gap: 24px;
|
||||||
gap: 24px;
|
padding: 24px;
|
||||||
padding: 24px;
|
max-width: 1200px;
|
||||||
max-width: 1200px;
|
margin: 0 auto;
|
||||||
margin: 0 auto;
|
}
|
||||||
}
|
|
||||||
|
dees-panel {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dees-panel:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-output {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 12px;
|
||||||
|
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: monospace;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-message {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-message.success {
|
||||||
|
background: ${cssManager.bdTheme('hsl(142.1 70.6% 45.3% / 0.1)', 'hsl(142.1 70.6% 45.3% / 0.2)')};
|
||||||
|
color: ${cssManager.bdTheme('hsl(142.1 70.6% 35.3%)', 'hsl(142.1 70.6% 65.3%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-message.error {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 72.2% 50.6% / 0.1)', 'hsl(0 72.2% 50.6% / 0.2)')};
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 72.2% 40.6%)', 'hsl(0 72.2% 60.6%)')};
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="demo-container">
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
const form = elementArg.querySelector('dees-form') as DeesForm;
|
||||||
|
const outputDiv = elementArg.querySelector('.form-output');
|
||||||
|
|
||||||
|
if (form && outputDiv) {
|
||||||
|
form.addEventListener('formData', async (eventArg: CustomEvent) => {
|
||||||
|
const data = eventArg.detail.data;
|
||||||
|
console.log('Form submitted with data:', data);
|
||||||
|
|
||||||
|
// Show processing state
|
||||||
|
form.setStatus('pending', 'Processing your registration...');
|
||||||
|
outputDiv.innerHTML = `<strong>Submitted Data:</strong>\n${JSON.stringify(data, null, 2)}`;
|
||||||
|
|
||||||
|
// Simulate API call
|
||||||
|
await domtools.plugins.smartdelay.delayFor(2000);
|
||||||
|
|
||||||
|
// Show success
|
||||||
|
form.setStatus('success', 'Registration completed successfully!');
|
||||||
|
|
||||||
|
// Reset form after delay
|
||||||
|
await domtools.plugins.smartdelay.delayFor(2000);
|
||||||
|
form.reset();
|
||||||
|
outputDiv.innerHTML = '<em>Form has been reset</em>';
|
||||||
|
});
|
||||||
|
|
||||||
dees-panel {
|
// Track individual field changes
|
||||||
margin-bottom: 24px;
|
const inputs = form.querySelectorAll('dees-input-text, dees-input-dropdown, dees-input-checkbox');
|
||||||
}
|
inputs.forEach((input) => {
|
||||||
|
input.addEventListener('changeSubject', () => {
|
||||||
dees-panel:last-child {
|
console.log('Field changed:', input.getAttribute('key'));
|
||||||
margin-bottom: 0;
|
});
|
||||||
}
|
});
|
||||||
`}
|
}
|
||||||
</style>
|
}}>
|
||||||
|
|
||||||
<div class="demo-container">
|
|
||||||
<dees-panel .heading="Complete Form Example" .description="A comprehensive form with various input types, validation, and form submission handling">
|
<dees-panel .heading="Complete Form Example" .description="A comprehensive form with various input types, validation, and form submission handling">
|
||||||
<dees-form
|
<dees-form>
|
||||||
@formData=${async (eventArg) => {
|
|
||||||
const form: DeesForm = eventArg.currentTarget;
|
|
||||||
form.setStatus('pending', 'Processing...');
|
|
||||||
await domtools.plugins.smartdelay.delayFor(2000);
|
|
||||||
form.setStatus('success', 'Form submitted successfully!');
|
|
||||||
await domtools.plugins.smartdelay.delayFor(2000);
|
|
||||||
form.reset();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.required=${true}
|
.required=${true}
|
||||||
key="firstName"
|
key="firstName"
|
||||||
@@ -92,13 +143,47 @@ export const demoFunc = () => html`
|
|||||||
|
|
||||||
<dees-form-submit>Create Account</dees-form-submit>
|
<dees-form-submit>Create Account</dees-form-submit>
|
||||||
</dees-form>
|
</dees-form>
|
||||||
|
|
||||||
|
<div class="form-output">
|
||||||
|
<em>Submit the form to see the collected data...</em>
|
||||||
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
const form = elementArg.querySelector('dees-form') as DeesForm;
|
||||||
|
|
||||||
|
if (form) {
|
||||||
|
// Track horizontal layout behavior
|
||||||
|
console.log('Horizontal form layout active');
|
||||||
|
|
||||||
|
// Monitor filter changes
|
||||||
|
form.addEventListener('formData', (event: CustomEvent) => {
|
||||||
|
const filters = event.detail.data;
|
||||||
|
console.log('Filter applied:', filters);
|
||||||
|
|
||||||
|
// Simulate search
|
||||||
|
const resultsCount = Math.floor(Math.random() * 100) + 1;
|
||||||
|
console.log(`Found ${resultsCount} results with filters:`, filters);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup real-time filter updates
|
||||||
|
const inputs = form.querySelectorAll('[key]');
|
||||||
|
inputs.forEach((input) => {
|
||||||
|
input.addEventListener('changeSubject', async () => {
|
||||||
|
// Get current form data
|
||||||
|
const formData = await form.collectFormData();
|
||||||
|
console.log('Live filter update:', formData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .heading="Horizontal Form Layout" .description="Compact form with inputs arranged horizontally - perfect for filters and quick forms">
|
<dees-panel .heading="Horizontal Form Layout" .description="Compact form with inputs arranged horizontally - perfect for filters and quick forms">
|
||||||
<dees-form horizontal-layout>
|
<dees-form horizontal-layout>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
key="search"
|
key="search"
|
||||||
label="Search"
|
label="Search"
|
||||||
|
placeholder="Enter keywords..."
|
||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
|
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
@@ -132,16 +217,55 @@ export const demoFunc = () => html`
|
|||||||
></dees-input-checkbox>
|
></dees-input-checkbox>
|
||||||
</dees-form>
|
</dees-form>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
const form = elementArg.querySelector('dees-form') as DeesForm;
|
||||||
|
const statusDiv = elementArg.querySelector('#status-display');
|
||||||
|
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener('formData', async (eventArg: CustomEvent) => {
|
||||||
|
const data = eventArg.detail.data;
|
||||||
|
console.log('Advanced form data:', data);
|
||||||
|
|
||||||
|
// Show validation in progress
|
||||||
|
form.setStatus('pending', 'Validating your information...');
|
||||||
|
|
||||||
|
// Simulate validation
|
||||||
|
await domtools.plugins.smartdelay.delayFor(1500);
|
||||||
|
|
||||||
|
// Check IBAN validity (simple check)
|
||||||
|
if (data.iban && data.iban.length > 15) {
|
||||||
|
form.setStatus('success', 'Application submitted successfully!');
|
||||||
|
|
||||||
|
if (statusDiv) {
|
||||||
|
statusDiv.className = 'status-message success';
|
||||||
|
statusDiv.textContent = '✓ Your application has been submitted. We will contact you soon.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
form.setStatus('error', 'Please check your IBAN');
|
||||||
|
|
||||||
|
if (statusDiv) {
|
||||||
|
statusDiv.className = 'status-message error';
|
||||||
|
statusDiv.textContent = '✗ Invalid IBAN format. Please check and try again.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Form data logged:', data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Monitor file uploads
|
||||||
|
const fileUpload = form.querySelector('dees-input-fileupload');
|
||||||
|
if (fileUpload) {
|
||||||
|
fileUpload.addEventListener('change', (event: any) => {
|
||||||
|
const files = event.detail?.files || [];
|
||||||
|
console.log(`${files.length} file(s) selected for upload`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .heading="Advanced Form Features" .description="Form with specialized input types and complex validation">
|
<dees-panel .heading="Advanced Form Features" .description="Form with specialized input types and complex validation">
|
||||||
<dees-form
|
<dees-form>
|
||||||
@formData=${async (eventArg) => {
|
|
||||||
const form: DeesForm = eventArg.currentTarget;
|
|
||||||
const data = eventArg.detail.data;
|
|
||||||
console.log('Form data:', data);
|
|
||||||
form.setStatus('success', 'Data logged to console!');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<dees-input-iban
|
<dees-input-iban
|
||||||
key="iban"
|
key="iban"
|
||||||
label="IBAN"
|
label="IBAN"
|
||||||
@@ -181,7 +305,9 @@ export const demoFunc = () => html`
|
|||||||
|
|
||||||
<dees-form-submit>Submit Application</dees-form-submit>
|
<dees-form-submit>Submit Application</dees-form-submit>
|
||||||
</dees-form>
|
</dees-form>
|
||||||
|
|
||||||
|
<div id="status-display"></div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
</div>
|
</dees-demowrapper>
|
||||||
</dees-demowrapper>
|
</div>
|
||||||
`;
|
`;
|
@@ -9,6 +9,7 @@ import {
|
|||||||
import * as domtools from '@design.estate/dees-domtools';
|
import * as domtools from '@design.estate/dees-domtools';
|
||||||
|
|
||||||
import { DeesInputCheckbox } from './dees-input-checkbox.js';
|
import { DeesInputCheckbox } from './dees-input-checkbox.js';
|
||||||
|
import { DeesInputDatepicker } from './dees-input-datepicker.js';
|
||||||
import { DeesInputText } from './dees-input-text.js';
|
import { DeesInputText } from './dees-input-text.js';
|
||||||
import { DeesInputQuantitySelector } from './dees-input-quantityselector.js';
|
import { DeesInputQuantitySelector } from './dees-input-quantityselector.js';
|
||||||
import { DeesInputRadiogroup } from './dees-input-radiogroup.js';
|
import { DeesInputRadiogroup } from './dees-input-radiogroup.js';
|
||||||
@@ -19,12 +20,13 @@ import { DeesInputMultitoggle } from './dees-input-multitoggle.js';
|
|||||||
import { DeesInputPhone } from './dees-input-phone.js';
|
import { DeesInputPhone } from './dees-input-phone.js';
|
||||||
import { DeesInputTypelist } from './dees-input-typelist.js';
|
import { DeesInputTypelist } from './dees-input-typelist.js';
|
||||||
import { DeesFormSubmit } from './dees-form-submit.js';
|
import { DeesFormSubmit } from './dees-form-submit.js';
|
||||||
import { DeesTable } from './dees-table.js';
|
import { DeesTable } from './dees-table/index.js';
|
||||||
import { demoFunc } from './dees-form.demo.js';
|
import { demoFunc } from './dees-form.demo.js';
|
||||||
|
|
||||||
// Unified set for form input types
|
// Unified set for form input types
|
||||||
const FORM_INPUT_TYPES = [
|
const FORM_INPUT_TYPES = [
|
||||||
DeesInputCheckbox,
|
DeesInputCheckbox,
|
||||||
|
DeesInputDatepicker,
|
||||||
DeesInputDropdown,
|
DeesInputDropdown,
|
||||||
DeesInputFileupload,
|
DeesInputFileupload,
|
||||||
DeesInputIban,
|
DeesInputIban,
|
||||||
@@ -39,6 +41,7 @@ const FORM_INPUT_TYPES = [
|
|||||||
|
|
||||||
export type TFormInputElement =
|
export type TFormInputElement =
|
||||||
| DeesInputCheckbox
|
| DeesInputCheckbox
|
||||||
|
| DeesInputDatepicker
|
||||||
| DeesInputDropdown
|
| DeesInputDropdown
|
||||||
| DeesInputFileupload
|
| DeesInputFileupload
|
||||||
| DeesInputIban
|
| DeesInputIban
|
||||||
|
@@ -40,6 +40,26 @@ export const demoFunc = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define the functions in TS scope instead of script tags
|
// Define the functions in TS scope instead of script tags
|
||||||
|
const copyAllIconNames = () => {
|
||||||
|
// Generate complete list of all icon names with prefixes
|
||||||
|
const faIconsList = faIcons.map(name => `fa:${name}`);
|
||||||
|
const lucideIconsListPrefixed = lucideIconsList.map(name => `lucide:${name}`);
|
||||||
|
const allIcons = [...faIconsList, ...lucideIconsListPrefixed];
|
||||||
|
const textToCopy = allIcons.join('\n');
|
||||||
|
|
||||||
|
navigator.clipboard.writeText(textToCopy).then(() => {
|
||||||
|
// Show feedback
|
||||||
|
const currentEvent = window.event as MouseEvent;
|
||||||
|
const button = currentEvent.currentTarget as HTMLElement;
|
||||||
|
const originalText = button.textContent;
|
||||||
|
button.textContent = `✓ Copied ${allIcons.length} icon names!`;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
button.textContent = originalText;
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const searchIcons = (event: InputEvent) => {
|
const searchIcons = (event: InputEvent) => {
|
||||||
const searchTerm = (event.target as HTMLInputElement).value.toLowerCase().trim();
|
const searchTerm = (event.target as HTMLInputElement).value.toLowerCase().trim();
|
||||||
// Get the demo container first, then search within it
|
// Get the demo container first, then search within it
|
||||||
@@ -111,6 +131,7 @@ export const demoFunc = () => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#iconSearch {
|
#iconSearch {
|
||||||
@@ -129,6 +150,27 @@ export const demoFunc = () => {
|
|||||||
border-color: #e4002b;
|
border-color: #e4002b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.copy-all-button {
|
||||||
|
padding: 12px 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #e4002b;
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-all-button:hover {
|
||||||
|
background: #c4001b;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-all-button:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
dees-icon {
|
dees-icon {
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
@@ -239,6 +281,7 @@ export const demoFunc = () => {
|
|||||||
<div class="demoContainer">
|
<div class="demoContainer">
|
||||||
<div class="search-container">
|
<div class="search-container">
|
||||||
<input type="text" id="iconSearch" placeholder="Search icons..." @input=${searchIcons}>
|
<input type="text" id="iconSearch" placeholder="Search icons..." @input=${searchIcons}>
|
||||||
|
<button class="copy-all-button" @click=${copyAllIconNames}>📋 Copy All Icon Names</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="api-note">
|
<div class="api-note">
|
||||||
@@ -258,7 +301,7 @@ export const demoFunc = () => {
|
|||||||
return html`
|
return html`
|
||||||
<div class="iconContainer fa-icon" data-name=${iconName.toLowerCase()} @click=${() => copyIconName(iconName, 'fa')}>
|
<div class="iconContainer fa-icon" data-name=${iconName.toLowerCase()} @click=${() => copyIconName(iconName, 'fa')}>
|
||||||
<dees-icon .icon=${prefixedName as IconWithPrefix} iconSize="24"></dees-icon>
|
<dees-icon .icon=${prefixedName as IconWithPrefix} iconSize="24"></dees-icon>
|
||||||
<div class="iconName">${iconName}</div>
|
<div class="iconName">fa:${iconName}</div>
|
||||||
<span class="copy-tooltip">Click to copy</span>
|
<span class="copy-tooltip">Click to copy</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -279,7 +322,7 @@ export const demoFunc = () => {
|
|||||||
return html`
|
return html`
|
||||||
<div class="iconContainer lucide-icon" data-name=${iconName.toLowerCase()} @click=${() => copyIconName(iconName, 'lucide')}>
|
<div class="iconContainer lucide-icon" data-name=${iconName.toLowerCase()} @click=${() => copyIconName(iconName, 'lucide')}>
|
||||||
<dees-icon .icon=${prefixedName as IconWithPrefix} iconSize="24"></dees-icon>
|
<dees-icon .icon=${prefixedName as IconWithPrefix} iconSize="24"></dees-icon>
|
||||||
<div class="iconName">${iconName}</div>
|
<div class="iconName">lucide:${iconName}</div>
|
||||||
<span class="copy-tooltip">Click to copy</span>
|
<span class="copy-tooltip">Click to copy</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@@ -28,6 +28,9 @@ export class DeesInputCheckbox extends DeesInputBase<DeesInputCheckbox> {
|
|||||||
})
|
})
|
||||||
public value: boolean = false;
|
public value: boolean = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public indeterminate: boolean = false;
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -166,7 +169,15 @@ export class DeesInputCheckbox extends DeesInputBase<DeesInputCheckbox> {
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
`
|
`
|
||||||
: html``}
|
: this.indeterminate
|
||||||
|
? html`
|
||||||
|
<span class="checkmark">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M5 12H19" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
`
|
||||||
|
: html``}
|
||||||
</div>
|
</div>
|
||||||
<div class="label-container">
|
<div class="label-container">
|
||||||
${this.label ? html`<div class="checkbox-label">${this.label}</div>` : ''}
|
${this.label ? html`<div class="checkbox-label">${this.label}</div>` : ''}
|
||||||
|
410
ts_web/elements/dees-input-datepicker.demo.ts
Normal file
410
ts_web/elements/dees-input-datepicker.demo.ts
Normal file
@@ -0,0 +1,410 @@
|
|||||||
|
import { html, css } from '@design.estate/dees-element';
|
||||||
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
|
import './dees-panel.js';
|
||||||
|
import './dees-input-datepicker.js';
|
||||||
|
import type { DeesInputDatepicker } from './dees-input-datepicker.js';
|
||||||
|
|
||||||
|
export const demoFunc = () => html`
|
||||||
|
<style>
|
||||||
|
${css`
|
||||||
|
.demo-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 24px;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
dees-panel {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dees-panel:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.demo-output {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 12px;
|
||||||
|
background: rgba(0, 105, 242, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="demo-container">
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate basic date picker functionality
|
||||||
|
const datePicker = elementArg.querySelector('dees-input-datepicker');
|
||||||
|
|
||||||
|
if (datePicker) {
|
||||||
|
datePicker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
console.log('Basic date selected:', (event.target as DeesInputDatepicker).value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Basic Date Picker'} .subtitle=${'Simple date selection without time'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Select Date"
|
||||||
|
description="Choose a date from the calendar"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate date and time picker
|
||||||
|
const dateTimePicker = elementArg.querySelector('dees-input-datepicker[label="Event Date & Time"]');
|
||||||
|
const appointmentPicker = elementArg.querySelector('dees-input-datepicker[label="Appointment"]');
|
||||||
|
|
||||||
|
if (dateTimePicker) {
|
||||||
|
dateTimePicker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const value = (event.target as DeesInputDatepicker).value;
|
||||||
|
console.log('24h format datetime:', value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appointmentPicker) {
|
||||||
|
appointmentPicker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const value = (event.target as DeesInputDatepicker).value;
|
||||||
|
console.log('12h format datetime:', value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Date and Time Selection'} .subtitle=${'Date pickers with time selection in different formats'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Event Date & Time"
|
||||||
|
description="Select both date and time (24-hour format)"
|
||||||
|
.enableTime=${true}
|
||||||
|
timeFormat="24h"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Appointment"
|
||||||
|
description="Date and time with AM/PM selector (15-minute increments)"
|
||||||
|
.enableTime=${true}
|
||||||
|
timeFormat="12h"
|
||||||
|
.minuteIncrement=${15}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate timezone functionality
|
||||||
|
const timezonePickers = elementArg.querySelectorAll('dees-input-datepicker');
|
||||||
|
|
||||||
|
timezonePickers.forEach((picker) => {
|
||||||
|
picker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const target = event.target as DeesInputDatepicker;
|
||||||
|
console.log(`${target.label} value:`, target.value);
|
||||||
|
const input = target.shadowRoot?.querySelector('.date-input') as HTMLInputElement;
|
||||||
|
if (input) {
|
||||||
|
console.log(`${target.label} formatted:`, input.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Timezone Support'} .subtitle=${'Date and time selection with timezone awareness'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Meeting Time (with Timezone)"
|
||||||
|
description="Select a date/time and timezone for the meeting"
|
||||||
|
.enableTime=${true}
|
||||||
|
.enableTimezone=${true}
|
||||||
|
timeFormat="24h"
|
||||||
|
timezone="America/New_York"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Global Event Schedule"
|
||||||
|
description="Schedule an event across different timezones"
|
||||||
|
.enableTime=${true}
|
||||||
|
.enableTimezone=${true}
|
||||||
|
timeFormat="12h"
|
||||||
|
timezone="Europe/London"
|
||||||
|
.minuteIncrement=${30}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate date constraints
|
||||||
|
const futureDatePicker = elementArg.querySelector('dees-input-datepicker');
|
||||||
|
|
||||||
|
if (futureDatePicker) {
|
||||||
|
// Show the min/max constraints in action
|
||||||
|
futureDatePicker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const value = (event.target as DeesInputDatepicker).value;
|
||||||
|
if (value) {
|
||||||
|
const selectedDate = new Date(value);
|
||||||
|
const today = new Date();
|
||||||
|
const daysDiff = Math.floor((selectedDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
|
console.log(`Selected date is ${daysDiff} days from today`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Date Range Constraints'} .subtitle=${'Limit selectable dates with min and max values'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Future Date Only"
|
||||||
|
description="Can only select dates from today to 90 days in the future"
|
||||||
|
.minDate=${new Date().toISOString()}
|
||||||
|
.maxDate=${new Date(Date.now() + 90 * 24 * 60 * 60 * 1000).toISOString()}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate different date formats
|
||||||
|
const formatters = {
|
||||||
|
'DD/MM/YYYY': 'European',
|
||||||
|
'MM/DD/YYYY': 'US',
|
||||||
|
'YYYY-MM-DD': 'ISO'
|
||||||
|
};
|
||||||
|
|
||||||
|
const datePickers = elementArg.querySelectorAll('dees-input-datepicker');
|
||||||
|
datePickers.forEach((picker) => {
|
||||||
|
picker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const target = event.target as DeesInputDatepicker;
|
||||||
|
// Log the formatted value that's displayed in the input
|
||||||
|
const input = target.shadowRoot?.querySelector('.date-input') as HTMLInputElement;
|
||||||
|
if (input) {
|
||||||
|
console.log(`${target.label} format:`, input.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Date Formats'} .subtitle=${'Different date display formats for various regions'}>
|
||||||
|
<div class="date-group">
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="European Format"
|
||||||
|
dateFormat="DD/MM/YYYY"
|
||||||
|
.value=${new Date().toISOString()}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="US Format"
|
||||||
|
dateFormat="MM/DD/YYYY"
|
||||||
|
.value=${new Date().toISOString()}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="ISO Format"
|
||||||
|
dateFormat="YYYY-MM-DD"
|
||||||
|
.value=${new Date().toISOString()}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate required field validation
|
||||||
|
const requiredPicker = elementArg.querySelector('dees-input-datepicker[required]');
|
||||||
|
|
||||||
|
if (requiredPicker) {
|
||||||
|
// Monitor blur events for validation
|
||||||
|
requiredPicker.addEventListener('blur', () => {
|
||||||
|
const picker = requiredPicker as DeesInputDatepicker;
|
||||||
|
const value = picker.getValue();
|
||||||
|
if (!value) {
|
||||||
|
console.log('Required date field is empty');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Form States'} .subtitle=${'Required and disabled states'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Birth Date"
|
||||||
|
description="This field is required"
|
||||||
|
.required=${true}
|
||||||
|
placeholder="Select your birth date"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Disabled Date"
|
||||||
|
description="This field cannot be edited"
|
||||||
|
.disabled=${true}
|
||||||
|
.value=${new Date().toISOString()}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate week start customization
|
||||||
|
const usPicker = elementArg.querySelector('dees-input-datepicker[label="US Calendar"]');
|
||||||
|
const euPicker = elementArg.querySelector('dees-input-datepicker[label="EU Calendar"]');
|
||||||
|
|
||||||
|
if (usPicker) {
|
||||||
|
console.log('US Calendar starts on Sunday (0)');
|
||||||
|
}
|
||||||
|
if (euPicker) {
|
||||||
|
console.log('EU Calendar starts on Monday (1)');
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Calendar Customization'} .subtitle=${'Different week start days for various regions'}>
|
||||||
|
<div class="date-group">
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="US Calendar"
|
||||||
|
description="Week starts on Sunday"
|
||||||
|
.weekStartsOn=${0}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="EU Calendar"
|
||||||
|
description="Week starts on Monday"
|
||||||
|
.weekStartsOn=${1}
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Generate weekend dates for the current month
|
||||||
|
const generateWeekends = () => {
|
||||||
|
const weekends = [];
|
||||||
|
const now = new Date();
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = now.getMonth();
|
||||||
|
|
||||||
|
// Get all weekends for current month
|
||||||
|
const date = new Date(year, month, 1);
|
||||||
|
while (date.getMonth() === month) {
|
||||||
|
if (date.getDay() === 0 || date.getDay() === 6) {
|
||||||
|
weekends.push(new Date(date).toISOString());
|
||||||
|
}
|
||||||
|
date.setDate(date.getDate() + 1);
|
||||||
|
}
|
||||||
|
return weekends;
|
||||||
|
};
|
||||||
|
|
||||||
|
const picker = elementArg.querySelector('dees-input-datepicker');
|
||||||
|
if (picker) {
|
||||||
|
picker.disabledDates = generateWeekends();
|
||||||
|
console.log('Disabled weekend dates for current month');
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Disabled Dates'} .subtitle=${'Calendar with specific dates disabled (weekends in current month)'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Availability Calendar"
|
||||||
|
description="Weekends are disabled for the current month"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Generate sample events for the calendar
|
||||||
|
const today = new Date();
|
||||||
|
const currentMonth = today.getMonth();
|
||||||
|
const currentYear = today.getFullYear();
|
||||||
|
|
||||||
|
const sampleEvents = [
|
||||||
|
// Current week events
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`,
|
||||||
|
title: "Team Meeting",
|
||||||
|
type: "info" as const,
|
||||||
|
count: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 1).toString().padStart(2, '0')}-${(today.getDate() + 1).toString().padStart(2, '0')}`,
|
||||||
|
title: "Project Deadline",
|
||||||
|
type: "warning" as const
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 1).toString().padStart(2, '0')}-${(today.getDate() + 2).toString().padStart(2, '0')}`,
|
||||||
|
title: "Release Day",
|
||||||
|
type: "success" as const
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 1).toString().padStart(2, '0')}-${(today.getDate() + 5).toString().padStart(2, '0')}`,
|
||||||
|
title: "Urgent Fix Required",
|
||||||
|
type: "error" as const
|
||||||
|
},
|
||||||
|
// Multiple events on one day
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 1).toString().padStart(2, '0')}-${(today.getDate() + 7).toString().padStart(2, '0')}`,
|
||||||
|
title: "Multiple Events Today",
|
||||||
|
type: "info" as const,
|
||||||
|
count: 5
|
||||||
|
},
|
||||||
|
// Next month event
|
||||||
|
{
|
||||||
|
date: `${currentYear}-${(currentMonth + 2).toString().padStart(2, '0')}-15`,
|
||||||
|
title: "Future Planning Session",
|
||||||
|
type: "info" as const
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const picker = elementArg.querySelector('dees-input-datepicker');
|
||||||
|
if (picker) {
|
||||||
|
picker.events = sampleEvents;
|
||||||
|
console.log('Calendar events loaded:', sampleEvents);
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Calendar with Events'} .subtitle=${'Visual feedback for scheduled events'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Event Calendar"
|
||||||
|
description="Days with colored dots have events. Hover to see details."
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<div class="demo-output" style="margin-top: 16px;">
|
||||||
|
<strong>Event Legend:</strong><br>
|
||||||
|
<span style="color: #0969da;">● Info</span> |
|
||||||
|
<span style="color: #d29922;">● Warning</span> |
|
||||||
|
<span style="color: #2ea043;">● Success</span> |
|
||||||
|
<span style="color: #cf222e;">● Error</span><br>
|
||||||
|
<em>Days with more than 3 events show a count badge</em>
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Interactive event demonstration
|
||||||
|
const picker = elementArg.querySelector('dees-input-datepicker');
|
||||||
|
const output = elementArg.querySelector('#event-output');
|
||||||
|
|
||||||
|
if (picker && output) {
|
||||||
|
picker.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
const target = event.target as DeesInputDatepicker;
|
||||||
|
const value = target.value;
|
||||||
|
if (value) {
|
||||||
|
const date = new Date(value);
|
||||||
|
// Get the formatted value from the input element
|
||||||
|
const input = target.shadowRoot?.querySelector('.date-input') as HTMLInputElement;
|
||||||
|
const formattedValue = input?.value || 'N/A';
|
||||||
|
output.innerHTML = `
|
||||||
|
<strong>Event triggered!</strong><br>
|
||||||
|
ISO Value: ${value}<br>
|
||||||
|
Formatted: ${formattedValue}<br>
|
||||||
|
Date object: ${date.toLocaleString()}
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
output.innerHTML = '<em>Date cleared</em>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
picker.addEventListener('blur', () => {
|
||||||
|
console.log('Datepicker lost focus');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<dees-panel .title=${'Event Handling'} .subtitle=${'Interactive demonstration of change events'}>
|
||||||
|
<dees-input-datepicker
|
||||||
|
label="Event Demo"
|
||||||
|
description="Select a date to see the event details"
|
||||||
|
></dees-input-datepicker>
|
||||||
|
|
||||||
|
<div id="event-output" class="demo-output">
|
||||||
|
<em>Select a date to see event details...</em>
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
</div>
|
||||||
|
`;
|
1309
ts_web/elements/dees-input-datepicker.ts
Normal file
1309
ts_web/elements/dees-input-datepicker.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,45 +5,63 @@ import './dees-form.js';
|
|||||||
import './dees-form-submit.js';
|
import './dees-form-submit.js';
|
||||||
|
|
||||||
export const demoFunc = () => html`
|
export const demoFunc = () => html`
|
||||||
<dees-demowrapper>
|
<style>
|
||||||
<style>
|
${css`
|
||||||
${css`
|
.demo-container {
|
||||||
.demo-container {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
flex-direction: column;
|
gap: 24px;
|
||||||
gap: 24px;
|
padding: 24px;
|
||||||
padding: 24px;
|
max-width: 1200px;
|
||||||
max-width: 1200px;
|
margin: 0 auto;
|
||||||
margin: 0 auto;
|
}
|
||||||
}
|
|
||||||
|
dees-panel {
|
||||||
dees-panel {
|
margin-bottom: 24px;
|
||||||
margin-bottom: 24px;
|
}
|
||||||
}
|
|
||||||
|
dees-panel:last-child {
|
||||||
dees-panel:last-child {
|
margin-bottom: 0;
|
||||||
margin-bottom: 0;
|
}
|
||||||
}
|
|
||||||
|
.horizontal-group {
|
||||||
.horizontal-group {
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
gap: 16px;
|
||||||
gap: 16px;
|
flex-wrap: wrap;
|
||||||
flex-wrap: wrap;
|
}
|
||||||
}
|
|
||||||
|
.spacer {
|
||||||
.spacer {
|
height: 200px;
|
||||||
height: 200px;
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
justify-content: center;
|
||||||
justify-content: center;
|
color: #999;
|
||||||
color: #999;
|
font-size: 14px;
|
||||||
font-size: 14px;
|
}
|
||||||
}
|
`}
|
||||||
`}
|
</style>
|
||||||
</style>
|
|
||||||
|
<div class="demo-container">
|
||||||
<div class="demo-container">
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate programmatic interaction with basic dropdowns
|
||||||
|
const countryDropdown = elementArg.querySelector('dees-input-dropdown[label="Select Country"]');
|
||||||
|
const roleDropdown = elementArg.querySelector('dees-input-dropdown[label="Select Role"]');
|
||||||
|
|
||||||
|
// Log when country changes
|
||||||
|
if (countryDropdown) {
|
||||||
|
countryDropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
|
console.log('Country selected:', event.detail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log when role changes
|
||||||
|
if (roleDropdown) {
|
||||||
|
roleDropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
|
console.log('Role selected:', event.detail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'1. Basic Dropdowns'} .subtitle=${'Standard dropdown with search functionality and various options'}>
|
<dees-panel .title=${'1. Basic Dropdowns'} .subtitle=${'Standard dropdown with search functionality and various options'}>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
.label=${'Select Country'}
|
.label=${'Select Country'}
|
||||||
@@ -70,7 +88,18 @@ export const demoFunc = () => html`
|
|||||||
]}
|
]}
|
||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate simpler dropdown without search
|
||||||
|
const priorityDropdown = elementArg.querySelector('dees-input-dropdown');
|
||||||
|
|
||||||
|
if (priorityDropdown) {
|
||||||
|
priorityDropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
|
console.log(`Priority changed to: ${event.detail.option}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'2. Without Search'} .subtitle=${'Dropdown with search functionality disabled for simpler selection'}>
|
<dees-panel .title=${'2. Without Search'} .subtitle=${'Dropdown with search functionality disabled for simpler selection'}>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
.label=${'Priority Level'}
|
.label=${'Priority Level'}
|
||||||
@@ -83,7 +112,20 @@ export const demoFunc = () => html`
|
|||||||
.selectedOption=${{ option: 'Medium', key: 'medium' }}
|
.selectedOption=${{ option: 'Medium', key: 'medium' }}
|
||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate horizontal layout with multiple dropdowns
|
||||||
|
const dropdowns = elementArg.querySelectorAll('dees-input-dropdown');
|
||||||
|
|
||||||
|
// Log all changes from horizontal dropdowns
|
||||||
|
dropdowns.forEach((dropdown) => {
|
||||||
|
dropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
|
const label = dropdown.getAttribute('label');
|
||||||
|
console.log(`${label}: ${event.detail.option}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'3. Horizontal Layout'} .subtitle=${'Multiple dropdowns in a horizontal layout for compact forms'}>
|
<dees-panel .title=${'3. Horizontal Layout'} .subtitle=${'Multiple dropdowns in a horizontal layout for compact forms'}>
|
||||||
<div class="horizontal-group">
|
<div class="horizontal-group">
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
@@ -120,7 +162,19 @@ export const demoFunc = () => html`
|
|||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate state handling
|
||||||
|
const requiredDropdown = elementArg.querySelector('dees-input-dropdown[required]');
|
||||||
|
|
||||||
|
if (requiredDropdown) {
|
||||||
|
// Show validation state changes
|
||||||
|
requiredDropdown.addEventListener('blur', () => {
|
||||||
|
console.log('Required dropdown lost focus');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'4. States'} .subtitle=${'Different states and configurations'}>
|
<dees-panel .title=${'4. States'} .subtitle=${'Different states and configurations'}>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
.label=${'Required Field'}
|
.label=${'Required Field'}
|
||||||
@@ -141,11 +195,25 @@ export const demoFunc = () => html`
|
|||||||
.selectedOption=${{ option: 'Cannot Select', key: 'disabled' }}
|
.selectedOption=${{ option: 'Cannot Select', key: 'disabled' }}
|
||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<div class="spacer">
|
||||||
|
(Spacer to test dropdown positioning)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// This dropdown demonstrates automatic positioning
|
||||||
|
const dropdown = elementArg.querySelector('dees-input-dropdown');
|
||||||
|
|
||||||
<div class="spacer">
|
if (dropdown) {
|
||||||
(Spacer to test dropdown positioning)
|
dropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
</div>
|
console.log('Bottom dropdown selected:', event.detail);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Note: The dropdown automatically detects available space
|
||||||
|
// and opens upward when near the bottom of the viewport
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'5. Bottom Positioning'} .subtitle=${'Dropdown that opens upward when near bottom of viewport'}>
|
<dees-panel .title=${'5. Bottom Positioning'} .subtitle=${'Dropdown that opens upward when near bottom of viewport'}>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
.label=${'Opens Upward'}
|
.label=${'Opens Upward'}
|
||||||
@@ -158,7 +226,30 @@ export const demoFunc = () => html`
|
|||||||
]}
|
]}
|
||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Setup the interactive payload display
|
||||||
|
const dropdown = elementArg.querySelector('dees-input-dropdown');
|
||||||
|
const output = elementArg.querySelector('#selection-output');
|
||||||
|
|
||||||
|
if (dropdown && output) {
|
||||||
|
// Initialize output
|
||||||
|
output.innerHTML = '<em>Select a product to see details...</em>';
|
||||||
|
|
||||||
|
// Handle dropdown changes
|
||||||
|
dropdown.addEventListener('change', (event: CustomEvent) => {
|
||||||
|
if (event.detail.value) {
|
||||||
|
output.innerHTML = `
|
||||||
|
<strong>Selected:</strong> ${event.detail.value.option}<br>
|
||||||
|
<strong>Key:</strong> ${event.detail.value.key}<br>
|
||||||
|
<strong>Price:</strong> $${event.detail.value.payload?.price || 'N/A'}<br>
|
||||||
|
<strong>Features:</strong> ${event.detail.value.payload?.features?.join(', ') || 'N/A'}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'6. Event Handling & Payload'} .subtitle=${'Dropdown with payload data and change event handling'}>
|
<dees-panel .title=${'6. Event Handling & Payload'} .subtitle=${'Dropdown with payload data and change event handling'}>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
.label=${'Select Product'}
|
.label=${'Select Product'}
|
||||||
@@ -167,24 +258,35 @@ export const demoFunc = () => html`
|
|||||||
{ option: 'Pro Plan', key: 'pro', payload: { price: 19.99, features: ['Feature A', 'Feature B'] } },
|
{ option: 'Pro Plan', key: 'pro', payload: { price: 19.99, features: ['Feature A', 'Feature B'] } },
|
||||||
{ option: 'Enterprise Plan', key: 'enterprise', payload: { price: 49.99, features: ['Feature A', 'Feature B', 'Feature C'] } }
|
{ option: 'Enterprise Plan', key: 'enterprise', payload: { price: 49.99, features: ['Feature A', 'Feature B', 'Feature C'] } }
|
||||||
]}
|
]}
|
||||||
@change=${(e: CustomEvent) => {
|
|
||||||
const output = document.querySelector('#selection-output');
|
|
||||||
if (output && e.detail.value) {
|
|
||||||
output.innerHTML = `
|
|
||||||
<strong>Selected:</strong> ${e.detail.value.option}<br>
|
|
||||||
<strong>Key:</strong> ${e.detail.value.key}<br>
|
|
||||||
<strong>Price:</strong> $${e.detail.value.payload?.price || 'N/A'}<br>
|
|
||||||
<strong>Features:</strong> ${e.detail.value.payload?.features?.join(', ') || 'N/A'}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
></dees-input-dropdown>
|
></dees-input-dropdown>
|
||||||
|
|
||||||
<div id="selection-output" style="margin-top: 16px; padding: 12px; background: rgba(0, 105, 242, 0.1); border-radius: 4px; font-size: 14px;">
|
<div id="selection-output" style="margin-top: 16px; padding: 12px; background: rgba(0, 105, 242, 0.1); border-radius: 4px; font-size: 14px;"></div>
|
||||||
<em>Select a product to see details...</em>
|
|
||||||
</div>
|
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate form integration and validation
|
||||||
|
const form = elementArg.querySelector('dees-form');
|
||||||
|
const projectTypeDropdown = elementArg.querySelector('dees-input-dropdown[key="projectType"]');
|
||||||
|
const frameworkDropdown = elementArg.querySelector('dees-input-dropdown[key="framework"]');
|
||||||
|
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener('formData', (event: CustomEvent) => {
|
||||||
|
console.log('Form submitted with data:', event.detail.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectTypeDropdown && frameworkDropdown) {
|
||||||
|
// Filter frameworks based on project type
|
||||||
|
projectTypeDropdown.addEventListener('selectedOption', (event: CustomEvent) => {
|
||||||
|
const selectedType = event.detail.key;
|
||||||
|
console.log(`Project type changed to: ${selectedType}`);
|
||||||
|
|
||||||
|
// In a real app, you could filter the framework options based on project type
|
||||||
|
// For demo purposes, we just log the change
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'7. Form Integration'} .subtitle=${'Dropdown working within a form with validation'}>
|
<dees-panel .title=${'7. Form Integration'} .subtitle=${'Dropdown working within a form with validation'}>
|
||||||
<dees-form>
|
<dees-form>
|
||||||
<dees-input-dropdown
|
<dees-input-dropdown
|
||||||
@@ -216,6 +318,6 @@ export const demoFunc = () => html`
|
|||||||
<dees-form-submit .text=${'Create Project'}></dees-form-submit>
|
<dees-form-submit .text=${'Create Project'}></dees-form-submit>
|
||||||
</dees-form>
|
</dees-form>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
</div>
|
</dees-demowrapper>
|
||||||
</dees-demowrapper>
|
</div>
|
||||||
`
|
`
|
@@ -37,6 +37,9 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
@property()
|
@property()
|
||||||
public state: 'idle' | 'dragOver' | 'dropped' | 'uploading' | 'completed' = 'idle';
|
public state: 'idle' | 'dragOver' | 'dropped' | 'uploading' | 'completed' = 'idle';
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
private isLoading: boolean = false;
|
||||||
|
|
||||||
@property({
|
@property({
|
||||||
type: String,
|
type: String,
|
||||||
})
|
})
|
||||||
@@ -317,6 +320,53 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Loading state styles */
|
||||||
|
.uploadButton.loading {
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploadButton .button-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid ${cssManager.bdTheme('rgba(0, 0, 0, 0.1)', 'rgba(255, 255, 255, 0.1)')};
|
||||||
|
border-top-color: ${cssManager.bdTheme('#3b82f6', '#60a5fa')};
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.6s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0% {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: scale(1.02);
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploadButton.loading {
|
||||||
|
animation: pulse 1s ease-in-out infinite;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -353,7 +403,7 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
${isImage && this.canShowPreview(fileArg) ? html`
|
${isImage && this.canShowPreview(fileArg) ? html`
|
||||||
<img class="image-preview" src="${URL.createObjectURL(fileArg)}" alt="${fileArg.name}">
|
<img class="image-preview" src="${URL.createObjectURL(fileArg)}" alt="${fileArg.name}">
|
||||||
` : html`
|
` : html`
|
||||||
<dees-icon .iconName=${this.getFileIcon(fileArg)}></dees-icon>
|
<dees-icon .icon=${this.getFileIcon(fileArg)}></dees-icon>
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
@@ -366,7 +416,7 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
@click=${() => this.removeFile(fileArg)}
|
@click=${() => this.removeFile(fileArg)}
|
||||||
title="Remove file"
|
title="Remove file"
|
||||||
>
|
>
|
||||||
<dees-icon .iconName=${'lucide:x'}></dees-icon>
|
<dees-icon .icon=${'lucide:x'}></dees-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -375,13 +425,20 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
</div>
|
</div>
|
||||||
` : html`
|
` : html`
|
||||||
<div class="drop-hint">
|
<div class="drop-hint">
|
||||||
<dees-icon .iconName=${'lucide:cloud-upload'}></dees-icon>
|
<dees-icon .icon=${'lucide:cloud-upload'}></dees-icon>
|
||||||
<div>Drag files here or click to browse</div>
|
<div>Drag files here or click to browse</div>
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
<div class="uploadButton" @click=${this.openFileSelector}>
|
<div class="uploadButton ${this.isLoading ? 'loading' : ''}" @click=${this.openFileSelector}>
|
||||||
<dees-icon .iconName=${'lucide:upload'}></dees-icon>
|
<div class="button-content">
|
||||||
${this.buttonText}
|
${this.isLoading ? html`
|
||||||
|
<div class="loading-spinner"></div>
|
||||||
|
<span>Opening...</span>
|
||||||
|
` : html`
|
||||||
|
<dees-icon .icon=${'lucide:upload'}></dees-icon>
|
||||||
|
${this.buttonText}
|
||||||
|
`}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
${this.description ? html`
|
${this.description ? html`
|
||||||
@@ -482,8 +539,25 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async openFileSelector() {
|
public async openFileSelector() {
|
||||||
if (this.disabled) return;
|
if (this.disabled || this.isLoading) return;
|
||||||
|
|
||||||
|
// Set loading state
|
||||||
|
this.isLoading = true;
|
||||||
|
|
||||||
const inputFile: HTMLInputElement = this.shadowRoot.querySelector('input[type="file"]');
|
const inputFile: HTMLInputElement = this.shadowRoot.querySelector('input[type="file"]');
|
||||||
|
|
||||||
|
// Set up a focus handler to detect when the dialog is closed without selection
|
||||||
|
const handleFocus = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
// Check if no file was selected
|
||||||
|
if (!inputFile.files || inputFile.files.length === 0) {
|
||||||
|
this.isLoading = false;
|
||||||
|
}
|
||||||
|
window.removeEventListener('focus', handleFocus);
|
||||||
|
}, 300);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('focus', handleFocus);
|
||||||
inputFile.click();
|
inputFile.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,6 +590,10 @@ export class DeesInputFileupload extends DeesInputBase<DeesInputFileupload> {
|
|||||||
inputFile.addEventListener('change', async (event: Event) => {
|
inputFile.addEventListener('change', async (event: Event) => {
|
||||||
const target = event.target as HTMLInputElement;
|
const target = event.target as HTMLInputElement;
|
||||||
const newFiles = Array.from(target.files);
|
const newFiles = Array.from(target.files);
|
||||||
|
|
||||||
|
// Always reset loading state when file dialog interaction completes
|
||||||
|
this.isLoading = false;
|
||||||
|
|
||||||
await this.addFiles(newFiles);
|
await this.addFiles(newFiles);
|
||||||
// Reset the input value to allow selecting the same file again if needed
|
// Reset the input value to allow selecting the same file again if needed
|
||||||
target.value = '';
|
target.value = '';
|
||||||
|
275
ts_web/elements/dees-input-list.demo.ts
Normal file
275
ts_web/elements/dees-input-list.demo.ts
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
import { html, css } from '@design.estate/dees-element';
|
||||||
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
|
import './dees-panel.js';
|
||||||
|
import './dees-form.js';
|
||||||
|
import './dees-input-text.js';
|
||||||
|
import './dees-form-submit.js';
|
||||||
|
|
||||||
|
export const demoFunc = () => html`
|
||||||
|
<dees-demowrapper>
|
||||||
|
<style>
|
||||||
|
${css`
|
||||||
|
.demo-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 24px;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
dees-panel {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dees-panel:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-layout {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.grid-layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-preview {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 16px;
|
||||||
|
background: #f3f4f6;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #374151;
|
||||||
|
word-break: break-all;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.output-preview {
|
||||||
|
background: #2c2c2c;
|
||||||
|
color: #e4e4e7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-note {
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 12px;
|
||||||
|
background: #eff6ff;
|
||||||
|
border-left: 3px solid #3b82f6;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #1e40af;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.feature-note {
|
||||||
|
background: #1e3a5f;
|
||||||
|
color: #93c5fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="demo-container">
|
||||||
|
<dees-panel .title=${'1. Basic List Input'} .subtitle=${'Simple list management with add, edit, and delete'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Shopping List'}
|
||||||
|
.placeholder=${'Add item to your list...'}
|
||||||
|
.value=${['Milk', 'Bread', 'Eggs', 'Cheese']}
|
||||||
|
.description=${'Double-click to edit items, or use the edit button'}
|
||||||
|
></dees-input-list>
|
||||||
|
<div class="feature-note">
|
||||||
|
💡 Double-click any item to quickly edit it inline
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'2. Sortable List'} .subtitle=${'Drag and drop to reorder items'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Task Priority'}
|
||||||
|
.placeholder=${'Add a task...'}
|
||||||
|
.sortable=${true}
|
||||||
|
.value=${[
|
||||||
|
'Review pull requests',
|
||||||
|
'Fix critical bug',
|
||||||
|
'Update documentation',
|
||||||
|
'Deploy to production',
|
||||||
|
'Team standup meeting'
|
||||||
|
]}
|
||||||
|
.description=${'Drag items using the handle to reorder them'}
|
||||||
|
></dees-input-list>
|
||||||
|
<div class="feature-note">
|
||||||
|
🔄 Drag the grip handle to reorder tasks by priority
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'3. Validation & Constraints'} .subtitle=${'Lists with minimum/maximum items and duplicate prevention'}>
|
||||||
|
<div class="grid-layout">
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Team Members (Min 2, Max 5)'}
|
||||||
|
.placeholder=${'Add team member...'}
|
||||||
|
.minItems=${2}
|
||||||
|
.maxItems=${5}
|
||||||
|
.value=${['Alice', 'Bob']}
|
||||||
|
.required=${true}
|
||||||
|
.description=${'Add 2-5 team members'}
|
||||||
|
></dees-input-list>
|
||||||
|
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Unique Tags (No Duplicates)'}
|
||||||
|
.placeholder=${'Add unique tag...'}
|
||||||
|
.allowDuplicates=${false}
|
||||||
|
.value=${['frontend', 'backend', 'database']}
|
||||||
|
.description=${'Duplicate items are not allowed'}
|
||||||
|
></dees-input-list>
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'4. Delete Confirmation'} .subtitle=${'Require confirmation before deleting items'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Important Documents'}
|
||||||
|
.placeholder=${'Add document name...'}
|
||||||
|
.confirmDelete=${true}
|
||||||
|
.value=${[
|
||||||
|
'Contract_2024.pdf',
|
||||||
|
'Financial_Report_Q3.xlsx',
|
||||||
|
'Project_Proposal.docx',
|
||||||
|
'Meeting_Notes.txt'
|
||||||
|
]}
|
||||||
|
.description=${'Deletion requires confirmation for safety'}
|
||||||
|
></dees-input-list>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'5. Disabled State'} .subtitle=${'Read-only list display'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'System Defaults'}
|
||||||
|
.value=${['Default Setting 1', 'Default Setting 2', 'Default Setting 3']}
|
||||||
|
.disabled=${true}
|
||||||
|
.description=${'These items cannot be modified'}
|
||||||
|
></dees-input-list>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'6. Form Integration'} .subtitle=${'List input working within a form context'}>
|
||||||
|
<dees-form>
|
||||||
|
<dees-input-text
|
||||||
|
.label=${'Recipe Name'}
|
||||||
|
.placeholder=${'My Amazing Recipe'}
|
||||||
|
.required=${true}
|
||||||
|
.key=${'name'}
|
||||||
|
></dees-input-text>
|
||||||
|
|
||||||
|
<div class="grid-layout">
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Ingredients'}
|
||||||
|
.placeholder=${'Add ingredient...'}
|
||||||
|
.required=${true}
|
||||||
|
.minItems=${3}
|
||||||
|
.key=${'ingredients'}
|
||||||
|
.sortable=${true}
|
||||||
|
.value=${[
|
||||||
|
'2 cups flour',
|
||||||
|
'1 cup sugar',
|
||||||
|
'3 eggs'
|
||||||
|
]}
|
||||||
|
.description=${'Add at least 3 ingredients'}
|
||||||
|
></dees-input-list>
|
||||||
|
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Instructions'}
|
||||||
|
.placeholder=${'Add instruction step...'}
|
||||||
|
.required=${true}
|
||||||
|
.minItems=${2}
|
||||||
|
.key=${'instructions'}
|
||||||
|
.sortable=${true}
|
||||||
|
.value=${[
|
||||||
|
'Preheat oven to 350°F',
|
||||||
|
'Mix dry ingredients'
|
||||||
|
]}
|
||||||
|
.description=${'Add cooking instructions in order'}
|
||||||
|
></dees-input-list>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dees-input-text
|
||||||
|
.label=${'Notes'}
|
||||||
|
.inputType=${'textarea'}
|
||||||
|
.placeholder=${'Any special notes or tips...'}
|
||||||
|
.key=${'notes'}
|
||||||
|
></dees-input-text>
|
||||||
|
|
||||||
|
<dees-form-submit .text=${'Save Recipe'}></dees-form-submit>
|
||||||
|
</dees-form>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'7. Interactive Demo'} .subtitle=${'Build your own feature list and see the data'}>
|
||||||
|
<dees-input-list
|
||||||
|
id="interactive-list"
|
||||||
|
.label=${'Product Features'}
|
||||||
|
.placeholder=${'Add a feature...'}
|
||||||
|
.sortable=${true}
|
||||||
|
.confirmDelete=${false}
|
||||||
|
.allowDuplicates=${false}
|
||||||
|
.maxItems=${10}
|
||||||
|
@change=${(e: CustomEvent) => {
|
||||||
|
const preview = document.querySelector('#list-json');
|
||||||
|
if (preview) {
|
||||||
|
const data = {
|
||||||
|
items: e.detail.value,
|
||||||
|
count: e.detail.value.length,
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
};
|
||||||
|
preview.textContent = JSON.stringify(data, null, 2);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
></dees-input-list>
|
||||||
|
|
||||||
|
<div class="output-preview" id="list-json">
|
||||||
|
{
|
||||||
|
"items": [],
|
||||||
|
"count": 0,
|
||||||
|
"timestamp": "${new Date().toISOString()}"
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="feature-note">
|
||||||
|
✨ Add, edit, remove, and reorder items to see the JSON output update in real-time
|
||||||
|
</div>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'8. Advanced Configuration'} .subtitle=${'Combine all features for complex use cases'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Project Milestones'}
|
||||||
|
.placeholder=${'Add milestone...'}
|
||||||
|
.value=${[
|
||||||
|
'Project Kickoff - Week 1',
|
||||||
|
'Requirements Gathering - Week 2-3',
|
||||||
|
'Design Phase - Week 4-6',
|
||||||
|
'Development Sprint 1 - Week 7-9',
|
||||||
|
'Testing & QA - Week 10-11',
|
||||||
|
'Deployment - Week 12'
|
||||||
|
]}
|
||||||
|
.sortable=${true}
|
||||||
|
.confirmDelete=${true}
|
||||||
|
.allowDuplicates=${false}
|
||||||
|
.minItems=${3}
|
||||||
|
.maxItems=${12}
|
||||||
|
.required=${true}
|
||||||
|
.description=${'Manage project milestones (3-12 items, sortable, no duplicates)'}
|
||||||
|
></dees-input-list>
|
||||||
|
</dees-panel>
|
||||||
|
|
||||||
|
<dees-panel .title=${'9. Empty State'} .subtitle=${'How the component looks with no items'}>
|
||||||
|
<dees-input-list
|
||||||
|
.label=${'Your Ideas'}
|
||||||
|
.placeholder=${'Share your ideas...'}
|
||||||
|
.value=${[]}
|
||||||
|
.description=${'Start adding items to build your list'}
|
||||||
|
></dees-input-list>
|
||||||
|
</dees-panel>
|
||||||
|
</div>
|
||||||
|
</dees-demowrapper>
|
||||||
|
`;
|
622
ts_web/elements/dees-input-list.ts
Normal file
622
ts_web/elements/dees-input-list.ts
Normal file
@@ -0,0 +1,622 @@
|
|||||||
|
import {
|
||||||
|
customElement,
|
||||||
|
html,
|
||||||
|
css,
|
||||||
|
cssManager,
|
||||||
|
property,
|
||||||
|
state,
|
||||||
|
type TemplateResult,
|
||||||
|
} from '@design.estate/dees-element';
|
||||||
|
import { DeesInputBase } from './dees-input-base.js';
|
||||||
|
import './dees-icon.js';
|
||||||
|
import './dees-button.js';
|
||||||
|
import { demoFunc } from './dees-input-list.demo.js';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'dees-input-list': DeesInputList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@customElement('dees-input-list')
|
||||||
|
export class DeesInputList extends DeesInputBase<DeesInputList> {
|
||||||
|
// STATIC
|
||||||
|
public static demo = demoFunc;
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
@property({ type: Array })
|
||||||
|
public value: string[] = [];
|
||||||
|
|
||||||
|
@property({ type: String })
|
||||||
|
public placeholder: string = 'Add new item...';
|
||||||
|
|
||||||
|
@property({ type: Number })
|
||||||
|
public maxItems: number = 0; // 0 means unlimited
|
||||||
|
|
||||||
|
@property({ type: Number })
|
||||||
|
public minItems: number = 0;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public allowDuplicates: boolean = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public sortable: boolean = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
public confirmDelete: boolean = false;
|
||||||
|
|
||||||
|
@property({ type: String })
|
||||||
|
public validationText: string = '';
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private inputValue: string = '';
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private editingIndex: number = -1;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private editingValue: string = '';
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private draggedIndex: number = -1;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private dragOverIndex: number = -1;
|
||||||
|
|
||||||
|
public static styles = [
|
||||||
|
...DeesInputBase.baseStyles,
|
||||||
|
cssManager.defaultStyles,
|
||||||
|
css`
|
||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-container {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 100%)', 'hsl(0 0% 3.9%)')};
|
||||||
|
border: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-container:hover:not(.disabled) {
|
||||||
|
border-color: ${cssManager.bdTheme('hsl(0 0% 79.8%)', 'hsl(0 0% 20.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-container:focus-within {
|
||||||
|
border-color: ${cssManager.bdTheme('hsl(222.2 47.4% 51.2%)', 'hsl(217.2 91.2% 59.8%)')};
|
||||||
|
box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(222.2 47.4% 51.2% / 0.1)', 'hsl(217.2 91.2% 59.8% / 0.1)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-container.disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-items {
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 100%)', 'hsl(0 0% 3.9%)')};
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden; /* Prevent animation from affecting scroll bounds */
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item:last-of-type {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item:hover:not(.disabled) {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 97.5%)', 'hsl(0 0% 6.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item.dragging {
|
||||||
|
opacity: 0.4;
|
||||||
|
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 10.8%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item.drag-over {
|
||||||
|
background: ${cssManager.bdTheme('hsl(210 40% 93.1%)', 'hsl(215 20.2% 13.8%)')};
|
||||||
|
border-color: ${cssManager.bdTheme('hsl(222.2 47.4% 51.2%)', 'hsl(217.2 91.2% 59.8%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.drag-handle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: move;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 63.9%)', 'hsl(0 0% 45.1%)')};
|
||||||
|
transition: color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drag-handle:hover {
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 45.1%)', 'hsl(0 0% 63.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.drag-handle dees-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-content {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text {
|
||||||
|
flex: 1;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-edit-input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: inherit;
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 100%)', 'hsl(0 0% 9%)')};
|
||||||
|
border: 1px solid ${cssManager.bdTheme('hsl(222.2 47.4% 51.2%)', 'hsl(217.2 91.2% 59.8%)')};
|
||||||
|
border-radius: 4px;
|
||||||
|
outline: none;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 45.1%)', 'hsl(0 0% 63.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 95.1%)', 'hsl(0 0% 14.9%)')};
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.save {
|
||||||
|
color: ${cssManager.bdTheme('hsl(142.1 76.2% 36.3%)', 'hsl(142.1 70.6% 45.3%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.save:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(142.1 76.2% 36.3% / 0.1)', 'hsl(142.1 70.6% 45.3% / 0.1)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.cancel {
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 72.2% 50.6%)', 'hsl(0 62.8% 50.6%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.cancel:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 72.2% 50.6% / 0.1)', 'hsl(0 62.8% 50.6% / 0.1)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.delete {
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 72.2% 50.6%)', 'hsl(0 62.8% 50.6%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button.delete:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 72.2% 50.6% / 0.1)', 'hsl(0 62.8% 50.6% / 0.1)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button dees-icon {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-item-container {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 97.5%)', 'hsl(0 0% 6.9%)')};
|
||||||
|
border-top: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: inherit;
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 100%)', 'hsl(0 0% 9%)')};
|
||||||
|
border: 1px solid ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 14.9%)')};
|
||||||
|
border-radius: 4px;
|
||||||
|
outline: none;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 9%)', 'hsl(0 0% 95%)')};
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-input:focus {
|
||||||
|
border-color: ${cssManager.bdTheme('hsl(222.2 47.4% 51.2%)', 'hsl(217.2 91.2% 59.8%)')};
|
||||||
|
box-shadow: 0 0 0 3px ${cssManager.bdTheme('hsl(222.2 47.4% 51.2% / 0.1)', 'hsl(217.2 91.2% 59.8% / 0.1)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-input::placeholder {
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 63.9%)', 'hsl(0 0% 45.1%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-input:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-button {
|
||||||
|
padding: 8px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
padding: 32px 16px;
|
||||||
|
text-align: center;
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 0% 63.9%)', 'hsl(0 0% 45.1%)')};
|
||||||
|
font-size: 14px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-message {
|
||||||
|
color: ${cssManager.bdTheme('hsl(0 72.2% 50.6%)', 'hsl(0 62.8% 30.6%)')};
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 6px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
color: ${cssManager.bdTheme('hsl(215.4 16.3% 56.9%)', 'hsl(215 20.2% 55.1%)')};
|
||||||
|
font-size: 13px;
|
||||||
|
margin-top: 6px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scrollbar styling */
|
||||||
|
.list-items::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-items::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-items::-webkit-scrollbar-thumb {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 89.8%)', 'hsl(0 0% 24.9%)')};
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-items::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(0 0% 79.8%)', 'hsl(0 0% 34.9%)')};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation for adding/removing items */
|
||||||
|
@keyframes slideIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-10px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item {
|
||||||
|
animation: slideIn 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override any inherited contain/content-visibility that might cause scrolling issues */
|
||||||
|
.list-items, .list-item {
|
||||||
|
content-visibility: visible !important;
|
||||||
|
contain: none !important;
|
||||||
|
contain-intrinsic-size: auto !important;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
|
||||||
|
public render(): TemplateResult {
|
||||||
|
return html`
|
||||||
|
<div class="input-wrapper">
|
||||||
|
${this.label ? html`<dees-label .label=${this.label} .required=${this.required}></dees-label>` : ''}
|
||||||
|
|
||||||
|
<div class="list-container ${this.disabled ? 'disabled' : ''}">
|
||||||
|
<div class="list-items">
|
||||||
|
${this.value.length > 0 ? this.value.map((item, index) => html`
|
||||||
|
<div
|
||||||
|
class="list-item ${this.draggedIndex === index ? 'dragging' : ''} ${this.dragOverIndex === index ? 'drag-over' : ''}"
|
||||||
|
draggable="${this.sortable && !this.disabled}"
|
||||||
|
@dragstart=${(e: DragEvent) => this.handleDragStart(e, index)}
|
||||||
|
@dragend=${this.handleDragEnd}
|
||||||
|
@dragover=${(e: DragEvent) => this.handleDragOver(e, index)}
|
||||||
|
@dragleave=${this.handleDragLeave}
|
||||||
|
@drop=${(e: DragEvent) => this.handleDrop(e, index)}
|
||||||
|
>
|
||||||
|
${this.sortable && !this.disabled ? html`
|
||||||
|
<div class="drag-handle">
|
||||||
|
<dees-icon .icon=${'lucide:gripVertical'}></dees-icon>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
|
||||||
|
<div class="item-content">
|
||||||
|
${this.editingIndex === index ? html`
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="item-edit-input"
|
||||||
|
.value=${this.editingValue}
|
||||||
|
@input=${(e: InputEvent) => this.editingValue = (e.target as HTMLInputElement).value}
|
||||||
|
@keydown=${(e: KeyboardEvent) => this.handleEditKeyDown(e, index)}
|
||||||
|
@blur=${() => this.saveEdit(index)}
|
||||||
|
/>
|
||||||
|
` : html`
|
||||||
|
<div class="item-text" @dblclick=${() => !this.disabled && this.startEdit(index)}>
|
||||||
|
${item}
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item-actions">
|
||||||
|
${this.editingIndex === index ? html`
|
||||||
|
<button class="action-button save" @click=${() => this.saveEdit(index)}>
|
||||||
|
<dees-icon .icon=${'lucide:check'}></dees-icon>
|
||||||
|
</button>
|
||||||
|
<button class="action-button cancel" @click=${() => this.cancelEdit()}>
|
||||||
|
<dees-icon .icon=${'lucide:x'}></dees-icon>
|
||||||
|
</button>
|
||||||
|
` : html`
|
||||||
|
${!this.disabled ? html`
|
||||||
|
<button class="action-button" @click=${() => this.startEdit(index)}>
|
||||||
|
<dees-icon .icon=${'lucide:pencil'}></dees-icon>
|
||||||
|
</button>
|
||||||
|
<button class="action-button delete" @click=${() => this.removeItem(index)}>
|
||||||
|
<dees-icon .icon=${'lucide:trash2'}></dees-icon>
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`) : html`
|
||||||
|
<div class="empty-state">
|
||||||
|
No items added yet
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${!this.disabled && (!this.maxItems || this.value.length < this.maxItems) ? html`
|
||||||
|
<div class="add-item-container">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="add-input"
|
||||||
|
.placeholder=${this.placeholder}
|
||||||
|
.value=${this.inputValue}
|
||||||
|
@input=${this.handleInput}
|
||||||
|
@keydown=${this.handleAddKeyDown}
|
||||||
|
?disabled=${this.disabled}
|
||||||
|
/>
|
||||||
|
<dees-button
|
||||||
|
class="add-button"
|
||||||
|
@click=${this.addItem}
|
||||||
|
?disabled=${!this.inputValue.trim()}
|
||||||
|
>
|
||||||
|
<dees-icon .icon=${'lucide:plus'}></dees-icon> Add
|
||||||
|
</dees-button>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${this.validationText ? html`
|
||||||
|
<div class="validation-message">${this.validationText}</div>
|
||||||
|
` : ''}
|
||||||
|
|
||||||
|
${this.description ? html`
|
||||||
|
<div class="description">${this.description}</div>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleInput(e: InputEvent) {
|
||||||
|
this.inputValue = (e.target as HTMLInputElement).value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleAddKeyDown(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Enter' && this.inputValue.trim()) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.addItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleEditKeyDown(e: KeyboardEvent, index: number) {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
this.saveEdit(index);
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
e.preventDefault();
|
||||||
|
this.cancelEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private addItem() {
|
||||||
|
const trimmedValue = this.inputValue.trim();
|
||||||
|
if (!trimmedValue) return;
|
||||||
|
|
||||||
|
if (!this.allowDuplicates && this.value.includes(trimmedValue)) {
|
||||||
|
this.validationText = 'This item already exists in the list';
|
||||||
|
setTimeout(() => this.validationText = '', 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.maxItems && this.value.length >= this.maxItems) {
|
||||||
|
this.validationText = `Maximum ${this.maxItems} items allowed`;
|
||||||
|
setTimeout(() => this.validationText = '', 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.value = [...this.value, trimmedValue];
|
||||||
|
this.inputValue = '';
|
||||||
|
this.validationText = '';
|
||||||
|
|
||||||
|
// Clear the input
|
||||||
|
const input = this.shadowRoot?.querySelector('.add-input') as HTMLInputElement;
|
||||||
|
if (input) {
|
||||||
|
input.value = '';
|
||||||
|
input.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emitChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private startEdit(index: number) {
|
||||||
|
this.editingIndex = index;
|
||||||
|
this.editingValue = this.value[index];
|
||||||
|
|
||||||
|
// Focus the input after render
|
||||||
|
this.updateComplete.then(() => {
|
||||||
|
const input = this.shadowRoot?.querySelector('.item-edit-input') as HTMLInputElement;
|
||||||
|
if (input) {
|
||||||
|
input.focus();
|
||||||
|
input.select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private saveEdit(index: number) {
|
||||||
|
const trimmedValue = this.editingValue.trim();
|
||||||
|
|
||||||
|
if (!trimmedValue) {
|
||||||
|
this.cancelEdit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.allowDuplicates && trimmedValue !== this.value[index] && this.value.includes(trimmedValue)) {
|
||||||
|
this.validationText = 'This item already exists in the list';
|
||||||
|
setTimeout(() => this.validationText = '', 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newValue = [...this.value];
|
||||||
|
newValue[index] = trimmedValue;
|
||||||
|
this.value = newValue;
|
||||||
|
|
||||||
|
this.editingIndex = -1;
|
||||||
|
this.editingValue = '';
|
||||||
|
this.validationText = '';
|
||||||
|
this.emitChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private cancelEdit() {
|
||||||
|
this.editingIndex = -1;
|
||||||
|
this.editingValue = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private async removeItem(index: number) {
|
||||||
|
if (this.confirmDelete) {
|
||||||
|
const confirmed = await this.showConfirmDialog(`Delete "${this.value[index]}"?`);
|
||||||
|
if (!confirmed) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.value = this.value.filter((_, i) => i !== index);
|
||||||
|
this.emitChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async showConfirmDialog(message: string): Promise<boolean> {
|
||||||
|
// For now, use native confirm. In production, this should use a proper modal
|
||||||
|
return confirm(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drag and drop handlers
|
||||||
|
private handleDragStart(e: DragEvent, index: number) {
|
||||||
|
if (!this.sortable || this.disabled) return;
|
||||||
|
|
||||||
|
this.draggedIndex = index;
|
||||||
|
e.dataTransfer!.effectAllowed = 'move';
|
||||||
|
e.dataTransfer!.setData('text/plain', index.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleDragEnd() {
|
||||||
|
this.draggedIndex = -1;
|
||||||
|
this.dragOverIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleDragOver(e: DragEvent, index: number) {
|
||||||
|
if (!this.sortable || this.disabled) return;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.dataTransfer!.dropEffect = 'move';
|
||||||
|
this.dragOverIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleDragLeave() {
|
||||||
|
this.dragOverIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleDrop(e: DragEvent, dropIndex: number) {
|
||||||
|
if (!this.sortable || this.disabled) return;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
const draggedIndex = parseInt(e.dataTransfer!.getData('text/plain'));
|
||||||
|
|
||||||
|
if (draggedIndex !== dropIndex) {
|
||||||
|
const newValue = [...this.value];
|
||||||
|
const [draggedItem] = newValue.splice(draggedIndex, 1);
|
||||||
|
newValue.splice(dropIndex, 0, draggedItem);
|
||||||
|
this.value = newValue;
|
||||||
|
this.emitChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draggedIndex = -1;
|
||||||
|
this.dragOverIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private emitChange() {
|
||||||
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
detail: { value: this.value },
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
}));
|
||||||
|
this.changeSubject.next(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getValue(): string[] {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setValue(value: string[]): void {
|
||||||
|
this.value = value || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async validate(): Promise<boolean> {
|
||||||
|
if (this.required && (!this.value || this.value.length === 0)) {
|
||||||
|
this.validationText = 'At least one item is required';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.minItems && this.value.length < this.minItems) {
|
||||||
|
this.validationText = `At least ${this.minItems} items required`;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.validationText = '';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,67 +1,87 @@
|
|||||||
import { html, css, cssManager } from '@design.estate/dees-element';
|
import { html, css, cssManager } from '@design.estate/dees-element';
|
||||||
import '@design.estate/dees-wcctools/demotools';
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
import './dees-panel.js';
|
import './dees-panel.js';
|
||||||
|
import type { DeesInputText } from './dees-input-text.js';
|
||||||
|
|
||||||
export const demoFunc = () => html`
|
export const demoFunc = () => html`
|
||||||
<dees-demowrapper>
|
<style>
|
||||||
<style>
|
${css`
|
||||||
${css`
|
.demo-container {
|
||||||
.demo-container {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: column;
|
||||||
flex-direction: column;
|
gap: 24px;
|
||||||
gap: 24px;
|
padding: 24px;
|
||||||
padding: 24px;
|
max-width: 1200px;
|
||||||
max-width: 1200px;
|
margin: 0 auto;
|
||||||
margin: 0 auto;
|
}
|
||||||
}
|
|
||||||
|
dees-panel {
|
||||||
dees-panel {
|
margin-bottom: 24px;
|
||||||
margin-bottom: 24px;
|
}
|
||||||
}
|
|
||||||
|
dees-panel:last-child {
|
||||||
dees-panel:last-child {
|
margin-bottom: 0;
|
||||||
margin-bottom: 0;
|
}
|
||||||
}
|
|
||||||
|
.horizontal-group {
|
||||||
.horizontal-group {
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
align-items: center;
|
gap: 16px;
|
||||||
gap: 16px;
|
flex-wrap: wrap;
|
||||||
flex-wrap: wrap;
|
}
|
||||||
}
|
|
||||||
|
.grid-layout {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
.grid-layout {
|
.grid-layout {
|
||||||
display: grid;
|
grid-template-columns: 1fr;
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 16px;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.interactive-section {
|
||||||
|
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-text {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
color: ${cssManager.bdTheme('hsl(215.3 25% 26.7%)', 'hsl(210 40% 80%)')};
|
||||||
|
padding: 8px;
|
||||||
|
background: ${cssManager.bdTheme('hsl(210 40% 98%)', 'hsl(215 20.2% 11.8%)')};
|
||||||
|
border-radius: 4px;
|
||||||
|
min-height: 24px;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="demo-container">
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate basic text input functionality
|
||||||
|
const inputs = elementArg.querySelectorAll('dees-input-text');
|
||||||
|
|
||||||
|
inputs.forEach((input: DeesInputText) => {
|
||||||
|
input.addEventListener('changeSubject', (event: CustomEvent) => {
|
||||||
|
console.log(`Input "${input.label}" changed to:`, input.getValue());
|
||||||
|
});
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
input.addEventListener('blur', () => {
|
||||||
.grid-layout {
|
console.log(`Input "${input.label}" lost focus`);
|
||||||
grid-template-columns: 1fr;
|
});
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
// Show password visibility toggle
|
||||||
.interactive-section {
|
const passwordInput = elementArg.querySelector('dees-input-text[key="password"]') as DeesInputText;
|
||||||
background: ${cssManager.bdTheme('hsl(210 40% 96.1%)', 'hsl(215 20.2% 16.8%)')};
|
if (passwordInput) {
|
||||||
border-radius: 8px;
|
console.log('Password input includes visibility toggle');
|
||||||
padding: 16px;
|
}
|
||||||
margin-top: 16px;
|
}}>
|
||||||
}
|
|
||||||
|
|
||||||
.output-text {
|
|
||||||
font-family: monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
color: ${cssManager.bdTheme('hsl(215.3 25% 26.7%)', 'hsl(210 40% 80%)')};
|
|
||||||
padding: 8px;
|
|
||||||
background: ${cssManager.bdTheme('hsl(210 40% 98%)', 'hsl(215 20.2% 11.8%)')};
|
|
||||||
border-radius: 4px;
|
|
||||||
min-height: 24px;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<div class="demo-container">
|
|
||||||
<dees-panel .title=${'Basic Text Inputs'} .subtitle=${'Standard text inputs with labels and descriptions'}>
|
<dees-panel .title=${'Basic Text Inputs'} .subtitle=${'Standard text inputs with labels and descriptions'}>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.label=${'Username'}
|
.label=${'Username'}
|
||||||
@@ -83,7 +103,33 @@ export const demoFunc = () => html`
|
|||||||
.key=${'password'}
|
.key=${'password'}
|
||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate horizontal layout behavior
|
||||||
|
const horizontalInputs = elementArg.querySelectorAll('dees-input-text');
|
||||||
|
|
||||||
|
// Check that inputs are properly spaced horizontally
|
||||||
|
horizontalInputs.forEach((input: DeesInputText) => {
|
||||||
|
const computedStyle = window.getComputedStyle(input);
|
||||||
|
console.log(`Horizontal input "${input.label}" display:`, computedStyle.display);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track value changes
|
||||||
|
const firstNameInput = elementArg.querySelector('dees-input-text[key="firstName"]');
|
||||||
|
const lastNameInput = elementArg.querySelector('dees-input-text[key="lastName"]');
|
||||||
|
|
||||||
|
if (firstNameInput && lastNameInput) {
|
||||||
|
const updateFullName = () => {
|
||||||
|
const firstName = (firstNameInput as DeesInputText).getValue();
|
||||||
|
const lastName = (lastNameInput as DeesInputText).getValue();
|
||||||
|
console.log(`Full name: ${firstName} ${lastName}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
firstNameInput.addEventListener('changeSubject', updateFullName);
|
||||||
|
lastNameInput.addEventListener('changeSubject', updateFullName);
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'Horizontal Layout'} .subtitle=${'Multiple inputs arranged horizontally for compact forms'}>
|
<dees-panel .title=${'Horizontal Layout'} .subtitle=${'Multiple inputs arranged horizontally for compact forms'}>
|
||||||
<div class="horizontal-group">
|
<div class="horizontal-group">
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
@@ -108,7 +154,23 @@ export const demoFunc = () => html`
|
|||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate different label positions
|
||||||
|
const inputs = elementArg.querySelectorAll('dees-input-text');
|
||||||
|
|
||||||
|
inputs.forEach((input: DeesInputText) => {
|
||||||
|
const position = input.labelPosition;
|
||||||
|
console.log(`Input "${input.label}" has label position: ${position}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show how label position affects layout
|
||||||
|
const leftLabelInputs = elementArg.querySelectorAll('dees-input-text[labelPosition="left"]');
|
||||||
|
if (leftLabelInputs.length > 0) {
|
||||||
|
console.log(`${leftLabelInputs.length} inputs have left-aligned labels for inline layout`);
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'Label Positions'} .subtitle=${'Different label positioning options for various layouts'}>
|
<dees-panel .title=${'Label Positions'} .subtitle=${'Different label positioning options for various layouts'}>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.label=${'Label on Top (Default)'}
|
.label=${'Label on Top (Default)'}
|
||||||
@@ -136,7 +198,41 @@ export const demoFunc = () => html`
|
|||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Demonstrate validation states
|
||||||
|
const requiredInput = elementArg.querySelector('dees-input-text[required]') as DeesInputText;
|
||||||
|
const disabledInput = elementArg.querySelector('dees-input-text[disabled]') as DeesInputText;
|
||||||
|
const errorInput = elementArg.querySelector('dees-input-text[validationState="invalid"]') as DeesInputText;
|
||||||
|
|
||||||
|
if (requiredInput) {
|
||||||
|
// Show validation on blur for empty required field
|
||||||
|
requiredInput.addEventListener('blur', () => {
|
||||||
|
if (!requiredInput.getValue()) {
|
||||||
|
console.log('Required field is empty!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disabledInput) {
|
||||||
|
console.log('Disabled input cannot be edited');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorInput) {
|
||||||
|
console.log('Error input shows validation message:', errorInput.validationText);
|
||||||
|
|
||||||
|
// Simulate fixing the error
|
||||||
|
errorInput.addEventListener('changeSubject', () => {
|
||||||
|
const value = errorInput.getValue();
|
||||||
|
if (value.includes('@') && value.includes('.')) {
|
||||||
|
errorInput.validationState = 'valid';
|
||||||
|
errorInput.validationText = '';
|
||||||
|
console.log('Email validation passed!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'Validation & States'} .subtitle=${'Different validation states and input configurations'}>
|
<dees-panel .title=${'Validation & States'} .subtitle=${'Different validation states and input configurations'}>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.label=${'Required Field'}
|
.label=${'Required Field'}
|
||||||
@@ -157,7 +253,31 @@ export const demoFunc = () => html`
|
|||||||
.validationState=${'invalid'}
|
.validationState=${'invalid'}
|
||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Track password visibility toggles
|
||||||
|
const passwordInputs = elementArg.querySelectorAll('dees-input-text[isPasswordBool]');
|
||||||
|
|
||||||
|
passwordInputs.forEach((input: DeesInputText) => {
|
||||||
|
// Monitor for toggle button clicks within shadow DOM
|
||||||
|
const checkToggle = () => {
|
||||||
|
const inputEl = input.shadowRoot?.querySelector('input');
|
||||||
|
if (inputEl) {
|
||||||
|
console.log(`Password field "${input.label}" type:`, inputEl.type);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use MutationObserver to detect changes
|
||||||
|
if (input.shadowRoot) {
|
||||||
|
const observer = new MutationObserver(checkToggle);
|
||||||
|
const inputEl = input.shadowRoot.querySelector('input');
|
||||||
|
if (inputEl) {
|
||||||
|
observer.observe(inputEl, { attributes: true, attributeFilter: ['type'] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'Advanced Features'} .subtitle=${'Password visibility toggle and other advanced features'}>
|
<dees-panel .title=${'Advanced Features'} .subtitle=${'Password visibility toggle and other advanced features'}>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.label=${'Password with Toggle'}
|
.label=${'Password with Toggle'}
|
||||||
@@ -173,23 +293,47 @@ export const demoFunc = () => html`
|
|||||||
.description=${'Keep this key secure and never share it'}
|
.description=${'Keep this key secure and never share it'}
|
||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
|
</dees-demowrapper>
|
||||||
|
|
||||||
|
<dees-demowrapper .runAfterRender=${async (elementArg: HTMLElement) => {
|
||||||
|
// Set up interactive example
|
||||||
|
const dynamicInput = elementArg.querySelector('dees-input-text');
|
||||||
|
const output = elementArg.querySelector('#text-input-output');
|
||||||
|
|
||||||
|
if (dynamicInput && output) {
|
||||||
|
// Update output on every change
|
||||||
|
dynamicInput.addEventListener('changeSubject', (event: CustomEvent) => {
|
||||||
|
const value = (event.detail as DeesInputText).getValue();
|
||||||
|
output.textContent = `Current value: "${value}"`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also track focus/blur events
|
||||||
|
dynamicInput.addEventListener('focus', () => {
|
||||||
|
console.log('Input focused');
|
||||||
|
});
|
||||||
|
|
||||||
|
dynamicInput.addEventListener('blur', () => {
|
||||||
|
console.log('Input blurred');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track keypress events
|
||||||
|
let keypressCount = 0;
|
||||||
|
dynamicInput.addEventListener('keydown', () => {
|
||||||
|
keypressCount++;
|
||||||
|
console.log(`Keypress count: ${keypressCount}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}>
|
||||||
<dees-panel .title=${'Interactive Example'} .subtitle=${'Try typing in the inputs to see real-time value changes'}>
|
<dees-panel .title=${'Interactive Example'} .subtitle=${'Try typing in the inputs to see real-time value changes'}>
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.label=${'Dynamic Input'}
|
.label=${'Dynamic Input'}
|
||||||
.placeholder=${'Type something here...'}
|
.placeholder=${'Type something here...'}
|
||||||
@changeSubject=${(event) => {
|
|
||||||
const output = document.querySelector('#text-input-output');
|
|
||||||
if (output && event.detail) {
|
|
||||||
output.textContent = `Current value: "${event.detail.getValue()}"`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
></dees-input-text>
|
></dees-input-text>
|
||||||
|
|
||||||
<div class="interactive-section">
|
<div class="interactive-section">
|
||||||
<div id="text-input-output" class="output-text">Current value: ""</div>
|
<div id="text-input-output" class="output-text">Current value: ""</div>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
</div>
|
</dees-demowrapper>
|
||||||
</dees-demowrapper>
|
</div>
|
||||||
`;
|
`;
|
@@ -231,7 +231,7 @@ export class DeesInputText extends DeesInputBase {
|
|||||||
${this.isPasswordBool
|
${this.isPasswordBool
|
||||||
? html`
|
? html`
|
||||||
<div class="showPassword" @click=${this.togglePasswordView}>
|
<div class="showPassword" @click=${this.togglePasswordView}>
|
||||||
<dees-icon .iconName=${this.showPasswordBool ? 'lucideEye' : 'lucideEyeOff'}></dees-icon>
|
<dees-icon .icon=${this.showPasswordBool ? 'lucide:Eye' : 'lucide:EyeOff'}></dees-icon>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: html``}
|
: html``}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { html, css, type TemplateResult } from '@design.estate/dees-element';
|
import { html, css, type TemplateResult } from '@design.estate/dees-element';
|
||||||
import '@design.estate/dees-wcctools/demotools';
|
import '@design.estate/dees-wcctools/demotools';
|
||||||
import './dees-panel.js';
|
import './dees-panel.js';
|
||||||
import type { DeesInputWysiwyg } from './dees-input-wysiwyg.js';
|
import type { DeesInputWysiwyg } from './dees-input-wysiwyg/dees-input-wysiwyg.js';
|
||||||
import type { IBlock } from './wysiwyg/wysiwyg.types.js';
|
import type { IBlock } from './dees-input-wysiwyg/wysiwyg.types.js';
|
||||||
|
|
||||||
interface IDemoEditor {
|
interface IDemoEditor {
|
||||||
basic: DeesInputWysiwyg;
|
basic: DeesInputWysiwyg;
|
||||||
@@ -250,6 +250,30 @@ const setupExportDemo = (container: HTMLElement, editor: DeesInputWysiwyg) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setupOutputFormatDemo = (
|
||||||
|
container: HTMLElement,
|
||||||
|
htmlEditor?: DeesInputWysiwyg,
|
||||||
|
markdownEditor?: DeesInputWysiwyg,
|
||||||
|
) => {
|
||||||
|
const htmlBtn = container.querySelector('#btn-show-html-output') as HTMLButtonElement | null;
|
||||||
|
const htmlPreview = container.querySelector('#output-preview-html') as HTMLElement | null;
|
||||||
|
if (htmlBtn && htmlPreview && htmlEditor) {
|
||||||
|
htmlBtn.addEventListener('click', () => {
|
||||||
|
htmlPreview.textContent = htmlEditor.getValue();
|
||||||
|
htmlPreview.classList.add('visible');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const markdownBtn = container.querySelector('#btn-show-markdown-output') as HTMLButtonElement | null;
|
||||||
|
const markdownPreview = container.querySelector('#output-preview-markdown') as HTMLElement | null;
|
||||||
|
if (markdownBtn && markdownPreview && markdownEditor) {
|
||||||
|
markdownBtn.addEventListener('click', () => {
|
||||||
|
markdownPreview.textContent = markdownEditor.getValue();
|
||||||
|
markdownPreview.classList.add('visible');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const populateInitialContent = (editors: IDemoEditor) => {
|
const populateInitialContent = (editors: IDemoEditor) => {
|
||||||
// Article editor content
|
// Article editor content
|
||||||
if (editors.article) {
|
if (editors.article) {
|
||||||
@@ -488,11 +512,46 @@ export const demoFunc = (): TemplateResult => html`
|
|||||||
|
|
||||||
.output-grid {
|
.output-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||||
gap: 24px;
|
gap: 24px;
|
||||||
margin-top: 24px;
|
margin-top: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.output-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-preview {
|
||||||
|
display: none;
|
||||||
|
background: rgba(15, 23, 42, 0.04);
|
||||||
|
color: var(--dees-color-text, #0f172a);
|
||||||
|
border: 1px solid rgba(15, 23, 42, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
font-family: 'Geist Mono', 'Fira Code', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
max-height: 280px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([theme='dark']) .output-preview {
|
||||||
|
background: rgba(250, 250, 250, 0.06);
|
||||||
|
border-color: rgba(250, 250, 250, 0.15);
|
||||||
|
color: var(--dees-color-text, #f4f4f5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.output-preview.visible {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.output-grid {
|
.output-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
@@ -858,7 +917,7 @@ git merge feature-branch
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="output-grid">
|
<div class="output-grid">
|
||||||
<div>
|
<div class="output-card">
|
||||||
<dees-input-wysiwyg
|
<dees-input-wysiwyg
|
||||||
id="editor-meeting"
|
id="editor-meeting"
|
||||||
label="Meeting Notes"
|
label="Meeting Notes"
|
||||||
@@ -866,9 +925,13 @@ git merge feature-branch
|
|||||||
outputFormat="html"
|
outputFormat="html"
|
||||||
value="<h2>Q4 Planning Meeting</h2><p><strong>Date:</strong> December 15, 2024<br><strong>Attendees:</strong> Product Team, Engineering, Design</p><h3>Agenda Items</h3><ol><li>Review Q3 achievements</li><li>Set Q4 objectives</li><li>Resource allocation</li><li>Timeline discussion</li></ol><h3>Key Decisions</h3><ul><li>Launch new dashboard feature by end of January</li><li>Increase engineering team by 2 developers</li><li>Implement weekly design reviews</li></ul><blockquote>"Focus on user experience improvements based on Q3 feedback" - Product Manager</blockquote><h3>Action Items</h3><ul><li>Sarah: Create detailed project timeline</li><li>Mike: Draft technical requirements</li><li>Lisa: Schedule user research sessions</li></ul><hr><p>Next meeting: January 5, 2025</p>"
|
value="<h2>Q4 Planning Meeting</h2><p><strong>Date:</strong> December 15, 2024<br><strong>Attendees:</strong> Product Team, Engineering, Design</p><h3>Agenda Items</h3><ol><li>Review Q3 achievements</li><li>Set Q4 objectives</li><li>Resource allocation</li><li>Timeline discussion</li></ol><h3>Key Decisions</h3><ul><li>Launch new dashboard feature by end of January</li><li>Increase engineering team by 2 developers</li><li>Implement weekly design reviews</li></ul><blockquote>"Focus on user experience improvements based on Q3 feedback" - Product Manager</blockquote><h3>Action Items</h3><ul><li>Sarah: Create detailed project timeline</li><li>Mike: Draft technical requirements</li><li>Lisa: Schedule user research sessions</li></ul><hr><p>Next meeting: January 5, 2025</p>"
|
||||||
></dees-input-wysiwyg>
|
></dees-input-wysiwyg>
|
||||||
|
<div class="output-actions">
|
||||||
|
<button id="btn-show-html-output" class="demo-button">Show HTML Output</button>
|
||||||
|
</div>
|
||||||
|
<pre id="output-preview-html" class="output-preview" aria-live="polite"></pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="output-card">
|
||||||
<dees-input-wysiwyg
|
<dees-input-wysiwyg
|
||||||
id="editor-recipe"
|
id="editor-recipe"
|
||||||
label="Recipe Blog Post"
|
label="Recipe Blog Post"
|
||||||
@@ -927,6 +990,10 @@ Gradually blend in flour mixture, then stir in chocolate chips. Drop rounded tab
|
|||||||
|
|
||||||
**Yield:** About 5 dozen cookies"
|
**Yield:** About 5 dozen cookies"
|
||||||
></dees-input-wysiwyg>
|
></dees-input-wysiwyg>
|
||||||
|
<div class="output-actions">
|
||||||
|
<button id="btn-show-markdown-output" class="demo-button">Show Markdown Output</button>
|
||||||
|
</div>
|
||||||
|
<pre id="output-preview-markdown" class="output-preview" aria-live="polite"></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</dees-panel>
|
</dees-panel>
|
||||||
@@ -1066,4 +1133,4 @@ POST /api/v2/batch
|
|||||||
</dees-panel>
|
</dees-panel>
|
||||||
</div>
|
</div>
|
||||||
</dees-demowrapper>
|
</dees-demowrapper>
|
||||||
`;
|
`;
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
// Re-export the modular component from the wysiwyg directory
|
// Re-export the component and related helpers from the dedicated subdirectory
|
||||||
export { DeesInputWysiwyg } from './wysiwyg/dees-input-wysiwyg.js';
|
export { DeesInputWysiwyg } from './dees-input-wysiwyg/dees-input-wysiwyg.js';
|
||||||
|
export * from './dees-input-wysiwyg/index.js';
|
||||||
|
@@ -118,6 +118,17 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async firstUpdated() {
|
async firstUpdated() {
|
||||||
|
if (this.value && this.value.trim().length > 0) {
|
||||||
|
const parsedBlocks =
|
||||||
|
this.outputFormat === 'html'
|
||||||
|
? WysiwygConverters.parseHtmlToBlocks(this.value)
|
||||||
|
: WysiwygConverters.parseMarkdownToBlocks(this.value);
|
||||||
|
|
||||||
|
if (parsedBlocks.length > 0) {
|
||||||
|
this.blocks = parsedBlocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
this.editorContentRef = this.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
this.editorContentRef = this.shadowRoot!.querySelector('.editor-content') as HTMLDivElement;
|
||||||
|
|
||||||
@@ -988,4 +999,4 @@ export class DeesInputWysiwyg extends DeesInputBase<string> {
|
|||||||
this.history.saveCheckpoint(this.blocks, this.selectedBlockId, cursorPosition);
|
this.history.saveCheckpoint(this.blocks, this.selectedBlockId, cursorPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,4 +15,4 @@ export * from './wysiwyg.modalmanager.js';
|
|||||||
export * from './wysiwyg.history.js';
|
export * from './wysiwyg.history.js';
|
||||||
export * from './dees-wysiwyg-block.js';
|
export * from './dees-wysiwyg-block.js';
|
||||||
export * from './dees-slash-menu.js';
|
export * from './dees-slash-menu.js';
|
||||||
export * from './dees-formatting-menu.js';
|
export * from './dees-formatting-menu.js';
|
@@ -11,6 +11,8 @@ export class WysiwygDragDropHandler {
|
|||||||
private initialBlockY: number = 0;
|
private initialBlockY: number = 0;
|
||||||
private draggedBlockElement: HTMLElement | null = null;
|
private draggedBlockElement: HTMLElement | null = null;
|
||||||
private draggedBlockHeight: number = 0;
|
private draggedBlockHeight: number = 0;
|
||||||
|
private draggedBlockContentHeight: number = 0;
|
||||||
|
private draggedBlockMarginTop: number = 0;
|
||||||
private lastUpdateTime: number = 0;
|
private lastUpdateTime: number = 0;
|
||||||
private updateThrottle: number = 80; // milliseconds
|
private updateThrottle: number = 80; // milliseconds
|
||||||
|
|
||||||
@@ -48,11 +50,33 @@ export class WysiwygDragDropHandler {
|
|||||||
this.initialMouseY = e.clientY;
|
this.initialMouseY = e.clientY;
|
||||||
this.draggedBlockElement = this.component.editorContentRef.querySelector(`[data-block-id="${block.id}"]`);
|
this.draggedBlockElement = this.component.editorContentRef.querySelector(`[data-block-id="${block.id}"]`);
|
||||||
|
|
||||||
|
|
||||||
if (this.draggedBlockElement) {
|
if (this.draggedBlockElement) {
|
||||||
|
// Get the wrapper rect for measurements
|
||||||
const rect = this.draggedBlockElement.getBoundingClientRect();
|
const rect = this.draggedBlockElement.getBoundingClientRect();
|
||||||
this.draggedBlockHeight = rect.height;
|
|
||||||
this.initialBlockY = rect.top;
|
this.initialBlockY = rect.top;
|
||||||
|
|
||||||
|
// Get the inner block element for proper measurements
|
||||||
|
const innerBlock = this.draggedBlockElement.querySelector('.block');
|
||||||
|
if (innerBlock) {
|
||||||
|
const innerRect = innerBlock.getBoundingClientRect();
|
||||||
|
const computedStyle = window.getComputedStyle(innerBlock);
|
||||||
|
this.draggedBlockMarginTop = parseInt(computedStyle.marginTop) || 0;
|
||||||
|
this.draggedBlockContentHeight = innerRect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The drop indicator should match the wrapper height exactly
|
||||||
|
// The wrapper already includes all the space the block occupies
|
||||||
|
this.draggedBlockHeight = rect.height;
|
||||||
|
|
||||||
|
console.log('Drag measurements:', {
|
||||||
|
wrapperHeight: rect.height,
|
||||||
|
marginTop: this.draggedBlockMarginTop,
|
||||||
|
dropIndicatorHeight: this.draggedBlockHeight,
|
||||||
|
contentHeight: this.draggedBlockContentHeight,
|
||||||
|
blockId: block.id
|
||||||
|
});
|
||||||
|
|
||||||
// Create drop indicator
|
// Create drop indicator
|
||||||
this.createDropIndicator();
|
this.createDropIndicator();
|
||||||
|
|
||||||
@@ -98,6 +122,8 @@ export class WysiwygDragDropHandler {
|
|||||||
this.dragOverPosition = null;
|
this.dragOverPosition = null;
|
||||||
this.draggedBlockElement = null;
|
this.draggedBlockElement = null;
|
||||||
this.draggedBlockHeight = 0;
|
this.draggedBlockHeight = 0;
|
||||||
|
this.draggedBlockContentHeight = 0;
|
||||||
|
this.draggedBlockMarginTop = 0;
|
||||||
this.initialBlockY = 0;
|
this.initialBlockY = 0;
|
||||||
|
|
||||||
// Update component state
|
// Update component state
|
||||||
@@ -284,34 +310,93 @@ export class WysiwygDragDropHandler {
|
|||||||
if (!this.dropIndicator || !this.draggedBlockElement) return;
|
if (!this.dropIndicator || !this.draggedBlockElement) return;
|
||||||
|
|
||||||
this.dropIndicator.style.display = 'block';
|
this.dropIndicator.style.display = 'block';
|
||||||
this.dropIndicator.style.height = `${this.draggedBlockHeight}px`;
|
|
||||||
|
|
||||||
const containerRect = this.component.editorContentRef.getBoundingClientRect();
|
const containerRect = this.component.editorContentRef.getBoundingClientRect();
|
||||||
// Calculate where the block will actually land
|
|
||||||
let topPosition = 0;
|
let topPosition = 0;
|
||||||
|
|
||||||
if (targetIndex === 0) {
|
// Build array of visual block positions (excluding dragged block)
|
||||||
// Before first block
|
const visualBlocks: { index: number, top: number, bottom: number }[] = [];
|
||||||
topPosition = 0;
|
|
||||||
} else {
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
// After a specific block
|
if (i === draggedIndex) continue; // Skip the dragged block
|
||||||
const prevIndex = targetIndex - 1;
|
|
||||||
let blockCount = 0;
|
|
||||||
|
|
||||||
// Find the visual position of the block that will be before our dropped block
|
const block = blocks[i];
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
const rect = block.getBoundingClientRect();
|
||||||
if (i === draggedIndex) continue; // Skip the dragged block
|
let top = rect.top - containerRect.top;
|
||||||
|
let bottom = rect.bottom - containerRect.top;
|
||||||
if (blockCount === prevIndex) {
|
|
||||||
const rect = blocks[i].getBoundingClientRect();
|
// Account for any transforms
|
||||||
topPosition = rect.bottom - containerRect.top + 16; // 16px gap
|
const transform = window.getComputedStyle(block).transform;
|
||||||
break;
|
if (transform && transform !== 'none') {
|
||||||
|
const matrix = new DOMMatrix(transform);
|
||||||
|
const yOffset = matrix.m42;
|
||||||
|
top += yOffset;
|
||||||
|
bottom += yOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
visualBlocks.push({ index: i, top, bottom });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by visual position
|
||||||
|
visualBlocks.sort((a, b) => a.top - b.top);
|
||||||
|
|
||||||
|
// Adjust targetIndex to account for excluded dragged block
|
||||||
|
let adjustedTargetIndex = targetIndex;
|
||||||
|
if (targetIndex > draggedIndex) {
|
||||||
|
adjustedTargetIndex--; // Reduce by 1 since dragged block is not in visualBlocks
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate drop position
|
||||||
|
// Get the margin that will be applied based on the dragged block type
|
||||||
|
let blockMargin = 16; // default margin
|
||||||
|
if (this.draggedBlockElement) {
|
||||||
|
const draggedBlock = this.component.blocks.find(b => b.id === this.draggedBlockId);
|
||||||
|
if (draggedBlock) {
|
||||||
|
const blockType = draggedBlock.type;
|
||||||
|
if (blockType === 'heading-1' || blockType === 'heading-2' || blockType === 'heading-3') {
|
||||||
|
blockMargin = 24;
|
||||||
|
} else if (blockType === 'code' || blockType === 'quote') {
|
||||||
|
blockMargin = 20;
|
||||||
}
|
}
|
||||||
blockCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dropIndicator.style.top = `${topPosition}px`;
|
if (adjustedTargetIndex === 0) {
|
||||||
|
// Insert at the very top - no margin needed for first block
|
||||||
|
topPosition = 0;
|
||||||
|
} else if (adjustedTargetIndex >= visualBlocks.length) {
|
||||||
|
// Insert at the end
|
||||||
|
const lastBlock = visualBlocks[visualBlocks.length - 1];
|
||||||
|
if (lastBlock) {
|
||||||
|
topPosition = lastBlock.bottom;
|
||||||
|
// Add margin that will be applied to the dropped block
|
||||||
|
topPosition += blockMargin;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Insert between blocks
|
||||||
|
const blockBefore = visualBlocks[adjustedTargetIndex - 1];
|
||||||
|
if (blockBefore) {
|
||||||
|
topPosition = blockBefore.bottom;
|
||||||
|
// Add margin that will be applied to the dropped block
|
||||||
|
topPosition += blockMargin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the indicator height to match the dragged block
|
||||||
|
this.dropIndicator.style.height = `${this.draggedBlockHeight}px`;
|
||||||
|
|
||||||
|
// Set position
|
||||||
|
this.dropIndicator.style.top = `${Math.max(0, topPosition)}px`;
|
||||||
|
|
||||||
|
console.log('Drop indicator update:', {
|
||||||
|
targetIndex,
|
||||||
|
adjustedTargetIndex,
|
||||||
|
draggedIndex,
|
||||||
|
topPosition,
|
||||||
|
height: this.draggedBlockHeight,
|
||||||
|
blockMargin,
|
||||||
|
visualBlocks: visualBlocks.map(b => ({ index: b.index, top: b.top, bottom: b.bottom }))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user