@surreal-ui/web 0.5.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 (124) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +12075 -0
  3. package/package.json +27 -0
  4. package/src/components/GlassmorphismAlert.ts +116 -0
  5. package/src/components/GlassmorphismButton.ts +19 -0
  6. package/src/components/GlassmorphismCard.ts +33 -0
  7. package/src/components/GlassmorphismEmptyState.ts +29 -0
  8. package/src/components/GlassmorphismInputGroup.ts +202 -0
  9. package/src/components/GlassmorphismMenubar.ts +36 -0
  10. package/src/components/GlassmorphismScrollArea.ts +83 -0
  11. package/src/components/GlassmorphismTable.ts +52 -0
  12. package/src/components/GlassmorphismTypography.ts +67 -0
  13. package/src/components/MinimalistAccordion.ts +248 -0
  14. package/src/components/MinimalistAlert.ts +99 -0
  15. package/src/components/MinimalistAlertDialog.ts +100 -0
  16. package/src/components/MinimalistAspectRatio.ts +34 -0
  17. package/src/components/MinimalistAvatar.ts +98 -0
  18. package/src/components/MinimalistBadge.ts +71 -0
  19. package/src/components/MinimalistBreadcrumb.ts +92 -0
  20. package/src/components/MinimalistButton.ts +111 -0
  21. package/src/components/MinimalistButtonGroup.ts +110 -0
  22. package/src/components/MinimalistCalendar.ts +282 -0
  23. package/src/components/MinimalistCard.ts +131 -0
  24. package/src/components/MinimalistCarousel.ts +122 -0
  25. package/src/components/MinimalistChart.ts +151 -0
  26. package/src/components/MinimalistCheckbox.ts +179 -0
  27. package/src/components/MinimalistCodeBlock.ts +113 -0
  28. package/src/components/MinimalistCollapsible.ts +155 -0
  29. package/src/components/MinimalistCommand.ts +112 -0
  30. package/src/components/MinimalistContextMenu.ts +99 -0
  31. package/src/components/MinimalistDialog.ts +104 -0
  32. package/src/components/MinimalistDrawer.ts +223 -0
  33. package/src/components/MinimalistDropdownMenu.ts +120 -0
  34. package/src/components/MinimalistEmpty.ts +98 -0
  35. package/src/components/MinimalistEmptyState.ts +38 -0
  36. package/src/components/MinimalistField.ts +171 -0
  37. package/src/components/MinimalistForm.ts +101 -0
  38. package/src/components/MinimalistHoverCard.ts +150 -0
  39. package/src/components/MinimalistInput.ts +105 -0
  40. package/src/components/MinimalistInputGroup.ts +93 -0
  41. package/src/components/MinimalistInputOtp.ts +155 -0
  42. package/src/components/MinimalistItem.ts +160 -0
  43. package/src/components/MinimalistKbd.ts +38 -0
  44. package/src/components/MinimalistLabel.ts +54 -0
  45. package/src/components/MinimalistMenubar.ts +82 -0
  46. package/src/components/MinimalistNativeSelect.ts +144 -0
  47. package/src/components/MinimalistNavigationMenu.ts +98 -0
  48. package/src/components/MinimalistPagination.ts +141 -0
  49. package/src/components/MinimalistPopover.ts +113 -0
  50. package/src/components/MinimalistProgress.ts +71 -0
  51. package/src/components/MinimalistRadioGroup.ts +226 -0
  52. package/src/components/MinimalistRangeCalendar.ts +267 -0
  53. package/src/components/MinimalistResizable.ts +44 -0
  54. package/src/components/MinimalistScrollArea.ts +11 -0
  55. package/src/components/MinimalistSelect.ts +104 -0
  56. package/src/components/MinimalistSeparator.ts +53 -0
  57. package/src/components/MinimalistSheet.ts +166 -0
  58. package/src/components/MinimalistSidebar.ts +75 -0
  59. package/src/components/MinimalistSkeleton.ts +33 -0
  60. package/src/components/MinimalistSlider.ts +237 -0
  61. package/src/components/MinimalistSonner.ts +94 -0
  62. package/src/components/MinimalistSpinner.ts +53 -0
  63. package/src/components/MinimalistSwitch.ts +166 -0
  64. package/src/components/MinimalistTable.ts +35 -0
  65. package/src/components/MinimalistTabs.ts +98 -0
  66. package/src/components/MinimalistTextarea.ts +100 -0
  67. package/src/components/MinimalistToggle.ts +105 -0
  68. package/src/components/MinimalistToggleGroup.ts +175 -0
  69. package/src/components/MinimalistTooltip.ts +83 -0
  70. package/src/components/MinimalistTypography.ts +107 -0
  71. package/src/components/NeubrutalismCard.ts +35 -0
  72. package/src/components/NeubrutalismItem.ts +67 -0
  73. package/src/components/ShadcnAccordion.ts +244 -0
  74. package/src/components/ShadcnAlertDialog.ts +96 -0
  75. package/src/components/ShadcnAspectRatio.ts +30 -0
  76. package/src/components/ShadcnAvatar.ts +94 -0
  77. package/src/components/ShadcnBadge.ts +67 -0
  78. package/src/components/ShadcnBreadcrumb.ts +88 -0
  79. package/src/components/ShadcnButton.ts +107 -0
  80. package/src/components/ShadcnButtonGroup.ts +106 -0
  81. package/src/components/ShadcnCalendar.ts +278 -0
  82. package/src/components/ShadcnCarousel.ts +118 -0
  83. package/src/components/ShadcnChart.ts +147 -0
  84. package/src/components/ShadcnCheckbox.ts +175 -0
  85. package/src/components/ShadcnCodeBlock.ts +109 -0
  86. package/src/components/ShadcnCollapsible.ts +151 -0
  87. package/src/components/ShadcnCommand.ts +108 -0
  88. package/src/components/ShadcnContextMenu.ts +95 -0
  89. package/src/components/ShadcnDialog.ts +100 -0
  90. package/src/components/ShadcnDrawer.ts +219 -0
  91. package/src/components/ShadcnDropdownMenu.ts +116 -0
  92. package/src/components/ShadcnEmpty.ts +94 -0
  93. package/src/components/ShadcnField.ts +167 -0
  94. package/src/components/ShadcnForm.ts +97 -0
  95. package/src/components/ShadcnHoverCard.ts +146 -0
  96. package/src/components/ShadcnInput.ts +101 -0
  97. package/src/components/ShadcnInputGroup.ts +89 -0
  98. package/src/components/ShadcnInputOtp.ts +151 -0
  99. package/src/components/ShadcnItem.ts +156 -0
  100. package/src/components/ShadcnKbd.ts +34 -0
  101. package/src/components/ShadcnLabel.ts +50 -0
  102. package/src/components/ShadcnMenubar.ts +78 -0
  103. package/src/components/ShadcnNativeSelect.ts +140 -0
  104. package/src/components/ShadcnNavigationMenu.ts +94 -0
  105. package/src/components/ShadcnPagination.ts +137 -0
  106. package/src/components/ShadcnPopover.ts +109 -0
  107. package/src/components/ShadcnProgress.ts +67 -0
  108. package/src/components/ShadcnRadioGroup.ts +222 -0
  109. package/src/components/ShadcnRangeCalendar.ts +263 -0
  110. package/src/components/ShadcnSelect.ts +100 -0
  111. package/src/components/ShadcnSeparator.ts +49 -0
  112. package/src/components/ShadcnSheet.ts +162 -0
  113. package/src/components/ShadcnSidebar.ts +71 -0
  114. package/src/components/ShadcnSkeleton.ts +29 -0
  115. package/src/components/ShadcnSlider.ts +233 -0
  116. package/src/components/ShadcnSonner.ts +90 -0
  117. package/src/components/ShadcnSpinner.ts +49 -0
  118. package/src/components/ShadcnSwitch.ts +162 -0
  119. package/src/components/ShadcnTabs.ts +94 -0
  120. package/src/components/ShadcnTextarea.ts +96 -0
  121. package/src/components/ShadcnToggle.ts +101 -0
  122. package/src/components/ShadcnToggleGroup.ts +171 -0
  123. package/src/components/ShadcnTooltip.ts +79 -0
  124. package/src/index.ts +124 -0
