@designbasekorea/ui-wc 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/lottie-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2637aa0f.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,94 @@
|
|
|
1
|
-
const
|
|
1
|
+
const VARIANTS = ['text', 'circular', 'rectangular', 'rounded'];
|
|
2
|
+
const SIZES = ['xs', 's', 'm', 'l', 'xl'];
|
|
3
|
+
function getDefaultSize(variant, size) {
|
|
4
|
+
if (variant === 'circular') {
|
|
5
|
+
switch (size) {
|
|
6
|
+
case 'xs': return '16px';
|
|
7
|
+
case 's': return '24px';
|
|
8
|
+
case 'l': return '48px';
|
|
9
|
+
case 'xl': return '64px';
|
|
10
|
+
default: return '32px';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
switch (size) {
|
|
14
|
+
case 'xs': return '12px';
|
|
15
|
+
case 's': return '16px';
|
|
16
|
+
case 'l': return '24px';
|
|
17
|
+
case 'xl': return '32px';
|
|
18
|
+
default: return '20px';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function getTextLineHeight(size) {
|
|
22
|
+
switch (size) {
|
|
23
|
+
case 'xs': return '12px';
|
|
24
|
+
case 's': return '16px';
|
|
25
|
+
case 'l': return '24px';
|
|
26
|
+
case 'xl': return '32px';
|
|
27
|
+
default: return '20px';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function toCssSize(value) {
|
|
31
|
+
return /^\d+$/.test(value) ? `${value}px` : value;
|
|
32
|
+
}
|
|
33
|
+
class DbSkeleton extends HTMLElement {
|
|
34
|
+
static get observedAttributes() {
|
|
35
|
+
return ['variant', 'size', 'width', 'height', 'animation', 'lines', 'line-spacing', 'last-line-width', 'aria-label'];
|
|
36
|
+
}
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
attributeChangedCallback() {
|
|
41
|
+
if (!this.isConnected)
|
|
42
|
+
return;
|
|
43
|
+
this.render();
|
|
44
|
+
}
|
|
45
|
+
render() {
|
|
46
|
+
const variant = this.getAttribute('variant') || 'text';
|
|
47
|
+
const size = this.getAttribute('size') || 'm';
|
|
48
|
+
const animation = this.getAttribute('animation') || 'pulse';
|
|
49
|
+
const lines = Number(this.getAttribute('lines') || 1);
|
|
50
|
+
const width = this.getAttribute('width');
|
|
51
|
+
const height = this.getAttribute('height');
|
|
52
|
+
const lineSpacing = this.getAttribute('line-spacing') || '8px';
|
|
53
|
+
const lastLineWidth = this.getAttribute('last-line-width') || '60%';
|
|
54
|
+
const resolvedVariant = VARIANTS.includes(variant) ? variant : 'text';
|
|
55
|
+
const resolvedSize = SIZES.includes(size) ? size : 'm';
|
|
56
|
+
const nextClassName = [
|
|
57
|
+
'designbase-wc-skeleton',
|
|
58
|
+
`designbase-wc-skeleton--${resolvedVariant}`,
|
|
59
|
+
`designbase-wc-skeleton--${resolvedSize}`,
|
|
60
|
+
`designbase-wc-skeleton--${animation}`,
|
|
61
|
+
(width || height) && 'designbase-wc-skeleton--custom-size',
|
|
62
|
+
]
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join(' ');
|
|
65
|
+
if (this.className !== nextClassName) {
|
|
66
|
+
this.className = nextClassName;
|
|
67
|
+
}
|
|
68
|
+
const nextAriaLabel = this.getAttribute('aria-label') ?? `${resolvedVariant} 스켈레톤 로딩 중`;
|
|
69
|
+
if (this.getAttribute('aria-label') !== nextAriaLabel) {
|
|
70
|
+
this.setAttribute('aria-label', nextAriaLabel);
|
|
71
|
+
}
|
|
72
|
+
this.setAttribute('role', 'status');
|
|
73
|
+
this.setAttribute('aria-live', 'polite');
|
|
74
|
+
this.replaceChildren();
|
|
75
|
+
this.style.width = width ? toCssSize(width) : (resolvedVariant === 'circular' ? getDefaultSize(resolvedVariant, resolvedSize) : '100%');
|
|
76
|
+
this.style.height = height
|
|
77
|
+
? toCssSize(height)
|
|
78
|
+
: (resolvedVariant === 'circular' ? getDefaultSize(resolvedVariant, resolvedSize) : getTextLineHeight(resolvedSize));
|
|
79
|
+
if (resolvedVariant === 'text' && lines > 1) {
|
|
80
|
+
for (let index = 1; index < lines; index += 1) {
|
|
81
|
+
const line = document.createElement('div');
|
|
82
|
+
line.className = 'designbase-wc-skeleton__line';
|
|
83
|
+
line.style.marginTop = toCssSize(lineSpacing);
|
|
84
|
+
if (index === lines - 1)
|
|
85
|
+
line.style.width = toCssSize(lastLineWidth);
|
|
86
|
+
this.append(line);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!customElements.get('db-skeleton'))
|
|
92
|
+
customElements.define('db-skeleton', DbSkeleton);
|
|
93
|
+
|
|
94
|
+
export { DbSkeleton };
|
|
@@ -1 +1,102 @@
|
|
|
1
|
-
const
|
|
1
|
+
const TYPES = ['circular', 'dots', 'bars', 'pulse', 'ripple'];
|
|
2
|
+
const SIZES = ['xs', 's', 'm', 'l', 'xl'];
|
|
3
|
+
class DbSpinner extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['type', 'size', 'color', 'speed', 'label', 'show-label'];
|
|
6
|
+
}
|
|
7
|
+
get type() {
|
|
8
|
+
return this.getAttribute('type') || 'circular';
|
|
9
|
+
}
|
|
10
|
+
set type(value) {
|
|
11
|
+
this.setAttribute('type', value);
|
|
12
|
+
}
|
|
13
|
+
get size() {
|
|
14
|
+
return this.getAttribute('size') || 'm';
|
|
15
|
+
}
|
|
16
|
+
set size(value) {
|
|
17
|
+
this.setAttribute('size', value);
|
|
18
|
+
}
|
|
19
|
+
get color() {
|
|
20
|
+
return this.getAttribute('color') || '';
|
|
21
|
+
}
|
|
22
|
+
set color(value) {
|
|
23
|
+
if (value)
|
|
24
|
+
this.setAttribute('color', value);
|
|
25
|
+
else
|
|
26
|
+
this.removeAttribute('color');
|
|
27
|
+
}
|
|
28
|
+
get speed() {
|
|
29
|
+
return Number(this.getAttribute('speed') || 1);
|
|
30
|
+
}
|
|
31
|
+
set speed(value) {
|
|
32
|
+
this.setAttribute('speed', String(value));
|
|
33
|
+
}
|
|
34
|
+
get label() {
|
|
35
|
+
return this.getAttribute('label') || '로딩 중...';
|
|
36
|
+
}
|
|
37
|
+
set label(value) {
|
|
38
|
+
this.setAttribute('label', value);
|
|
39
|
+
}
|
|
40
|
+
get showLabel() {
|
|
41
|
+
return this.hasAttribute('show-label');
|
|
42
|
+
}
|
|
43
|
+
set showLabel(value) {
|
|
44
|
+
this.toggleAttribute('show-label', value);
|
|
45
|
+
}
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
this.render();
|
|
48
|
+
}
|
|
49
|
+
attributeChangedCallback() {
|
|
50
|
+
this.render();
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
this.className = Array.from(this.classList)
|
|
54
|
+
.filter((className) => !className.startsWith('designbase-wc-spinner'))
|
|
55
|
+
.join(' ');
|
|
56
|
+
this.classList.add('designbase-wc-spinner');
|
|
57
|
+
this.classList.add(`designbase-wc-spinner--${TYPES.includes(this.type) ? this.type : 'circular'}`);
|
|
58
|
+
this.classList.add(`designbase-wc-spinner--${SIZES.includes(this.size) ? this.size : 'm'}`);
|
|
59
|
+
this.setAttribute('role', 'status');
|
|
60
|
+
this.setAttribute('aria-live', 'polite');
|
|
61
|
+
this.setAttribute('aria-busy', 'true');
|
|
62
|
+
if (this.showLabel)
|
|
63
|
+
this.setAttribute('aria-label', this.label);
|
|
64
|
+
this.style.setProperty('--spinner-speed', `${this.speed}s`);
|
|
65
|
+
if (this.color)
|
|
66
|
+
this.style.setProperty('--spinner-color', this.color);
|
|
67
|
+
else
|
|
68
|
+
this.style.removeProperty('--spinner-color');
|
|
69
|
+
this.innerHTML = `${this.renderSpinner()}${this.showLabel && this.label
|
|
70
|
+
? `<span class="designbase-wc-spinner__label" aria-hidden="true">${this.escape(this.label)}</span>`
|
|
71
|
+
: ''}`;
|
|
72
|
+
}
|
|
73
|
+
renderSpinner() {
|
|
74
|
+
switch (this.type) {
|
|
75
|
+
case 'dots':
|
|
76
|
+
return '<span class="designbase-wc-spinner__dots" aria-hidden="true"><span class="designbase-wc-spinner__dot"></span><span class="designbase-wc-spinner__dot"></span><span class="designbase-wc-spinner__dot"></span></span>';
|
|
77
|
+
case 'bars':
|
|
78
|
+
return '<span class="designbase-wc-spinner__bars" aria-hidden="true"><span class="designbase-wc-spinner__bar"></span><span class="designbase-wc-spinner__bar"></span><span class="designbase-wc-spinner__bar"></span><span class="designbase-wc-spinner__bar"></span><span class="designbase-wc-spinner__bar"></span></span>';
|
|
79
|
+
case 'pulse':
|
|
80
|
+
return '<span class="designbase-wc-spinner__pulse" aria-hidden="true"></span>';
|
|
81
|
+
case 'ripple':
|
|
82
|
+
return '<span class="designbase-wc-spinner__ripple" aria-hidden="true"><span class="designbase-wc-spinner__ripple-circle"></span><span class="designbase-wc-spinner__ripple-circle"></span></span>';
|
|
83
|
+
case 'circular':
|
|
84
|
+
default:
|
|
85
|
+
return '<svg class="designbase-wc-spinner__circular" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><circle class="designbase-wc-spinner__circular-track" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" fill="none"></circle><circle class="designbase-wc-spinner__circular-indicator" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round"></circle></svg>';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
escape(value) {
|
|
89
|
+
return value.replace(/[&<>"']/g, (char) => ({
|
|
90
|
+
'&': '&',
|
|
91
|
+
'<': '<',
|
|
92
|
+
'>': '>',
|
|
93
|
+
'"': '"',
|
|
94
|
+
"'": ''',
|
|
95
|
+
}[char] || char));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!customElements.get('db-spinner')) {
|
|
99
|
+
customElements.define('db-spinner', DbSpinner);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { DbSpinner };
|
|
@@ -1 +1,297 @@
|
|
|
1
|
-
class DbSplitView extends HTMLElement
|
|
1
|
+
class DbSplitView extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(...arguments);
|
|
4
|
+
this.panelSizes = [];
|
|
5
|
+
this.draggingIndex = null;
|
|
6
|
+
this.panelSources = [];
|
|
7
|
+
this.isSyncing = false;
|
|
8
|
+
this.isObserving = false;
|
|
9
|
+
this.handleMouseDown = (index) => (event) => {
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
this.draggingIndex = index;
|
|
12
|
+
document.body.style.cursor = this.getDirection() === 'horizontal' ? 'col-resize' : 'row-resize';
|
|
13
|
+
document.body.style.userSelect = 'none';
|
|
14
|
+
};
|
|
15
|
+
this.handleMouseMove = (event) => {
|
|
16
|
+
if (this.draggingIndex === null)
|
|
17
|
+
return;
|
|
18
|
+
if (!this.panelSources.length)
|
|
19
|
+
return;
|
|
20
|
+
const direction = this.getDirection();
|
|
21
|
+
const mode = this.getMode();
|
|
22
|
+
const splitterSize = this.getSplitterSize();
|
|
23
|
+
const rect = this.getBoundingClientRect();
|
|
24
|
+
const panel = this.panelSources[this.draggingIndex];
|
|
25
|
+
if (!panel)
|
|
26
|
+
return;
|
|
27
|
+
const config = this.readPanelConfig(panel, this.draggingIndex, this.panelSources.length);
|
|
28
|
+
let newSize = this.panelSizes[this.draggingIndex];
|
|
29
|
+
if (direction === 'horizontal') {
|
|
30
|
+
const containerWidth = rect.width;
|
|
31
|
+
const mouseX = event.clientX - rect.left;
|
|
32
|
+
let offsetX = 0;
|
|
33
|
+
for (let i = 0; i < this.draggingIndex; i++) {
|
|
34
|
+
const size = this.panelSizes[i];
|
|
35
|
+
offsetX += mode === 'fixed' ? size : size * containerWidth;
|
|
36
|
+
offsetX += splitterSize;
|
|
37
|
+
}
|
|
38
|
+
const rawSize = mouseX - offsetX;
|
|
39
|
+
if (mode === 'fixed') {
|
|
40
|
+
newSize = Math.max(config.minSize || 0, Math.min(config.maxSize || containerWidth, rawSize));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
newSize = rawSize / containerWidth;
|
|
44
|
+
const minSplit = config.minSize ? config.minSize / containerWidth : 0;
|
|
45
|
+
const maxSplit = config.maxSize ? config.maxSize / containerWidth : 1;
|
|
46
|
+
newSize = Math.max(minSplit, Math.min(maxSplit, newSize));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const containerHeight = rect.height;
|
|
51
|
+
const mouseY = event.clientY - rect.top;
|
|
52
|
+
let offsetY = 0;
|
|
53
|
+
for (let i = 0; i < this.draggingIndex; i++) {
|
|
54
|
+
const size = this.panelSizes[i];
|
|
55
|
+
offsetY += mode === 'fixed' ? size : size * containerHeight;
|
|
56
|
+
offsetY += splitterSize;
|
|
57
|
+
}
|
|
58
|
+
const rawSize = mouseY - offsetY;
|
|
59
|
+
if (mode === 'fixed') {
|
|
60
|
+
newSize = Math.max(config.minSize || 0, Math.min(config.maxSize || containerHeight, rawSize));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
newSize = rawSize / containerHeight;
|
|
64
|
+
const minSplit = config.minSize ? config.minSize / containerHeight : 0;
|
|
65
|
+
const maxSplit = config.maxSize ? config.maxSize / containerHeight : 1;
|
|
66
|
+
newSize = Math.max(minSplit, Math.min(maxSplit, newSize));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this.panelSizes[this.draggingIndex] = newSize;
|
|
70
|
+
this.applyPanelSizes();
|
|
71
|
+
this.classList.toggle('designbase-wc-split-view--dragging', true);
|
|
72
|
+
};
|
|
73
|
+
this.handleMouseUp = () => {
|
|
74
|
+
if (this.draggingIndex === null)
|
|
75
|
+
return;
|
|
76
|
+
this.draggingIndex = null;
|
|
77
|
+
document.body.style.cursor = '';
|
|
78
|
+
document.body.style.userSelect = '';
|
|
79
|
+
this.classList.toggle('designbase-wc-split-view--dragging', false);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
static get observedAttributes() {
|
|
83
|
+
return ['direction', 'mode', 'splitter-size', 'splitter-color', 'splitter-hover-color', 'gap', 'full-width', 'full-height'];
|
|
84
|
+
}
|
|
85
|
+
connectedCallback() {
|
|
86
|
+
this.style.display = 'flex';
|
|
87
|
+
this.style.boxSizing = 'border-box';
|
|
88
|
+
this.collectPanelSources();
|
|
89
|
+
this.initPanelSizes();
|
|
90
|
+
this.sync();
|
|
91
|
+
this.observer = new MutationObserver(() => {
|
|
92
|
+
if (this.isSyncing)
|
|
93
|
+
return;
|
|
94
|
+
this.collectPanelSources();
|
|
95
|
+
this.initPanelSizes();
|
|
96
|
+
this.sync();
|
|
97
|
+
});
|
|
98
|
+
this.startObserving();
|
|
99
|
+
document.addEventListener('mousemove', this.handleMouseMove);
|
|
100
|
+
document.addEventListener('mouseup', this.handleMouseUp);
|
|
101
|
+
}
|
|
102
|
+
disconnectedCallback() {
|
|
103
|
+
this.stopObserving();
|
|
104
|
+
document.removeEventListener('mousemove', this.handleMouseMove);
|
|
105
|
+
document.removeEventListener('mouseup', this.handleMouseUp);
|
|
106
|
+
this.draggingIndex = null;
|
|
107
|
+
document.body.style.cursor = '';
|
|
108
|
+
document.body.style.userSelect = '';
|
|
109
|
+
}
|
|
110
|
+
startObserving() {
|
|
111
|
+
if (!this.observer || this.isObserving)
|
|
112
|
+
return;
|
|
113
|
+
this.observer.observe(this, { childList: true });
|
|
114
|
+
this.isObserving = true;
|
|
115
|
+
}
|
|
116
|
+
stopObserving() {
|
|
117
|
+
if (!this.observer || !this.isObserving)
|
|
118
|
+
return;
|
|
119
|
+
this.observer.disconnect();
|
|
120
|
+
this.isObserving = false;
|
|
121
|
+
}
|
|
122
|
+
attributeChangedCallback() {
|
|
123
|
+
if (this.isConnected)
|
|
124
|
+
this.sync();
|
|
125
|
+
}
|
|
126
|
+
collectPanelSources() {
|
|
127
|
+
this.panelSources = [];
|
|
128
|
+
// Keep tracking original panel nodes even after wrapping.
|
|
129
|
+
const slotted = Array.from(this.querySelectorAll('[slot="panel"]'));
|
|
130
|
+
if (slotted.length) {
|
|
131
|
+
this.panelSources = slotted;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const wrapped = Array.from(this.querySelectorAll(':scope > .designbase-wc-split-view__panel > .designbase-wc-split-view__panel-body'));
|
|
135
|
+
if (wrapped.length) {
|
|
136
|
+
this.panelSources = wrapped
|
|
137
|
+
.map((body) => body.firstElementChild)
|
|
138
|
+
.filter((node) => node instanceof HTMLElement);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
readPanelConfig(element, index, total) {
|
|
142
|
+
const sizeAttr = element.getAttribute('data-size');
|
|
143
|
+
const minSizeAttr = element.getAttribute('data-min-size');
|
|
144
|
+
const maxSizeAttr = element.getAttribute('data-max-size');
|
|
145
|
+
const mode = this.getMode();
|
|
146
|
+
let size;
|
|
147
|
+
if (sizeAttr != null && sizeAttr !== '') {
|
|
148
|
+
size = Number(sizeAttr);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
size: size !== undefined && Number.isFinite(size)
|
|
152
|
+
? size
|
|
153
|
+
: mode === 'ratio'
|
|
154
|
+
? 1 / total
|
|
155
|
+
: 200,
|
|
156
|
+
minSize: minSizeAttr ? Number(minSizeAttr) : undefined,
|
|
157
|
+
maxSize: maxSizeAttr ? Number(maxSizeAttr) : undefined,
|
|
158
|
+
resizable: element.getAttribute('data-resizable') !== 'false',
|
|
159
|
+
flexible: element.hasAttribute('data-flexible') ||
|
|
160
|
+
(element.getAttribute('data-flexible') !== 'false' && index === total - 1),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
initPanelSizes() {
|
|
164
|
+
const total = this.panelSources.length;
|
|
165
|
+
if (!total)
|
|
166
|
+
return;
|
|
167
|
+
if (this.panelSizes.length === total)
|
|
168
|
+
return;
|
|
169
|
+
const mode = this.getMode();
|
|
170
|
+
this.panelSizes = this.panelSources.map((panel, index) => {
|
|
171
|
+
const config = this.readPanelConfig(panel, index, total);
|
|
172
|
+
return config.size ?? (mode === 'ratio' ? 1 / total : 200);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getDirection() {
|
|
176
|
+
const value = this.getAttribute('direction') || 'horizontal';
|
|
177
|
+
return value === 'vertical' ? 'vertical' : 'horizontal';
|
|
178
|
+
}
|
|
179
|
+
getMode() {
|
|
180
|
+
const value = this.getAttribute('mode') || 'ratio';
|
|
181
|
+
return value === 'fixed' ? 'fixed' : 'ratio';
|
|
182
|
+
}
|
|
183
|
+
getSplitterSize() {
|
|
184
|
+
return Number(this.getAttribute('splitter-size') || 4);
|
|
185
|
+
}
|
|
186
|
+
getGap() {
|
|
187
|
+
return Number(this.getAttribute('gap') || 0);
|
|
188
|
+
}
|
|
189
|
+
applyPanelSizes() {
|
|
190
|
+
if (!this.panelSources.length)
|
|
191
|
+
return;
|
|
192
|
+
const direction = this.getDirection();
|
|
193
|
+
const mode = this.getMode();
|
|
194
|
+
const panels = Array.from(this.querySelectorAll(':scope > .designbase-wc-split-view__panel'));
|
|
195
|
+
panels.forEach((panelEl, index) => {
|
|
196
|
+
const source = this.panelSources[index];
|
|
197
|
+
if (!source)
|
|
198
|
+
return;
|
|
199
|
+
const config = this.readPanelConfig(source, index, this.panelSources.length);
|
|
200
|
+
const size = this.panelSizes[index];
|
|
201
|
+
const isFlexible = config.flexible;
|
|
202
|
+
panelEl.style.width = '';
|
|
203
|
+
panelEl.style.height = '';
|
|
204
|
+
panelEl.style.flexBasis = '';
|
|
205
|
+
panelEl.style.flexGrow = '';
|
|
206
|
+
panelEl.style.flexShrink = '';
|
|
207
|
+
panelEl.style.minHeight = '';
|
|
208
|
+
panelEl.style.minWidth = '';
|
|
209
|
+
if (isFlexible) {
|
|
210
|
+
panelEl.style.flex = '1 1 0';
|
|
211
|
+
if (direction === 'vertical')
|
|
212
|
+
panelEl.style.minHeight = '0';
|
|
213
|
+
else
|
|
214
|
+
panelEl.style.minWidth = '0';
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const basis = mode === 'fixed' ? `${size}px` : `${size * 100}%`;
|
|
218
|
+
panelEl.style.flex = `0 0 ${basis}`;
|
|
219
|
+
}
|
|
220
|
+
panelEl.classList.toggle('designbase-wc-split-view__panel--flexible', Boolean(isFlexible));
|
|
221
|
+
panelEl.classList.toggle('designbase-wc-split-view__panel--fixed', !isFlexible);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
sync() {
|
|
225
|
+
this.isSyncing = true;
|
|
226
|
+
this.stopObserving();
|
|
227
|
+
this.collectPanelSources();
|
|
228
|
+
this.initPanelSizes();
|
|
229
|
+
if (!this.panelSources.length) {
|
|
230
|
+
this.isSyncing = false;
|
|
231
|
+
this.startObserving();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const direction = this.getDirection();
|
|
235
|
+
const mode = this.getMode();
|
|
236
|
+
const gap = this.getGap();
|
|
237
|
+
const splitterSize = this.getSplitterSize();
|
|
238
|
+
const splitterColor = this.getAttribute('splitter-color');
|
|
239
|
+
const splitterHoverColor = this.getAttribute('splitter-hover-color');
|
|
240
|
+
this.className = [
|
|
241
|
+
'designbase-wc-split-view',
|
|
242
|
+
`designbase-wc-split-view--direction-${direction}`,
|
|
243
|
+
`designbase-wc-split-view--mode-${mode}`,
|
|
244
|
+
this.hasAttribute('full-width') && 'designbase-wc-split-view--full-width',
|
|
245
|
+
this.hasAttribute('full-height') && 'designbase-wc-split-view--full-height',
|
|
246
|
+
this.draggingIndex !== null && 'designbase-wc-split-view--dragging',
|
|
247
|
+
]
|
|
248
|
+
.filter(Boolean)
|
|
249
|
+
.join(' ');
|
|
250
|
+
this.style.setProperty('--splitter-size', `${splitterSize}px`);
|
|
251
|
+
if (splitterColor)
|
|
252
|
+
this.style.setProperty('--splitter-color', splitterColor);
|
|
253
|
+
else
|
|
254
|
+
this.style.removeProperty('--splitter-color');
|
|
255
|
+
if (splitterHoverColor)
|
|
256
|
+
this.style.setProperty('--splitter-hover-color', splitterHoverColor);
|
|
257
|
+
else
|
|
258
|
+
this.style.removeProperty('--splitter-hover-color');
|
|
259
|
+
if (gap > 0)
|
|
260
|
+
this.style.gap = `${gap}px`;
|
|
261
|
+
else
|
|
262
|
+
this.style.gap = '';
|
|
263
|
+
const existingPanels = Array.from(this.querySelectorAll(':scope > .designbase-wc-split-view__panel'));
|
|
264
|
+
const existingSplitters = Array.from(this.querySelectorAll(':scope > .designbase-wc-split-view__splitter'));
|
|
265
|
+
existingPanels.forEach((node) => node.remove());
|
|
266
|
+
existingSplitters.forEach((node) => node.remove());
|
|
267
|
+
this.panelSources.forEach((source, index) => {
|
|
268
|
+
const config = this.readPanelConfig(source, index, this.panelSources.length);
|
|
269
|
+
const isLast = index === this.panelSources.length - 1;
|
|
270
|
+
const isResizable = config.resizable !== false && !isLast;
|
|
271
|
+
const panelEl = document.createElement('div');
|
|
272
|
+
panelEl.className = 'designbase-wc-split-view__panel';
|
|
273
|
+
const body = document.createElement('div');
|
|
274
|
+
body.className = 'designbase-wc-split-view__panel-body';
|
|
275
|
+
if (source.parentElement !== body) {
|
|
276
|
+
body.append(source);
|
|
277
|
+
}
|
|
278
|
+
panelEl.append(body);
|
|
279
|
+
this.append(panelEl);
|
|
280
|
+
if (!isLast && isResizable && gap === 0) {
|
|
281
|
+
const splitter = document.createElement('div');
|
|
282
|
+
splitter.className = `designbase-wc-split-view__splitter designbase-wc-split-view__splitter--direction-${direction}`;
|
|
283
|
+
splitter.style.cursor = direction === 'horizontal' ? 'col-resize' : 'row-resize';
|
|
284
|
+
splitter.addEventListener('mousedown', this.handleMouseDown(index));
|
|
285
|
+
this.append(splitter);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
this.applyPanelSizes();
|
|
289
|
+
this.isSyncing = false;
|
|
290
|
+
this.startObserving();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (!customElements.get('db-split-view')) {
|
|
294
|
+
customElements.define('db-split-view', DbSplitView);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { DbSplitView };
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
const
|
|
1
|
+
const DIRECTIONS = ['vertical', 'horizontal'];
|
|
2
|
+
const ALIGNMENTS = ['start', 'center', 'end', 'stretch'];
|
|
3
|
+
const JUSTIFY = ['start', 'center', 'end', 'space-between', 'space-around', 'space-evenly'];
|
|
4
|
+
const SPACINGS = ['none', 'xs', 's', 'm', 'l', 'xl'];
|
|
5
|
+
class DbStack extends HTMLElement {
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['direction', 'alignment', 'justify', 'spacing', 'full-width', 'full-height', 'wrap'];
|
|
8
|
+
}
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
this.syncClasses();
|
|
11
|
+
}
|
|
12
|
+
attributeChangedCallback() {
|
|
13
|
+
this.syncClasses();
|
|
14
|
+
}
|
|
15
|
+
syncClasses() {
|
|
16
|
+
const direction = this.getAttribute('direction') || 'vertical';
|
|
17
|
+
const alignment = this.getAttribute('alignment') || 'start';
|
|
18
|
+
const justify = this.getAttribute('justify') || 'start';
|
|
19
|
+
const spacing = this.getAttribute('spacing') || 'm';
|
|
20
|
+
const spacingAlias = {
|
|
21
|
+
none: 'none',
|
|
22
|
+
xs: 'xs',
|
|
23
|
+
s: 'sm',
|
|
24
|
+
m: 'md',
|
|
25
|
+
l: 'lg',
|
|
26
|
+
xl: 'xl',
|
|
27
|
+
};
|
|
28
|
+
const safeSpacing = SPACINGS.includes(spacing) ? spacing : 'm';
|
|
29
|
+
this.className = [
|
|
30
|
+
'designbase-wc-stack',
|
|
31
|
+
`designbase-wc-stack--direction-${DIRECTIONS.includes(direction) ? direction : 'vertical'}`,
|
|
32
|
+
`designbase-wc-stack--alignment-${ALIGNMENTS.includes(alignment) ? alignment : 'start'}`,
|
|
33
|
+
`designbase-wc-stack--justify-${JUSTIFY.includes(justify) ? justify : 'start'}`,
|
|
34
|
+
`designbase-wc-stack--spacing-${spacingAlias[safeSpacing] || 'md'}`,
|
|
35
|
+
this.hasAttribute('full-width') && 'designbase-wc-stack--full-width',
|
|
36
|
+
this.hasAttribute('full-height') && 'designbase-wc-stack--full-height',
|
|
37
|
+
this.hasAttribute('wrap') && 'designbase-wc-stack--wrap',
|
|
38
|
+
]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(' ');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!customElements.get('db-stack'))
|
|
44
|
+
customElements.define('db-stack', DbStack);
|
|
45
|
+
|
|
46
|
+
export { DbStack };
|