Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/**
2
 * TinyMCE version 6.8.3 (2024-02-08)
3
 */
4
 
5
(function () {
6
    'use strict';
7
 
8
    var global$4 = tinymce.util.Tools.resolve('tinymce.PluginManager');
9
 
10
    const hasProto = (v, constructor, predicate) => {
11
      var _a;
12
      if (predicate(v, constructor.prototype)) {
13
        return true;
14
      } else {
15
        return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
16
      }
17
    };
18
    const typeOf = x => {
19
      const t = typeof x;
20
      if (x === null) {
21
        return 'null';
22
      } else if (t === 'object' && Array.isArray(x)) {
23
        return 'array';
24
      } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
25
        return 'string';
26
      } else {
27
        return t;
28
      }
29
    };
30
    const isType = type => value => typeOf(value) === type;
31
    const eq = t => a => t === a;
32
    const isString = isType('string');
33
    const isUndefined = eq(undefined);
34
 
35
    var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay');
36
 
37
    var global$2 = tinymce.util.Tools.resolve('tinymce.util.LocalStorage');
38
 
39
    var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
40
 
41
    const fireRestoreDraft = editor => editor.dispatch('RestoreDraft');
42
    const fireStoreDraft = editor => editor.dispatch('StoreDraft');
43
    const fireRemoveDraft = editor => editor.dispatch('RemoveDraft');
44
 
45
    const parse = timeString => {
46
      const multiples = {
47
        s: 1000,
48
        m: 60000
49
      };
50
      const parsedTime = /^(\d+)([ms]?)$/.exec(timeString);
51
      return (parsedTime && parsedTime[2] ? multiples[parsedTime[2]] : 1) * parseInt(timeString, 10);
52
    };
53
 
54
    const option = name => editor => editor.options.get(name);
55
    const register$1 = editor => {
56
      const registerOption = editor.options.register;
57
      const timeProcessor = value => {
58
        const valid = isString(value);
59
        if (valid) {
60
          return {
61
            value: parse(value),
62
            valid
63
          };
64
        } else {
65
          return {
66
            valid: false,
67
            message: 'Must be a string.'
68
          };
69
        }
70
      };
71
      registerOption('autosave_ask_before_unload', {
72
        processor: 'boolean',
73
        default: true
74
      });
75
      registerOption('autosave_prefix', {
76
        processor: 'string',
77
        default: 'tinymce-autosave-{path}{query}{hash}-{id}-'
78
      });
79
      registerOption('autosave_restore_when_empty', {
80
        processor: 'boolean',
81
        default: false
82
      });
83
      registerOption('autosave_interval', {
84
        processor: timeProcessor,
85
        default: '30s'
86
      });
87
      registerOption('autosave_retention', {
88
        processor: timeProcessor,
89
        default: '20m'
90
      });
91
    };
92
    const shouldAskBeforeUnload = option('autosave_ask_before_unload');
93
    const shouldRestoreWhenEmpty = option('autosave_restore_when_empty');
94
    const getAutoSaveInterval = option('autosave_interval');
95
    const getAutoSaveRetention = option('autosave_retention');
96
    const getAutoSavePrefix = editor => {
97
      const location = document.location;
98
      return editor.options.get('autosave_prefix').replace(/{path}/g, location.pathname).replace(/{query}/g, location.search).replace(/{hash}/g, location.hash).replace(/{id}/g, editor.id);
99
    };
100
 
101
    const isEmpty = (editor, html) => {
102
      if (isUndefined(html)) {
103
        return editor.dom.isEmpty(editor.getBody());
104
      } else {
105
        const trimmedHtml = global$1.trim(html);
106
        if (trimmedHtml === '') {
107
          return true;
108
        } else {
109
          const fragment = new DOMParser().parseFromString(trimmedHtml, 'text/html');
110
          return editor.dom.isEmpty(fragment);
111
        }
112
      }
113
    };
114
    const hasDraft = editor => {
115
      var _a;
116
      const time = parseInt((_a = global$2.getItem(getAutoSavePrefix(editor) + 'time')) !== null && _a !== void 0 ? _a : '0', 10) || 0;
117
      if (new Date().getTime() - time > getAutoSaveRetention(editor)) {
118
        removeDraft(editor, false);
119
        return false;
120
      }
121
      return true;
122
    };
123
    const removeDraft = (editor, fire) => {
124
      const prefix = getAutoSavePrefix(editor);
125
      global$2.removeItem(prefix + 'draft');
126
      global$2.removeItem(prefix + 'time');
127
      if (fire !== false) {
128
        fireRemoveDraft(editor);
129
      }
130
    };
131
    const storeDraft = editor => {
132
      const prefix = getAutoSavePrefix(editor);
133
      if (!isEmpty(editor) && editor.isDirty()) {
134
        global$2.setItem(prefix + 'draft', editor.getContent({
135
          format: 'raw',
136
          no_events: true
137
        }));
138
        global$2.setItem(prefix + 'time', new Date().getTime().toString());
139
        fireStoreDraft(editor);
140
      }
141
    };
142
    const restoreDraft = editor => {
143
      var _a;
144
      const prefix = getAutoSavePrefix(editor);
145
      if (hasDraft(editor)) {
146
        editor.setContent((_a = global$2.getItem(prefix + 'draft')) !== null && _a !== void 0 ? _a : '', { format: 'raw' });
147
        fireRestoreDraft(editor);
148
      }
149
    };
150
    const startStoreDraft = editor => {
151
      const interval = getAutoSaveInterval(editor);
152
      global$3.setEditorInterval(editor, () => {
153
        storeDraft(editor);
154
      }, interval);
155
    };
156
    const restoreLastDraft = editor => {
157
      editor.undoManager.transact(() => {
158
        restoreDraft(editor);
159
        removeDraft(editor);
160
      });
161
      editor.focus();
162
    };
163
 
164
    const get = editor => ({
165
      hasDraft: () => hasDraft(editor),
166
      storeDraft: () => storeDraft(editor),
167
      restoreDraft: () => restoreDraft(editor),
168
      removeDraft: fire => removeDraft(editor, fire),
169
      isEmpty: html => isEmpty(editor, html)
170
    });
171
 
172
    var global = tinymce.util.Tools.resolve('tinymce.EditorManager');
173
 
174
    const setup = editor => {
175
      editor.editorManager.on('BeforeUnload', e => {
176
        let msg;
177
        global$1.each(global.get(), editor => {
178
          if (editor.plugins.autosave) {
179
            editor.plugins.autosave.storeDraft();
180
          }
181
          if (!msg && editor.isDirty() && shouldAskBeforeUnload(editor)) {
182
            msg = editor.translate('You have unsaved changes are you sure you want to navigate away?');
183
          }
184
        });
185
        if (msg) {
186
          e.preventDefault();
187
          e.returnValue = msg;
188
        }
189
      });
190
    };
191
 
192
    const makeSetupHandler = editor => api => {
193
      api.setEnabled(hasDraft(editor));
194
      const editorEventCallback = () => api.setEnabled(hasDraft(editor));
195
      editor.on('StoreDraft RestoreDraft RemoveDraft', editorEventCallback);
196
      return () => editor.off('StoreDraft RestoreDraft RemoveDraft', editorEventCallback);
197
    };
198
    const register = editor => {
199
      startStoreDraft(editor);
200
      const onAction = () => {
201
        restoreLastDraft(editor);
202
      };
203
      editor.ui.registry.addButton('restoredraft', {
204
        tooltip: 'Restore last draft',
205
        icon: 'restore-draft',
206
        onAction,
207
        onSetup: makeSetupHandler(editor)
208
      });
209
      editor.ui.registry.addMenuItem('restoredraft', {
210
        text: 'Restore last draft',
211
        icon: 'restore-draft',
212
        onAction,
213
        onSetup: makeSetupHandler(editor)
214
      });
215
    };
216
 
217
    var Plugin = () => {
218
      global$4.add('autosave', editor => {
219
        register$1(editor);
220
        setup(editor);
221
        register(editor);
222
        editor.on('init', () => {
223
          if (shouldRestoreWhenEmpty(editor) && editor.dom.isEmpty(editor.getBody())) {
224
            restoreDraft(editor);
225
          }
226
        });
227
        return get(editor);
228
      });
229
    };
230
 
231
    Plugin();
232
 
233
})();