big restructure
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { warnOnce } from '../core/app-dom.js';
|
||||
|
||||
let multiSelectLoader = null;
|
||||
|
||||
const resolveScriptUrl = (script) => {
|
||||
@@ -65,13 +67,14 @@ export const initMultiSelect = async (target = '[data-multi-select]') => {
|
||||
try {
|
||||
instance = new MultiSelect(element, options);
|
||||
} catch (error) {
|
||||
console.error('[multi-select] init failed', element, error);
|
||||
warnOnce('UI_INIT_FAIL', 'multi-select init failed', { module: 'multi-select', element, error });
|
||||
return;
|
||||
}
|
||||
if (element.dataset.disabled === 'true' || element.disabled) {
|
||||
instance.disable();
|
||||
}
|
||||
element.dataset.multiSelectInit = '1';
|
||||
element._multiSelectInstance = instance;
|
||||
instances.push(instance);
|
||||
if (syncInput) {
|
||||
syncInput._multiSelectInstance = instance;
|
||||
@@ -98,8 +101,22 @@ export const initMultiSelect = async (target = '[data-multi-select]') => {
|
||||
return instances;
|
||||
};
|
||||
|
||||
export const getMultiSelectInstance = (target) => {
|
||||
const element = typeof target === 'string' ? document.querySelector(target) : target;
|
||||
if (!element) return null;
|
||||
if (element._multiSelectInstance) return element._multiSelectInstance;
|
||||
const syncTarget = element.dataset?.syncTarget;
|
||||
if (syncTarget) {
|
||||
const syncElement = document.querySelector(syncTarget);
|
||||
if (syncElement && syncElement._multiSelectInstance) return syncElement._multiSelectInstance;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const autoInit = () => {
|
||||
initMultiSelect().catch(() => {});
|
||||
initMultiSelect().catch((error) => {
|
||||
warnOnce('UI_INIT_FAIL', 'multi-select auto init failed', { module: 'multi-select', error });
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
|
||||
Reference in New Issue
Block a user