@nuralyui/popconfirm 0.0.4 → 0.0.6
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/bundle.js +1460 -2
- package/bundle.js.gz +0 -0
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/popconfirm-manager.component.d.ts +132 -0
- package/popconfirm-manager.component.d.ts.map +1 -0
- package/popconfirm-manager.component.js +376 -0
- package/popconfirm-manager.component.js.map +1 -0
- package/popconfirm-manager.style.d.ts +2 -0
- package/popconfirm-manager.style.d.ts.map +1 -0
- package/popconfirm-manager.style.js +137 -0
- package/popconfirm-manager.style.js.map +1 -0
- package/popconfirm.component.d.ts +24 -5
- package/popconfirm.component.d.ts.map +1 -1
- package/popconfirm.component.js +93 -35
- package/popconfirm.component.js.map +1 -1
- package/popconfirm.style.d.ts.map +1 -1
- package/popconfirm.style.js.map +1 -1
- package/popconfirm.types.d.ts +41 -0
- package/popconfirm.types.d.ts.map +1 -1
- package/popconfirm.types.js.map +1 -1
- package/react.d.ts.map +1 -1
- package/react.js.map +1 -1
package/bundle.js.gz
CHANGED
|
Binary file
|
package/index.d.ts
CHANGED
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/popconfirm/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC"}
|
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/popconfirm/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './popconfirm.component.js';\nexport * from './popconfirm-manager.component.js';\nexport * from './popconfirm.types.js';\n"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { LitElement, nothing } from 'lit';
|
|
7
|
+
import { PopconfirmShowConfig, PopconfirmPosition } from './popconfirm.types.js';
|
|
8
|
+
import '../icon/icon.component.js';
|
|
9
|
+
import '../button/button.component.js';
|
|
10
|
+
import '../label/label.component.js';
|
|
11
|
+
declare const NrPopconfirmManagerElement_base: (new (...args: any[]) => import("@nuralyui/common/mixins").DependencyAware) & (new (...args: any[]) => import("@nuralyui/common/mixins").ThemeAware) & (new (...args: any[]) => import("@nuralyui/common/mixins").EventHandlerCapable) & typeof LitElement;
|
|
12
|
+
/**
|
|
13
|
+
* # PopconfirmManager Component
|
|
14
|
+
*
|
|
15
|
+
* A container component that manages popconfirm instances displayed at cursor position.
|
|
16
|
+
* Similar to toast notifications but for confirmation dialogs.
|
|
17
|
+
*
|
|
18
|
+
* ## Features
|
|
19
|
+
* - Show popconfirm at cursor/mouse position
|
|
20
|
+
* - Programmatic API for creating confirmations
|
|
21
|
+
* - Async confirmation support with loading state
|
|
22
|
+
* - Auto-dismiss on outside click or escape
|
|
23
|
+
* - Customizable appearance and callbacks
|
|
24
|
+
*
|
|
25
|
+
* ## Usage
|
|
26
|
+
* ```html
|
|
27
|
+
* <!-- Add once to your app -->
|
|
28
|
+
* <nr-popconfirm-manager></nr-popconfirm-manager>
|
|
29
|
+
*
|
|
30
|
+
* <!-- Programmatic usage -->
|
|
31
|
+
* <script>
|
|
32
|
+
* const manager = document.querySelector('nr-popconfirm-manager');
|
|
33
|
+
*
|
|
34
|
+
* // Show at cursor position (from click event)
|
|
35
|
+
* element.addEventListener('click', (e) => {
|
|
36
|
+
* manager.show({
|
|
37
|
+
* title: 'Delete item?',
|
|
38
|
+
* description: 'This action cannot be undone.',
|
|
39
|
+
* okType: 'danger',
|
|
40
|
+
* onConfirm: () => {
|
|
41
|
+
* console.log('Deleted!');
|
|
42
|
+
* }
|
|
43
|
+
* }, { x: e.clientX, y: e.clientY });
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Or use the static confirm helper
|
|
47
|
+
* const confirmed = await NrPopconfirmManager.confirm({
|
|
48
|
+
* title: 'Are you sure?',
|
|
49
|
+
* }, { x: event.clientX, y: event.clientY });
|
|
50
|
+
* </script>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @element nr-popconfirm-manager
|
|
54
|
+
* @fires nr-popconfirm-confirm - Fired when user confirms
|
|
55
|
+
* @fires nr-popconfirm-cancel - Fired when user cancels
|
|
56
|
+
*/
|
|
57
|
+
export declare class NrPopconfirmManagerElement extends NrPopconfirmManagerElement_base {
|
|
58
|
+
static styles: import("lit").CSSResult;
|
|
59
|
+
requiredComponents: string[];
|
|
60
|
+
/** Active popconfirm items */
|
|
61
|
+
private items;
|
|
62
|
+
/** Bound event handlers */
|
|
63
|
+
private _boundHandleOutsideClick;
|
|
64
|
+
private _boundHandleKeydown;
|
|
65
|
+
/** Timestamp when popconfirm was shown (to prevent immediate close from same click) */
|
|
66
|
+
private _showTimestamp;
|
|
67
|
+
/** Static instance for global access */
|
|
68
|
+
private static _instance;
|
|
69
|
+
connectedCallback(): void;
|
|
70
|
+
disconnectedCallback(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get the global instance
|
|
73
|
+
*/
|
|
74
|
+
static getInstance(): NrPopconfirmManagerElement | null;
|
|
75
|
+
/**
|
|
76
|
+
* Static helper to show a confirmation dialog
|
|
77
|
+
* Returns a promise that resolves to true if confirmed, false if cancelled
|
|
78
|
+
*/
|
|
79
|
+
static confirm(config: PopconfirmShowConfig, position: PopconfirmPosition): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Show a popconfirm at the specified position
|
|
82
|
+
*/
|
|
83
|
+
show(config: PopconfirmShowConfig, position: PopconfirmPosition): string;
|
|
84
|
+
/**
|
|
85
|
+
* Close a specific popconfirm
|
|
86
|
+
*/
|
|
87
|
+
close(id: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Close all popconfirms
|
|
90
|
+
*/
|
|
91
|
+
closeAll(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Handle confirm button click
|
|
94
|
+
*/
|
|
95
|
+
private handleConfirm;
|
|
96
|
+
/**
|
|
97
|
+
* Handle cancel button click
|
|
98
|
+
*/
|
|
99
|
+
private handleCancel;
|
|
100
|
+
/**
|
|
101
|
+
* Handle clicks outside the popconfirm
|
|
102
|
+
*/
|
|
103
|
+
private handleOutsideClick;
|
|
104
|
+
/**
|
|
105
|
+
* Handle escape key
|
|
106
|
+
*/
|
|
107
|
+
private handleKeydown;
|
|
108
|
+
/**
|
|
109
|
+
* Adjust position to keep popconfirm within viewport
|
|
110
|
+
*/
|
|
111
|
+
private adjustPosition;
|
|
112
|
+
/**
|
|
113
|
+
* Generate unique ID
|
|
114
|
+
*/
|
|
115
|
+
private generateId;
|
|
116
|
+
/**
|
|
117
|
+
* Get icon color based on icon type
|
|
118
|
+
*/
|
|
119
|
+
private getIconClass;
|
|
120
|
+
/**
|
|
121
|
+
* Render a single popconfirm item
|
|
122
|
+
*/
|
|
123
|
+
private renderItem;
|
|
124
|
+
render(): typeof nothing | import("lit-html").TemplateResult<1>;
|
|
125
|
+
}
|
|
126
|
+
declare global {
|
|
127
|
+
interface HTMLElementTagNameMap {
|
|
128
|
+
'nr-popconfirm-manager': NrPopconfirmManagerElement;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=popconfirm-manager.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popconfirm-manager.component.d.ts","sourceRoot":"","sources":["../../../../src/components/popconfirm/popconfirm-manager.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAKhD,OAAO,EAEL,oBAAoB,EACpB,kBAAkB,EAEnB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,2BAA2B,CAAC;AACnC,OAAO,+BAA+B,CAAC;AACvC,OAAO,6BAA6B,CAAC;;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBACa,0BAA2B,SAAQ,+BAA6B;IAC3E,OAAgB,MAAM,0BAA2B;IAExC,kBAAkB,WAAwC;IAEnE,8BAA8B;IACrB,OAAO,CAAC,KAAK,CAAwB;IAE9C,2BAA2B;IAC3B,OAAO,CAAC,wBAAwB,CAAqC;IACrE,OAAO,CAAC,mBAAmB,CAA6C;IAExE,uFAAuF;IACvF,OAAO,CAAC,cAAc,CAAa;IAEnC,wCAAwC;IACxC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA2C;IAE1D,iBAAiB,IAAI,IAAI;IAUzB,oBAAoB,IAAI,IAAI;IAYrC;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,0BAA0B,GAAG,IAAI;IAIvD;;;OAGG;WACU,OAAO,CAClB,MAAM,EAAE,oBAAoB,EAC5B,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,OAAO,CAAC;IAyBnB;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,QAAQ,EAAE,kBAAkB,GAAG,MAAM;IAyBxE;;OAEG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIvB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAIhB;;OAEG;YACW,aAAa;IA+B3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;OAEG;IACH,OAAO,CAAC,aAAa;IASrB;;OAEG;IACH,OAAO,CAAC,cAAc;IA6BtB;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACH,OAAO,CAAC,YAAY;IAYpB;;OAEG;IACH,OAAO,CAAC,UAAU;IA0DT,MAAM;CAWhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,uBAAuB,EAAE,0BAA0B,CAAC;KACrD;CACF"}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
7
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var NrPopconfirmManagerElement_1;
|
|
22
|
+
import { html, LitElement, nothing } from 'lit';
|
|
23
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
24
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
25
|
+
import { popconfirmManagerStyles } from './popconfirm-manager.style.js';
|
|
26
|
+
import { NuralyUIBaseMixin } from '@nuralyui/common/mixins';
|
|
27
|
+
// Import required components
|
|
28
|
+
import '../icon/icon.component.js';
|
|
29
|
+
import '../button/button.component.js';
|
|
30
|
+
import '../label/label.component.js';
|
|
31
|
+
/**
|
|
32
|
+
* # PopconfirmManager Component
|
|
33
|
+
*
|
|
34
|
+
* A container component that manages popconfirm instances displayed at cursor position.
|
|
35
|
+
* Similar to toast notifications but for confirmation dialogs.
|
|
36
|
+
*
|
|
37
|
+
* ## Features
|
|
38
|
+
* - Show popconfirm at cursor/mouse position
|
|
39
|
+
* - Programmatic API for creating confirmations
|
|
40
|
+
* - Async confirmation support with loading state
|
|
41
|
+
* - Auto-dismiss on outside click or escape
|
|
42
|
+
* - Customizable appearance and callbacks
|
|
43
|
+
*
|
|
44
|
+
* ## Usage
|
|
45
|
+
* ```html
|
|
46
|
+
* <!-- Add once to your app -->
|
|
47
|
+
* <nr-popconfirm-manager></nr-popconfirm-manager>
|
|
48
|
+
*
|
|
49
|
+
* <!-- Programmatic usage -->
|
|
50
|
+
* <script>
|
|
51
|
+
* const manager = document.querySelector('nr-popconfirm-manager');
|
|
52
|
+
*
|
|
53
|
+
* // Show at cursor position (from click event)
|
|
54
|
+
* element.addEventListener('click', (e) => {
|
|
55
|
+
* manager.show({
|
|
56
|
+
* title: 'Delete item?',
|
|
57
|
+
* description: 'This action cannot be undone.',
|
|
58
|
+
* okType: 'danger',
|
|
59
|
+
* onConfirm: () => {
|
|
60
|
+
* console.log('Deleted!');
|
|
61
|
+
* }
|
|
62
|
+
* }, { x: e.clientX, y: e.clientY });
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Or use the static confirm helper
|
|
66
|
+
* const confirmed = await NrPopconfirmManager.confirm({
|
|
67
|
+
* title: 'Are you sure?',
|
|
68
|
+
* }, { x: event.clientX, y: event.clientY });
|
|
69
|
+
* </script>
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @element nr-popconfirm-manager
|
|
73
|
+
* @fires nr-popconfirm-confirm - Fired when user confirms
|
|
74
|
+
* @fires nr-popconfirm-cancel - Fired when user cancels
|
|
75
|
+
*/
|
|
76
|
+
let NrPopconfirmManagerElement = NrPopconfirmManagerElement_1 = class NrPopconfirmManagerElement extends NuralyUIBaseMixin(LitElement) {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
this.requiredComponents = ['nr-icon', 'nr-button', 'nr-label'];
|
|
80
|
+
/** Active popconfirm items */
|
|
81
|
+
this.items = [];
|
|
82
|
+
/** Bound event handlers */
|
|
83
|
+
this._boundHandleOutsideClick = null;
|
|
84
|
+
this._boundHandleKeydown = null;
|
|
85
|
+
/** Timestamp when popconfirm was shown (to prevent immediate close from same click) */
|
|
86
|
+
this._showTimestamp = 0;
|
|
87
|
+
}
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
super.connectedCallback();
|
|
90
|
+
NrPopconfirmManagerElement_1._instance = this;
|
|
91
|
+
this._boundHandleOutsideClick = this.handleOutsideClick.bind(this);
|
|
92
|
+
this._boundHandleKeydown = this.handleKeydown.bind(this);
|
|
93
|
+
document.addEventListener('click', this._boundHandleOutsideClick, true);
|
|
94
|
+
document.addEventListener('keydown', this._boundHandleKeydown);
|
|
95
|
+
}
|
|
96
|
+
disconnectedCallback() {
|
|
97
|
+
super.disconnectedCallback();
|
|
98
|
+
NrPopconfirmManagerElement_1._instance = null;
|
|
99
|
+
if (this._boundHandleOutsideClick) {
|
|
100
|
+
document.removeEventListener('click', this._boundHandleOutsideClick, true);
|
|
101
|
+
}
|
|
102
|
+
if (this._boundHandleKeydown) {
|
|
103
|
+
document.removeEventListener('keydown', this._boundHandleKeydown);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the global instance
|
|
108
|
+
*/
|
|
109
|
+
static getInstance() {
|
|
110
|
+
return NrPopconfirmManagerElement_1._instance;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Static helper to show a confirmation dialog
|
|
114
|
+
* Returns a promise that resolves to true if confirmed, false if cancelled
|
|
115
|
+
*/
|
|
116
|
+
static confirm(config, position) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const instance = NrPopconfirmManagerElement_1.getInstance();
|
|
119
|
+
if (!instance) {
|
|
120
|
+
console.warn('NrPopconfirmManager: No instance found. Add <nr-popconfirm-manager> to your app.');
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return new Promise((resolve) => {
|
|
124
|
+
instance.show(Object.assign(Object.assign({}, config), { onConfirm: () => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
yield ((_a = config.onConfirm) === null || _a === void 0 ? void 0 : _a.call(config));
|
|
127
|
+
resolve(true);
|
|
128
|
+
}), onCancel: () => {
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = config.onCancel) === null || _a === void 0 ? void 0 : _a.call(config);
|
|
131
|
+
resolve(false);
|
|
132
|
+
} }), position);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Show a popconfirm at the specified position
|
|
138
|
+
*/
|
|
139
|
+
show(config, position) {
|
|
140
|
+
const id = this.generateId();
|
|
141
|
+
// Adjust position to keep popconfirm within viewport
|
|
142
|
+
const adjustedPosition = this.adjustPosition(position);
|
|
143
|
+
const item = {
|
|
144
|
+
id,
|
|
145
|
+
config,
|
|
146
|
+
position: adjustedPosition,
|
|
147
|
+
loading: false,
|
|
148
|
+
};
|
|
149
|
+
// Record timestamp to prevent immediate close from same click event
|
|
150
|
+
this._showTimestamp = Date.now();
|
|
151
|
+
// Only allow one popconfirm at a time
|
|
152
|
+
this.items = [item];
|
|
153
|
+
console.log('[nr-popconfirm-manager] show() called, items:', this.items);
|
|
154
|
+
this.requestUpdate();
|
|
155
|
+
return id;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Close a specific popconfirm
|
|
159
|
+
*/
|
|
160
|
+
close(id) {
|
|
161
|
+
this.items = this.items.filter(item => item.id !== id);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Close all popconfirms
|
|
165
|
+
*/
|
|
166
|
+
closeAll() {
|
|
167
|
+
this.items = [];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Handle confirm button click
|
|
171
|
+
*/
|
|
172
|
+
handleConfirm(item, e) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
const confirmEvent = new CustomEvent('nr-popconfirm-confirm', {
|
|
176
|
+
bubbles: true,
|
|
177
|
+
composed: true,
|
|
178
|
+
detail: { id: item.id, config: item.config },
|
|
179
|
+
});
|
|
180
|
+
this.dispatchEvent(confirmEvent);
|
|
181
|
+
// Handle async onConfirm
|
|
182
|
+
if (item.config.onConfirm) {
|
|
183
|
+
const result = item.config.onConfirm();
|
|
184
|
+
if (result && typeof result.then === 'function') {
|
|
185
|
+
// Show loading state
|
|
186
|
+
item.loading = true;
|
|
187
|
+
this.requestUpdate();
|
|
188
|
+
try {
|
|
189
|
+
yield result;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error('Popconfirm confirmation failed:', error);
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
item.loading = false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
this.close(item.id);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Handle cancel button click
|
|
204
|
+
*/
|
|
205
|
+
handleCancel(item, e) {
|
|
206
|
+
var _a, _b;
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
const cancelEvent = new CustomEvent('nr-popconfirm-cancel', {
|
|
209
|
+
bubbles: true,
|
|
210
|
+
composed: true,
|
|
211
|
+
detail: { id: item.id, config: item.config },
|
|
212
|
+
});
|
|
213
|
+
this.dispatchEvent(cancelEvent);
|
|
214
|
+
(_b = (_a = item.config).onCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
215
|
+
this.close(item.id);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Handle clicks outside the popconfirm
|
|
219
|
+
*/
|
|
220
|
+
handleOutsideClick(e) {
|
|
221
|
+
var _a;
|
|
222
|
+
if (this.items.length === 0)
|
|
223
|
+
return;
|
|
224
|
+
// Prevent immediate close from the same click event that opened the popconfirm
|
|
225
|
+
// Allow at least 100ms before responding to outside clicks
|
|
226
|
+
if (Date.now() - this._showTimestamp < 100) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const path = e.composedPath();
|
|
230
|
+
const popconfirmContainer = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.popconfirm-manager__item');
|
|
231
|
+
if (popconfirmContainer && !path.includes(popconfirmContainer)) {
|
|
232
|
+
// Cancel all open popconfirms
|
|
233
|
+
this.items.forEach(item => {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
(_b = (_a = item.config).onCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
236
|
+
});
|
|
237
|
+
this.closeAll();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Handle escape key
|
|
242
|
+
*/
|
|
243
|
+
handleKeydown(e) {
|
|
244
|
+
if (e.key === 'Escape' && this.items.length > 0) {
|
|
245
|
+
this.items.forEach(item => {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
(_b = (_a = item.config).onCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
248
|
+
});
|
|
249
|
+
this.closeAll();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Adjust position to keep popconfirm within viewport
|
|
254
|
+
*/
|
|
255
|
+
adjustPosition(position) {
|
|
256
|
+
const padding = 16;
|
|
257
|
+
const estimatedWidth = 280;
|
|
258
|
+
const estimatedHeight = 120;
|
|
259
|
+
const viewportWidth = window.innerWidth;
|
|
260
|
+
const viewportHeight = window.innerHeight;
|
|
261
|
+
let x = position.x;
|
|
262
|
+
let y = position.y;
|
|
263
|
+
// Adjust horizontal position
|
|
264
|
+
if (x + estimatedWidth > viewportWidth - padding) {
|
|
265
|
+
x = viewportWidth - estimatedWidth - padding;
|
|
266
|
+
}
|
|
267
|
+
if (x < padding) {
|
|
268
|
+
x = padding;
|
|
269
|
+
}
|
|
270
|
+
// Adjust vertical position
|
|
271
|
+
if (y + estimatedHeight > viewportHeight - padding) {
|
|
272
|
+
y = position.y - estimatedHeight - 8; // Show above cursor
|
|
273
|
+
}
|
|
274
|
+
if (y < padding) {
|
|
275
|
+
y = padding;
|
|
276
|
+
}
|
|
277
|
+
return { x, y };
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Generate unique ID
|
|
281
|
+
*/
|
|
282
|
+
generateId() {
|
|
283
|
+
return `popconfirm-${crypto.randomUUID()}`;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get icon color based on icon type
|
|
287
|
+
*/
|
|
288
|
+
getIconClass(icon) {
|
|
289
|
+
const iconColorMap = {
|
|
290
|
+
["exclamation-circle" /* PopconfirmIcon.Warning */]: 'warning',
|
|
291
|
+
["question-circle" /* PopconfirmIcon.Question */]: 'question',
|
|
292
|
+
["info-circle" /* PopconfirmIcon.Info */]: 'info',
|
|
293
|
+
["close-circle" /* PopconfirmIcon.Error */]: 'error',
|
|
294
|
+
["check-circle" /* PopconfirmIcon.Success */]: 'success',
|
|
295
|
+
};
|
|
296
|
+
return iconColorMap[icon || ''] || 'warning';
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Render a single popconfirm item
|
|
300
|
+
*/
|
|
301
|
+
renderItem(item) {
|
|
302
|
+
const { config, position } = item;
|
|
303
|
+
const icon = config.icon || "exclamation-circle" /* PopconfirmIcon.Warning */;
|
|
304
|
+
const iconClass = config.iconColor ? 'custom' : this.getIconClass(icon);
|
|
305
|
+
const showCancel = config.showCancel !== false;
|
|
306
|
+
const positionStyles = {
|
|
307
|
+
left: `${position.x}px`,
|
|
308
|
+
top: `${position.y}px`,
|
|
309
|
+
};
|
|
310
|
+
const iconStyles = config.iconColor ? { color: config.iconColor } : {};
|
|
311
|
+
return html `
|
|
312
|
+
<div
|
|
313
|
+
class="popconfirm-manager__item"
|
|
314
|
+
style=${styleMap(positionStyles)}
|
|
315
|
+
@click=${(e) => e.stopPropagation()}
|
|
316
|
+
>
|
|
317
|
+
<div class="popconfirm-manager__content">
|
|
318
|
+
<div class="popconfirm-manager__message">
|
|
319
|
+
<div
|
|
320
|
+
class="popconfirm-manager__icon popconfirm-manager__icon--${iconClass}"
|
|
321
|
+
style=${styleMap(iconStyles)}
|
|
322
|
+
>
|
|
323
|
+
<nr-icon name=${icon}></nr-icon>
|
|
324
|
+
</div>
|
|
325
|
+
<div class="popconfirm-manager__text">
|
|
326
|
+
${config.title ? html `<nr-label class="popconfirm-manager__title" size="medium">${config.title}</nr-label>` : nothing}
|
|
327
|
+
${config.description ? html `<nr-label class="popconfirm-manager__description" size="small" variant="secondary">${config.description}</nr-label>` : nothing}
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
<div class="popconfirm-manager__buttons">
|
|
331
|
+
${showCancel
|
|
332
|
+
? html `
|
|
333
|
+
<nr-button
|
|
334
|
+
size="small"
|
|
335
|
+
@click=${(e) => this.handleCancel(item, e)}
|
|
336
|
+
>
|
|
337
|
+
${config.cancelText || 'Cancel'}
|
|
338
|
+
</nr-button>
|
|
339
|
+
`
|
|
340
|
+
: nothing}
|
|
341
|
+
<nr-button
|
|
342
|
+
size="small"
|
|
343
|
+
type=${config.okType === 'danger' ? 'danger' : config.okType === 'primary' ? 'primary' : 'default'}
|
|
344
|
+
?loading=${item.loading}
|
|
345
|
+
?disabled=${item.loading}
|
|
346
|
+
@click=${(e) => this.handleConfirm(item, e)}
|
|
347
|
+
>
|
|
348
|
+
${config.okText || 'OK'}
|
|
349
|
+
</nr-button>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
`;
|
|
354
|
+
}
|
|
355
|
+
render() {
|
|
356
|
+
if (this.items.length === 0) {
|
|
357
|
+
return nothing;
|
|
358
|
+
}
|
|
359
|
+
return html `
|
|
360
|
+
<div class="popconfirm-manager">
|
|
361
|
+
${this.items.map(item => this.renderItem(item))}
|
|
362
|
+
</div>
|
|
363
|
+
`;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
NrPopconfirmManagerElement.styles = popconfirmManagerStyles;
|
|
367
|
+
/** Static instance for global access */
|
|
368
|
+
NrPopconfirmManagerElement._instance = null;
|
|
369
|
+
__decorate([
|
|
370
|
+
state()
|
|
371
|
+
], NrPopconfirmManagerElement.prototype, "items", void 0);
|
|
372
|
+
NrPopconfirmManagerElement = NrPopconfirmManagerElement_1 = __decorate([
|
|
373
|
+
customElement('nr-popconfirm-manager')
|
|
374
|
+
], NrPopconfirmManagerElement);
|
|
375
|
+
export { NrPopconfirmManagerElement };
|
|
376
|
+
//# sourceMappingURL=popconfirm-manager.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popconfirm-manager.component.js","sourceRoot":"","sources":["../../../../src/components/popconfirm/popconfirm-manager.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,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ElD,CAAC;IACJ,CAAC;CACF,CAAA;AA7UiB,iCAAM,GAAG,uBAAwB,CAAA;AAcjD,wCAAwC;AACzB,oCAAS,GAAsC,IAAK,CAAA;AAV1D;IAAR,KAAK,EAAE;yDAAsC;AANnC,0BAA0B;IADtC,aAAa,CAAC,uBAAuB,CAAC;GAC1B,0BAA0B,CA8UtC;SA9UY,0BAA0B","sourcesContent":["/**\n * @license\n * Copyright 2023 Nuraly, Laabidi Aymen\n * SPDX-License-Identifier: MIT\n */\n\nimport { html, LitElement, nothing } from 'lit';\nimport { customElement, state } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { popconfirmManagerStyles } from './popconfirm-manager.style.js';\nimport { NuralyUIBaseMixin } from '@nuralyui/common/mixins';\nimport {\n PopconfirmIcon,\n PopconfirmShowConfig,\n PopconfirmPosition,\n PopconfirmItem,\n} from './popconfirm.types.js';\n\n// Import required components\nimport '../icon/icon.component.js';\nimport '../button/button.component.js';\nimport '../label/label.component.js';\n\n/**\n * # PopconfirmManager Component\n *\n * A container component that manages popconfirm instances displayed at cursor position.\n * Similar to toast notifications but for confirmation dialogs.\n *\n * ## Features\n * - Show popconfirm at cursor/mouse position\n * - Programmatic API for creating confirmations\n * - Async confirmation support with loading state\n * - Auto-dismiss on outside click or escape\n * - Customizable appearance and callbacks\n *\n * ## Usage\n * ```html\n * <!-- Add once to your app -->\n * <nr-popconfirm-manager></nr-popconfirm-manager>\n *\n * <!-- Programmatic usage -->\n * <script>\n * const manager = document.querySelector('nr-popconfirm-manager');\n *\n * // Show at cursor position (from click event)\n * element.addEventListener('click', (e) => {\n * manager.show({\n * title: 'Delete item?',\n * description: 'This action cannot be undone.',\n * okType: 'danger',\n * onConfirm: () => {\n * console.log('Deleted!');\n * }\n * }, { x: e.clientX, y: e.clientY });\n * });\n *\n * // Or use the static confirm helper\n * const confirmed = await NrPopconfirmManager.confirm({\n * title: 'Are you sure?',\n * }, { x: event.clientX, y: event.clientY });\n * </script>\n * ```\n *\n * @element nr-popconfirm-manager\n * @fires nr-popconfirm-confirm - Fired when user confirms\n * @fires nr-popconfirm-cancel - Fired when user cancels\n */\n@customElement('nr-popconfirm-manager')\nexport class NrPopconfirmManagerElement extends NuralyUIBaseMixin(LitElement) {\n static override styles = popconfirmManagerStyles;\n\n override requiredComponents = ['nr-icon', 'nr-button', 'nr-label'];\n\n /** Active popconfirm items */\n @state() private items: PopconfirmItem[] = [];\n\n /** Bound event handlers */\n private _boundHandleOutsideClick: ((e: Event) => void) | null = null;\n private _boundHandleKeydown: ((e: KeyboardEvent) => void) | null = null;\n\n /** Timestamp when popconfirm was shown (to prevent immediate close from same click) */\n private _showTimestamp: number = 0;\n\n /** Static instance for global access */\n private static _instance: NrPopconfirmManagerElement | null = null;\n\n override connectedCallback(): void {\n super.connectedCallback();\n NrPopconfirmManagerElement._instance = this;\n\n this._boundHandleOutsideClick = this.handleOutsideClick.bind(this);\n this._boundHandleKeydown = this.handleKeydown.bind(this);\n document.addEventListener('click', this._boundHandleOutsideClick, true);\n document.addEventListener('keydown', this._boundHandleKeydown);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n NrPopconfirmManagerElement._instance = null;\n\n if (this._boundHandleOutsideClick) {\n document.removeEventListener('click', this._boundHandleOutsideClick, true);\n }\n if (this._boundHandleKeydown) {\n document.removeEventListener('keydown', this._boundHandleKeydown);\n }\n }\n\n /**\n * Get the global instance\n */\n static getInstance(): NrPopconfirmManagerElement | null {\n return NrPopconfirmManagerElement._instance;\n }\n\n /**\n * Static helper to show a confirmation dialog\n * Returns a promise that resolves to true if confirmed, false if cancelled\n */\n static async confirm(\n config: PopconfirmShowConfig,\n position: PopconfirmPosition\n ): Promise<boolean> {\n const instance = NrPopconfirmManagerElement.getInstance();\n if (!instance) {\n console.warn('NrPopconfirmManager: No instance found. Add <nr-popconfirm-manager> to your app.');\n return false;\n }\n\n return new Promise((resolve) => {\n instance.show(\n {\n ...config,\n onConfirm: async () => {\n await config.onConfirm?.();\n resolve(true);\n },\n onCancel: () => {\n config.onCancel?.();\n resolve(false);\n },\n },\n position\n );\n });\n }\n\n /**\n * Show a popconfirm at the specified position\n */\n show(config: PopconfirmShowConfig, position: PopconfirmPosition): string {\n const id = this.generateId();\n\n // Adjust position to keep popconfirm within viewport\n const adjustedPosition = this.adjustPosition(position);\n\n const item: PopconfirmItem = {\n id,\n config,\n position: adjustedPosition,\n loading: false,\n };\n\n // Record timestamp to prevent immediate close from same click event\n this._showTimestamp = Date.now();\n\n // Only allow one popconfirm at a time\n this.items = [item];\n\n console.log('[nr-popconfirm-manager] show() called, items:', this.items);\n this.requestUpdate();\n\n return id;\n }\n\n /**\n * Close a specific popconfirm\n */\n close(id: string): void {\n this.items = this.items.filter(item => item.id !== id);\n }\n\n /**\n * Close all popconfirms\n */\n closeAll(): void {\n this.items = [];\n }\n\n /**\n * Handle confirm button click\n */\n private async handleConfirm(item: PopconfirmItem, e: Event): Promise<void> {\n e.stopPropagation();\n\n const confirmEvent = new CustomEvent('nr-popconfirm-confirm', {\n bubbles: true,\n composed: true,\n detail: { id: item.id, config: item.config },\n });\n this.dispatchEvent(confirmEvent);\n\n // Handle async onConfirm\n if (item.config.onConfirm) {\n const result = item.config.onConfirm();\n if (result && typeof (result as Promise<void>).then === 'function') {\n // Show loading state\n item.loading = true;\n this.requestUpdate();\n\n try {\n await result;\n } catch (error) {\n console.error('Popconfirm confirmation failed:', error);\n } finally {\n item.loading = false;\n }\n }\n }\n\n this.close(item.id);\n }\n\n /**\n * Handle cancel button click\n */\n private handleCancel(item: PopconfirmItem, e: Event): void {\n e.stopPropagation();\n\n const cancelEvent = new CustomEvent('nr-popconfirm-cancel', {\n bubbles: true,\n composed: true,\n detail: { id: item.id, config: item.config },\n });\n this.dispatchEvent(cancelEvent);\n\n item.config.onCancel?.();\n this.close(item.id);\n }\n\n /**\n * Handle clicks outside the popconfirm\n */\n private handleOutsideClick(e: Event): void {\n if (this.items.length === 0) return;\n\n // Prevent immediate close from the same click event that opened the popconfirm\n // Allow at least 100ms before responding to outside clicks\n if (Date.now() - this._showTimestamp < 100) {\n return;\n }\n\n const path = e.composedPath();\n const popconfirmContainer = this.shadowRoot?.querySelector('.popconfirm-manager__item');\n\n if (popconfirmContainer && !path.includes(popconfirmContainer)) {\n // Cancel all open popconfirms\n this.items.forEach(item => {\n item.config.onCancel?.();\n });\n this.closeAll();\n }\n }\n\n /**\n * Handle escape key\n */\n private handleKeydown(e: KeyboardEvent): void {\n if (e.key === 'Escape' && this.items.length > 0) {\n this.items.forEach(item => {\n item.config.onCancel?.();\n });\n this.closeAll();\n }\n }\n\n /**\n * Adjust position to keep popconfirm within viewport\n */\n private adjustPosition(position: PopconfirmPosition): PopconfirmPosition {\n const padding = 16;\n const estimatedWidth = 280;\n const estimatedHeight = 120;\n const viewportWidth = window.innerWidth;\n const viewportHeight = window.innerHeight;\n\n let x = position.x;\n let y = position.y;\n\n // Adjust horizontal position\n if (x + estimatedWidth > viewportWidth - padding) {\n x = viewportWidth - estimatedWidth - padding;\n }\n if (x < padding) {\n x = padding;\n }\n\n // Adjust vertical position\n if (y + estimatedHeight > viewportHeight - padding) {\n y = position.y - estimatedHeight - 8; // Show above cursor\n }\n if (y < padding) {\n y = padding;\n }\n\n return { x, y };\n }\n\n /**\n * Generate unique ID\n */\n private generateId(): string {\n return `popconfirm-${crypto.randomUUID()}`;\n }\n\n /**\n * Get icon color based on icon type\n */\n private getIconClass(icon?: string): string {\n const iconColorMap: Record<string, string> = {\n [PopconfirmIcon.Warning]: 'warning',\n [PopconfirmIcon.Question]: 'question',\n [PopconfirmIcon.Info]: 'info',\n [PopconfirmIcon.Error]: 'error',\n [PopconfirmIcon.Success]: 'success',\n };\n\n return iconColorMap[icon || ''] || 'warning';\n }\n\n /**\n * Render a single popconfirm item\n */\n private renderItem(item: PopconfirmItem) {\n const { config, position } = item;\n const icon = config.icon || PopconfirmIcon.Warning;\n const iconClass = config.iconColor ? 'custom' : this.getIconClass(icon);\n const showCancel = config.showCancel !== false;\n\n const positionStyles = {\n left: `${position.x}px`,\n top: `${position.y}px`,\n };\n\n const iconStyles = config.iconColor ? { color: config.iconColor } : {};\n\n return html`\n <div\n class=\"popconfirm-manager__item\"\n style=${styleMap(positionStyles)}\n @click=${(e: Event) => e.stopPropagation()}\n >\n <div class=\"popconfirm-manager__content\">\n <div class=\"popconfirm-manager__message\">\n <div\n class=\"popconfirm-manager__icon popconfirm-manager__icon--${iconClass}\"\n style=${styleMap(iconStyles)}\n >\n <nr-icon name=${icon}></nr-icon>\n </div>\n <div class=\"popconfirm-manager__text\">\n ${config.title ? html`<nr-label class=\"popconfirm-manager__title\" size=\"medium\">${config.title}</nr-label>` : nothing}\n ${config.description ? html`<nr-label class=\"popconfirm-manager__description\" size=\"small\" variant=\"secondary\">${config.description}</nr-label>` : nothing}\n </div>\n </div>\n <div class=\"popconfirm-manager__buttons\">\n ${showCancel\n ? html`\n <nr-button\n size=\"small\"\n @click=${(e: Event) => this.handleCancel(item, e)}\n >\n ${config.cancelText || 'Cancel'}\n </nr-button>\n `\n : nothing}\n <nr-button\n size=\"small\"\n type=${config.okType === 'danger' ? 'danger' : config.okType === 'primary' ? 'primary' : 'default'}\n ?loading=${item.loading}\n ?disabled=${item.loading}\n @click=${(e: Event) => this.handleConfirm(item, e)}\n >\n ${config.okText || 'OK'}\n </nr-button>\n </div>\n </div>\n </div>\n `;\n }\n\n override render() {\n if (this.items.length === 0) {\n return nothing;\n }\n\n return html`\n <div class=\"popconfirm-manager\">\n ${this.items.map(item => this.renderItem(item))}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nr-popconfirm-manager': NrPopconfirmManagerElement;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popconfirm-manager.style.d.ts","sourceRoot":"","sources":["../../../../src/components/popconfirm/popconfirm-manager.style.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,yBAsInC,CAAC"}
|