@rettangoli/ui 0.1.2-rc3 → 0.1.2-rc30

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 (54) hide show
  1. package/dist/rettangoli-iife-layout.min.js +115 -43
  2. package/dist/rettangoli-iife-ui.min.js +187 -67
  3. package/package.json +5 -3
  4. package/src/cli/buildSvg.js +86 -0
  5. package/src/cli/index.js +1 -0
  6. package/src/common.js +19 -0
  7. package/src/components/breadcrumb/breadcrumb.handlers.js +9 -0
  8. package/src/components/breadcrumb/breadcrumb.store.js +29 -0
  9. package/src/components/breadcrumb/breadcrumb.view.yaml +64 -0
  10. package/src/components/dropdownMenu/dropdownMenu.handlers.js +4 -4
  11. package/src/components/dropdownMenu/dropdownMenu.store.js +5 -17
  12. package/src/components/dropdownMenu/dropdownMenu.view.yaml +15 -13
  13. package/src/components/form/form.handlers.js +173 -25
  14. package/src/components/form/form.store.js +176 -22
  15. package/src/components/form/form.view.yaml +217 -33
  16. package/src/components/pageOutline/pageOutline.handlers.js +1 -1
  17. package/src/components/popoverInput/popoverInput.handlers.js +99 -0
  18. package/src/components/popoverInput/popoverInput.store.js +48 -0
  19. package/src/components/popoverInput/popoverInput.view.yaml +55 -0
  20. package/src/components/select/select.handlers.js +116 -11
  21. package/src/components/select/select.store.js +84 -18
  22. package/src/components/select/select.view.yaml +40 -10
  23. package/src/components/sidebar/sidebar.view.yaml +1 -1
  24. package/src/components/sliderInput/sliderInput.handlers.js +41 -0
  25. package/src/components/sliderInput/sliderInput.store.js +18 -0
  26. package/src/components/sliderInput/sliderInput.view.yaml +42 -0
  27. package/src/components/table/table.handlers.js +1 -1
  28. package/src/components/tabs/tabs.handlers.js +10 -0
  29. package/src/components/tabs/tabs.store.js +29 -0
  30. package/src/components/tabs/tabs.view.yaml +64 -0
  31. package/src/components/tooltip/tooltip.handlers.js +0 -0
  32. package/src/components/tooltip/tooltip.store.js +12 -0
  33. package/src/components/tooltip/tooltip.view.yaml +27 -0
  34. package/src/components/waveform/waveform.handlers.js +92 -0
  35. package/src/components/waveform/waveform.store.js +17 -0
  36. package/src/components/waveform/waveform.view.yaml +38 -0
  37. package/src/entry-iife-layout.js +3 -0
  38. package/src/entry-iife-ui.js +4 -0
  39. package/src/index.js +5 -1
  40. package/src/primitives/button.js +10 -0
  41. package/src/primitives/colorPicker.js +9 -0
  42. package/src/primitives/dialog.js +254 -0
  43. package/src/primitives/input.js +41 -11
  44. package/src/primitives/popover.js +280 -0
  45. package/src/primitives/slider.js +18 -9
  46. package/src/primitives/svg.js +2 -0
  47. package/src/primitives/textarea.js +25 -1
  48. package/src/styles/cursorStyles.js +38 -2
  49. package/src/components/dialog/dialog.handlers.js +0 -5
  50. package/src/components/dialog/dialog.store.js +0 -25
  51. package/src/components/dialog/dialog.view.yaml +0 -44
  52. package/src/components/popover/popover.handlers.js +0 -5
  53. package/src/components/popover/popover.store.js +0 -12
  54. package/src/components/popover/popover.view.yaml +0 -57
