) => {
const stack: string[] = [];
if (isPlainObject(colors)) {
Object.keys(colors).forEach(key => {
stack.push(
''
);
stack.push(eachColor((colors as any)[key]));
stack.push('
');
});
} else if (isArray(colors)) {
colors.forEach(color => {
stack.push(
''
);
});
}
return stack.join('');
};
form.appendChild(
editor.c.fromHTML(
'' +
eachColor(editor.o.colors) +
'
'
)
);
form.appendChild(
editor.c.fromHTML(
''
)
);
const { extra } = refs(form);
if (editor.o.showBrowserColorPicker && hasBrowserColorPicker()) {
extra.appendChild(
editor.c.fromHTML(
'' +
iconPalette +
'' +
'
'
)
);
editor.e.on(form, 'change', (e: MouseEvent) => {
e.stopPropagation();
const target: HTMLInputElement = e.target as HTMLInputElement;
if (!target || !target.tagName || !Dom.isTag(target, 'input')) {
return;
}
const color: string = target.value || '';
if (isFunction(callback)) {
callback(color);
}
e.preventDefault();
});
}
editor.e.on(form, 'mousedown touchend', (e: MouseEvent) => {
e.stopPropagation();
let target = e.target as HTMLElement;
if (
(!target ||
!target.tagName ||
Dom.isTag(target, 'svg') ||
Dom.isTag(target, 'path')) &&
target.parentNode
) {
target = Dom.closest(
target.parentNode,
'a',
editor.editor
) as HTMLElement;
}
if (!Dom.isTag(target, 'a')) {
return;
}
const color: string = attr(target, '-color') || '';
if (callback && typeof callback === 'function') {
callback(color);
}
e.preventDefault();
});
editor.e.fire('afterGenerateColorPicker', form, extra, callback, valueHex);
return form;
};