Skip to content

Commit

Permalink
make delaying of importCssString more reliable and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Sep 29, 2021
1 parent 2792d45 commit 910c09a
Show file tree
Hide file tree
Showing 56 changed files with 87 additions and 64 deletions.
13 changes: 8 additions & 5 deletions Makefile.dryice.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,17 @@ function buildAce(options, callback) {
sanityCheck(options, callback);
if (options.noconflict && !options.compress)
buildTypes();
extractCss(options);

extractCss(options, function() {
if (callback)
return callback();
console.log("Finished building " + getTargetDir(options));

if (callback)
return callback();
console.log("Finished building " + getTargetDir(options));
});
}
}

function extractCss(options) {
function extractCss(options, callback) {
var dir = BUILD_DIR + "/src" + (options.noconflict ? "-noconflict" : "");
var filenames = fs.readdirSync(dir);
var css = "";
Expand Down Expand Up @@ -497,6 +499,7 @@ function extractCss(options) {
outputFile: "ace.css"
}, function() {
saveImages();
callback();
});

function detectCssImports(code) {
Expand Down
16 changes: 16 additions & 0 deletions lib/ace/ace_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if (typeof process !== "undefined") {
define(function(require, exports, module) {
"use strict";

var dom = require("./lib/dom");
var ace = require("./ace");
var assert = require("./test/assertions");

Expand Down Expand Up @@ -116,6 +117,21 @@ module.exports = {

done();
});
},
"test: useStrictCSP": function() {
ace.config.set("useStrictCSP", undefined);
function getStyleNode() {
return document.getElementById("test.css");
}
assert.ok(!getStyleNode());
dom.importCssString("test{}", "test.css", false);
assert.ok(!getStyleNode());

ace.config.set("useStrictCSP", true);
assert.ok(!getStyleNode());

ace.config.set("useStrictCSP", false);
assert.ok(getStyleNode());
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/ace/autocomplete/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ dom.importCssString("\
line-height: 1.4;\
background: #25282c;\
color: #c1c1c1;\
}", "autocompletion.css");
}", "autocompletion.css", false);

exports.AcePopup = AcePopup;
exports.$singleLineEditor = $singleLineEditor;
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var options = {
$moduleUrls: {},
loadWorkerFromBlob: true,
sharedPopups: false,
useStrictCSP: false
useStrictCSP: null
};

exports.get = function(key) {
Expand Down
1 change: 1 addition & 0 deletions lib/ace/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (typeof process !== "undefined") {
define(function(require, exports, module) {
"use strict";

var dom = require("./config");
var config = require("./config");
var assert = require("./test/assertions");

Expand Down
2 changes: 1 addition & 1 deletion lib/ace/ext/code_lens.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ dom.importCssString("\
.ace_dark > .ace_codeLens > a:hover {\
color: #4e94ce;\
}\
", "");
", "codelense.css", false);

});
2 changes: 1 addition & 1 deletion lib/ace/ext/error_marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,6 @@ dom.importCssString("\
border-left-color: transparent!important;\
top: -5px;\
}\
", "");
", "error_marker.css", false);

});
2 changes: 1 addition & 1 deletion lib/ace/ext/menu_tools/overlay_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ define(function(require, exports, module) {
'use strict';
var dom = require("../../lib/dom");
var cssText = require("../../requirejs/text!./settings_menu.css");
dom.importCssString(cssText);
dom.importCssString(cssText, "settings_menu.css", false);

/**
* Generates an overlay for displaying menus. The overlay is an absolutely
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/ext/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ dom.importCssString(".ace_prompt_container {\
background: white;\
border-radius: 2px;\
box-shadow: 0px 2px 3px 0px #555;\
}");
}", "promtp.css", false);


exports.prompt = prompt;
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/ext/searchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var keyUtil = require("../lib/keys");

var MAX_COUNT = 999;

dom.importCssString(searchboxCss, "ace_searchbox");
dom.importCssString(searchboxCss, "ace_searchbox", false);

var SearchBox = function(editor, range, showReplaceForm) {
var div = dom.createElement("div");
Expand Down
4 changes: 2 additions & 2 deletions lib/ace/incremental_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ exports.IncrementalSearch = IncrementalSearch;
**/

var dom = require('./lib/dom');
dom.importCssString && dom.importCssString("\
dom.importCssString("\
.ace_marker-layer .ace_isearch-result {\
position: absolute;\
z-index: 6;\
Expand All @@ -282,7 +282,7 @@ div.ace_isearch-result {\
.ace_dark div.ace_isearch-result {\
background-color: rgb(100, 110, 160);\
box-shadow: 0 0 4px rgb(80, 90, 140);\
}", "incremental-search-highlighting");
}", "incremental-search-highlighting", false);

// support for default keyboard handler
var commands = require("./commands/command_manager");
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/keyboard/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
width: 20em;\
color: inherit;\
font-family: monospace;\
}", "vimMode");
}", "vimMode", false);
(function() {
function dialogDiv(cm, template, bottom) {
var wrap = cm.ace.container;
Expand Down
10 changes: 5 additions & 5 deletions lib/ace/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,21 @@ var strictCSP;
var cssCache = [];
exports.useStrictCSP = function(value) {
strictCSP = value;
if (value == false) insertPendingStyles();
else if (!cssCache) cssCache = [];
};

function insertPendingStyles() {
var cache = cssCache;
cssCache = null;
cache.forEach(function(item) {
cache && cache.forEach(function(item) {
importCssString(item[0], item[1]);
});
}

function importCssString(cssText, id, target) {
if (typeof document == "undefined")
return;
if (cssCache) {
if (target) {
insertPendingStyles();
Expand Down Expand Up @@ -272,10 +276,6 @@ exports.scrollbarWidth = function(document) {
return noScrollbar-withScrollbar;
};

if (typeof document == "undefined") {
exports.importCssString = function() {};
}

exports.computedStyle = function(element, style) {
return window.getComputedStyle(element, "") || {};
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/occur.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ dom.importCssString(".ace_occur-highlight {\n\
.ace_dark .ace_occur-highlight {\n\
background-color: rgb(80, 140, 85);\n\
box-shadow: 0 0 4px rgb(60, 120, 70);\n\
}\n", "incremental-occur-highlighting");
}\n", "incremental-occur-highlighting", false);

exports.Occur = Occur;

Expand Down
5 changes: 3 additions & 2 deletions lib/ace/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

define(function(require, exports, module) {
"use strict";
var dom = require("./lib/dom");
var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var lang = require("./lib/lang");
Expand Down Expand Up @@ -1027,14 +1028,14 @@ var moveRelative = function(point, start) {
};


require("./lib/dom").importCssString("\
dom.importCssString("\
.ace_snippet-marker {\
-moz-box-sizing: border-box;\
box-sizing: border-box;\
background: rgba(194, 193, 208, 0.09);\
border: 1px dotted rgba(211, 208, 235, 0.62);\
position: absolute;\
}");
}", "snippets.css", false);

exports.snippetManager = new SnippetManager();

Expand Down
2 changes: 1 addition & 1 deletion lib/ace/test/mockdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function Node(name) {
if (!isAMatch && !skip) return false;
node = node.parentNode;
}
}
};
this.closest = function(s) {
var el = this;
do {
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/theme/ambiance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ exports.cssClass = "ace-ambiance";
exports.cssText = require("../requirejs/text!./ambiance.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);

});
2 changes: 1 addition & 1 deletion lib/ace/theme/chaos.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ exports.cssClass = "ace-chaos";
exports.cssText = require("../requirejs/text!./chaos.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);

});
2 changes: 1 addition & 1 deletion lib/ace/theme/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-chrome";
exports.cssText = require("../requirejs/text!./chrome.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/clouds.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-clouds";
exports.cssText = require("../requirejs/text!./clouds.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/clouds_midnight.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-clouds-midnight";
exports.cssText = require("../requirejs/text!./clouds_midnight.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/cobalt.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-cobalt";
exports.cssText = require("../requirejs/text!./cobalt.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/crimson_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssText = require("../requirejs/text!./crimson_editor.css");
exports.cssClass = "ace-crimson-editor";

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/dawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-dawn";
exports.cssText = require("../requirejs/text!./dawn.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/dracula.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ exports.cssText = require("../requirejs/text!./dracula.css");
exports.$selectionColorConflict = true;

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/dreamweaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ exports.cssClass = "ace-dreamweaver";
exports.cssText = require("../requirejs/text!./dreamweaver.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/eclipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ exports.cssText = require("../requirejs/text!./eclipse.css");
exports.cssClass = "ace-eclipse";

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-github";
exports.cssText = require("../requirejs/text!./github.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/gob.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-gob";
exports.cssText = require("../requirejs/text!./gob.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/gruvbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ exports.cssClass = "ace-gruvbox";
exports.cssText = require("../requirejs/text!./gruvbox.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);

});
2 changes: 1 addition & 1 deletion lib/ace/theme/idle_fingers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-idle-fingers";
exports.cssText = require("../requirejs/text!./idle_fingers.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/iplastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ exports.cssClass = "ace-iplastic";
exports.cssText = require("../requirejs/text!./iplastic.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/katzenmilch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-katzenmilch";
exports.cssText = require("../requirejs/text!./katzenmilch.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/kr_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-kr-theme";
exports.cssText = require("../requirejs/text!./kr_theme.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/kuroir.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-kuroir";
exports.cssText = require("../requirejs/text!./kuroir.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/merbivore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-merbivore";
exports.cssText = require("../requirejs/text!./merbivore.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/merbivore_soft.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-merbivore-soft";
exports.cssText = require("../requirejs/text!./merbivore_soft.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/mono_industrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-mono-industrial";
exports.cssText = require("../requirejs/text!./mono_industrial.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
2 changes: 1 addition & 1 deletion lib/ace/theme/monokai.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ exports.cssClass = "ace-monokai";
exports.cssText = require("../requirejs/text!./monokai.css");

var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
dom.importCssString(exports.cssText, exports.cssClass, false);
});
Loading

0 comments on commit 910c09a

Please sign in to comment.