@designbasekorea/ui-wc 0.5.3 → 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.d.ts +1 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2d1f6278.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,191 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
class DbConfirm extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.root = null;
|
|
7
|
+
this.keyHandler = null;
|
|
8
|
+
}
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return [
|
|
11
|
+
'open',
|
|
12
|
+
'title',
|
|
13
|
+
'message',
|
|
14
|
+
'confirm-text',
|
|
15
|
+
'cancel-text',
|
|
16
|
+
'confirm-variant',
|
|
17
|
+
'variant',
|
|
18
|
+
'size',
|
|
19
|
+
'show-icon',
|
|
20
|
+
'initial-focus',
|
|
21
|
+
'confirm-disabled',
|
|
22
|
+
'cancel-disabled',
|
|
23
|
+
'close-on-escape',
|
|
24
|
+
'close-on-backdrop',
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
connectedCallback() {
|
|
28
|
+
this.render();
|
|
29
|
+
}
|
|
30
|
+
disconnectedCallback() {
|
|
31
|
+
this.detachEscape();
|
|
32
|
+
document.body.style.overflow = '';
|
|
33
|
+
this.root?.remove();
|
|
34
|
+
this.root = null;
|
|
35
|
+
}
|
|
36
|
+
attributeChangedCallback() {
|
|
37
|
+
this.render();
|
|
38
|
+
}
|
|
39
|
+
isOpen() {
|
|
40
|
+
return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
|
|
41
|
+
}
|
|
42
|
+
attachEscape() {
|
|
43
|
+
if (this.keyHandler)
|
|
44
|
+
return;
|
|
45
|
+
this.keyHandler = (event) => {
|
|
46
|
+
if (event.key !== 'Escape')
|
|
47
|
+
return;
|
|
48
|
+
if (this.getAttribute('close-on-escape') === 'false')
|
|
49
|
+
return;
|
|
50
|
+
this.dispatchCancel();
|
|
51
|
+
};
|
|
52
|
+
document.addEventListener('keydown', this.keyHandler);
|
|
53
|
+
}
|
|
54
|
+
detachEscape() {
|
|
55
|
+
if (!this.keyHandler)
|
|
56
|
+
return;
|
|
57
|
+
document.removeEventListener('keydown', this.keyHandler);
|
|
58
|
+
this.keyHandler = null;
|
|
59
|
+
}
|
|
60
|
+
dispatchCancel() {
|
|
61
|
+
this.setAttribute('open', 'false');
|
|
62
|
+
this.dispatchEvent(new CustomEvent('db-cancel', { bubbles: true, composed: true }));
|
|
63
|
+
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
64
|
+
}
|
|
65
|
+
dispatchConfirm() {
|
|
66
|
+
this.setAttribute('open', 'false');
|
|
67
|
+
this.dispatchEvent(new CustomEvent('db-confirm', { bubbles: true, composed: true }));
|
|
68
|
+
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
69
|
+
}
|
|
70
|
+
iconForVariant(variant) {
|
|
71
|
+
if (variant === 'success')
|
|
72
|
+
return 'award';
|
|
73
|
+
if (variant === 'warning')
|
|
74
|
+
return 'bell-active';
|
|
75
|
+
if (variant === 'danger')
|
|
76
|
+
return 'cloud-close';
|
|
77
|
+
return 'bulb';
|
|
78
|
+
}
|
|
79
|
+
iconSize(size) {
|
|
80
|
+
if (size === 's')
|
|
81
|
+
return 20;
|
|
82
|
+
if (size === 'l')
|
|
83
|
+
return 32;
|
|
84
|
+
return 24;
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
this.root?.remove();
|
|
88
|
+
this.root = null;
|
|
89
|
+
this.detachEscape();
|
|
90
|
+
if (!this.isOpen()) {
|
|
91
|
+
document.body.style.overflow = '';
|
|
92
|
+
this.replaceChildren();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
document.body.style.overflow = 'hidden';
|
|
96
|
+
this.attachEscape();
|
|
97
|
+
const title = this.getAttribute('title') || '';
|
|
98
|
+
const message = this.getAttribute('message') || this.textContent?.trim() || '';
|
|
99
|
+
const confirmText = this.getAttribute('confirm-text') || '확인';
|
|
100
|
+
const cancelText = this.getAttribute('cancel-text') || '취소';
|
|
101
|
+
const confirmVariant = this.getAttribute('confirm-variant') || 'primary';
|
|
102
|
+
const variant = this.getAttribute('variant') || 'info';
|
|
103
|
+
const size = this.getAttribute('size') || 's';
|
|
104
|
+
const showIcon = this.getAttribute('show-icon') !== 'false';
|
|
105
|
+
const initialFocus = this.getAttribute('initial-focus') || 'confirm';
|
|
106
|
+
const confirmDisabled = this.getAttribute('confirm-disabled') === 'true';
|
|
107
|
+
const cancelDisabled = this.getAttribute('cancel-disabled') === 'true';
|
|
108
|
+
const overlay = document.createElement('div');
|
|
109
|
+
overlay.className = 'designbase-wc-confirm__overlay';
|
|
110
|
+
overlay.setAttribute('role', 'dialog');
|
|
111
|
+
overlay.setAttribute('aria-modal', 'true');
|
|
112
|
+
if (title)
|
|
113
|
+
overlay.setAttribute('aria-labelledby', 'confirm-title');
|
|
114
|
+
overlay.setAttribute('aria-describedby', 'confirm-content');
|
|
115
|
+
overlay.addEventListener('click', (event) => {
|
|
116
|
+
if (event.target !== overlay)
|
|
117
|
+
return;
|
|
118
|
+
if (this.getAttribute('close-on-backdrop') === 'false')
|
|
119
|
+
return;
|
|
120
|
+
this.dispatchCancel();
|
|
121
|
+
});
|
|
122
|
+
const modal = document.createElement('div');
|
|
123
|
+
modal.className = [
|
|
124
|
+
'designbase-wc-confirm__modal',
|
|
125
|
+
`designbase-wc-confirm__modal--${variant}`,
|
|
126
|
+
`designbase-wc-confirm__modal--${size}`,
|
|
127
|
+
!showIcon && 'designbase-wc-confirm__modal--no-icon',
|
|
128
|
+
]
|
|
129
|
+
.filter(Boolean)
|
|
130
|
+
.join(' ');
|
|
131
|
+
const header = document.createElement('div');
|
|
132
|
+
header.className = [
|
|
133
|
+
'designbase-wc-confirm__header',
|
|
134
|
+
!showIcon && 'designbase-wc-confirm__header--no-icon',
|
|
135
|
+
]
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.join(' ');
|
|
138
|
+
if (showIcon) {
|
|
139
|
+
const icon = document.createElement('div');
|
|
140
|
+
icon.className = 'designbase-wc-confirm__icon';
|
|
141
|
+
icon.append(createDbIcon(this.iconForVariant(variant), this.iconSize(size)));
|
|
142
|
+
header.append(icon);
|
|
143
|
+
}
|
|
144
|
+
const titleArea = document.createElement('div');
|
|
145
|
+
titleArea.className = 'designbase-wc-confirm__title-area';
|
|
146
|
+
if (title) {
|
|
147
|
+
const heading = document.createElement('h2');
|
|
148
|
+
heading.id = 'confirm-title';
|
|
149
|
+
heading.className = 'designbase-wc-confirm__title';
|
|
150
|
+
heading.textContent = title;
|
|
151
|
+
titleArea.append(heading);
|
|
152
|
+
}
|
|
153
|
+
header.append(titleArea);
|
|
154
|
+
modal.append(header);
|
|
155
|
+
const content = document.createElement('div');
|
|
156
|
+
content.id = 'confirm-content';
|
|
157
|
+
content.className = 'designbase-wc-confirm__content';
|
|
158
|
+
content.textContent = message;
|
|
159
|
+
modal.append(content);
|
|
160
|
+
const footer = document.createElement('div');
|
|
161
|
+
footer.className = 'designbase-wc-confirm__footer';
|
|
162
|
+
const cancel = document.createElement('db-button');
|
|
163
|
+
cancel.setAttribute('variant', 'tertiary');
|
|
164
|
+
cancel.setAttribute('full-width', '');
|
|
165
|
+
cancel.textContent = cancelText;
|
|
166
|
+
if (cancelDisabled)
|
|
167
|
+
cancel.setAttribute('disabled', '');
|
|
168
|
+
cancel.addEventListener('db-click', () => this.dispatchCancel());
|
|
169
|
+
const confirm = document.createElement('db-button');
|
|
170
|
+
confirm.setAttribute('variant', confirmVariant);
|
|
171
|
+
confirm.setAttribute('full-width', '');
|
|
172
|
+
confirm.textContent = confirmText;
|
|
173
|
+
if (confirmDisabled)
|
|
174
|
+
confirm.setAttribute('disabled', '');
|
|
175
|
+
confirm.addEventListener('db-click', () => this.dispatchConfirm());
|
|
176
|
+
footer.append(cancel, confirm);
|
|
177
|
+
modal.append(footer);
|
|
178
|
+
overlay.append(modal);
|
|
179
|
+
document.body.append(overlay);
|
|
180
|
+
this.root = overlay;
|
|
181
|
+
requestAnimationFrame(() => {
|
|
182
|
+
const focusTarget = initialFocus === 'cancel' ? cancel : confirm;
|
|
183
|
+
focusTarget.focus();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!customElements.get('db-confirm')) {
|
|
188
|
+
customElements.define('db-confirm', DbConfirm);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { DbConfirm };
|
|
@@ -1 +1,39 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SIZES = ['s', 'm', 'l', 'xl', 'full'];
|
|
2
|
+
const PADDINGS = ['none', 's', 'm', 'l', 'xl'];
|
|
3
|
+
class DbContainer extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['size', 'padding', 'max-width', 'full-width'];
|
|
6
|
+
}
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
this.syncClasses();
|
|
9
|
+
}
|
|
10
|
+
attributeChangedCallback() {
|
|
11
|
+
this.syncClasses();
|
|
12
|
+
}
|
|
13
|
+
syncClasses() {
|
|
14
|
+
const size = this.getAttribute('size') || 'l';
|
|
15
|
+
const padding = this.getAttribute('padding') || 'm';
|
|
16
|
+
const maxWidth = this.getAttribute('max-width');
|
|
17
|
+
this.className = [
|
|
18
|
+
'designbase-wc-container',
|
|
19
|
+
`designbase-wc-container--size-${SIZES.includes(size) ? size : 'l'}`,
|
|
20
|
+
PADDINGS.includes(padding) && `designbase-wc-container--padding-${padding}`,
|
|
21
|
+
this.hasAttribute('full-width') && 'designbase-wc-container--full-width',
|
|
22
|
+
]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(' ');
|
|
25
|
+
if (this.hasAttribute('full-width')) {
|
|
26
|
+
this.style.maxWidth = '100%';
|
|
27
|
+
}
|
|
28
|
+
else if (maxWidth) {
|
|
29
|
+
this.style.maxWidth = maxWidth.includes('px') || maxWidth.includes('%') ? maxWidth : `${maxWidth}px`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.style.removeProperty('max-width');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!customElements.get('db-container'))
|
|
37
|
+
customElements.define('db-container', DbContainer);
|
|
38
|
+
|
|
39
|
+
export { DbContainer };
|
|
@@ -1 +1,265 @@
|
|
|
1
|
-
class DbContextMenu extends HTMLElement
|
|
1
|
+
class DbContextMenu extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(...arguments);
|
|
4
|
+
this.externalTarget = null;
|
|
5
|
+
this.activeSubMenu = null;
|
|
6
|
+
this.onExternalContextMenu = null;
|
|
7
|
+
this.handleDocumentMouseDown = (event) => {
|
|
8
|
+
if (!this.open)
|
|
9
|
+
return;
|
|
10
|
+
const target = event.target;
|
|
11
|
+
if (this.menuEl?.contains(target))
|
|
12
|
+
return;
|
|
13
|
+
// 트리거 영역 안이라도 좌클릭(또는 우클릭 외 버튼)이면 닫는다.
|
|
14
|
+
// 우클릭(button 2)만 재오픈/위치이동을 위해 닫지 않고 넘긴다.
|
|
15
|
+
if (event.button === 2 && (this.targetWrap?.contains(target) || this.externalTarget?.contains(target))) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this.close();
|
|
19
|
+
};
|
|
20
|
+
this.handleKeyDown = (event) => {
|
|
21
|
+
if (!this.open)
|
|
22
|
+
return;
|
|
23
|
+
if (event.key === 'Escape')
|
|
24
|
+
this.close();
|
|
25
|
+
};
|
|
26
|
+
this.handleContextMenu = (event) => {
|
|
27
|
+
if (this.hasAttribute('disabled'))
|
|
28
|
+
return;
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
this.openAt(event.clientX, event.clientY);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
static get observedAttributes() {
|
|
35
|
+
return ['open', 'x', 'y', 'items', 'target-id', 'disabled'];
|
|
36
|
+
}
|
|
37
|
+
get open() {
|
|
38
|
+
return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
|
|
39
|
+
}
|
|
40
|
+
set open(value) {
|
|
41
|
+
if (value)
|
|
42
|
+
this.setAttribute('open', 'true');
|
|
43
|
+
else
|
|
44
|
+
this.removeAttribute('open');
|
|
45
|
+
}
|
|
46
|
+
get items() {
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(this.getAttribute('items') || '[]');
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
set items(value) {
|
|
55
|
+
this.setAttribute('items', typeof value === 'string' ? value : JSON.stringify(value));
|
|
56
|
+
}
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
this.style.display = 'contents';
|
|
59
|
+
requestAnimationFrame(() => {
|
|
60
|
+
this.renderTarget();
|
|
61
|
+
this.syncMenu();
|
|
62
|
+
});
|
|
63
|
+
document.addEventListener('mousedown', this.handleDocumentMouseDown);
|
|
64
|
+
document.addEventListener('keydown', this.handleKeyDown);
|
|
65
|
+
}
|
|
66
|
+
disconnectedCallback() {
|
|
67
|
+
document.removeEventListener('mousedown', this.handleDocumentMouseDown);
|
|
68
|
+
document.removeEventListener('keydown', this.handleKeyDown);
|
|
69
|
+
this.unbindExternalTarget();
|
|
70
|
+
this.menuEl?.remove();
|
|
71
|
+
this.menuEl = undefined;
|
|
72
|
+
}
|
|
73
|
+
attributeChangedCallback(name) {
|
|
74
|
+
if (!this.isConnected)
|
|
75
|
+
return;
|
|
76
|
+
if (name === 'target-id') {
|
|
77
|
+
this.unbindExternalTarget();
|
|
78
|
+
this.bindExternalTarget();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (name === 'open' || name === 'x' || name === 'y' || name === 'items') {
|
|
82
|
+
this.syncMenu();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
openAt(x, y) {
|
|
86
|
+
this.setAttribute('x', String(x));
|
|
87
|
+
this.setAttribute('y', String(y));
|
|
88
|
+
this.setAttribute('open', 'true');
|
|
89
|
+
this.dispatchEvent(new CustomEvent('db-open', {
|
|
90
|
+
bubbles: true,
|
|
91
|
+
composed: true,
|
|
92
|
+
detail: { x, y },
|
|
93
|
+
}));
|
|
94
|
+
this.syncMenu();
|
|
95
|
+
}
|
|
96
|
+
close() {
|
|
97
|
+
this.activeSubMenu = null;
|
|
98
|
+
this.removeAttribute('open');
|
|
99
|
+
this.menuEl?.remove();
|
|
100
|
+
this.menuEl = undefined;
|
|
101
|
+
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
102
|
+
}
|
|
103
|
+
collectTargetChildren() {
|
|
104
|
+
const fromHost = Array.from(this.children).filter((child) => !child.hasAttribute('data-wc-internal') && child !== this.targetWrap);
|
|
105
|
+
if (fromHost.length > 0)
|
|
106
|
+
return fromHost;
|
|
107
|
+
return Array.from(this.targetWrap?.children || []);
|
|
108
|
+
}
|
|
109
|
+
bindExternalTarget() {
|
|
110
|
+
const targetId = this.getAttribute('target-id');
|
|
111
|
+
if (!targetId)
|
|
112
|
+
return;
|
|
113
|
+
this.externalTarget = document.getElementById(targetId);
|
|
114
|
+
if (!this.externalTarget)
|
|
115
|
+
return;
|
|
116
|
+
this.onExternalContextMenu = (event) => this.handleContextMenu(event);
|
|
117
|
+
this.externalTarget.addEventListener('contextmenu', this.onExternalContextMenu);
|
|
118
|
+
}
|
|
119
|
+
unbindExternalTarget() {
|
|
120
|
+
if (this.externalTarget && this.onExternalContextMenu) {
|
|
121
|
+
this.externalTarget.removeEventListener('contextmenu', this.onExternalContextMenu);
|
|
122
|
+
}
|
|
123
|
+
this.externalTarget = null;
|
|
124
|
+
this.onExternalContextMenu = null;
|
|
125
|
+
}
|
|
126
|
+
renderTarget() {
|
|
127
|
+
const targetChildren = this.collectTargetChildren();
|
|
128
|
+
const targetId = this.getAttribute('target-id');
|
|
129
|
+
if (!targetId) {
|
|
130
|
+
if (!this.targetWrap) {
|
|
131
|
+
this.targetWrap = document.createElement('div');
|
|
132
|
+
this.targetWrap.className = 'designbase-wc-context-menu__target';
|
|
133
|
+
this.targetWrap.addEventListener('contextmenu', this.handleContextMenu);
|
|
134
|
+
}
|
|
135
|
+
this.replaceChildren();
|
|
136
|
+
targetChildren.forEach((child) => this.targetWrap.append(child));
|
|
137
|
+
if (targetChildren.length > 0) {
|
|
138
|
+
this.append(this.targetWrap);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.replaceChildren();
|
|
143
|
+
this.bindExternalTarget();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
adjustPosition() {
|
|
147
|
+
if (!this.menuEl)
|
|
148
|
+
return;
|
|
149
|
+
const x = Number(this.getAttribute('x') || 0);
|
|
150
|
+
const y = Number(this.getAttribute('y') || 0);
|
|
151
|
+
const rect = this.menuEl.getBoundingClientRect();
|
|
152
|
+
let adjustedX = x;
|
|
153
|
+
let adjustedY = y;
|
|
154
|
+
if (x + rect.width > window.innerWidth)
|
|
155
|
+
adjustedX = x - rect.width;
|
|
156
|
+
if (y + rect.height > window.innerHeight)
|
|
157
|
+
adjustedY = y - rect.height;
|
|
158
|
+
this.menuEl.style.left = `${Math.max(0, adjustedX)}px`;
|
|
159
|
+
this.menuEl.style.top = `${Math.max(0, adjustedY)}px`;
|
|
160
|
+
}
|
|
161
|
+
createMenuItem(item) {
|
|
162
|
+
const menuItem = document.createElement('db-menu-item');
|
|
163
|
+
menuItem.setAttribute('label', item.label || item.id);
|
|
164
|
+
menuItem.setAttribute('type', 'block');
|
|
165
|
+
menuItem.setAttribute('menu-style', 'dropdown');
|
|
166
|
+
if (item.icon)
|
|
167
|
+
menuItem.setAttribute('icon', item.icon);
|
|
168
|
+
if (item.disabled)
|
|
169
|
+
menuItem.setAttribute('disabled', '');
|
|
170
|
+
if (item.variant)
|
|
171
|
+
menuItem.setAttribute('variant', item.variant);
|
|
172
|
+
if (item.subItems?.length) {
|
|
173
|
+
menuItem.setAttribute('sub-items', JSON.stringify(item.subItems));
|
|
174
|
+
menuItem.setAttribute('expandable', '');
|
|
175
|
+
}
|
|
176
|
+
menuItem.addEventListener('db-click', () => {
|
|
177
|
+
if (item.disabled)
|
|
178
|
+
return;
|
|
179
|
+
if (!item.subItems?.length) {
|
|
180
|
+
this.dispatchEvent(new CustomEvent('db-select', {
|
|
181
|
+
detail: { item },
|
|
182
|
+
bubbles: true,
|
|
183
|
+
composed: true,
|
|
184
|
+
}));
|
|
185
|
+
this.close();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
menuItem.addEventListener('db-child-click', (event) => {
|
|
189
|
+
const child = event.detail?.child;
|
|
190
|
+
this.dispatchEvent(new CustomEvent('db-select', {
|
|
191
|
+
detail: { item: child },
|
|
192
|
+
bubbles: true,
|
|
193
|
+
composed: true,
|
|
194
|
+
}));
|
|
195
|
+
this.close();
|
|
196
|
+
});
|
|
197
|
+
return menuItem;
|
|
198
|
+
}
|
|
199
|
+
renderItem(item, index) {
|
|
200
|
+
if (item.divider || item.isDivider) {
|
|
201
|
+
const divider = document.createElement('db-divider');
|
|
202
|
+
divider.className = 'designbase-wc-divider';
|
|
203
|
+
return divider;
|
|
204
|
+
}
|
|
205
|
+
const wrapper = document.createElement('div');
|
|
206
|
+
wrapper.className = 'designbase-wc-context-menu__item-wrapper';
|
|
207
|
+
wrapper.append(this.createMenuItem(item));
|
|
208
|
+
const hasSubMenu = Boolean(item.subItems?.length);
|
|
209
|
+
if (hasSubMenu) {
|
|
210
|
+
const submenu = document.createElement('div');
|
|
211
|
+
submenu.className = [
|
|
212
|
+
'designbase-wc-context-menu__submenu',
|
|
213
|
+
this.activeSubMenu === item.id && 'designbase-wc-context-menu__submenu--open',
|
|
214
|
+
]
|
|
215
|
+
.filter(Boolean)
|
|
216
|
+
.join(' ');
|
|
217
|
+
item.subItems?.forEach((subItem, subIndex) => {
|
|
218
|
+
const child = this.renderItem(subItem, subIndex);
|
|
219
|
+
if (child)
|
|
220
|
+
submenu.append(child);
|
|
221
|
+
});
|
|
222
|
+
wrapper.addEventListener('mouseenter', () => {
|
|
223
|
+
this.activeSubMenu = item.id;
|
|
224
|
+
submenu.classList.add('designbase-wc-context-menu__submenu--open');
|
|
225
|
+
});
|
|
226
|
+
wrapper.addEventListener('mouseleave', () => {
|
|
227
|
+
this.activeSubMenu = null;
|
|
228
|
+
submenu.classList.remove('designbase-wc-context-menu__submenu--open');
|
|
229
|
+
});
|
|
230
|
+
wrapper.append(submenu);
|
|
231
|
+
}
|
|
232
|
+
return wrapper;
|
|
233
|
+
}
|
|
234
|
+
syncMenu() {
|
|
235
|
+
this.menuEl?.remove();
|
|
236
|
+
this.menuEl = undefined;
|
|
237
|
+
if (!this.open)
|
|
238
|
+
return;
|
|
239
|
+
const x = Number(this.getAttribute('x') || 0);
|
|
240
|
+
const y = Number(this.getAttribute('y') || 0);
|
|
241
|
+
const items = this.items;
|
|
242
|
+
const menu = document.createElement('div');
|
|
243
|
+
menu.className = 'designbase-wc-context-menu';
|
|
244
|
+
menu.setAttribute('data-wc-internal', '');
|
|
245
|
+
menu.style.position = 'fixed';
|
|
246
|
+
menu.style.left = `${x}px`;
|
|
247
|
+
menu.style.top = `${y}px`;
|
|
248
|
+
menu.style.zIndex = '1000';
|
|
249
|
+
menu.setAttribute('role', 'menu');
|
|
250
|
+
menu.setAttribute('aria-orientation', 'vertical');
|
|
251
|
+
items.forEach((item, index) => {
|
|
252
|
+
const node = this.renderItem(item, index);
|
|
253
|
+
if (node)
|
|
254
|
+
menu.append(node);
|
|
255
|
+
});
|
|
256
|
+
document.body.append(menu);
|
|
257
|
+
this.menuEl = menu;
|
|
258
|
+
requestAnimationFrame(() => this.adjustPosition());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (!customElements.get('db-context-menu')) {
|
|
262
|
+
customElements.define('db-context-menu', DbContextMenu);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { DbContextMenu };
|
|
@@ -1 +1,146 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SIZES = ['s', 'm', 'l'];
|
|
2
|
+
const VARIANTS = ['default', 'compact', 'minimal'];
|
|
3
|
+
class DbCountdown extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.timer = null;
|
|
7
|
+
this.targetTime = Date.now();
|
|
8
|
+
}
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return [
|
|
11
|
+
'end-date',
|
|
12
|
+
'duration',
|
|
13
|
+
'size',
|
|
14
|
+
'variant',
|
|
15
|
+
'show-days',
|
|
16
|
+
'show-hours',
|
|
17
|
+
'show-minutes',
|
|
18
|
+
'show-seconds',
|
|
19
|
+
'show-labels',
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
this.setupTargetTime();
|
|
24
|
+
this.start();
|
|
25
|
+
}
|
|
26
|
+
disconnectedCallback() {
|
|
27
|
+
this.stop();
|
|
28
|
+
}
|
|
29
|
+
attributeChangedCallback() {
|
|
30
|
+
this.setupTargetTime();
|
|
31
|
+
this.render();
|
|
32
|
+
}
|
|
33
|
+
boolAttr(name, fallback = false) {
|
|
34
|
+
if (!this.hasAttribute(name))
|
|
35
|
+
return fallback;
|
|
36
|
+
const value = this.getAttribute(name);
|
|
37
|
+
return value === '' || value === 'true';
|
|
38
|
+
}
|
|
39
|
+
optionAttr(name, options, fallback) {
|
|
40
|
+
const value = this.getAttribute(name);
|
|
41
|
+
return value && options.includes(value) ? value : fallback;
|
|
42
|
+
}
|
|
43
|
+
setupTargetTime() {
|
|
44
|
+
const endDate = this.getAttribute('end-date');
|
|
45
|
+
const duration = Number(this.getAttribute('duration'));
|
|
46
|
+
if (endDate) {
|
|
47
|
+
const parsed = new Date(endDate).getTime();
|
|
48
|
+
this.targetTime = Number.isFinite(parsed) ? parsed : Date.now();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (Number.isFinite(duration) && duration > 0) {
|
|
52
|
+
this.targetTime = Date.now() + duration * 1000;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.targetTime = Date.now();
|
|
56
|
+
}
|
|
57
|
+
getRemaining() {
|
|
58
|
+
const total = this.targetTime - Date.now();
|
|
59
|
+
if (total <= 0)
|
|
60
|
+
return { days: 0, hours: 0, minutes: 0, seconds: 0, total: 0 };
|
|
61
|
+
return {
|
|
62
|
+
days: Math.floor(total / (1000 * 60 * 60 * 24)),
|
|
63
|
+
hours: Math.floor((total / (1000 * 60 * 60)) % 24),
|
|
64
|
+
minutes: Math.floor((total / (1000 * 60)) % 60),
|
|
65
|
+
seconds: Math.floor((total / 1000) % 60),
|
|
66
|
+
total,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
stop() {
|
|
70
|
+
if (this.timer !== null) {
|
|
71
|
+
window.clearInterval(this.timer);
|
|
72
|
+
this.timer = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
start() {
|
|
76
|
+
this.stop();
|
|
77
|
+
this.render();
|
|
78
|
+
this.timer = window.setInterval(() => {
|
|
79
|
+
const remaining = this.getRemaining();
|
|
80
|
+
this.render();
|
|
81
|
+
this.dispatchEvent(new CustomEvent('db-tick', { detail: remaining, bubbles: true, composed: true }));
|
|
82
|
+
if (remaining.total <= 0) {
|
|
83
|
+
this.stop();
|
|
84
|
+
this.dispatchEvent(new CustomEvent('db-complete', { bubbles: true, composed: true }));
|
|
85
|
+
}
|
|
86
|
+
}, 1000);
|
|
87
|
+
}
|
|
88
|
+
two(value) {
|
|
89
|
+
return String(value).padStart(2, '0');
|
|
90
|
+
}
|
|
91
|
+
render() {
|
|
92
|
+
const size = this.optionAttr('size', SIZES, 'm');
|
|
93
|
+
const variant = this.optionAttr('variant', VARIANTS, 'default');
|
|
94
|
+
const showLabels = this.boolAttr('show-labels', true);
|
|
95
|
+
const remaining = this.getRemaining();
|
|
96
|
+
this.className = [
|
|
97
|
+
'designbase-wc-countdown',
|
|
98
|
+
`designbase-wc-countdown--${size}`,
|
|
99
|
+
`designbase-wc-countdown--${variant}`,
|
|
100
|
+
showLabels && 'designbase-wc-countdown--with-labels',
|
|
101
|
+
remaining.total <= 0 && 'designbase-wc-countdown--expired',
|
|
102
|
+
]
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join(' ');
|
|
105
|
+
const labels = {
|
|
106
|
+
days: this.getAttribute('label-days') || '일',
|
|
107
|
+
hours: this.getAttribute('label-hours') || '시간',
|
|
108
|
+
minutes: this.getAttribute('label-minutes') || '분',
|
|
109
|
+
seconds: this.getAttribute('label-seconds') || '초',
|
|
110
|
+
};
|
|
111
|
+
const units = [
|
|
112
|
+
{ key: 'days', value: remaining.days, show: this.boolAttr('show-days', true) },
|
|
113
|
+
{ key: 'hours', value: remaining.hours, show: this.boolAttr('show-hours', true) },
|
|
114
|
+
{ key: 'minutes', value: remaining.minutes, show: this.boolAttr('show-minutes', true) },
|
|
115
|
+
{ key: 'seconds', value: remaining.seconds, show: this.boolAttr('show-seconds', true) },
|
|
116
|
+
].filter((item) => item.show);
|
|
117
|
+
const nodes = [];
|
|
118
|
+
for (let i = 0; i < units.length; i += 1) {
|
|
119
|
+
const unit = units[i];
|
|
120
|
+
const unitEl = document.createElement('div');
|
|
121
|
+
unitEl.className = 'designbase-wc-countdown__unit';
|
|
122
|
+
const valueEl = document.createElement('div');
|
|
123
|
+
valueEl.className = 'designbase-wc-countdown__value';
|
|
124
|
+
valueEl.textContent = this.two(unit.value);
|
|
125
|
+
unitEl.append(valueEl);
|
|
126
|
+
if (showLabels) {
|
|
127
|
+
const labelEl = document.createElement('div');
|
|
128
|
+
labelEl.className = 'designbase-wc-countdown__label';
|
|
129
|
+
labelEl.textContent = labels[unit.key];
|
|
130
|
+
unitEl.append(labelEl);
|
|
131
|
+
}
|
|
132
|
+
nodes.push(unitEl);
|
|
133
|
+
if (i < units.length - 1 && variant !== 'minimal') {
|
|
134
|
+
const sep = document.createElement('div');
|
|
135
|
+
sep.className = 'designbase-wc-countdown__separator';
|
|
136
|
+
sep.textContent = ':';
|
|
137
|
+
nodes.push(sep);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.replaceChildren(...nodes);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!customElements.get('db-countdown'))
|
|
144
|
+
customElements.define('db-countdown', DbCountdown);
|
|
145
|
+
|
|
146
|
+
export { DbCountdown };
|