2 * TinyMCE version 6.6.2 (2023-08-09)
8 var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
10 const option = name => editor => editor.options.get(name);
11 const register$2 = editor => {
12 const registerOption = editor.options.register;
13 registerOption('insertdatetime_dateformat', {
15 default: editor.translate('%Y-%m-%d')
17 registerOption('insertdatetime_timeformat', {
19 default: editor.translate('%H:%M:%S')
21 registerOption('insertdatetime_formats', {
22 processor: 'string[]',
30 registerOption('insertdatetime_element', {
35 const getDateFormat = option('insertdatetime_dateformat');
36 const getTimeFormat = option('insertdatetime_timeformat');
37 const getFormats = option('insertdatetime_formats');
38 const shouldInsertTimeElement = option('insertdatetime_element');
39 const getDefaultDateTime = editor => {
40 const formats = getFormats(editor);
41 return formats.length > 0 ? formats[0] : getTimeFormat(editor);
44 const daysShort = 'Sun Mon Tue Wed Thu Fri Sat Sun'.split(' ');
45 const daysLong = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday'.split(' ');
46 const monthsShort = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
47 const monthsLong = 'January February March April May June July August September October November December'.split(' ');
48 const addZeros = (value, len) => {
50 if (value.length < len) {
51 for (let i = 0; i < len - value.length; i++) {
57 const getDateTime = (editor, fmt, date = new Date()) => {
58 fmt = fmt.replace('%D', '%m/%d/%Y');
59 fmt = fmt.replace('%r', '%I:%M:%S %p');
60 fmt = fmt.replace('%Y', '' + date.getFullYear());
61 fmt = fmt.replace('%y', '' + date.getYear());
62 fmt = fmt.replace('%m', addZeros(date.getMonth() + 1, 2));
63 fmt = fmt.replace('%d', addZeros(date.getDate(), 2));
64 fmt = fmt.replace('%H', '' + addZeros(date.getHours(), 2));
65 fmt = fmt.replace('%M', '' + addZeros(date.getMinutes(), 2));
66 fmt = fmt.replace('%S', '' + addZeros(date.getSeconds(), 2));
67 fmt = fmt.replace('%I', '' + ((date.getHours() + 11) % 12 + 1));
68 fmt = fmt.replace('%p', '' + (date.getHours() < 12 ? 'AM' : 'PM'));
69 fmt = fmt.replace('%B', '' + editor.translate(monthsLong[date.getMonth()]));
70 fmt = fmt.replace('%b', '' + editor.translate(monthsShort[date.getMonth()]));
71 fmt = fmt.replace('%A', '' + editor.translate(daysLong[date.getDay()]));
72 fmt = fmt.replace('%a', '' + editor.translate(daysShort[date.getDay()]));
73 fmt = fmt.replace('%%', '%');
76 const updateElement = (editor, timeElm, computerTime, userTime) => {
77 const newTimeElm = editor.dom.create('time', { datetime: computerTime }, userTime);
78 editor.dom.replace(newTimeElm, timeElm);
79 editor.selection.select(newTimeElm, true);
80 editor.selection.collapse(false);
82 const insertDateTime = (editor, format) => {
83 if (shouldInsertTimeElement(editor)) {
84 const userTime = getDateTime(editor, format);
86 if (/%[HMSIp]/.test(format)) {
87 computerTime = getDateTime(editor, '%Y-%m-%dT%H:%M');
89 computerTime = getDateTime(editor, '%Y-%m-%d');
91 const timeElm = editor.dom.getParent(editor.selection.getStart(), 'time');
93 updateElement(editor, timeElm, computerTime, userTime);
95 editor.insertContent('<time datetime="' + computerTime + '">' + userTime + '</time>');
98 editor.insertContent(getDateTime(editor, format));
102 const register$1 = editor => {
103 editor.addCommand('mceInsertDate', (_ui, value) => {
104 insertDateTime(editor, value !== null && value !== void 0 ? value : getDateFormat(editor));
106 editor.addCommand('mceInsertTime', (_ui, value) => {
107 insertDateTime(editor, value !== null && value !== void 0 ? value : getTimeFormat(editor));
111 const Cell = initial => {
125 var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
127 const onSetupEditable = editor => api => {
128 const nodeChanged = () => {
129 api.setEnabled(editor.selection.isEditable());
131 editor.on('NodeChange', nodeChanged);
134 editor.off('NodeChange', nodeChanged);
137 const register = editor => {
138 const formats = getFormats(editor);
139 const defaultFormat = Cell(getDefaultDateTime(editor));
140 const insertDateTime = format => editor.execCommand('mceInsertDate', false, format);
141 editor.ui.registry.addSplitButton('insertdatetime', {
143 tooltip: 'Insert date/time',
144 select: value => value === defaultFormat.get(),
146 done(global.map(formats, format => ({
148 text: getDateTime(editor, format),
153 insertDateTime(defaultFormat.get());
155 onItemAction: (_api, value) => {
156 defaultFormat.set(value);
157 insertDateTime(value);
159 onSetup: onSetupEditable(editor)
161 const makeMenuItemHandler = format => () => {
162 defaultFormat.set(format);
163 insertDateTime(format);
165 editor.ui.registry.addNestedMenuItem('insertdatetime', {
168 getSubmenuItems: () => global.map(formats, format => ({
170 text: getDateTime(editor, format),
171 onAction: makeMenuItemHandler(format)
173 onSetup: onSetupEditable(editor)
178 global$1.add('insertdatetime', editor => {