@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.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +832 -6249
  3. package/dist/utils.d.ts +9 -0
  4. package/dist/utils.js +14 -0
  5. package/package.json +14 -3
  6. package/CHANGELOG.md +0 -142
  7. package/src/components/GlassmorphismAlert.ts +0 -115
  8. package/src/components/GlassmorphismButton.ts +0 -18
  9. package/src/components/GlassmorphismCard.ts +0 -36
  10. package/src/components/GlassmorphismEmptyState.ts +0 -35
  11. package/src/components/GlassmorphismInputGroup.ts +0 -205
  12. package/src/components/GlassmorphismMenubar.ts +0 -36
  13. package/src/components/GlassmorphismScrollArea.ts +0 -86
  14. package/src/components/GlassmorphismTable.ts +0 -52
  15. package/src/components/GlassmorphismTypography.ts +0 -70
  16. package/src/components/MinimalistAccordion.ts +0 -252
  17. package/src/components/MinimalistAlert.ts +0 -98
  18. package/src/components/MinimalistAlertDialog.ts +0 -102
  19. package/src/components/MinimalistAspectRatio.ts +0 -36
  20. package/src/components/MinimalistAvatar.ts +0 -97
  21. package/src/components/MinimalistBadge.ts +0 -70
  22. package/src/components/MinimalistBreadcrumb.ts +0 -92
  23. package/src/components/MinimalistButton.ts +0 -110
  24. package/src/components/MinimalistButtonGroup.ts +0 -112
  25. package/src/components/MinimalistCalendar.ts +0 -281
  26. package/src/components/MinimalistCard.ts +0 -130
  27. package/src/components/MinimalistCarousel.ts +0 -121
  28. package/src/components/MinimalistChart.ts +0 -150
  29. package/src/components/MinimalistCheckbox.ts +0 -178
  30. package/src/components/MinimalistCodeBlock.ts +0 -112
  31. package/src/components/MinimalistCollapsible.ts +0 -160
  32. package/src/components/MinimalistCommand.ts +0 -111
  33. package/src/components/MinimalistContextMenu.ts +0 -101
  34. package/src/components/MinimalistDialog.ts +0 -103
  35. package/src/components/MinimalistDrawer.ts +0 -222
  36. package/src/components/MinimalistDropdownMenu.ts +0 -125
  37. package/src/components/MinimalistEmpty.ts +0 -97
  38. package/src/components/MinimalistEmptyState.ts +0 -41
  39. package/src/components/MinimalistField.ts +0 -176
  40. package/src/components/MinimalistForm.ts +0 -102
  41. package/src/components/MinimalistHoverCard.ts +0 -149
  42. package/src/components/MinimalistInput.ts +0 -104
  43. package/src/components/MinimalistInputGroup.ts +0 -95
  44. package/src/components/MinimalistInputOtp.ts +0 -154
  45. package/src/components/MinimalistItem.ts +0 -159
  46. package/src/components/MinimalistKbd.ts +0 -37
  47. package/src/components/MinimalistLabel.ts +0 -53
  48. package/src/components/MinimalistMenubar.ts +0 -81
  49. package/src/components/MinimalistNativeSelect.ts +0 -149
  50. package/src/components/MinimalistNavigationMenu.ts +0 -103
  51. package/src/components/MinimalistPagination.ts +0 -140
  52. package/src/components/MinimalistPopover.ts +0 -112
  53. package/src/components/MinimalistProgress.ts +0 -70
  54. package/src/components/MinimalistRadioGroup.ts +0 -228
  55. package/src/components/MinimalistRangeCalendar.ts +0 -272
  56. package/src/components/MinimalistResizable.ts +0 -44
  57. package/src/components/MinimalistScrollArea.ts +0 -42
  58. package/src/components/MinimalistSelect.ts +0 -103
  59. package/src/components/MinimalistSeparator.ts +0 -52
  60. package/src/components/MinimalistSheet.ts +0 -165
  61. package/src/components/MinimalistSidebar.ts +0 -74
  62. package/src/components/MinimalistSkeleton.ts +0 -32
  63. package/src/components/MinimalistSlider.ts +0 -236
  64. package/src/components/MinimalistSonner.ts +0 -93
  65. package/src/components/MinimalistSpinner.ts +0 -52
  66. package/src/components/MinimalistSwitch.ts +0 -165
  67. package/src/components/MinimalistTable.ts +0 -35
  68. package/src/components/MinimalistTabs.ts +0 -97
  69. package/src/components/MinimalistTextarea.ts +0 -99
  70. package/src/components/MinimalistToggle.ts +0 -104
  71. package/src/components/MinimalistToggleGroup.ts +0 -177
  72. package/src/components/MinimalistTooltip.ts +0 -82
  73. package/src/components/MinimalistTypography.ts +0 -106
  74. package/src/components/NeubrutalismCard.ts +0 -35
  75. package/src/components/NeubrutalismItem.ts +0 -67
  76. package/src/components/ShadcnAccordion.ts +0 -248
  77. package/src/components/ShadcnAlertDialog.ts +0 -95
  78. package/src/components/ShadcnAspectRatio.ts +0 -29
  79. package/src/components/ShadcnAvatar.ts +0 -93
  80. package/src/components/ShadcnBadge.ts +0 -66
  81. package/src/components/ShadcnBreadcrumb.ts +0 -88
  82. package/src/components/ShadcnButton.ts +0 -106
  83. package/src/components/ShadcnButtonGroup.ts +0 -105
  84. package/src/components/ShadcnCalendar.ts +0 -277
  85. package/src/components/ShadcnCarousel.ts +0 -117
  86. package/src/components/ShadcnChart.ts +0 -146
  87. package/src/components/ShadcnCheckbox.ts +0 -174
  88. package/src/components/ShadcnCodeBlock.ts +0 -108
  89. package/src/components/ShadcnCollapsible.ts +0 -153
  90. package/src/components/ShadcnCommand.ts +0 -107
  91. package/src/components/ShadcnContextMenu.ts +0 -94
  92. package/src/components/ShadcnDialog.ts +0 -99
  93. package/src/components/ShadcnDrawer.ts +0 -218
  94. package/src/components/ShadcnDropdownMenu.ts +0 -118
  95. package/src/components/ShadcnEmpty.ts +0 -93
  96. package/src/components/ShadcnField.ts +0 -172
  97. package/src/components/ShadcnForm.ts +0 -98
  98. package/src/components/ShadcnHoverCard.ts +0 -145
  99. package/src/components/ShadcnInput.ts +0 -100
  100. package/src/components/ShadcnInputGroup.ts +0 -88
  101. package/src/components/ShadcnInputOtp.ts +0 -150
  102. package/src/components/ShadcnItem.ts +0 -155
  103. package/src/components/ShadcnKbd.ts +0 -33
  104. package/src/components/ShadcnLabel.ts +0 -49
  105. package/src/components/ShadcnMenubar.ts +0 -77
  106. package/src/components/ShadcnNativeSelect.ts +0 -142
  107. package/src/components/ShadcnNavigationMenu.ts +0 -96
  108. package/src/components/ShadcnPagination.ts +0 -136
  109. package/src/components/ShadcnPopover.ts +0 -108
  110. package/src/components/ShadcnProgress.ts +0 -66
  111. package/src/components/ShadcnRadioGroup.ts +0 -221
  112. package/src/components/ShadcnRangeCalendar.ts +0 -265
  113. package/src/components/ShadcnSelect.ts +0 -99
  114. package/src/components/ShadcnSeparator.ts +0 -48
  115. package/src/components/ShadcnSheet.ts +0 -161
  116. package/src/components/ShadcnSidebar.ts +0 -70
  117. package/src/components/ShadcnSkeleton.ts +0 -28
  118. package/src/components/ShadcnSlider.ts +0 -232
  119. package/src/components/ShadcnSonner.ts +0 -89
  120. package/src/components/ShadcnSpinner.ts +0 -48
  121. package/src/components/ShadcnSwitch.ts +0 -161
  122. package/src/components/ShadcnTabs.ts +0 -93
  123. package/src/components/ShadcnTextarea.ts +0 -95
  124. package/src/components/ShadcnToggle.ts +0 -100
  125. package/src/components/ShadcnToggleGroup.ts +0 -170
  126. package/src/components/ShadcnTooltip.ts +0 -78
  127. package/src/index.ts +0 -124