@@ -0,0 +1,64 @@
1
+ elementName: rtgl-tabs
2
+
3
+ viewDataSchema:
4
+ type: object
5
+ properties:
6
+ containerAttrString:
7
+ type: string
8
+ items:
9
+ type: array
10
+ items:
11
+ type: object
12
+ properties:
13
+ label:
14
+ type: string
15
+ id:
16
+ type: string
17
+ isSelected:
18
+ type: boolean
19
+ bgColor:
20
+ type: string
21
+ textColor:
22
+ type: string
23
+ borderColor:
24
+ type: string
25
+ selectedTab:
26
+ type: string
27
+
28
+ propsSchema:
29
+ type: object
30
+ properties:
31
+ items:
32
+ type: array
33
+ items:
34
+ type: object
35
+ properties:
36
+ label:
37
+ type: string
38
+ id:
39
+ type: string
40
+
41
+ attrsSchema:
42
+ type: object
43
+ properties:
44
+ selected-tab:
45
+ type: string
46
+
47
+ refs:
48
+ tab-*:
49
+ eventListeners:
50
+ click:
51
+ handler: handleClickItem
52
+
53
+ events:
54
+ item-click:
55
+ type: object
56
+ properties:
57
+ id:
58
+ type: string
59
+
60
+ template:
61
+ - rtgl-view d=h g=sm bgc=mu p=sm br=lg ${containerAttrString}:
62
+ - $for item in items:
63
+ - rtgl-view#tab-${item.id} data-id=${item.id} cur=p bgc=${item.bgColor} bw=xs bc=${item.borderColor} pv=md ph=lg br=lg:
64
+ - rtgl-text s=sm c=${item.textColor}: "${item.label}"
File without changes
@@ -0,0 +1,12 @@
1
+ export const INITIAL_STATE = Object.freeze({
2
+ });
3
+
4
+ export const toViewData = ({ attrs }) => {
5
+ return {
6
+ open: !!attrs.open,
7
+ x: attrs.x || 0,
8
+ y: attrs.y || 0,
9
+ placement: attrs.placement || 'top',
10
+ content: attrs.content || ''
11
+ };
12
+ }
@@ -0,0 +1,27 @@
1
+ elementName: rtgl-tooltip
2
+
3
+ viewDataSchema:
4
+ type: object
5
+
6
+ attrsSchema:
7
+ type: object
8
+ properties:
9
+ open:
10
+ type: string
11
+ x:
12
+ type: string
13
+ y:
14
+ type: string
15
+ placement:
16
+ type: string
17
+ content:
18
+ type: string
19
+
20
+ refs:
21
+ popover:
22
+
23
+ template:
24
+ - rtgl-popover#popover ?open=${open} x=${x} y=${y} placement=${placement} no-overlay:
25
+ - rtgl-view slot=content bgc=background bc=border br=md p=sm ah=c av=c:
26
+ - rtgl-text ta=c s=sm c=foreground: ${content}
27
+
@@ -0,0 +1,92 @@
1
+ export const handleAfterMount = async (deps) => {
2
+ const { props, store, render, getRefIds, } = deps;
3
+ const { waveformData } = props;
4
+
5
+ store.setWaveformData(waveformData);
6
+ render();
7
+
8
+ const canvas = getRefIds().canvas?.elm;
9
+ if (canvas) {
10
+ renderWaveform(waveformData, canvas);
11
+ }
12
+ };
13
+
14
+ export const handleOnUpdate = async (changes, deps) => {
15
+ const { store, render, getRefIds, props } = deps;
16
+ const { waveformData } = props;
17
+
18
+ if (!waveformData) {
19
+ console.log('waveform handleOnUpdate: no waveformData provided');
20
+ return;
21
+ }
22
+
23
+ store.setWaveformData(waveformData);
24
+ render();
25
+
26
+ const canvas = getRefIds().canvas?.elm;
27
+ if (canvas) {
28
+ renderWaveform(waveformData, canvas);
29
+ }
30
+ };
31
+
32
+ async function renderWaveform(waveformData, canvas) {
33
+ const ctx = canvas.getContext("2d");
34
+
35
+ // Get the actual display size of the canvas
36
+ const rect = canvas.getBoundingClientRect();
37
+ const displayWidth = rect.width;
38
+ const displayHeight = rect.height;
39
+
40
+ // Set canvas internal resolution to match display size
41
+ canvas.width = displayWidth;
42
+ canvas.height = displayHeight;
43
+
44
+ const width = canvas.width;
45
+ const height = canvas.height;
46
+
47
+ // Clear canvas
48
+ ctx.clearRect(0, 0, width, height);
49
+
50
+ // Dark theme background
51
+ ctx.fillStyle = "#1a1a1a";
52
+ ctx.fillRect(0, 0, width, height);
53
+
54
+ if (!waveformData || !waveformData.data) {
55
+ return;
56
+ }
57
+
58
+ const data = waveformData.data;
59
+ const centerY = height / 2;
60
+
61
+ // Create gradient for waveform
62
+ const gradient = ctx.createLinearGradient(0, 0, 0, height);
63
+ gradient.addColorStop(0, "#404040");
64
+ gradient.addColorStop(0.5, "#A1A1A1");
65
+ gradient.addColorStop(1, "#404040");
66
+
67
+ // Draw waveform bars
68
+ const barWidth = Math.max(1, width / data.length);
69
+ const barSpacing = 0.2; // 20% spacing between bars
70
+
71
+ for (let i = 0; i < data.length; i++) {
72
+ const amplitude = data[i];
73
+ const barHeight = amplitude * (height * 0.85);
74
+ const x = i * barWidth;
75
+ const y = centerY - barHeight / 2;
76
+
77
+ ctx.fillStyle = gradient;
78
+ ctx.fillRect(x, y, Math.max(1, barWidth * (1 - barSpacing)), barHeight);
79
+ }
80
+
81
+ // Draw subtle center line
82
+ ctx.strokeStyle = "rgba(255, 255, 255, 0.1)";
83
+ ctx.lineWidth = 1;
84
+ ctx.beginPath();
85
+ ctx.moveTo(0, centerY);
86
+ ctx.lineTo(width, centerY);
87
+ ctx.stroke();
88
+
89
+ // Add subtle glow effect
90
+ ctx.shadowBlur = 10;
91
+ ctx.shadowColor = "#2196F3";
92
+ }
@@ -0,0 +1,17 @@
1
+ export const INITIAL_STATE = Object.freeze({
2
+ waveformData: null,
3
+ });
4
+
5
+ export const setWaveformData = (state, data) => {
6
+ state.waveformData = data;
7
+ };
8
+
9
+ export const toViewData = ({ state, attrs, props }) => {
10
+ return {
11
+ isLoading: props.isLoading,
12
+ w: attrs.w || "250",
13
+ h: attrs.h || "150",
14
+ cur: attrs.cur,
15
+ waveformData: props.waveformData,
16
+ };
17
+ };
@@ -0,0 +1,38 @@
1
+ elementName: rtgl-waveform
2
+
3
+ attrsSchema:
4
+ type: object
5
+ properties:
6
+ w:
7
+ type: string
8
+ description: Width of the waveform visualizer
9
+ default: '250'
10
+ h:
11
+ type: string
12
+ description: Height of the waveform visualizer
13
+ default: '150'
14
+ cur:
15
+ type: string
16
+ description: cursor
17
+
18
+ propsSchema:
19
+ type: object
20
+ properties:
21
+ waveformData:
22
+ type: object
23
+ description: File ID of the waveform data in object storage
24
+ isLoading:
25
+ type: boolean
26
+ description: Whether the waveform data is currently being loaded
27
+
28
+ refs:
29
+ canvas:
30
+ selector: canvas
31
+
32
+ template:
33
+ - rtgl-view w=f h=f pos=rel w=${w} h=${h} cur=${cur}:
34
+ - $if isLoading:
35
+ - rtgl-view w=f h=f av=c ah=c:
36
+ - rtgl-text c=mu-fg: ...
37
+ $else:
38
+ - 'canvas#canvas style="width:100%; height:100%;"':
@@ -5,6 +5,8 @@ import RettangoliImage from './primitives/image.js';
5
5
  import RettangoliSvg from './primitives/svg.js';
