@themarioga/grid-editor 9.2.3 → 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.
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.esm.js +25 -3
- package/dist/grideditor.js +25 -3
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/plugins/grideditor.autosave.esm.js +14 -2
- package/dist/plugins/grideditor.autosave.js +14 -2
- package/dist/plugins/grideditor.autosave.min.js +1 -1
- package/dist/plugins/grideditor.autosave.min.js.map +2 -2
- package/docs/plugins.md +13 -0
- package/package.json +1 -1
- package/src/js/grideditor.js +33 -3
- package/src/js/plugins/grideditor.autosave.js +14 -3
|
@@ -299,7 +299,18 @@ GridEditor.features.autosave = function(ge) {
|
|
|
299
299
|
},
|
|
300
300
|
// What there is now is not a draft any more - a page calls this
|
|
301
301
|
// once it has saved to its server - so the save waiting does not
|
|
302
|
-
// write it back, and only a change from here makes a new draft
|
|
302
|
+
// write it back, and only a change from here makes a new draft.
|
|
303
|
+
// What there is now is also the base of the drafts that follow:
|
|
304
|
+
// the page, loaded again, starts from the html it saved, and a
|
|
305
|
+
// draft made after this is offered to it.
|
|
306
|
+
//
|
|
307
|
+
// With the source view open the canvas reads as getHtml gives it -
|
|
308
|
+
// what the page saved - so that is the base; what is typed in the
|
|
309
|
+
// source and not saved is a change from it, and saved as a draft
|
|
310
|
+
// once the view closes.
|
|
311
|
+
//
|
|
312
|
+
// Not while it asks: the canvas is not what was offered yet, and
|
|
313
|
+
// the base stays the html the editor started from.
|
|
303
314
|
clearDraft: function() {
|
|
304
315
|
if (state === "unavailable") {
|
|
305
316
|
return false;
|
|
@@ -307,12 +318,13 @@ GridEditor.features.autosave = function(ge) {
|
|
|
307
318
|
window.clearTimeout(timer);
|
|
308
319
|
timer = null;
|
|
309
320
|
remove();
|
|
310
|
-
if (base !== null && state !== "asking"
|
|
321
|
+
if (base !== null && state !== "asking") {
|
|
311
322
|
var watching = !!observer && state === "enabled";
|
|
312
323
|
if (watching) {
|
|
313
324
|
observer.disconnect();
|
|
314
325
|
}
|
|
315
326
|
last = ge.snapshotHtml();
|
|
327
|
+
base = fingerprint(last);
|
|
316
328
|
if (watching) {
|
|
317
329
|
watch();
|
|
318
330
|
}
|
|
@@ -305,7 +305,18 @@
|
|
|
305
305
|
},
|
|
306
306
|
// What there is now is not a draft any more - a page calls this
|
|
307
307
|
// once it has saved to its server - so the save waiting does not
|
|
308
|
-
// write it back, and only a change from here makes a new draft
|
|
308
|
+
// write it back, and only a change from here makes a new draft.
|
|
309
|
+
// What there is now is also the base of the drafts that follow:
|
|
310
|
+
// the page, loaded again, starts from the html it saved, and a
|
|
311
|
+
// draft made after this is offered to it.
|
|
312
|
+
//
|
|
313
|
+
// With the source view open the canvas reads as getHtml gives it -
|
|
314
|
+
// what the page saved - so that is the base; what is typed in the
|
|
315
|
+
// source and not saved is a change from it, and saved as a draft
|
|
316
|
+
// once the view closes.
|
|
317
|
+
//
|
|
318
|
+
// Not while it asks: the canvas is not what was offered yet, and
|
|
319
|
+
// the base stays the html the editor started from.
|
|
309
320
|
clearDraft: function() {
|
|
310
321
|
if (state === "unavailable") {
|
|
311
322
|
return false;
|
|
@@ -313,12 +324,13 @@
|
|
|
313
324
|
window.clearTimeout(timer);
|
|
314
325
|
timer = null;
|
|
315
326
|
remove();
|
|
316
|
-
if (base !== null && state !== "asking"
|
|
327
|
+
if (base !== null && state !== "asking") {
|
|
317
328
|
var watching = !!observer && state === "enabled";
|
|
318
329
|
if (watching) {
|
|
319
330
|
observer.disconnect();
|
|
320
331
|
}
|
|
321
332
|
last = ge.snapshotHtml();
|
|
333
|
+
base = fingerprint(last);
|
|
322
334
|
if (watching) {
|
|
323
335
|
watch();
|
|
324
336
|
}
|
|
@@ -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
|
|
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 },\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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AAW,CAAEA,EAAa,EAAO,EAEhD,UAAW,UAAW,CACdR,IAAU,WAAaM,GAASa,EAAK,SAAS,EAElDM,EAAQ,EACRlB,EAAW,KACX,OAAO,oBAAoB,WAAYmB,CAAU,EAC7C1B,IAAU,eAAiBb,EAAS,OAAOU,CAAG,EAClDG,EAAQ,WACZ,EAEA,QAAS,CACL,eAAgB,UAAW,CACvB,OAAIA,IAAU,cAAwB,GAClCA,IAAU,UACVC,EAAqB,GACd,KAEPD,IAAU,YACVA,EAAQ,UACJI,IAAS,MAAQmB,EAAM,GAExB,GACX,EAEA,gBAAiB,UAAW,CACxB,OAAIvB,IAAU,cAAwB,GAClCA,IAAU,UACVC,EAAqB,GACd,KAEXwB,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,
|
|
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,EA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hD,UAAW,UAAW,CACdR,IAAU,WAAaM,GAASa,EAAK,SAAS,EAElDM,EAAQ,EACRlB,EAAW,KACX,OAAO,oBAAoB,WAAYmB,CAAU,EAC7C1B,IAAU,eAAiBb,EAAS,OAAOU,CAAG,EAClDG,EAAQ,WACZ,EAEA,QAAS,CACL,eAAgB,UAAW,CACvB,OAAIA,IAAU,cAAwB,GAClCA,IAAU,UACVC,EAAqB,GACd,KAEPD,IAAU,YACVA,EAAQ,UACJI,IAAS,MAAQmB,EAAM,GAExB,GACX,EAEA,gBAAiB,UAAW,CACxB,OAAIvB,IAAU,cAAwB,GAClCA,IAAU,UACVC,EAAqB,GACd,KAEXwB,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/docs/plugins.md
CHANGED
|
@@ -189,6 +189,7 @@ element, and where there may be several, an array.
|
|
|
189
189
|
| `ge.nodeHtml(node)` | One node's markup as `getHtml` would give it. The canvas leaves editing to read it and comes back, as it does for `getHtml` |
|
|
190
190
|
| `ge.snapshotHtml()` | The canvas's markup as `getHtml` gives it, read on a copy so the canvas never leaves editing: what `getHtml({ keepEditing: true })` is. See [Reading on a copy](#reading-on-a-copy) |
|
|
191
191
|
| `ge.setHtml(html)` | The canvas made of other markup, and edited again: the source view closed if it is open, `deinit`, the markup in, `init`. No add or delete events: it is replaced as a whole. A `<script>` in it does not run in the editor |
|
|
192
|
+
| `ge.reinit()` | The canvas out of editing and back in - `deinit` then `init`, as `getHtml` does around its read - for a plugin that shows the same markup another way and wants it painted again. Does nothing with the source view open, and after `destroy` |
|
|
192
193
|
| `ge.confirm(message, options, answer)` | A question in the editor's confirm modal, the one deleting asks in. `options`: `title`, `ok`, `cancel` - the texts, the locale's by default - and `danger`, a red ok button. `answer(true)` for ok, `answer(false)` for cancel, the close button or Escape, `answer(null)` when the modal is taken away unanswered: `setLocale`, `destroy`, or another question. The browser's `confirm` without Bootstrap's javascript |
|
|
193
194
|
| `ge.refreshToolbar()` | The toolbar built again, from what the feature plugins' `toolbar`s hold now: for a plugin whose buttons come and go. The category shown with `toolbar_groups`, the preview and the source view stay as they are. Does nothing before the toolbar is first built, and after `destroy` |
|
|
194
195
|
| `ge.getActiveTarget()` | The node the toolbar adds to and the sidebar shows - any node with settings - as the public method gives it: `null` without `active_target` |
|
|
@@ -222,6 +223,7 @@ GridEditor.features.elements = function(ge) {
|
|
|
222
223
|
onDeinit: function() { … }, // every deinit: take it out again
|
|
223
224
|
onBeforeDeinit: function() { … }, // every deinit, before the drawers come off: close what you opened
|
|
224
225
|
cleanMarkup: function(root, liveOf) { … }, // what onDeinit and onBeforeDeinit take off, off a copy
|
|
226
|
+
plainMarkup: function(root, options) { … }, // the markup getPlainHtml is about to clean, to change first
|
|
225
227
|
onDestroy: function() { … }, // destroy, first, while the editor is whole
|
|
226
228
|
onSourceOpen: function(textarea) { … }, // the source view opened: the canvas's html is in the textarea
|
|
227
229
|
onSourceClose: function(textarea) { … }, // and is closing: put what you edited back in the textarea
|
|
@@ -465,6 +467,17 @@ rather than remembering anything about it.
|
|
|
465
467
|
goes over the textarea on open and puts its value back in it on close, which
|
|
466
468
|
is all the codemirror plugin does; `destroy` with the source open closes it
|
|
467
469
|
first.
|
|
470
|
+
- **`plainMarkup(root, options)`** is called by `getPlainHtml(options)`, for
|
|
471
|
+
every kind of plugin in the order `deinit` calls them, with the markup
|
|
472
|
+
`getHtml` read, parsed in a document of its own that does not run scripts
|
|
473
|
+
or load images, and still carrying grid-editor's marking: the `data-ge-*`
|
|
474
|
+
attributes and `ge-*` classes come off after every plugin has had its turn.
|
|
475
|
+
Change `root` as the published page should be. `options` is what
|
|
476
|
+
`getPlainHtml` was given, which a plugin may read its own keys from. Return
|
|
477
|
+
`false` to make `getPlainHtml` answer `null` - for a request the plugin
|
|
478
|
+
cannot serve - and the plugins after it are not called. An error it throws
|
|
479
|
+
reaches the caller of `getPlainHtml`. Not called for the jQuery adapter's
|
|
480
|
+
html that is not on a canvas, nor after `destroy`.
|
|
468
481
|
- **`plainTools(drawer, block)`** puts tools in the drawer of the host's plain
|
|
469
482
|
content, between move and delete. That drawer has no gear, so
|
|
470
483
|
`drawerTools` never runs for it: plain content gets no utility, no copy and
|
package/package.json
CHANGED
package/src/js/grideditor.js
CHANGED
|
@@ -294,12 +294,16 @@ function modalLibrary() {
|
|
|
294
294
|
*
|
|
295
295
|
* The marking is what lets the editor read its markup back, so this is for
|
|
296
296
|
* publishing, not for saving something to edit again.
|
|
297
|
+
*
|
|
298
|
+
* `prepare(root)` sees the markup in the inert document before the marking
|
|
299
|
+
* comes off, and can change it; false from it gives null instead of the html.
|
|
297
300
|
*/
|
|
298
|
-
function plainHtml(html) {
|
|
301
|
+
function plainHtml(html, prepare) {
|
|
299
302
|
// Parsed in a document of its own, which is inert: no script in the
|
|
300
303
|
// markup runs and no image starts loading while it is being cleaned
|
|
301
304
|
var root = document.implementation.createHTMLDocument('').body;
|
|
302
305
|
root.innerHTML = html;
|
|
306
|
+
if (prepare && prepare(root) === false) { return null; }
|
|
303
307
|
var emptied = [];
|
|
304
308
|
|
|
305
309
|
dom.all(root, '*').forEach(function(node) {
|
|
@@ -2668,9 +2672,15 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2668
2672
|
return html;
|
|
2669
2673
|
}
|
|
2670
2674
|
|
|
2671
|
-
/**
|
|
2675
|
+
/**
|
|
2676
|
+
* getHtml with grid-editor's own classes and attributes taken off.
|
|
2677
|
+
* A plugin's plainMarkup(root, options) may change the markup first,
|
|
2678
|
+
* while the marking is still on it; false from one makes this null.
|
|
2679
|
+
*/
|
|
2672
2680
|
function getPlainHtml(options) {
|
|
2673
|
-
return plainHtml(getHtml(options))
|
|
2681
|
+
return plainHtml(getHtml(options), function(root) {
|
|
2682
|
+
return pluginsAccept('plainMarkup', root, options);
|
|
2683
|
+
});
|
|
2674
2684
|
}
|
|
2675
2685
|
|
|
2676
2686
|
/**
|
|
@@ -2795,6 +2805,18 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2795
2805
|
});
|
|
2796
2806
|
}
|
|
2797
2807
|
|
|
2808
|
+
/**
|
|
2809
|
+
* plugins(), for a hook that can refuse: false as soon as one says
|
|
2810
|
+
* false, the rest not asked.
|
|
2811
|
+
*/
|
|
2812
|
+
function pluginsAccept(hook, argument, extra) {
|
|
2813
|
+
return [CONTAINERS, FEATURES, UTILITIES].every(function(registry) {
|
|
2814
|
+
return Object.keys(registry).every(function(name) {
|
|
2815
|
+
return !registry[name][hook] || registry[name][hook](argument, extra) !== false;
|
|
2816
|
+
});
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2798
2820
|
/** What a plugin is handed. See docs/plugins.md. */
|
|
2799
2821
|
function pluginApi() {
|
|
2800
2822
|
return {
|
|
@@ -2844,6 +2866,14 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2844
2866
|
// The markup as getHtml gives it, with the canvas left editing
|
|
2845
2867
|
snapshotHtml: snapshotHtml,
|
|
2846
2868
|
setHtml: setHtml,
|
|
2869
|
+
// The canvas out of editing and back in, as getHtml does it,
|
|
2870
|
+
// for a plugin that shows the same markup another way. Not
|
|
2871
|
+
// with the source view open, or after destroy
|
|
2872
|
+
reinit: function() {
|
|
2873
|
+
if (sourceOpen || destroyed) { return; }
|
|
2874
|
+
deinit();
|
|
2875
|
+
init();
|
|
2876
|
+
},
|
|
2847
2877
|
// A question in the editor's confirm modal
|
|
2848
2878
|
confirm: confirmWith,
|
|
2849
2879
|
// A text editor has rewritten a content area, so whatever the
|
|
@@ -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
|
-
|
|
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;
|