@@ -1,117 +0,0 @@
1
- class SurrealShadcnCarousel extends HTMLElement {
2
- private container: HTMLElement | null = null;
3
- private prevButton: HTMLElement | null = null;
4
- private nextButton: HTMLElement | null = null;
5
-
6
- static get observedAttributes() {
7
- return ['orientation'];
8
- }
9
-
10
- constructor() {
11
- super();
12
- }
13
-
14
- get orientation(): 'horizontal' | 'vertical' {
15
- return (this.getAttribute('orientation') as 'horizontal' | 'vertical') || 'horizontal';
16
- }
17
-
18
- connectedCallback() {
19
- this.setAttribute('data-slot', 'carousel');
20
- this.setAttribute('role', 'region');
21
- this.setAttribute('aria-roledescription', 'carousel');
22
- this.classList.add('relative', 'block');
23
-
24
- this.setupListeners();
25
- }
26
-
27
- private setupListeners() {
28
- this.container = this.querySelector(
29
- '[data-slot="carousel-content"] > [data-embla-container], [data-embla-container]'
30
- );
31
- this.prevButton = this.querySelector('[data-slot="carousel-previous"]');
32
- this.nextButton = this.querySelector('[data-slot="carousel-next"]');
33
-
34
- if (this.prevButton) {
35
- this.prevButton.addEventListener('click', () => this.scrollPrev());
36
- }
37
- if (this.nextButton) {
38
- this.nextButton.addEventListener('click', () => this.scrollNext());
39
- }
40
-
41
- if (this.container) {
42
- this.container.addEventListener('scroll', () => this.updateScrollState());
43
- this.updateScrollState();
44
- }
45
-
46
- this.addEventListener('keydown', (e: KeyboardEvent) => {
47
- if (e.key === 'ArrowLeft' || (this.orientation === 'vertical' && e.key === 'ArrowUp')) {
48
- e.preventDefault();
49
- this.scrollPrev();
50
- } else if (
51
- e.key === 'ArrowRight' ||
52
- (this.orientation === 'vertical' && e.key === 'ArrowDown')
53
- ) {
54
- e.preventDefault();
55
- this.scrollNext();
56
- }
57
- });
58
- }
59
-
60
- public scrollPrev() {
61
- if (!this.container) return;
62
- if (this.orientation === 'horizontal') {
63
- this.container.scrollBy({ left: -this.container.clientWidth, behavior: 'smooth' });
64
- } else {
65
- this.container.scrollBy({ top: -this.container.clientHeight, behavior: 'smooth' });
66
- }
67
- }
68
-
69
- public scrollNext() {
70
- if (!this.container) return;
71
- if (this.orientation === 'horizontal') {
72
- this.container.scrollBy({ left: this.container.clientWidth, behavior: 'smooth' });
73
- } else {
74
- this.container.scrollBy({ top: this.container.clientHeight, behavior: 'smooth' });
75
- }
76
- }
77
-
78
- private updateScrollState() {
79
- if (!this.container) return;
80
- const isHoriz = this.orientation === 'horizontal';
81
- const canPrev = isHoriz ? this.container.scrollLeft > 2 : this.container.scrollTop > 2;
82
- const maxScroll = isHoriz
83
- ? this.container.scrollWidth - this.container.clientWidth
84
- : this.container.scrollHeight - this.container.clientHeight;
85
- const canNext = isHoriz
86
- ? this.container.scrollLeft < maxScroll - 2
87
- : this.container.scrollTop < maxScroll - 2;
88
-
89
- if (this.prevButton) {
90
- if (canPrev) {
91
- this.prevButton.removeAttribute('disabled');
92
- this.prevButton.setAttribute('aria-disabled', 'false');
93
- } else {
94
- this.prevButton.setAttribute('disabled', 'true');
95
- this.prevButton.setAttribute('aria-disabled', 'true');
96
- }
97
- }
98
- if (this.nextButton) {
99
- if (canNext) {
100
- this.nextButton.removeAttribute('disabled');
101
- this.nextButton.setAttribute('aria-disabled', 'false');
102
- } else {
103
- this.nextButton.setAttribute('disabled', 'true');
104
- this.nextButton.setAttribute('aria-disabled', 'true');
105
- }
106
- }
107
- }
108
- }
109
-
110
- if (!customElements.get('surreal-carousel')) {
111
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-carousel')) {
112
- customElements.define('surreal-shadcn-carousel', SurrealShadcnCarousel);
113
- }
114
- }
115
- export { SurrealShadcnCarousel as ShadcnCarousel, SurrealShadcnCarousel };
116
-
117
- export default SurrealShadcnCarousel;
@@ -1,146 +0,0 @@
1
- class SurrealShadcnChartContainer extends HTMLElement {
2
- private styleTag: HTMLStyleElement | null = null;
3
-
4
- static get observedAttributes() {
5
- return ['config', 'chart-id'];
6
- }
7
-
8
- connectedCallback() {
9
- this.render();
10
- }
11
-
12
- attributeChangedCallback() {
13
- this.applyConfigStyles();
14
- }
15
-
16
- private get configData() {
17
- try {
18
- const attr = this.getAttribute('config');
19
- return attr ? JSON.parse(attr) : {};
20
- } catch {
21
- return {};
22
- }
23
- }
24
-
25
- private applyConfigStyles() {
26
- const id = this.getAttribute('chart-id') || 'chart-root';
27
- this.setAttribute('data-chart', id);
28
- this.setAttribute('data-slot', 'chart');
29
-
30
- const config = this.configData;
31
- const entries = Object.entries(config);
32
-
33
- if (!this.styleTag) {
34
- this.styleTag = document.createElement('style');
35
- this.prepend(this.styleTag);
36
- }
37
-
38
- if (!entries.length) {
39
- this.styleTag.textContent = '';
40
- return;
41
- }
42
-
43
- let css = `[data-chart="${id}"] {\n`;
44
- for (const [key, val] of entries) {
45
- const item = val as { color?: string; theme?: Record<string, string> };
46
- if (item.color) {
47
- css += ` --color-${key}: ${item.color};\n`;
48
- }
49
- }
50
- css += '}\n';
51
-
52
- css += `.dark [data-chart="${id}"] {\n`;
53
- for (const [key, val] of entries) {
54
- const item = val as { color?: string; theme?: Record<string, string> };
55
- const darkColor = item.theme?.dark || item.color;
56
- if (darkColor) {
57
- css += ` --color-${key}: ${darkColor};\n`;
58
- }
59
- }
60
- css += '}\n';
61
-
62
- this.styleTag.textContent = css;
63
- }
64
-
65
- render() {
66
- this.className = [
67
- 'flex aspect-video justify-center overflow-visible text-xs w-full',
68
- this.className
69
- ].join(' ');
70
- this.applyConfigStyles();
71
- }
72
- }
73
-
74
- class SurrealShadcnChartTooltip extends HTMLElement {
75
- static get observedAttributes() {
76
- return ['label', 'payload', 'indicator'];
77
- }
78
-
79
- connectedCallback() {
80
- this.render();
81
- }
82
-
83
- attributeChangedCallback() {
84
- this.render();
85
- }
86
-
87
- render() {
88
- const label = this.getAttribute('label') || '';
89
- const indicator = this.getAttribute('indicator') || 'dot';
90
- let payload: Array<{ key?: string; name?: string; value?: number; color?: string }> = [];
91
-
92
- try {
93
- const rawPayload = this.getAttribute('payload');
94
- if (rawPayload) payload = JSON.parse(rawPayload);
95
- } catch {}
96
-
97
- this.setAttribute('data-slot', 'chart-tooltip');
98
- this.className = [
99
- 'grid min-w-[9rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl',
100
- this.className
101
- ].join(' ');
102
-
103
- let html = '';
104
- if (label) {
105
- html += `<div class="font-medium text-foreground">${label}</div>`;
106
- }
107
-
108
- html += '<div class="grid gap-1.5">';
109
- payload.forEach((item) => {
110
- const itemName = item.name || item.key || 'value';
111
- const itemVal = item.value !== undefined ? Number(item.value).toLocaleString() : '';
112
- const color = item.color || 'var(--primary)';
113
-
114
- let indicatorClass = 'size-2.5 rounded-[2px] shrink-0';
115
- if (indicator === 'line') indicatorClass = 'h-3.5 w-1 rounded-[2px] shrink-0';
116
- if (indicator === 'dashed')
117
- indicatorClass = 'w-0 border-[1.5px] border-dashed bg-transparent shrink-0';
118
-
119
- html += `
120
- <div class="flex w-full items-center gap-2">
121
- <div class="${indicatorClass}" style="background-color: ${indicator === 'dashed' ? 'transparent' : color}; border-color: ${color};"></div>
122
- <div class="flex flex-1 justify-between items-center leading-none">
123
- <span class="text-muted-foreground">${itemName}</span>
124
- <span class="font-mono font-medium text-foreground tabular-nums">${itemVal}</span>
125
- </div>
126
- </div>
127
- `;
128
- });
129
- html += '</div>';
130
-
131
- this.innerHTML = html;
132
- }
133
- }
134
-
135
- if (!customElements.get('surreal-chart-container')) {
136
- if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-chart')) {
137
- customElements.define('surreal-shadcn-chart', SurrealShadcnChartContainer);
138
- }
139
- }
140
-
141
- if (!customElements.get('surreal-chart-tooltip')) {
142
- customElements.define('surreal-shadcn-chart', SurrealShadcnChartTooltip);
143
- }
144
- export { SurrealShadcnChartContainer as ShadcnChart, SurrealShadcnChartContainer };
145
-
146
- export default SurrealShadcnChartContainer;
@@ -1,174 +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
- export default SurrealShadcnCheckbox;
@@ -1,108 +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, '&amp;')
44
- .replace(/</g, '&lt;')
45
- .replace(/>/g, '&gt;');
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 ShadcnCodeBlock, SurrealShadcnCodeBlock };
107
-
108
- export default SurrealShadcnCodeBlock;
@@ -1,153 +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
- export default SurrealShadcnCollapsible;