@xwiki/cristal-navigation-tree-xwiki 0.22.0 → 0.23.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,21 @@
1
1
  # @xwiki/cristal-navigation-tree-xwiki
2
2
 
3
+ ## 0.23.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Cristal 0.23 Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @xwiki/cristal-api@0.23.0
13
+ - @xwiki/cristal-authentication-api@0.23.0
14
+ - @xwiki/cristal-model-api@0.23.0
15
+ - @xwiki/cristal-model-reference-api@0.23.0
16
+ - @xwiki/cristal-model-remote-url-api@0.23.0
17
+ - @xwiki/cristal-navigation-tree-api@0.23.0
18
+
3
19
  ## 0.22.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
- import { name as g } from "@xwiki/cristal-navigation-tree-api";
2
- import { injectable as f, inject as c, named as u } from "inversify";
1
+ import { name as d } from "@xwiki/cristal-navigation-tree-api";
2
+ import { injectable as f, inject as l, named as g } from "inversify";
3
3
  var m = Object.getOwnPropertyDescriptor, w = (t, i, a, e) => {
4
- for (var r = e > 1 ? void 0 : e ? m(i, a) : i, o = t.length - 1, l; o >= 0; o--)
5
- (l = t[o]) && (r = l(r) || r);
4
+ for (var r = e > 1 ? void 0 : e ? m(i, a) : i, n = t.length - 1, c; n >= 0; n--)
5
+ (c = t[n]) && (r = c(r) || r);
6
6
  return r;
7
7
  }, s = (t, i) => (a, e) => i(a, e, t);
