This commit is contained in:
liaoxuezhi 2020-07-22 23:11:59 +08:00
commit 9f4921fb5c
9 changed files with 596 additions and 625 deletions

View File

@ -132,11 +132,13 @@ module.exports = function (ret, pack, settings, opt) {
} catch (e) {
d = (/((?:https?|file)\:.*)$/.test(e.stack) && RegExp.$1).replace(/\\/[^\\/]*$/, '');
}
${contents
.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function (_, quote, value) {
return `"url": d + ${quote}${value.substring(1)}${quote}`;
})
.replace(/require\.resourceMap/, 'amis.require.resourceMap')}
${contents.replace(/\"url\"\s*\:\s*('|")(\.\/.*)\1/g, function (
_,
quote,
value
) {
return `"url": d + ${quote}${value.substring(1)}${quote}`;
})}
})()`;
}

View File

@ -62,7 +62,7 @@
})();
/* @require ./index.jsx 标记为同步依赖,提前加载 */
require(['./index.jsx'], function (app) {
amis.require(['./index.jsx'], function (app) {
var initialState = {};
app.bootstrap(document.getElementById('root'), initialState);
});

View File

@ -0,0 +1,235 @@
// 这是个特殊的方法,请看考 mod.js 里面的实现。
export function __mod__async__load(callback: (exports: any) => void) {
// @ts-ignore
const monacoLoader = __uri('monaco-editor/min/vs/loader.js');
// @ts-ignore
const script = amis.require.loadJs(filterUrl(monacoLoader));
script.onload = () => onLoad(window.require, callback);
}
function __uri(url: string) {
return url;
}
// 用于发布 sdk 版本的时候替换,因为不确定 sdk 版本怎么部署,而 worker 地址路径不可知。
// 所以会被 fis3 替换成取相对的代码。
function filterUrl(url: string) {
return url;
}
function onLoad(req: any, callback: (result: any) => void) {
const config = {
'vs/nls': {
availableLanguages: {
'*': 'zh-cn'
}
},
'paths': {
'vs': __uri('monaco-editor/min/vs/editor/editor.main.js').replace(
/\/vs\/.*$/,
''
),
'vs/base/worker/workerMain': __uri(
'monaco-editor/min/vs/base/worker/workerMain.js'
),
'vs/basic-languages/apex/apex': __uri(
'monaco-editor/min/vs/basic-languages/apex/apex'
),
'vs/basic-languages/azcli/azcli': __uri(
'monaco-editor/min/vs/basic-languages/azcli/azcli'
),
'vs/basic-languages/clojure/clojure': __uri(
'monaco-editor/min/vs/basic-languages/clojure/clojure'
),
'vs/basic-languages/bat/bat': __uri(
'monaco-editor/min/vs/basic-languages/bat/bat'
),
'vs/basic-languages/coffee/coffee': __uri(
'monaco-editor/min/vs/basic-languages/coffee/coffee'
),
'vs/basic-languages/cpp/cpp': __uri(
'monaco-editor/min/vs/basic-languages/cpp/cpp'
),
'vs/basic-languages/csharp/csharp': __uri(
'monaco-editor/min/vs/basic-languages/csharp/csharp'
),
'vs/basic-languages/css/css': __uri(
'monaco-editor/min/vs/basic-languages/css/css'
),
'vs/basic-languages/dockerfile/dockerfile': __uri(
'monaco-editor/min/vs/basic-languages/dockerfile/dockerfile'
),
'vs/basic-languages/fsharp/fsharp': __uri(
'monaco-editor/min/vs/basic-languages/fsharp/fsharp'
),
'vs/basic-languages/go/go': __uri(
'monaco-editor/min/vs/basic-languages/go/go'
),
'vs/basic-languages/handlebars/handlebars': __uri(
'monaco-editor/min/vs/basic-languages/handlebars/handlebars'
),
'vs/basic-languages/html/html': __uri(
'monaco-editor/min/vs/basic-languages/html/html'
),
'vs/basic-languages/ini/ini': __uri(
'monaco-editor/min/vs/basic-languages/ini/ini'
),
'vs/basic-languages/java/java': __uri(
'monaco-editor/min/vs/basic-languages/java/java'
),
'vs/basic-languages/javascript/javascript': __uri(
'monaco-editor/min/vs/basic-languages/javascript/javascript'
),
'vs/basic-languages/less/less': __uri(
'monaco-editor/min/vs/basic-languages/less/less'
),
'vs/basic-languages/lua/lua': __uri(
'monaco-editor/min/vs/basic-languages/lua/lua'
),
'vs/basic-languages/markdown/markdown': __uri(
'monaco-editor/min/vs/basic-languages/markdown/markdown'
),
'vs/basic-languages/msdax/msdax': __uri(
'monaco-editor/min/vs/basic-languages/msdax/msdax'
),
'vs/basic-languages/objective-c/objective-c': __uri(
'monaco-editor/min/vs/basic-languages/objective-c/objective-c'
),
'vs/basic-languages/php/php': __uri(
'monaco-editor/min/vs/basic-languages/php/php'
),
'vs/basic-languages/postiats/postiats': __uri(
'monaco-editor/min/vs/basic-languages/postiats/postiats'
),
'vs/basic-languages/powershell/powershell': __uri(
'monaco-editor/min/vs/basic-languages/powershell/powershell'
),
'vs/basic-languages/pug/pug': __uri(
'monaco-editor/min/vs/basic-languages/pug/pug'
),
'vs/basic-languages/python/python': __uri(
'monaco-editor/min/vs/basic-languages/python/python'
),
'vs/basic-languages/r/r': __uri(
'monaco-editor/min/vs/basic-languages/r/r'
),
'vs/basic-languages/razor/razor': __uri(
'monaco-editor/min/vs/basic-languages/razor/razor'
),
'vs/basic-languages/redis/redis': __uri(
'monaco-editor/min/vs/basic-languages/redis/redis'
),
'vs/basic-languages/redshift/redshift': __uri(
'monaco-editor/min/vs/basic-languages/redshift/redshift'
),
'vs/basic-languages/ruby/ruby': __uri(
'monaco-editor/min/vs/basic-languages/ruby/ruby'
),
'vs/basic-languages/rust/rust': __uri(
'monaco-editor/min/vs/basic-languages/rust/rust'
),
'vs/basic-languages/sb/sb': __uri(
'monaco-editor/min/vs/basic-languages/sb/sb'
),
'vs/basic-languages/scheme/scheme': __uri(
'monaco-editor/min/vs/basic-languages/scheme/scheme'
),
'vs/basic-languages/scss/scss': __uri(
'monaco-editor/min/vs/basic-languages/scss/scss'
),
'vs/basic-languages/shell/shell': __uri(
'monaco-editor/min/vs/basic-languages/shell/shell'
),
'vs/basic-languages/solidity/solidity': __uri(
'monaco-editor/min/vs/basic-languages/solidity/solidity'
),
'vs/basic-languages/sql/sql': __uri(
'monaco-editor/min/vs/basic-languages/sql/sql'
),
'vs/basic-languages/st/st': __uri(
'monaco-editor/min/vs/basic-languages/st/st'
),
'vs/basic-languages/swift/swift': __uri(
'monaco-editor/min/vs/basic-languages/swift/swift'
),
'vs/basic-languages/typescript/typescript': __uri(
'monaco-editor/min/vs/basic-languages/typescript/typescript'
),
'vs/basic-languages/vb/vb': __uri(
'monaco-editor/min/vs/basic-languages/vb/vb'
),
'vs/basic-languages/xml/xml': __uri(
'monaco-editor/min/vs/basic-languages/xml/xml'
),
'vs/basic-languages/yaml/yaml': __uri(
'monaco-editor/min/vs/basic-languages/yaml/yaml'
),
'vs/editor/editor.main': __uri(
'monaco-editor/min/vs/editor/editor.main.js'
),
'vs/editor/editor.main.css': __uri(
'monaco-editor/min/vs/editor/editor.main.css'
),
'vs/editor/editor.main.nls': __uri(
'monaco-editor/min/vs/editor/editor.main.nls.js'
),
'vs/editor/editor.main.nls.zh-cn': __uri(
'monaco-editor/min/vs/editor/editor.main.nls.zh-cn.js'
),
// 'vs/editor/contrib/suggest/media/String_16x.svg': __uri('monaco-editor/min/vs/editor/contrib/suggest/media/String_16x.svg'),
// 'vs/editor/contrib/suggest/media/String_inverse_16x.svg': __uri('monaco-editor/min/vs/editor/contrib/suggest/media/String_inverse_16x.svg'),
// 'vs/editor/standalone/browser/quickOpen/symbol-sprite.svg': __uri('monaco-editor/min/vs/editor/standalone/browser/quickOpen/symbol-sprite.svg'),
'vs/language/typescript/tsMode': __uri(
'monaco-editor/min/vs/language/typescript/tsMode.js'
),
// 'vs/language/typescript/lib/typescriptServices': __uri('monaco-editor/min/vs/language/typescript/lib/typescriptServices.js'),
'vs/language/typescript/tsWorker': __uri(
'monaco-editor/min/vs/language/typescript/tsWorker.js'
),
'vs/language/json/jsonMode': __uri(
'monaco-editor/min/vs/language/json/jsonMode.js'
),
'vs/language/json/jsonWorker': __uri(
'monaco-editor/min/vs/language/json/jsonWorker.js'
),
'vs/language/html/htmlMode': __uri(
'monaco-editor/min/vs/language/html/htmlMode.js'
),
'vs/language/html/htmlWorker': __uri(
'monaco-editor/min/vs/language/html/htmlWorker.js'
),
'vs/language/css/cssMode': __uri(
'monaco-editor/min/vs/language/css/cssMode.js'
),
'vs/language/css/cssWorker': __uri(
'monaco-editor/min/vs/language/css/cssWorker.js'
)
}
};
Object.keys(config.paths).forEach((key: keyof typeof config.paths) => {
config.paths[key] = filterUrl(config.paths[key].replace(/\.js$/, ''));
});
req.config(config);
if (/^(https?:)?\/\//.test(config.paths.vs)) {
(window as any).MonacoEnvironment = {
getWorkerUrl: function () {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: '${config.paths.vs}',
paths: ${JSON.stringify(config.paths)}
};
importScripts('${__uri(
'monaco-editor/min/vs/base/worker/workerMain.js'
)}');`)}`;
}
};
} else {
delete (window as any).MonacoEnvironment;
}
req(['vs/editor/editor.main'], function (ret: any) {
callback(ret);
});
}

View File

@ -1,287 +1,307 @@
/**
* @file: mod.js
* @author fis
* ver: 1.0.13
* update: 2016/01/27
* https://github.com/fex-team/mod
* @file 模块加载器改成私有化的了慎用
*/
var require;
/* eslint-disable no-unused-vars */
var define;
/* eslint-disable */
(function (global) {
var require, define;
var amis = window.amis || {};
// 避免重复加载而导致已定义模块丢失
if (amis.require) {
return;
}
// 避免重复加载而导致已定义模块丢失
if (require) {
return;
var head = document.getElementsByTagName('head')[0];
var loadingMap = {};
var factoryMap = {};
var modulesMap = {};
var scriptsMap = {};
var resMap = {};
var pkgMap = {};
var createScripts = function (queues, onerror) {
var docFrag = document.createDocumentFragment();
for (var i = 0, len = queues.length; i < len; i++) {
var id = queues[i].id;
var url = queues[i].url;
if (url in scriptsMap) {
continue;
}
scriptsMap[url] = true;
var script = document.createElement('script');
if (onerror) {
(function (script, id) {
var tid = setTimeout(function () {
onerror(id);
}, require.timeout);
script.onerror = function () {
clearTimeout(tid);
onerror(id);
};
var onload = function () {
clearTimeout(tid);
};
if ('onload' in script) {
script.onload = onload;
} else {
script.onreadystatechange = function () {
if (
this.readyState === 'loaded' ||
this.readyState === 'complete'
) {
onload();
}
};
}
})(script, id);
}
script.type = 'text/javascript';
script.src = url;
docFrag.appendChild(script);
}
var head = document.getElementsByTagName('head')[0];
var loadingMap = {};
var factoryMap = {};
var modulesMap = {};
var scriptsMap = {};
var resMap = {};
var pkgMap = {};
head.appendChild(docFrag);
};
var createScripts = function (queues, onerror) {
var loadScripts = function (ids, callback, onerror) {
var queues = [];
for (var i = 0, len = ids.length; i < len; i++) {
var id = ids[i];
var queue = loadingMap[id] || (loadingMap[id] = []);
queue.push(callback);
var docFrag = document.createDocumentFragment();
//
// resource map query
//
var res = resMap[id] || resMap[id + '.js'] || {};
var pkg = res.pkg;
var url;
for (var i = 0, len = queues.length; i < len; i++) {
var id = queues[i].id;
var url = queues[i].url;
if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri;
} else {
url = res.url || res.uri || id;
}
if (url in scriptsMap) {
continue;
}
queues.push({
id: id,
url: url
});
}
scriptsMap[url] = true;
createScripts(queues, onerror);
};
var script = document.createElement('script');
if (onerror) {
(function (script, id) {
var tid = setTimeout(function () {
onerror(id);
}, require.timeout);
var runQueue = function (id) {
var queue = loadingMap[id];
if (queue) {
for (var i = 0, n = queue.length; i < n; i++) {
queue[i]();
}
delete loadingMap[id];
}
};
script.onerror = function () {
clearTimeout(tid);
onerror(id);
};
define = function (id, factory) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
var onload = function () {
clearTimeout(tid);
};
if ('onload' in script) {
script.onload = onload;
}
else {
script.onreadystatechange = function () {
if (this.readyState === 'loaded' || this.readyState === 'complete') {
onload();
}
};
}
})(script, id);
}
script.type = 'text/javascript';
script.src = url;
docFrag.appendChild(script);
if (~factory.toString().indexOf('__mod__async__load')) {
var mod = {exports: {}};
factoryMap[id] = {
deffer: true,
callbacks: [],
loaded: false,
load: function () {}
};
factory.apply(mod, [require, mod.exports, mod]);
var load = mod.exports.__mod__async__load;
factoryMap[id].load = function () {
if (this.loaded) {
return;
}
this.loaded = true;
head.appendChild(docFrag);
};
var loadScripts = function (ids, callback, onerror) {
var queues = [];
for (var i = 0, len = ids.length; i < len; i++) {
var id = ids[i];
var queue = loadingMap[id] || (loadingMap[id] = []);
queue.push(callback);
//
// resource map query
//
var res = resMap[id] || resMap[id + '.js'] || {};
var pkg = res.pkg;
var url;
if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri;
}
else {
url = res.url || res.uri || id;
}
queues.push({
id: id,
url: url
});
}
createScripts(queues, onerror);
};
define = function (id, factory) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
var queue = loadingMap[id];
if (queue) {
for (var i = 0, n = queue.length; i < n; i++) {
queue[i]();
}
delete loadingMap[id];
}
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax.
if (id && id.splice) {
return require.async.apply(this, arguments);
}
id = require.alias(id);
var mod = modulesMap[id];
if (mod) {
return mod.exports;
}
//
// init module
//
var factory = factoryMap[id];
if (!factory) {
throw '[ModJS] Cannot find module `' + id + '`';
}
mod = modulesMap[id] = {
exports: {}
};
//
// factory: function OR value
//
var ret = (typeof factory === 'function') ? factory.apply(mod, [require, mod.exports, mod]) : factory;
if (ret) {
mod.exports = ret;
}
return mod.exports;
};
require.async = function (names, onload, onerror) {
if (typeof names === 'string') {
names = [names];
}
var needMap = {};
var needNum = 0;
var needLoad = [];
function findNeed(depArr) {
var child;
for (var i = 0, n = depArr.length; i < n; i++) {
//
// skip loading or loaded
//
var dep = require.alias(depArr[i]);
if (dep in needMap) {
continue;
}
needMap[dep] = true;
if (dep in factoryMap) {
// check whether loaded resource's deps is loaded or not
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
continue;
}
needLoad.push(dep);
needNum++;
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
}
}
function updateNeed() {
if (0 === needNum--) {
var args = [];
for (var i = 0, n = names.length; i < n; i++) {
args[i] = require(names[i]);
}
onload && onload.apply(global, args);
}
}
findNeed(names);
loadScripts(needLoad, updateNeed, onerror);
updateNeed();
};
require.ensure = function (names, callback) {
require.async(names, function () {
callback && callback.call(this, require);
load(function (ret) {
var callbacks = factoryMap[id].callbacks;
factoryMap[id] = function () {
return ret;
};
callbacks.forEach(function (fn) {
fn();
});
runQueue(id);
});
};
if (loadingMap[id] && loadingMap[id].length) {
factoryMap[id].load();
}
} else {
runQueue(id);
}
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax.
if (id && id.splice) {
return require.async.apply(this, arguments);
}
id = require.alias(id);
var mod = modulesMap[id];
if (mod) {
return mod.exports;
}
//
// init module
//
var factory = factoryMap[id];
if (!factory) {
throw '[ModJS] Cannot find module `' + id + '`';
}
mod = modulesMap[id] = {
exports: {}
};
require.resourceMap = function (obj) {
var k;
var col;
//
// factory: function OR value
//
var ret =
typeof factory === 'function'
? factory.apply(mod, [require, mod.exports, mod])
: factory;
// merge `res` & `pkg` fields
col = obj.res;
for (k in col) {
if (col.hasOwnProperty(k)) {
resMap[k] = col[k];
}
if (ret) {
mod.exports = ret;
}
return mod.exports;
};
require.async = function (names, onload, onerror) {
if (typeof names === 'string') {
names = [names];
}
var needMap = {};
var needNum = 0;
var needLoad = [];
function findNeed(depArr) {
var child;
for (var i = 0, n = depArr.length; i < n; i++) {
//
// skip loading or loaded
//
var dep = require.alias(depArr[i]);
if (dep in needMap) {
continue;
}
col = obj.pkg;
for (k in col) {
if (col.hasOwnProperty(k)) {
pkgMap[k] = col[k];
}
}
};
needMap[dep] = true;
require.loadJs = function (url) {
if (url in scriptsMap) {
return;
if (dep in factoryMap) {
if (factoryMap[dep] && factoryMap[dep].deffer) {
needNum++;
factoryMap[dep].callbacks.push(updateNeed);
factoryMap[dep].load();
}
// check whether loaded resource's deps is loaded or not
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
continue;
}
scriptsMap[url] = true;
needLoad.push(dep);
needNum++;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
};
require.loadCss = function (cfg) {
if (cfg.content) {
var sty = document.createElement('style');
sty.type = 'text/css';
if (sty.styleSheet) { // IE
sty.styleSheet.cssText = cfg.content;
}
else {
sty.innerHTML = cfg.content;
}
head.appendChild(sty);
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
else if (cfg.url) {
var link = document.createElement('link');
link.href = cfg.url;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
}
function updateNeed() {
if (0 === needNum--) {
var args = [];
for (var i = 0, n = names.length; i < n; i++) {
args[i] = require(names[i]);
}
};
onload && onload.apply(global, args);
}
}
require.alias = function (id) {
return id.replace(/\.js$/i, '');
};
findNeed(names);
loadScripts(needLoad, updateNeed, onerror);
updateNeed();
};
require.timeout = 5000;
require.ensure = function (names, callback) {
require.async(names, function () {
callback && callback.call(this, require);
});
};
require.resourceMap = function (obj) {
var k;
var col;
// merge `res` & `pkg` fields
col = obj.res;
for (k in col) {
if (col.hasOwnProperty(k)) {
resMap[k] = col[k];
}
}
col = obj.pkg;
for (k in col) {
if (col.hasOwnProperty(k)) {
pkgMap[k] = col[k];
}
}
};
require.loadJs = function (url) {
if (url in scriptsMap) {
return;
}
scriptsMap[url] = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
return script;
};
require.alias = function (id) {
return id.replace(/\.js$/i, '');
};
require.timeout = 5000;
amis.require = require;
amis.define = define;
window.amis = amis;
// window.require = window.require || require;
})(this);

View File

@ -1,265 +0,0 @@
/**
* @file mod-sandbox.js.
*/
/* eslint-disable */
(function (global) {
var require, define;
var amis = window.amis || {};
// 避免重复加载而导致已定义模块丢失
if (amis.require) {
return;
}
var head = document.getElementsByTagName('head')[0];
var loadingMap = {};
var factoryMap = {};
var modulesMap = {};
var scriptsMap = {};
var resMap = {};
var pkgMap = {};
var createScripts = function (queues, onerror) {
var docFrag = document.createDocumentFragment();
for (var i = 0, len = queues.length; i < len; i++) {
var id = queues[i].id;
var url = queues[i].url;
if (url in scriptsMap) {
continue;
}
scriptsMap[url] = true;
var script = document.createElement('script');
if (onerror) {
(function (script, id) {
var tid = setTimeout(function () {
onerror(id);
}, require.timeout);
script.onerror = function () {
clearTimeout(tid);
onerror(id);
};
var onload = function () {
clearTimeout(tid);
};
if ('onload' in script) {
script.onload = onload;
} else {
script.onreadystatechange = function () {
if (
this.readyState === 'loaded' ||
this.readyState === 'complete'
) {
onload();
}
};
}
})(script, id);
}
script.type = 'text/javascript';
script.src = url;
docFrag.appendChild(script);
}
head.appendChild(docFrag);
};
var loadScripts = function (ids, callback, onerror) {
var queues = [];
for (var i = 0, len = ids.length; i < len; i++) {
var id = ids[i];
var queue = loadingMap[id] || (loadingMap[id] = []);
queue.push(callback);
//
// resource map query
//
var res = resMap[id] || resMap[id + '.js'] || {};
var pkg = res.pkg;
var url;
if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri;
} else {
url = res.url || res.uri || id;
}
queues.push({
id: id,
url: url
});
}
createScripts(queues, onerror);
};
define = function (id, factory) {
id = id.replace(/\.js$/i, '');
factoryMap[id] = factory;
var queue = loadingMap[id];
if (queue) {
for (var i = 0, n = queue.length; i < n; i++) {
queue[i]();
}
delete loadingMap[id];
}
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax.
if (id && id.splice) {
return require.async.apply(this, arguments);
}
id = require.alias(id);
var mod = modulesMap[id];
if (mod) {
return mod.exports;
}
//
// init module
//
var factory = factoryMap[id];
if (!factory) {
throw '[ModJS] Cannot find module `' + id + '`';
}
mod = modulesMap[id] = {
exports: {}
};
//
// factory: function OR value
//
var ret =
typeof factory === 'function'
? factory.apply(mod, [require, mod.exports, mod])
: factory;
if (ret) {
mod.exports = ret;
}
return mod.exports;
};
require.async = function (names, onload, onerror) {
if (typeof names === 'string') {
names = [names];
}
var needMap = {};
var needNum = 0;
var needLoad = [];
function findNeed(depArr) {
var child;
for (var i = 0, n = depArr.length; i < n; i++) {
//
// skip loading or loaded
//
var dep = require.alias(depArr[i]);
if (dep in needMap) {
continue;
}
needMap[dep] = true;
if (dep in factoryMap) {
// check whether loaded resource's deps is loaded or not
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
continue;
}
needLoad.push(dep);
needNum++;
child = resMap[dep] || resMap[dep + '.js'];
if (child && 'deps' in child) {
findNeed(child.deps);
}
}
}
function updateNeed() {
if (0 === needNum--) {
var args = [];
for (var i = 0, n = names.length; i < n; i++) {
args[i] = require(names[i]);
}
onload && onload.apply(global, args);
}
}
findNeed(names);
loadScripts(needLoad, updateNeed, onerror);
updateNeed();
};
require.ensure = function (names, callback) {
require.async(names, function () {
callback && callback.call(this, require);
});
};
require.resourceMap = function (obj) {
var k;
var col;
// merge `res` & `pkg` fields
col = obj.res;
for (k in col) {
if (col.hasOwnProperty(k)) {
resMap[k] = col[k];
}
}
col = obj.pkg;
for (k in col) {
if (col.hasOwnProperty(k)) {
pkgMap[k] = col[k];
}
}
};
require.loadJs = function (url) {
if (url in scriptsMap) {
return;
}
scriptsMap[url] = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
};
require.alias = function (id) {
return id.replace(/\.js$/i, '');
};
require.timeout = 5000;
amis.require = require;
amis.define = define;
window.amis = amis;
// window.require = window.require || require;
})(this);

View File

@ -10,7 +10,7 @@
<!--STYLE_PLACEHOLDER-->
</head>
<body>
<script data-loader src="./sdk-mod.js"></script>
<script data-loader src="./mod.js"></script>
<script>
/* @require "./embed.tsx" */
/* @require "./loader" */

View File

@ -8,6 +8,27 @@ const parserMarkdown = require('./build/md-parser');
fis.get('project.ignore').push('public/**', 'gh-pages/**', '.*/**');
// 配置只编译哪些文件。
const Resource = fis.require('postpackager-loader/lib/resource.js');
Resource.extend({
buildResourceMap: function () {
return 'amis.' + this.__super();
},
calculate: function () {
this.__super.apply(this);
// 标记这个文件,肯定是异步资源,即便是同步加载了。
Object.keys(this.loaded).forEach(id => {
const file = this.getFileById(id);
if (file && file.subpath === '/examples/loadMonacoEditor.ts') {
this.loaded[id] = true;
}
});
}
});
fis.set('project.files', [
'scss/**.scss',
'/examples/*.html',
@ -69,6 +90,15 @@ fis.match('tinymce/plugins/*/index.js', {
ignoreDependencies: false
});
fis.match(/(?:flv\.js)/, {
ignoreDependencies: true
});
fis.match('monaco-editor/min/**.js', {
isMod: false,
ignoreDependencies: true
});
fis.match('/docs/**.md', {
rExt: 'js',
parser: [
@ -103,14 +133,24 @@ fis.on('compile:parser', function (file) {
}
});
fis.match('monaco-editor/esm/**.js', {
parser: fis.plugin('typescript', {
importHelpers: true,
esModuleInterop: true,
experimentalDecorators: true,
sourceMap: false
}),
preprocessor: fis.plugin('js-require-css')
fis.on('compile:optimizer', function (file) {
if (file.isJsLike && file.isMod) {
var contents = file.getContent();
if (
typeof contents === 'string' &&
contents.substring(0, 7) === 'define('
) {
contents = 'amis.' + contents;
contents = contents.replace(
'function(require, exports, module)',
'function(require, exports, module, define)'
);
file.setContent(contents);
}
}
});
fis.match('{*.ts,*.jsx,*.tsx,/src/**.js,/src/**.ts}', {
@ -145,22 +185,14 @@ fis.hook('node_modules', {
// shutup: true
});
fis.hook('commonjs', {
extList: ['.js', '.jsx', '.tsx', '.ts']
sourceMap: false,
extList: ['.js', '.jsx', '.tsx', '.ts'],
paths: {
'monaco-editor': '/examples/loadMonacoEditor'
}
});
fis.media('dev').match('::package', {
prepackager: fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js': 'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
postpackager: fis.plugin('loader', {
useInlineMap: false,
resourceType: 'mod'
@ -171,6 +203,10 @@ fis.media('dev').match('/node_modules/**.js', {
packTo: '/pkg/npm.js'
});
fis.match('monaco-editor/**', {
packTo: null
});
if (fis.project.currentMedia() === 'publish') {
const publishEnv = fis.media('publish');
publishEnv.get('project.ignore').push('lib/**');
@ -333,10 +369,10 @@ if (fis.project.currentMedia() === 'publish') {
env.match('::package', {
packager: fis.plugin('deps-pack', {
'sdk.js': [
'examples/sdk-mod.js',
'examples/mod.js',
'examples/embed.tsx',
'examples/embed.tsx:deps',
'!monaco-editor/**',
'examples/loadMonacoEditor.ts',
'!flv.js/**',
'!hls.js/**',
'!froala-editor/**',
@ -344,7 +380,8 @@ if (fis.project.currentMedia() === 'publish') {
'!jquery/**',
'!zrender/**',
'!echarts/**',
'!docsearch.js/**'
'!docsearch.js/**',
'!monaco-editor/**.css'
],
'rich-text.js': [
@ -357,11 +394,6 @@ if (fis.project.currentMedia() === 'publish') {
'charts.js': ['zrender/**', 'echarts/**'],
'editor.js': [
'monaco-editor/esm/vs/editor/editor.main.js',
'monaco-editor/esm/vs/editor/editor.main.js:deps'
],
'rest.js': [
'*.js',
'!monaco-editor/**',
@ -384,13 +416,20 @@ if (fis.project.currentMedia() === 'publish') {
]
});
env.match('{*.min.js,monaco-editor/min/**.js}', {
optimizer: null
});
fis.on('compile:optimizer', function (file) {
if (file.isJsLike && file.isMod) {
var contents = file.getContent();
// 替换 worker 地址的路径,让 sdk 加载同目录下的文件。
// 如果 sdk 和 worker 不是部署在一个地方,请通过指定 MonacoEnvironment.getWorkerUrl
if (file.subpath === '/src/components/Editor.tsx') {
if (
file.subpath === '/src/components/Editor.tsx' ||
file.subpath === '/examples/loadMonacoEditor.ts'
) {
contents = contents.replace(
/function\sfilterUrl\(url\)\s\{\s*return\s*url;/m,
function () {
@ -404,18 +443,6 @@ if (fis.project.currentMedia() === 'publish') {
return _path + url.substring(1);`;
}
);
}
if (
typeof contents === 'string' &&
contents.substring(0, 7) === 'define('
) {
contents = 'amis.' + contents;
contents = contents.replace(
'function(require, exports, module)',
'function(require, exports, module, define)'
);
file.setContent(contents);
}
@ -426,40 +453,6 @@ if (fis.project.currentMedia() === 'publish') {
isMod: false
});
env.match('::packager', {
prepackager: [
fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js':
'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
function (ret) {
const root = fis.project.getProjectPath();
[
'/pkg/editor.worker.js',
'/pkg/json.worker.js',
'/pkg/css.worker.js',
'/pkg/html.worker.js',
'/pkg/ts.worker.js'
].forEach(function (pkgFile) {
const packedFile = fis.file.wrap(path.join(root, pkgFile));
const file = ret.pkg[packedFile.subpath];
let contents = file.getContent();
contents = contents.replace(/amis\.define/g, 'define');
file.setContent(contents);
});
}
]
});
env.match('*', {
domain: '.',
deploy: [
@ -559,17 +552,6 @@ if (fis.project.currentMedia() === 'publish') {
});
ghPages.match('::package', {
prepackager: fis.plugin('stand-alone-pack', {
'/pkg/editor.worker.js': 'monaco-editor/esm/vs/editor/editor.worker.js',
'/pkg/json.worker.js': 'monaco-editor/esm/vs/language/json/json.worker',
'/pkg/css.worker.js': 'monaco-editor/esm/vs/language/css/css.worker',
'/pkg/html.worker.js': 'monaco-editor/esm/vs/language/html/html.worker',
'/pkg/ts.worker.js': 'monaco-editor/esm/vs/language/typescript/ts.worker',
// 替换这些文件里面的路径引用。
// 如果不配置,源码中对于打包文件的引用是不正确的。
'replaceFiles': ['src/components/Editor.tsx']
}),
packager: fis.plugin('deps-pack', {
'pkg/npm.js': [
'/examples/mod.js',
@ -596,11 +578,6 @@ if (fis.project.currentMedia() === 'publish') {
'/examples/components/App.jsx:deps'
],
'pkg/editor.js': [
'monaco-editor/esm/vs/editor/editor.main.js',
'monaco-editor/esm/vs/editor/editor.main.js:deps'
],
'pkg/rest.js': [
'**.{js,jsx,ts,tsx}',
'!static/mod.js',
@ -624,6 +601,7 @@ if (fis.project.currentMedia() === 'publish') {
'!/scss/themes/*.scss',
// 要切换主题,不能打在一起。'/scss/*.scss',
'!/examples/style.scss',
'!monaco-editor/**',
'/examples/style.scss' // 让它在最下面
]
}),
@ -707,7 +685,7 @@ if (fis.project.currentMedia() === 'publish') {
})
]
});
ghPages.match('{*.min.js}', {
ghPages.match('{*.min.js,monaco-editor/min/**.js}', {
optimizer: null
});
}

View File

@ -954,17 +954,13 @@ export function render(
options: RenderOptions = {},
pathPrefix: string = ''
): JSX.Element {
options = {
...defaultOptions,
...options
};
const locale = props.locale || getDefaultLocale();
const translate = props.translate || makeTranslator(locale);
let store = stores[options.session || 'global'];
if (!store) {
options = {
...defaultOptions,
...options,
fetcher: options.fetcher
? wrapFetcher(options.fetcher)
@ -1041,7 +1037,7 @@ export function updateEnv(options: Partial<RenderOptions>, session = 'global') {
let store = stores[options.session || session];
if (!store) {
store = RendererStore.create({}, options);
stores[options.session || 'global'] = store;
stores[options.session || session] = store;
} else {
const env = getEnv(store);
Object.assign(env, options);

View File

@ -761,7 +761,12 @@ export default class Form extends React.Component<FormProps, object> {
action.reload && this.reloadTarget(action.reload, store.data);
action.close && this.closeTarget(action.close);
})
.catch(() => {});
.catch(e => {
onFailed && onFailed(e, store.errors);
if (throwErrors) {
throw e;
}
});
} else if (action.actionType === 'reload') {
store.setCurrentAction(action);
action.target && this.reloadTarget(action.target, data);