@@ -0,0 +1,113 @@
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, '&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
+
103
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-code-block')) {
104
+ customElements.define('surreal-shadcn-code-block', SurrealShadcnCodeBlock);
105
+ }
106
+ };
107
+ export { SurrealShadcnCodeBlock as MinimalistCodeBlock, SurrealShadcnCodeBlock };
108
+
109
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-code-block')) {
110
+ customElements.define('surreal-minimalist-code-block', SurrealShadcnCodeBlock);
111
+ }
112
+
113
+ export default SurrealShadcnCodeBlock;
@@ -0,0 +1,155 @@
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
+
143
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-collapsible')) {
144
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsible);
145
+ }
146
+ if (!customElements.get('surreal-collapsible-trigger'))
147
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleTrigger);
148
+ if (!customElements.get('surreal-collapsible-content'))
149
+ customElements.define('surreal-shadcn-collapsible', SurrealShadcnCollapsibleContent);
150
+ }
151
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-collapsible')) {
152
+ customElements.define('surreal-minimalist-collapsible', SurrealShadcnCollapsible);
153
+ }
154
+
155
+ export default SurrealShadcnCollapsible;
@@ -0,0 +1,112 @@
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
+
104
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-command')) {
105
+ customElements.define('surreal-shadcn-command', SurrealShadcnCommand);
106
+ }
107
+ }
108
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-command')) {
109
+ customElements.define('surreal-minimalist-command', SurrealShadcnCommand);
110
+ }
111
+
112
+ export default SurrealShadcnCommand;
@@ -0,0 +1,99 @@
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
+
89
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-context-menu')) {
90
+ customElements.define('surreal-shadcn-context-menu', SurrealShadcnContextMenu);
91
+ }
92
+ };
93
+ export { SurrealShadcnContextMenu as MinimalistContextMenu, SurrealShadcnContextMenu };
94
+
95
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-context-menu')) {
96
+ customElements.define('surreal-minimalist-context-menu', SurrealShadcnContextMenu);
97
+ }
98
+
99
+ export default SurrealShadcnContextMenu;
@@ -0,0 +1,104 @@
1
+ class SurrealShadcnDialog extends HTMLElement {
2
+ private _open = false;
3
+ private _showCloseButton = true;
4
+ private dialogEl: HTMLDialogElement | null = null;
5
+
6
+ static get observedAttributes() {
7
+ return ['open', 'show-close-button'];
8
+ }
9
+
10
+ get open(): boolean {
11
+ return this._open;
12
+ }
13
+
14
+ set open(val: boolean) {
15
+ if (this._open === val) return;
16
+ this._open = val;
17
+ if (val) {
18
+ this.setAttribute('open', '');
19
+ this.dialogEl?.showModal();
20
+ } else {
21
+ this.removeAttribute('open');
22
+ this.dialogEl?.close();
23
+ }
24
+ this.dispatchEvent(new CustomEvent('openchange', { detail: { open: val } }));
25
+ }
26
+
27
+ connectedCallback() {
28
+ this.render();
29
+ }
30
+
31
+ attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
32
+ if (name === 'open') {
33
+ this.open = newValue !== null;
34
+ } else if (name === 'show-close-button') {
35
+ this._showCloseButton = newValue !== 'false';
36
+ }
37
+ }
38
+
39
+ private render() {
40
+ this.innerHTML = `
41
+ <div data-slot="dialog-trigger-wrapper" class="inline-block">
42
+ <slot name="trigger"></slot>
43
+ </div>
44
+ <dialog data-slot="dialog-native" class="backdrop:bg-black/10 backdrop:duration-100 backdrop:supports-backdrop-filter:backdrop-blur-xs fixed inset-0 m-0 h-full w-full max-h-none max-w-none bg-transparent p-0 border-none outline-none z-50 flex items-center justify-center">
45
+ <div data-slot="dialog-content" class="grid max-w-[calc(100%-2rem)] gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 sm:max-w-sm w-full relative outline-none shadow-lg">
46
+ <slot name="header">
47
+ <div data-slot="dialog-header" class="gap-2 flex flex-col">
48
+ <slot name="title"></slot>
49
+ <slot name="description"></slot>
50
+ </div>
51
+ </slot>
52
+ <slot></slot>
53
+ <slot name="footer"></slot>
54
+ ${
55
+ this._showCloseButton
56
+ ? `
57
+ <button type="button" data-slot="dialog-close-btn" aria-label="Close" class="absolute top-2 right-2 inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring outline-none transition-colors">
58
+ <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
59
+ <span class="sr-only">Close</span>
60
+ </button>
61
+ `
62
+ : ''
63
+ }
64
+ </div>
65
+ </dialog>
66
+ `;
67
+
68
+ this.dialogEl = this.querySelector('dialog');
69
+ const triggerWrapper = this.querySelector('[data-slot="dialog-trigger-wrapper"]');
70
+ const closeBtn = this.querySelector('[data-slot="dialog-close-btn"]');
71
+
72
+ triggerWrapper?.addEventListener('click', () => {
73
+ this.open = true;
74
+ });
75
+
76
+ closeBtn?.addEventListener('click', () => {
77
+ this.open = false;
78
+ });
79
+
80
+ this.dialogEl?.addEventListener('click', (e) => {
81
+ if (e.target === this.dialogEl) {
82
+ this.open = false;
83
+ }
84
+ });
85
+
86
+ this.dialogEl?.addEventListener('cancel', () => {
87
+ this.open = false;
88
+ });
89
+ }
90
+ }
91
+
92
+ if (!customElements.get('surreal-dialog')) {
93
+
94
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-shadcn-dialog')) {
95
+ customElements.define('surreal-shadcn-dialog', SurrealShadcnDialog);
96
+ }
97
+ }
98
+
99
+ export default SurrealShadcnDialog;;
100
+ export { SurrealShadcnDialog as MinimalistDialog, SurrealShadcnDialog };
101
+
102
+ if (typeof customElements !== 'undefined' && !customElements.get('surreal-minimalist-dialog')) {
103
+ customElements.define('surreal-minimalist-dialog', SurrealShadcnDialog);
104
+ }