qumra-engine 2.0.75 → 2.0.77
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/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/logic/content copy.js +14 -1
- package/dist/extensions/logic/template.d.ts +10 -0
- package/dist/extensions/logic/template.js +66 -0
- package/dist/middleware/prepareData.middleware.js +5 -7
- package/dist/middleware/setGlobals.middleware.js +1 -2
- package/package.json +1 -1
|
@@ -8,3 +8,4 @@ export { default as qumra_head } from './logic/qumra-head';
|
|
|
8
8
|
export { default as qumra_scripts } from './logic/qumra-scripts';
|
|
9
9
|
export { default as include } from './logic/ui';
|
|
10
10
|
export { default as preview_widget } from './logic/preview-widget';
|
|
11
|
+
export { default as template } from './logic/template';
|
package/dist/extensions/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.preview_widget = exports.include = exports.qumra_scripts = exports.qumra_head = exports.content = exports.footer = exports.header = exports.form = exports.widget = exports.seo = void 0;
|
|
6
|
+
exports.template = exports.preview_widget = exports.include = exports.qumra_scripts = exports.qumra_head = exports.content = exports.footer = exports.header = exports.form = exports.widget = exports.seo = void 0;
|
|
7
7
|
var seo_1 = require("./logic/seo");
|
|
8
8
|
Object.defineProperty(exports, "seo", { enumerable: true, get: function () { return __importDefault(seo_1).default; } });
|
|
9
9
|
var widget_1 = require("./logic/widget");
|
|
@@ -24,3 +24,5 @@ var ui_1 = require("./logic/ui");
|
|
|
24
24
|
Object.defineProperty(exports, "include", { enumerable: true, get: function () { return __importDefault(ui_1).default; } });
|
|
25
25
|
var preview_widget_1 = require("./logic/preview-widget");
|
|
26
26
|
Object.defineProperty(exports, "preview_widget", { enumerable: true, get: function () { return __importDefault(preview_widget_1).default; } });
|
|
27
|
+
var template_1 = require("./logic/template");
|
|
28
|
+
Object.defineProperty(exports, "template", { enumerable: true, get: function () { return __importDefault(template_1).default; } });
|
|
@@ -16,7 +16,20 @@ exports.default = new (class WidgetExtension {
|
|
|
16
16
|
return new nodes.CallExtension(this, "run", args);
|
|
17
17
|
}
|
|
18
18
|
run({ ctx, env }) {
|
|
19
|
-
|
|
19
|
+
let widgetPreview = null;
|
|
20
|
+
if (env.getGlobal("widget")) {
|
|
21
|
+
widgetPreview = env.getGlobal("widget");
|
|
22
|
+
}
|
|
23
|
+
let widgets = [];
|
|
24
|
+
if (!widgetPreview) {
|
|
25
|
+
widgets = env.getGlobal("widgets");
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
widgets = [{
|
|
29
|
+
...widgetPreview,
|
|
30
|
+
widget: widgetPreview.widgetKey,
|
|
31
|
+
}];
|
|
32
|
+
}
|
|
20
33
|
const renderedWidgets = [];
|
|
21
34
|
for (const widget of widgets) {
|
|
22
35
|
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import nunjucks from "nunjucks";
|
|
2
|
+
declare const _default: {
|
|
3
|
+
tags: string[];
|
|
4
|
+
parse(parser: any, nodes: any): any;
|
|
5
|
+
run({ ctx, env }: {
|
|
6
|
+
ctx: any;
|
|
7
|
+
env: nunjucks.Environment;
|
|
8
|
+
}, templateKey: string): "" | nunjucks.runtime.SafeString;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
|
+
const normalizeWidgetPath_1 = require("../../utils/normalizeWidgetPath");
|
|
8
|
+
exports.default = new (class WidgetExtension {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.tags = ["template"];
|
|
11
|
+
}
|
|
12
|
+
parse(parser, nodes) {
|
|
13
|
+
const tok = parser.nextToken();
|
|
14
|
+
const args = parser.parseSignature(true, true);
|
|
15
|
+
parser.advanceAfterBlockEnd(tok.value);
|
|
16
|
+
return new nodes.CallExtension(this, "run", args);
|
|
17
|
+
}
|
|
18
|
+
run({ ctx, env }, templateKey) {
|
|
19
|
+
const widgetPreview = env.getGlobal("widget");
|
|
20
|
+
if (widgetPreview) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
if (templateKey === "main") {
|
|
24
|
+
return new nunjucks_1.default.runtime.SafeString(`
|
|
25
|
+
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
26
|
+
⚠️ <strong>لا يمكن تضمين قالب "{% template "main" %}" بشكل مباشر:</strong>
|
|
27
|
+
<p>يمكنك استخدام "{% content %}" لعرض المحتوى الرئيسي للصفحة</p>
|
|
28
|
+
</div>
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
const templates = env.getGlobal("templates");
|
|
32
|
+
const widgets = templates.find((t) => t.key === templateKey)?.widgets || [];
|
|
33
|
+
const renderedWidgets = [];
|
|
34
|
+
for (const widget of widgets) {
|
|
35
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
36
|
+
if (!widgetTemplatePath) {
|
|
37
|
+
return new nunjucks_1.default.runtime.SafeString(`
|
|
38
|
+
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
39
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
40
|
+
</div>
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const html = env.render(widgetTemplatePath, {
|
|
45
|
+
context: ctx.context,
|
|
46
|
+
globals: ctx.globals,
|
|
47
|
+
widget: {
|
|
48
|
+
id: widget.id,
|
|
49
|
+
type: widget.widget,
|
|
50
|
+
data: widget.data,
|
|
51
|
+
blocks: widget.blocks ?? [],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
renderedWidgets.push(html);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
renderedWidgets.push(`
|
|
58
|
+
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
59
|
+
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
60
|
+
</div>
|
|
61
|
+
`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
@@ -59,13 +59,11 @@ const prepareDataMiddleware = (req, res, next) => {
|
|
|
59
59
|
const expectedHost = typeof backendUrl === "string"
|
|
60
60
|
? new URL(backendUrl).host
|
|
61
61
|
: backendUrl?.host;
|
|
62
|
-
|
|
63
|
-
if (parsedUrl.host !== expectedHost &&
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
// `${backendUrl}${parsedUrl.pathname}`
|
|
68
|
-
// );
|
|
62
|
+
const currentUrl = req.headers.host + req.originalUrl;
|
|
63
|
+
if (parsedUrl.host !== expectedHost &&
|
|
64
|
+
!currentUrl.includes("localhost")) {
|
|
65
|
+
// redirect to expected host
|
|
66
|
+
return res.redirect(301, `${backendUrl}${parsedUrl.pathname}`);
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
res.locals.render = engineResponse.data?.data;
|
|
@@ -4,8 +4,6 @@ exports.mergeDataMiddleware = void 0;
|
|
|
4
4
|
const globals_1 = require("../store/globals");
|
|
5
5
|
const mergeDataMiddleware = async (req, res, next) => {
|
|
6
6
|
try {
|
|
7
|
-
const templates = res.locals.render.engine?.templates;
|
|
8
|
-
console.log("🚀 ~ mergeDataMiddleware ~ res.locals.render:", templates);
|
|
9
7
|
if (res.locals.preview && res.locals.themeWidget) {
|
|
10
8
|
res.locals.env.addGlobal("widget", res.locals.render.engine?.widget ?? []);
|
|
11
9
|
}
|
|
@@ -14,6 +12,7 @@ const mergeDataMiddleware = async (req, res, next) => {
|
|
|
14
12
|
}
|
|
15
13
|
const widgets = res.locals.render.engine?.page?.widgets ?? [];
|
|
16
14
|
(0, globals_1.setGlobal)("currency", res.locals.render.globals?.currency);
|
|
15
|
+
res.locals.env.addGlobal("templates", res.locals.render.engine?.templates);
|
|
17
16
|
res.locals.env.addGlobal("engineData", res.locals.render.engine);
|
|
18
17
|
res.locals.env.addGlobal("widgets", widgets);
|
|
19
18
|
res.locals.env.addGlobal("pageData", {
|