@surreal-ui/web 0.8.0 → 0.9.0
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/LICENSE +21 -0
- package/dist/index.js +832 -6249
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +14 -0
- package/package.json +14 -3
- package/CHANGELOG.md +0 -142
- package/src/components/GlassmorphismAlert.ts +0 -115
- package/src/components/GlassmorphismButton.ts +0 -18
- package/src/components/GlassmorphismCard.ts +0 -36
- package/src/components/GlassmorphismEmptyState.ts +0 -35
- package/src/components/GlassmorphismInputGroup.ts +0 -205
- package/src/components/GlassmorphismMenubar.ts +0 -36
- package/src/components/GlassmorphismScrollArea.ts +0 -86
- package/src/components/GlassmorphismTable.ts +0 -52
- package/src/components/GlassmorphismTypography.ts +0 -70
- package/src/components/MinimalistAccordion.ts +0 -252
- package/src/components/MinimalistAlert.ts +0 -98
- package/src/components/MinimalistAlertDialog.ts +0 -102
- package/src/components/MinimalistAspectRatio.ts +0 -36
- package/src/components/MinimalistAvatar.ts +0 -97
- package/src/components/MinimalistBadge.ts +0 -70
- package/src/components/MinimalistBreadcrumb.ts +0 -92
- package/src/components/MinimalistButton.ts +0 -110
- package/src/components/MinimalistButtonGroup.ts +0 -112
- package/src/components/MinimalistCalendar.ts +0 -281
- package/src/components/MinimalistCard.ts +0 -130
- package/src/components/MinimalistCarousel.ts +0 -121
- package/src/components/MinimalistChart.ts +0 -150
- package/src/components/MinimalistCheckbox.ts +0 -178
- package/src/components/MinimalistCodeBlock.ts +0 -112
- package/src/components/MinimalistCollapsible.ts +0 -160
- package/src/components/MinimalistCommand.ts +0 -111
- package/src/components/MinimalistContextMenu.ts +0 -101
- package/src/components/MinimalistDialog.ts +0 -103
- package/src/components/MinimalistDrawer.ts +0 -222
- package/src/components/MinimalistDropdownMenu.ts +0 -125
- package/src/components/MinimalistEmpty.ts +0 -97
- package/src/components/MinimalistEmptyState.ts +0 -41
- package/src/components/MinimalistField.ts +0 -176
- package/src/components/MinimalistForm.ts +0 -102
- package/src/components/MinimalistHoverCard.ts +0 -149
- package/src/components/MinimalistInput.ts +0 -104
- package/src/components/MinimalistInputGroup.ts +0 -95
- package/src/components/MinimalistInputOtp.ts +0 -154
- package/src/components/MinimalistItem.ts +0 -159
- package/src/components/MinimalistKbd.ts +0 -37
- package/src/components/MinimalistLabel.ts +0 -53
- package/src/components/MinimalistMenubar.ts +0 -81
- package/src/components/MinimalistNativeSelect.ts +0 -149
- package/src/components/MinimalistNavigationMenu.ts +0 -103
- package/src/components/MinimalistPagination.ts +0 -140
- package/src/components/MinimalistPopover.ts +0 -112
- package/src/components/MinimalistProgress.ts +0 -70
- package/src/components/MinimalistRadioGroup.ts +0 -228
- package/src/components/MinimalistRangeCalendar.ts +0 -272
- package/src/components/MinimalistResizable.ts +0 -44
- package/src/components/MinimalistScrollArea.ts +0 -42
- package/src/components/MinimalistSelect.ts +0 -103
- package/src/components/MinimalistSeparator.ts +0 -52
- package/src/components/MinimalistSheet.ts +0 -165
- package/src/components/MinimalistSidebar.ts +0 -74
- package/src/components/MinimalistSkeleton.ts +0 -32
- package/src/components/MinimalistSlider.ts +0 -236
- package/src/components/MinimalistSonner.ts +0 -93
- package/src/components/MinimalistSpinner.ts +0 -52
- package/src/components/MinimalistSwitch.ts +0 -165
- package/src/components/MinimalistTable.ts +0 -35
- package/src/components/MinimalistTabs.ts +0 -97
- package/src/components/MinimalistTextarea.ts +0 -99
- package/src/components/MinimalistToggle.ts +0 -104
- package/src/components/MinimalistToggleGroup.ts +0 -177
- package/src/components/MinimalistTooltip.ts +0 -82
- package/src/components/MinimalistTypography.ts +0 -106
- package/src/components/NeubrutalismCard.ts +0 -35
- package/src/components/NeubrutalismItem.ts +0 -67
- package/src/components/ShadcnAccordion.ts +0 -248
- package/src/components/ShadcnAlertDialog.ts +0 -95
- package/src/components/ShadcnAspectRatio.ts +0 -29
- package/src/components/ShadcnAvatar.ts +0 -93
- package/src/components/ShadcnBadge.ts +0 -66
- package/src/components/ShadcnBreadcrumb.ts +0 -88
- package/src/components/ShadcnButton.ts +0 -106
- package/src/components/ShadcnButtonGroup.ts +0 -105
- package/src/components/ShadcnCalendar.ts +0 -277
- package/src/components/ShadcnCarousel.ts +0 -117
- package/src/components/ShadcnChart.ts +0 -146
- package/src/components/ShadcnCheckbox.ts +0 -174
- package/src/components/ShadcnCodeBlock.ts +0 -108
- package/src/components/ShadcnCollapsible.ts +0 -153
- package/src/components/ShadcnCommand.ts +0 -107
- package/src/components/ShadcnContextMenu.ts +0 -94
- package/src/components/ShadcnDialog.ts +0 -99
- package/src/components/ShadcnDrawer.ts +0 -218
- package/src/components/ShadcnDropdownMenu.ts +0 -118
- package/src/components/ShadcnEmpty.ts +0 -93
- package/src/components/ShadcnField.ts +0 -172
- package/src/components/ShadcnForm.ts +0 -98
- package/src/components/ShadcnHoverCard.ts +0 -145
- package/src/components/ShadcnInput.ts +0 -100
- package/src/components/ShadcnInputGroup.ts +0 -88
- package/src/components/ShadcnInputOtp.ts +0 -150
- package/src/components/ShadcnItem.ts +0 -155
- package/src/components/ShadcnKbd.ts +0 -33
- package/src/components/ShadcnLabel.ts +0 -49
- package/src/components/ShadcnMenubar.ts +0 -77
- package/src/components/ShadcnNativeSelect.ts +0 -142
- package/src/components/ShadcnNavigationMenu.ts +0 -96
- package/src/components/ShadcnPagination.ts +0 -136
- package/src/components/ShadcnPopover.ts +0 -108
- package/src/components/ShadcnProgress.ts +0 -66
- package/src/components/ShadcnRadioGroup.ts +0 -221
- package/src/components/ShadcnRangeCalendar.ts +0 -265
- package/src/components/ShadcnSelect.ts +0 -99
- package/src/components/ShadcnSeparator.ts +0 -48
- package/src/components/ShadcnSheet.ts +0 -161
- package/src/components/ShadcnSidebar.ts +0 -70
- package/src/components/ShadcnSkeleton.ts +0 -28
- package/src/components/ShadcnSlider.ts +0 -232
- package/src/components/ShadcnSonner.ts +0 -89
- package/src/components/ShadcnSpinner.ts +0 -48
- package/src/components/ShadcnSwitch.ts +0 -161
- package/src/components/ShadcnTabs.ts +0 -93
- package/src/components/ShadcnTextarea.ts +0 -95
- package/src/components/ShadcnToggle.ts +0 -100
- package/src/components/ShadcnToggleGroup.ts +0 -170
- package/src/components/ShadcnTooltip.ts +0 -78
- package/src/index.ts +0 -124
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
class SurrealShadcnCheckbox extends HTMLElement {
|
|
2
|
-
static get observedAttributes() {
|
|
3
|
-
return ['checked', 'indeterminate', 'disabled', 'required', 'name', 'value', 'class'];
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
private _button: HTMLButtonElement;
|
|
7
|
-
private _indicator: HTMLDivElement;
|
|
8
|
-
private _hiddenInput: HTMLInputElement | null = null;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this._button = document.createElement('button');
|
|
13
|
-
this._indicator = document.createElement('div');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
connectedCallback() {
|
|
17
|
-
this.render();
|
|
18
|
-
this._button.addEventListener('click', this._handleClick);
|
|
19
|
-
this._button.addEventListener('keydown', this._handleKeyDown);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
disconnectedCallback() {
|
|
23
|
-
this._button.removeEventListener('click', this._handleClick);
|
|
24
|
-
this._button.removeEventListener('keydown', this._handleKeyDown);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
28
|
-
if (oldValue !== newValue) {
|
|
29
|
-
this.updateState();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get checked(): boolean {
|
|
34
|
-
return this.hasAttribute('checked') && this.getAttribute('checked') !== 'false';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set checked(val: boolean) {
|
|
38
|
-
if (val) {
|
|
39
|
-
this.setAttribute('checked', '');
|
|
40
|
-
} else {
|
|
41
|
-
this.removeAttribute('checked');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get indeterminate(): boolean {
|
|
46
|
-
return this.hasAttribute('indeterminate');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
set indeterminate(val: boolean) {
|
|
50
|
-
if (val) {
|
|
51
|
-
this.setAttribute('indeterminate', '');
|
|
52
|
-
} else {
|
|
53
|
-
this.removeAttribute('indeterminate');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get disabled(): boolean {
|
|
58
|
-
return this.hasAttribute('disabled');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
set disabled(val: boolean) {
|
|
62
|
-
if (val) {
|
|
63
|
-
this.setAttribute('disabled', '');
|
|
64
|
-
} else {
|
|
65
|
-
this.removeAttribute('disabled');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private _handleClick = (e: MouseEvent) => {
|
|
70
|
-
if (this.disabled) {
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const nextChecked = this.indeterminate ? true : !this.checked;
|
|
76
|
-
this.indeterminate = false;
|
|
77
|
-
this.checked = nextChecked;
|
|
78
|
-
|
|
79
|
-
this.dispatchEvent(
|
|
80
|
-
new CustomEvent('change', {
|
|
81
|
-
detail: { checked: this.checked },
|
|
82
|
-
bubbles: true,
|
|
83
|
-
composed: true
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
private _handleKeyDown = (e: KeyboardEvent) => {
|
|
89
|
-
if (e.key === ' ') {
|
|
90
|
-
e.preventDefault();
|
|
91
|
-
this._handleClick(e as unknown as MouseEvent);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
private updateState() {
|
|
96
|
-
const isIndeterminate = this.indeterminate;
|
|
97
|
-
const isChecked = !isIndeterminate && this.checked;
|
|
98
|
-
const isDisabled = this.disabled;
|
|
99
|
-
const isRequired = this.hasAttribute('required');
|
|
100
|
-
const extraClasses = this.getAttribute('class') || '';
|
|
101
|
-
|
|
102
|
-
this._button.type = 'button';
|
|
103
|
-
this._button.setAttribute('role', 'checkbox');
|
|
104
|
-
this._button.setAttribute(
|
|
105
|
-
'aria-checked',
|
|
106
|
-
isIndeterminate ? 'mixed' : isChecked ? 'true' : 'false'
|
|
107
|
-
);
|
|
108
|
-
this._button.setAttribute('aria-required', isRequired ? 'true' : 'false');
|
|
109
|
-
this._button.setAttribute('data-slot', 'checkbox');
|
|
110
|
-
this._button.setAttribute(
|
|
111
|
-
'data-state',
|
|
112
|
-
isIndeterminate ? 'indeterminate' : isChecked ? 'checked' : 'unchecked'
|
|
113
|
-
);
|
|
114
|
-
this._button.disabled = isDisabled;
|
|
115
|
-
if (isDisabled) {
|
|
116
|
-
this._button.setAttribute('data-disabled', '');
|
|
117
|
-
} else {
|
|
118
|
-
this._button.removeAttribute('data-disabled');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this._button.className =
|
|
122
|
-
`peer relative inline-flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors group-has-disabled/field:opacity-50 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50 ${extraClasses}`.trim();
|
|
123
|
-
|
|
124
|
-
this._indicator.setAttribute('data-slot', 'checkbox-indicator');
|
|
125
|
-
this._indicator.className =
|
|
126
|
-
'[&>svg]:size-3.5 grid place-content-center text-current transition-none';
|
|
127
|
-
|
|
128
|
-
if (isChecked) {
|
|
129
|
-
this._indicator.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="size-3.5"><polyline points="20 6 9 17 4 12"/></svg>`;
|
|
130
|
-
} else if (isIndeterminate) {
|
|
131
|
-
this._indicator.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="size-3.5"><line x1="5" y1="12" x2="19" y2="12"/></svg>`;
|
|
132
|
-
} else {
|
|
133
|
-
this._indicator.innerHTML = '';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const name = this.getAttribute('name');
|
|
137
|
-
if (name) {
|
|
138
|
-
if (!this._hiddenInput) {
|
|
139
|
-
this._hiddenInput = document.createElement('input');
|
|
140
|
-
this._hiddenInput.type = 'checkbox';
|
|
141
|
-
this._hiddenInput.tabIndex = -1;
|
|
142
|
-
this._hiddenInput.setAttribute('aria-hidden', 'true');
|
|
143
|
-
this._hiddenInput.className = 'sr-only pointer-events-none';
|
|
144
|
-
this.appendChild(this._hiddenInput);
|
|
145
|
-
}
|
|
146
|
-
this._hiddenInput.name = name;
|
|
147
|
-
this._hiddenInput.value = this.getAttribute('value') || 'on';
|
|
148
|
-
this._hiddenInput.checked = isChecked;
|
|
149
|
-
this._hiddenInput.disabled = isDisabled;
|
|
150
|
-
this._hiddenInput.required = isRequired;
|
|
151
|
-
} else if (this._hiddenInput) {
|
|
152
|
-
this._hiddenInput.remove();
|
|
153
|
-
this._hiddenInput = null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private render() {
|
|
158
|
-
if (!this.contains(this._button)) {
|
|
159
|
-
this.innerHTML = '';
|
|
160
|
-
this._button.appendChild(this._indicator);
|
|
161
|
-
this.appendChild(this._button);
|
|
162
|
-
}
|
|
163
|
-
this.updateState();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-checkbox')) {
|
|
168
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-checkbox')) {
|
|
169
|
-
customElements.define('surreal-shadcn-checkbox', SurrealShadcnCheckbox);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export { SurrealShadcnCheckbox };
|
|
174
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-checkbox')) {
|
|
175
|
-
customElements.define('surreal-minimalist-checkbox', SurrealShadcnCheckbox);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export default SurrealShadcnCheckbox;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
class SurrealShadcnCodeBlock extends HTMLElement {
|
|
2
|
-
static get observedAttributes() {
|
|
3
|
-
return ['code', 'language', 'show-line-numbers', 'wrap'];
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
this._code = '';
|
|
9
|
-
this._language = 'plaintext';
|
|
10
|
-
this._showLineNumbers = false;
|
|
11
|
-
this._wrap = false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get code() {
|
|
15
|
-
return this._code;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
set code(val) {
|
|
19
|
-
this._code = val;
|
|
20
|
-
this.setAttribute('code', val);
|
|
21
|
-
this.render();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
connectedCallback() {
|
|
25
|
-
this._code = this.getAttribute('code') || this.textContent || '';
|
|
26
|
-
this._language = this.getAttribute('language') || 'plaintext';
|
|
27
|
-
this._showLineNumbers = this.hasAttribute('show-line-numbers');
|
|
28
|
-
this._wrap = this.hasAttribute('wrap');
|
|
29
|
-
this.render();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
33
|
-
if (oldValue === newValue) return;
|
|
34
|
-
if (name === 'code') this._code = newValue || '';
|
|
35
|
-
if (name === 'language') this._language = newValue || 'plaintext';
|
|
36
|
-
if (name === 'show-line-numbers') this._showLineNumbers = newValue !== null;
|
|
37
|
-
if (name === 'wrap') this._wrap = newValue !== null;
|
|
38
|
-
this.render();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
render() {
|
|
42
|
-
const escaped = (this._code || '')
|
|
43
|
-
.replace(/&/g, '&')
|
|
44
|
-
.replace(/</g, '<')
|
|
45
|
-
.replace(/>/g, '>');
|
|
46
|
-
|
|
47
|
-
const lines = escaped.split('\n');
|
|
48
|
-
const formattedLines = this._showLineNumbers
|
|
49
|
-
? lines
|
|
50
|
-
.map(
|
|
51
|
-
(line, idx) =>
|
|
52
|
-
`<span class="inline-block min-w-10 mr-4 text-right select-none text-muted-foreground">${idx + 1}</span>${line}`
|
|
53
|
-
)
|
|
54
|
-
.join('\n')
|
|
55
|
-
: escaped;
|
|
56
|
-
|
|
57
|
-
const wrapClass = this._wrap ? 'whitespace-pre-wrap break-words' : 'overflow-x-auto';
|
|
58
|
-
|
|
59
|
-
this.className =
|
|
60
|
-
'group relative block w-full overflow-hidden rounded-md border border-border bg-background text-foreground font-mono text-sm';
|
|
61
|
-
this.innerHTML = `
|
|
62
|
-
<div class="relative">
|
|
63
|
-
<div class="overflow-auto p-4 text-sm font-mono ${wrapClass}">
|
|
64
|
-
<pre class="m-0 text-foreground font-mono text-sm"><code>${formattedLines}</code></pre>
|
|
65
|
-
</div>
|
|
66
|
-
<div class="absolute top-2 right-2 flex items-center gap-2 z-10">
|
|
67
|
-
<slot name="actions">
|
|
68
|
-
<button type="button" class="surreal-code-copy-btn inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground h-8 w-8 text-muted-foreground hover:text-foreground" title="Copy to clipboard">
|
|
69
|
-
<svg class="copy-icon h-4 w-4" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
|
|
70
|
-
<svg class="check-icon h-4 w-4 text-emerald-500 hidden" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
|
|
71
|
-
</button>
|
|
72
|
-
</slot>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
const copyBtn = this.querySelector('.surreal-code-copy-btn');
|
|
78
|
-
if (copyBtn) {
|
|
79
|
-
copyBtn.addEventListener('click', async () => {
|
|
80
|
-
try {
|
|
81
|
-
await navigator.clipboard.writeText(this._code);
|
|
82
|
-
const copyIcon = copyBtn.querySelector('.copy-icon');
|
|
83
|
-
const checkIcon = copyBtn.querySelector('.check-icon');
|
|
84
|
-
if (copyIcon && checkIcon) {
|
|
85
|
-
copyIcon.classList.add('hidden');
|
|
86
|
-
checkIcon.classList.remove('hidden');
|
|
87
|
-
setTimeout(() => {
|
|
88
|
-
copyIcon.classList.remove('hidden');
|
|
89
|
-
checkIcon.classList.add('hidden');
|
|
90
|
-
}, 2000);
|
|
91
|
-
}
|
|
92
|
-
this.dispatchEvent(new CustomEvent('copy', { detail: { code: this._code } }));
|
|
93
|
-
} catch (err) {
|
|
94
|
-
this.dispatchEvent(new CustomEvent('error', { detail: err }));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-code-block')) {
|
|
102
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-code-block')) {
|
|
103
|
-
customElements.define('surreal-shadcn-code-block', SurrealShadcnCodeBlock);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
export { SurrealShadcnCodeBlock as MinimalistCodeBlock, SurrealShadcnCodeBlock };
|
|
107
|
-
|
|
108
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-code-block')) {
|
|
109
|
-
customElements.define('surreal-minimalist-code-block', SurrealShadcnCodeBlock);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export default SurrealShadcnCodeBlock;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
export class SurrealShadcnCollapsible extends HTMLElement {
|
|
2
|
-
private _open = false;
|
|
3
|
-
private _disabled = false;
|
|
4
|
-
|
|
5
|
-
static get observedAttributes() {
|
|
6
|
-
return ['open', 'disabled'];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
connectedCallback() {
|
|
10
|
-
this.setAttribute('data-slot', 'collapsible');
|
|
11
|
-
this._upgradeProperty('open');
|
|
12
|
-
this._upgradeProperty('disabled');
|
|
13
|
-
this._syncState();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null) {
|
|
17
|
-
if (oldValue === newValue) return;
|
|
18
|
-
if (name === 'open') {
|
|
19
|
-
this._open = newValue !== null;
|
|
20
|
-
} else if (name === 'disabled') {
|
|
21
|
-
this._disabled = newValue !== null;
|
|
22
|
-
}
|
|
23
|
-
this._syncState();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get open() {
|
|
27
|
-
return this._open;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
set open(value: boolean) {
|
|
31
|
-
if (value) {
|
|
32
|
-
this.setAttribute('open', '');
|
|
33
|
-
} else {
|
|
34
|
-
this.removeAttribute('open');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get disabled() {
|
|
39
|
-
return this._disabled;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set disabled(value: boolean) {
|
|
43
|
-
if (value) {
|
|
44
|
-
this.setAttribute('disabled', '');
|
|
45
|
-
} else {
|
|
46
|
-
this.removeAttribute('disabled');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public toggle() {
|
|
51
|
-
if (this._disabled) return;
|
|
52
|
-
this.open = !this.open;
|
|
53
|
-
this.dispatchEvent(
|
|
54
|
-
new CustomEvent('openchange', { detail: { open: this.open }, bubbles: true })
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private _upgradeProperty(prop: string) {
|
|
59
|
-
if (Object.prototype.hasOwnProperty.call(this, prop)) {
|
|
60
|
-
const value = (this as any)[prop];
|
|
61
|
-
delete (this as any)[prop];
|
|
62
|
-
(this as any)[prop] = value;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private _syncState() {
|
|
67
|
-
const state = this._open ? 'open' : 'closed';
|
|
68
|
-
this.setAttribute('data-state', state);
|
|
69
|
-
if (this._disabled) {
|
|
70
|
-
this.setAttribute('data-disabled', '');
|
|
71
|
-
} else {
|
|
72
|
-
this.removeAttribute('data-disabled');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const triggers = this.querySelectorAll(
|
|
76
|
-
'surreal-collapsible-trigger, [data-slot="collapsible-trigger"]'
|
|
77
|
-
);
|
|
78
|
-
triggers.forEach((trigger) => {
|
|
79
|
-
trigger.setAttribute('data-state', state);
|
|
80
|
-
trigger.setAttribute('aria-expanded', String(this._open));
|
|
81
|
-
if (this._disabled) trigger.setAttribute('disabled', '');
|
|
82
|
-
else trigger.removeAttribute('disabled');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const contents = this.querySelectorAll(
|
|
86
|
-
'surreal-collapsible-content, [data-slot="collapsible-content"]'
|
|
87
|
-
);
|
|
88
|
-
contents.forEach((content) => {
|
|
89
|
-
content.setAttribute('data-state', state);
|
|
90
|
-
if (this._open) {
|
|
91
|
-
(content as HTMLElement).style.display = '';
|
|
92
|
-
} else {
|
|
93
|
-
(content as HTMLElement).style.display = 'none';
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export class SurrealShadcnCollapsibleTrigger extends HTMLElement {
|
|
100
|
-
connectedCallback() {
|
|
101
|
-
this.setAttribute('data-slot', 'collapsible-trigger');
|
|
102
|
-
this.setAttribute('role', 'button');
|
|
103
|
-
this.setAttribute('tabindex', '0');
|
|
104
|
-
this.addEventListener('click', this._handleClick);
|
|
105
|
-
this.addEventListener('keydown', this._handleKeyDown);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
disconnectedCallback() {
|
|
109
|
-
this.removeEventListener('click', this._handleClick);
|
|
110
|
-
this.removeEventListener('keydown', this._handleKeyDown);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private _handleClick = (e: MouseEvent) => {
|
|
114
|
-
if (this.hasAttribute('disabled')) return;
|
|
115
|
-
const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
|
|
116
|
-
parent?.toggle();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
private _handleKeyDown = (e: KeyboardEvent) => {
|
|
120
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
if (!this.hasAttribute('disabled')) {
|
|
123
|
-
const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
|
|
124
|
-
parent?.toggle();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export class SurrealShadcnCollapsibleContent extends HTMLElement {
|
|
131
|
-
connectedCallback() {
|
|
132
|
-
this.setAttribute('data-slot', 'collapsible-content');
|
|
133
|
-
const parent = this.closest('surreal-collapsible') as SurrealShadcnCollapsible | null;
|
|
134
|
-
if (parent && !parent.open) {
|
|
135
|
-
this.style.display = 'none';
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (typeof customElements !== 'undefined') {
|
|
141
|
-
if (!customElements.get('surreal-collapsible'))
|
|
142
|
-
if (
|
|
143
|
-
typeof customElements !== 'undefined' &&
|
|
144
|
-
!customElements.get('surreal-shadcn-collapsible')
|
|
145
|
-
) {
|
|
146
|
-
customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsible);
|
|
147
|
-
}
|
|
148
|
-
if (!customElements.get('surreal-collapsible-trigger'))
|
|
149
|
-
customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleTrigger);
|
|
150
|
-
if (!customElements.get('surreal-collapsible-content'))
|
|
151
|
-
customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleContent);
|
|
152
|
-
}
|
|
153
|
-
if (
|
|
154
|
-
typeof customElements !== 'undefined' &&
|
|
155
|
-
!customElements.get('surreal-minimalist-collapsible')
|
|
156
|
-
) {
|
|
157
|
-
customElements.define('surreal-minimalist-collapsible', SurrealShadcnCollapsible);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export default SurrealShadcnCollapsible;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export class SurrealShadcnCommand extends HTMLElement {
|
|
2
|
-
private _searchInput: HTMLInputElement | null = null;
|
|
3
|
-
private _items: HTMLElement[] = [];
|
|
4
|
-
|
|
5
|
-
static get observedAttributes() {
|
|
6
|
-
return ['value'];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
connectedCallback() {
|
|
10
|
-
this.classList.add(
|
|
11
|
-
'rounded-xl',
|
|
12
|
-
'bg-popover',
|
|
13
|
-
'p-1',
|
|
14
|
-
'text-popover-foreground',
|
|
15
|
-
'flex',
|
|
16
|
-
'size-full',
|
|
17
|
-
'flex-col',
|
|
18
|
-
'overflow-hidden',
|
|
19
|
-
'border',
|
|
20
|
-
'border-border',
|
|
21
|
-
'shadow-md'
|
|
22
|
-
);
|
|
23
|
-
this.setAttribute('data-slot', 'command');
|
|
24
|
-
|
|
25
|
-
this.addEventListener('input', this.handleInput.bind(this));
|
|
26
|
-
this.addEventListener('keydown', this.handleKeydown.bind(this));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private handleInput(e: Event) {
|
|
30
|
-
const target = e.target as HTMLInputElement;
|
|
31
|
-
if (target && target.getAttribute('data-slot') === 'command-input') {
|
|
32
|
-
const query = target.value.toLowerCase().trim();
|
|
33
|
-
this.filterItems(query);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private filterItems(query: string) {
|
|
38
|
-
const items = Array.from(this.querySelectorAll('[data-slot="command-item"]')) as HTMLElement[];
|
|
39
|
-
const groups = Array.from(
|
|
40
|
-
this.querySelectorAll('[data-slot="command-group"]')
|
|
41
|
-
) as HTMLElement[];
|
|
42
|
-
const empty = this.querySelector('[data-slot="command-empty"]') as HTMLElement | null;
|
|
43
|
-
|
|
44
|
-
let visibleCount = 0;
|
|
45
|
-
|
|
46
|
-
items.forEach((item) => {
|
|
47
|
-
const text = (item.textContent || '').toLowerCase();
|
|
48
|
-
const matches = !query || text.includes(query);
|
|
49
|
-
item.style.display = matches ? 'flex' : 'none';
|
|
50
|
-
if (matches) visibleCount++;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
groups.forEach((group) => {
|
|
54
|
-
const groupItems = Array.from(
|
|
55
|
-
group.querySelectorAll('[data-slot="command-item"]')
|
|
56
|
-
) as HTMLElement[];
|
|
57
|
-
const hasVisible = groupItems.some((i) => i.style.display !== 'none');
|
|
58
|
-
group.style.display = hasVisible ? 'block' : 'none';
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (empty) {
|
|
62
|
-
empty.style.display = visibleCount === 0 ? 'block' : 'none';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private handleKeydown(e: KeyboardEvent) {
|
|
67
|
-
const items = Array.from(
|
|
68
|
-
this.querySelectorAll('[data-slot="command-item"]:not([data-disabled="true"])')
|
|
69
|
-
) as HTMLElement[];
|
|
70
|
-
const visibleItems = items.filter((i) => i.style.display !== 'none');
|
|
71
|
-
|
|
72
|
-
if (visibleItems.length === 0) return;
|
|
73
|
-
|
|
74
|
-
const currentIndex = visibleItems.findIndex((i) => i.getAttribute('data-selected') === 'true');
|
|
75
|
-
|
|
76
|
-
if (e.key === 'ArrowDown') {
|
|
77
|
-
e.preventDefault();
|
|
78
|
-
const nextIndex = (currentIndex + 1) % visibleItems.length;
|
|
79
|
-
this.setSelectedItem(visibleItems, nextIndex);
|
|
80
|
-
} else if (e.key === 'ArrowUp') {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
const prevIndex = (currentIndex - 1 + visibleItems.length) % visibleItems.length;
|
|
83
|
-
this.setSelectedItem(visibleItems, prevIndex);
|
|
84
|
-
} else if (e.key === 'Enter' && currentIndex >= 0) {
|
|
85
|
-
e.preventDefault();
|
|
86
|
-
visibleItems[currentIndex].click();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private setSelectedItem(items: HTMLElement[], index: number) {
|
|
91
|
-
items.forEach((item, idx) => {
|
|
92
|
-
if (idx === index) {
|
|
93
|
-
item.setAttribute('data-selected', 'true');
|
|
94
|
-
item.scrollIntoView({ block: 'nearest' });
|
|
95
|
-
} else {
|
|
96
|
-
item.removeAttribute('data-selected');
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!customElements.get('surreal-command')) {
|
|
103
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-command')) {
|
|
104
|
-
customElements.define('surreal-shadcn-command', SurrealShadcnCommand);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-command')) {
|
|
108
|
-
customElements.define('surreal-minimalist-command', SurrealShadcnCommand);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export default SurrealShadcnCommand;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
class SurrealShadcnContextMenu extends HTMLElement {
|
|
2
|
-
private triggerArea: HTMLElement | null = null;
|
|
3
|
-
private menuContent: HTMLElement | null = null;
|
|
4
|
-
private isOpen: boolean = false;
|
|
5
|
-
|
|
6
|
-
static get observedAttributes() {
|
|
7
|
-
return ['open'];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
connectedCallback() {
|
|
11
|
-
this.render();
|
|
12
|
-
this.attachEventListeners();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
disconnectedCallback() {
|
|
16
|
-
document.removeEventListener('pointerdown', this.handleOutsideClick);
|
|
17
|
-
document.removeEventListener('keydown', this.handleKeyDown);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
21
|
-
if (name === 'open' && oldValue !== newValue) {
|
|
22
|
-
this.isOpen = newValue !== null && newValue !== 'false';
|
|
23
|
-
this.updateMenuVisibility();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private render() {
|
|
28
|
-
this.triggerArea = this.querySelector('[data-slot="context-menu-trigger"]');
|
|
29
|
-
this.menuContent = this.querySelector('[data-slot="context-menu-content"]');
|
|
30
|
-
if (this.menuContent) {
|
|
31
|
-
this.menuContent.classList.add('hidden');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private attachEventListeners() {
|
|
36
|
-
this.addEventListener('contextmenu', (e: MouseEvent) => {
|
|
37
|
-
const target = e.target as HTMLElement;
|
|
38
|
-
if (this.triggerArea && (this.triggerArea === target || this.triggerArea.contains(target))) {
|
|
39
|
-
e.preventDefault();
|
|
40
|
-
this.openMenu(e.clientX, e.clientY);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
document.addEventListener('pointerdown', this.handleOutsideClick);
|
|
45
|
-
document.addEventListener('keydown', this.handleKeyDown);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private handleOutsideClick = (e: MouseEvent) => {
|
|
49
|
-
if (this.isOpen && this.menuContent && !this.menuContent.contains(e.target as Node)) {
|
|
50
|
-
this.closeMenu();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
private handleKeyDown = (e: KeyboardEvent) => {
|
|
55
|
-
if (e.key === 'Escape' && this.isOpen) {
|
|
56
|
-
this.closeMenu();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
private openMenu(x: number, y: number) {
|
|
61
|
-
if (!this.menuContent) return;
|
|
62
|
-
this.isOpen = true;
|
|
63
|
-
this.menuContent.classList.remove('hidden');
|
|
64
|
-
this.menuContent.style.position = 'fixed';
|
|
65
|
-
this.menuContent.style.left = `${x}px`;
|
|
66
|
-
this.menuContent.style.top = `${y}px`;
|
|
67
|
-
this.menuContent.style.zIndex = '50';
|
|
68
|
-
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: true } }));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private closeMenu() {
|
|
72
|
-
if (!this.menuContent) return;
|
|
73
|
-
this.isOpen = false;
|
|
74
|
-
this.menuContent.classList.add('hidden');
|
|
75
|
-
this.dispatchEvent(new CustomEvent('openchange', { detail: { open: false } }));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private updateMenuVisibility() {
|
|
79
|
-
if (this.isOpen) {
|
|
80
|
-
this.menuContent?.classList.remove('hidden');
|
|
81
|
-
} else {
|
|
82
|
-
this.menuContent?.classList.add('hidden');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-context-menu')) {
|
|
88
|
-
if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-context-menu')) {
|
|
89
|
-
customElements.define('surreal-shadcn-context-menu', SurrealShadcnContextMenu);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export { SurrealShadcnContextMenu as MinimalistContextMenu, SurrealShadcnContextMenu };
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
typeof customElements !== 'undefined' &&
|
|
96
|
-
!customElements.get('surreal-minimalist-context-menu')
|
|
97
|
-
) {
|
|
98
|
-
customElements.define('surreal-minimalist-context-menu', SurrealShadcnContextMenu);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default SurrealShadcnContextMenu;
|