6
6
  import RettangoliInput from './primitives/input.js';
7
7
  import RettangoliTextArea from './primitives/textarea.js';
8
+ import RettangoliDialog from './primitives/dialog.js';
9
+
8
10
 
9
11
  customElements.define("rtgl-button", RettangoliButton({}));
10
12
  customElements.define("rtgl-view", RettangoliView({}));
@@ -13,3 +15,4 @@ customElements.define("rtgl-image", RettangoliImage({}));
13
15
  customElements.define("rtgl-svg", RettangoliSvg({}));
14
16
  customElements.define("rtgl-input", RettangoliInput({}));
15
17
  customElements.define("rtgl-textarea", RettangoliTextArea({}));
18
+ customElements.define("rtgl-dialog", RettangoliDialog({}));
@@ -7,6 +7,8 @@ import RettangoliInput from './primitives/input.js';
7
7
  import RettangoliTextArea from './primitives/textarea.js';
8
8
  import RettangoliColorPicker from './primitives/colorPicker.js';
9
9
  import RettangoliSlider from './primitives/slider.js';
10
+ import RettangoliDialog from './primitives/dialog.js';
11
+ import RettangoliPopover from './primitives/popover.js';
10
12
 
11
13
  customElements.define("rtgl-button", RettangoliButton({}));
