@rettangoli/ui 0.1.2-rc32 → 0.1.2-rc34
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/dist/rettangoli-iife-ui.min.js +51 -51
- package/package.json +2 -2
- package/src/components/globalUi/globalUi.handlers.js +51 -0
- package/src/components/globalUi/globalUi.store.js +57 -0
- package/src/components/globalUi/globalUi.view.yaml +59 -0
- package/src/components/waveform/waveform.handlers.js +5 -5
- package/src/deps/createGlobalUI.js +39 -0
- package/src/index.js +2 -0
- package/src/setup.js +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rettangoli/ui",
|
|
3
|
-
"version": "0.1.2-
|
|
3
|
+
"version": "0.1.2-rc34",
|
|
4
4
|
"description": "A UI component library for building web interfaces.",
|
|
5
5
|
"main": "dist/rettangoli-esm.min.js",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"homepage": "https://github.com/yuusoft-org/rettangoli#readme",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@floating-ui/dom": "^1.6.13",
|
|
52
|
-
"@rettangoli/fe": "0.0.7-
|
|
52
|
+
"@rettangoli/fe": "0.0.7-rc16",
|
|
53
53
|
"commander": "^13.1.0",
|
|
54
54
|
"jempl": "0.1.4-rc1",
|
|
55
55
|
"js-yaml": "^4.1.0",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const handleDialogClose = (_, deps) => {
|
|
2
|
+
const { store, render } = deps;
|
|
3
|
+
|
|
4
|
+
store.closeDialog();
|
|
5
|
+
render();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const handleConfirm = (_, deps) => {
|
|
9
|
+
const { store, render, globalUI } = deps;
|
|
10
|
+
|
|
11
|
+
store.closeDialog();
|
|
12
|
+
render();
|
|
13
|
+
globalUI.emit('event', true);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const handleCancel = (_, deps) => {
|
|
17
|
+
const { store, render, globalUI } = deps;
|
|
18
|
+
|
|
19
|
+
store.closeDialog();
|
|
20
|
+
render();
|
|
21
|
+
globalUI.emit('event', false);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const showAlert = (options, deps) => {
|
|
25
|
+
const { store, render } = deps;
|
|
26
|
+
|
|
27
|
+
if (store.selectIsOpen()) {
|
|
28
|
+
throw new Error("A dialog is already open");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
store.setAlertConfig(options);
|
|
32
|
+
render();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const showConfirm = async (options, deps) => {
|
|
36
|
+
const { store, render, globalUI } = deps;
|
|
37
|
+
|
|
38
|
+
if (store.selectIsOpen()) {
|
|
39
|
+
throw new Error("A dialog is already open");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
store.setConfirmConfig(options);
|
|
43
|
+
render();
|
|
44
|
+
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
globalUI.once('event', (result) => {
|
|
47
|
+
// result contains info of whehter is confirm of cancel
|
|
48
|
+
resolve(result)
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const INITIAL_STATE = Object.freeze({
|
|
2
|
+
isOpen: false,
|
|
3
|
+
config: {
|
|
4
|
+
status: undefined, // undefined | info | warning | error
|
|
5
|
+
title: "",
|
|
6
|
+
message: "",
|
|
7
|
+
confirmText: "OK",
|
|
8
|
+
cancelText: "Cancel",
|
|
9
|
+
mode: "alert", // alert | confirm
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const setAlertConfig = (state, options) => {
|
|
14
|
+
if (!options.message) {
|
|
15
|
+
throw new Error("message is required for showAlert");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
state.config = {
|
|
19
|
+
status: options.status || undefined,
|
|
20
|
+
title: options.title || "",
|
|
21
|
+
message: options.message,
|
|
22
|
+
confirmText: options.confirmText || "OK",
|
|
23
|
+
cancelText: "",
|
|
24
|
+
mode: "alert",
|
|
25
|
+
};
|
|
26
|
+
state.isOpen = true;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const setConfirmConfig = (state, options) => {
|
|
30
|
+
if (!options.message) {
|
|
31
|
+
throw new Error("message is required for showConfirm");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
state.config = {
|
|
35
|
+
status: options.status || undefined,
|
|
36
|
+
title: options.title || "",
|
|
37
|
+
message: options.message,
|
|
38
|
+
confirmText: options.confirmText || "Yes",
|
|
39
|
+
cancelText: options.cancelText || "Cancel",
|
|
40
|
+
mode: "confirm",
|
|
41
|
+
};
|
|
42
|
+
state.isOpen = true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const closeDialog = (state) => {
|
|
46
|
+
state.isOpen = false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const selectConfig = ({ state }) => state.config;
|
|
50
|
+
export const selectIsOpen = ({ state }) => state.isOpen;
|
|
51
|
+
|
|
52
|
+
export const toViewData = ({ state }) => {
|
|
53
|
+
return {
|
|
54
|
+
isOpen: state.isOpen,
|
|
55
|
+
config: state.config,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
elementName: rtgl-global-ui
|
|
2
|
+
|
|
3
|
+
viewDataSchema:
|
|
4
|
+
type: object
|
|
5
|
+
properties:
|
|
6
|
+
isOpen:
|
|
7
|
+
type: boolean
|
|
8
|
+
config:
|
|
9
|
+
type: object
|
|
10
|
+
properties:
|
|
11
|
+
status:
|
|
12
|
+
type: string
|
|
13
|
+
title:
|
|
14
|
+
type: string
|
|
15
|
+
message:
|
|
16
|
+
type: string
|
|
17
|
+
confirmText:
|
|
18
|
+
type: string
|
|
19
|
+
cancelText:
|
|
20
|
+
type: string
|
|
21
|
+
mode:
|
|
22
|
+
type: string
|
|
23
|
+
|
|
24
|
+
refs:
|
|
25
|
+
dialog:
|
|
26
|
+
eventListeners:
|
|
27
|
+
close:
|
|
28
|
+
handler: handleDialogClose
|
|
29
|
+
confirm-button:
|
|
30
|
+
eventListeners:
|
|
31
|
+
click:
|
|
32
|
+
handler: handleConfirm
|
|
33
|
+
cancel-button:
|
|
34
|
+
eventListeners:
|
|
35
|
+
click:
|
|
36
|
+
handler: handleCancel
|
|
37
|
+
|
|
38
|
+
template:
|
|
39
|
+
- rtgl-dialog#dialog ?open=${isOpen} s=sm:
|
|
40
|
+
- rtgl-view slot=content g=lg p=lg:
|
|
41
|
+
- rtgl-view d=h ah=c g=md:
|
|
42
|
+
- $if config.status == 'error':
|
|
43
|
+
- rtgl-icon name=x-circle c=error s=lg:
|
|
44
|
+
$elif config.status == 'warning':
|
|
45
|
+
- rtgl-icon name=alert-triangle c=warning s=lg:
|
|
46
|
+
$elif config.status == 'info':
|
|
47
|
+
- rtgl-icon name=info c=primary s=lg:
|
|
48
|
+
$elif config.status:
|
|
49
|
+
- rtgl-icon name=check-circle c=success s=lg:
|
|
50
|
+
- $if config.title:
|
|
51
|
+
- rtgl-text fs=lg fw=600: ${config.title}
|
|
52
|
+
|
|
53
|
+
- rtgl-view p=md:
|
|
54
|
+
- rtgl-text: ${config.message}
|
|
55
|
+
|
|
56
|
+
- rtgl-view d=h jc=fe g=md mt=lg:
|
|
57
|
+
- $if config.mode == 'confirm':
|
|
58
|
+
- rtgl-button#cancel-button variant=se: ${config.cancelText}
|
|
59
|
+
- rtgl-button#confirm-button variant=pr: ${config.confirmText}
|
|
@@ -51,11 +51,11 @@ async function renderWaveform(waveformData, canvas) {
|
|
|
51
51
|
ctx.fillStyle = "#1a1a1a";
|
|
52
52
|
ctx.fillRect(0, 0, width, height);
|
|
53
53
|
|
|
54
|
-
if (!waveformData || !waveformData.
|
|
54
|
+
if (!waveformData || !waveformData.amplitudes) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const amplitudes = waveformData.amplitudes;
|
|
59
59
|
const centerY = height / 2;
|
|
60
60
|
|
|
61
61
|
// Create gradient for waveform
|
|
@@ -65,11 +65,11 @@ async function renderWaveform(waveformData, canvas) {
|
|
|
65
65
|
gradient.addColorStop(1, "#404040");
|
|
66
66
|
|
|
67
67
|
// Draw waveform bars
|
|
68
|
-
const barWidth = Math.max(1, width /
|
|
68
|
+
const barWidth = Math.max(1, width / amplitudes.length);
|
|
69
69
|
const barSpacing = 0.2; // 20% spacing between bars
|
|
70
70
|
|
|
71
|
-
for (let i = 0; i <
|
|
72
|
-
const amplitude =
|
|
71
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
72
|
+
const amplitude = amplitudes[i];
|
|
73
73
|
const barHeight = amplitude * (height * 0.85);
|
|
74
74
|
const x = i * barWidth;
|
|
75
75
|
const y = centerY - barHeight / 2;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const createGlobalUI = (globalUIElement) => {
|
|
2
|
+
let listeners = {};
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
once: (event, callback) => {
|
|
6
|
+
if (!listeners[event]) {
|
|
7
|
+
listeners[event] = [];
|
|
8
|
+
}
|
|
9
|
+
const onceCallback = (...args) => {
|
|
10
|
+
callback(...args);
|
|
11
|
+
listeners[event] = listeners[event].filter(cb => cb !== onceCallback);
|
|
12
|
+
}
|
|
13
|
+
listeners[event].push(onceCallback);
|
|
14
|
+
},
|
|
15
|
+
emit: (event, ...args) => {
|
|
16
|
+
if (listeners[event]) {
|
|
17
|
+
listeners[event].forEach(callback => {
|
|
18
|
+
callback(...args);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
showAlert: async (options) => {
|
|
23
|
+
if(!globalUIElement)
|
|
24
|
+
{
|
|
25
|
+
throw new Error("globalUIElement is not set. Make sure to initialize the global UI component and pass it to createGlobalUIManager.");
|
|
26
|
+
}
|
|
27
|
+
globalUIElement.transformedHandlers.showAlert(options);
|
|
28
|
+
},
|
|
29
|
+
showConfirm: async (options) => {
|
|
30
|
+
if(!globalUIElement)
|
|
31
|
+
{
|
|
32
|
+
throw new Error("globalUIElement is not set. Make sure to initialize the global UI component and pass it to createGlobalUIManager.");
|
|
33
|
+
}
|
|
34
|
+
return globalUIElement.transformedHandlers.showConfirm(options);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default createGlobalUI;
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import RettangoliInput from './primitives/input.js';
|
|
|
7
7
|
import RettangoliTextArea from './primitives/textarea.js';
|
|
8
8
|
import RettangoliDialog from './primitives/dialog.js';
|
|
9
9
|
import RettangoliPopover from './primitives/popover.js';
|
|
10
|
+
import createGlobalUI from './deps/createGlobalUI.js';
|
|
10
11
|
|
|
11
12
|
export {
|
|
12
13
|
RettangoliButton,
|
|
@@ -18,4 +19,5 @@ export {
|
|
|
18
19
|
RettangoliTextArea,
|
|
19
20
|
RettangoliDialog,
|
|
20
21
|
RettangoliPopover,
|
|
22
|
+
createGlobalUI,
|
|
21
23
|
}
|
package/src/setup.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { createWebPatch } from '@rettangoli/fe';
|
|
2
|
+
import createGlobalUI from './deps/createGlobalUI';
|
|
2
3
|
import { h } from 'snabbdom/build/h';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
+
const globalUI = createGlobalUI();
|
|
6
|
+
|
|
7
|
+
const componentDependencies = {
|
|
8
|
+
globalUI: globalUI
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
const deps = {
|
|
7
12
|
components: componentDependencies,
|
|
@@ -13,4 +18,4 @@ export {
|
|
|
13
18
|
h,
|
|
14
19
|
patch,
|
|
15
20
|
deps,
|
|
16
|
-
}
|
|
21
|
+
}
|