metaowl 0.2.10 → 0.2.11
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/modules/app-mounter.js +15 -1
- package/modules/layouts.js +3 -3
- package/package.json +1 -1
- package/vite/plugin.js +4 -0
package/modules/app-mounter.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { mount } from '@odoo/owl'
|
|
9
9
|
import { mergeTemplates } from './templates-manager.js'
|
|
10
|
+
import { resolveLayout, getLayout, mountWithLayout } from './layouts.js'
|
|
10
11
|
|
|
11
12
|
const _defaults = {
|
|
12
13
|
warnIfNoStaticProps: true,
|
|
@@ -43,5 +44,18 @@ export async function mountApp(route) {
|
|
|
43
44
|
const mountElement = document.getElementById('metaowl')
|
|
44
45
|
mountElement.innerHTML = ''
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
const pageComponent = route[0].component
|
|
48
|
+
const pagePath = route[0].path
|
|
49
|
+
|
|
50
|
+
// Check for layout
|
|
51
|
+
const layoutName = resolveLayout(pageComponent, pagePath)
|
|
52
|
+
const LayoutClass = getLayout(layoutName)
|
|
53
|
+
|
|
54
|
+
if (LayoutClass) {
|
|
55
|
+
// Mount with layout
|
|
56
|
+
await mountWithLayout(pageComponent, mountElement, { routePath: pagePath, templates })
|
|
57
|
+
} else {
|
|
58
|
+
// Mount without layout
|
|
59
|
+
await mount(pageComponent, mountElement, { ..._config, templates })
|
|
60
|
+
}
|
|
47
61
|
}
|
package/modules/layouts.js
CHANGED
|
@@ -272,7 +272,7 @@ export function createLayoutWrapper(layoutComponent, pageComponent, props = {})
|
|
|
272
272
|
* @returns {Promise<Component>} Mounted component instance
|
|
273
273
|
*/
|
|
274
274
|
export async function mountWithLayout(pageComponent, target, options = {}, config = {}) {
|
|
275
|
-
const { routePath, props = {} } = options
|
|
275
|
+
const { routePath, props = {}, templates } = options
|
|
276
276
|
|
|
277
277
|
const layoutName = resolveLayout(pageComponent, routePath)
|
|
278
278
|
const LayoutClass = getLayout(layoutName)
|
|
@@ -280,14 +280,14 @@ export async function mountWithLayout(pageComponent, target, options = {}, confi
|
|
|
280
280
|
if (!LayoutClass) {
|
|
281
281
|
console.warn(`[metaowl] Layout "${layoutName}" not found, mounting page without layout`)
|
|
282
282
|
const { mount } = await import('@odoo/owl')
|
|
283
|
-
return mount(pageComponent, target, { ...config, props })
|
|
283
|
+
return mount(pageComponent, target, { ...config, props, templates })
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// Create wrapper that combines layout and page
|
|
287
287
|
const WrapperClass = createLayoutWrapper(LayoutClass, pageComponent, props)
|
|
288
288
|
|
|
289
289
|
const { mount } = await import('@odoo/owl')
|
|
290
|
-
const instance = await mount(WrapperClass, target, config)
|
|
290
|
+
const instance = await mount(WrapperClass, target, { ...config, templates })
|
|
291
291
|
|
|
292
292
|
_currentLayout = instance
|
|
293
293
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metaowl",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Lightweight meta-framework for Odoo OWL — file-based routing, app mounting, Fetch helper, Cache, Meta tags, SSG generator, and a Vite plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/vite/plugin.js
CHANGED
|
@@ -187,10 +187,14 @@ export async function metaowlPlugin(options = {}) {
|
|
|
187
187
|
transform(code, id) {
|
|
188
188
|
if (!id.endsWith('/metaowl.js')) return
|
|
189
189
|
const pagesRel = pagesDir.replace(new RegExp(`^${root}[\\/]`), '')
|
|
190
|
+
const layoutsRel = layoutsDir.replace(new RegExp(`^${root}[\\/]`), '')
|
|
190
191
|
return {
|
|
191
192
|
code: code.replace(
|
|
192
193
|
/boot\(\s*\)/,
|
|
193
194
|
`boot(import.meta.glob('./${pagesRel}/**/*.js', { eager: true }))`
|
|
195
|
+
).replace(
|
|
196
|
+
/discoverLayouts\(\s*\)/,
|
|
197
|
+
`discoverLayouts(import.meta.glob('./${layoutsRel}/**/*.js', { eager: true }))`
|
|
194
198
|
),
|
|
195
199
|
map: null
|
|
196
200
|
}
|