diff --git a/lib/editor/tiny/plugins/autosave/amd/build/autosaver.min.js.map b/lib/editor/tiny/plugins/autosave/amd/build/autosaver.min.js.map index 2dfcd385103..9fb5152ac8c 100644 --- a/lib/editor/tiny/plugins/autosave/amd/build/autosaver.min.js.map +++ b/lib/editor/tiny/plugins/autosave/amd/build/autosaver.min.js.map @@ -1 +1 @@ -{"version":3,"file":"autosaver.min.js","sources":["../src/autosaver.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Storage helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/plugin\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Options from './options';\nimport * as Storage from './storage';\nimport Log from 'core/log';\nimport {getLogSource} from './common';\n\nexport const register = (editor) => {\n const undoHandler = () => {\n if (!editor.undoManager.hasUndo()) {\n Log.debug(`Ignoring undo event as there is no undo history`, getLogSource(editor));\n return;\n }\n Storage.saveDraft(editor);\n };\n\n const visibilityChangedHandler = () => {\n if (document.visibilityState === 'hidden') {\n if (Options.isInitialised(editor)) {\n Storage.saveDraft(editor);\n }\n }\n };\n\n // Attempt to store the draft one final time before the page unloads.\n // Note: This may need to be sent as a beacon instead.\n document.addEventListener('visibilitychange', visibilityChangedHandler);\n\n // When the page is submitted as a form, remove the draft.\n editor.on('submit', () => {\n document.removeEventListener('visibilitychange', visibilityChangedHandler);\n Storage.removeAutosaveSession(editor);\n });\n\n\n editor.on('init', () => {\n // Setup the Undo handler.\n editor.on('AddUndo', undoHandler);\n\n if (editor.dom.isEmpty(editor.getBody())) {\n Log.info(`Attempting to restore draft`, getLogSource(editor));\n Storage.restoreDraft(editor);\n } else {\n // There was nothing to restore, so we can mark the editor as initialised.\n Log.warn(`Skipping draft restoration. The editor is not empty.`, getLogSource(editor));\n Options.markInitialised(editor);\n }\n });\n};\n"],"names":["editor","undoHandler","undoManager","hasUndo","Storage","saveDraft","debug","visibilityChangedHandler","document","visibilityState","Options","isInitialised","addEventListener","on","removeEventListener","removeAutosaveSession","dom","isEmpty","getBody","info","restoreDraft","warn","markInitialised"],"mappings":";;;;;;;4OA4ByBA,eACfC,YAAc,KACXD,OAAOE,YAAYC,UAIxBC,QAAQC,UAAUL,qBAHVM,yDAAyD,wBAAaN,UAM5EO,yBAA2B,KACI,WAA7BC,SAASC,iBACLC,QAAQC,cAAcX,SACtBI,QAAQC,UAAUL,SAO9BQ,SAASI,iBAAiB,mBAAoBL,0BAG9CP,OAAOa,GAAG,UAAU,KAChBL,SAASM,oBAAoB,mBAAoBP,0BACjDH,QAAQW,sBAAsBf,WAIlCA,OAAOa,GAAG,QAAQ,KAEdb,OAAOa,GAAG,UAAWZ,aAEjBD,OAAOgB,IAAIC,QAAQjB,OAAOkB,yBACtBC,oCAAoC,wBAAanB,SACrDI,QAAQgB,aAAapB,uBAGjBqB,6DAA6D,wBAAarB,SAC9EU,QAAQY,gBAAgBtB"} \ No newline at end of file +{"version":3,"file":"autosaver.min.js","sources":["../src/autosaver.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Storage helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/plugin\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Options from './options';\nimport * as Storage from './storage';\nimport Log from 'core/log';\nimport {getLogSource} from './common';\n\nexport const register = (editor) => {\n const undoHandler = () => {\n if (!editor.undoManager.hasUndo()) {\n Log.debug(`Ignoring undo event as there is no undo history`, getLogSource(editor));\n return;\n }\n Storage.saveDraft(editor);\n };\n\n const visibilityChangedHandler = () => {\n if (document.visibilityState === 'hidden') {\n if (Options.isInitialised(editor)) {\n Storage.saveDraft(editor);\n }\n }\n };\n\n // Attempt to store the draft one final time before the page unloads.\n // Note: This may need to be sent as a beacon instead.\n document.addEventListener('visibilitychange', visibilityChangedHandler);\n\n // When the page is submitted as a form, remove the draft.\n editor.on('submit', () => {\n document.removeEventListener('visibilitychange', visibilityChangedHandler);\n Storage.removeAutosaveSession(editor);\n });\n\n editor.on('init', () => {\n // Setup the Undo handler.\n editor.on('AddUndo', undoHandler);\n\n if (editor.dom.isEmpty(editor.getBody())) {\n Log.info(`Attempting to restore draft`, getLogSource(editor));\n Storage.restoreDraft(editor);\n } else {\n // There was nothing to restore, so we can mark the editor as initialised.\n Log.warn(`Skipping draft restoration. The editor is not empty.`, getLogSource(editor));\n Options.markInitialised(editor);\n }\n });\n};\n"],"names":["editor","undoHandler","undoManager","hasUndo","Storage","saveDraft","debug","visibilityChangedHandler","document","visibilityState","Options","isInitialised","addEventListener","on","removeEventListener","removeAutosaveSession","dom","isEmpty","getBody","info","restoreDraft","warn","markInitialised"],"mappings":";;;;;;;4OA4ByBA,eACfC,YAAc,KACXD,OAAOE,YAAYC,UAIxBC,QAAQC,UAAUL,qBAHVM,yDAAyD,wBAAaN,UAM5EO,yBAA2B,KACI,WAA7BC,SAASC,iBACLC,QAAQC,cAAcX,SACtBI,QAAQC,UAAUL,SAO9BQ,SAASI,iBAAiB,mBAAoBL,0BAG9CP,OAAOa,GAAG,UAAU,KAChBL,SAASM,oBAAoB,mBAAoBP,0BACjDH,QAAQW,sBAAsBf,WAGlCA,OAAOa,GAAG,QAAQ,KAEdb,OAAOa,GAAG,UAAWZ,aAEjBD,OAAOgB,IAAIC,QAAQjB,OAAOkB,yBACtBC,oCAAoC,wBAAanB,SACrDI,QAAQgB,aAAapB,uBAGjBqB,6DAA6D,wBAAarB,SAC9EU,QAAQY,gBAAgBtB"} \ No newline at end of file diff --git a/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js b/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js index 49d6ca4e29f..6663526450c 100644 --- a/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js +++ b/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js @@ -5,6 +5,6 @@ define("tiny_autosave/repository",["exports","core/ajax","core/config","./option * @module tiny_autosave/repository * @copyright 2022 Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.updateAutosaveSession=_exports.resumeAutosaveSession=_exports.removeAutosaveSession=void 0,config=_interopRequireWildcard(config),Options=_interopRequireWildcard(Options),_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const fetchOne=(methodname,args)=>(0,_ajax.call)([{methodname:methodname,args:args}])[0];_exports.resumeAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))return Promise.reject("Invalid editor");const pendingPromise=new _pending.default("tiny_autosave/repository:resumeAutosaveSession");return fetchOne("tiny_autosave_resume_session",{contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id,draftid:Options.getDraftItemId(editor)}).then((result=>(pendingPromise.resolve(),result)))};_exports.updateAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))return Promise.reject("Invalid editor");if(Options.hasAutosaveHasReset(editor))return Promise.reject("Unable to store autosave content - content has been reset");const pendingPromise=new _pending.default("tiny_autosave/repository:updateAutosaveSession");return fetchOne("tiny_autosave_update_session",{contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id,drafttext:editor.getContent()}).then((result=>(pendingPromise.resolve(),result)))};_exports.removeAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))throw new Error("Invalid editor");Options.setAutosaveHasReset(editor);const requestUrl=new URL("".concat(config.wwwroot,"/lib/ajax/service.php"));requestUrl.searchParams.set("sesskey",config.sesskey);const args={contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id};fetch(requestUrl,{method:"POST",body:JSON.stringify([{index:0,methodname:"tiny_autosave_reset_session",args:args}]),keepalive:!0})}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.updateAutosaveSession=_exports.resumeAutosaveSession=_exports.removeAutosaveSession=void 0,config=_interopRequireWildcard(config),Options=_interopRequireWildcard(Options),_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const fetchOne=(methodname,args)=>(0,_ajax.call)([{methodname:methodname,args:args}])[0];_exports.resumeAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))return Promise.reject("Invalid editor");const pendingPromise=new _pending.default("tiny_autosave/repository:resumeAutosaveSession");return fetchOne("tiny_autosave_resume_session",{contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id,draftid:Options.getDraftItemId(editor)}).then((result=>(pendingPromise.resolve(),result)))};_exports.updateAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))return Promise.reject("Invalid editor");if(Options.hasAutosaveHasReset(editor))return Promise.reject("Skipping store of autosave content - content has been reset");const pendingPromise=new _pending.default("tiny_autosave/repository:updateAutosaveSession");return fetchOne("tiny_autosave_update_session",{contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id,drafttext:editor.getContent()}).then((result=>(pendingPromise.resolve(),result)))};_exports.removeAutosaveSession=editor=>{if(!(0,_utils.ensureEditorIsValid)(editor))throw new Error("Invalid editor");Options.setAutosaveHasReset(editor);const requestUrl=new URL("".concat(config.wwwroot,"/lib/ajax/service.php"));requestUrl.searchParams.set("sesskey",config.sesskey);const args={contextid:Options.getContextId(editor),pagehash:Options.getPageHash(editor),pageinstance:Options.getPageInstance(editor),elementid:editor.targetElm.id};navigator.sendBeacon(requestUrl,JSON.stringify([{index:0,methodname:"tiny_autosave_reset_session",args:args}]))}})); //# sourceMappingURL=repository.min.js.map \ No newline at end of file diff --git a/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js.map b/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js.map index d91ac38c2dc..5fb76373fd9 100644 --- a/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js.map +++ b/lib/editor/tiny/plugins/autosave/amd/build/repository.min.js.map @@ -1 +1 @@ -{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Repository helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/repository\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call} from 'core/ajax';\nimport * as config from 'core/config';\nimport * as Options from './options';\nimport Pending from 'core/pending';\nimport {ensureEditorIsValid} from 'editor_tiny/utils';\n\nconst fetchOne = (methodname, args) => call([{\n methodname,\n args,\n}])[0];\n\n/**\n * Resume an Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n * @returns {Promise} The Autosave session\n */\nexport const resumeAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n return Promise.reject('Invalid editor');\n }\n const pendingPromise = new Pending('tiny_autosave/repository:resumeAutosaveSession');\n return fetchOne('tiny_autosave_resume_session', {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n draftid: Options.getDraftItemId(editor),\n })\n .then((result) => {\n pendingPromise.resolve();\n return result;\n });\n};\n\n/**\n * Update the content of the Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n * @returns {Promise} The Autosave session\n */\nexport const updateAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n return Promise.reject('Invalid editor');\n }\n if (Options.hasAutosaveHasReset(editor)) {\n return Promise.reject('Unable to store autosave content - content has been reset');\n }\n\n const pendingPromise = new Pending('tiny_autosave/repository:updateAutosaveSession');\n\n return fetchOne('tiny_autosave_update_session', {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n drafttext: editor.getContent(),\n })\n .then((result) => {\n pendingPromise.resolve();\n return result;\n });\n};\n\n/**\n * Remove the Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n */\nexport const removeAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n throw new Error('Invalid editor');\n }\n Options.setAutosaveHasReset(editor);\n\n // Please note that we must use a Beacon send here.\n // The XHR is not guaranteed because it will be aborted on page transition.\n // https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API\n // Note: Moodle does not currently have a sendBeacon API endpoint.\n const requestUrl = new URL(`${config.wwwroot}/lib/ajax/service.php`);\n requestUrl.searchParams.set('sesskey', config.sesskey);\n\n const args = {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n };\n fetch(requestUrl, {\n method: 'POST',\n body: JSON.stringify([{\n index: 0,\n methodname: 'tiny_autosave_reset_session',\n args,\n }]),\n keepalive: true,\n });\n};\n"],"names":["fetchOne","methodname","args","editor","Promise","reject","pendingPromise","Pending","contextid","Options","getContextId","pagehash","getPageHash","pageinstance","getPageInstance","elementid","targetElm","id","draftid","getDraftItemId","then","result","resolve","hasAutosaveHasReset","drafttext","getContent","Error","setAutosaveHasReset","requestUrl","URL","config","wwwroot","searchParams","set","sesskey","fetch","method","body","JSON","stringify","index","keepalive"],"mappings":";;;;;;;iTA6BMA,SAAW,CAACC,WAAYC,QAAS,cAAK,CAAC,CACzCD,WAAAA,WACAC,KAAAA,QACA,kCAQkCC,cAC7B,8BAAoBA,eACdC,QAAQC,OAAO,wBAEpBC,eAAiB,IAAIC,iBAAQ,yDAC5BP,SAAS,+BAAgC,CAC5CQ,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,GAC5BC,QAAST,QAAQU,eAAehB,UAEnCiB,MAAMC,SACHf,eAAegB,UACRD,0CAUuBlB,cAC7B,8BAAoBA,eACdC,QAAQC,OAAO,qBAEtBI,QAAQc,oBAAoBpB,eACrBC,QAAQC,OAAO,mEAGpBC,eAAiB,IAAIC,iBAAQ,yDAE5BP,SAAS,+BAAgC,CAC5CQ,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,GAC5BO,UAAWrB,OAAOsB,eAErBL,MAAMC,SACHf,eAAegB,UACRD,0CASuBlB,cAC7B,8BAAoBA,cACf,IAAIuB,MAAM,kBAEpBjB,QAAQkB,oBAAoBxB,cAMtByB,WAAa,IAAIC,cAAOC,OAAOC,kCACrCH,WAAWI,aAAaC,IAAI,UAAWH,OAAOI,eAExChC,KAAO,CACTM,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,IAEhCkB,MAAMP,WAAY,CACdQ,OAAQ,OACRC,KAAMC,KAAKC,UAAU,CAAC,CAClBC,MAAO,EACPvC,WAAY,8BACZC,KAAAA,QAEJuC,WAAW"} \ No newline at end of file +{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Repository helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/repository\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call} from 'core/ajax';\nimport * as config from 'core/config';\nimport * as Options from './options';\nimport Pending from 'core/pending';\nimport {ensureEditorIsValid} from 'editor_tiny/utils';\n\nconst fetchOne = (methodname, args) => call([{\n methodname,\n args,\n}])[0];\n\n/**\n * Resume an Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n * @returns {Promise} The Autosave session\n */\nexport const resumeAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n return Promise.reject('Invalid editor');\n }\n const pendingPromise = new Pending('tiny_autosave/repository:resumeAutosaveSession');\n return fetchOne('tiny_autosave_resume_session', {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n draftid: Options.getDraftItemId(editor),\n })\n .then((result) => {\n pendingPromise.resolve();\n return result;\n });\n};\n\n/**\n * Update the content of the Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n * @returns {Promise} The Autosave session\n */\nexport const updateAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n return Promise.reject('Invalid editor');\n }\n if (Options.hasAutosaveHasReset(editor)) {\n return Promise.reject('Skipping store of autosave content - content has been reset');\n }\n\n const pendingPromise = new Pending('tiny_autosave/repository:updateAutosaveSession');\n\n return fetchOne('tiny_autosave_update_session', {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n drafttext: editor.getContent(),\n })\n .then((result) => {\n pendingPromise.resolve();\n return result;\n });\n};\n\n/**\n * Remove the Autosave session.\n *\n * @param {TinyMCE} editor The TinyMCE editor instance\n */\nexport const removeAutosaveSession = (editor) => {\n if (!ensureEditorIsValid(editor)) {\n throw new Error('Invalid editor');\n }\n Options.setAutosaveHasReset(editor);\n\n // Please note that we must use a Beacon send here.\n // The XHR is not guaranteed because it will be aborted on page transition.\n // https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API\n // Note: Moodle does not currently have a sendBeacon API endpoint.\n const requestUrl = new URL(`${config.wwwroot}/lib/ajax/service.php`);\n requestUrl.searchParams.set('sesskey', config.sesskey);\n\n const args = {\n contextid: Options.getContextId(editor),\n pagehash: Options.getPageHash(editor),\n pageinstance: Options.getPageInstance(editor),\n elementid: editor.targetElm.id,\n };\n navigator.sendBeacon(requestUrl, JSON.stringify([{\n index: 0,\n methodname: 'tiny_autosave_reset_session',\n args,\n }]));\n};\n"],"names":["fetchOne","methodname","args","editor","Promise","reject","pendingPromise","Pending","contextid","Options","getContextId","pagehash","getPageHash","pageinstance","getPageInstance","elementid","targetElm","id","draftid","getDraftItemId","then","result","resolve","hasAutosaveHasReset","drafttext","getContent","Error","setAutosaveHasReset","requestUrl","URL","config","wwwroot","searchParams","set","sesskey","navigator","sendBeacon","JSON","stringify","index"],"mappings":";;;;;;;iTA6BMA,SAAW,CAACC,WAAYC,QAAS,cAAK,CAAC,CACzCD,WAAAA,WACAC,KAAAA,QACA,kCAQkCC,cAC7B,8BAAoBA,eACdC,QAAQC,OAAO,wBAEpBC,eAAiB,IAAIC,iBAAQ,yDAC5BP,SAAS,+BAAgC,CAC5CQ,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,GAC5BC,QAAST,QAAQU,eAAehB,UAEnCiB,MAAMC,SACHf,eAAegB,UACRD,0CAUuBlB,cAC7B,8BAAoBA,eACdC,QAAQC,OAAO,qBAEtBI,QAAQc,oBAAoBpB,eACrBC,QAAQC,OAAO,qEAGpBC,eAAiB,IAAIC,iBAAQ,yDAE5BP,SAAS,+BAAgC,CAC5CQ,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,GAC5BO,UAAWrB,OAAOsB,eAErBL,MAAMC,SACHf,eAAegB,UACRD,0CASuBlB,cAC7B,8BAAoBA,cACf,IAAIuB,MAAM,kBAEpBjB,QAAQkB,oBAAoBxB,cAMtByB,WAAa,IAAIC,cAAOC,OAAOC,kCACrCH,WAAWI,aAAaC,IAAI,UAAWH,OAAOI,eAExChC,KAAO,CACTM,UAAWC,QAAQC,aAAaP,QAChCQ,SAAUF,QAAQG,YAAYT,QAC9BU,aAAcJ,QAAQK,gBAAgBX,QACtCY,UAAWZ,OAAOa,UAAUC,IAEhCkB,UAAUC,WAAWR,WAAYS,KAAKC,UAAU,CAAC,CAC7CC,MAAO,EACPtC,WAAY,8BACZC,KAAAA"} \ No newline at end of file diff --git a/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js b/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js index 17856f30625..24a92110b02 100644 --- a/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js +++ b/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js @@ -5,6 +5,6 @@ define("tiny_autosave/storage",["exports","./repository","core/pending","./optio * @module tiny_autosave/plugin * @copyright 2022 Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(Repository),_pending=_interopRequireDefault(_pending),_log=_interopRequireDefault(_log);const saveDebounceMap=new Map;_exports.restoreDraft=async editor=>{const pendingPromise=new _pending.default("tiny_autosave/restoreDraft");try{const session=await Repository.resumeAutosaveSession(editor);session&&session.drafttext&&editor.undoManager.ignore((()=>{editor.setContent(session.drafttext),editor.save()}))}catch(error){_log.default.warn("Failed to restore draft: ".concat(error),(0,_common.getLogSource)(editor))}(0,_options.markInitialised)(editor),pendingPromise.resolve()};_exports.saveDraft=editor=>{const timerId=saveDebounceMap.get(editor);timerId&&clearTimeout(timerId),saveDebounceMap.set(editor,setTimeout((()=>{_log.default.debug("Saving draft",(0,_common.getLogSource)(editor)),Repository.updateAutosaveSession(editor)}),(0,_options.getBackoffTime)(editor)))};_exports.removeAutosaveSession=editor=>{_log.default.debug("Removing Autosave session",(0,_common.getLogSource)(editor)),Repository.removeAutosaveSession(editor)}})); + */(Repository),_pending=_interopRequireDefault(_pending),_log=_interopRequireDefault(_log);const saveDebounceMap=new Map;_exports.restoreDraft=async editor=>{const pendingPromise=new _pending.default("tiny_autosave/restoreDraft");try{const session=await Repository.resumeAutosaveSession(editor);session&&session.drafttext&&editor.undoManager.ignore((()=>{editor.setContent(session.drafttext),editor.save()}))}catch(error){_log.default.warn("Failed to restore draft: ".concat(error),(0,_common.getLogSource)(editor))}(0,_options.markInitialised)(editor),pendingPromise.resolve()};_exports.saveDraft=editor=>{const timerId=saveDebounceMap.get(editor);timerId&&clearTimeout(timerId),saveDebounceMap.set(editor,setTimeout((()=>{_log.default.debug("Saving draft",(0,_common.getLogSource)(editor)),Repository.updateAutosaveSession(editor).catch((error=>window.console.warn(error)))}),(0,_options.getBackoffTime)(editor)))};_exports.removeAutosaveSession=editor=>{_log.default.debug("Removing Autosave session",(0,_common.getLogSource)(editor)),Repository.removeAutosaveSession(editor)}})); //# sourceMappingURL=storage.min.js.map \ No newline at end of file diff --git a/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js.map b/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js.map index b6454708020..904b2254bea 100644 --- a/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js.map +++ b/lib/editor/tiny/plugins/autosave/amd/build/storage.min.js.map @@ -1 +1 @@ -{"version":3,"file":"storage.min.js","sources":["../src/storage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Storage helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/plugin\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Repository from \"./repository\";\nimport Pending from 'core/pending';\nimport {\n markInitialised,\n getBackoffTime,\n} from \"./options\";\nimport Log from 'core/log';\nimport {getLogSource} from './common';\n\n/** @property {Map} A map of debounced draft saves */\nconst saveDebounceMap = new Map();\n\n/**\n * Attempt to restore a draft into the editor\n *\n * @param {TinyMCE} editor The Editor to restore a draft for\n */\nexport const restoreDraft = async(editor) => {\n const pendingPromise = new Pending('tiny_autosave/restoreDraft');\n try {\n const session = await Repository.resumeAutosaveSession(editor);\n if (session && session.drafttext) {\n editor.undoManager.ignore(() => {\n editor.setContent(session.drafttext);\n editor.save();\n });\n }\n } catch (error) {\n // Ignore any errors as drafts are optional.\n Log.warn(`Failed to restore draft: ${error}`, getLogSource(editor));\n }\n markInitialised(editor);\n pendingPromise.resolve();\n};\n\n/**\n * Save the current content of the editor as a draft.\n *\n * @param {TinyMCE} editor\n */\nexport const saveDraft = (editor) => {\n const timerId = saveDebounceMap.get(editor);\n if (timerId) {\n clearTimeout(timerId);\n }\n saveDebounceMap.set(editor, setTimeout(() => {\n Log.debug(`Saving draft`, getLogSource(editor));\n Repository.updateAutosaveSession(editor);\n }, getBackoffTime(editor)));\n};\n\n/**\n * Delete the draft for the current editor.\n *\n * @param {TinyMCE} editor\n */\nexport const removeAutosaveSession = (editor) => {\n Log.debug(`Removing Autosave session`, getLogSource(editor));\n Repository.removeAutosaveSession(editor);\n};\n"],"names":["saveDebounceMap","Map","async","pendingPromise","Pending","session","Repository","resumeAutosaveSession","editor","drafttext","undoManager","ignore","setContent","save","error","warn","resolve","timerId","get","clearTimeout","set","setTimeout","debug","updateAutosaveSession","removeAutosaveSession"],"mappings":";;;;;;;oGAiCMA,gBAAkB,IAAIC,0BAOAC,MAAAA,eAClBC,eAAiB,IAAIC,iBAAQ,wCAEzBC,cAAgBC,WAAWC,sBAAsBC,QACnDH,SAAWA,QAAQI,WACnBD,OAAOE,YAAYC,QAAO,KACtBH,OAAOI,WAAWP,QAAQI,WAC1BD,OAAOK,UAGjB,MAAOC,oBAEDC,wCAAiCD,QAAS,wBAAaN,sCAE/CA,QAChBL,eAAea,8BAQOR,eAChBS,QAAUjB,gBAAgBkB,IAAIV,QAChCS,SACAE,aAAaF,SAEjBjB,gBAAgBoB,IAAIZ,OAAQa,YAAW,kBAC/BC,sBAAsB,wBAAad,SACvCF,WAAWiB,sBAAsBf,WAClC,2BAAeA,0CAQgBA,sBAC9Bc,mCAAmC,wBAAad,SACpDF,WAAWkB,sBAAsBhB"} \ No newline at end of file +{"version":3,"file":"storage.min.js","sources":["../src/storage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Storage helper for the Moodle Tiny Autosave plugin.\n *\n * @module tiny_autosave/plugin\n * @copyright 2022 Andrew Lyons \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Repository from \"./repository\";\nimport Pending from 'core/pending';\nimport {\n markInitialised,\n getBackoffTime,\n} from \"./options\";\nimport Log from 'core/log';\nimport {getLogSource} from './common';\n\n/** @property {Map} A map of debounced draft saves */\nconst saveDebounceMap = new Map();\n\n/**\n * Attempt to restore a draft into the editor\n *\n * @param {TinyMCE} editor The Editor to restore a draft for\n */\nexport const restoreDraft = async(editor) => {\n const pendingPromise = new Pending('tiny_autosave/restoreDraft');\n try {\n const session = await Repository.resumeAutosaveSession(editor);\n if (session && session.drafttext) {\n editor.undoManager.ignore(() => {\n editor.setContent(session.drafttext);\n editor.save();\n });\n }\n } catch (error) {\n // Ignore any errors as drafts are optional.\n Log.warn(`Failed to restore draft: ${error}`, getLogSource(editor));\n }\n markInitialised(editor);\n pendingPromise.resolve();\n};\n\n/**\n * Save the current content of the editor as a draft.\n *\n * @param {TinyMCE} editor\n */\nexport const saveDraft = (editor) => {\n const timerId = saveDebounceMap.get(editor);\n if (timerId) {\n clearTimeout(timerId);\n }\n saveDebounceMap.set(editor, setTimeout(() => {\n Log.debug(`Saving draft`, getLogSource(editor));\n Repository.updateAutosaveSession(editor)\n .catch((error) => window.console.warn(error));\n }, getBackoffTime(editor)));\n};\n\n/**\n * Delete the draft for the current editor.\n *\n * @param {TinyMCE} editor\n */\nexport const removeAutosaveSession = (editor) => {\n Log.debug(`Removing Autosave session`, getLogSource(editor));\n Repository.removeAutosaveSession(editor);\n};\n"],"names":["saveDebounceMap","Map","async","pendingPromise","Pending","session","Repository","resumeAutosaveSession","editor","drafttext","undoManager","ignore","setContent","save","error","warn","resolve","timerId","get","clearTimeout","set","setTimeout","debug","updateAutosaveSession","catch","window","console","removeAutosaveSession"],"mappings":";;;;;;;oGAiCMA,gBAAkB,IAAIC,0BAOAC,MAAAA,eAClBC,eAAiB,IAAIC,iBAAQ,wCAEzBC,cAAgBC,WAAWC,sBAAsBC,QACnDH,SAAWA,QAAQI,WACnBD,OAAOE,YAAYC,QAAO,KACtBH,OAAOI,WAAWP,QAAQI,WAC1BD,OAAOK,UAGjB,MAAOC,oBAEDC,wCAAiCD,QAAS,wBAAaN,sCAE/CA,QAChBL,eAAea,8BAQOR,eAChBS,QAAUjB,gBAAgBkB,IAAIV,QAChCS,SACAE,aAAaF,SAEjBjB,gBAAgBoB,IAAIZ,OAAQa,YAAW,kBAC/BC,sBAAsB,wBAAad,SACvCF,WAAWiB,sBAAsBf,QAChCgB,OAAOV,OAAUW,OAAOC,QAAQX,KAAKD,YACvC,2BAAeN,0CAQgBA,sBAC9Bc,mCAAmC,wBAAad,SACpDF,WAAWqB,sBAAsBnB"} \ No newline at end of file diff --git a/lib/editor/tiny/plugins/autosave/amd/src/autosaver.js b/lib/editor/tiny/plugins/autosave/amd/src/autosaver.js index daeb9cc66be..194a27a2238 100644 --- a/lib/editor/tiny/plugins/autosave/amd/src/autosaver.js +++ b/lib/editor/tiny/plugins/autosave/amd/src/autosaver.js @@ -53,7 +53,6 @@ export const register = (editor) => { Storage.removeAutosaveSession(editor); }); - editor.on('init', () => { // Setup the Undo handler. editor.on('AddUndo', undoHandler); diff --git a/lib/editor/tiny/plugins/autosave/amd/src/repository.js b/lib/editor/tiny/plugins/autosave/amd/src/repository.js index 0c0218fffca..3ab733e8095 100644 --- a/lib/editor/tiny/plugins/autosave/amd/src/repository.js +++ b/lib/editor/tiny/plugins/autosave/amd/src/repository.js @@ -67,7 +67,7 @@ export const updateAutosaveSession = (editor) => { return Promise.reject('Invalid editor'); } if (Options.hasAutosaveHasReset(editor)) { - return Promise.reject('Unable to store autosave content - content has been reset'); + return Promise.reject('Skipping store of autosave content - content has been reset'); } const pendingPromise = new Pending('tiny_autosave/repository:updateAutosaveSession'); @@ -109,13 +109,9 @@ export const removeAutosaveSession = (editor) => { pageinstance: Options.getPageInstance(editor), elementid: editor.targetElm.id, }; - fetch(requestUrl, { - method: 'POST', - body: JSON.stringify([{ - index: 0, - methodname: 'tiny_autosave_reset_session', - args, - }]), - keepalive: true, - }); + navigator.sendBeacon(requestUrl, JSON.stringify([{ + index: 0, + methodname: 'tiny_autosave_reset_session', + args, + }])); }; diff --git a/lib/editor/tiny/plugins/autosave/amd/src/storage.js b/lib/editor/tiny/plugins/autosave/amd/src/storage.js index 9de48e3d4ba..328b9f8d460 100644 --- a/lib/editor/tiny/plugins/autosave/amd/src/storage.js +++ b/lib/editor/tiny/plugins/autosave/amd/src/storage.js @@ -68,7 +68,8 @@ export const saveDraft = (editor) => { } saveDebounceMap.set(editor, setTimeout(() => { Log.debug(`Saving draft`, getLogSource(editor)); - Repository.updateAutosaveSession(editor); + Repository.updateAutosaveSession(editor) + .catch((error) => window.console.warn(error)); }, getBackoffTime(editor))); };