@saltcorn/sbadmin2 1.1.4-beta.1 → 1.1.4-beta.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.
Files changed (2) hide show
  1. package/index.js +75 -72
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -29,6 +29,7 @@ const {
29
29
  headersInHead,
30
30
  headersInBody,
31
31
  show_icon,
32
+ activeChecker,
32
33
  } = require("@saltcorn/markup/layout_utils");
33
34
  const db = require("@saltcorn/data/db");
34
35
  const { isNode } = require("@saltcorn/data/utils");
@@ -58,22 +59,22 @@ const subItem = (currentUrl) => (item) =>
58
59
  )
59
60
  )
60
61
  : item.link
61
- ? a(
62
- {
63
- class: [
64
- "collapse-item",
65
- active(currentUrl, item) && "active",
66
- item.class,
67
- ],
68
- href: text(item.link),
69
- target: item.target_blank ? "_blank" : undefined,
70
- },
71
- show_icon(item.icon, "mr-05"),
72
- item.label
73
- )
74
- : item.type === "Separator"
75
- ? hr({ class: "sidebar-divider my-0" })
76
- : h6({ class: "collapse-header" }, item.label);
62
+ ? a(
63
+ {
64
+ class: [
65
+ "collapse-item",
66
+ active(currentUrl, item) && "active",
67
+ item.class,
68
+ ],
69
+ href: text(item.link),
70
+ target: item.target_blank ? "_blank" : undefined,
71
+ },
72
+ show_icon(item.icon, "mr-05"),
73
+ item.label
74
+ )
75
+ : item.type === "Separator"
76
+ ? hr({ class: "sidebar-divider my-0" })
77
+ : h6({ class: "collapse-header" }, item.label);
77
78
 
78
79
  /**
79
80
  * @param {object} item
@@ -98,13 +99,13 @@ const logit = (x, s) => {
98
99
  * @returns {boolean}
99
100
  */
100
101
  const active = (currentUrl, item) =>
101
- (item.link && currentUrl.startsWith(item.link)) ||
102
- (item.altlinks && item.altlinks.some((l) => currentUrl.startsWith(l))) ||
102
+ (item.link && activeChecker(item.link, currentUrl)) ||
103
+ (item.altlinks && item.altlinks.some((l) => activeChecker(l, currentUrl))) ||
103
104
  (item.subitems &&
104
105
  item.subitems.some(
105
106
  (si) =>
106
- (si.link && currentUrl.startsWith(si.link)) ||
107
- (si.altlinks && si.altlinks.some((l) => currentUrl.startsWith(l)))
107
+ (si.link && activeChecker(si.link, currentUrl)) ||
108
+ (si.altlinks && si.altlinks.some((l) => activeChecker(l, currentUrl)))
108
109
  ));
109
110
 
110
111
  /**
@@ -147,45 +148,45 @@ const sideBarItem = (currentUrl) => (item) => {
147
148
  ),
148
149
  ]
149
150
  : item.link
150
- ? a(
151
- {
152
- class: "nav-link",
153
- href: text(item.link),
154
- target: item.target_blank ? "_blank" : undefined,
155
- },
156
- show_icon(item.icon),
157
- span(text(item.label))
158
- )
159
- : item.type === "Search"
160
- ? form(
161
- {
162
- action: "/search",
163
- class: "menusearch ms-2 me-3",
164
- method: "get",
165
- },
166
- div(
167
- { class: "input-group search-bar" },
168
-
169
- input({
170
- type: "search",
171
- class: "form-control search-bar pl-2p5",
172
- placeholder: item.label,
173
- id: "inputq",
174
- name: "q",
175
- "aria-label": "Search",
176
- "aria-describedby": "button-search-submit",
177
- }),
178
-
179
- button(
151
+ ? a(
152
+ {
153
+ class: "nav-link",
154
+ href: text(item.link),
155
+ target: item.target_blank ? "_blank" : undefined,
156
+ },
157
+ show_icon(item.icon),
158
+ span(text(item.label))
159
+ )
160
+ : item.type === "Search"
161
+ ? form(
180
162
  {
181
- class: "btn btn-outline-secondary search-bar",
182
- type: "submit",
163
+ action: "/search",
164
+ class: "menusearch ms-2 me-3",
165
+ method: "get",
183
166
  },
184
- i({ class: "fas fa-search" })
167
+ div(
168
+ { class: "input-group search-bar" },
169
+
170
+ input({
171
+ type: "search",
172
+ class: "form-control search-bar pl-2p5",
173
+ placeholder: item.label,
174
+ id: "inputq",
175
+ name: "q",
176
+ "aria-label": "Search",
177
+ "aria-describedby": "button-search-submit",
178
+ }),
179
+
180
+ button(
181
+ {
182
+ class: "btn btn-outline-secondary search-bar",
183
+ type: "submit",
184
+ },
185
+ i({ class: "fas fa-search" })
186
+ )
187
+ )
185
188
  )
186
- )
187
- )
188
- : span({ class: "nav-link" }, text(item.label))
189
+ : span({ class: "nav-link" }, text(item.label))
189
190
  );
190
191
  };
191
192
 
@@ -193,13 +194,12 @@ const sideBarItem = (currentUrl) => (item) => {
193
194
  * @param {string} currentUrl
194
195
  * @returns {function}
195
196
  */
