Fix: allow live-preview to assign newest vars
This commit is contained in:
parent
e4dfb82e07
commit
b9cc8b8ca5
|
@ -71,6 +71,7 @@
|
||||||
* @param {Boolean=} _.checkDup
|
* @param {Boolean=} _.checkDup
|
||||||
* @param {Boolean=} _.metaOnly
|
* @param {Boolean=} _.metaOnly
|
||||||
* @param {Object} _.vars
|
* @param {Object} _.vars
|
||||||
|
* @param {Boolean=} _.assignVars
|
||||||
* @returns {Promise<{style, dup:Boolean?}>}
|
* @returns {Promise<{style, dup:Boolean?}>}
|
||||||
*/
|
*/
|
||||||
function build({
|
function build({
|
||||||
|
@ -78,20 +79,23 @@
|
||||||
checkDup,
|
checkDup,
|
||||||
metaOnly,
|
metaOnly,
|
||||||
vars,
|
vars,
|
||||||
|
assignVars = false,
|
||||||
}) {
|
}) {
|
||||||
return usercss.buildMeta(sourceCode)
|
return usercss.buildMeta(sourceCode)
|
||||||
.then(style =>
|
.then(style => {
|
||||||
Promise.all([
|
const findDup = checkDup || assignVars ? find(style) : null;
|
||||||
metaOnly ? style : doBuild(style),
|
return Promise.all([
|
||||||
checkDup ? find(style) : undefined
|
metaOnly ? style : doBuild(style, findDup),
|
||||||
])
|
findDup
|
||||||
)
|
]);
|
||||||
|
})
|
||||||
.then(([style, dup]) => ({style, dup}));
|
.then(([style, dup]) => ({style, dup}));
|
||||||
|
|
||||||
function doBuild(style) {
|
function doBuild(style, findDup) {
|
||||||
if (vars) {
|
if (vars || assignVars) {
|
||||||
const oldStyle = {usercssData: {vars}};
|
const getOld = vars ? Promise.resolve({usercssData: {vars}}) : findDup;
|
||||||
return usercss.assignVars(style, oldStyle)
|
return getOld
|
||||||
|
.then(oldStyle => usercss.assignVars(style, oldStyle))
|
||||||
.then(() => usercss.buildCode(style));
|
.then(() => usercss.buildCode(style));
|
||||||
}
|
}
|
||||||
return usercss.buildCode(style);
|
return usercss.buildCode(style);
|
||||||
|
|
|
@ -83,7 +83,7 @@ function createSourceEditor(style) {
|
||||||
function preprocess(style) {
|
function preprocess(style) {
|
||||||
return API.buildUsercss({
|
return API.buildUsercss({
|
||||||
sourceCode: style.sourceCode,
|
sourceCode: style.sourceCode,
|
||||||
vars: style.usercssData.vars
|
assignVars: true
|
||||||
})
|
})
|
||||||
.then(({style: newStyle}) => {
|
.then(({style: newStyle}) => {
|
||||||
delete newStyle.enabled;
|
delete newStyle.enabled;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user