@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,325 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
const SIZES = ['s', 'm', 'l'];
|
|
4
|
+
const VARIANTS = ['default', 'minimal', 'card', 'inline', 'large'];
|
|
5
|
+
const DISPLAYS = ['stars', 'number', 'both', 'reviews', 'detailed'];
|
|
6
|
+
const TYPES = ['star', 'number', 'percentage', 'text'];
|
|
7
|
+
const COLORS = ['primary', 'secondary', 'success', 'warning', 'error', 'custom'];
|
|
8
|
+
class DbRating extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.hoverValue = null;
|
|
12
|
+
this.starsEl = null;
|
|
13
|
+
this.handlePointerMove = (event) => {
|
|
14
|
+
if (!this.isInteractive() || !this.getBooleanAttr('hover-effect', true))
|
|
15
|
+
return;
|
|
16
|
+
const star = event.target?.closest('.designbase-wc-rating__star');
|
|
17
|
+
if (!star || !this.contains(star))
|
|
18
|
+
return;
|
|
19
|
+
const index = Number(star.dataset.index);
|
|
20
|
+
if (!Number.isFinite(index))
|
|
21
|
+
return;
|
|
22
|
+
const maxValue = this.getNumberAttr('max-value', 5);
|
|
23
|
+
const nextHover = this.getPointerValue(index, event.clientX, star, maxValue);
|
|
24
|
+
if (this.hoverValue === nextHover)
|
|
25
|
+
return;
|
|
26
|
+
this.hoverValue = nextHover;
|
|
27
|
+
this.classList.toggle('designbase-wc-rating--hovering', true);
|
|
28
|
+
this.refreshStars();
|
|
29
|
+
this.dispatchEvent(new CustomEvent('db-hover', {
|
|
30
|
+
detail: { value: nextHover },
|
|
31
|
+
bubbles: true,
|
|
32
|
+
composed: true,
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
this.handlePointerLeave = () => {
|
|
36
|
+
if (this.hoverValue === null)
|
|
37
|
+
return;
|
|
38
|
+
this.hoverValue = null;
|
|
39
|
+
this.classList.remove('designbase-wc-rating--hovering');
|
|
40
|
+
this.refreshStars();
|
|
41
|
+
};
|
|
42
|
+
this.handleClick = (event) => {
|
|
43
|
+
if (!this.isInteractive())
|
|
44
|
+
return;
|
|
45
|
+
const star = event.target?.closest('.designbase-wc-rating__star');
|
|
46
|
+
if (!star || !this.contains(star))
|
|
47
|
+
return;
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
const index = Number(star.dataset.index);
|
|
50
|
+
if (!Number.isFinite(index))
|
|
51
|
+
return;
|
|
52
|
+
const maxValue = this.getNumberAttr('max-value', 5);
|
|
53
|
+
const nextValue = this.getPointerValue(index, event.clientX, star, maxValue);
|
|
54
|
+
this.hoverValue = null;
|
|
55
|
+
this.classList.remove('designbase-wc-rating--hovering');
|
|
56
|
+
this.setAttribute('value', String(nextValue));
|
|
57
|
+
this.dispatchEvent(new CustomEvent('db-change', {
|
|
58
|
+
detail: { value: nextValue },
|
|
59
|
+
bubbles: true,
|
|
60
|
+
composed: true,
|
|
61
|
+
}));
|
|
62
|
+
this.render();
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static get observedAttributes() {
|
|
66
|
+
return [
|
|
67
|
+
'value',
|
|
68
|
+
'max-value',
|
|
69
|
+
'size',
|
|
70
|
+
'variant',
|
|
71
|
+
'type',
|
|
72
|
+
'display',
|
|
73
|
+
'review-count',
|
|
74
|
+
'rating-text',
|
|
75
|
+
'review-text',
|
|
76
|
+
'allow-half',
|
|
77
|
+
'readonly',
|
|
78
|
+
'disabled',
|
|
79
|
+
'clickable',
|
|
80
|
+
'color',
|
|
81
|
+
'custom-color',
|
|
82
|
+
'animated',
|
|
83
|
+
'hover-effect',
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
connectedCallback() {
|
|
87
|
+
this.addEventListener('mousemove', this.handlePointerMove);
|
|
88
|
+
this.addEventListener('mouseleave', this.handlePointerLeave);
|
|
89
|
+
this.addEventListener('click', this.handleClick);
|
|
90
|
+
this.render();
|
|
91
|
+
}
|
|
92
|
+
disconnectedCallback() {
|
|
93
|
+
this.removeEventListener('mousemove', this.handlePointerMove);
|
|
94
|
+
this.removeEventListener('mouseleave', this.handlePointerLeave);
|
|
95
|
+
this.removeEventListener('click', this.handleClick);
|
|
96
|
+
}
|
|
97
|
+
attributeChangedCallback() {
|
|
98
|
+
if (this.isConnected)
|
|
99
|
+
this.render();
|
|
100
|
+
}
|
|
101
|
+
getNumberAttr(name, fallback) {
|
|
102
|
+
const raw = this.getAttribute(name);
|
|
103
|
+
if (raw === null || raw === '')
|
|
104
|
+
return fallback;
|
|
105
|
+
const value = Number(raw);
|
|
106
|
+
return Number.isFinite(value) ? value : fallback;
|
|
107
|
+
}
|
|
108
|
+
getBooleanAttr(name, fallback = false) {
|
|
109
|
+
if (!this.hasAttribute(name))
|
|
110
|
+
return fallback;
|
|
111
|
+
const value = this.getAttribute(name);
|
|
112
|
+
return value === '' || value === 'true';
|
|
113
|
+
}
|
|
114
|
+
getOption(name, options, fallback) {
|
|
115
|
+
const value = this.getAttribute(name);
|
|
116
|
+
return value && options.includes(value) ? value : fallback;
|
|
117
|
+
}
|
|
118
|
+
normalizeSize(raw) {
|
|
119
|
+
if (raw === 'xs' || raw === 's')
|
|
120
|
+
return 's';
|
|
121
|
+
if (raw === 'xl' || raw === 'l')
|
|
122
|
+
return 'l';
|
|
123
|
+
if (raw === 'm')
|
|
124
|
+
return 'm';
|
|
125
|
+
return this.getOption('size', SIZES, 'm');
|
|
126
|
+
}
|
|
127
|
+
getStarIconSize() {
|
|
128
|
+
const size = this.normalizeSize(this.getAttribute('size'));
|
|
129
|
+
if (size === 's')
|
|
130
|
+
return 16;
|
|
131
|
+
if (size === 'l')
|
|
132
|
+
return 24;
|
|
133
|
+
return 20;
|
|
134
|
+
}
|
|
135
|
+
supportsHalfSteps() {
|
|
136
|
+
return this.getBooleanAttr('allow-half') || this.getBooleanAttr('clickable');
|
|
137
|
+
}
|
|
138
|
+
isInteractive() {
|
|
139
|
+
return (this.getBooleanAttr('clickable') &&
|
|
140
|
+
!this.getBooleanAttr('readonly') &&
|
|
141
|
+
!this.getBooleanAttr('disabled'));
|
|
142
|
+
}
|
|
143
|
+
getStarFill(index, normalizedValue, allowHalfDisplay) {
|
|
144
|
+
const starIndex = index + 1;
|
|
145
|
+
if (normalizedValue >= starIndex)
|
|
146
|
+
return 1;
|
|
147
|
+
if (allowHalfDisplay && normalizedValue >= starIndex - 0.5)
|
|
148
|
+
return 0.5;
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
getPointerValue(index, clientX, starEl, maxValue) {
|
|
152
|
+
const rect = starEl.getBoundingClientRect();
|
|
153
|
+
let normalized;
|
|
154
|
+
if (this.supportsHalfSteps()) {
|
|
155
|
+
normalized = clientX - rect.left < rect.width / 2 ? index + 0.5 : index + 1;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
normalized = index + 1;
|
|
159
|
+
}
|
|
160
|
+
return (normalized / 5) * maxValue;
|
|
161
|
+
}
|
|
162
|
+
formatRating(value, maxValue, type, allowHalf) {
|
|
163
|
+
const normalized = (value / maxValue) * 5;
|
|
164
|
+
if (type === 'percentage')
|
|
165
|
+
return `${Math.round((value / maxValue) * 100)}%`;
|
|
166
|
+
if (type === 'number')
|
|
167
|
+
return allowHalf ? normalized.toFixed(1) : String(Math.round(normalized));
|
|
168
|
+
if (type === 'text')
|
|
169
|
+
return normalized >= 4.5 ? '매우 좋음' : normalized >= 3 ? '보통' : '낮음';
|
|
170
|
+
return `${normalized.toFixed(1)}/5`;
|
|
171
|
+
}
|
|
172
|
+
updateStarElement(star, fill, index, interactive, isHoverPreview) {
|
|
173
|
+
star.className = [
|
|
174
|
+
'designbase-wc-rating__star',
|
|
175
|
+
fill === 0 && 'designbase-wc-rating__star--empty',
|
|
176
|
+
fill > 0 && isHoverPreview && 'designbase-wc-rating__star--hover-preview',
|
|
177
|
+
interactive && 'designbase-wc-rating__star--clickable',
|
|
178
|
+
this.getBooleanAttr('animated') && 'designbase-wc-rating__star--animated',
|
|
179
|
+
]
|
|
180
|
+
.filter(Boolean)
|
|
181
|
+
.join(' ');
|
|
182
|
+
star.dataset.index = String(index);
|
|
183
|
+
const iconName = fill === 1 ? 'star-filled' : fill === 0.5 ? 'star-half' : 'star';
|
|
184
|
+
const iconSize = this.getStarIconSize();
|
|
185
|
+
const current = star.querySelector('svg');
|
|
186
|
+
if (current?.getAttribute('data-designbase-icon') === iconName && current.getAttribute('width') === String(iconSize)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
star.replaceChildren(createDbIcon(iconName, iconSize));
|
|
190
|
+
}
|
|
191
|
+
refreshStars() {
|
|
192
|
+
if (!this.starsEl)
|
|
193
|
+
return;
|
|
194
|
+
const value = this.getNumberAttr('value', 0);
|
|
195
|
+
const maxValue = this.getNumberAttr('max-value', 5);
|
|
196
|
+
const allowHalf = this.getBooleanAttr('allow-half', false);
|
|
197
|
+
const hoverEffect = this.getBooleanAttr('hover-effect', true);
|
|
198
|
+
const isHovering = this.hoverValue !== null && hoverEffect;
|
|
199
|
+
const shownValue = isHovering ? this.hoverValue : value;
|
|
200
|
+
const normalized = (shownValue / maxValue) * 5;
|
|
201
|
+
const interactive = this.isInteractive();
|
|
202
|
+
const allowHalfDisplay = allowHalf || isHovering;
|
|
203
|
+
const stars = Array.from(this.starsEl.querySelectorAll(':scope > .designbase-wc-rating__star'));
|
|
204
|
+
for (let i = 0; i < 5; i += 1) {
|
|
205
|
+
const fill = this.getStarFill(i, normalized, allowHalfDisplay);
|
|
206
|
+
const isHoverPreview = isHovering && fill > 0;
|
|
207
|
+
const star = stars[i] ?? document.createElement('span');
|
|
208
|
+
star.setAttribute('aria-hidden', 'true');
|
|
209
|
+
this.updateStarElement(star, fill, i, interactive, isHoverPreview);
|
|
210
|
+
if (!stars[i])
|
|
211
|
+
this.starsEl.append(star);
|
|
212
|
+
}
|
|
213
|
+
for (let i = stars.length - 1; i >= 5; i -= 1) {
|
|
214
|
+
stars[i]?.remove();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
render() {
|
|
218
|
+
const value = this.getNumberAttr('value', 0);
|
|
219
|
+
const maxValue = this.getNumberAttr('max-value', 5);
|
|
220
|
+
const size = this.normalizeSize(this.getAttribute('size'));
|
|
221
|
+
const variant = this.getOption('variant', VARIANTS, 'default');
|
|
222
|
+
const type = this.getOption('type', TYPES, 'star');
|
|
223
|
+
const display = this.getOption('display', DISPLAYS, 'stars');
|
|
224
|
+
const color = this.getOption('color', COLORS, 'primary');
|
|
225
|
+
const reviewCount = this.getNumberAttr('review-count', 0);
|
|
226
|
+
const allowHalf = this.getBooleanAttr('allow-half', false);
|
|
227
|
+
const readonly = this.getBooleanAttr('readonly', false);
|
|
228
|
+
const disabled = this.getBooleanAttr('disabled', false);
|
|
229
|
+
const clickable = this.getBooleanAttr('clickable', false);
|
|
230
|
+
const hoverEffect = this.getBooleanAttr('hover-effect', true);
|
|
231
|
+
const isHovering = this.hoverValue !== null && hoverEffect;
|
|
232
|
+
this.className = [
|
|
233
|
+
'designbase-wc-rating',
|
|
234
|
+
`designbase-wc-rating--size-${size}`,
|
|
235
|
+
`designbase-wc-rating--variant-${variant}`,
|
|
236
|
+
`designbase-wc-rating--type-${type}`,
|
|
237
|
+
`designbase-wc-rating--display-${display}`,
|
|
238
|
+
`designbase-wc-rating--color-${color}`,
|
|
239
|
+
readonly && 'designbase-wc-rating--readonly',
|
|
240
|
+
disabled && 'designbase-wc-rating--disabled',
|
|
241
|
+
clickable && 'designbase-wc-rating--clickable',
|
|
242
|
+
this.getBooleanAttr('animated') && 'designbase-wc-rating--animated',
|
|
243
|
+
isHovering && 'designbase-wc-rating--hovering',
|
|
244
|
+
]
|
|
245
|
+
.filter(Boolean)
|
|
246
|
+
.join(' ');
|
|
247
|
+
const customColor = this.getAttribute('custom-color');
|
|
248
|
+
if (color === 'custom' && customColor) {
|
|
249
|
+
this.style.setProperty('--rating-color', customColor);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.style.removeProperty('--rating-color');
|
|
253
|
+
}
|
|
254
|
+
let root = this.querySelector(':scope > [role="img"]');
|
|
255
|
+
if (!root) {
|
|
256
|
+
root = document.createElement('div');
|
|
257
|
+
this.replaceChildren(root);
|
|
258
|
+
}
|
|
259
|
+
root.setAttribute('role', 'img');
|
|
260
|
+
root.setAttribute('aria-label', `rating ${this.formatRating(value, maxValue, type, allowHalf)}`);
|
|
261
|
+
const showStars = display === 'stars' || display === 'both' || display === 'detailed';
|
|
262
|
+
if (showStars) {
|
|
263
|
+
const existingStars = root.querySelectorAll(':scope > .designbase-wc-rating__stars');
|
|
264
|
+
existingStars.forEach((node, index) => {
|
|
265
|
+
if (index > 0)
|
|
266
|
+
node.remove();
|
|
267
|
+
});
|
|
268
|
+
const starsContainer = existingStars[0];
|
|
269
|
+
if (starsContainer) {
|
|
270
|
+
this.starsEl = starsContainer;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
this.starsEl = document.createElement('div');
|
|
274
|
+
this.starsEl.className = 'designbase-wc-rating__stars';
|
|
275
|
+
root.prepend(this.starsEl);
|
|
276
|
+
}
|
|
277
|
+
this.refreshStars();
|
|
278
|
+
}
|
|
279
|
+
else if (this.starsEl) {
|
|
280
|
+
this.starsEl.remove();
|
|
281
|
+
this.starsEl = null;
|
|
282
|
+
}
|
|
283
|
+
const ratingText = this.getAttribute('rating-text') || this.formatRating(value, maxValue, type, allowHalf);
|
|
284
|
+
let numberWrap = root.querySelector('.designbase-wc-rating__number-container');
|
|
285
|
+
if (display === 'number' || display === 'both') {
|
|
286
|
+
if (!numberWrap) {
|
|
287
|
+
numberWrap = document.createElement('div');
|
|
288
|
+
numberWrap.className = 'designbase-wc-rating__number-container';
|
|
289
|
+
const number = document.createElement('span');
|
|
290
|
+
number.className = 'designbase-wc-rating__number';
|
|
291
|
+
numberWrap.append(number);
|
|
292
|
+
root.append(numberWrap);
|
|
293
|
+
}
|
|
294
|
+
const number = numberWrap.querySelector('.designbase-wc-rating__number');
|
|
295
|
+
if (number)
|
|
296
|
+
number.textContent = ratingText;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
numberWrap?.remove();
|
|
300
|
+
}
|
|
301
|
+
let reviews = root.querySelector('.designbase-wc-rating__review-count');
|
|
302
|
+
if (display === 'reviews' || display === 'detailed') {
|
|
303
|
+
const reviewText = this.getAttribute('review-text') ||
|
|
304
|
+
(reviewCount > 0 ? `${reviewCount.toLocaleString()} 리뷰` : '');
|
|
305
|
+
if (reviewText) {
|
|
306
|
+
if (!reviews) {
|
|
307
|
+
reviews = document.createElement('span');
|
|
308
|
+
reviews.className = 'designbase-wc-rating__review-count';
|
|
309
|
+
root.append(reviews);
|
|
310
|
+
}
|
|
311
|
+
reviews.textContent = reviewText;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
reviews?.remove();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
reviews?.remove();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (!customElements.get('db-rating'))
|
|
323
|
+
customElements.define('db-rating', DbRating);
|
|
324
|
+
|
|
325
|
+
export { DbRating };
|
|
@@ -1 +1,286 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
const VARIANTS = ['default', 'bordered', 'filled', 'minimal'];
|
|
4
|
+
const SIZES = ['s', 'm', 'l'];
|
|
5
|
+
const ORIENTATIONS = ['vertical', 'horizontal'];
|
|
6
|
+
class DbReorder extends HTMLElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.draggedIndex = -1;
|
|
10
|
+
this.dropIndex = -1;
|
|
11
|
+
this.handleContainerDragOver = (event) => {
|
|
12
|
+
if (this.draggedIndex < 0)
|
|
13
|
+
return;
|
|
14
|
+
const target = event.target;
|
|
15
|
+
if (target instanceof Element && target.closest('.designbase-wc-reorder__item'))
|
|
16
|
+
return;
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
if (event.dataTransfer) {
|
|
19
|
+
event.dataTransfer.dropEffect = 'move';
|
|
20
|
+
}
|
|
21
|
+
const nextDropIndex = this.getDropIndexFromContainerPointer(event);
|
|
22
|
+
this.setDropIndex(this.isValidDropIndex(nextDropIndex) ? nextDropIndex : -1);
|
|
23
|
+
};
|
|
24
|
+
this.handleContainerDrop = (event) => {
|
|
25
|
+
if (this.draggedIndex < 0)
|
|
26
|
+
return;
|
|
27
|
+
const target = event.target;
|
|
28
|
+
if (target instanceof Element && target.closest('.designbase-wc-reorder__item'))
|
|
29
|
+
return;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
const nextDropIndex = this.dropIndex >= 0 ? this.dropIndex : this.getDropIndexFromContainerPointer(event);
|
|
32
|
+
this.commitDrop(nextDropIndex);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static get observedAttributes() {
|
|
36
|
+
return ['items', 'variant', 'size', 'orientation', 'selectable', 'multi-select', 'show-drag-handle', 'show-drag-icon', 'full-width', 'disabled'];
|
|
37
|
+
}
|
|
38
|
+
get items() {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(this.getAttribute('items') || '[]');
|
|
41
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
set items(value) {
|
|
48
|
+
this.setAttribute('items', typeof value === 'string' ? value : JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
this.addEventListener('dragover', this.handleContainerDragOver);
|
|
52
|
+
this.addEventListener('drop', this.handleContainerDrop);
|
|
53
|
+
this.render();
|
|
54
|
+
}
|
|
55
|
+
disconnectedCallback() {
|
|
56
|
+
this.removeEventListener('dragover', this.handleContainerDragOver);
|
|
57
|
+
this.removeEventListener('drop', this.handleContainerDrop);
|
|
58
|
+
}
|
|
59
|
+
attributeChangedCallback() {
|
|
60
|
+
this.render();
|
|
61
|
+
}
|
|
62
|
+
getBool(name, fallback = false) {
|
|
63
|
+
if (!this.hasAttribute(name))
|
|
64
|
+
return fallback;
|
|
65
|
+
const value = this.getAttribute(name);
|
|
66
|
+
return value === '' || value === 'true';
|
|
67
|
+
}
|
|
68
|
+
getOption(name, values, fallback) {
|
|
69
|
+
const value = this.getAttribute(name);
|
|
70
|
+
return value && values.includes(value) ? value : fallback;
|
|
71
|
+
}
|
|
72
|
+
emitReorder(next) {
|
|
73
|
+
this.items = next;
|
|
74
|
+
this.dispatchEvent(new CustomEvent('db-reorder', { detail: { items: next }, bubbles: true, composed: true }));
|
|
75
|
+
}
|
|
76
|
+
getItemElements() {
|
|
77
|
+
return Array.from(this.children).filter((child) => child instanceof HTMLElement && child.classList.contains('designbase-wc-reorder__item'));
|
|
78
|
+
}
|
|
79
|
+
updateDragClasses() {
|
|
80
|
+
const orientation = this.getOption('orientation', ORIENTATIONS, 'vertical');
|
|
81
|
+
const hasActiveDrag = this.draggedIndex >= 0;
|
|
82
|
+
const itemCount = this.items.length;
|
|
83
|
+
const hasActiveDrop = hasActiveDrag && this.isValidDropIndex(this.dropIndex);
|
|
84
|
+
this.classList.toggle('designbase-wc-reorder--dragging', hasActiveDrag);
|
|
85
|
+
this.getItemElements().forEach((itemEl, index) => {
|
|
86
|
+
const isDragged = hasActiveDrag && this.draggedIndex === index;
|
|
87
|
+
const showBefore = hasActiveDrop && this.dropIndex === index;
|
|
88
|
+
const showAfterLast = hasActiveDrop && this.dropIndex === itemCount && index === itemCount - 1;
|
|
89
|
+
const isDragOver = showBefore || showAfterLast;
|
|
90
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--dragged', isDragged);
|
|
91
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--drag-over', isDragOver);
|
|
92
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--drag-down', showBefore && orientation === 'vertical');
|
|
93
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--drag-up', showAfterLast && orientation === 'vertical');
|
|
94
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--drag-right', showBefore && orientation === 'horizontal');
|
|
95
|
+
itemEl.classList.toggle('designbase-wc-reorder__item--drag-left', showAfterLast && orientation === 'horizontal');
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getAdjustedDropIndex(dropIndex = this.dropIndex) {
|
|
99
|
+
if (this.draggedIndex < 0 || dropIndex < 0)
|
|
100
|
+
return -1;
|
|
101
|
+
return dropIndex > this.draggedIndex ? dropIndex - 1 : dropIndex;
|
|
102
|
+
}
|
|
103
|
+
isValidDropIndex(dropIndex = this.dropIndex) {
|
|
104
|
+
const adjustedDropIndex = this.getAdjustedDropIndex(dropIndex);
|
|
105
|
+
return adjustedDropIndex >= 0 && adjustedDropIndex !== this.draggedIndex;
|
|
106
|
+
}
|
|
107
|
+
getDropIndexFromPointer(event, itemEl, index, orientation) {
|
|
108
|
+
const rect = itemEl.getBoundingClientRect();
|
|
109
|
+
const pointerOffset = orientation === 'horizontal' ? event.clientX - rect.left : event.clientY - rect.top;
|
|
110
|
+
const midpoint = orientation === 'horizontal' ? rect.width / 2 : rect.height / 2;
|
|
111
|
+
return pointerOffset < midpoint ? index : index + 1;
|
|
112
|
+
}
|
|
113
|
+
getDropIndexFromContainerPointer(event) {
|
|
114
|
+
const orientation = this.getOption('orientation', ORIENTATIONS, 'vertical');
|
|
115
|
+
const items = this.getItemElements();
|
|
116
|
+
if (items.length === 0)
|
|
117
|
+
return -1;
|
|
118
|
+
const pointerPosition = orientation === 'horizontal' ? event.clientX : event.clientY;
|
|
119
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
120
|
+
const rect = items[index].getBoundingClientRect();
|
|
121
|
+
const start = orientation === 'horizontal' ? rect.left : rect.top;
|
|
122
|
+
const size = orientation === 'horizontal' ? rect.width : rect.height;
|
|
123
|
+
if (pointerPosition < start + size / 2) {
|
|
124
|
+
return index;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return items.length;
|
|
128
|
+
}
|
|
129
|
+
commitDrop(dropIndex) {
|
|
130
|
+
const adjustedDropIndex = this.getAdjustedDropIndex(dropIndex);
|
|
131
|
+
if (this.draggedIndex < 0 || adjustedDropIndex < 0 || adjustedDropIndex === this.draggedIndex) {
|
|
132
|
+
this.resetDragState();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const copied = [...this.items];
|
|
136
|
+
const [moved] = copied.splice(this.draggedIndex, 1);
|
|
137
|
+
copied.splice(adjustedDropIndex, 0, moved);
|
|
138
|
+
this.draggedIndex = -1;
|
|
139
|
+
this.dropIndex = -1;
|
|
140
|
+
this.emitReorder(copied);
|
|
141
|
+
}
|
|
142
|
+
setDropIndex(index) {
|
|
143
|
+
if (this.dropIndex === index)
|
|
144
|
+
return;
|
|
145
|
+
this.dropIndex = index;
|
|
146
|
+
this.updateDragClasses();
|
|
147
|
+
}
|
|
148
|
+
resetDragState() {
|
|
149
|
+
this.draggedIndex = -1;
|
|
150
|
+
this.dropIndex = -1;
|
|
151
|
+
this.updateDragClasses();
|
|
152
|
+
}
|
|
153
|
+
render() {
|
|
154
|
+
const variant = this.getOption('variant', VARIANTS, 'default');
|
|
155
|
+
const size = this.getOption('size', SIZES, 'm');
|
|
156
|
+
const orientation = this.getOption('orientation', ORIENTATIONS, 'vertical');
|
|
157
|
+
const disabled = this.getBool('disabled');
|
|
158
|
+
const selectable = this.getBool('selectable');
|
|
159
|
+
const multiSelect = this.getBool('multi-select');
|
|
160
|
+
const showDragHandle = this.getBool('show-drag-handle', true);
|
|
161
|
+
const showDragIcon = this.getBool('show-drag-icon', true);
|
|
162
|
+
this.className = [
|
|
163
|
+
'designbase-wc-reorder',
|
|
164
|
+
`designbase-wc-reorder--${variant}`,
|
|
165
|
+
`designbase-wc-reorder--${size}`,
|
|
166
|
+
`designbase-wc-reorder--${orientation}`,
|
|
167
|
+
this.getBool('full-width') && 'designbase-wc-reorder--full-width',
|
|
168
|
+
disabled && 'designbase-wc-reorder--disabled',
|
|
169
|
+
selectable && 'designbase-wc-reorder--selectable',
|
|
170
|
+
]
|
|
171
|
+
.filter(Boolean)
|
|
172
|
+
.join(' ');
|
|
173
|
+
const fragment = document.createDocumentFragment();
|
|
174
|
+
this.items.forEach((item, index) => {
|
|
175
|
+
const itemEl = document.createElement('div');
|
|
176
|
+
const isDisabled = disabled || !!item.disabled;
|
|
177
|
+
const isDragged = this.draggedIndex === index;
|
|
178
|
+
const hasActiveDrop = this.draggedIndex >= 0 && this.isValidDropIndex(this.dropIndex);
|
|
179
|
+
const showBefore = hasActiveDrop && this.dropIndex === index;
|
|
180
|
+
const showAfterLast = hasActiveDrop && this.dropIndex === this.items.length && index === this.items.length - 1;
|
|
181
|
+
const isDragOver = showBefore || showAfterLast;
|
|
182
|
+
itemEl.className = [
|
|
183
|
+
'designbase-wc-reorder__item',
|
|
184
|
+
item.selected && 'designbase-wc-reorder__item--selected',
|
|
185
|
+
isDragged && 'designbase-wc-reorder__item--dragged',
|
|
186
|
+
isDisabled && 'designbase-wc-reorder__item--disabled',
|
|
187
|
+
isDragOver && 'designbase-wc-reorder__item--drag-over',
|
|
188
|
+
showBefore && orientation === 'vertical' && 'designbase-wc-reorder__item--drag-down',
|
|
189
|
+
showAfterLast && orientation === 'vertical' && 'designbase-wc-reorder__item--drag-up',
|
|
190
|
+
showBefore && orientation === 'horizontal' && 'designbase-wc-reorder__item--drag-right',
|
|
191
|
+
showAfterLast && orientation === 'horizontal' && 'designbase-wc-reorder__item--drag-left',
|
|
192
|
+
]
|
|
193
|
+
.filter(Boolean)
|
|
194
|
+
.join(' ');
|
|
195
|
+
itemEl.draggable = !isDisabled;
|
|
196
|
+
itemEl.addEventListener('dragstart', (event) => {
|
|
197
|
+
if (isDisabled)
|
|
198
|
+
return;
|
|
199
|
+
this.draggedIndex = index;
|
|
200
|
+
this.dropIndex = -1;
|
|
201
|
+
if (event.dataTransfer) {
|
|
202
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
203
|
+
event.dataTransfer.setData('text/plain', item.id);
|
|
204
|
+
}
|
|
205
|
+
this.updateDragClasses();
|
|
206
|
+
});
|
|
207
|
+
itemEl.addEventListener('dragover', (event) => {
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
if (event.dataTransfer) {
|
|
210
|
+
event.dataTransfer.dropEffect = 'move';
|
|
211
|
+
}
|
|
212
|
+
if (this.draggedIndex < 0) {
|
|
213
|
+
this.setDropIndex(-1);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const nextDropIndex = this.getDropIndexFromPointer(event, itemEl, index, orientation);
|
|
217
|
+
this.setDropIndex(this.isValidDropIndex(nextDropIndex) ? nextDropIndex : -1);
|
|
218
|
+
});
|
|
219
|
+
itemEl.addEventListener('dragleave', (event) => {
|
|
220
|
+
const rect = itemEl.getBoundingClientRect();
|
|
221
|
+
const x = event.clientX - rect.left;
|
|
222
|
+
const y = event.clientY - rect.top;
|
|
223
|
+
if (x < 0 || x > rect.width || y < 0 || y > rect.height) {
|
|
224
|
+
this.setDropIndex(-1);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
itemEl.addEventListener('drop', (event) => {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
const nextDropIndex = this.dropIndex >= 0
|
|
230
|
+
? this.dropIndex
|
|
231
|
+
: this.getDropIndexFromPointer(event, itemEl, index, orientation);
|
|
232
|
+
this.commitDrop(nextDropIndex);
|
|
233
|
+
});
|
|
234
|
+
itemEl.addEventListener('dragend', () => {
|
|
235
|
+
this.resetDragState();
|
|
236
|
+
});
|
|
237
|
+
if (showDragHandle && !isDisabled) {
|
|
238
|
+
const handle = document.createElement('div');
|
|
239
|
+
handle.className = 'designbase-wc-reorder__drag-handle';
|
|
240
|
+
handle.setAttribute('aria-hidden', 'true');
|
|
241
|
+
if (showDragIcon) {
|
|
242
|
+
const gripIcon = orientation === 'horizontal' ? 'grip-horizontal' : 'grip-vertical';
|
|
243
|
+
const gripSize = size === 's' ? 14 : size === 'l' ? 18 : 16;
|
|
244
|
+
handle.append(createDbIcon(gripIcon, gripSize));
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
handle.textContent = '≡';
|
|
248
|
+
}
|
|
249
|
+
itemEl.append(handle);
|
|
250
|
+
}
|
|
251
|
+
if (selectable) {
|
|
252
|
+
const checkbox = document.createElement('div');
|
|
253
|
+
checkbox.className = 'designbase-wc-reorder__checkbox';
|
|
254
|
+
const input = document.createElement('input');
|
|
255
|
+
input.type = multiSelect ? 'checkbox' : 'radio';
|
|
256
|
+
input.checked = !!item.selected;
|
|
257
|
+
input.disabled = isDisabled;
|
|
258
|
+
input.className = 'designbase-wc-reorder__checkbox-input';
|
|
259
|
+
input.addEventListener('change', () => {
|
|
260
|
+
const current = this.items;
|
|
261
|
+
const next = current.map((entry) => {
|
|
262
|
+
if (entry.id !== item.id) {
|
|
263
|
+
return multiSelect ? entry : { ...entry, selected: false };
|
|
264
|
+
}
|
|
265
|
+
return { ...entry, selected: multiSelect ? !entry.selected : true };
|
|
266
|
+
});
|
|
267
|
+
this.items = next;
|
|
268
|
+
this.dispatchEvent(new CustomEvent('db-select', { detail: { items: next.filter((entry) => entry.selected) }, bubbles: true, composed: true }));
|
|
269
|
+
this.render();
|
|
270
|
+
});
|
|
271
|
+
checkbox.append(input);
|
|
272
|
+
itemEl.append(checkbox);
|
|
273
|
+
}
|
|
274
|
+
const content = document.createElement('div');
|
|
275
|
+
content.className = 'designbase-wc-reorder__content';
|
|
276
|
+
content.textContent = item.content;
|
|
277
|
+
itemEl.append(content);
|
|
278
|
+
fragment.append(itemEl);
|
|
279
|
+
});
|
|
280
|
+
this.replaceChildren(fragment);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!customElements.get('db-reorder'))
|
|
284
|
+
customElements.define('db-reorder', DbReorder);
|
|
285
|
+
|
|
286
|
+
export { DbReorder };
|