Merge branch 'master' into resize-header
This commit is contained in:
commit
4439fb8aab
|
@ -33,6 +33,7 @@ const editor = {
|
||||||
/** @type {'customName'|'name'} */
|
/** @type {'customName'|'name'} */
|
||||||
nameTarget: 'name',
|
nameTarget: 'name',
|
||||||
previewDelay: 200, // Chrome devtools uses 200
|
previewDelay: 200, // Chrome devtools uses 200
|
||||||
|
saving: false,
|
||||||
scrollInfo: null,
|
scrollInfo: null,
|
||||||
|
|
||||||
cancel: () => location.assign('/manage.html'),
|
cancel: () => location.assign('/manage.html'),
|
||||||
|
|
25
edit/edit.js
25
edit/edit.js
|
@ -61,19 +61,11 @@ baseInit.ready.then(async () => {
|
||||||
//#endregion
|
//#endregion
|
||||||
//#region events
|
//#region events
|
||||||
|
|
||||||
const IGNORE_UPDATE_REASONS = [
|
|
||||||
'editPreview',
|
|
||||||
'editPreviewEnd',
|
|
||||||
'editSave',
|
|
||||||
// https://github.com/openstyles/stylus/issues/807 is closed without fix
|
|
||||||
// 'config,
|
|
||||||
];
|
|
||||||
|
|
||||||
msg.onExtension(request => {
|
msg.onExtension(request => {
|
||||||
const {style} = request;
|
const {style} = request;
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case 'styleUpdated':
|
case 'styleUpdated':
|
||||||
if (editor.style.id === style.id && !IGNORE_UPDATE_REASONS.includes(request.reason)) {
|
if (editor.style.id === style.id) {
|
||||||
handleExternalUpdate(request);
|
handleExternalUpdate(request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -89,6 +81,14 @@ msg.onExtension(request => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleExternalUpdate({style, reason}) {
|
async function handleExternalUpdate({style, reason}) {
|
||||||
|
if (reason === 'editPreview' ||
|
||||||
|
reason === 'editPreviewEnd') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (reason === 'editSave' && editor.saving) {
|
||||||
|
editor.saving = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (reason === 'toggle') {
|
if (reason === 'toggle') {
|
||||||
if (editor.dirty.isDirty()) {
|
if (editor.dirty.isDirty()) {
|
||||||
editor.toggleStyle(style.enabled);
|
editor.toggleStyle(style.enabled);
|
||||||
|
@ -191,6 +191,13 @@ window.on('beforeunload', e => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async save() {
|
||||||
|
if (dirty.isDirty()) {
|
||||||
|
editor.saving = true;
|
||||||
|
await editor.saveImpl();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toggleStyle(enabled = !style.enabled) {
|
toggleStyle(enabled = !style.enabled) {
|
||||||
$('#enabled').checked = enabled;
|
$('#enabled').checked = enabled;
|
||||||
editor.updateEnabledness(enabled);
|
editor.updateEnabledness(enabled);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
/* global editor */
|
/* global editor */
|
||||||
/* global linterMan */
|
/* global linterMan */
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
|
/* global styleSectionsEqual */ // sections-util.js
|
||||||
/* global t */// localization.js
|
/* global t */// localization.js
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -86,9 +87,15 @@ function SectionsEditor() {
|
||||||
},
|
},
|
||||||
|
|
||||||
async replaceStyle(newStyle) {
|
async replaceStyle(newStyle) {
|
||||||
|
const sameCode = styleSectionsEqual(newStyle, getModel());
|
||||||
|
if (!sameCode && !await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
dirty.clear();
|
dirty.clear();
|
||||||
// FIXME: avoid recreating all editors?
|
// FIXME: avoid recreating all editors?
|
||||||
await initSections(newStyle.sections, {replace: true});
|
if (!sameCode) {
|
||||||
|
await initSections(newStyle.sections, {replace: true});
|
||||||
|
}
|
||||||
Object.assign(style, newStyle);
|
Object.assign(style, newStyle);
|
||||||
editor.updateClass();
|
editor.updateClass();
|
||||||
updateMeta();
|
updateMeta();
|
||||||
|
@ -99,18 +106,14 @@ function SectionsEditor() {
|
||||||
updateLivePreview();
|
updateLivePreview();
|
||||||
},
|
},
|
||||||
|
|
||||||
async save() {
|
async saveImpl() {
|
||||||
if (!dirty.isDirty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let newStyle = getModel();
|
let newStyle = getModel();
|
||||||
if (!validate(newStyle)) {
|
if (!validate(newStyle)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newStyle = await API.styles.editSave(newStyle);
|
newStyle = await API.styles.editSave(newStyle);
|
||||||
destroyRemovedSections();
|
|
||||||
sessionStore.justEditedStyleId = newStyle.id;
|
sessionStore.justEditedStyleId = newStyle.id;
|
||||||
editor.replaceStyle(newStyle, false);
|
dirty.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollToEditor(cm) {
|
scrollToEditor(cm) {
|
||||||
|
@ -453,18 +456,6 @@ function SectionsEditor() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroyRemovedSections() {
|
|
||||||
for (let i = 0; i < sections.length;) {
|
|
||||||
if (!sections[i].removed) {
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
sections[i].destroy();
|
|
||||||
sections[i].el.remove();
|
|
||||||
sections.splice(i, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateMeta() {
|
function updateMeta() {
|
||||||
$('#name').value = style.customName || style.name || '';
|
$('#name').value = style.customName || style.name || '';
|
||||||
$('#enabled').checked = style.enabled !== false;
|
$('#enabled').checked = style.enabled !== false;
|
||||||
|
|
|
@ -61,8 +61,7 @@ function SourceEditor() {
|
||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async save() {
|
async saveImpl() {
|
||||||
if (!dirty.isDirty()) return;
|
|
||||||
const sourceCode = cm.getValue();
|
const sourceCode = cm.getValue();
|
||||||
try {
|
try {
|
||||||
const {customName, enabled, id} = style;
|
const {customName, enabled, id} = style;
|
||||||
|
@ -221,7 +220,6 @@ function SourceEditor() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: also confirm in sections-editor?
|
|
||||||
if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) {
|
if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) {
|
||||||
updateEnvironment();
|
updateEnvironment();
|
||||||
if (!sameCode) {
|
if (!sameCode) {
|
||||||
|
|
|
@ -195,7 +195,7 @@ self.parserlib = (() => {
|
||||||
'color-interpolation-filters': 'auto | sRGB | linearRGB',
|
'color-interpolation-filters': 'auto | sRGB | linearRGB',
|
||||||
'color-profile': 1,
|
'color-profile': 1,
|
||||||
'color-rendering': 'auto | optimizeSpeed | optimizeQuality',
|
'color-rendering': 'auto | optimizeSpeed | optimizeQuality',
|
||||||
'color-scheme': 'normal | [ light | dark ]+',
|
'color-scheme': 'normal | [ light | dark | <ident> ]+ && only?',
|
||||||
'column-count': '<integer> | auto',
|
'column-count': '<integer> | auto',
|
||||||
'column-fill': 'auto | balance',
|
'column-fill': 'auto | balance',
|
||||||
'column-gap': '<column-gap>',
|
'column-gap': '<column-gap>',
|
||||||
|
@ -522,6 +522,7 @@ self.parserlib = (() => {
|
||||||
'scroll-snap-type': 'none | [ x | y | block | inline | both ] [ mandatory | proximity ]?',
|
'scroll-snap-type': 'none | [ x | y | block | inline | both ] [ mandatory | proximity ]?',
|
||||||
|
|
||||||
'scrollbar-color': 'auto | dark | light | <color>{2}',
|
'scrollbar-color': 'auto | dark | light | <color>{2}',
|
||||||
|
'scrollbar-gutter': 'auto | [ [ stable | always ] && both-edges? && force? ] || match-parent',
|
||||||
'scrollbar-width': 'auto | thin | none',
|
'scrollbar-width': 'auto | thin | none',
|
||||||
'shape-inside': 'auto | outside-shape | [ <basic-shape> || shape-box ] | <image> | display',
|
'shape-inside': 'auto | outside-shape | [ <basic-shape> || shape-box ] | <image> | display',
|
||||||
'shape-rendering': 'auto | optimizeSpeed | crispEdges | geometricPrecision',
|
'shape-rendering': 'auto | optimizeSpeed | crispEdges | geometricPrecision',
|
||||||
|
@ -983,12 +984,12 @@ self.parserlib = (() => {
|
||||||
'matrix( <number>#{6} ) | ' +
|
'matrix( <number>#{6} ) | ' +
|
||||||
'matrix3d( <number>#{16} ) | ' +
|
'matrix3d( <number>#{16} ) | ' +
|
||||||
'perspective( <len0+> | none ) | ' +
|
'perspective( <len0+> | none ) | ' +
|
||||||
'rotate( <angle-or-0> ) | ' +
|
'rotate( <angle-or-0> | none ) | ' +
|
||||||
'rotate3d( <number>#{3} , <angle-or-0> ) | ' +
|
'rotate3d( <number>#{3} , <angle-or-0> ) | ' +
|
||||||
'rotateX( <angle-or-0> ) | ' +
|
'rotateX( <angle-or-0> ) | ' +
|
||||||
'rotateY( <angle-or-0> ) | ' +
|
'rotateY( <angle-or-0> ) | ' +
|
||||||
'rotateZ( <angle-or-0> ) | ' +
|
'rotateZ( <angle-or-0> ) | ' +
|
||||||
'scale( [ <num-pct> ]#{1,2} ) | ' +
|
'scale( [ <num-pct> ]#{1,2} | none ) | ' +
|
||||||
'scale3d( <num-pct>#{3} ) | ' +
|
'scale3d( <num-pct>#{3} ) | ' +
|
||||||
'scaleX( <num-pct> ) | ' +
|
'scaleX( <num-pct> ) | ' +
|
||||||
'scaleY( <num-pct> ) | ' +
|
'scaleY( <num-pct> ) | ' +
|
||||||
|
@ -996,7 +997,7 @@ self.parserlib = (() => {
|
||||||
'skew( <angle-or-0> [ , <angle-or-0> ]? ) | ' +
|
'skew( <angle-or-0> [ , <angle-or-0> ]? ) | ' +
|
||||||
'skewX( <angle-or-0> ) | ' +
|
'skewX( <angle-or-0> ) | ' +
|
||||||
'skewY( <angle-or-0> ) | ' +
|
'skewY( <angle-or-0> ) | ' +
|
||||||
'translate( <len-pct>#{1,2} ) | ' +
|
'translate( <len-pct>#{1,2} | none ) | ' +
|
||||||
'translate3d( <len-pct>#{2} , <length> ) | ' +
|
'translate3d( <len-pct>#{2} , <length> ) | ' +
|
||||||
'translateX( <len-pct> ) | ' +
|
'translateX( <len-pct> ) | ' +
|
||||||
'translateY( <len-pct> ) | ' +
|
'translateY( <len-pct> ) | ' +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user