import { IEOEditor } from "../IEOEditor";
/**
* EOEditor command interface
*/
export interface IEOEditorCommand {
/**
* Icon
*/
icon: string;
/**
* Label
*/
label?: string;
/**
* Action
*/
action?: (editor: IEOEditor) => boolean;
/**
* Detect tag name
*/
detectTag?: string;
/**
* Detect style name and value
*/
detectStyle?: [string, string];
}
/**
* EOEditor icon command interface
*/
export interface IEOEditorIconCommand {
/**
* Name
*/
name: string;
/**
* Icon
*/
icon: string;
/**
* Label
*/
label: string;
/**
* Action
*/
action?: () => void;
}
/**
* EOEditor separator
*/
export const EOEditorSeparator: IEOEditorCommand & IEOEditorIconCommand = {
name: "s",
icon: "",
label: ""
};
/**
* EOEditor command creator interface
*/
export interface IEOEditorCommandCreator {
/**
* Name
*/
name: EOEditorCommandKey;
/**
* Command
*/
command: IEOEditorCommand;
/**
* Sub commands
*/
subs?: EOEditorCommandKey[];
}
/**
* EOEditor commands interface
*/
export interface IEOEditorCommands {
about: IEOEditorCommand;
align: IEOEditorCommand;
backColor: IEOEditorCommand;
bold: IEOEditorCommand;
code: IEOEditorCommand;
copy: IEOEditorCommand;
custom1: IEOEditorCommand;
custom2: IEOEditorCommand;
custom3: IEOEditorCommand;
cut: IEOEditorCommand;
decreaseFontSize: IEOEditorCommand;
delete: IEOEditorCommand;
foreColor: IEOEditorCommand;
formatBlock: IEOEditorCommand;
fullscreen: IEOEditorCommand;
h1: IEOEditorCommand;
h2: IEOEditorCommand;
h3: IEOEditorCommand;
h4: IEOEditorCommand;
h5: IEOEditorCommand;
h6: IEOEditorCommand;
hp: IEOEditorCommand;
iframe: IEOEditorCommand;
increaseFontSize: IEOEditorCommand;
indent: IEOEditorCommand;
insertHorizontalRule: IEOEditorCommand;
insertImage: IEOEditorCommand;
insertOrderedList: IEOEditorCommand;
insertTable: IEOEditorCommand;
insertText: IEOEditorCommand;
insertUnorderedList: IEOEditorCommand;
italic: IEOEditorCommand;
justifyCenter: IEOEditorCommand;
justifyFull: IEOEditorCommand;
justifyLeft: IEOEditorCommand;
justifyRight: IEOEditorCommand;
link: IEOEditorCommand;
lock: IEOEditorCommand;
more: IEOEditorCommand;
object: IEOEditorCommand;
outdent: IEOEditorCommand;
paste: IEOEditorCommand;
redo: IEOEditorCommand;
removeFormat: IEOEditorCommand;
s: IEOEditorCommand;
source: IEOEditorCommand;
strikeThrough: IEOEditorCommand;
style: IEOEditorCommand;
subscript: IEOEditorCommand;
symbols: IEOEditorCommand;
superscript: IEOEditorCommand;
textbox: IEOEditorCommand;
underline: IEOEditorCommand;
undo: IEOEditorCommand;
unlink: IEOEditorCommand;
video: IEOEditorCommand;
}
/**
* EOEditor command key
*/
export type EOEditorCommandKey = keyof IEOEditorCommands;
// EOEditor commands array for query
type EOEditorCommandsArray = (EOEditorCommandKey | EOEditorCommandKey[])[];
/**
* EOEditor other SVG paths
*/
export const EOEditorSVGs = {
arrayRight: '',
edit: '',
tableEdit:
'',
tableColumnAddAfter:
'',
tableColumnAddBefore:
'',
tableColumnRemove:
'',
tableMergeCells:
'',
tableRemove:
'',
tableRowAddAfter:
'',
tableRowAddBefore:
'',
tableRowRemove:
'',
tableSplitCell:
'',
upload: '',
floatCenter:
'',
floatLeft:
'',
floatNone:
'',
floatRight:
''
};
/**
* EOEditor all supported commands
* Icons: https://materialdesignicons.com/
*/
export const EOEditorCommands: IEOEditorCommands = {
about: {
icon: ''
},
align: {
icon: ''
},
backColor: {
icon: ''
},
bold: {
icon: '',
detectTag: "b",
detectStyle: ["fontWeight", "bold"]
},
code: {
icon: ''
},
copy: {
icon: ''
},
custom1: {
icon: ""
},
custom2: {
icon: ""
},
custom3: {
icon: ""
},
cut: {
icon: ''
},
decreaseFontSize: {
icon: ''
},
delete: {
icon: ''
},
foreColor: {
icon: ''
},
formatBlock: {
icon: ""
},
fullscreen: {
icon: ''
},
h1: {
icon: '',
detectTag: "h1"
},
h2: {
icon: '',
detectTag: "h2"
},
h3: {
icon: '',
detectTag: "h3"
},
h4: {
icon: '',
detectTag: "h4"
},
h5: {
icon: '',
detectTag: "h5"
},
h6: {
icon: '',
detectTag: "h6"
},
hp: {
icon: '',
detectTag: "p"
},
iframe: {
icon: ''
},
increaseFontSize: {
icon: ''
},
indent: {
icon: ''
},
insertHorizontalRule: {
icon: ''
},
insertImage: {
icon: ''
},
insertOrderedList: {
icon: ''
},
insertTable: {
icon: ''
},
insertText: {
icon: ''
},
insertUnorderedList: {
icon: '',
detectTag: "ul"
},
italic: {
icon: '',
detectTag: "i",
detectStyle: ["fontStyle", "italic"]
},
justifyCenter: {
icon: '',
detectStyle: ["textAlign", "center"]
},
justifyFull: {
icon: '',
detectStyle: ["textAlign", "justify"]
},
justifyLeft: {
icon: '',
detectStyle: ["textAlign", "left"]
},
justifyRight: {
icon: '',
detectStyle: ["textAlign", "right"]
},
link: {
icon: '',
detectTag: "a"
},
lock: {
icon: ''
},
more: {
icon: ''
},
object: {
icon: ""
},
outdent: {
icon: ''
},
paste: {
icon: ''
},
redo: {
icon: ''
},
removeFormat: {
icon: ''
},
s: {
icon: "|"
},
source: {
icon: ''
},
strikeThrough: {
icon: '',
detectTag: "strike",
detectStyle: ["textDecorationLine", "line-through"]
},
style: {
icon: ''
},
subscript: {
icon: '',
detectTag: "sub"
},
superscript: {
icon: '',
detectTag: "sup"
},
symbols: {
icon: ''
},
textbox: {
icon: ''
},
underline: {
icon: '',
detectTag: "u",
detectStyle: ["textDecorationLine", "underline"]
},
undo: {
icon: ''
},
unlink: {
icon: ''
},
video: {
icon: ''
}
};
export function EOEditorCommandsParse(commands: string | null | undefined) {
const items: EOEditorCommandsArray = commands?.startsWith("[")
? JSON.parse(commands)
: commands === "simple"
? ["bold", "italic", "underline"]
: [
"undo",
"redo",
"s",
["formatBlock", "hp", "h1", "h2", "h3", "h4"],
"bold",
"italic",
"underline",
"strikeThrough",
"foreColor",
"backColor",
"style",
"removeFormat",
"s",
[
"align",
"justifyLeft",
"justifyCenter",
"justifyRight",
"justifyFull"
],
"s",
"textbox",
"insertImage",
"link",
"insertUnorderedList",
"insertOrderedList",
"insertTable",
[
"more",
"insertHorizontalRule",
"symbols",
"code",
"s",
"indent",
"outdent",
"s",
"subscript",
"superscript",
"s",
"video",
"iframe"
],
"s",
"lock",
"source"
];
// Auto attach about / fullscreen icon
items.push("s", "about", "fullscreen");
return items.map((item): IEOEditorCommandCreator => {
if (Array.isArray(item)) {
const [first, ...subs] = item;
return {
name: first,
command: EOEditorCommands[first],
subs
};
}
return { name: item, command: EOEditorCommands[item] };
});
}