waibu-mpa 1.1.21 → 1.1.23
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/bajoTemplate/template/wmpa.js +1 -1
- package/lib/build-page.js +10 -1
- package/lib/class/component.js +3 -3
- package/lib/class/theme.js +1 -1
- package/lib/collect-themes.js +2 -2
- package/package.json +1 -1
package/lib/build-page.js
CHANGED
|
@@ -13,10 +13,18 @@ function alert (text, message, opts = {}) {
|
|
|
13
13
|
return `${text}\n${error}`
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const reqAsset = {}
|
|
17
|
+
|
|
16
18
|
async function buildPage ({ text, locals = {}, opts = {} } = {}) {
|
|
17
19
|
const { find, cloneDeep } = this.lib._
|
|
18
20
|
const { runHook } = this.app.bajo
|
|
19
21
|
const { req, reply } = opts
|
|
22
|
+
if (!reqAsset[req.id]) {
|
|
23
|
+
reqAsset[req.id] = {
|
|
24
|
+
scriptBlock: { root: [] },
|
|
25
|
+
styleBlock: { root: [] }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
20
28
|
const theme = find(this.themes, { name: opts.theme })
|
|
21
29
|
if (!theme) text = alert.call(this, text, req.t('unknownTheme%s', req.theme), opts)
|
|
22
30
|
const iconset = find(this.iconsets, { name: opts.iconset })
|
|
@@ -26,7 +34,7 @@ async function buildPage ({ text, locals = {}, opts = {} } = {}) {
|
|
|
26
34
|
if (partial) $('c\\:page-start, c\\:page-end').remove()
|
|
27
35
|
await runHook(`${this.name}:beforeBuildPage${partial ? 'Partial' : ''}`, { $, theme, iconset, req, reply, locals, ns, text })
|
|
28
36
|
await attrsMutation.call(this, { $, el: $.root(), req })
|
|
29
|
-
const cmp = await theme.createComponent({ $, iconset, req, reply, locals: cloneDeep(locals) })
|
|
37
|
+
const cmp = await theme.createComponent({ $, iconset, req, reply, locals: cloneDeep(locals), scriptBlock: reqAsset[req.id].scriptBlock, styleBlock: reqAsset[req.id].styleBlock })
|
|
30
38
|
await replaceTag.call(this, { el: $.root(), cmp, opts })
|
|
31
39
|
text = applyInclude.call(this, $)
|
|
32
40
|
if (!opts.partial) {
|
|
@@ -36,6 +44,7 @@ async function buildPage ({ text, locals = {}, opts = {} } = {}) {
|
|
|
36
44
|
await concatResources.call(this, { $, theme, iconset, req })
|
|
37
45
|
await runHook(`${this.name}:afterBuildPage`, { $, theme, iconset, req, reply, locals, ns, text })
|
|
38
46
|
text = $.root().html()
|
|
47
|
+
delete reqAsset[req.id]
|
|
39
48
|
}
|
|
40
49
|
return text
|
|
41
50
|
}
|
package/lib/class/component.js
CHANGED
|
@@ -16,7 +16,7 @@ class Component {
|
|
|
16
16
|
* @param {Object} options.reply - The reply object.
|
|
17
17
|
* @param {Object} options.req - The request object.
|
|
18
18
|
*/
|
|
19
|
-
constructor ({ plugin, $, theme, iconset, locals, reply, req } = {}) {
|
|
19
|
+
constructor ({ plugin, $, theme, iconset, locals, reply, req, scriptBlock, styleBlock } = {}) {
|
|
20
20
|
const { get } = plugin.app.bajo.lib._
|
|
21
21
|
this.baseFactory = baseFactory
|
|
22
22
|
this.plugin = plugin
|
|
@@ -29,8 +29,8 @@ class Component {
|
|
|
29
29
|
this.cacheMaxAge = get(plugin, 'app.waibuMpa.config.theme.component.cacheMaxAgeDur', 0)
|
|
30
30
|
this.namespace = 'c:'
|
|
31
31
|
this.noTags = []
|
|
32
|
-
this.scriptBlock =
|
|
33
|
-
this.styleBlock =
|
|
32
|
+
this.scriptBlock = scriptBlock
|
|
33
|
+
this.styleBlock = styleBlock
|
|
34
34
|
this.factory = {}
|
|
35
35
|
}
|
|
36
36
|
|
package/lib/class/theme.js
CHANGED
package/lib/collect-themes.js
CHANGED
|
@@ -40,8 +40,8 @@ async function build (mod, fw) {
|
|
|
40
40
|
Object.assign(theme, omit(mod, ['name']))
|
|
41
41
|
await loadItems.call(mod.plugin, 'factory', theme)
|
|
42
42
|
await loadItems.call(mod.plugin, 'method', theme)
|
|
43
|
-
theme.createComponent = async function ({ $, iconset, req, reply, locals }) {
|
|
44
|
-
const cmp = new Component({ plugin: fw ? fw.plugin : mod.plugin, $, theme, iconset, req, reply, locals })
|
|
43
|
+
theme.createComponent = async function ({ $, iconset, req, reply, locals, scriptBlock, styleBlock }) {
|
|
44
|
+
const cmp = new Component({ plugin: fw ? fw.plugin : mod.plugin, $, theme, iconset, req, reply, locals, scriptBlock, styleBlock })
|
|
45
45
|
await cmp.loadBaseFactories()
|
|
46
46
|
const framework = theme.framework ? find(me.themes, { name: theme.framework }) : undefined
|
|
47
47
|
merge(cmp.factory, framework ? framework.factory : theme.factory)
|