@preference-sl/pref-viewer 2.11.0-beta.1 → 2.11.0-beta.10
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/package.json +12 -8
- package/src/babylonjs-animation-controller.js +235 -0
- package/src/babylonjs-animation-opening-menu.js +360 -0
- package/src/babylonjs-animation-opening.js +496 -0
- package/src/babylonjs-controller.js +343 -86
- package/src/css/pref-viewer-2d.css +39 -0
- package/src/css/pref-viewer-3d.css +28 -0
- package/src/css/pref-viewer-dialog.css +105 -0
- package/src/css/pref-viewer.css +11 -0
- package/src/file-storage.js +166 -39
- package/src/index.js +317 -81
- package/src/pref-viewer-2d.js +66 -47
- package/src/pref-viewer-3d.js +326 -83
- package/src/pref-viewer-dialog.js +139 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PrefViewerDialog - Custom Web Component for displaying modal dialogs in PrefViewer.
|
|
3
|
+
*
|
|
4
|
+
* Overview:
|
|
5
|
+
* - Provides a modal dialog overlay for user interactions such as downloads or confirmations.
|
|
6
|
+
* - Handles DOM creation, styling, and open/close logic.
|
|
7
|
+
* - Ensures dialog content is centered and styled appropriately.
|
|
8
|
+
* - Automatically focuses the canvas when closed for improved accessibility.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* - Use as a custom HTML element: <pref-viewer-dialog></pref-viewer-dialog>
|
|
12
|
+
* - Call open(title, content, footer) to display the dialog with a header, content, and footer.
|
|
13
|
+
* - Call close() to hide and remove the dialog.
|
|
14
|
+
*
|
|
15
|
+
* Methods:
|
|
16
|
+
* - constructor(): Initializes the custom element.
|
|
17
|
+
* - connectedCallback(): Called when the element is added to the DOM; sets up DOM and styles.
|
|
18
|
+
* - disconnectedCallback(): Called when the element is removed from the DOM; cleans up resources.
|
|
19
|
+
* - open(title, content, footer): Displays the dialog and sets its header, content, and footer.
|
|
20
|
+
* - close(): Hides and removes the dialog, refocuses the canvas if available.
|
|
21
|
+
* - #createDOMElements(): Creates the dialog structure and applies styles.
|
|
22
|
+
*/
|
|
23
|
+
export class PrefViewerDialog extends HTMLElement {
|
|
24
|
+
#wrapper = null;
|
|
25
|
+
#header = null;
|
|
26
|
+
#content = null;
|
|
27
|
+
#footer = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the custom dialog element.
|
|
31
|
+
* Only calls super(); heavy initialization is deferred to connectedCallback.
|
|
32
|
+
*/
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Called when the element is inserted into the DOM.
|
|
39
|
+
* Sets up the dialog's DOM structure and styles.
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
this.#createDOMElements();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Called when the element is removed from the DOM.
|
|
48
|
+
* Cleans up resources and event listeners.
|
|
49
|
+
* @returns {void}
|
|
50
|
+
*/
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
this.removeEventListener("click", this.#closeOnBackdropClick.bind(this));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates the dialog's DOM structure and applies CSS styles.
|
|
57
|
+
* Adds a click handler to close the dialog when clicking outside the content.
|
|
58
|
+
* @private
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
#createDOMElements() {
|
|
62
|
+
this.#wrapper = document.createElement("div");
|
|
63
|
+
this.#wrapper.classList.add("dialog-wrapper");
|
|
64
|
+
this.#wrapper.innerHTML = `
|
|
65
|
+
<div class="dialog-header"><h3 class="dialog-header-title"></h3></div>
|
|
66
|
+
<div class="dialog-content"></div>
|
|
67
|
+
<div class="dialog-footer"></div>`;
|
|
68
|
+
this.append(this.#wrapper);
|
|
69
|
+
|
|
70
|
+
const style = document.createElement("style");
|
|
71
|
+
style.textContent = `@import "/dist/css/pref-viewer-dialog.css";`;
|
|
72
|
+
this.append(style);
|
|
73
|
+
|
|
74
|
+
this.addEventListener("click", this.#closeOnBackdropClick.bind(this));
|
|
75
|
+
|
|
76
|
+
this.#header = this.#wrapper.querySelector(".dialog-header");
|
|
77
|
+
this.#content = this.#wrapper.querySelector(".dialog-content");
|
|
78
|
+
this.#footer = this.#wrapper.querySelector(".dialog-footer");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#closeOnBackdropClick(event) {
|
|
82
|
+
if (event.target === this) {
|
|
83
|
+
this.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Opens the dialog and sets its header, content, and footer.
|
|
89
|
+
* @param {string} title - The dialog title to display in the header.
|
|
90
|
+
* @param {string} content - The HTML content to display in the dialog body.
|
|
91
|
+
* @param {string} footer - The HTML content to display in the dialog footer (e.g., action buttons).
|
|
92
|
+
* @returns {boolean} True if the dialog was opened, false if no content was provided.
|
|
93
|
+
*/
|
|
94
|
+
open(title = "", content = "", footer = "") {
|
|
95
|
+
if (this.#wrapper === null || this.#header === null || this.#content === null || this.#footer === null) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (title === "" && content === "" && footer === "") {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (title === "") {
|
|
103
|
+
this.#header.style.display = "none";
|
|
104
|
+
}
|
|
105
|
+
if (footer === "") {
|
|
106
|
+
this.#footer.style.display = "none";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.#header.querySelector(".dialog-header-title").innerHTML = title;
|
|
110
|
+
this.#content.innerHTML = content;
|
|
111
|
+
this.#footer.innerHTML = footer;
|
|
112
|
+
this.setAttribute("open", "");
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Closes and removes the dialog from the DOM.
|
|
118
|
+
* @returns {void}
|
|
119
|
+
*/
|
|
120
|
+
close() {
|
|
121
|
+
this.removeAttribute("open");
|
|
122
|
+
const parent = this.getRootNode().host;
|
|
123
|
+
if (parent) {
|
|
124
|
+
// Refocus 3D canvas or 2D component for accessibility
|
|
125
|
+
const canvas = parent.shadowRoot.querySelector("pref-viewer-3d[visible='true'] canvas");
|
|
126
|
+
if (canvas) {
|
|
127
|
+
canvas.focus();
|
|
128
|
+
} else {
|
|
129
|
+
const component2D = parent.shadowRoot.querySelector("pref-viewer-2d[visible='true']");
|
|
130
|
+
if (component2D) {
|
|
131
|
+
component2D.focus();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
this.#wrapper = this.#header = this.#content = this.#footer = null;
|
|
137
|
+
this.remove();
|
|
138
|
+
}
|
|
139
|
+
}
|