8
8
  let h = class {
@@ -29,8 +29,8 @@ let h = class {
29
29
  const e = a ? [""] : [];
30
30
  if (t.space) {
31
31
  let r = "";
32
- for (const o of t.space.names)
33
- r += o, e.push(`document:xwiki:${r}.WebHome`), r += ".";
32
+ for (const n of t.space.names)
33
+ r += n, e.push(`document:xwiki:${r}.WebHome`), r += ".";
34
34
  t.name != "WebHome" && i && e.push(
35
35
  `document:xwiki:${this.referenceSerializer.serialize(t)}`
36
36
  );
@@ -40,59 +40,62 @@ let h = class {
40
40
  // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule.
41
41
  // eslint-disable-next-line max-statements
42
42
  async fetchNodes(t, i, a) {
43
- const e = [], r = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, ""), o = new URL(
43
+ const e = [], r = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, ""), n = 100, c = new URL(
44
44
  `${this.cristalApp.getWikiConfig().baseURL}/bin/get`
45
45
  );
46
- o.search = new URLSearchParams([
46
+ c.search = new URLSearchParams([
47
47
  ["id", t],
48
48
  ["outputSyntax", "plain"],
49
49
  ["sheet", "XWiki.DocumentTree"],
50
50
  ["data", "children"],
51
51
  ["compact", "true"],
52
52
  ["offset", a.toString()],
53
+ ["limit", n.toString()],
53
54
  ["showTranslations", "false"],
54
55
  ["showAttachments", "false"]
55
56
  ]).toString();
56
- const d = await (await fetch(o, { headers: i })).json();
57
- for (const n of d)
58
- if (n.id == "pagination:wiki:xwiki")
57
+ const p = await (await fetch(c, { headers: i })).json();
58
+ for (const o of p)
59
+ if (o.id == "pagination:wiki:xwiki")
59
60
  e.push(
60
- ...await this.fetchNodes(t, i, n.data.offset)
61
+ ...await this.fetchNodes(t, i, o.data.offset)
61
62
  );
62
- else if (!["attachments", "translations"].includes(n.data.type) && n.a_attr) {
63
- const p = this.urlParser.parse(
64
- `${r}${n.a_attr.href}`
63
+ else if (!["attachments", "translations"].includes(o.data.type) && o.a_attr) {
64
+ const u = this.urlParser.parse(
65
+ `${r}${o.a_attr.href}`
65
66
  );
66
67
  e.push({
67
- id: n.id,
68
- label: n.text,
69
- location: p.space,
68
+ id: o.id,
69
+ label: o.text,
70
+ location: u.space,
70
71
  url: this.cristalApp.getRouter().resolve({
71
72
  name: "view",
72
73
  params: {
73
- page: this.referenceSerializer.serialize(p)
74
+ page: this.referenceSerializer.serialize(u)
74
75
  }
75
76
  }).href,
76
- has_children: n.children,
77
- is_terminal: !n.id.endsWith(".WebHome")
77
+ has_children: o.children,
78
+ is_terminal: !o.id.endsWith(".WebHome")
78
79
  });
79
80
  }
80
- return e;
81
+ return p.length >= n && e.push(
82
+ ...await this.fetchNodes(t, i, a + n)
83
+ ), e;
81
84
  }
82
85
  };
83
86
  h = w([
84
87
  f(),
85
- s(0, c("Logger")),
86
- s(1, c("CristalApp")),
87
- s(2, c("AuthenticationManagerProvider")),
88
- s(3, c("RemoteURLParser")),
89
- s(3, u("XWiki")),
90
- s(4, c("ModelReferenceSerializer")),
91
- s(4, u("XWiki"))
88
+ s(0, l("Logger")),
89
+ s(1, l("CristalApp")),
90
+ s(2, l("AuthenticationManagerProvider")),
91
+ s(3, l("RemoteURLParser")),
92
+ s(3, g("XWiki")),
93
+ s(4, l("ModelReferenceSerializer")),
94
+ s(4, g("XWiki"))
92
95
  ], h);
93
96
  class W {
94
97
  constructor(i) {
95
- i.bind(g).to(h).inSingletonScope().whenNamed("XWiki");
98
+ i.bind(d).to(h).inSingletonScope().whenNamed("XWiki");
96
99
  }
97
100
  }
98
101
  export {
@@ -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 } 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 * @beta\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 includeRootNode?: boolean,\n ): Array<string> {\n const result = includeRootNode ? [\"\"] : [];\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\n/**\n * @beta\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","headers","error","page","includeTerminal","includeRootNode","result","currentParent","parent","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAuCA,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,IAAA;AAAA,EAEJ;AAAA;AAAA;AAAA,EAIA,MAAM,cAAcC,GAAiD;AACnE,UAAMC,IAAYD,KAAU,KACtBE,IAA4C,CAAA;AAElD,QAAI;AACF,YAAMC,IAAgB,MAAM,KAAK,8BAC9B,IAAA,GACC,uBAAA,GACEC,IAAsD;AAAA,QAC1D,QAAQ;AAAA,MAAA;AAGV,MAAID,MACFC,EAAQ,gBAAgBD,IAG1BD,EAAe,KAAK,GAAI,MAAM,KAAK,WAAWD,GAAWG,GAAS,CAAC,CAAE;AAAA,IACvE,SAASC,GAAO;AACd,WAAK,OAAO,MAAMA,CAAK,GACvB,KAAK,OAAO,MAAM,iCAAiC;AAAA,IACrD;AACA,WAAOH;AAAA,EACT;AAAA,EAEA,iBACEI,GACAC,IAA2B,I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A,EAAS,QACT;AACA,cAAMC,IAAoB,KAAK,UAAU;AAAA,UACvC,GAAGJ,CAAY,GAAGG,EAAS,OAAO,IAAI;AAAA,QAAA;AAExC,QAAAJ,EAAM,KAAK;AAAA,UACT,IAAII,EAAS;AAAA,UACb,OAAOA,EAAS;AAAA,UAChB,UAAUC,EAAkB;AAAA,UAC5B,KAAK,KAAK,WAAW,UAAA,EAAY,QAAQ;AAAA,YACvC,MAAM;AAAA,YACN,QAAQ;AAAA,cACN,MAAM,KAAK,oBAAoB,UAAUA,CAAiB;AAAA,YAAA;AAAA,UAC5D,CACD,EAAE;AAAA,UACH,cAAcD,EAAS;AAAA,UACvB,aAAa,CAACA,EAAS,GAAG,SAAS,UAAU;AAAA,QAAA,CAC9C;AAAA,MACH;AAGF,WAAOJ;AAAA,EACT;AACF;AArIMnB,IAANyB,EAAA;AAAA,EADCC,EAAA;AAAA,EAGIC,OAAO,QAAQ,CAAA;AAAA,EACfA,OAAO,YAAY,CAAA;AAAA,EACnBA,OAAO,+BAA+B,CAAA;AAAA,EAEtCA,OAAO,iBAAiB,CAAA;AAAA,EACxBA,OAAM,OAAO,CAAA;AAAA,EAEbA,OAAO,0BAA0B,CAAA;AAAA,EACjCA,OAAM,OAAO,CAAA;AAAA,GAVZ3B,CAAA;AA0IC,MAAM4B,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAChC,IAAAA,EACG,KAA2BC,CAAwB,EACnD,GAAG9B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO;AAAA,EACtB;AACF;"}
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 * @beta\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 includeRootNode?: boolean,\n ): Array<string> {\n const result = includeRootNode ? [\"\"] : [];\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 // The DocumentTree sheet sets a default limit of 15 items par page.\n // We use a greater one to reduce the number of requests to fetch them all.\n const limit = 100;\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 [\"limit\", limit.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 // Handle paging if necessary.\n if (jsonResponse.length >= limit) {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, offset + limit)),\n );\n }\n\n return nodes;\n }\n}\n\n/**\n * @beta\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","headers","error","page","includeTerminal","includeRootNode","result","currentParent","parent","offset","nodes","baseXWikiURL","limit","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAuCA,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,IAAA;AAAA,EAEJ;AAAA;AAAA;AAAA,EAIA,MAAM,cAAcC,GAAiD;AACnE,UAAMC,IAA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iBAAiB,CAAA;AAAA,EACxBA,OAAM,OAAO,CAAA;AAAA,EAEbA,OAAO,0BAA0B,CAAA;AAAA,EACjCA,OAAM,OAAO,CAAA;AAAA,GAVZ5B,CAAA;AAqJC,MAAM6B,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAChC,IAAAA,EACG,KAA2BC,CAAwB,EACnD,GAAG/B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO;AAAA,EACtB;AACF;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(o,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):(o=typeof globalThis<"u"?globalThis:o||self,h(o["cristal_navigation-tree-xwiki"]={},o.cristalNavigationTreeApi,o.inversify))})(this,(function(o,h,s){"use strict";var f=Object.getOwnPropertyDescriptor,g=(t,i,r,e)=>{for(var n=e>1?void 0:e?f(i,r):i,c=t.length-1,d;c>=0;c--)(d=t[c])&&(n=d(n)||n);return n},l=(t,i)=>(r,e)=>i(r,e,t);let u=class{constructor(t,i,r,e,n){this.logger=t,this.cristalApp=i,this.authenticationManagerProvider=r,this.urlParser=e,this.referenceSerializer=n,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource")}async getChildNodes(t){const i=t||"#",r=[];try{const e=await this.authenticationManagerProvider.get()?.getAuthorizationHeader(),n={Accept:"application/json"};e&&(n.Authorization=e),r.push(...await this.fetchNodes(i,n,0))}catch(e){this.logger.error(e),this.logger.debug("Could not load navigation tree.")}return r}getParentNodesId(t,i=!0,r){const e=r?[""]:[];if(t.space){let n="";for(const c of t.space.names)n+=c,e.push(`document:xwiki:${n}.WebHome`),n+=".";t.name!="WebHome"&&i&&e.push(`document:xwiki:${this.referenceSerializer.serialize(t)}`)}return e}async fetchNodes(t,i,r){const e=[],n=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,""),c=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);c.search=new URLSearchParams([["id",t],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"],["offset",r.toString()],["showTranslations","false"],["showAttachments","false"]]).toString();const w=await(await fetch(c,{headers:i})).json();for(const a of w)if(a.id=="pagination:wiki:xwiki")e.push(...await this.fetchNodes(t,i,a.data.offset));else if(!["attachments","translations"].includes(a.data.type)&&a.a_attr){const p=this.urlParser.parse(`${n}${a.a_attr.href}`);e.push({id:a.id,label:a.text,location:p.space,url:this.cristalApp.getRouter().resolve({name:"view",params:{page:this.referenceSerializer.serialize(p)}}).href,has_children:a.children,is_terminal:!a.id.endsWith(".WebHome")})}return e}};u=g([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"))],u);class m{constructor(i){i.bind(h.name).to(u).inSingletonScope().whenNamed("XWiki")}}o.ComponentInit=m,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.getOwnPropertyDescriptor,m=(t,i,a,e)=>{for(var n=e>1?void 0:e?f(i,a):i,r=t.length-1,u;r>=0;r--)(u=t[r])&&(n=u(n)||n);return n},l=(t,i)=>(a,e)=>i(a,e,t);let p=class{constructor(t,i,a,e,n){this.logger=t,this.cristalApp=i,this.authenticationManagerProvider=a,this.urlParser=e,this.referenceSerializer=n,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource")}async getChildNodes(t){const i=t||"#",a=[];try{const e=await this.authenticationManagerProvider.get()?.getAuthorizationHeader(),n={Accept:"application/json"};e&&(n.Authorization=e),a.push(...await this.fetchNodes(i,n,0))}catch(e){this.logger.error(e),this.logger.debug("Could not load navigation tree.")}return a}getParentNodesId(t,i=!0,a){const e=a?[""]:[];if(t.space){let n="";for(const r of t.space.names)n+=r,e.push(`document:xwiki:${n}.WebHome`),n+=".";t.name!="WebHome"&&i&&e.push(`document:xwiki:${this.referenceSerializer.serialize(t)}`)}return e}async fetchNodes(t,i,a){const e=[],n=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,""),r=100,u=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);u.search=new URLSearchParams([["id",t],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"],["offset",a.toString()],["limit",r.toString()],["showTranslations","false"],["showAttachments","false"]]).toString();const d=await(await fetch(u,{headers:i})).json();for(const o of d)if(o.id=="pagination:wiki:xwiki")e.push(...await this.fetchNodes(t,i,o.data.offset));else if(!["attachments","translations"].includes(o.data.type)&&o.a_attr){const g=this.urlParser.parse(`${n}${o.a_attr.href}`);e.push({id:o.id,label:o.text,location:g.space,url:this.cristalApp.getRouter().resolve({name:"view",params:{page:this.referenceSerializer.serialize(g)}}).href,has_children:o.children,is_terminal:!o.id.endsWith(".WebHome")})}return d.length>=r&&e.push(...await this.fetchNodes(t,i,a+r)),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(i){i.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 } 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 * @beta\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 includeRootNode?: boolean,\n ): Array<string> {\n const result = includeRootNode ? [\"\"] : [];\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\n/**\n * @beta\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","headers","error","page","includeTerminal","includeRootNode","result","currentParent","parent","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"6jBAuCA,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,EAEjB,KAAK,OAAO,UACV,4DAAA,CAEJ,CA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,MAAM,MAAMD,EAA0B,CAAE,QAAAX,EAAS,GAS/C,KAAA,EACnB,UAAWa,KAAYD,EACrB,GAAIC,EAAS,IAAM,wBACjBJ,EAAM,KACJ,GAAI,MAAM,KAAK,WAAWZ,EAAWG,EAASa,EAAS,KAAK,MAAM,CAAA,UAGpE,CAAC,CAAC,cAAe,cAAc,EAAE,SAASA,EAAS,KAAK,IAAI,GAC5DA,EAAS,OACT,CACA,MAAMC,EAAoB,KAAK,UAAU,MACvC,GAAGJ,CAAY,GAAGG,EAAS,OAAO,IAAI,EAAA,EAExCJ,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,CAC5D,CACD,EAAE,KACH,aAAcD,EAAS,SACvB,YAAa,CAACA,EAAS,GAAG,SAAS,UAAU,CAAA,CAC9C,CACH,CAGF,OAAOJ,CACT,CACF,EArIMnB,EAANyB,EAAA,CADCC,aAAA,EAGIC,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,EA0IC,MAAM4B,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAA2BC,EAAAA,IAAwB,EACnD,GAAG9B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO,CACtB,CACF"}
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 * @beta\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 includeRootNode?: boolean,\n ): Array<string> {\n const result = includeRootNode ? [\"\"] : [];\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 // The DocumentTree sheet sets a default limit of 15 items par page.\n // We use a greater one to reduce the number of requests to fetch them all.\n const limit = 100;\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 [\"limit\", limit.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 // Handle paging if necessary.\n if (jsonResponse.length >= limit) {\n nodes.push(\n ...(await this.fetchNodes(currentId, headers, offset + limit)),\n );\n }\n\n return nodes;\n }\n}\n\n/**\n * @beta\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","headers","error","page","includeTerminal","includeRootNode","result","currentParent","parent","offset","nodes","baseXWikiURL","limit","navigationTreeRequestUrl","jsonResponse","treeNode","documentReference","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"6jBAuCA,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,EAEjB,KAAK,OAAO,UACV,4DAAA,CAEJ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
2
  "name": "@xwiki/cristal-navigation-tree-xwiki",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -28,23 +28,23 @@
28
28
  "main": "./dist/index.es.js",
29
29
  "types": "./dist/index.d.ts",
30
30
  "dependencies": {
31
- "@xwiki/cristal-api": "0.22.0",
32
- "@xwiki/cristal-model-reference-api": "0.22.0",
33
- "@xwiki/cristal-model-remote-url-api": "0.22.0",
34
- "@xwiki/cristal-navigation-tree-api": "0.22.0",
35
- "@xwiki/cristal-authentication-api": "0.22.0",
36
- "@xwiki/cristal-model-api": "0.22.0"
31
+ "@xwiki/cristal-authentication-api": "0.23.0",
32
+ "@xwiki/cristal-model-reference-api": "0.23.0",
33
+ "@xwiki/cristal-api": "0.23.0",
34
+ "@xwiki/cristal-model-api": "0.23.0",
35
+ "@xwiki/cristal-model-remote-url-api": "0.23.0",
36
+ "@xwiki/cristal-navigation-tree-api": "0.23.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "inversify": "7.x",
40
40
  "reflect-metadata": "0.x"
41
41
  },
42
42
  "devDependencies": {
43
- "inversify": "7.9.0",
43
+ "inversify": "7.10.2",
44
44
  "reflect-metadata": "0.2.2",
45
- "typescript": "5.9.2",
46
- "vite": "7.1.5",
47
- "@xwiki/cristal-dev-config": "0.22.0"
45
+ "typescript": "5.9.3",
46
+ "vite": "7.1.9",
47
+ "@xwiki/cristal-dev-config": "0.23.0"
48
48
  },
49
49
  "scripts": {
50
50
  "api-extractor:local": "api-extractor run --local",
@@ -115,6 +115,9 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
115
115
  const baseXWikiURL = this.cristalApp
116
116
  .getWikiConfig()
117
117
  .baseURL.replace(/\/[^/]*$/, "");
118
+ // The DocumentTree sheet sets a default limit of 15 items par page.
119
+ // We use a greater one to reduce the number of requests to fetch them all.
120
+ const limit = 100;
118
121
 
119
122
  const navigationTreeRequestUrl = new URL(
120
123
  `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,
@@ -126,6 +129,7 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
126
129
  ["data", "children"],
127
130
  ["compact", "true"],
128
131
  ["offset", offset.toString()],
132
+ ["limit", limit.toString()],
129
133
  ["showTranslations", "false"],
130
134
  ["showAttachments", "false"],
131
135
  ]).toString();
@@ -168,6 +172,13 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
168
172
  }
169
173
  }
170
174
 
175
+ // Handle paging if necessary.
176
+ if (jsonResponse.length >= limit) {
177
+ nodes.push(
178
+ ...(await this.fetchNodes(currentId, headers, offset + limit)),
179
+ );
180
+ }
181
+
171
182
  return nodes;
172
183
  }
173
184
  }