qumra-engine 2.0.149 → 2.0.150
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/controllers/localize/currency.controller.d.ts +1 -0
- package/dist/controllers/localize/currency.controller.js +34 -1
- package/dist/controllers/localize/lang.controller.js +0 -1
- package/dist/extensions/logic/all_products.js +0 -2
- package/dist/extensions/logic/content.d.ts +1 -1
- package/dist/extensions/logic/content.js +86 -69
- package/dist/extensions/logic/seo.js +0 -3
- package/dist/extensions/logic/template copy.d.ts +10 -0
- package/dist/extensions/logic/template copy.js +70 -0
- package/dist/extensions/logic/template.d.ts +5 -4
- package/dist/extensions/logic/template.js +61 -54
- package/dist/extensions/logic/ui.d.ts +5 -4
- package/dist/extensions/logic/ui.js +42 -17
- package/dist/extensions/logic/widget.d.ts +5 -4
- package/dist/extensions/logic/widget.js +47 -22
- package/dist/extensions/registerAllExtensions.js +0 -2
- package/dist/filters/index.d.ts +136 -22
- package/dist/filters/index.js +186 -49
- package/dist/filters/logic/array/index.d.ts +0 -19
- package/dist/filters/logic/array/index.js +0 -43
- package/dist/filters/logic/cart/index.d.ts +0 -2
- package/dist/filters/logic/cart/index.js +0 -9
- package/dist/filters/logic/colors/index.d.ts +0 -16
- package/dist/filters/logic/colors/index.js +0 -37
- package/dist/filters/logic/customer/index.d.ts +0 -4
- package/dist/filters/logic/customer/index.js +0 -13
- package/dist/filters/logic/default/index.d.ts +0 -1
- package/dist/filters/logic/default/index.js +0 -7
- package/dist/filters/logic/format/index.d.ts +0 -4
- package/dist/filters/logic/format/index.js +0 -13
- package/dist/filters/logic/format/unit_price_with_measurement.js +1 -1
- package/dist/filters/logic/format/weight_with_unit.d.ts +1 -1
- package/dist/filters/logic/format/weight_with_unit.js +1 -1
- package/dist/filters/logic/html/index.d.ts +0 -7
- package/dist/filters/logic/html/index.js +0 -19
- package/dist/filters/logic/localization/currency_selector.d.ts +1 -7
- package/dist/filters/logic/localization/currency_selector.js +10 -36
- package/dist/filters/logic/localization/index.d.ts +0 -2
- package/dist/filters/logic/localization/index.js +0 -9
- package/dist/filters/logic/math/index.d.ts +0 -11
- package/dist/filters/logic/math/index.js +0 -27
- package/dist/filters/logic/media/external_video_tag.d.ts +1 -1
- package/dist/filters/logic/media/external_video_tag.js +21 -1
- package/dist/filters/logic/media/image_url.d.ts +1 -1
- package/dist/filters/logic/media/image_url.js +30 -2
- package/dist/filters/logic/media/index.d.ts +0 -8
- package/dist/filters/logic/media/index.js +0 -21
- package/dist/filters/registerAllFilters.js +3 -36
- package/dist/functions/render-handler.js +29 -7
- package/dist/globals/logic/all_products.js +0 -1
- package/dist/graphql/query/findAllCountries.d.ts +2 -0
- package/dist/graphql/query/findAllCountries.js +41 -0
- package/dist/graphql/query/index.d.ts +2 -1
- package/dist/graphql/query/index.js +3 -1
- package/dist/middleware/init.middleware.js +0 -3
- package/dist/middleware/nunjucks.middleware.js +1 -1
- package/dist/middleware/prepareData.middleware.js +1 -1
- package/dist/middleware/render.middleware.js +14 -5
- package/dist/middleware.js +0 -1
- package/dist/nunjucksEnv.d.ts +1 -1
- package/dist/nunjucksEnv.js +2 -1
- package/dist/utils/client.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.currencyController = void 0;
|
|
3
|
+
exports.getAllCurrency = exports.currencyController = void 0;
|
|
4
|
+
const client_1 = require("../../utils/client");
|
|
5
|
+
const graphql_1 = require("../../graphql");
|
|
4
6
|
const currencyController = async (req, res) => {
|
|
5
7
|
const { currency } = req.body;
|
|
6
8
|
if (!currency) {
|
|
@@ -15,3 +17,34 @@ const currencyController = async (req, res) => {
|
|
|
15
17
|
res.redirect(redirectUrl);
|
|
16
18
|
};
|
|
17
19
|
exports.currencyController = currencyController;
|
|
20
|
+
const currencies = [
|
|
21
|
+
{ value: "AED", label: "AED د.إ" },
|
|
22
|
+
{ value: "AFN", label: "AFN ؋" },
|
|
23
|
+
{ value: "AUD", label: "AUD $" },
|
|
24
|
+
{ value: "CAD", label: "CAD $", selected: true },
|
|
25
|
+
{ value: "CHF", label: "CHF CHF" },
|
|
26
|
+
{ value: "CZK", label: "CZK Kč" },
|
|
27
|
+
{ value: "DKK", label: "DKK kr." },
|
|
28
|
+
{ value: "EUR", label: "EUR €" },
|
|
29
|
+
{ value: "GBP", label: "GBP £" },
|
|
30
|
+
{ value: "HKD", label: "HKD $" },
|
|
31
|
+
{ value: "ILS", label: "ILS ₪" },
|
|
32
|
+
{ value: "JPY", label: "JPY ¥" },
|
|
33
|
+
{ value: "KRW", label: "KRW ₩" },
|
|
34
|
+
{ value: "MYR", label: "MYR RM" },
|
|
35
|
+
{ value: "NZD", label: "NZD $" },
|
|
36
|
+
{ value: "PLN", label: "PLN zł" },
|
|
37
|
+
{ value: "SEK", label: "SEK kr" },
|
|
38
|
+
{ value: "SGD", label: "SGD $" },
|
|
39
|
+
{ value: "USD", label: "USD $" },
|
|
40
|
+
];
|
|
41
|
+
const getAllCurrency = () => {
|
|
42
|
+
// const client = getGqlClient();
|
|
43
|
+
// const Currency = await client.request(query.findAllCountries)
|
|
44
|
+
// return Currency.countries
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
const client = (0, client_1.getGqlClient)();
|
|
47
|
+
client.request(graphql_1.query.findAllCountries).then((data) => resolve(data.countries));
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
exports.getAllCurrency = getAllCurrency;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.langController = void 0;
|
|
4
4
|
const langController = async (req, res) => {
|
|
5
5
|
const { lang } = req.body;
|
|
6
|
-
console.log("🚀 ~ langController ~ req.body:", req.body);
|
|
7
6
|
if (!lang) {
|
|
8
7
|
return res.status(400).send("Missing redirect_url");
|
|
9
8
|
}
|
|
@@ -25,7 +25,6 @@ exports.default = new (class AllProductsExtension {
|
|
|
25
25
|
}
|
|
26
26
|
async run(_context, args = {}, callback) {
|
|
27
27
|
try {
|
|
28
|
-
console.log("🚀 ~ run ~ khalidstest:");
|
|
29
28
|
if (typeof args !== "object" || Array.isArray(args))
|
|
30
29
|
args = {};
|
|
31
30
|
const client = (0, client_js_1.getGqlClient)();
|
|
@@ -42,7 +41,6 @@ exports.default = new (class AllProductsExtension {
|
|
|
42
41
|
const input = { ...args };
|
|
43
42
|
const cleanedInput = cleanInput(input);
|
|
44
43
|
const data = await client.request(index_js_1.query.findAllProducts, { input: cleanedInput });
|
|
45
|
-
console.log("🚀 ~ run ~ datfindAllProductsa:", data?.findAllProducts?.data, cleanedInput);
|
|
46
44
|
const products = data?.findAllProducts?.data || [];
|
|
47
45
|
const json = JSON.stringify(products, null, 2);
|
|
48
46
|
callback(null, new nunjucks_1.default.runtime.SafeString(json));
|
|
@@ -5,6 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
7
|
const normalizeWidgetPath_1 = require("../../utils/normalizeWidgetPath");
|
|
8
|
+
function renderAsync(env, templatePath, data) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
env.render(templatePath, data, (err, res) => {
|
|
11
|
+
if (err)
|
|
12
|
+
reject(err);
|
|
13
|
+
else
|
|
14
|
+
resolve(res);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
8
18
|
exports.default = new (class WidgetExtension {
|
|
9
19
|
constructor() {
|
|
10
20
|
this.tags = ["content"];
|
|
@@ -12,79 +22,86 @@ exports.default = new (class WidgetExtension {
|
|
|
12
22
|
parse(parser, nodes) {
|
|
13
23
|
const tok = parser.nextToken();
|
|
14
24
|
const args = parser.parseSignature(true, true);
|
|
15
|
-
parser.advanceAfterBlockEnd(
|
|
16
|
-
return new nodes.
|
|
25
|
+
parser.advanceAfterBlockEnd(" ");
|
|
26
|
+
return new nodes.CallExtensionAsync(this, "run", args);
|
|
17
27
|
}
|
|
18
|
-
run({ ctx, env }) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
template = templates.find((t) => t.key === "main");
|
|
28
|
-
widgets = template?.widgets || [];
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
widgets = [
|
|
32
|
-
{
|
|
33
|
-
...widgetPreview,
|
|
34
|
-
widget: widgetPreview.widgetKey,
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
const renderedWidgets = [];
|
|
39
|
-
for (const widget of widgets) {
|
|
40
|
-
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
41
|
-
if (!widgetTemplatePath) {
|
|
42
|
-
return new nunjucks_1.default.runtime.SafeString(`
|
|
43
|
-
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
44
|
-
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
45
|
-
</div>
|
|
46
|
-
`);
|
|
28
|
+
run({ ctx, env }, templateKey, callback) {
|
|
29
|
+
try {
|
|
30
|
+
let widgetPreview = env.getGlobal("widget") || null;
|
|
31
|
+
let widgets = [];
|
|
32
|
+
let template = {};
|
|
33
|
+
if (!widgetPreview) {
|
|
34
|
+
const templates = env.getGlobal("templates");
|
|
35
|
+
template = templates.find((t) => t.key === "main");
|
|
36
|
+
widgets = template?.widgets || [];
|
|
47
37
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
currency: ctx.currency,
|
|
54
|
-
market: ctx.market,
|
|
55
|
-
widget: {
|
|
56
|
-
id: widget._id,
|
|
57
|
-
type: widget.widget,
|
|
58
|
-
data: widget.data,
|
|
59
|
-
blocks: widget.blocks ?? [],
|
|
38
|
+
else {
|
|
39
|
+
widgets = [
|
|
40
|
+
{
|
|
41
|
+
...widgetPreview,
|
|
42
|
+
widget: widgetPreview.widgetKey,
|
|
60
43
|
},
|
|
61
|
-
|
|
62
|
-
let showDevTools = false;
|
|
63
|
-
if (env.getGlobal("isIframe")) {
|
|
64
|
-
showDevTools = env.getGlobal("isIframe");
|
|
65
|
-
}
|
|
66
|
-
if (env.getGlobal("showDevTools")) {
|
|
67
|
-
showDevTools = env.getGlobal("showDevTools");
|
|
68
|
-
}
|
|
69
|
-
if (showDevTools) {
|
|
70
|
-
renderedWidgets.push(`
|
|
71
|
-
<section content-type="widget" widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="main" template-id="${template._id}">
|
|
72
|
-
${html}
|
|
73
|
-
</section>
|
|
74
|
-
`);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
renderedWidgets.push(html);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
renderedWidgets.push(`
|
|
82
|
-
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
83
|
-
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
84
|
-
</div>
|
|
85
|
-
`);
|
|
44
|
+
];
|
|
86
45
|
}
|
|
46
|
+
const showDevTools = env.getGlobal("isIframe") || env.getGlobal("showDevTools") || false;
|
|
47
|
+
widgets
|
|
48
|
+
.reduce((chain, widget) => {
|
|
49
|
+
return chain.then((renderedWidgets) => {
|
|
50
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
51
|
+
if (!widgetTemplatePath) {
|
|
52
|
+
renderedWidgets.push(`
|
|
53
|
+
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
54
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
55
|
+
</div>
|
|
56
|
+
`);
|
|
57
|
+
return renderedWidgets;
|
|
58
|
+
}
|
|
59
|
+
return renderAsync(env, widgetTemplatePath, {
|
|
60
|
+
context: ctx.context,
|
|
61
|
+
globals: ctx.globals,
|
|
62
|
+
lang: ctx.lang,
|
|
63
|
+
currency: ctx.currency,
|
|
64
|
+
market: ctx.market,
|
|
65
|
+
widget: {
|
|
66
|
+
id: widget._id,
|
|
67
|
+
type: widget.widget,
|
|
68
|
+
data: widget.data,
|
|
69
|
+
blocks: widget.blocks ?? [],
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
.then((html) => {
|
|
73
|
+
if (showDevTools) {
|
|
74
|
+
renderedWidgets.push(`
|
|
75
|
+
<section content-type="widget" widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="main" template-id="${template._id}">
|
|
76
|
+
${html}
|
|
77
|
+
</section>
|
|
78
|
+
`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
renderedWidgets.push(html);
|
|
82
|
+
}
|
|
83
|
+
return renderedWidgets;
|
|
84
|
+
})
|
|
85
|
+
.catch((err) => {
|
|
86
|
+
renderedWidgets.push(`
|
|
87
|
+
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
88
|
+
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
89
|
+
</div>
|
|
90
|
+
`);
|
|
91
|
+
return renderedWidgets;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}, Promise.resolve([]))
|
|
95
|
+
.then((renderedWidgets) => {
|
|
96
|
+
const output = new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
97
|
+
callback(null, output);
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => {
|
|
100
|
+
callback(err);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
callback(err);
|
|
87
105
|
}
|
|
88
|
-
return new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
89
106
|
}
|
|
90
107
|
})();
|
|
@@ -24,12 +24,9 @@ exports.default = new (class SeoExtension {
|
|
|
24
24
|
const product = page.product || c.product || {};
|
|
25
25
|
// أساسيات
|
|
26
26
|
const siteName = (0, textOnly_1.textOnly)(store?.name || "Store", 70);
|
|
27
|
-
console.log("🚀 ~ run ~ seo.title:", seo.title);
|
|
28
27
|
const titleRaw = seo.title || page.title || siteName;
|
|
29
|
-
console.log("🚀 ~ run ~ titleRaw:", titleRaw);
|
|
30
28
|
const descRaw = seo.description || page.description || "";
|
|
31
29
|
const pageTitle = (0, textOnly_1.textOnly)(titleRaw, 70);
|
|
32
|
-
console.log("🚀 ~ run ~ pageTitle:", pageTitle);
|
|
33
30
|
const pageDesc = (0, textOnly_1.textOnly)(descRaw, 160);
|
|
34
31
|
// روابط وصور
|
|
35
32
|
const canonical = (0, safeUrl_1.safeUrl)(seo.canonical || page.canonical || page.url || "");
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
console.log("CallExtension", nodes);
|
|
17
|
+
return new nodes.CallExtensionAsync(this, "run", args);
|
|
18
|
+
}
|
|
19
|
+
run({ ctx, env }, templateKey, callback) {
|
|
20
|
+
const widgetPreview = env.getGlobal("widget");
|
|
21
|
+
if (widgetPreview) {
|
|
22
|
+
return callback(null, "");
|
|
23
|
+
}
|
|
24
|
+
const templates = env.getGlobal("templates");
|
|
25
|
+
const template = templates.find((t) => t.key === templateKey);
|
|
26
|
+
const widgets = template?.widgets || [];
|
|
27
|
+
const renderedWidgets = [];
|
|
28
|
+
for (const widget of widgets) {
|
|
29
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
30
|
+
if (!widgetTemplatePath) {
|
|
31
|
+
return callback(null, new nunjucks_1.default.runtime.SafeString(`
|
|
32
|
+
<div style="padding:12px;background:#f8d7da;color:#721c24;border:1px solid #f5c6cb;border-radius:4px;">
|
|
33
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
34
|
+
</div>
|
|
35
|
+
`));
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const html = env.render(widgetTemplatePath, {
|
|
39
|
+
...ctx,
|
|
40
|
+
widget: {
|
|
41
|
+
id: widget._id,
|
|
42
|
+
type: widget.widget,
|
|
43
|
+
data: widget.data,
|
|
44
|
+
blocks: widget.blocks ?? [],
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
let showDevTools = env.getGlobal("isIframe") || env.getGlobal("showDevTools") || false;
|
|
48
|
+
if (showDevTools) {
|
|
49
|
+
renderedWidgets.push(`
|
|
50
|
+
<section widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="${templateKey}" template-id="${template._id}">
|
|
51
|
+
${html}
|
|
52
|
+
</section>
|
|
53
|
+
`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
renderedWidgets.push(html);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
renderedWidgets.push(`
|
|
61
|
+
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
62
|
+
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
63
|
+
</div>
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const htmlOutput = new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
68
|
+
return callback(null, htmlOutput);
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import nunjucks from "nunjucks";
|
|
2
|
+
interface RunContext {
|
|
3
|
+
ctx: any;
|
|
4
|
+
env: nunjucks.Environment;
|
|
5
|
+
}
|
|
2
6
|
declare const _default: {
|
|
3
7
|
tags: string[];
|
|
4
8
|
parse(parser: any, nodes: any): any;
|
|
5
|
-
run({ ctx, env }:
|
|
6
|
-
ctx: any;
|
|
7
|
-
env: nunjucks.Environment;
|
|
8
|
-
}, templateKey: string): "" | nunjucks.runtime.SafeString;
|
|
9
|
+
run({ ctx, env }: RunContext, templateKey: string, callback: any): any;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
|
@@ -5,6 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
7
|
const normalizeWidgetPath_1 = require("../../utils/normalizeWidgetPath");
|
|
8
|
+
function renderAsync(env, templatePath, data) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
env.render(templatePath, data, (err, res) => {
|
|
11
|
+
if (err)
|
|
12
|
+
reject(err);
|
|
13
|
+
else
|
|
14
|
+
resolve(res);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
8
18
|
exports.default = new (class WidgetExtension {
|
|
9
19
|
constructor() {
|
|
10
20
|
this.tags = ["template"];
|
|
@@ -13,36 +23,35 @@ exports.default = new (class WidgetExtension {
|
|
|
13
23
|
const tok = parser.nextToken();
|
|
14
24
|
const args = parser.parseSignature(true, true);
|
|
15
25
|
parser.advanceAfterBlockEnd(tok.value);
|
|
16
|
-
return new nodes.
|
|
26
|
+
return new nodes.CallExtensionAsync(this, "run", args);
|
|
17
27
|
}
|
|
18
|
-
run({ ctx, env }, templateKey) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// `);
|
|
30
|
-
// }
|
|
31
|
-
const templates = env.getGlobal("templates");
|
|
32
|
-
const template = templates.find((t) => t.key === templateKey);
|
|
33
|
-
const widgets = template?.widgets || [];
|
|
34
|
-
const renderedWidgets = [];
|
|
35
|
-
for (const widget of widgets) {
|
|
36
|
-
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
37
|
-
if (!widgetTemplatePath) {
|
|
38
|
-
return new nunjucks_1.default.runtime.SafeString(`
|
|
39
|
-
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
40
|
-
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
41
|
-
</div>
|
|
42
|
-
`);
|
|
28
|
+
run({ ctx, env }, templateKey, callback) {
|
|
29
|
+
try {
|
|
30
|
+
const widgetPreview = env.getGlobal("widget");
|
|
31
|
+
if (widgetPreview)
|
|
32
|
+
return callback(null, "");
|
|
33
|
+
const templates = env.getGlobal("templates") || [];
|
|
34
|
+
const template = templates.find((t) => t.key === templateKey);
|
|
35
|
+
if (!template) {
|
|
36
|
+
return callback(null, new nunjucks_1.default.runtime.SafeString(`<div style="padding:12px;background:#fdecea;color:#b71c1c;">
|
|
37
|
+
⚠️ Template not found: ${templateKey}
|
|
38
|
+
</div>`));
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const widgets = template.widgets || [];
|
|
41
|
+
const showDevTools = env.getGlobal("isIframe") || env.getGlobal("showDevTools") || false;
|
|
42
|
+
widgets
|
|
43
|
+
.reduce((chain, widget) => chain.then((results) => {
|
|
44
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
45
|
+
if (!widgetTemplatePath) {
|
|
46
|
+
results.push(`
|
|
47
|
+
<div style="padding:12px;background:#f8d7da;color:#721c24;
|
|
48
|
+
border:1px solid #f5c6cb;border-radius:4px;">
|
|
49
|
+
⚠️ مسار الويجيت غير صالح: ${widget.widget}
|
|
50
|
+
</div>
|
|
51
|
+
`);
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
return renderAsync(env, widgetTemplatePath, {
|
|
46
55
|
...ctx,
|
|
47
56
|
widget: {
|
|
48
57
|
id: widget._id,
|
|
@@ -50,33 +59,31 @@ exports.default = new (class WidgetExtension {
|
|
|
50
59
|
data: widget.data,
|
|
51
60
|
blocks: widget.blocks ?? [],
|
|
52
61
|
},
|
|
62
|
+
}).then((html) => {
|
|
63
|
+
if (showDevTools) {
|
|
64
|
+
results.push(`
|
|
65
|
+
<section widget-id="${widget._id}"
|
|
66
|
+
id="qumra-widget-id-${widget._id}"
|
|
67
|
+
template-key="${templateKey}"
|
|
68
|
+
template-id="${template._id}">
|
|
69
|
+
${html}
|
|
70
|
+
</section>
|
|
71
|
+
`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
results.push(html);
|
|
75
|
+
}
|
|
76
|
+
return results;
|
|
53
77
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<section widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="${templateKey}" template-id="${template._id}">
|
|
64
|
-
${html}
|
|
65
|
-
</section>
|
|
66
|
-
`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
renderedWidgets.push(html);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
renderedWidgets.push(`
|
|
74
|
-
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
75
|
-
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
76
|
-
</div>
|
|
77
|
-
`);
|
|
78
|
-
}
|
|
78
|
+
}), Promise.resolve([]))
|
|
79
|
+
.then((renderedHtml) => {
|
|
80
|
+
const output = new nunjucks_1.default.runtime.SafeString(renderedHtml.join("\n"));
|
|
81
|
+
callback(null, output);
|
|
82
|
+
})
|
|
83
|
+
.catch((err) => callback(err));
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
callback(err);
|
|
79
87
|
}
|
|
80
|
-
return new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
81
88
|
}
|
|
82
89
|
})();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import nunjucks from "nunjucks";
|
|
2
|
+
interface RunContext {
|
|
3
|
+
ctx: any;
|
|
4
|
+
env: nunjucks.Environment;
|
|
5
|
+
}
|
|
2
6
|
declare const _default: {
|
|
3
7
|
tags: string[];
|
|
4
8
|
parse(parser: any, nodes: any): any;
|
|
5
|
-
run({ ctx, env }:
|
|
6
|
-
ctx: any;
|
|
7
|
-
env: nunjucks.Environment;
|
|
8
|
-
}, file: string, ...data: any): nunjucks.runtime.SafeString;
|
|
9
|
+
run({ ctx, env }: RunContext, file: string, ...args: any[]): any;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|
|
@@ -6,7 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
7
|
const normalizeUiPath_1 = require("../../utils/normalizeUiPath");
|
|
8
8
|
const validateUiData_1 = require("../../utils/validateUiData");
|
|
9
|
-
|
|
9
|
+
function renderAsync(env, templatePath, data) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
env.render(templatePath, data, (err, res) => {
|
|
12
|
+
if (err)
|
|
13
|
+
reject(err);
|
|
14
|
+
else
|
|
15
|
+
resolve(res);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.default = new (class UiExtension {
|
|
10
20
|
constructor() {
|
|
11
21
|
this.tags = ["ui"];
|
|
12
22
|
}
|
|
@@ -14,25 +24,40 @@ exports.default = new (class WidgetExtension {
|
|
|
14
24
|
const tok = parser.nextToken();
|
|
15
25
|
const args = parser.parseSignature(true, true);
|
|
16
26
|
parser.advanceAfterBlockEnd(tok.value);
|
|
17
|
-
return new nodes.
|
|
27
|
+
return new nodes.CallExtensionAsync(this, "run", args);
|
|
18
28
|
}
|
|
19
|
-
run({ ctx, env }, file, ...
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
run({ ctx, env }, file, ...args) {
|
|
30
|
+
// ⭐ الـ callback دائماً آخر parameter
|
|
31
|
+
const callback = args[args.length - 1];
|
|
32
|
+
// ⭐ الـ data هي كل شيء ما عدا الـ callback
|
|
33
|
+
const data = args.slice(0, -1);
|
|
34
|
+
try {
|
|
35
|
+
// التحقق من صحة المسار
|
|
36
|
+
if (!file || typeof file !== 'string' || file.trim() === '' || !file.includes('.njk')) {
|
|
37
|
+
return callback(new Error("Invalid file path provided to ui extension"));
|
|
38
|
+
}
|
|
39
|
+
const filePath = (0, normalizeUiPath_1.normalizeUiPath)(file);
|
|
40
|
+
if (!filePath) {
|
|
41
|
+
return callback(null, new nunjucks_1.default.runtime.SafeString(`
|
|
26
42
|
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
27
|
-
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${
|
|
43
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${file}
|
|
28
44
|
</div>
|
|
29
|
-
|
|
45
|
+
`));
|
|
46
|
+
}
|
|
47
|
+
const validated = (0, validateUiData_1.validateUiData)(data);
|
|
48
|
+
// استخدام renderAsync بدلاً من render المباشر
|
|
49
|
+
renderAsync(env, filePath, {
|
|
50
|
+
...ctx,
|
|
51
|
+
data: validated,
|
|
52
|
+
})
|
|
53
|
+
.then((rendered) => {
|
|
54
|
+
const output = new nunjucks_1.default.runtime.SafeString(rendered);
|
|
55
|
+
callback(null, output);
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => callback(err));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
callback(err);
|
|
30
61
|
}
|
|
31
|
-
const validated = (0, validateUiData_1.validateUiData)(data);
|
|
32
|
-
const rendered = env.render(filePath, {
|
|
33
|
-
...ctx,
|
|
34
|
-
data: validated,
|
|
35
|
-
});
|
|
36
|
-
return new nunjucks_1.default.runtime.SafeString(rendered);
|
|
37
62
|
}
|
|
38
63
|
})();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import nunjucks from "nunjucks";
|
|
2
|
+
interface RunContext {
|
|
3
|
+
ctx: any;
|
|
4
|
+
env: nunjucks.Environment;
|
|
5
|
+
}
|
|
2
6
|
declare const _default: {
|
|
3
7
|
tags: string[];
|
|
4
8
|
parse(parser: any, nodes: any): any;
|
|
5
|
-
run({ ctx, env }:
|
|
6
|
-
ctx: any;
|
|
7
|
-
env: nunjucks.Environment;
|
|
8
|
-
}, widgetPath: string): nunjucks.runtime.SafeString;
|
|
9
|
+
run({ ctx, env }: RunContext, widgetPath: string, ...args: any[]): any;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|