qumra-engine 2.0.26 → 2.0.28

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.
@@ -5,3 +5,4 @@ export { default as header } from './logic/header';
5
5
  export { default as footer } from './logic/footer';
6
6
  export { default as content } from './logic/content';
7
7
  export { default as qumra_head } from './logic/qumra-head';
8
+ export { default as qumra_scripts } from './logic/qumra-scripts';
@@ -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.qumra_head = exports.content = exports.footer = exports.header = exports.form = exports.widget = exports.seo = void 0;
6
+ 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");
@@ -18,3 +18,5 @@ var content_1 = require("./logic/content");
18
18
  Object.defineProperty(exports, "content", { enumerable: true, get: function () { return __importDefault(content_1).default; } });
19
19
  var qumra_head_1 = require("./logic/qumra-head");
20
20
  Object.defineProperty(exports, "qumra_head", { enumerable: true, get: function () { return __importDefault(qumra_head_1).default; } });
21
+ var qumra_scripts_1 = require("./logic/qumra-scripts");
22
+ Object.defineProperty(exports, "qumra_scripts", { enumerable: true, get: function () { return __importDefault(qumra_scripts_1).default; } });
@@ -0,0 +1,7 @@
1
+ import { runtime } from "nunjucks";
2
+ declare const _default: {
3
+ tags: string[];
4
+ parse(parser: any, nodes: any): any;
5
+ run({ env, ctx }: any): runtime.SafeString;
6
+ };
7
+ export default _default;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const nunjucks_1 = require("nunjucks");
4
+ const globals_1 = require("../../store/globals");
5
+ exports.default = new (class SeoExtension {
6
+ constructor() {
7
+ this.tags = ["qumra_head"];
8
+ }
9
+ parse(parser, nodes) {
10
+ const tok = parser.nextToken();
11
+ parser.advanceAfterBlockEnd(tok.value);
12
+ return new nodes.CallExtension(this, "run", null);
13
+ }
14
+ run({ env, ctx }) {
15
+ const injectionCode = (0, globals_1.getGlobal)("injectionCode");
16
+ return new nunjucks_1.runtime.SafeString(`
17
+ ${injectionCode.head}
18
+ <script>
19
+ window.__qumra__ = window.__qumra__ || {};
20
+ window.__qumra__.context = ${JSON.stringify(ctx.context)};
21
+ window.__qumra__.globals = ${JSON.stringify(ctx.globals)};
22
+ </script>
23
+ <style>
24
+ :root {
25
+ --primary-color: #0070f3;
26
+ --secondary-color: #7928ca;
27
+ --background-color: #f9f9f9;
28
+ --text-color: #333333;
29
+ --border-color: #eaeaea;
30
+ --success-color: #22c55e;
31
+ --danger-color: #ef4444;
32
+ --warning-color: #facc15;
33
+ }
34
+ </style>
35
+ `);
36
+ }
37
+ })();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const nunjucks_1 = require("nunjucks");
4
+ const globals_1 = require("../../store/globals");
4
5
  exports.default = new (class SeoExtension {
5
6
  constructor() {
6
7
  this.tags = ["qumra_head"];
@@ -11,11 +12,15 @@ exports.default = new (class SeoExtension {
11
12
  return new nodes.CallExtension(this, "run", null);
12
13
  }
13
14
  run({ env, ctx }) {
14
- const contextData = JSON.stringify({ ...ctx.context || {} });
15
+ const injectionCode = (0, globals_1.getGlobal)("injectionCode");
16
+ // ${injectionCode.head}
15
17
  return new nunjucks_1.runtime.SafeString(`
18
+
19
+ <script src="http://127.0.0.1:5500/dist/qumra-gearbox.js"></script>
16
20
  <script>
17
21
  window.__qumra__ = window.__qumra__ || {};
18
- window.__qumra__.context = ${contextData};
22
+ window.__qumra__.context = ${JSON.stringify(ctx.context)};
23
+ window.__qumra__.globals = ${JSON.stringify(ctx.globals)};
19
24
  </script>
20
25
  <style>
21
26
  :root {
@@ -0,0 +1,7 @@
1
+ import { runtime } from "nunjucks";
2
+ declare const _default: {
3
+ tags: string[];
4
+ parse(parser: any, nodes: any): any;
5
+ run({ env, ctx }: any): runtime.SafeString;
6
+ };
7
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const nunjucks_1 = require("nunjucks");
4
+ const globals_1 = require("../../store/globals");
5
+ exports.default = new (class SeoExtension {
6
+ constructor() {
7
+ this.tags = ["qumra_scripts"];
8
+ }
9
+ parse(parser, nodes) {
10
+ const tok = parser.nextToken();
11
+ parser.advanceAfterBlockEnd(tok.value);
12
+ return new nodes.CallExtension(this, "run", null);
13
+ }
14
+ run({ env, ctx }) {
15
+ const injectionCode = (0, globals_1.getGlobal)("injectionCode");
16
+ return new nunjucks_1.runtime.SafeString(`
17
+ ${injectionCode.body}
18
+ `);
19
+ }
20
+ })();
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeDataMiddleware = void 0;
4
4
  const mergeDataMiddleware = async (req, res, next) => {
5
5
  try {
6
- const widgets = res.locals.render.engine.page?.widgets ?? [];
6
+ const widgets = res.locals.render.engine?.page?.widgets ?? [];
7
7
  res.locals.env.addGlobal("engineData", res.locals.render.engine);
8
8
  res.locals.env.addGlobal("widgets", widgets);
9
9
  res.locals.env.addGlobal("pageData", {
10
- layout: res.locals.render.engine.page?.layout,
11
- title: res.locals.render.engine.page?.title,
12
- handle: res.locals.render.engine.page?.handle,
10
+ layout: res.locals.render.engine?.page?.layout,
11
+ title: res.locals.render.engine?.page?.title,
12
+ handle: res.locals.render.engine?.page?.handle,
13
13
  });
14
- const settingsData = res.locals.render.engine.settings;
14
+ const settingsData = res.locals.render.engine?.settings;
15
15
  console.log("🚀 ~ settingsData:", settingsData);
16
16
  res.locals.env.addGlobal("settings", settingsData);
17
17
  next();
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderMiddleware = void 0;
4
4
  const resolveTranslations_1 = require("../utils/resolveTranslations");
5
+ const globals_1 = require("../store/globals");
5
6
  const renderMiddleware = (req, res, next) => {
6
7
  const render = res.locals.render;
7
- const { context, globals } = render;
8
+ const { context, globals, engine } = render;
9
+ (0, globals_1.setGlobal)("injectionCode", engine?.injectionCode);
8
10
  const env = res.locals.env;
9
11
  const pageLayout = env.getGlobal("pageData").layout ?? "layout";
10
12
  env.render(`layouts/${pageLayout}.njk`, (0, resolveTranslations_1.resolveTranslations)({
@@ -11,7 +11,23 @@ export type TMode = "production" | "devlopment";
11
11
  export interface MainData {
12
12
  globals?: Globals;
13
13
  context?: RenderContext;
14
- engine?: any;
14
+ engine?: {
15
+ page: {
16
+ title: string;
17
+ handle: string;
18
+ layout: string;
19
+ widgets: Array<{
20
+ type: string;
21
+ data: Record<string, any>;
22
+ id: string;
23
+ }>;
24
+ };
25
+ settings: Record<string, any>;
26
+ injectionCode: {
27
+ head: string;
28
+ body: string;
29
+ };
30
+ };
15
31
  themePath: string;
16
32
  assetsPath?: string;
17
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qumra-engine",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {