@onetype/framework 2.0.38 → 2.0.40

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.
@@ -1,239 +0,0 @@
1
- transforms.ItemAdd({
2
- id: 'sparkline',
3
- icon: 'show_chart',
4
- name: 'Sparkline',
5
- description: 'Inline mini charts for data trends. Compact line charts perfect for dashboards.',
6
- js: [
7
- 'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'
8
- ],
9
- config: {
10
- 'values': ['array', [5, 10, 5, 20, 8, 15, 12, 8, 10, 15, 20, 25]],
11
- 'type': ['string', 'line'], // line, bar, area
12
- 'width': ['number', 100],
13
- 'height': ['number', 30],
14
- 'color': ['string', ''], // empty means use theme brand color
15
- 'fill': ['boolean', false],
16
- 'show-dots': ['boolean', false],
17
- 'show-tooltip': ['boolean', true],
18
- 'smooth': ['boolean', true],
19
- 'animate': ['boolean', true],
20
- 'min': ['number', null],
21
- 'max': ['number', null]
22
- },
23
- code: function(data, node, transformer)
24
- {
25
- const id = 'sparkline-' + onetype.Generate(8);
26
-
27
- this.setup = () =>
28
- {
29
- node.innerHTML = '';
30
- node.classList.add('sparkline');
31
- node.classList.add(id);
32
-
33
- // Set inline-block display for sparklines
34
- node.style.display = 'inline-block';
35
- node.style.verticalAlign = 'middle';
36
- node.style.width = data['width'] + 'px';
37
- node.style.height = data['height'] + 'px';
38
-
39
- const canvas = document.createElement('canvas');
40
- canvas.width = data['width'];
41
- canvas.height = data['height'];
42
- this.canvas = canvas;
43
- node.appendChild(canvas);
44
- };
45
-
46
- this.colors = () =>
47
- {
48
- const style = getComputedStyle(document.body);
49
-
50
- // Get custom color or default to brand
51
- let lineColor = data['color'];
52
- if (!lineColor)
53
- {
54
- lineColor = style.getPropertyValue('--ot-brand').trim() || '#3b82f6';
55
- }
56
-
57
- // Extract RGB values for opacity
58
- let fillColor = lineColor;
59
- if (lineColor.startsWith('#'))
60
- {
61
- const r = parseInt(lineColor.slice(1, 3), 16);
62
- const g = parseInt(lineColor.slice(3, 5), 16);
63
- const b = parseInt(lineColor.slice(5, 7), 16);
64
- fillColor = `rgba(${r}, ${g}, ${b}, 0.1)`;
65
- }
66
- else if (lineColor.startsWith('rgb'))
67
- {
68
- fillColor = lineColor.replace('rgb', 'rgba').replace(')', ', 0.1)');
69
- }
70
-
71
- return {
72
- line: lineColor,
73
- fill: fillColor
74
- };
75
- };
76
-
77
- this.dataset = () =>
78
- {
79
- const values = data['values'];
80
- const colors = this.colors();
81
- const type = data['type'];
82
- const smooth = data['smooth'];
83
- const fill = data['fill'] || type === 'area';
84
- const showDots = data['show-dots'];
85
-
86
- const dataset = {
87
- data: values,
88
- borderColor: colors.line,
89
- backgroundColor: fill ? colors.fill : 'transparent',
90
- borderWidth: 1.5,
91
- pointRadius: showDots ? 2 : 0,
92
- pointHoverRadius: showDots ? 3 : 0,
93
- pointBackgroundColor: colors.line,
94
- pointBorderColor: colors.line,
95
- tension: smooth ? 0.4 : 0,
96
- fill: fill
97
- };
98
-
99
- // Adjust for bar type
100
- if (type === 'bar')
101
- {
102
- dataset.backgroundColor = colors.line;
103
- dataset.borderWidth = 0;
104
- }
105
-
106
- return dataset;
107
- };
108
-
109
- this.config = () =>
110
- {
111
- const type = data['type'] === 'area' ? 'line' : data['type'];
112
- const showTooltip = data['show-tooltip'];
113
- const animate = data['animate'];
114
- const minValue = data['min'];
115
- const maxValue = data['max'];
116
-
117
- // Generate labels based on data length
118
- const labels = Array.from({length: data['values'].length}, (_, i) => '');
119
-
120
- return {
121
- type: type === 'bar' ? 'bar' : 'line',
122
- data: {
123
- labels: labels,
124
- datasets: [this.dataset()]
125
- },
126
- options: {
127
- responsive: false,
128
- maintainAspectRatio: false,
129
- animation: {
130
- duration: animate ? 750 : 0
131
- },
132
- interaction: {
133
- intersect: false,
134
- mode: showTooltip ? 'index' : null
135
- },
136
- plugins: {
137
- legend: {
138
- display: false
139
- },
140
- tooltip: {
141
- enabled: showTooltip,
142
- backgroundColor: 'rgba(0, 0, 0, 0.8)',
143
- titleFont: {
144
- size: 11
145
- },
146
- bodyFont: {
147
- size: 11
148
- },
149
- padding: 4,
150
- displayColors: false,
151
- callbacks: {
152
- title: () => '',
153
- label: (context) => {
154
- return context.parsed.y.toLocaleString();
155
- }
156
- }
157
- }
158
- },
159
- scales: {
160
- x: {
161
- display: false,
162
- grid: {
163
- display: false
164
- }
165
- },
166
- y: {
167
- display: false,
168
- beginAtZero: minValue === null,
169
- min: minValue,
170
- max: maxValue,
171
- grid: {
172
- display: false
173
- }
174
- }
175
- },
176
- elements: {
177
- line: {
178
- borderJoinStyle: 'round'
179
- }
180
- },
181
- layout: {
182
- padding: 0
183
- }
184
- }
185
- };
186
- };
187
-
188
- this.styles = () =>
189
- {
190
- const style = document.createElement('style');
191
-
192
- style.textContent = `
193
- .sparkline-${id} {
194
- position: relative;
195
- line-height: 1;
196
- }
197
- .sparkline-${id} canvas {
198
- display: block;
199
- max-width: 100%;
200
- }
201
- `;
202
-
203
- document.head.appendChild(style);
204
- };
205
-
206
- this.initialize = () =>
207
- {
208
- setTimeout(() =>
209
- {
210
- if(typeof Chart === 'undefined')
211
- {
212
- console.error('Chart.js library not loaded for sparkline');
213
- return;
214
- }
215
-
216
- const context = this.canvas.getContext('2d');
217
- this.instance = new Chart(context, this.config());
218
-
219
- // Expose instance for external access
220
- node.sparkline = this.instance;
221
-
222
- // Add update method for dynamic updates
223
- node.updateSparkline = (newValues) =>
224
- {
225
- if (this.instance)
226
- {
227
- this.instance.data.datasets[0].data = newValues;
228
- this.instance.data.labels = Array.from({length: newValues.length}, () => '');
229
- this.instance.update('none'); // Update without animation
230
- }
231
- };
232
- }, 100);
233
- };
234
-
235
- this.setup();
236
- this.styles();
237
- this.initialize();
238
- }
239
- });
@@ -1,140 +0,0 @@
1
- transforms.ItemAdd({
2
- id: 'swiper',
3
- icon: 'swipe',
4
- name: 'Swiper',
5
- description: 'Touch-enabled slider/carousel component. Create image galleries and content sliders with swipe gestures.',
6
- js: [
7
- 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js'
8
- ],
9
- css: [
10
- 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css'
11
- ],
12
- config: {
13
- 'slides-per-view': ['number', 3],
14
- 'space-between': ['number', 20],
15
- 'loop': ['boolean', false],
16
- 'autoplay': ['boolean|object', false],
17
- 'navigation': ['boolean', true],
18
- 'pagination': ['boolean', true],
19
- 'speed': ['number', 300],
20
- 'grab-cursor': ['boolean', true],
21
- 'free-mode': ['boolean', false]
22
- },
23
- code: function(data, node, transformer)
24
- {
25
- this.setup = () =>
26
- {
27
- node.classList.add('swiper');
28
-
29
- const children = Array.from(node.children);
30
- const wrapper = document.createElement('div');
31
-
32
- wrapper.className = 'swiper-wrapper';
33
-
34
- children.forEach(child =>
35
- {
36
- child.classList.add('swiper-slide');
37
- wrapper.appendChild(child);
38
- });
39
-
40
- node.appendChild(wrapper);
41
- };
42
-
43
- this.navigation = () =>
44
- {
45
- if(!data['navigation'])
46
- {
47
- return;
48
- }
49
-
50
- const prev = document.createElement('div');
51
- const next = document.createElement('div');
52
-
53
- prev.className = 'swiper-button-prev';
54
- next.className = 'swiper-button-next';
55
-
56
- node.appendChild(prev);
57
- node.appendChild(next);
58
- };
59
-
60
- this.pagination = () =>
61
- {
62
- if(!data['pagination'])
63
- {
64
- return;
65
- }
66
-
67
- const pagination = document.createElement('div');
68
-
69
- pagination.className = 'swiper-pagination';
70
-
71
- node.appendChild(pagination);
72
- };
73
-
74
- this.config = () =>
75
- {
76
- const slidesPerView = data['slides-per-view'];
77
- const spaceBetween = data['space-between'];
78
-
79
- const config = {
80
- slidesPerView: 1,
81
- spaceBetween: spaceBetween,
82
- speed: data['speed'],
83
- loop: data['loop'],
84
- grabCursor: data['grab-cursor'],
85
- cssMode: false,
86
- allowTouchMove: true,
87
- touchRatio: 1,
88
- resistance: true,
89
- resistanceRatio: 0.85,
90
- breakpoints: {
91
- 640: { slidesPerView: Math.min(2, slidesPerView), spaceBetween: spaceBetween },
92
- 1024: { slidesPerView: Math.min(3, slidesPerView), spaceBetween: spaceBetween },
93
- 1280: { slidesPerView: slidesPerView, spaceBetween: spaceBetween }
94
- }
95
- };
96
-
97
- if(data['free-mode'])
98
- {
99
- config.freeMode = {
100
- enabled: true,
101
- sticky: false
102
- };
103
- }
104
-
105
- if(data['autoplay'])
106
- {
107
- config.autoplay = typeof data['autoplay'] === 'object'
108
- ? data['autoplay']
109
- : { delay: 3000 };
110
- }
111
-
112
- if(data['navigation'])
113
- {
114
- config.navigation = {
115
- nextEl: node.querySelector('.swiper-button-next'),
116
- prevEl: node.querySelector('.swiper-button-prev'),
117
- };
118
- }
119
-
120
- if(data['pagination'])
121
- {
122
- config.pagination = {
123
- el: node.querySelector('.swiper-pagination'),
124
- clickable: true,
125
- };
126
- }
127
-
128
- return config;
129
- };
130
-
131
- this.setup();
132
- this.navigation();
133
- this.pagination();
134
-
135
- setTimeout(() =>
136
- {
137
- new Swiper(node, this.config());
138
- }, 0);
139
- }
140
- });