@xwiki/cristal-navigation-tree-xwiki 0.14.0 → 0.16.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @xwiki/cristal-navigation-tree-xwiki
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Cristal 0.16 Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @xwiki/cristal-api@0.16.0
13
+ - @xwiki/cristal-authentication-api@0.16.0
14
+ - @xwiki/cristal-model-api@0.16.0
15
+ - @xwiki/cristal-model-reference-api@0.16.0
16
+ - @xwiki/cristal-model-remote-url-api@0.16.0
17
+ - @xwiki/cristal-navigation-tree-api@0.16.0
18
+
19
+ ## 0.15.0
20
+
21
+ ### Minor Changes
22
+
23
+ - Cristal 0.15 Release
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - @xwiki/cristal-api@0.15.0
29
+ - @xwiki/cristal-authentication-api@0.15.0
30
+ - @xwiki/cristal-model-api@0.15.0
31
+ - @xwiki/cristal-model-reference-api@0.15.0
32
+ - @xwiki/cristal-model-remote-url-api@0.15.0
33
+ - @xwiki/cristal-navigation-tree-api@0.15.0
34
+
3
35
  ## 0.14.0
4
36
 
5
37
  ### Minor Changes
package/dist/index.es.js CHANGED
@@ -1,57 +1,51 @@
1
- import { name as g } from "@xwiki/cristal-navigation-tree-api";
2
- import { injectable as f, inject as c, named as u } from "inversify";
3
- var m = Object.defineProperty, v = Object.getOwnPropertyDescriptor, w = (r, t, a, i) => {
4
- for (var e = i > 1 ? void 0 : i ? v(t, a) : t, n = r.length - 1, l; n >= 0; n--)
5
- (l = r[n]) && (e = (i ? l(t, a, e) : l(e)) || e);
6
- return i && e && m(t, a, e), e;
7
- }, s = (r, t) => (a, i) => t(a, i, r);
1
+ import { name as f } from "@xwiki/cristal-navigation-tree-api";
2
+ import { injectable as g, inject as c, named as u } from "inversify";
3
+ var m = Object.defineProperty, w = Object.getOwnPropertyDescriptor, v = (t, r, a, e) => {
4
+ for (var i = e > 1 ? void 0 : e ? w(r, a) : r, n = t.length - 1, l; n >= 0; n--)
5
+ (l = t[n]) && (i = (e ? l(r, a, i) : l(i)) || i);
6
+ return e && i && m(r, a, i), i;
7
+ }, s = (t, r) => (a, e) => r(a, e, t);
8
8
  let h = class {
9
- constructor(r, t, a, i, e) {
10
- this.logger = r, this.cristalApp = t, this.authenticationManagerProvider = a, this.urlParser = i, this.referenceSerializer = e, this.logger.setModule(
9
+ constructor(t, r, a, e, i) {
10
+ this.logger = t, this.cristalApp = r, this.authenticationManagerProvider = a, this.urlParser = e, this.referenceSerializer = i, this.logger.setModule(
11
11
  "navigation-tree-xwiki.components.XWikiNavigationTreeSource"
12
12
  );
13
13
  }
14
14
  // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
15
15
  // eslint-disable-next-line max-statements
16
- async getChildNodes(r) {
17
- var i;
18
- const t = r || "#", a = [];
16
+ async getChildNodes(t) {
17
+ var e;
18
+ const r = t || "#", a = [];
19
19
  try {
20
- const e = await ((i = this.authenticationManagerProvider.get()) == null ? void 0 : i.getAuthorizationHeader()), n = {
20
+ const i = await ((e = this.authenticationManagerProvider.get()) == null ? void 0 : e.getAuthorizationHeader()), n = {
21
21
  Accept: "application/json"
22
22
  };
23
- e && (n.Authorization = e), a.push(...await this.fetchNodes(t, n, 0));
24
- } catch (e) {
25
- this.logger.error(e), this.logger.debug("Could not load navigation tree.");
23
+ i && (n.Authorization = i), a.push(...await this.fetchNodes(r, n, 0));
24
+ } catch (i) {
25
+ this.logger.error(i), this.logger.debug("Could not load navigation tree.");
26
26
  }
27
27
  return a;
28
28
  }
29
- // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
30
- // eslint-disable-next-line max-statements
31
- getParentNodesId(r) {
32
- const t = [];
33
- if (r) {
34
- const a = r.document.getIdentifier();
35
- if (!a)
36
- return this.logger.debug(
37
- `No identifier found for page ${r.name}, cannot resolve parents.`
38
- ), [];
39
- const i = a.replace(/\.WebHome$/, "").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));
40
- let e = "", n;
41
- for (n = 0; n < i.length - 1; n++)
42
- e += i[n], t.push(`document:xwiki:${e}.WebHome`), e += ".";
43
- t.push(`document:xwiki:${a}`);
29
+ getParentNodesId(t, r = !0) {
30
+ const a = [];
31
+ if (t.space) {
32
+ let e = "";
33
+ for (const i of t.space.names)
34
+ e += i, a.push(`document:xwiki:${e}.WebHome`), e += ".";
35
+ t.name != "WebHome" && r && a.push(
36
+ `document:xwiki:${this.referenceSerializer.serialize(t)}`
37
+ );
44
38
  }
45
- return t;
39
+ return a;
46
40
  }
47
41
  // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
48
42
  // eslint-disable-next-line max-statements
49
- async fetchNodes(r, t, a) {
50
- const i = [], e = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, ""), n = new URL(
43
+ async fetchNodes(t, r, a) {
44
+ const e = [], i = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, ""), n = new URL(
51
45
  `${this.cristalApp.getWikiConfig().baseURL}/bin/get`
52
46
  );
53
47
  n.search = new URLSearchParams([
54
- ["id", r],
48
+ ["id", t],
55
49
  ["outputSyntax", "plain"],
56
50
  ["sheet", "XWiki.DocumentTree"],
57
51
  ["data", "children"],
@@ -60,17 +54,17 @@ let h = class {
60
54
  ["showTranslations", "false"],
61
55
  ["showAttachments", "false"]
62
56
  ]).toString();
63
- const d = await (await fetch(n, { headers: t })).json();
57
+ const d = await (await fetch(n, { headers: r })).json();
64
58
  for (const o of d)
65
59
  if (o.id == "pagination:wiki:xwiki")
66
- i.push(
67
- ...await this.fetchNodes(r, t, o.data.offset)
60
+ e.push(
61
+ ...await this.fetchNodes(t, r, o.data.offset)
68
62
  );
69
63
  else if (!["attachments", "translations"].includes(o.data.type) && o.a_attr) {
70
64
  const p = this.urlParser.parse(
71
- `${e}${o.a_attr.href}`
65
+ `${i}${o.a_attr.href}`
72
66
  );
73
- i.push({
67
+ e.push({
74
68
  id: o.id,
75
69
  label: o.text,
76
70
  location: p.space,
@@ -80,14 +74,15 @@ let h = class {
80
74
  page: this.referenceSerializer.serialize(p)
81
75
  }
82
76
  }).href,
83
- has_children: o.children
77
+ has_children: o.children,
78
+ is_terminal: !o.id.endsWith(".WebHome")
84
79
  });
85
80
  }
86
- return i;
81
+ return e;
87
82
  }
88
83
  };
89
- h = w([
90
- f(),
84
+ h = v([
85
+ g(),
91
86
  s(0, c("Logger")),
92
87
  s(1, c("CristalApp")),
93
88
  s(2, c("AuthenticationManagerProvider")),
@@ -96,12 +91,12 @@ h = w([
96
91
  s(4, c("ModelReferenceSerializer")),
97
92
  s(4, u("XWiki"))
98
93
  ], h);
99
- class R {
100
- constructor(t) {
101
- t.bind(g).to(h).inSingletonScope().whenTargetNamed("XWiki");
94
+ class W {
95
+ constructor(r) {
96
+ r.bind(f).to(h).inSingletonScope().whenNamed("XWiki");
102
97
  }
103
98
  }
104
99
  export {
105
- R as ComponentInit
100
+ W as ComponentInit
106
101
  };
107
102
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/components/componentsInit.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { name as NavigationTreeSourceName } from \"@xwiki/cristal-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/cristal-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/cristal-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/cristal-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/cristal-navigation-tree-api\";\n\n/**\n * Implementation of NavigationTreeSource for the XWiki backend.\n *\n * @since 0.10\n **/\n@injectable()\nclass XWikiNavigationTreeSource implements NavigationTreeSource {\n constructor(\n @inject<Logger>(\"Logger\") private readonly logger: Logger,\n @inject<CristalApp>(\"CristalApp\") private readonly cristalApp: CristalApp,\n @inject<AuthenticationManagerProvider>(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n @inject<RemoteURLParser>(\"RemoteURLParser\")\n @named(\"XWiki\")\n private readonly urlParser: RemoteURLParser,\n @inject<ModelReferenceSerializer>(\"ModelReferenceSerializer\")\n @named(\"XWiki\")\n private readonly referenceSerializer: ModelReferenceSerializer,\n ) {\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\n\n try {\n const authorization = await this.authenticationManagerProvider\n .get()\n ?.getAuthorizationHeader();\n const headers: { Accept: string; Authorization?: string } = {\n Accept: \"application/json\",\n };\n\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n navigationTree.push(...(await this.fetchNodes(currentId, headers, 0)));\n } catch (error) {\n this.logger.error(error);\n this.logger.debug(\"Could not load navigation tree.\");\n }\n return navigationTree;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n getParentNodesId(page?: PageData): Array<string> {\n const result = [];\n if (page) {\n const documentId = page.document.getIdentifier();\n if (!documentId) {\n this.logger.debug(\n `No identifier found for page ${page.name}, cannot resolve parents.`,\n );\n return [];\n }\n // TODO: Use a page resolver instead when CRISTAL-234 is fixed.\n const parents = documentId\n .replace(/\\.WebHome$/, \"\")\n .split(/(?<![^\\\\](?:\\\\\\\\)*\\\\)\\./);\n let currentParent = \"\";\n let i;\n for (i = 0; i < parents.length - 1; i++) {\n currentParent += parents[i];\n // TODO: Support subwikis.\n result.push(`document:xwiki:${currentParent}.WebHome`);\n currentParent += \".\";\n }\n result.push(`document:xwiki:${documentId}`);\n }\n return result;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n private async fetchNodes(\n currentId: string,\n headers: { Accept: string; Authorization?: string },\n offset: number,\n ): Promise<Array<NavigationTreeNode>> {\n const nodes: Array<NavigationTreeNode> = [];\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n\n const navigationTreeRequestUrl = new URL(\n `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,\n );\n navigationTreeRequestUrl.search = new URLSearchParams([\n [\"id\", currentId],\n [\"outputSyntax\", \"plain\"],\n [\"sheet\", \"XWiki.DocumentTree\"],\n [\"data\", \"children\"],\n [\"compact\", \"true\"],\n [\"offset\", offset.toString()],\n [\"showTranslations\", \"false\"],\n [\"showAttachments\", \"false\"],\n ]).toString();\n\n const response = await fetch(navigationTreeRequestUrl, { headers });\n const jsonResponse: [\n {\n id: string;\n text: string;\n children: boolean;\n data: { type: string; offset: number };\n a_attr?: { href: string };\n },\n ] = await response.json();\n for (const treeNode of jsonResponse) {\n if (treeNode.id == \"pagination:wiki:xwiki\") {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, treeNode.data.offset)),\n );\n } else if (\n ![\"attachments\", \"translations\"].includes(treeNode.data.type) &&\n treeNode.a_attr\n ) {\n const documentReference = this.urlParser.parse(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )! as DocumentReference;\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: documentReference.space!,\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: this.referenceSerializer.serialize(documentReference),\n },\n }).href,\n has_children: treeNode.children,\n });\n }\n }\n\n return nodes;\n }\n}\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<NavigationTreeSource>(NavigationTreeSourceName)\n .to(XWikiNavigationTreeSource)\n .inSingletonScope()\n .whenTargetNamed(\"XWiki\");\n }\n}\n"],"names":["XWikiNavigationTreeSource","logger","cristalApp","authenticationManagerProvider","urlParser","referenceSerializer","id","currentId","navigationTree","authorization","_a","headers","error","page","result","documentId","parents","currentParent","i","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAsCA,IAAMA,IAAN,MAAgE;AAAA,EAC9D,YAC6CC,GACQC,GAE3CC,GAGSC,GAGAC,GACjB;AAV2C,SAAA,SAAAJ,GACQ,KAAA,aAAAC,GAE3C,KAAA,gCAAAC,GAGS,KAAA,YAAAC,GAGA,KAAA,sBAAAC,GAEjB,KAAK,OAAO;AAAA,MACV;AAAA,IACF;AAAA,EAAA;AAAA;AAAA;AAAA,EAKF,MAAM,cAAcC,GAAiD;;AAC7D,UAAAC,IAAYD,KAAU,KACtBE,IAA4C,CAAC;AAE/C,QAAA;AACF,YAAMC,IAAgB,QAAMC,IAAA,KAAK,8BAC9B,IAAA,MADyB,gBAAAA,EAExB,2BACEC,IAAsD;AAAA,QAC1D,QAAQ;AAAA,MACV;AAEA,MAAIF,MACFE,EAAQ,gBA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AAA,EACA,gBAAgB,OAAO;AAAA,EAAA;AAE9B;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/components/componentsInit.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { name as NavigationTreeSourceName } from \"@xwiki/cristal-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/cristal-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/cristal-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/cristal-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/cristal-navigation-tree-api\";\n\n/**\n * Implementation of NavigationTreeSource for the XWiki backend.\n *\n * @since 0.10\n **/\n@injectable()\nclass XWikiNavigationTreeSource implements NavigationTreeSource {\n constructor(\n @inject(\"Logger\") private readonly logger: Logger,\n @inject(\"CristalApp\") private readonly cristalApp: CristalApp,\n @inject(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n @inject(\"RemoteURLParser\")\n @named(\"XWiki\")\n private readonly urlParser: RemoteURLParser,\n @inject(\"ModelReferenceSerializer\")\n @named(\"XWiki\")\n private readonly referenceSerializer: ModelReferenceSerializer,\n ) {\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\n\n try {\n const authorization = await this.authenticationManagerProvider\n .get()\n ?.getAuthorizationHeader();\n const headers: { Accept: string; Authorization?: string } = {\n Accept: \"application/json\",\n };\n\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n navigationTree.push(...(await this.fetchNodes(currentId, headers, 0)));\n } catch (error) {\n this.logger.error(error);\n this.logger.debug(\"Could not load navigation tree.\");\n }\n return navigationTree;\n }\n\n getParentNodesId(\n page: DocumentReference,\n includeTerminal: boolean = true,\n ): Array<string> {\n const result = [];\n if (page.space) {\n let currentParent = \"\";\n for (const parent of page.space!.names) {\n currentParent += parent;\n // TODO: Support subwikis.\n result.push(`document:xwiki:${currentParent}.WebHome`);\n currentParent += \".\";\n }\n if (page.name != \"WebHome\" && includeTerminal) {\n result.push(\n `document:xwiki:${this.referenceSerializer.serialize(page)}`,\n );\n }\n }\n return result;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n private async fetchNodes(\n currentId: string,\n headers: { Accept: string; Authorization?: string },\n offset: number,\n ): Promise<Array<NavigationTreeNode>> {\n const nodes: Array<NavigationTreeNode> = [];\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n\n const navigationTreeRequestUrl = new URL(\n `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,\n );\n navigationTreeRequestUrl.search = new URLSearchParams([\n [\"id\", currentId],\n [\"outputSyntax\", \"plain\"],\n [\"sheet\", \"XWiki.DocumentTree\"],\n [\"data\", \"children\"],\n [\"compact\", \"true\"],\n [\"offset\", offset.toString()],\n [\"showTranslations\", \"false\"],\n [\"showAttachments\", \"false\"],\n ]).toString();\n\n const response = await fetch(navigationTreeRequestUrl, { headers });\n const jsonResponse: [\n {\n id: string;\n text: string;\n children: boolean;\n data: { type: string; offset: number };\n a_attr?: { href: string };\n },\n ] = await response.json();\n for (const treeNode of jsonResponse) {\n if (treeNode.id == \"pagination:wiki:xwiki\") {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, treeNode.data.offset)),\n );\n } else if (\n ![\"attachments\", \"translations\"].includes(treeNode.data.type) &&\n treeNode.a_attr\n ) {\n const documentReference = this.urlParser.parse(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )! as DocumentReference;\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: documentReference.space!,\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: this.referenceSerializer.serialize(documentReference),\n },\n }).href,\n has_children: treeNode.children,\n is_terminal: !treeNode.id.endsWith(\".WebHome\"),\n });\n }\n }\n\n return nodes;\n }\n}\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<NavigationTreeSource>(NavigationTreeSourceName)\n .to(XWikiNavigationTreeSource)\n .inSingletonScope()\n .whenNamed(\"XWiki\");\n }\n}\n"],"names":["XWikiNavigationTreeSource","logger","cristalApp","authenticationManagerProvider","urlParser","referenceSerializer","id","currentId","navigationTree","authorization","_a","headers","error","page","includeTerminal","result","currentParent","parent","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAsCA,IAAMA,IAAN,MAAgE;AAAA,EAC9D,YACqCC,GACIC,GAE/BC,GAGSC,GAGAC,GACjB;AAVmC,SAAA,SAAAJ,GACI,KAAA,aAAAC,GAE/B,KAAA,gCAAAC,GAGS,KAAA,YAAAC,GAGA,KAAA,sBAAAC,GAEjB,KAAK,OAAO;AAAA,MACV;AAAA,IACF;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GAVZ3B,CAAA;AAsIC,MAAM4B,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAE7B,IAAAA,EAAA,KAA2BC,CAAwB,EACnD,GAAG9B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO;AAAA,EAAA;AAExB;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@xwiki/cristal-navigation-tree-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","@xwiki/cristal-navigation-tree-api","inversify"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o["cristal_navigation-tree-xwiki"]={},o.cristalNavigationTreeApi,o.inversify))})(this,function(o,u,s){"use strict";var g=Object.defineProperty,f=Object.getOwnPropertyDescriptor,m=(n,t,r,i)=>{for(var e=i>1?void 0:i?f(t,r):t,a=n.length-1,h;a>=0;a--)(h=n[a])&&(e=(i?h(t,r,e):h(e))||e);return i&&e&&g(t,r,e),e},l=(n,t)=>(r,i)=>t(r,i,n);let p=class{constructor(n,t,r,i,e){this.logger=n,this.cristalApp=t,this.authenticationManagerProvider=r,this.urlParser=i,this.referenceSerializer=e,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource")}async getChildNodes(n){var i;const t=n||"#",r=[];try{const e=await((i=this.authenticationManagerProvider.get())==null?void 0:i.getAuthorizationHeader()),a={Accept:"application/json"};e&&(a.Authorization=e),r.push(...await this.fetchNodes(t,a,0))}catch(e){this.logger.error(e),this.logger.debug("Could not load navigation tree.")}return r}getParentNodesId(n){const t=[];if(n){const r=n.document.getIdentifier();if(!r)return this.logger.debug(`No identifier found for page ${n.name}, cannot resolve parents.`),[];const i=r.replace(/\.WebHome$/,"").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));let e="",a;for(a=0;a<i.length-1;a++)e+=i[a],t.push(`document:xwiki:${e}.WebHome`),e+=".";t.push(`document:xwiki:${r}`)}return t}async fetchNodes(n,t,r){const i=[],e=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,""),a=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);a.search=new URLSearchParams([["id",n],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"],["offset",r.toString()],["showTranslations","false"],["showAttachments","false"]]).toString();const v=await(await fetch(a,{headers:t})).json();for(const c of v)if(c.id=="pagination:wiki:xwiki")i.push(...await this.fetchNodes(n,t,c.data.offset));else if(!["attachments","translations"].includes(c.data.type)&&c.a_attr){const d=this.urlParser.parse(`${e}${c.a_attr.href}`);i.push({id:c.id,label:c.text,location:d.space,url:this.cristalApp.getRouter().resolve({name:"view",params:{page:this.referenceSerializer.serialize(d)}}).href,has_children:c.children})}return i}};p=m([s.injectable(),l(0,s.inject("Logger")),l(1,s.inject("CristalApp")),l(2,s.inject("AuthenticationManagerProvider")),l(3,s.inject("RemoteURLParser")),l(3,s.named("XWiki")),l(4,s.inject("ModelReferenceSerializer")),l(4,s.named("XWiki"))],p);class w{constructor(t){t.bind(u.name).to(p).inSingletonScope().whenTargetNamed("XWiki")}}o.ComponentInit=w,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@xwiki/cristal-navigation-tree-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","@xwiki/cristal-navigation-tree-api","inversify"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s["cristal_navigation-tree-xwiki"]={},s.cristalNavigationTreeApi,s.inversify))})(this,function(s,h,c){"use strict";var f=Object.defineProperty,g=Object.getOwnPropertyDescriptor,m=(t,n,r,e)=>{for(var i=e>1?void 0:e?g(n,r):n,a=t.length-1,u;a>=0;a--)(u=t[a])&&(i=(e?u(n,r,i):u(i))||i);return e&&i&&f(n,r,i),i},l=(t,n)=>(r,e)=>n(r,e,t);let p=class{constructor(t,n,r,e,i){this.logger=t,this.cristalApp=n,this.authenticationManagerProvider=r,this.urlParser=e,this.referenceSerializer=i,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource")}async getChildNodes(t){var e;const n=t||"#",r=[];try{const i=await((e=this.authenticationManagerProvider.get())==null?void 0:e.getAuthorizationHeader()),a={Accept:"application/json"};i&&(a.Authorization=i),r.push(...await this.fetchNodes(n,a,0))}catch(i){this.logger.error(i),this.logger.debug("Could not load navigation tree.")}return r}getParentNodesId(t,n=!0){const r=[];if(t.space){let e="";for(const i of t.space.names)e+=i,r.push(`document:xwiki:${e}.WebHome`),e+=".";t.name!="WebHome"&&n&&r.push(`document:xwiki:${this.referenceSerializer.serialize(t)}`)}return r}async fetchNodes(t,n,r){const e=[],i=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,""),a=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);a.search=new URLSearchParams([["id",t],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"],["offset",r.toString()],["showTranslations","false"],["showAttachments","false"]]).toString();const v=await(await fetch(a,{headers:n})).json();for(const o of v)if(o.id=="pagination:wiki:xwiki")e.push(...await this.fetchNodes(t,n,o.data.offset));else if(!["attachments","translations"].includes(o.data.type)&&o.a_attr){const d=this.urlParser.parse(`${i}${o.a_attr.href}`);e.push({id:o.id,label:o.text,location:d.space,url:this.cristalApp.getRouter().resolve({name:"view",params:{page:this.referenceSerializer.serialize(d)}}).href,has_children:o.children,is_terminal:!o.id.endsWith(".WebHome")})}return e}};p=m([c.injectable(),l(0,c.inject("Logger")),l(1,c.inject("CristalApp")),l(2,c.inject("AuthenticationManagerProvider")),l(3,c.inject("RemoteURLParser")),l(3,c.named("XWiki")),l(4,c.inject("ModelReferenceSerializer")),l(4,c.named("XWiki"))],p);class w{constructor(n){n.bind(h.name).to(p).inSingletonScope().whenNamed("XWiki")}}s.ComponentInit=w,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/components/componentsInit.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { name as NavigationTreeSourceName } from \"@xwiki/cristal-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/cristal-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/cristal-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/cristal-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/cristal-navigation-tree-api\";\n\n/**\n * Implementation of NavigationTreeSource for the XWiki backend.\n *\n * @since 0.10\n **/\n@injectable()\nclass XWikiNavigationTreeSource implements NavigationTreeSource {\n constructor(\n @inject<Logger>(\"Logger\") private readonly logger: Logger,\n @inject<CristalApp>(\"CristalApp\") private readonly cristalApp: CristalApp,\n @inject<AuthenticationManagerProvider>(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n @inject<RemoteURLParser>(\"RemoteURLParser\")\n @named(\"XWiki\")\n private readonly urlParser: RemoteURLParser,\n @inject<ModelReferenceSerializer>(\"ModelReferenceSerializer\")\n @named(\"XWiki\")\n private readonly referenceSerializer: ModelReferenceSerializer,\n ) {\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\n\n try {\n const authorization = await this.authenticationManagerProvider\n .get()\n ?.getAuthorizationHeader();\n const headers: { Accept: string; Authorization?: string } = {\n Accept: \"application/json\",\n };\n\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n navigationTree.push(...(await this.fetchNodes(currentId, headers, 0)));\n } catch (error) {\n this.logger.error(error);\n this.logger.debug(\"Could not load navigation tree.\");\n }\n return navigationTree;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n getParentNodesId(page?: PageData): Array<string> {\n const result = [];\n if (page) {\n const documentId = page.document.getIdentifier();\n if (!documentId) {\n this.logger.debug(\n `No identifier found for page ${page.name}, cannot resolve parents.`,\n );\n return [];\n }\n // TODO: Use a page resolver instead when CRISTAL-234 is fixed.\n const parents = documentId\n .replace(/\\.WebHome$/, \"\")\n .split(/(?<![^\\\\](?:\\\\\\\\)*\\\\)\\./);\n let currentParent = \"\";\n let i;\n for (i = 0; i < parents.length - 1; i++) {\n currentParent += parents[i];\n // TODO: Support subwikis.\n result.push(`document:xwiki:${currentParent}.WebHome`);\n currentParent += \".\";\n }\n result.push(`document:xwiki:${documentId}`);\n }\n return result;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n private async fetchNodes(\n currentId: string,\n headers: { Accept: string; Authorization?: string },\n offset: number,\n ): Promise<Array<NavigationTreeNode>> {\n const nodes: Array<NavigationTreeNode> = [];\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n\n const navigationTreeRequestUrl = new URL(\n `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,\n );\n navigationTreeRequestUrl.search = new URLSearchParams([\n [\"id\", currentId],\n [\"outputSyntax\", \"plain\"],\n [\"sheet\", \"XWiki.DocumentTree\"],\n [\"data\", \"children\"],\n [\"compact\", \"true\"],\n [\"offset\", offset.toString()],\n [\"showTranslations\", \"false\"],\n [\"showAttachments\", \"false\"],\n ]).toString();\n\n const response = await fetch(navigationTreeRequestUrl, { headers });\n const jsonResponse: [\n {\n id: string;\n text: string;\n children: boolean;\n data: { type: string; offset: number };\n a_attr?: { href: string };\n },\n ] = await response.json();\n for (const treeNode of jsonResponse) {\n if (treeNode.id == \"pagination:wiki:xwiki\") {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, treeNode.data.offset)),\n );\n } else if (\n ![\"attachments\", \"translations\"].includes(treeNode.data.type) &&\n treeNode.a_attr\n ) {\n const documentReference = this.urlParser.parse(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )! as DocumentReference;\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: documentReference.space!,\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: this.referenceSerializer.serialize(documentReference),\n },\n }).href,\n has_children: treeNode.children,\n });\n }\n }\n\n return nodes;\n }\n}\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<NavigationTreeSource>(NavigationTreeSourceName)\n .to(XWikiNavigationTreeSource)\n .inSingletonScope()\n .whenTargetNamed(\"XWiki\");\n }\n}\n"],"names":["XWikiNavigationTreeSource","logger","cristalApp","authenticationManagerProvider","urlParser","referenceSerializer","id","currentId","navigationTree","authorization","_a","headers","error","page","result","documentId","parents","currentParent","i","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"gnBAsCA,IAAMA,EAAN,KAAgE,CAC9D,YAC6C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A,KAA2BC,EAAwB,IAAA,EACnD,GAAG/B,CAAyB,EAC5B,iBAAA,EACA,gBAAgB,OAAO,CAAA,CAE9B"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/components/componentsInit.ts"],"sourcesContent":["/*\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport { name as NavigationTreeSourceName } from \"@xwiki/cristal-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/cristal-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/cristal-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/cristal-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/cristal-navigation-tree-api\";\n\n/**\n * Implementation of NavigationTreeSource for the XWiki backend.\n *\n * @since 0.10\n **/\n@injectable()\nclass XWikiNavigationTreeSource implements NavigationTreeSource {\n constructor(\n @inject(\"Logger\") private readonly logger: Logger,\n @inject(\"CristalApp\") private readonly cristalApp: CristalApp,\n @inject(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n @inject(\"RemoteURLParser\")\n @named(\"XWiki\")\n private readonly urlParser: RemoteURLParser,\n @inject(\"ModelReferenceSerializer\")\n @named(\"XWiki\")\n private readonly referenceSerializer: ModelReferenceSerializer,\n ) {\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\n\n try {\n const authorization = await this.authenticationManagerProvider\n .get()\n ?.getAuthorizationHeader();\n const headers: { Accept: string; Authorization?: string } = {\n Accept: \"application/json\",\n };\n\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n navigationTree.push(...(await this.fetchNodes(currentId, headers, 0)));\n } catch (error) {\n this.logger.error(error);\n this.logger.debug(\"Could not load navigation tree.\");\n }\n return navigationTree;\n }\n\n getParentNodesId(\n page: DocumentReference,\n includeTerminal: boolean = true,\n ): Array<string> {\n const result = [];\n if (page.space) {\n let currentParent = \"\";\n for (const parent of page.space!.names) {\n currentParent += parent;\n // TODO: Support subwikis.\n result.push(`document:xwiki:${currentParent}.WebHome`);\n currentParent += \".\";\n }\n if (page.name != \"WebHome\" && includeTerminal) {\n result.push(\n `document:xwiki:${this.referenceSerializer.serialize(page)}`,\n );\n }\n }\n return result;\n }\n\n // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.\n // eslint-disable-next-line max-statements\n private async fetchNodes(\n currentId: string,\n headers: { Accept: string; Authorization?: string },\n offset: number,\n ): Promise<Array<NavigationTreeNode>> {\n const nodes: Array<NavigationTreeNode> = [];\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n\n const navigationTreeRequestUrl = new URL(\n `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,\n );\n navigationTreeRequestUrl.search = new URLSearchParams([\n [\"id\", currentId],\n [\"outputSyntax\", \"plain\"],\n [\"sheet\", \"XWiki.DocumentTree\"],\n [\"data\", \"children\"],\n [\"compact\", \"true\"],\n [\"offset\", offset.toString()],\n [\"showTranslations\", \"false\"],\n [\"showAttachments\", \"false\"],\n ]).toString();\n\n const response = await fetch(navigationTreeRequestUrl, { headers });\n const jsonResponse: [\n {\n id: string;\n text: string;\n children: boolean;\n data: { type: string; offset: number };\n a_attr?: { href: string };\n },\n ] = await response.json();\n for (const treeNode of jsonResponse) {\n if (treeNode.id == \"pagination:wiki:xwiki\") {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, treeNode.data.offset)),\n );\n } else if (\n ![\"attachments\", \"translations\"].includes(treeNode.data.type) &&\n treeNode.a_attr\n ) {\n const documentReference = this.urlParser.parse(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )! as DocumentReference;\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: documentReference.space!,\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: this.referenceSerializer.serialize(documentReference),\n },\n }).href,\n has_children: treeNode.children,\n is_terminal: !treeNode.id.endsWith(\".WebHome\"),\n });\n }\n }\n\n return nodes;\n }\n}\n\nexport class ComponentInit {\n constructor(container: Container) {\n container\n .bind<NavigationTreeSource>(NavigationTreeSourceName)\n .to(XWikiNavigationTreeSource)\n .inSingletonScope()\n .whenNamed(\"XWiki\");\n }\n}\n"],"names":["XWikiNavigationTreeSource","logger","cristalApp","authenticationManagerProvider","urlParser","referenceSerializer","id","currentId","navigationTree","authorization","_a","headers","error","page","includeTerminal","result","currentParent","parent","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"gnBAsCA,IAAMA,EAAN,KAAgE,CAC9D,YACqCC,EACIC,EAE/BC,EAGSC,EAGAC,EACjB,CAVmC,KAAA,OAAAJ,EACI,KAAA,WAAAC,EAE/B,KAAA,8BAAAC,EAGS,KAAA,UAAAC,EAGA,KAAA,oBAAAC,EA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MATa,MAAM,MAAMD,EAA0B,CAAE,QAAAV,EAAS,GAS/C,KAAK,EACxB,UAAWY,KAAYD,EACjB,GAAAC,EAAS,IAAM,wBACXJ,EAAA,KACJ,GAAI,MAAM,KAAK,WAAWZ,EAAWI,EAASY,EAAS,KAAK,MAAM,CACpE,UAEA,CAAC,CAAC,cAAe,cAAc,EAAE,SAASA,EAAS,KAAK,IAAI,GAC5DA,EAAS,OACT,CACM,MAAAC,EAAoB,KAAK,UAAU,MACvC,GAAGJ,CAAY,GAAGG,EAAS,OAAO,IAAI,EACxC,EACAJ,EAAM,KAAK,CACT,GAAII,EAAS,GACb,MAAOA,EAAS,KAChB,SAAUC,EAAkB,MAC5B,IAAK,KAAK,WAAW,UAAA,EAAY,QAAQ,CACvC,KAAM,OACN,OAAQ,CACN,KAAM,KAAK,oBAAoB,UAAUA,CAAiB,CAAA,CAE7D,CAAA,EAAE,KACH,aAAcD,EAAS,SACvB,YAAa,CAACA,EAAS,GAAG,SAAS,UAAU,CAAA,CAC9C,CAAA,CAIE,OAAAJ,CAAA,CAEX,EApIMnB,EAANyB,EAAA,CADCC,aAAW,EAGPC,aAAO,QAAQ,CAAA,EACfA,aAAO,YAAY,CAAA,EACnBA,aAAO,+BAA+B,CAAA,EAEtCA,aAAO,iBAAiB,CAAA,EACxBA,YAAM,OAAO,CAAA,EAEbA,aAAO,0BAA0B,CAAA,EACjCA,YAAM,OAAO,CAAA,CAAA,EAVZ3B,CAAA,EAsIC,MAAM4B,CAAc,CACzB,YAAYC,EAAsB,CAE7BA,EAAA,KAA2BC,EAAwB,IAAA,EACnD,GAAG9B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO,CAAA,CAExB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-navigation-tree-xwiki",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -22,22 +22,22 @@
22
22
  },
23
23
  "main": "./dist/index.es.js",
24
24
  "dependencies": {
25
- "inversify": "6.2.1",
26
- "@xwiki/cristal-authentication-api": "0.14.0",
27
- "@xwiki/cristal-model-reference-api": "0.14.0",
28
- "@xwiki/cristal-model-api": "0.14.0",
29
- "@xwiki/cristal-model-remote-url-api": "0.14.0",
30
- "@xwiki/cristal-api": "0.14.0",
31
- "@xwiki/cristal-navigation-tree-api": "0.14.0"
25
+ "inversify": "7.1.0",
26
+ "@xwiki/cristal-api": "0.16.0",
27
+ "@xwiki/cristal-authentication-api": "0.16.0",
28
+ "@xwiki/cristal-model-api": "0.16.0",
29
+ "@xwiki/cristal-model-reference-api": "0.16.0",
30
+ "@xwiki/cristal-model-remote-url-api": "0.16.0",
31
+ "@xwiki/cristal-navigation-tree-api": "0.16.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "reflect-metadata": "0.2.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "reflect-metadata": "0.2.2",
38
- "typescript": "5.7.3",
39
- "vite": "6.0.11",
40
- "@xwiki/cristal-dev-config": "0.14.0"
38
+ "typescript": "5.8.2",
39
+ "vite": "6.2.2",
40
+ "@xwiki/cristal-dev-config": "0.16.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsc --project tsconfig.json && vite build",
@@ -20,7 +20,7 @@
20
20
 
21
21
  import { name as NavigationTreeSourceName } from "@xwiki/cristal-navigation-tree-api";
22
22
  import { Container, inject, injectable, named } from "inversify";
23
- import type { CristalApp, Logger, PageData } from "@xwiki/cristal-api";
23
+ import type { CristalApp, Logger } from "@xwiki/cristal-api";
24
24
  import type { AuthenticationManagerProvider } from "@xwiki/cristal-authentication-api";
25
25
  import type { DocumentReference } from "@xwiki/cristal-model-api";
26
26
  import type { ModelReferenceSerializer } from "@xwiki/cristal-model-reference-api";
@@ -38,14 +38,14 @@ import type {
38
38
  @injectable()
39
39
  class XWikiNavigationTreeSource implements NavigationTreeSource {
40
40
  constructor(
41
- @inject<Logger>("Logger") private readonly logger: Logger,
42
- @inject<CristalApp>("CristalApp") private readonly cristalApp: CristalApp,
43
- @inject<AuthenticationManagerProvider>("AuthenticationManagerProvider")
41
+ @inject("Logger") private readonly logger: Logger,
42
+ @inject("CristalApp") private readonly cristalApp: CristalApp,
43
+ @inject("AuthenticationManagerProvider")
44
44
  private authenticationManagerProvider: AuthenticationManagerProvider,
45
- @inject<RemoteURLParser>("RemoteURLParser")
45
+ @inject("RemoteURLParser")
46
46
  @named("XWiki")
47
47
  private readonly urlParser: RemoteURLParser,
48
- @inject<ModelReferenceSerializer>("ModelReferenceSerializer")
48
+ @inject("ModelReferenceSerializer")
49
49
  @named("XWiki")
50
50
  private readonly referenceSerializer: ModelReferenceSerializer,
51
51
  ) {
@@ -80,31 +80,24 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
80
80
  return navigationTree;
81
81
  }
82
82
 
83
- // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
84
- // eslint-disable-next-line max-statements
85
- getParentNodesId(page?: PageData): Array<string> {
83
+ getParentNodesId(
84
+ page: DocumentReference,
85
+ includeTerminal: boolean = true,
86
+ ): Array<string> {
86
87
  const result = [];
87
- if (page) {
88
- const documentId = page.document.getIdentifier();
89
- if (!documentId) {
90
- this.logger.debug(
91
- `No identifier found for page ${page.name}, cannot resolve parents.`,
92
- );
93
- return [];
94
- }
95
- // TODO: Use a page resolver instead when CRISTAL-234 is fixed.
96
- const parents = documentId
97
- .replace(/\.WebHome$/, "")
98
- .split(/(?<![^\\](?:\\\\)*\\)\./);
88
+ if (page.space) {
99
89
  let currentParent = "";
100
- let i;
101
- for (i = 0; i < parents.length - 1; i++) {
102
- currentParent += parents[i];
90
+ for (const parent of page.space!.names) {
91
+ currentParent += parent;
103
92
  // TODO: Support subwikis.
104
93
  result.push(`document:xwiki:${currentParent}.WebHome`);
105
94
  currentParent += ".";
106
95
  }
107
- result.push(`document:xwiki:${documentId}`);
96
+ if (page.name != "WebHome" && includeTerminal) {
97
+ result.push(
98
+ `document:xwiki:${this.referenceSerializer.serialize(page)}`,
99
+ );
100
+ }
108
101
  }
109
102
  return result;
110
103
  }
@@ -168,6 +161,7 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
168
161
  },
169
162
  }).href,
170
163
  has_children: treeNode.children,
164
+ is_terminal: !treeNode.id.endsWith(".WebHome"),
171
165
  });
172
166
  }
173
167
  }
@@ -182,6 +176,6 @@ export class ComponentInit {
182
176
  .bind<NavigationTreeSource>(NavigationTreeSourceName)
183
177
  .to(XWikiNavigationTreeSource)
184
178
  .inSingletonScope()
185
- .whenTargetNamed("XWiki");
179
+ .whenNamed("XWiki");
186
180
  }
187
181
  }