12
14
  customElements.define("rtgl-view", RettangoliView({}));
@@ -17,6 +19,8 @@ customElements.define("rtgl-input", RettangoliInput({}));
17
19
  customElements.define("rtgl-textarea", RettangoliTextArea({}));
18
20
  customElements.define("rtgl-color-picker", RettangoliColorPicker({}));
19
21
  customElements.define("rtgl-slider", RettangoliSlider({}));
22
+ customElements.define("rtgl-dialog", RettangoliDialog({}));
23
+ customElements.define("rtgl-popover", RettangoliPopover({}));
20
24
 
21
25
  // built from rettangoli cli fe
22
26
  import '../.temp/dynamicImport.js'
package/src/index.js CHANGED
@@ -5,6 +5,8 @@ import RettangoliImage from './primitives/image.js';
5
5
  import RettangoliSvg from './primitives/svg.js';
6
6
  import RettangoliInput from './primitives/input.js';
7
7
  import RettangoliTextArea from './primitives/textarea.js';
8
+ import RettangoliDialog from './primitives/dialog.js';
9
+ import RettangoliPopover from './primitives/popover.js';
8
10
 
9
11
  export {
10
12
  RettangoliButton,
@@ -14,4 +16,6 @@ export {
14
16
  RettangoliSvg,
15
17
  RettangoliInput,
16
18
  RettangoliTextArea,
17
- }
19
+ RettangoliDialog,
20
+ RettangoliPopover,
21
+ }
@@ -296,6 +296,16 @@ class RettangoliButtonElement extends HTMLElement {
296
296
  this._buttonElement.style.maxWidth = "";
297
297
  }
298
298
  }
299
+
300
+ // Public method to get the actual button's bounding rect
301
+ // This is needed because the host element has display: contents
302
+ getBoundingClientRect() {
303
+ if (this._buttonElement) {
304
+ return this._buttonElement.getBoundingClientRect();
305
+ }
306
+ // Fallback to host element
307
+ return super.getBoundingClientRect();
308
+ }
299
309
  }
300
310
 
301
311
  // Export factory function to maintain API compatibility
@@ -114,6 +114,15 @@ class RettangoliColorPickerElement extends HTMLElement {
114
114
  };
115
115
 
116
116
  attributeChangedCallback(name, oldValue, newValue) {
117
+ // Handle key attribute change - reset value
118
+ if (name === "key" && oldValue !== newValue) {
119
+ requestAnimationFrame(() => {
120
+ const value = this.getAttribute("value");
121
+ this._inputElement.value = value ?? "#000000";
122
+ });
123
+ return;
124
+ }
125
+
117
126
  // Handle input-specific attributes first
118
127
  if (["value", "disabled"].includes(name)) {
119
128
  this._updateInputAttributes();
@@ -0,0 +1,254 @@
1
+ import { css } from "../common.js";
2
+
3
+ class RettangoliDialogElement extends HTMLElement {
4
+ static styleSheet = null;
5
+
6
+ static initializeStyleSheet() {
7
+ if (!RettangoliDialogElement.styleSheet) {
8
+ RettangoliDialogElement.styleSheet = new CSSStyleSheet();
9
+ RettangoliDialogElement.styleSheet.replaceSync(css`
10
+ :host {
11
+ display: contents;
12
+ }
13
+
14
+ dialog {
15
+ padding: 0;
16
+ border: none;
17
+ background: transparent;
18
+ margin: auto;
19
+ overflow-y: scroll;
20
+ color: inherit;
21
+ max-height: 100vh;
22
+ height: 100vh;
23
+ max-width: 100vw;
24
+ scrollbar-width: none;
25
+ outline: none;
26
+ }
27
+
28
+ dialog::backdrop {
29
+ background-color: rgba(0, 0, 0, 0.5);
30
+ }
31
+
32
+ slot[name="content"] {
33
+ background-color: var(--background) !important;
34
+ display: block;
35
+ padding: var(--spacing-lg);
36
+ border: 1px solid var(--border);
37
+ border-radius: var(--border-radius-md);
38
+ margin-left: var(--spacing-lg);
39
+ margin-right: var(--spacing-lg);
40
+ width: fit-content;
41
+ max-width: calc(100vw - 2 * var(--spacing-lg));
42
+ /* Default margins will be set dynamically via JavaScript for adaptive centering */
43
+ margin-top: 40px;
44
+ margin-bottom: 40px;
45
+ }
46
+
47
+ /* Size attribute styles */
48
+ :host([s="sm"]) slot[name="content"] {
49
+ width: 33vw;
50
+ }
51
+
52
+ :host([s="md"]) slot[name="content"] {
53
+ width: 50vw;
54
+ }
55
+
56
+ :host([s="lg"]) slot[name="content"] {
57
+ width: 80vw;
58
+ }
59
+
60
+ :host([s="f"]) slot[name="content"] {
61
+ width: 100vw;
62
+ margin-left: 0;
63
+ margin-right: 0;
64
+ }
65
+
66
+ @keyframes dialog-in {
67
+ from {
68
+ opacity: 0;
69
+ transform: scale(0.95);
70
+ }
71
+ to {
72
+ opacity: 1;
73
+ transform: scale(1);
74
+ }
75
+ }
76
+
77
+ dialog[open] slot[name="content"] {
78
+ animation: dialog-in 150ms cubic-bezier(0.16, 1, 0.3, 1);
79
+ }
80
+ `);
81
+ }
82
+ }
83
+
84
+ constructor() {
85
+ super();
86
+ RettangoliDialogElement.initializeStyleSheet();
87
+ this.shadow = this.attachShadow({ mode: "open" });
88
+ this.shadow.adoptedStyleSheets = [RettangoliDialogElement.styleSheet];
89
+
90
+ // Create dialog element
91
+ this._dialogElement = document.createElement('dialog');
92
+ this.shadow.appendChild(this._dialogElement);
93
+
94
+ // Store reference for content slot
95
+ this._slotElement = null;
96
+ this._isConnected = false;
97
+
98
+ // Handle click outside - emit custom event
99
+ this._dialogElement.addEventListener('click', (e) => {
100
+ if (e.target === this._dialogElement) {
101
+ this.dispatchEvent(new CustomEvent('close', {
102
+ detail: {}
103
+ }));
104
+ }
105
+ });
106
+
107
+ // Handle right-click on overlay to close dialog
108
+ this._dialogElement.addEventListener('contextmenu', (e) => {
109
+ if (e.target === this._dialogElement) {
110
+ e.preventDefault();
111
+ this.dispatchEvent(new CustomEvent('close', {
112
+ detail: {}
113
+ }));
114
+ }
115
+ });
116
+
117
+ // Handle ESC key - prevent native close and emit custom event
118
+ this._dialogElement.addEventListener('cancel', (e) => {
119
+ e.preventDefault();
120
+ this.dispatchEvent(new CustomEvent('close', {
121
+ detail: {}
122
+ }));
123
+ });
124
+ }
125
+
126
+ static get observedAttributes() {
127
+ return ["open", "w", "s"];
128
+ }
129
+
130
+ connectedCallback() {
131
+ this._updateDialog();
132
+ this._isConnected = true;
133
+ // Check initial open attribute
134
+ if (this.hasAttribute('open')) {
135
+ this._showModal();
136
+ }
137
+ }
138
+
139
+ attributeChangedCallback(name, oldValue, newValue) {
140
+ if (name === 'open') {
141
+ if (newValue !== null && !this._dialogElement.open && this._isConnected) {
142
+ this._showModal();
143
+ } else if (newValue === null && this._dialogElement.open) {
144
+ this._hideModal();
145
+ }
146
+ } else if (name === 'w') {
147
+ this._updateWidth();
148
+ } else if (name === 's') {
149
+ // Size is handled via CSS :host() selectors
150
+ }
151
+ }
152
+
153
+ _updateDialog() {
154
+ this._updateWidth();
155
+ }
156
+
157
+ _updateWidth() {
158
+ const width = this.getAttribute('w');
159
+ if (width) {
160
+ this._dialogElement.style.width = width;
161
+ } else {
162
+ this._dialogElement.style.width = '';
163
+ }
164
+ }
165
+
166
+ // Internal methods
167
+ _showModal() {
168
+ if (!this._dialogElement.open) {
169
+ // Create and append slot for content only if it doesn't exist
170
+ if (!this._slotElement) {
171
+ this._slotElement = document.createElement('slot');
172
+ this._slotElement.setAttribute('name', 'content');
173
+ this._dialogElement.appendChild(this._slotElement);
174
+ }
175
+
176
+ this._dialogElement.showModal();
177
+
178
+ // Reset scroll position
179
+ this._dialogElement.scrollTop = 0;
180
+
181
+ // Apply adaptive centering
182
+ this._applyAdaptiveCentering();
183
+ }
184
+ }
185
+
186
+ _hideModal() {
187
+ if (this._dialogElement.open) {
188
+ this._dialogElement.close();
189
+
190
+ // Remove slot to unmount content
191
+ if (this._slotElement) {
192
+ // Reset any inline styles applied for adaptive centering
193
+ this._slotElement.style.marginTop = '';
194
+ this._slotElement.style.marginBottom = '';
195
+
196
+ this._dialogElement.removeChild(this._slotElement);
197
+ this._slotElement = null;
198
+ }
199
+
200
+ // Reset dialog height
201
+ this._dialogElement.style.height = '';
202
+
203
+ // Don't emit any event when programmatically closed via attribute
204
+ }
205
+ }
206
+
207
+ _applyAdaptiveCentering() {
208
+ if (!this._slotElement) {
209
+ return;
210
+ }
211
+
212
+ // Use requestAnimationFrame to ensure DOM has updated
213
+ requestAnimationFrame(() => {
214
+ if (!this._slotElement) return;
215
+
216
+ // Get the actual height of the content
217
+ const contentHeight = this._slotElement.offsetHeight;
218
+ const viewportHeight = window.innerHeight;
219
+
220
+ // Calculate centered position with minimum margins for scrollability
221
+ const minMargin = 40; // Minimum margin in pixels to ensure scrollability
222
+
223
+ if (contentHeight >= viewportHeight - (2 * minMargin)) {
224
+ // Content is too tall, use minimum margins to allow scrolling
225
+ // Start near the top with small margin so content isn't pushed too far down
226
+ this._slotElement.style.marginTop = `${minMargin}px`;
227
+ this._slotElement.style.marginBottom = `${minMargin}px`;
228
+ // Keep dialog at full height for scrolling
229
+ this._dialogElement.style.height = '100vh';
230
+ } else {
231
+ // Content fits, center it vertically
232
+ const totalMargin = viewportHeight - contentHeight;
233
+ const margin = Math.floor(totalMargin / 2);
234
+ this._slotElement.style.marginTop = `${margin}px`;
235
+ this._slotElement.style.marginBottom = `${margin}px`;
236
+ // Set dialog height to auto to prevent unnecessary scrollbar
237
+ this._dialogElement.style.height = 'auto';
238
+ }
239
+ });
240
+ }
241
+
242
+
243
+ // Expose dialog element for advanced usage
244
+ get dialog() {
245
+ return this._dialogElement;
246
+ }
247
+ }
248
+
249
+ // Export factory function to maintain API compatibility
250
+ export default ({ render, html }) => {
251
+ // Note: render and html parameters are accepted but not used
252
+ // This maintains backward compatibility with existing code
253
+ return RettangoliDialogElement;
254
+ };