196
- const sideBarSection = (currentUrl) => (section) =>
197
- [
198
- section.section &&
199
- hr({ class: "sidebar-divider" }) +
200
- div({ class: "sidebar-heading" }, section.section),
201
- section.items.map(sideBarItem(currentUrl)).join(""),
202
- ];
197
+ const sideBarSection = (currentUrl) => (section) => [
198
+ section.section &&
199
+ hr({ class: "sidebar-divider" }) +
200
+ div({ class: "sidebar-heading" }, section.section),
201
+ section.items.map(sideBarItem(currentUrl)).join(""),
202
+ ];
203
203
 
204
204
  /**
205
205
  * @param {object} brand
@@ -323,21 +323,23 @@ const renderBody = (title, body, role, req) =>
323
323
  * @param {object} authLinks
324
324
  * @returns {hr|a}
325
325
  */
326
- const renderAuthLinks = (authLinks) => {
326
+ const renderAuthLinks = (authLinks, req) => {
327
+ const __ = req?.__ || ((s) => s);
327
328
  let links = [];
328
329
  if (authLinks.login)
329
- links.push(link(authLinks.login, "Already have an account? Login!"));
330
- if (authLinks.forgot) links.push(link(authLinks.forgot, "Forgot password?"));
330
+ links.push(link(authLinks.login, __("Already have an account? Login!")));
331
+ if (authLinks.forgot)
332
+ links.push(link(authLinks.forgot, __("Forgot password?")));
331
333
  if (authLinks.signup)
332
- links.push(link(authLinks.signup, "Create an account!"));
334
+ links.push(link(authLinks.signup, __("Create an account!")));
333
335
  if (authLinks.publicUser)
334
- links.push(link(authLinks.publicUser, "Continue as public user"));
336
+ links.push(link(authLinks.publicUser, __("Continue as public user")));
335
337
  const meth_links = (authLinks.methods || [])
336
338
  .map(({ url, icon, label }) =>
337
339
  a(
338
340
  { href: url, class: "btn btn-secondary btn-user btn-block" },
339
341
  icon || "",
340
- ` Login with ${label}`
342
+ ` ${__("Login with %s", label)}`
341
343
  )
342
344
  )
343
345
  .join("");
@@ -393,8 +395,8 @@ const wrapIt = (headers, title, bodyAttr, rest) =>
393
395
  <body ${bodyAttr}>
394
396
  ${rest}
395
397
  <script src="${safeSlash()}static_assets/${
396
- db.connectObj.version_tag
397
- }/jquery-3.6.0.min.js"></script>
398
+ db.connectObj.version_tag
399
+ }/jquery-3.6.0.min.js"></script>
398
400
  <script src="${linkPrefix()}/public/sbadmin2${verstring}/bootstrap.bundle.min.js"></script>
399
401
  <script src="${linkPrefix()}/public/sbadmin2${verstring}/jquery.easing.min.js"></script>
400
402
  <script src="${linkPrefix()}/public/sbadmin2${verstring}/sb-admin-2.min.js"></script>
@@ -422,6 +424,7 @@ const authWrap = ({
422
424
  csrfToken,
423
425
  authLinks,
424
426
  bodyClass,
427
+ req,
425
428
  }) =>
426
429
  wrapIt(
427
430
  headers,
@@ -440,7 +443,7 @@ const authWrap = ({
440
443
  <h1 class="h4 text-gray-900 mb-4">${title}</h1>
441
444
  </div>
442
445
  ${renderForm(formModify(form), csrfToken)}
443
- ${renderAuthLinks(authLinks)}
446
+ ${renderAuthLinks(authLinks, req)}
444
447
  ${afterForm ? afterForm : ""}
445
448
  </div>
446
449
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/sbadmin2",
3
- "version": "1.1.4-beta.1",
3
+ "version": "1.1.4-beta.11",
4
4
  "description": "SB Admin 2 layout plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,8 +9,8 @@
9
9
  "clean": "echo \"Error: no TypeScript support yet\""
10
10
  },
11
11
  "dependencies": {
12
- "@saltcorn/data": "1.1.4-beta.1",
13
- "@saltcorn/markup": "1.1.4-beta.1"
12
+ "@saltcorn/data": "1.1.4-beta.11",
13
+ "@saltcorn/markup": "1.1.4-beta.11"
14
14
  },
15
15
  "author": "Tom Nielsen",
16
16
  "license": "MIT",