@themarioga/grid-editor 9.2.4 → 9.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (()=>{var v=window.GridEditor;if(!v||typeof v.get!="function")throw new Error("grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, its locales and grideditor.jquery.js");Object.assign(v.locales.en,{"autosave.restore_title":"Restore the draft?","autosave.restore_message":"There is a draft of this page saved on {date}, with changes that were not published. Restore it?","autosave.restore":"Restore","autosave.discard":"Discard"});var L=1,A={local:"localStorage",session:"sessionStorage"},k=1e3,D=new Set;function F(e){for(var s=2166136261,n=0;n<e.length;n++)s^=e.charCodeAt(n),s=Math.imul(s,16777619);return(s>>>0).toString(16).padStart(8,"0")}function G(e){return!!e&&typeof e=="object"&&e.version===L&&typeof e.html=="string"&&typeof e.base=="string"&&typeof e.savedAt=="string"&&!isNaN(Date.parse(e.savedAt))}v.features.autosave=function(e){var s=j(e.settings.autosave||{}),n=s.key||"grideditor.autosave:"+window.location.pathname+"#"+e.canvas.id,m=N(s.storage),r="disabled",p=!0,S=!1,u=null,f=null,d=null,l=null,o=null,h=!1,x=!1;m?D.has(n)?(e.warn('autosave: another editor on this page already saves to "'+n+'", so this one does not; give each its own autosave.key'),r="unavailable"):(D.add(n),s.enabled&&(r="enabled",u=E(!0))):(e.warn("autosave: the browser will not give this page its "+A[s.storage]+", so nothing is saved"),r="unavailable");function j(t){var a={enabled:t.enabled===void 0?!0:!!t.enabled,storage:t.storage===void 0?"local":t.storage,key:t.key===void 0?null:t.key,delay:t.delay===void 0?k:t.delay,maxAge:t.maxAge===void 0?null:t.maxAge};return A[a.storage]||(e.warn('autosave.storage "'+a.storage+'" is not local or session: local is used'),a.storage="local"),a.key!==null&&(typeof a.key!="string"||a.key==="")&&(e.warn("autosave.key must be a string: the page's own key is used"),a.key=null),(typeof a.delay!="number"||!Number.isInteger(a.delay)||a.delay<0)&&(e.warn("autosave.delay must be a whole number of milliseconds, 0 or more: "+k+" is used"),a.delay=k),a.maxAge!==null&&!(typeof a.maxAge=="number"&&isFinite(a.maxAge)&&a.maxAge>0)&&(e.warn("autosave.maxAge must be a number of milliseconds over 0, or null: drafts do not expire"),a.maxAge=null),a}function N(t){try{var a=window[A[t]];return a.getItem(n),a}catch(i){return null}}function E(t){var a;try{a=m.getItem(n)}catch(y){return null}if(a===null)return null;var i=null;try{i=JSON.parse(a)}catch(y){}return G(i)?t&&s.maxAge!==null&&Date.now()-Date.parse(i.savedAt)>s.maxAge?(b(),null):i:(t&&(e.warn('autosave: what is saved under "'+n+'" is not a draft this version can read: it is discarded'),b()),null)}function b(){try{m.removeItem(n)}catch(t){}}function w(t){if(window.clearTimeout(l),l=null,h||f===null)return!1;var a=!!o;a&&o.disconnect();var i=e.snapshotHtml();if(a&&c(),i===d)return!1;var y={version:L,html:i,savedAt:new Date().toISOString(),base:f};try{m.setItem(n,JSON.stringify(y))}catch(g){return x||(x=!0,e.warn("autosave: the draft could not be saved ("+(g&&g.message||g)+")")),e.emit("autosave-error",{canvas:e.canvas,error:g}),!1}return d=i,e.emit("after-autosave",{canvas:e.canvas,html:i,savedAt:y.savedAt,source:t}),!0}function H(){window.clearTimeout(l),l=window.setTimeout(function(){w("change")},s.delay)}function c(){o||(o=new MutationObserver(H)),o.observe(e.canvas,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function O(){window.clearTimeout(l),l=null,o&&o.disconnect()}function T(){r==="enabled"&&w("pagehide")}function R(){if(!(r==="destroyed"||r==="unavailable")){if(d=e.snapshotHtml(),f=F(d),window.addEventListener("pagehide",T),r==="enabled"&&u&&u.base===f&&u.html!==d){I(u);return}u=null,r==="enabled"&&c()}}function _(t){try{return new Date(t).toLocaleString(e.settings.locale||void 0)}catch(a){return new Date(t).toLocaleString()}}function I(t){r="asking",e.confirm(e.t("autosave.restore_message",{date:_(t.savedAt)}),{title:e.t("autosave.restore_title"),ok:e.t("autosave.restore"),cancel:e.t("autosave.discard")},function(a){if(r!=="destroyed"){if(a===null){window.setTimeout(function(){r==="asking"&&I(t)},0);return}u=null,a?(d=t.html,e.setHtml(t.html),e.emit("after-restore-draft",{canvas:e.canvas,html:t.html,savedAt:t.savedAt})):b(),r=p?"enabled":"disabled",r==="enabled"&&c()}})}return{onInit:function(){S||(S=!0,Promise.resolve().then(R))},onSourceOpen:function(){h=!0},onSourceClose:function(){h=!1},onDestroy:function(){r==="enabled"&&l&&w("destroy"),O(),o=null,window.removeEventListener("pagehide",T),r!=="unavailable"&&D.delete(n),r="destroyed"},methods:{enableAutosave:function(){return r==="unavailable"?!1:r==="asking"?(p=!0,!0):(r!=="enabled"&&(r="enabled",f!==null&&c()),!0)},disableAutosave:function(){return r==="unavailable"?!1:r==="asking"?(p=!1,!0):(O(),r="disabled",!0)},saveDraft:function(){return r==="unavailable"||r==="asking"?!1:w("api")},getDraft:function(){if(r==="unavailable")return null;var t=E(!1);return t?{html:t.html,savedAt:t.savedAt}:null},clearDraft:function(){if(r==="unavailable")return!1;if(window.clearTimeout(l),l=null,b(),f!==null&&r!=="asking"&&!h){var t=!!o&&r==="enabled";t&&o.disconnect(),d=e.snapshotHtml(),t&&c()}return!0}}}};})();
1
+ (()=>{var v=window.GridEditor;if(!v||typeof v.get!="function")throw new Error("grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, its locales and grideditor.jquery.js");Object.assign(v.locales.en,{"autosave.restore_title":"Restore the draft?","autosave.restore_message":"There is a draft of this page saved on {date}, with changes that were not published. Restore it?","autosave.restore":"Restore","autosave.discard":"Discard"});var j=1,A={local:"localStorage",session:"sessionStorage"},k=1e3,D=new Set;function L(e){for(var s=2166136261,n=0;n<e.length;n++)s^=e.charCodeAt(n),s=Math.imul(s,16777619);return(s>>>0).toString(16).padStart(8,"0")}function G(e){return!!e&&typeof e=="object"&&e.version===j&&typeof e.html=="string"&&typeof e.base=="string"&&typeof e.savedAt=="string"&&!isNaN(Date.parse(e.savedAt))}v.features.autosave=function(e){var s=N(e.settings.autosave||{}),n=s.key||"grideditor.autosave:"+window.location.pathname+"#"+e.canvas.id,m=H(s.storage),r="disabled",g=!0,S=!1,d=null,f=null,u=null,l=null,o=null,p=!1,x=!1;m?D.has(n)?(e.warn('autosave: another editor on this page already saves to "'+n+'", so this one does not; give each its own autosave.key'),r="unavailable"):(D.add(n),s.enabled&&(r="enabled",d=E(!0))):(e.warn("autosave: the browser will not give this page its "+A[s.storage]+", so nothing is saved"),r="unavailable");function N(t){var a={enabled:t.enabled===void 0?!0:!!t.enabled,storage:t.storage===void 0?"local":t.storage,key:t.key===void 0?null:t.key,delay:t.delay===void 0?k:t.delay,maxAge:t.maxAge===void 0?null:t.maxAge};return A[a.storage]||(e.warn('autosave.storage "'+a.storage+'" is not local or session: local is used'),a.storage="local"),a.key!==null&&(typeof a.key!="string"||a.key==="")&&(e.warn("autosave.key must be a string: the page's own key is used"),a.key=null),(typeof a.delay!="number"||!Number.isInteger(a.delay)||a.delay<0)&&(e.warn("autosave.delay must be a whole number of milliseconds, 0 or more: "+k+" is used"),a.delay=k),a.maxAge!==null&&!(typeof a.maxAge=="number"&&isFinite(a.maxAge)&&a.maxAge>0)&&(e.warn("autosave.maxAge must be a number of milliseconds over 0, or null: drafts do not expire"),a.maxAge=null),a}function H(t){try{var a=window[A[t]];return a.getItem(n),a}catch(i){return null}}function E(t){var a;try{a=m.getItem(n)}catch(w){return null}if(a===null)return null;var i=null;try{i=JSON.parse(a)}catch(w){}return G(i)?t&&s.maxAge!==null&&Date.now()-Date.parse(i.savedAt)>s.maxAge?(h(),null):i:(t&&(e.warn('autosave: what is saved under "'+n+'" is not a draft this version can read: it is discarded'),h()),null)}function h(){try{m.removeItem(n)}catch(t){}}function b(t){if(window.clearTimeout(l),l=null,p||f===null)return!1;var a=!!o;a&&o.disconnect();var i=e.snapshotHtml();if(a&&c(),i===u)return!1;var w={version:j,html:i,savedAt:new Date().toISOString(),base:f};try{m.setItem(n,JSON.stringify(w))}catch(y){return x||(x=!0,e.warn("autosave: the draft could not be saved ("+(y&&y.message||y)+")")),e.emit("autosave-error",{canvas:e.canvas,error:y}),!1}return u=i,e.emit("after-autosave",{canvas:e.canvas,html:i,savedAt:w.savedAt,source:t}),!0}function R(){window.clearTimeout(l),l=window.setTimeout(function(){b("change")},s.delay)}function c(){o||(o=new MutationObserver(R)),o.observe(e.canvas,{subtree:!0,childList:!0,attributes:!0,characterData:!0})}function O(){window.clearTimeout(l),l=null,o&&o.disconnect()}function T(){r==="enabled"&&b("pagehide")}function _(){if(!(r==="destroyed"||r==="unavailable")){if(u=e.snapshotHtml(),f=L(u),window.addEventListener("pagehide",T),r==="enabled"&&d&&d.base===f&&d.html!==u){I(d);return}d=null,r==="enabled"&&c()}}function F(t){try{return new Date(t).toLocaleString(e.settings.locale||void 0)}catch(a){return new Date(t).toLocaleString()}}function I(t){r="asking",e.confirm(e.t("autosave.restore_message",{date:F(t.savedAt)}),{title:e.t("autosave.restore_title"),ok:e.t("autosave.restore"),cancel:e.t("autosave.discard")},function(a){if(r!=="destroyed"){if(a===null){window.setTimeout(function(){r==="asking"&&I(t)},0);return}d=null,a?(u=t.html,e.setHtml(t.html),e.emit("after-restore-draft",{canvas:e.canvas,html:t.html,savedAt:t.savedAt})):h(),r=g?"enabled":"disabled",r==="enabled"&&c()}})}return{onInit:function(){S||(S=!0,Promise.resolve().then(_))},onSourceOpen:function(){p=!0},onSourceClose:function(){p=!1},onDestroy:function(){r==="enabled"&&l&&b("destroy"),O(),o=null,window.removeEventListener("pagehide",T),r!=="unavailable"&&D.delete(n),r="destroyed"},methods:{enableAutosave:function(){return r==="unavailable"?!1:r==="asking"?(g=!0,!0):(r!=="enabled"&&(r="enabled",f!==null&&c()),!0)},disableAutosave:function(){return r==="unavailable"?!1:r==="asking"?(g=!1,!0):(O(),r="disabled",!0)},saveDraft:function(){return r==="unavailable"||r==="asking"?!1:b("api")},getDraft:function(){if(r==="unavailable")return null;var t=E(!1);return t?{html:t.html,savedAt:t.savedAt}:null},clearDraft:function(){if(r==="unavailable")return!1;if(window.clearTimeout(l),l=null,h(),f!==null&&r!=="asking"){var t=!!o&&r==="enabled";t&&o.disconnect(),u=e.snapshotHtml(),f=L(u),t&&c()}return!0}}}};})();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/js/register.js", "../../src/js/plugins/grideditor.autosave.js"],
4
- "sourcesContent": ["/**\n * What a plugin's or a locale's classic script imports in place of the\n * editor: the GridEditor the page already loaded.\n *\n * The build points `import { GridEditor } from '../grideditor.js'` here for\n * the classic scripts, so each registers on the editor the page has rather\n * than bringing its own. Loaded before the editor there is nothing to\n * register on, and saying so is better than a TypeError three calls later.\n */\nvar GridEditor = window.GridEditor;\n\nif (!GridEditor || typeof GridEditor.get !== 'function') {\n throw new Error('grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, ' +\n 'its locales and grideditor.jquery.js');\n}\n\nexport { GridEditor };\nexport default GridEditor;\n", "/**\n * Autosave for grid-editor.\n *\n * A feature plugin: load this file after the editor and what is being edited\n * is kept in the browser's storage as it changes, and offered back the next\n * time an editor starts from the same html. What it can ask the editor for is\n * the handle its factory is called with, described in docs/plugins.md.\n *\n * <script src=\"dist/grideditor.min.js\"></script>\n * <script src=\"dist/plugins/grideditor.autosave.min.js\"></script>\n *\n * It reads the canvas with ge.snapshotHtml(), which leaves the canvas\n * editing: the text being typed into stays open, with its cursor. A save\n * comes `delay` ms after the last change, and when the page is left.\n *\n * A draft remembers the html its editor started from, and is only offered\n * to an editor that starts from the same html: a page that loads one\n * document after another is not offered one document's draft over another.\n * Such a page gives each document a key of its own, and each keeps its draft.\n *\n * new GridEditor('#myGrid', { autosave: { key: 'page-42', storage: 'session' } });\n */\nimport { GridEditor } from '../grideditor.js';\n\nObject.assign(GridEditor.locales.en, {\n 'autosave.restore_title': 'Restore the draft?',\n 'autosave.restore_message': 'There is a draft of this page saved on {date}, with changes that were not published. Restore it?',\n 'autosave.restore': 'Restore',\n 'autosave.discard': 'Discard',\n});\n\nvar VERSION = 1;\nvar STORAGES = { local: 'localStorage', session: 'sessionStorage' };\nvar DEFAULT_DELAY = 1000;\n\n/** The keys the editors on this page save to: one editor to a key. */\nvar liveKeys = new Set();\n\n/** FNV-1a, 32 bits, as hex: enough to tell one document's html from another's. */\nfunction fingerprint(text) {\n var hash = 0x811c9dc5;\n\n for (var i = 0; i < text.length; i++) {\n hash ^= text.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n\n return (hash >>> 0).toString(16).padStart(8, '0');\n}\n\n/** A stored value that is a draft this file wrote, or null. */\nfunction validDraft(value) {\n return !!value && typeof value === 'object' && value.version === VERSION &&\n typeof value.html === 'string' && typeof value.base === 'string' &&\n typeof value.savedAt === 'string' && !isNaN(Date.parse(value.savedAt));\n}\n\nGridEditor.features.autosave = function(ge) {\n\n var options = optionsFrom(ge.settings.autosave || {});\n var key = options.key || 'grideditor.autosave:' + window.location.pathname + '#' + ge.canvas.id;\n var storage = storageFor(options.storage);\n\n // unavailable | disabled | asking | enabled | destroyed\n var state = 'disabled';\n var enabledAfterAsking = true; // What asking ends in: a method may have changed it meanwhile\n var started = false; // Whether the first init has been looked at\n var draft = null; // The draft found when the editor was made, while it may be offered\n var base = null; // The fingerprint of the html the editor started from\n var last = null; // The html saved last, or the one there was to start from\n var timer = null;\n var observer = null;\n var sourceOpen = false;\n var warnedWrite = false;\n\n if (!storage) {\n ge.warn('autosave: the browser will not give this page its ' + STORAGES[options.storage] +\n ', so nothing is saved');\n state = 'unavailable';\n } else if (liveKeys.has(key)) {\n ge.warn('autosave: another editor on this page already saves to \"' + key + '\", so this one does not; ' +\n 'give each its own autosave.key');\n state = 'unavailable';\n } else {\n liveKeys.add(key);\n if (options.enabled) {\n state = 'enabled';\n draft = readDraft(true);\n }\n }\n\n function optionsFrom(given) {\n var result = {\n enabled: given.enabled === undefined ? true : !!given.enabled,\n storage: given.storage === undefined ? 'local' : given.storage,\n key: given.key === undefined ? null : given.key,\n delay: given.delay === undefined ? DEFAULT_DELAY : given.delay,\n maxAge: given.maxAge === undefined ? null : given.maxAge,\n };\n\n if (!STORAGES[result.storage]) {\n ge.warn('autosave.storage \"' + result.storage + '\" is not local or session: local is used');\n result.storage = 'local';\n }\n if (result.key !== null && (typeof result.key !== 'string' || result.key === '')) {\n ge.warn('autosave.key must be a string: the page\\'s own key is used');\n result.key = null;\n }\n if (typeof result.delay !== 'number' || !Number.isInteger(result.delay) || result.delay < 0) {\n ge.warn('autosave.delay must be a whole number of milliseconds, 0 or more: ' + DEFAULT_DELAY + ' is used');\n result.delay = DEFAULT_DELAY;\n }\n if (result.maxAge !== null && !(typeof result.maxAge === 'number' && isFinite(result.maxAge) && result.maxAge > 0)) {\n ge.warn('autosave.maxAge must be a number of milliseconds over 0, or null: drafts do not expire');\n result.maxAge = null;\n }\n\n return result;\n }\n\n /** The storage, if the browser lets the page have it. */\n function storageFor(name) {\n try {\n var found = window[STORAGES[name]];\n found.getItem(key);\n return found;\n } catch (error) {\n return null;\n }\n }\n\n /**\n * The draft saved under the key, or null. Starting, one that cannot be\n * read or has expired is taken away: nothing will ever offer it.\n */\n function readDraft(starting) {\n var raw;\n\n try {\n raw = storage.getItem(key);\n } catch (error) {\n return null;\n }\n if (raw === null) { return null; }\n\n var value = null;\n try { value = JSON.parse(raw); } catch (error) { /* not ours, or mangled */ }\n\n if (!validDraft(value)) {\n if (starting) {\n ge.warn('autosave: what is saved under \"' + key + '\" is not a draft this version can read: it is discarded');\n remove();\n }\n return null;\n }\n\n if (starting && options.maxAge !== null && Date.now() - Date.parse(value.savedAt) > options.maxAge) {\n remove();\n return null;\n }\n\n return value;\n }\n\n function remove() {\n try { storage.removeItem(key); } catch (error) { /* nothing to take away */ }\n }\n\n /** Write the canvas as it is, if it changed. True when it was written. */\n function save(source) {\n window.clearTimeout(timer);\n timer = null;\n\n if (sourceOpen || base === null) { return false; }\n\n // The read itself may change the canvas - getHtml, when a plugin\n // cannot be read on a copy - and that is not a change to save\n var watching = !!observer;\n if (watching) { observer.disconnect(); }\n var html = ge.snapshotHtml();\n if (watching) { watch(); }\n\n if (html === last) { return false; }\n\n var value = { version: VERSION, html: html, savedAt: new Date().toISOString(), base: base };\n\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch (error) {\n if (!warnedWrite) {\n warnedWrite = true;\n ge.warn('autosave: the draft could not be saved (' + (error && error.message || error) + ')');\n }\n ge.emit('autosave-error', { canvas: ge.canvas, error: error });\n return false;\n }\n\n last = html;\n ge.emit('after-autosave', { canvas: ge.canvas, html: html, savedAt: value.savedAt, source: source });\n return true;\n }\n\n function schedule() {\n window.clearTimeout(timer);\n timer = window.setTimeout(function() { save('change'); }, options.delay);\n }\n\n function watch() {\n if (!observer) { observer = new MutationObserver(schedule); }\n observer.observe(ge.canvas, { subtree: true, childList: true, attributes: true, characterData: true });\n }\n\n function unwatch() {\n window.clearTimeout(timer);\n timer = null;\n if (observer) { observer.disconnect(); }\n }\n\n function onPageHide() {\n if (state === 'enabled') { save('pagehide'); }\n }\n\n /** After the first init has finished: what there is to start from, and the draft offered. */\n function start() {\n if (state === 'destroyed' || state === 'unavailable') { return; }\n\n last = ge.snapshotHtml();\n base = fingerprint(last);\n window.addEventListener('pagehide', onPageHide);\n\n // One of another document, or the same as what is there, is not offered\n if (state === 'enabled' && draft && draft.base === base && draft.html !== last) {\n ask(draft);\n return;\n }\n\n draft = null;\n if (state === 'enabled') { watch(); }\n }\n\n function dateOf(savedAt) {\n try {\n return new Date(savedAt).toLocaleString(ge.settings.locale || undefined);\n } catch (error) {\n return new Date(savedAt).toLocaleString();\n }\n }\n\n function ask(found) {\n state = 'asking';\n\n ge.confirm(ge.t('autosave.restore_message', { date: dateOf(found.savedAt) }), {\n title: ge.t('autosave.restore_title'),\n ok: ge.t('autosave.restore'),\n cancel: ge.t('autosave.discard'),\n }, function(restore) {\n if (state === 'destroyed') { return; }\n\n // Taken away unanswered - setLocale - so asked again, in the new\n // language, once the old modal is out of the way\n if (restore === null) {\n window.setTimeout(function() {\n if (state === 'asking') { ask(found); }\n }, 0);\n return;\n }\n\n draft = null;\n\n if (restore) {\n last = found.html;\n ge.setHtml(found.html);\n ge.emit('after-restore-draft', { canvas: ge.canvas, html: found.html, savedAt: found.savedAt });\n } else {\n remove();\n }\n\n state = enabledAfterAsking ? 'enabled' : 'disabled';\n if (state === 'enabled') { watch(); }\n });\n }\n\n return {\n // The first init, once it has finished: the canvas is ready to be read\n onInit: function() {\n if (started) { return; }\n started = true;\n Promise.resolve().then(start);\n },\n\n onSourceOpen: function() { sourceOpen = true; },\n onSourceClose: function() { sourceOpen = false; },\n\n onDestroy: function() {\n if (state === 'enabled' && timer) { save('destroy'); }\n\n unwatch();\n observer = null;\n window.removeEventListener('pagehide', onPageHide);\n if (state !== 'unavailable') { liveKeys.delete(key); }\n state = 'destroyed';\n },\n\n methods: {\n enableAutosave: function() {\n if (state === 'unavailable') { return false; }\n if (state === 'asking') {\n enabledAfterAsking = true;\n return true;\n }\n if (state !== 'enabled') {\n state = 'enabled';\n if (base !== null) { watch(); }\n }\n return true;\n },\n\n disableAutosave: function() {\n if (state === 'unavailable') { return false; }\n if (state === 'asking') {\n enabledAfterAsking = false;\n return true;\n }\n unwatch();\n state = 'disabled';\n return true;\n },\n\n saveDraft: function() {\n if (state === 'unavailable' || state === 'asking') { return false; }\n return save('api');\n },\n\n getDraft: function() {\n if (state === 'unavailable') { return null; }\n\n var found = readDraft(false);\n return found ? { html: found.html, savedAt: found.savedAt } : null;\n },\n\n // What there is now is not a draft any more - a page calls this\n // once it has saved to its server - so the save waiting does not\n // write it back, and only a change from here makes a new draft\n clearDraft: function() {\n if (state === 'unavailable') { return false; }\n\n window.clearTimeout(timer);\n timer = null;\n remove();\n\n // Not while it asks: the canvas is not what was offered yet\n if (base !== null && state !== 'asking' && !sourceOpen) {\n var watching = !!observer && state === 'enabled';\n if (watching) { observer.disconnect(); }\n last = ge.snapshotHtml();\n if (watching) { watch(); }\n }\n return true;\n },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AAI,IAClE,EAKA,WAAY,UAAW,CACnB,GAAId,IAAU,cAAiB,MAAO,GAOtC,GALA,OAAO,aAAaM,CAAK,EACzBA,EAAQ,KACRY,EAAO,EAGHd,IAAS,MAAQJ,IAAU,UAAY,CAACQ,EAAY,CACpD,IAAIa,EAAW,CAAC,CAACd,GAAYP,IAAU,UACnCqB,GAAYd,EAAS,WAAW,EACpCF,EAAOX,EAAG,aAAa,EACnB2B,GAAYE,EAAM,CAC1B,CACA,MAAO,EACX,CACJ,CACJ,CACJ",
4
+ "sourcesContent": ["/**\n * What a plugin's or a locale's classic script imports in place of the\n * editor: the GridEditor the page already loaded.\n *\n * The build points `import { GridEditor } from '../grideditor.js'` here for\n * the classic scripts, so each registers on the editor the page has rather\n * than bringing its own. Loaded before the editor there is nothing to\n * register on, and saying so is better than a TypeError three calls later.\n */\nvar GridEditor = window.GridEditor;\n\nif (!GridEditor || typeof GridEditor.get !== 'function') {\n throw new Error('grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, ' +\n 'its locales and grideditor.jquery.js');\n}\n\nexport { GridEditor };\nexport default GridEditor;\n", "/**\n * Autosave for grid-editor.\n *\n * A feature plugin: load this file after the editor and what is being edited\n * is kept in the browser's storage as it changes, and offered back the next\n * time an editor starts from the same html. What it can ask the editor for is\n * the handle its factory is called with, described in docs/plugins.md.\n *\n * <script src=\"dist/grideditor.min.js\"></script>\n * <script src=\"dist/plugins/grideditor.autosave.min.js\"></script>\n *\n * It reads the canvas with ge.snapshotHtml(), which leaves the canvas\n * editing: the text being typed into stays open, with its cursor. A save\n * comes `delay` ms after the last change, and when the page is left.\n *\n * A draft remembers the html its editor started from, and is only offered\n * to an editor that starts from the same html: a page that loads one\n * document after another is not offered one document's draft over another.\n * Such a page gives each document a key of its own, and each keeps its draft.\n *\n * new GridEditor('#myGrid', { autosave: { key: 'page-42', storage: 'session' } });\n */\nimport { GridEditor } from '../grideditor.js';\n\nObject.assign(GridEditor.locales.en, {\n 'autosave.restore_title': 'Restore the draft?',\n 'autosave.restore_message': 'There is a draft of this page saved on {date}, with changes that were not published. Restore it?',\n 'autosave.restore': 'Restore',\n 'autosave.discard': 'Discard',\n});\n\nvar VERSION = 1;\nvar STORAGES = { local: 'localStorage', session: 'sessionStorage' };\nvar DEFAULT_DELAY = 1000;\n\n/** The keys the editors on this page save to: one editor to a key. */\nvar liveKeys = new Set();\n\n/** FNV-1a, 32 bits, as hex: enough to tell one document's html from another's. */\nfunction fingerprint(text) {\n var hash = 0x811c9dc5;\n\n for (var i = 0; i < text.length; i++) {\n hash ^= text.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n\n return (hash >>> 0).toString(16).padStart(8, '0');\n}\n\n/** A stored value that is a draft this file wrote, or null. */\nfunction validDraft(value) {\n return !!value && typeof value === 'object' && value.version === VERSION &&\n typeof value.html === 'string' && typeof value.base === 'string' &&\n typeof value.savedAt === 'string' && !isNaN(Date.parse(value.savedAt));\n}\n\nGridEditor.features.autosave = function(ge) {\n\n var options = optionsFrom(ge.settings.autosave || {});\n var key = options.key || 'grideditor.autosave:' + window.location.pathname + '#' + ge.canvas.id;\n var storage = storageFor(options.storage);\n\n // unavailable | disabled | asking | enabled | destroyed\n var state = 'disabled';\n var enabledAfterAsking = true; // What asking ends in: a method may have changed it meanwhile\n var started = false; // Whether the first init has been looked at\n var draft = null; // The draft found when the editor was made, while it may be offered\n var base = null; // The fingerprint of the html the editor started from\n var last = null; // The html saved last, or the one there was to start from\n var timer = null;\n var observer = null;\n var sourceOpen = false;\n var warnedWrite = false;\n\n if (!storage) {\n ge.warn('autosave: the browser will not give this page its ' + STORAGES[options.storage] +\n ', so nothing is saved');\n state = 'unavailable';\n } else if (liveKeys.has(key)) {\n ge.warn('autosave: another editor on this page already saves to \"' + key + '\", so this one does not; ' +\n 'give each its own autosave.key');\n state = 'unavailable';\n } else {\n liveKeys.add(key);\n if (options.enabled) {\n state = 'enabled';\n draft = readDraft(true);\n }\n }\n\n function optionsFrom(given) {\n var result = {\n enabled: given.enabled === undefined ? true : !!given.enabled,\n storage: given.storage === undefined ? 'local' : given.storage,\n key: given.key === undefined ? null : given.key,\n delay: given.delay === undefined ? DEFAULT_DELAY : given.delay,\n maxAge: given.maxAge === undefined ? null : given.maxAge,\n };\n\n if (!STORAGES[result.storage]) {\n ge.warn('autosave.storage \"' + result.storage + '\" is not local or session: local is used');\n result.storage = 'local';\n }\n if (result.key !== null && (typeof result.key !== 'string' || result.key === '')) {\n ge.warn('autosave.key must be a string: the page\\'s own key is used');\n result.key = null;\n }\n if (typeof result.delay !== 'number' || !Number.isInteger(result.delay) || result.delay < 0) {\n ge.warn('autosave.delay must be a whole number of milliseconds, 0 or more: ' + DEFAULT_DELAY + ' is used');\n result.delay = DEFAULT_DELAY;\n }\n if (result.maxAge !== null && !(typeof result.maxAge === 'number' && isFinite(result.maxAge) && result.maxAge > 0)) {\n ge.warn('autosave.maxAge must be a number of milliseconds over 0, or null: drafts do not expire');\n result.maxAge = null;\n }\n\n return result;\n }\n\n /** The storage, if the browser lets the page have it. */\n function storageFor(name) {\n try {\n var found = window[STORAGES[name]];\n found.getItem(key);\n return found;\n } catch (error) {\n return null;\n }\n }\n\n /**\n * The draft saved under the key, or null. Starting, one that cannot be\n * read or has expired is taken away: nothing will ever offer it.\n */\n function readDraft(starting) {\n var raw;\n\n try {\n raw = storage.getItem(key);\n } catch (error) {\n return null;\n }\n if (raw === null) { return null; }\n\n var value = null;\n try { value = JSON.parse(raw); } catch (error) { /* not ours, or mangled */ }\n\n if (!validDraft(value)) {\n if (starting) {\n ge.warn('autosave: what is saved under \"' + key + '\" is not a draft this version can read: it is discarded');\n remove();\n }\n return null;\n }\n\n if (starting && options.maxAge !== null && Date.now() - Date.parse(value.savedAt) > options.maxAge) {\n remove();\n return null;\n }\n\n return value;\n }\n\n function remove() {\n try { storage.removeItem(key); } catch (error) { /* nothing to take away */ }\n }\n\n /** Write the canvas as it is, if it changed. True when it was written. */\n function save(source) {\n window.clearTimeout(timer);\n timer = null;\n\n if (sourceOpen || base === null) { return false; }\n\n // The read itself may change the canvas - getHtml, when a plugin\n // cannot be read on a copy - and that is not a change to save\n var watching = !!observer;\n if (watching) { observer.disconnect(); }\n var html = ge.snapshotHtml();\n if (watching) { watch(); }\n\n if (html === last) { return false; }\n\n var value = { version: VERSION, html: html, savedAt: new Date().toISOString(), base: base };\n\n try {\n storage.setItem(key, JSON.stringify(value));\n } catch (error) {\n if (!warnedWrite) {\n warnedWrite = true;\n ge.warn('autosave: the draft could not be saved (' + (error && error.message || error) + ')');\n }\n ge.emit('autosave-error', { canvas: ge.canvas, error: error });\n return false;\n }\n\n last = html;\n ge.emit('after-autosave', { canvas: ge.canvas, html: html, savedAt: value.savedAt, source: source });\n return true;\n }\n\n function schedule() {\n window.clearTimeout(timer);\n timer = window.setTimeout(function() { save('change'); }, options.delay);\n }\n\n function watch() {\n if (!observer) { observer = new MutationObserver(schedule); }\n observer.observe(ge.canvas, { subtree: true, childList: true, attributes: true, characterData: true });\n }\n\n function unwatch() {\n window.clearTimeout(timer);\n timer = null;\n if (observer) { observer.disconnect(); }\n }\n\n function onPageHide() {\n if (state === 'enabled') { save('pagehide'); }\n }\n\n /** After the first init has finished: what there is to start from, and the draft offered. */\n function start() {\n if (state === 'destroyed' || state === 'unavailable') { return; }\n\n last = ge.snapshotHtml();\n base = fingerprint(last);\n window.addEventListener('pagehide', onPageHide);\n\n // One of another document, or the same as what is there, is not offered\n if (state === 'enabled' && draft && draft.base === base && draft.html !== last) {\n ask(draft);\n return;\n }\n\n draft = null;\n if (state === 'enabled') { watch(); }\n }\n\n function dateOf(savedAt) {\n try {\n return new Date(savedAt).toLocaleString(ge.settings.locale || undefined);\n } catch (error) {\n return new Date(savedAt).toLocaleString();\n }\n }\n\n function ask(found) {\n state = 'asking';\n\n ge.confirm(ge.t('autosave.restore_message', { date: dateOf(found.savedAt) }), {\n title: ge.t('autosave.restore_title'),\n ok: ge.t('autosave.restore'),\n cancel: ge.t('autosave.discard'),\n }, function(restore) {\n if (state === 'destroyed') { return; }\n\n // Taken away unanswered - setLocale - so asked again, in the new\n // language, once the old modal is out of the way\n if (restore === null) {\n window.setTimeout(function() {\n if (state === 'asking') { ask(found); }\n }, 0);\n return;\n }\n\n draft = null;\n\n if (restore) {\n last = found.html;\n ge.setHtml(found.html);\n ge.emit('after-restore-draft', { canvas: ge.canvas, html: found.html, savedAt: found.savedAt });\n } else {\n remove();\n }\n\n state = enabledAfterAsking ? 'enabled' : 'disabled';\n if (state === 'enabled') { watch(); }\n });\n }\n\n return {\n // The first init, once it has finished: the canvas is ready to be read\n onInit: function() {\n if (started) { return; }\n started = true;\n Promise.resolve().then(start);\n },\n\n onSourceOpen: function() { sourceOpen = true; },\n onSourceClose: function() { sourceOpen = false; },\n\n onDestroy: function() {\n if (state === 'enabled' && timer) { save('destroy'); }\n\n unwatch();\n observer = null;\n window.removeEventListener('pagehide', onPageHide);\n if (state !== 'unavailable') { liveKeys.delete(key); }\n state = 'destroyed';\n },\n\n methods: {\n enableAutosave: function() {\n if (state === 'unavailable') { return false; }\n if (state === 'asking') {\n enabledAfterAsking = true;\n return true;\n }\n if (state !== 'enabled') {\n state = 'enabled';\n if (base !== null) { watch(); }\n }\n return true;\n },\n\n disableAutosave: function() {\n if (state === 'unavailable') { return false; }\n if (state === 'asking') {\n enabledAfterAsking = false;\n return true;\n }\n unwatch();\n state = 'disabled';\n return true;\n },\n\n saveDraft: function() {\n if (state === 'unavailable' || state === 'asking') { return false; }\n return save('api');\n },\n\n getDraft: function() {\n if (state === 'unavailable') { return null; }\n\n var found = readDraft(false);\n return found ? { html: found.html, savedAt: found.savedAt } : null;\n },\n\n // What there is now is not a draft any more - a page calls this\n // once it has saved to its server - so the save waiting does not\n // write it back, and only a change from here makes a new draft.\n // What there is now is also the base of the drafts that follow:\n // the page, loaded again, starts from the html it saved, and a\n // draft made after this is offered to it.\n //\n // With the source view open the canvas reads as getHtml gives it -\n // what the page saved - so that is the base; what is typed in the\n // source and not saved is a change from it, and saved as a draft\n // once the view closes.\n //\n // Not while it asks: the canvas is not what was offered yet, and\n // the base stays the html the editor started from.\n clearDraft: function() {\n if (state === 'unavailable') { return false; }\n\n window.clearTimeout(timer);\n timer = null;\n remove();\n\n if (base !== null && state !== 'asking') {\n var watching = !!observer && state === 'enabled';\n if (watching) { observer.disconnect(); }\n last = ge.snapshotHtml();\n base = fingerprint(last);\n if (watching) { watch(); }\n }\n return true;\n },\n },\n };\n};\n"],
5
+ "mappings": "MASA,IAAIA,EAAa,OAAO,WAExB,GAAI,CAACA,GAAc,OAAOA,EAAW,KAAQ,WACzC,MAAM,IAAI,MAAM,wHAC0B,ECW9C,OAAO,OAAOC,EAAW,QAAQ,GAAI,CACjC,yBAA0B,qBAC1B,2BAA4B,mGAC5B,mBAAoB,UACpB,mBAAoB,SACxB,CAAC,EAED,IAAIC,EAAU,EACVC,EAAW,CAAE,MAAO,eAAgB,QAAS,gBAAiB,EAC9DC,EAAgB,IAGhBC,EAAW,IAAI,IAGnB,SAASC,EAAYC,EAAM,CAGvB,QAFIC,EAAO,WAEFC,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAQD,EAAK,WAAWE,CAAC,EACzBD,EAAO,KAAK,KAAKA,EAAM,QAAU,EAGrC,OAAQA,IAAS,GAAG,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CACpD,CAGA,SAASE,EAAWC,EAAO,CACvB,MAAO,CAAC,CAACA,GAAS,OAAOA,GAAU,UAAYA,EAAM,UAAYT,GAC7D,OAAOS,EAAM,MAAS,UAAY,OAAOA,EAAM,MAAS,UACxD,OAAOA,EAAM,SAAY,UAAY,CAAC,MAAM,KAAK,MAAMA,EAAM,OAAO,CAAC,CAC7E,CAEAV,EAAW,SAAS,SAAW,SAASW,EAAI,CAExC,IAAIC,EAAUC,EAAYF,EAAG,SAAS,UAAY,CAAC,CAAC,EAChDG,EAAMF,EAAQ,KAAO,uBAAyB,OAAO,SAAS,SAAW,IAAMD,EAAG,O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wB,EAAQ,EACRzB,EAAQ,WACD,GACX,EAEA,UAAW,UAAW,CAClB,OAAIA,IAAU,eAAiBA,IAAU,SAAmB,GACrDmB,EAAK,KAAK,CACrB,EAEA,SAAU,UAAW,CACjB,GAAInB,IAAU,cAAiB,OAAO,KAEtC,IAAIc,EAAQJ,EAAU,EAAK,EAC3B,OAAOI,EAAQ,CAAE,KAAMA,EAAM,KAAM,QAASA,EAAM,OAAQ,EAAI,IAClE,EAgBA,WAAY,UAAW,CACnB,GAAId,IAAU,cAAiB,MAAO,GAMtC,GAJA,OAAO,aAAaM,CAAK,EACzBA,EAAQ,KACRY,EAAO,EAEHd,IAAS,MAAQJ,IAAU,SAAU,CACrC,IAAIqB,EAAW,CAAC,CAACd,GAAYP,IAAU,UACnCqB,GAAYd,EAAS,WAAW,EACpCF,EAAOX,EAAG,aAAa,EACvBU,EAAOhB,EAAYiB,CAAI,EACnBgB,GAAYE,EAAM,CAC1B,CACA,MAAO,EACX,CACJ,CACJ,CACJ",
6
6
  "names": ["GridEditor", "GridEditor", "VERSION", "STORAGES", "DEFAULT_DELAY", "liveKeys", "fingerprint", "text", "hash", "i", "validDraft", "value", "ge", "options", "optionsFrom", "key", "storage", "storageFor", "state", "enabledAfterAsking", "started", "draft", "base", "last", "timer", "observer", "sourceOpen", "warnedWrite", "readDraft", "given", "result", "name", "found", "error", "starting", "raw", "remove", "save", "source", "watching", "html", "watch", "schedule", "unwatch", "onPageHide", "start", "ask", "dateOf", "savedAt", "restore"]
7
7
  }
package/package.json CHANGED
@@ -32,7 +32,7 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "version": "9.2.4",
35
+ "version": "9.2.5",
36
36
  "main": "dist/grideditor.js",
37
37
  "module": "dist/grideditor.esm.js",
38
38
  "types": "dist/grideditor.d.ts",
@@ -340,7 +340,18 @@ GridEditor.features.autosave = function(ge) {
340
340
 
341
341
  // What there is now is not a draft any more - a page calls this
342
342
  // once it has saved to its server - so the save waiting does not
343
- // write it back, and only a change from here makes a new draft
343
+ // write it back, and only a change from here makes a new draft.
344
+ // What there is now is also the base of the drafts that follow:
345
+ // the page, loaded again, starts from the html it saved, and a
346
+ // draft made after this is offered to it.
347
+ //
348
+ // With the source view open the canvas reads as getHtml gives it -
349
+ // what the page saved - so that is the base; what is typed in the
350
+ // source and not saved is a change from it, and saved as a draft
351
+ // once the view closes.
352
+ //
353
+ // Not while it asks: the canvas is not what was offered yet, and
354
+ // the base stays the html the editor started from.
344
355
  clearDraft: function() {
345
356
  if (state === 'unavailable') { return false; }
346
357
 
@@ -348,11 +359,11 @@ GridEditor.features.autosave = function(ge) {
348
359
  timer = null;
349
360
  remove();
350
361
 
351
- // Not while it asks: the canvas is not what was offered yet
352
- if (base !== null && state !== 'asking' && !sourceOpen) {
362
+ if (base !== null && state !== 'asking') {
353
363
  var watching = !!observer && state === 'enabled';
354
364
  if (watching) { observer.disconnect(); }
355
365
  last = ge.snapshotHtml();
366
+ base = fingerprint(last);
356
367
  if (watching) { watch(); }
357
368
  }
358
369
  return true;