@designbasekorea/ui-wc 0.5.6 → 0.6.1
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-35a9b0f5.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +64 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +63 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.d.ts +20 -0
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +71 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1125 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1637 -21
- package/dist/react/index.esm.js +1 -39373
- package/package.json +2 -2
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,191 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{createDbIcon as e}from"./db-icons.js";class DbConfirm extends HTMLElement{constructor(){super(...arguments),this.root=null,this.keyHandler=null}static get observedAttributes(){return["open","title","message","confirm-text","cancel-text","confirm-variant","variant","size","show-icon","initial-focus","confirm-disabled","cancel-disabled","close-on-escape","close-on-backdrop"]}connectedCallback(){this.render()}disconnectedCallback(){this.detachEscape(),document.body.style.overflow="",this.root?.remove(),this.root=null}attributeChangedCallback(){this.render()}isOpen(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}attachEscape(){this.keyHandler||(this.keyHandler=e=>{"Escape"===e.key&&"false"!==this.getAttribute("close-on-escape")&&this.dispatchCancel()},document.addEventListener("keydown",this.keyHandler))}detachEscape(){this.keyHandler&&(document.removeEventListener("keydown",this.keyHandler),this.keyHandler=null)}dispatchCancel(){this.setAttribute("open","false"),this.dispatchEvent(new CustomEvent("db-cancel",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}dispatchConfirm(){this.setAttribute("open","false"),this.dispatchEvent(new CustomEvent("db-confirm",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}iconForVariant(e){return"success"===e?"award":"warning"===e?"bell-active":"danger"===e?"cloud-close":"bulb"}iconSize(e){return"s"===e?20:"l"===e?32:24}render(){if(this.root?.remove(),this.root=null,this.detachEscape(),!this.isOpen())return document.body.style.overflow="",void this.replaceChildren();document.body.style.overflow="hidden",this.attachEscape();const t=this.getAttribute("title")||"",i=this.getAttribute("message")||this.textContent?.trim()||"",n=this.getAttribute("confirm-text")||"확인",s=this.getAttribute("cancel-text")||"취소",c=this.getAttribute("confirm-variant")||"primary",o=this.getAttribute("variant")||"info",a=this.getAttribute("size")||"s",r="false"!==this.getAttribute("show-icon"),d=this.getAttribute("initial-focus")||"confirm",l="true"===this.getAttribute("confirm-disabled"),m="true"===this.getAttribute("cancel-disabled"),b=document.createElement("div");b.className="designbase-wc-confirm__overlay",b.setAttribute("role","dialog"),b.setAttribute("aria-modal","true"),t&&b.setAttribute("aria-labelledby","confirm-title"),b.setAttribute("aria-describedby","confirm-content"),b.addEventListener("click",e=>{e.target===b&&"false"!==this.getAttribute("close-on-backdrop")&&this.dispatchCancel()});const u=document.createElement("div");u.className=["designbase-wc-confirm__modal",`designbase-wc-confirm__modal--${o}`,`designbase-wc-confirm__modal--${a}`,!r&&"designbase-wc-confirm__modal--no-icon"].filter(Boolean).join(" ");const h=document.createElement("div");if(h.className=["designbase-wc-confirm__header",!r&&"designbase-wc-confirm__header--no-icon"].filter(Boolean).join(" "),r){const t=document.createElement("div");t.className="designbase-wc-confirm__icon",t.append(e(this.iconForVariant(o),this.iconSize(a))),h.append(t)}const p=document.createElement("div");if(p.className="designbase-wc-confirm__title-area",t){const e=document.createElement("h2");e.id="confirm-title",e.className="designbase-wc-confirm__title",e.textContent=t,p.append(e)}h.append(p),u.append(h);const f=document.createElement("div");f.id="confirm-content",f.className="designbase-wc-confirm__content",f.textContent=i,u.append(f);const v=document.createElement("div");v.className="designbase-wc-confirm__footer";const g=document.createElement("db-button");g.setAttribute("variant","tertiary"),g.setAttribute("full-width",""),g.textContent=s,m&&g.setAttribute("disabled",""),g.addEventListener("db-click",()=>this.dispatchCancel());const E=document.createElement("db-button");E.setAttribute("variant",c),E.setAttribute("full-width",""),E.textContent=n,l&&E.setAttribute("disabled",""),E.addEventListener("db-click",()=>this.dispatchConfirm()),v.append(g,E),u.append(v),b.append(u),document.body.append(b),this.root=b,requestAnimationFrame(()=>{("cancel"===d?g:E).focus()})}}customElements.get("db-confirm")||customElements.define("db-confirm",DbConfirm);export{DbConfirm};
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
const
|
|
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
|
+
const t=["s","m","l","xl","full"],e=["none","s","m","l","xl"];class DbContainer extends HTMLElement{static get observedAttributes(){return["size","padding","max-width","full-width"]}connectedCallback(){this.syncClasses()}attributeChangedCallback(){this.syncClasses()}syncClasses(){const s=this.getAttribute("size")||"l",i=this.getAttribute("padding")||"m",n=this.getAttribute("max-width");this.className=["designbase-wc-container",`designbase-wc-container--size-${t.includes(s)?s:"l"}`,e.includes(i)&&`designbase-wc-container--padding-${i}`,this.hasAttribute("full-width")&&"designbase-wc-container--full-width"].filter(Boolean).join(" "),this.hasAttribute("full-width")?this.style.maxWidth="100%":n?this.style.maxWidth=n.includes("px")||n.includes("%")?n:`${n}px`:this.style.removeProperty("max-width")}}customElements.get("db-container")||customElements.define("db-container",DbContainer);export{DbContainer};
|
|
@@ -1,265 +1 @@
|
|
|
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
|
+
class DbContextMenu extends HTMLElement{constructor(){super(...arguments),this.externalTarget=null,this.activeSubMenu=null,this.onExternalContextMenu=null,this.handleDocumentMouseDown=t=>{if(!this.open)return;const e=t.target;this.menuEl?.contains(e)||2===t.button&&(this.targetWrap?.contains(e)||this.externalTarget?.contains(e))||this.close()},this.handleKeyDown=t=>{this.open&&"Escape"===t.key&&this.close()},this.handleContextMenu=t=>{this.hasAttribute("disabled")||(t.preventDefault(),t.stopPropagation(),this.openAt(t.clientX,t.clientY))}}static get observedAttributes(){return["open","x","y","items","target-id","disabled"]}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(t){t?this.setAttribute("open","true"):this.removeAttribute("open")}get items(){try{return JSON.parse(this.getAttribute("items")||"[]")}catch{return[]}}set items(t){this.setAttribute("items","string"==typeof t?t:JSON.stringify(t))}connectedCallback(){this.style.display="contents",requestAnimationFrame(()=>{this.renderTarget(),this.syncMenu()}),document.addEventListener("mousedown",this.handleDocumentMouseDown),document.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){document.removeEventListener("mousedown",this.handleDocumentMouseDown),document.removeEventListener("keydown",this.handleKeyDown),this.unbindExternalTarget(),this.menuEl?.remove(),this.menuEl=void 0}attributeChangedCallback(t){if(this.isConnected)return"target-id"===t?(this.unbindExternalTarget(),void this.bindExternalTarget()):void("open"!==t&&"x"!==t&&"y"!==t&&"items"!==t||this.syncMenu())}openAt(t,e){this.setAttribute("x",String(t)),this.setAttribute("y",String(e)),this.setAttribute("open","true"),this.dispatchEvent(new CustomEvent("db-open",{bubbles:!0,composed:!0,detail:{x:t,y:e}})),this.syncMenu()}close(){this.activeSubMenu=null,this.removeAttribute("open"),this.menuEl?.remove(),this.menuEl=void 0,this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}collectTargetChildren(){const t=Array.from(this.children).filter(t=>!t.hasAttribute("data-wc-internal")&&t!==this.targetWrap);return t.length>0?t:Array.from(this.targetWrap?.children||[])}bindExternalTarget(){const t=this.getAttribute("target-id");t&&(this.externalTarget=document.getElementById(t),this.externalTarget&&(this.onExternalContextMenu=t=>this.handleContextMenu(t),this.externalTarget.addEventListener("contextmenu",this.onExternalContextMenu)))}unbindExternalTarget(){this.externalTarget&&this.onExternalContextMenu&&this.externalTarget.removeEventListener("contextmenu",this.onExternalContextMenu),this.externalTarget=null,this.onExternalContextMenu=null}renderTarget(){const t=this.collectTargetChildren();this.getAttribute("target-id")?(this.replaceChildren(),this.bindExternalTarget()):(this.targetWrap||(this.targetWrap=document.createElement("div"),this.targetWrap.className="designbase-wc-context-menu__target",this.targetWrap.addEventListener("contextmenu",this.handleContextMenu)),this.replaceChildren(),t.forEach(t=>this.targetWrap.append(t)),t.length>0&&this.append(this.targetWrap))}adjustPosition(){if(!this.menuEl)return;const t=Number(this.getAttribute("x")||0),e=Number(this.getAttribute("y")||0),n=this.menuEl.getBoundingClientRect();let i=t,s=e;t+n.width>window.innerWidth&&(i=t-n.width),e+n.height>window.innerHeight&&(s=e-n.height),this.menuEl.style.left=`${Math.max(0,i)}px`,this.menuEl.style.top=`${Math.max(0,s)}px`}createMenuItem(t){const e=document.createElement("db-menu-item");return e.setAttribute("label",t.label||t.id),e.setAttribute("type","block"),e.setAttribute("menu-style","dropdown"),t.icon&&e.setAttribute("icon",t.icon),t.disabled&&e.setAttribute("disabled",""),t.variant&&e.setAttribute("variant",t.variant),t.subItems?.length&&(e.setAttribute("sub-items",JSON.stringify(t.subItems)),e.setAttribute("expandable","")),e.addEventListener("db-click",()=>{t.disabled||t.subItems?.length||(this.dispatchEvent(new CustomEvent("db-select",{detail:{item:t},bubbles:!0,composed:!0})),this.close())}),e.addEventListener("db-child-click",t=>{const e=t.detail?.child;this.dispatchEvent(new CustomEvent("db-select",{detail:{item:e},bubbles:!0,composed:!0})),this.close()}),e}renderItem(t,e){if(t.divider||t.isDivider){const t=document.createElement("db-divider");return t.className="designbase-wc-divider",t}const n=document.createElement("div");n.className="designbase-wc-context-menu__item-wrapper",n.append(this.createMenuItem(t));if(Boolean(t.subItems?.length)){const e=document.createElement("div");e.className=["designbase-wc-context-menu__submenu",this.activeSubMenu===t.id&&"designbase-wc-context-menu__submenu--open"].filter(Boolean).join(" "),t.subItems?.forEach((t,n)=>{const i=this.renderItem(t,n);i&&e.append(i)}),n.addEventListener("mouseenter",()=>{this.activeSubMenu=t.id,e.classList.add("designbase-wc-context-menu__submenu--open")}),n.addEventListener("mouseleave",()=>{this.activeSubMenu=null,e.classList.remove("designbase-wc-context-menu__submenu--open")}),n.append(e)}return n}syncMenu(){if(this.menuEl?.remove(),this.menuEl=void 0,!this.open)return;const t=Number(this.getAttribute("x")||0),e=Number(this.getAttribute("y")||0),n=this.items,i=document.createElement("div");i.className="designbase-wc-context-menu",i.setAttribute("data-wc-internal",""),i.style.position="fixed",i.style.left=`${t}px`,i.style.top=`${e}px`,i.style.zIndex="1000",i.setAttribute("role","menu"),i.setAttribute("aria-orientation","vertical"),n.forEach((t,e)=>{const n=this.renderItem(t,e);n&&i.append(n)}),document.body.append(i),this.menuEl=i,requestAnimationFrame(()=>this.adjustPosition())}}customElements.get("db-context-menu")||customElements.define("db-context-menu",DbContextMenu);export{DbContextMenu};
|
|
@@ -1,146 +1 @@
|
|
|
1
|
-
const
|
|
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 };
|
|
1
|
+
const t=["s","m","l"],e=["default","compact","minimal"];class DbCountdown extends HTMLElement{constructor(){super(...arguments),this.timer=null,this.targetTime=Date.now()}static get observedAttributes(){return["end-date","duration","size","variant","show-days","show-hours","show-minutes","show-seconds","show-labels"]}connectedCallback(){this.setupTargetTime(),this.start()}disconnectedCallback(){this.stop()}attributeChangedCallback(){this.setupTargetTime(),this.render()}boolAttr(t,e=!1){if(!this.hasAttribute(t))return e;const s=this.getAttribute(t);return""===s||"true"===s}optionAttr(t,e,s){const n=this.getAttribute(t);return n&&e.includes(n)?n:s}setupTargetTime(){const t=this.getAttribute("end-date"),e=Number(this.getAttribute("duration"));if(t){const e=new Date(t).getTime();return void(this.targetTime=Number.isFinite(e)?e:Date.now())}Number.isFinite(e)&&e>0?this.targetTime=Date.now()+1e3*e:this.targetTime=Date.now()}getRemaining(){const t=this.targetTime-Date.now();return t<=0?{days:0,hours:0,minutes:0,seconds:0,total:0}:{days:Math.floor(t/864e5),hours:Math.floor(t/36e5%24),minutes:Math.floor(t/6e4%60),seconds:Math.floor(t/1e3%60),total:t}}stop(){null!==this.timer&&(window.clearInterval(this.timer),this.timer=null)}start(){this.stop(),this.render(),this.timer=window.setInterval(()=>{const t=this.getRemaining();this.render(),this.dispatchEvent(new CustomEvent("db-tick",{detail:t,bubbles:!0,composed:!0})),t.total<=0&&(this.stop(),this.dispatchEvent(new CustomEvent("db-complete",{bubbles:!0,composed:!0})))},1e3)}two(t){return String(t).padStart(2,"0")}render(){const s=this.optionAttr("size",t,"m"),n=this.optionAttr("variant",e,"default"),o=this.boolAttr("show-labels",!0),i=this.getRemaining();this.className=["designbase-wc-countdown",`designbase-wc-countdown--${s}`,`designbase-wc-countdown--${n}`,o&&"designbase-wc-countdown--with-labels",i.total<=0&&"designbase-wc-countdown--expired"].filter(Boolean).join(" ");const a={days:this.getAttribute("label-days")||"일",hours:this.getAttribute("label-hours")||"시간",minutes:this.getAttribute("label-minutes")||"분",seconds:this.getAttribute("label-seconds")||"초"},r=[{key:"days",value:i.days,show:this.boolAttr("show-days",!0)},{key:"hours",value:i.hours,show:this.boolAttr("show-hours",!0)},{key:"minutes",value:i.minutes,show:this.boolAttr("show-minutes",!0)},{key:"seconds",value:i.seconds,show:this.boolAttr("show-seconds",!0)}].filter(t=>t.show),d=[];for(let t=0;t<r.length;t+=1){const e=r[t],s=document.createElement("div");s.className="designbase-wc-countdown__unit";const i=document.createElement("div");if(i.className="designbase-wc-countdown__value",i.textContent=this.two(e.value),s.append(i),o){const t=document.createElement("div");t.className="designbase-wc-countdown__label",t.textContent=a[e.key],s.append(t)}if(d.push(s),t<r.length-1&&"minimal"!==n){const t=document.createElement("div");t.className="designbase-wc-countdown__separator",t.textContent=":",d.push(t)}}this.replaceChildren(...d)}}customElements.get("db-countdown")||customElements.define("db-countdown",DbCountdown);export{DbCountdown};
|