@xwiki/cristal-navigation-tree-xwiki 0.10.0 → 0.12.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,31 @@
1
1
  # @xwiki/cristal-navigation-tree-xwiki
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 681a9b7: Cristal 0.12 Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [681a9b7]
12
+ - @xwiki/cristal-api@0.12.0
13
+ - @xwiki/cristal-authentication-api@0.12.0
14
+ - @xwiki/cristal-navigation-tree-api@0.12.0
15
+
16
+ ## 0.11.0
17
+
18
+ ### Minor Changes
19
+
20
+ - d54422d: Cristal 0.11 Release
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [d54422d]
25
+ - @xwiki/cristal-api@0.11.0
26
+ - @xwiki/cristal-authentication-api@0.11.0
27
+ - @xwiki/cristal-navigation-tree-api@0.11.0
28
+
3
29
  ## 0.10.0
4
30
 
5
31
  ### Minor Changes
@@ -1,5 +1,4 @@
1
1
  import { Container } from 'inversify';
2
-
3
2
  export declare class ComponentInit {
4
3
  constructor(container: Container);
5
4
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { ComponentInit } from './components/componentsInit';
2
-
3
2
  export { ComponentInit };
package/dist/index.es.js CHANGED
@@ -1,88 +1,98 @@
1
- import { injectable as u, inject as l } from "inversify";
2
- import { name as h } from "@xwiki/cristal-navigation-tree-api";
3
- var d = Object.defineProperty, m = Object.getOwnPropertyDescriptor, f = (r, e, i, n) => {
4
- for (var t = n > 1 ? void 0 : n ? m(e, i) : e, o = r.length - 1, s; o >= 0; o--)
5
- (s = r[o]) && (t = (n ? s(e, i, t) : s(t)) || t);
6
- return n && t && d(e, i, t), t;
7
- }, g = (r, e) => (i, n) => e(i, n, r);
8
- let c = class {
9
- constructor(r, e) {
10
- this.logger = r, this.logger.setModule(
1
+ import { name as d } from "@xwiki/cristal-navigation-tree-api";
2
+ import { injectable as u, inject as c } from "inversify";
3
+ var f = Object.defineProperty, m = Object.getOwnPropertyDescriptor, v = (i, e, o, r) => {
4
+ for (var t = r > 1 ? void 0 : r ? m(e, o) : e, n = i.length - 1, s; n >= 0; n--)
5
+ (s = i[n]) && (t = (r ? s(e, o, t) : s(t)) || t);
6
+ return r && t && f(e, o, t), t;
7
+ }, p = (i, e) => (o, r) => e(o, r, i);
8
+ let g = class {
9
+ constructor(i, e, o) {
10
+ this.authenticationManagerProvider = o, this.logger = i, this.logger.setModule(
11
11
  "navigation-tree-xwiki.components.XWikiNavigationTreeSource"
12
12
  ), this.cristalApp = e;
13
13
  }
14
- async getChildNodes(r) {
15
- const e = r || "#", i = [], n = new URL(
16
- `${this.cristalApp.getWikiConfig().baseURL}/bin/get`
17
- );
18
- n.search = new URLSearchParams([
19
- ["id", e],
20
- ["outputSyntax", "plain"],
21
- ["sheet", "XWiki.DocumentTree"],
22
- ["data", "children"],
23
- ["compact", "true"]
24
- ]).toString();
14
+ async getChildNodes(i) {
15
+ var r;
16
+ const e = i || "#", o = [];
25
17
  try {
26
- const t = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, "");
27
- (await (await fetch(n, {
28
- headers: { Accept: "application/json" }
29
- })).json()).forEach(
30
- (a) => {
31
- if (!["attachments", "translations"].includes(a.data.type)) {
32
- const p = decodeURIComponent(
33
- this.cristalApp.getWikiConfig().storage.getPageFromViewURL(
34
- `${t}${a.a_attr.href}`
35
- )
36
- );
37
- i.push({
38
- id: a.id,
39
- label: a.text,
40
- location: p.replace(/\.WebHome$/, ""),
41
- url: this.cristalApp.getRouter().resolve({
42
- name: "view",
43
- params: {
44
- page: p
45
- }
46
- }).href,
47
- has_children: a.children
48
- //TODO: ignore translations and attachments
49
- });
50
- }
51
- }
52
- );
18
+ const t = await ((r = this.authenticationManagerProvider.get()) == null ? void 0 : r.getAuthorizationHeader()), n = {
19
+ Accept: "application/json"
20
+ };
21
+ t && (n.Authorization = t), o.push(...await this.fetchNodes(e, n, 0));
53
22
  } catch (t) {
54
23
  this.logger.error(t), this.logger.debug("Could not load navigation tree.");
55
24
  }
56
- return i;
25
+ return o;
57
26
  }
58
- getParentNodesId(r) {
27
+ getParentNodesId(i) {
59
28
  const e = [];
60
- if (r) {
61
- const i = r.document.getIdentifier();
62
- if (!i)
29
+ if (i) {
30
+ const o = i.document.getIdentifier();
31
+ if (!o)
63
32
  return this.logger.debug(
64
- `No identifier found for page ${r.name}, cannot resolve parents.`
33
+ `No identifier found for page ${i.name}, cannot resolve parents.`
65
34
  ), [];
66
- const n = i.replace(/\.WebHome$/, "").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));
67
- let t = "", o;
68
- for (o = 0; o < n.length - 1; o++)
69
- t += n[o], e.push(`document:xwiki:${t}.WebHome`), t += ".";
70
- e.push(`document:xwiki:${i}`);
35
+ const r = o.replace(/\.WebHome$/, "").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));
36
+ let t = "", n;
37
+ for (n = 0; n < r.length - 1; n++)
38
+ t += r[n], e.push(`document:xwiki:${t}.WebHome`), t += ".";
39
+ e.push(`document:xwiki:${o}`);
71
40
  }
72
41
  return e;
73
42
  }
43
+ async fetchNodes(i, e, o) {
44
+ const r = [], t = this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/, ""), n = new URL(
45
+ `${this.cristalApp.getWikiConfig().baseURL}/bin/get`
46
+ );
47
+ n.search = new URLSearchParams([
48
+ ["id", i],
49
+ ["outputSyntax", "plain"],
50
+ ["sheet", "XWiki.DocumentTree"],
51
+ ["data", "children"],
52
+ ["compact", "true"],
53
+ ["offset", o.toString()]
54
+ ]).toString();
55
+ const h = await (await fetch(n, { headers: e })).json();
56
+ for (const a of h)
57
+ if (a.id == "pagination:wiki:xwiki")
58
+ r.push(
59
+ ...await this.fetchNodes(i, e, a.data.offset)
60
+ );
61
+ else if (!["attachments", "translations"].includes(a.data.type) && a.a_attr) {
62
+ const l = decodeURIComponent(
63
+ this.cristalApp.getWikiConfig().storage.getPageFromViewURL(
64
+ `${t}${a.a_attr.href}`
65
+ )
66
+ );
67
+ r.push({
68
+ id: a.id,
69
+ label: a.text,
70
+ location: l.replace(/\.WebHome$/, ""),
71
+ url: this.cristalApp.getRouter().resolve({
72
+ name: "view",
73
+ params: {
74
+ page: l
75
+ }
76
+ }).href,
77
+ has_children: a.children
78
+ //TODO: ignore translations and attachments
79
+ });
80
+ }
81
+ return r;
82
+ }
74
83
  };
75
- c = f([
84
+ g = v([
76
85
  u(),
77
- g(0, l("Logger")),
78
- g(1, l("CristalApp"))
79
- ], c);
80
- class w {
86
+ p(0, c("Logger")),
87
+ p(1, c("CristalApp")),
88
+ p(2, c("AuthenticationManagerProvider"))
89
+ ], g);
90
+ class P {
81
91
  constructor(e) {
82
- e.bind(h).to(c).inSingletonScope().whenTargetNamed("XWiki");
92
+ e.bind(d).to(g).inSingletonScope().whenTargetNamed("XWiki");
83
93
  }
84
94
  }
85
95
  export {
86
- w as ComponentInit
96
+ P as ComponentInit
87
97
  };
88
98
  //# 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 { Container, inject, injectable } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport {\n name as NavigationTreeSourceName,\n type NavigationTreeNode,\n type 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 private cristalApp: CristalApp;\n public logger: Logger;\n\n constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.logger = logger;\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n this.cristalApp = cristalApp;\n }\n\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\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 ]).toString();\n try {\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n const response = await fetch(navigationTreeRequestUrl, {\n headers: { Accept: \"application/json\" },\n });\n const jsonResponse = await response.json();\n jsonResponse.forEach(\n (treeNode: {\n id: string;\n text: string;\n children: boolean;\n data: { type: string };\n a_attr: { href: string };\n }) => {\n if (![\"attachments\", \"translations\"].includes(treeNode.data.type)) {\n const pageId = decodeURIComponent(\n this.cristalApp\n .getWikiConfig()\n .storage.getPageFromViewURL(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )!,\n );\n navigationTree.push({\n id: treeNode.id,\n label: treeNode.text,\n location: pageId.replace(/\\.WebHome$/, \"\"),\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: pageId,\n },\n }).href,\n has_children: treeNode.children, //TODO: ignore translations and attachments\n });\n }\n },\n );\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(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\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","id","currentId","navigationTree","navigationTreeRequestUrl","baseXWikiURL","treeNode","pageId","error","page","result","documentId","parents","currentParent","i","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAkCA,IAAMA,IAAN,MAAgE;AAAA,EAI9D,YAC4BC,GACQC,GAClC;AACA,SAAK,SAASD,GACd,KAAK,OAAO;AAAA,MACV;AAAA,IAAA,GAEF,KAAK,aAAaC;AAAA,EACpB;AAAA,EAEA,MAAM,cAAcC,GAAiD;AAC7D,UAAAC,IAAYD,KAAU,KACtBE,IAA4C,CAAA,GAE5CC,IAA2B,IAAI;AAAA,MACnC,GAAG,KAAK,WAAW,cAAA,EAAgB,OAAO;AAAA,IAAA;AAEnB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ACH,oBAAK,OAAO;AAAA,UACV,gCAAgCF,EAAK,IAAI;AAAA,QAAA,GAEpC;AAGT,YAAMG,IAAUD,EACb,QAAQ,cAAc,EAAE,EACxB,MAAM,WAAA,kCAAyB;AAClC,UAAIE,IAAgB,IAChBC;AACJ,WAAKA,IAAI,GAAGA,IAAIF,EAAQ,SAAS,GAAGE;AAClC,QAAAD,KAAiBD,EAAQE,CAAC,GAEnBJ,EAAA,KAAK,kBAAkBG,CAAa,UAAU,GACpCA,KAAA;AAEZ,MAAAH,EAAA,KAAK,kBAAkBC,CAAU,EAAE;AAAA,IAC5C;AACO,WAAAD;AAAA,EACT;AACF;AArGMZ,IAANiB,EAAA;AAAA,EADCC,EAAW;AAAA,EAMPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAmB,YAAY,CAAA;AAAA,GAN9BnB,CAAA;AAuGC,MAAMoB,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAE7B,IAAAA,EAAA,KAA2BC,CAAwB,EACnD,GAAGtB,CAAyB,EAC5B,iBACA,EAAA,gBAAgB,OAAO;AAAA,EAC5B;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 } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-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 private cristalApp: CristalApp;\n public logger: Logger;\n\n constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n @inject<AuthenticationManagerProvider>(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n ) {\n this.logger = logger;\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n this.cristalApp = cristalApp;\n }\n\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(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 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 ]).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 pageId = decodeURIComponent(\n this.cristalApp\n .getWikiConfig()\n .storage.getPageFromViewURL(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )!,\n );\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: pageId.replace(/\\.WebHome$/, \"\"),\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: pageId,\n },\n }).href,\n has_children: treeNode.children, //TODO: ignore translations and attachments\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","id","currentId","navigationTree","authorization","_a","headers","error","page","result","documentId","parents","currentParent","i","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","pageId","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":";;;;;;;AAmCA,IAAMA,IAAN,MAAgE;AAAA,EAI9D,YAC4BC,GACQC,GAE1BC,GACR;AADQ,SAAA,gCAAAA,GAER,KAAK,SAASF,GACd,KAAK,OAAO;AAAA,MACV;AAAA,IAAA,GAEF,KAAK,aAAaC;AAAA,EACpB;AAAA,EAEA,MAAM,cAAcE,GAAiD;;AAC7D,UAAAC,IAAYD,KAAU,KACtBE,IAA4C,CAAA;AAE9C,QAAA;AACF,YAAMC,IAAgB,QAAMC,IAAA,KAAK,8BAC9B,IAAA,MADyB,gBAAAA,EAExB,2BACEC,IAAsD;AAAA,QAC1D,QAAQ;AAAA,MAAA;AAGV,MAAIF,MACFE,EAAQ,gBAAgBF,IAGXD,EAAA,KAAK,GAAI,MAAM,KAAK,WAAWD,GAAWI,GAAS,CAAC,CAAE;AAAA,aAC9DC,GAAO;AACT,WAAA,OAAO,MAAMA,CAAK,GAClB,KAAA,OAAO,MAAM,iCAAiC;AAAA,IACrD;AACO,WAAAJ;AAAA,EACT;AAAA,EAEA,iBAAiBK,GAAgC;AAC/C,UAAMC,IAAS,CAAA;AACf,QAAID,GAAM;AACF,YAAAE,IAAaF,EAAK,SAAS,cAAc;AAC/C,UAAI,CAACE;AACH,oBAAK,OAAO;AAAA,UACV,gCAAgCF,EAAK,IAAI;AAAA,QAAA,GAEpC;AAGT,YAAMG,IAAUD,EACb,QAAQ,cAAc,EAAE,EACxB,MAAM,WAAA,kCAAyB;AAClC,UAAIE,IAAgB,IAChBC;AACJ,WAAKA,IAAI,GAAGA,IAAIF,EAAQ,SAAS,GAAGE;AAClC,QAAAD,KAAiBD,EAAQE,CAAC,GAEnBJ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YACvC,MAAM;AAAA,YACN,QAAQ;AAAA,cACN,MAAMA;AAAA,YACR;AAAA,UACD,CAAA,EAAE;AAAA,UACH,cAAcD,EAAS;AAAA;AAAA,QAAA,CACxB;AAAA,MACH;AAGK,WAAAJ;AAAA,EACT;AACF;AArIMlB,IAANwB,EAAA;AAAA,EADCC,EAAW;AAAA,EAMPC,OAAe,QAAQ,CAAA;AAAA,EACvBA,OAAmB,YAAY,CAAA;AAAA,EAC/BA,OAAsC,+BAA+B,CAAA;AAAA,GAPpE1B,CAAA;AAuIC,MAAM2B,EAAc;AAAA,EACzB,YAAYC,GAAsB;AAE7B,IAAAA,EAAA,KAA2BC,CAAwB,EACnD,GAAG7B,CAAyB,EAC5B,iBACA,EAAA,gBAAgB,OAAO;AAAA,EAC5B;AACF;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("inversify"),require("@xwiki/cristal-navigation-tree-api")):typeof define=="function"&&define.amd?define(["exports","inversify","@xwiki/cristal-navigation-tree-api"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a["cristal_navigation-tree-xwiki"]={},a.inversify,a.cristalNavigationTreeApi))})(this,function(a,s,d){"use strict";var h=Object.defineProperty,f=Object.getOwnPropertyDescriptor,m=(i,e,n,r)=>{for(var t=r>1?void 0:r?f(e,n):e,o=i.length-1,p;o>=0;o--)(p=i[o])&&(t=(r?p(e,n,t):p(t))||t);return r&&t&&h(e,n,t),t},g=(i,e)=>(n,r)=>e(n,r,i);let l=class{constructor(i,e){this.logger=i,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource"),this.cristalApp=e}async getChildNodes(i){const e=i||"#",n=[],r=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);r.search=new URLSearchParams([["id",e],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"]]).toString();try{const t=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,"");(await(await fetch(r,{headers:{Accept:"application/json"}})).json()).forEach(c=>{if(!["attachments","translations"].includes(c.data.type)){const u=decodeURIComponent(this.cristalApp.getWikiConfig().storage.getPageFromViewURL(`${t}${c.a_attr.href}`));n.push({id:c.id,label:c.text,location:u.replace(/\.WebHome$/,""),url:this.cristalApp.getRouter().resolve({name:"view",params:{page:u}}).href,has_children:c.children})}})}catch(t){this.logger.error(t),this.logger.debug("Could not load navigation tree.")}return n}getParentNodesId(i){const e=[];if(i){const n=i.document.getIdentifier();if(!n)return this.logger.debug(`No identifier found for page ${i.name}, cannot resolve parents.`),[];const r=n.replace(/\.WebHome$/,"").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));let t="",o;for(o=0;o<r.length-1;o++)t+=r[o],e.push(`document:xwiki:${t}.WebHome`),t+=".";e.push(`document:xwiki:${n}`)}return e}};l=m([s.injectable(),g(0,s.inject("Logger")),g(1,s.inject("CristalApp"))],l);class v{constructor(e){e.bind(d.name).to(l).inSingletonScope().whenTargetNamed("XWiki")}}a.ComponentInit=v,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@xwiki/cristal-navigation-tree-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","@xwiki/cristal-navigation-tree-api","inversify"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a["cristal_navigation-tree-xwiki"]={},a.cristalNavigationTreeApi,a.inversify))})(this,function(a,c,p){"use strict";var h=Object.defineProperty,f=Object.getOwnPropertyDescriptor,m=(i,e,n,o)=>{for(var t=o>1?void 0:o?f(e,n):e,r=i.length-1,d;r>=0;r--)(d=i[r])&&(t=(o?d(e,n,t):d(t))||t);return o&&t&&h(e,n,t),t},l=(i,e)=>(n,o)=>e(n,o,i);let u=class{constructor(i,e,n){this.authenticationManagerProvider=n,this.logger=i,this.logger.setModule("navigation-tree-xwiki.components.XWikiNavigationTreeSource"),this.cristalApp=e}async getChildNodes(i){var o;const e=i||"#",n=[];try{const t=await((o=this.authenticationManagerProvider.get())==null?void 0:o.getAuthorizationHeader()),r={Accept:"application/json"};t&&(r.Authorization=t),n.push(...await this.fetchNodes(e,r,0))}catch(t){this.logger.error(t),this.logger.debug("Could not load navigation tree.")}return n}getParentNodesId(i){const e=[];if(i){const n=i.document.getIdentifier();if(!n)return this.logger.debug(`No identifier found for page ${i.name}, cannot resolve parents.`),[];const o=n.replace(/\.WebHome$/,"").split(new RegExp("(?<![^\\\\](?:\\\\\\\\)*\\\\)\\."));let t="",r;for(r=0;r<o.length-1;r++)t+=o[r],e.push(`document:xwiki:${t}.WebHome`),t+=".";e.push(`document:xwiki:${n}`)}return e}async fetchNodes(i,e,n){const o=[],t=this.cristalApp.getWikiConfig().baseURL.replace(/\/[^/]*$/,""),r=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);r.search=new URLSearchParams([["id",i],["outputSyntax","plain"],["sheet","XWiki.DocumentTree"],["data","children"],["compact","true"],["offset",n.toString()]]).toString();const w=await(await fetch(r,{headers:e})).json();for(const s of w)if(s.id=="pagination:wiki:xwiki")o.push(...await this.fetchNodes(i,e,s.data.offset));else if(!["attachments","translations"].includes(s.data.type)&&s.a_attr){const g=decodeURIComponent(this.cristalApp.getWikiConfig().storage.getPageFromViewURL(`${t}${s.a_attr.href}`));o.push({id:s.id,label:s.text,location:g.replace(/\.WebHome$/,""),url:this.cristalApp.getRouter().resolve({name:"view",params:{page:g}}).href,has_children:s.children})}return o}};u=m([p.injectable(),l(0,p.inject("Logger")),l(1,p.inject("CristalApp")),l(2,p.inject("AuthenticationManagerProvider"))],u);class v{constructor(e){e.bind(c.name).to(u).inSingletonScope().whenTargetNamed("XWiki")}}a.ComponentInit=v,Object.defineProperty(a,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 { Container, inject, injectable } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport {\n name as NavigationTreeSourceName,\n type NavigationTreeNode,\n type 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 private cristalApp: CristalApp;\n public logger: Logger;\n\n constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n ) {\n this.logger = logger;\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n this.cristalApp = cristalApp;\n }\n\n async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {\n const currentId = id ? id : \"#\";\n const navigationTree: Array<NavigationTreeNode> = [];\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 ]).toString();\n try {\n const baseXWikiURL = this.cristalApp\n .getWikiConfig()\n .baseURL.replace(/\\/[^/]*$/, \"\");\n const response = await fetch(navigationTreeRequestUrl, {\n headers: { Accept: \"application/json\" },\n });\n const jsonResponse = await response.json();\n jsonResponse.forEach(\n (treeNode: {\n id: string;\n text: string;\n children: boolean;\n data: { type: string };\n a_attr: { href: string };\n }) => {\n if (![\"attachments\", \"translations\"].includes(treeNode.data.type)) {\n const pageId = decodeURIComponent(\n this.cristalApp\n .getWikiConfig()\n .storage.getPageFromViewURL(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )!,\n );\n navigationTree.push({\n id: treeNode.id,\n label: treeNode.text,\n location: pageId.replace(/\\.WebHome$/, \"\"),\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: pageId,\n },\n }).href,\n has_children: treeNode.children, //TODO: ignore translations and attachments\n });\n }\n },\n );\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(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\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","id","currentId","navigationTree","navigationTreeRequestUrl","baseXWikiURL","treeNode","pageId","error","page","result","documentId","parents","currentParent","i","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"gnBAkCA,IAAMA,EAAN,KAAgE,CAI9D,YAC4BC,EACQC,EAClC,CACA,KAAK,OAASD,EACd,KAAK,OAAO,UACV,4DAAA,EAEF,KAAK,WAAaC,CACpB,CAEA,MAAM,cAAcC,EAAiD,CAC7D,MAAAC,EAAYD,GAAU,IACtBE,EAA4C,CAAA,EAE5CC,EAA2B,IAAI,IACnC,GAAG,KAAK,WAAW,cAAA,EAAgB,OAAO,UAAA,EAEnBA,EAAA,OAAS,IAAI,gBAAgB,CACpD,CAAC,KAAMF,CAAS,EAChB,CAAC,eAAgB,OAAO,EACxB,CAAC,QAAS,oBAAoB,EAC9B,CAAC,OAAQ,UAAU,EACnB,CAAC,UAAW,MAAM,CAAA,CACnB,EAAE,SAAS,EACR,GAAA,CACI,MAAAG,EAAe,KAAK,WACvB,cAAA,EACA,QAAQ,QAAQ,WAAY,EAAE,GAIZ,MAHJ,MAAM,MAAMD,EAA0B,CACrD,QAAS,CAAE,OAAQ,kBAAmB,CAAA,CACvC,GACmC,QACvB,QACVE,GAMK,CACA,GAAA,CAAC,CAAC,cAAe,cAAc,EAAE,SAASA,EAAS,KAAK,IAAI,EAAG,CACjE,MAAMC,EAAS,mBACb,KAAK,WACF,cAAc,EACd,QAAQ,mBACP,GAAGF,CAAY,GAAGC,EAAS,OAAO,IAAI,EACxC,CAAA,EAEJH,EAAe,KAAK,CAClB,GAAIG,EAAS,GACb,MAAOA,EAAS,KAChB,SAAUC,EAAO,QAAQ,aAAc,EAAE,EACzC,IAAK,KAAK,WAAW,UAAA,EAAY,QAAQ,CACvC,KAAM,OACN,OAAQ,CACN,KAAMA,CACR,CACD,CAAA,EAAE,KACH,aAAcD,EAAS,QAAA,CACxB,CACH,CACF,CAAA,QAEKE,EAAO,CACT,KAAA,OAAO,MAAMA,CAAK,EAClB,KAAA,OAAO,MAAM,iCAAiC,CACrD,CACO,OAAAL,CACT,CAEA,iBAAiBM,EAAgC,CAC/C,MAAMC,EAAS,CAAA,EACf,GAAID,EAAM,CACF,MAAAE,EAAaF,EAAK,SAAS,cAAc,EAC/C,GAAI,CAACE,EACH,YAAK,OAAO,MACV,gCAAgCF,EAAK,IAAI,2BAAA,EAEpC,GAGT,MAAMG,EAAUD,EACb,QAAQ,aAAc,EAAE,EACxB,MAAM,WAAA,kCAAyB,GAClC,IAAIE,EAAgB,GAChBC,EACJ,IAAKA,EAAI,EAAGA,EAAIF,EAAQ,OAAS,EAAGE,IAClCD,GAAiBD,EAAQE,CAAC,EAEnBJ,EAAA,KAAK,kBAAkBG,CAAa,UAAU,EACpCA,GAAA,IAEZH,EAAA,KAAK,kBAAkBC,CAAU,EAAE,CAC5C,CACO,OAAAD,CACT,CACF,EArGMZ,EAANiB,EAAA,CADCC,aAAW,EAMPC,aAAe,QAAQ,CAAA,EACvBA,aAAmB,YAAY,CAAA,CAAA,EAN9BnB,CAAA,EAuGC,MAAMoB,CAAc,CACzB,YAAYC,EAAsB,CAE7BA,EAAA,KAA2BC,EAAwB,IAAA,EACnD,GAAGtB,CAAyB,EAC5B,iBACA,EAAA,gBAAgB,OAAO,CAC5B,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 } from \"inversify\";\nimport type { CristalApp, Logger, PageData } from \"@xwiki/cristal-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/cristal-authentication-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 private cristalApp: CristalApp;\n public logger: Logger;\n\n constructor(\n @inject<Logger>(\"Logger\") logger: Logger,\n @inject<CristalApp>(\"CristalApp\") cristalApp: CristalApp,\n @inject<AuthenticationManagerProvider>(\"AuthenticationManagerProvider\")\n private authenticationManagerProvider: AuthenticationManagerProvider,\n ) {\n this.logger = logger;\n this.logger.setModule(\n \"navigation-tree-xwiki.components.XWikiNavigationTreeSource\",\n );\n this.cristalApp = cristalApp;\n }\n\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(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 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 ]).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 pageId = decodeURIComponent(\n this.cristalApp\n .getWikiConfig()\n .storage.getPageFromViewURL(\n `${baseXWikiURL}${treeNode.a_attr.href}`,\n )!,\n );\n nodes.push({\n id: treeNode.id,\n label: treeNode.text,\n location: pageId.replace(/\\.WebHome$/, \"\"),\n url: this.cristalApp.getRouter().resolve({\n name: \"view\",\n params: {\n page: pageId,\n },\n }).href,\n has_children: treeNode.children, //TODO: ignore translations and attachments\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","id","currentId","navigationTree","authorization","_a","headers","error","page","result","documentId","parents","currentParent","i","offset","nodes","baseXWikiURL","navigationTreeRequestUrl","jsonResponse","treeNode","pageId","__decorateClass","injectable","__decorateParam","ComponentInit","container","NavigationTreeSourceName"],"mappings":"gnBAmCA,IAAMA,EAAN,KAAgE,CAI9D,YAC4BC,EACQC,EAE1BC,EACR,CADQ,KAAA,8BAAAA,EAER,KAAK,OAASF,EACd,KAAK,OAAO,UACV,4DAAA,EAEF,KAAK,WAAaC,CACpB,CAEA,MAAM,cAAcE,EAAiD,OAC7D,MAAAC,EAAYD,GAAU,IACtBE,EAA4C,CAAA,EAE9C,GAAA,CACF,MAAMC,EAAgB,OAAMC,EAAA,KAAK,8BAC9B,IAAA,IADyB,YAAAA,EAExB,0BACEC,EAAsD,CAC1D,OAAQ,kBAAA,EAGNF,IACFE,EAAQ,cAAgBF,GAGXD,EAAA,KAAK,GAAI,MAAM,KAAK,WAAWD,EAAWI,EAAS,CAAC,CAAE,QAC9DC,EAAO,CACT,KAAA,OAAO,MAAMA,CAAK,EAClB,KAAA,OAAO,MAAM,iCAAiC,CACrD,CACO,OAAAJ,CACT,CAEA,iBAAiBK,EAAgC,CAC/C,MAAMC,EAAS,CAAA,EACf,GAAID,EAAM,CACF,MAAAE,EAAaF,EAAK,SAAS,cAAc,EAC/C,GAAI,CAACE,EACH,YAAK,OAAO,MACV,gCAAgCF,EAAK,IAAI,2BAAA,EAEpC,GAGT,MAAMG,EAAUD,EACb,QAAQ,aAAc,EAAE,EACxB,MAAM,WAAA,kCAAyB,GAClC,IAAIE,EAAgB,GAChBC,EACJ,IAAKA,EAAI,EAAGA,EAAIF,EAAQ,OAAS,EAAGE,IAClCD,GAAiBD,EAAQE,CAAC,EAEnBJ,EAAA,KAAK,kBAAk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mB,YAAY,CAAA,EAC/BA,aAAsC,+BAA+B,CAAA,CAAA,EAPpE1B,CAAA,EAuIC,MAAM2B,CAAc,CACzB,YAAYC,EAAsB,CAE7BA,EAAA,KAA2BC,EAAwB,IAAA,EACnD,GAAG7B,CAAyB,EAC5B,iBACA,EAAA,gBAAgB,OAAO,CAC5B,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-navigation-tree-xwiki",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -22,13 +22,15 @@
22
22
  },
23
23
  "main": "./dist/index.es.js",
24
24
  "dependencies": {
25
- "inversify": "6.0.2",
26
- "@xwiki/cristal-api": "0.10.0",
27
- "@xwiki/cristal-navigation-tree-api": "0.10.0"
25
+ "inversify": "6.0.3",
26
+ "@xwiki/cristal-api": "0.12.0",
27
+ "@xwiki/cristal-authentication-api": "0.12.0",
28
+ "@xwiki/cristal-navigation-tree-api": "0.12.0"
28
29
  },
29
30
  "scripts": {
31
+ "build": "tsc --project tsconfig.json && vite build",
30
32
  "clean": "rimraf dist",
31
- "build": "tsc --project tsconfig.json && vite build"
33
+ "lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0"
32
34
  },
33
35
  "types": "./dist/index.d.ts"
34
36
  }
@@ -18,12 +18,13 @@
18
18
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19
19
  */
20
20
 
21
+ import { name as NavigationTreeSourceName } from "@xwiki/cristal-navigation-tree-api";
21
22
  import { Container, inject, injectable } from "inversify";
22
23
  import type { CristalApp, Logger, PageData } from "@xwiki/cristal-api";
23
- import {
24
- name as NavigationTreeSourceName,
25
- type NavigationTreeNode,
26
- type NavigationTreeSource,
24
+ import type { AuthenticationManagerProvider } from "@xwiki/cristal-authentication-api";
25
+ import type {
26
+ NavigationTreeNode,
27
+ NavigationTreeSource,
27
28
  } from "@xwiki/cristal-navigation-tree-api";
28
29
 
29
30
  /**
@@ -39,6 +40,8 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
39
40
  constructor(
40
41
  @inject<Logger>("Logger") logger: Logger,
41
42
  @inject<CristalApp>("CristalApp") cristalApp: CristalApp,
43
+ @inject<AuthenticationManagerProvider>("AuthenticationManagerProvider")
44
+ private authenticationManagerProvider: AuthenticationManagerProvider,
42
45
  ) {
43
46
  this.logger = logger;
44
47
  this.logger.setModule(
@@ -51,55 +54,19 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
51
54
  const currentId = id ? id : "#";
52
55
  const navigationTree: Array<NavigationTreeNode> = [];
53
56
 
54
- const navigationTreeRequestUrl = new URL(
55
- `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,
56
- );
57
- navigationTreeRequestUrl.search = new URLSearchParams([
58
- ["id", currentId],
59
- ["outputSyntax", "plain"],
60
- ["sheet", "XWiki.DocumentTree"],
61
- ["data", "children"],
62
- ["compact", "true"],
63
- ]).toString();
64
57
  try {
65
- const baseXWikiURL = this.cristalApp
66
- .getWikiConfig()
67
- .baseURL.replace(/\/[^/]*$/, "");
68
- const response = await fetch(navigationTreeRequestUrl, {
69
- headers: { Accept: "application/json" },
70
- });
71
- const jsonResponse = await response.json();
72
- jsonResponse.forEach(
73
- (treeNode: {
74
- id: string;
75
- text: string;
76
- children: boolean;
77
- data: { type: string };
78
- a_attr: { href: string };
79
- }) => {
80
- if (!["attachments", "translations"].includes(treeNode.data.type)) {
81
- const pageId = decodeURIComponent(
82
- this.cristalApp
83
- .getWikiConfig()
84
- .storage.getPageFromViewURL(
85
- `${baseXWikiURL}${treeNode.a_attr.href}`,
86
- )!,
87
- );
88
- navigationTree.push({
89
- id: treeNode.id,
90
- label: treeNode.text,
91
- location: pageId.replace(/\.WebHome$/, ""),
92
- url: this.cristalApp.getRouter().resolve({
93
- name: "view",
94
- params: {
95
- page: pageId,
96
- },
97
- }).href,
98
- has_children: treeNode.children, //TODO: ignore translations and attachments
99
- });
100
- }
101
- },
102
- );
58
+ const authorization = await this.authenticationManagerProvider
59
+ .get()
60
+ ?.getAuthorizationHeader();
61
+ const headers: { Accept: string; Authorization?: string } = {
62
+ Accept: "application/json",
63
+ };
64
+
65
+ if (authorization) {
66
+ headers.Authorization = authorization;
67
+ }
68
+
69
+ navigationTree.push(...(await this.fetchNodes(currentId, headers, 0)));
103
70
  } catch (error) {
104
71
  this.logger.error(error);
105
72
  this.logger.debug("Could not load navigation tree.");
@@ -133,6 +100,72 @@ class XWikiNavigationTreeSource implements NavigationTreeSource {
133
100
  }
134
101
  return result;
135
102
  }
103
+
104
+ private async fetchNodes(
105
+ currentId: string,
106
+ headers: { Accept: string; Authorization?: string },
107
+ offset: number,
108
+ ): Promise<Array<NavigationTreeNode>> {
109
+ const nodes: Array<NavigationTreeNode> = [];
110
+ const baseXWikiURL = this.cristalApp
111
+ .getWikiConfig()
112
+ .baseURL.replace(/\/[^/]*$/, "");
113
+
114
+ const navigationTreeRequestUrl = new URL(
115
+ `${this.cristalApp.getWikiConfig().baseURL}/bin/get`,
116
+ );
117
+ navigationTreeRequestUrl.search = new URLSearchParams([
118
+ ["id", currentId],
119
+ ["outputSyntax", "plain"],
120
+ ["sheet", "XWiki.DocumentTree"],
121
+ ["data", "children"],
122
+ ["compact", "true"],
123
+ ["offset", offset.toString()],
124
+ ]).toString();
125
+
126
+ const response = await fetch(navigationTreeRequestUrl, { headers });
127
+ const jsonResponse: [
128
+ {
129
+ id: string;
130
+ text: string;
131
+ children: boolean;
132
+ data: { type: string; offset: number };
133
+ a_attr?: { href: string };
134
+ },
135
+ ] = await response.json();
136
+ for (const treeNode of jsonResponse) {
137
+ if (treeNode.id == "pagination:wiki:xwiki") {
138
+ nodes.push(
139
+ ...(await this.fetchNodes(currentId, headers, treeNode.data.offset)),
140
+ );
141
+ } else if (
142
+ !["attachments", "translations"].includes(treeNode.data.type) &&
143
+ treeNode.a_attr
144
+ ) {
145
+ const pageId = decodeURIComponent(
146
+ this.cristalApp
147
+ .getWikiConfig()
148
+ .storage.getPageFromViewURL(
149
+ `${baseXWikiURL}${treeNode.a_attr.href}`,
150
+ )!,
151
+ );
152
+ nodes.push({
153
+ id: treeNode.id,
154
+ label: treeNode.text,
155
+ location: pageId.replace(/\.WebHome$/, ""),
156
+ url: this.cristalApp.getRouter().resolve({
157
+ name: "view",
158
+ params: {
159
+ page: pageId,
160
+ },
161
+ }).href,
162
+ has_children: treeNode.children, //TODO: ignore translations and attachments
163
+ });
164
+ }
165
+ }
166
+
167
+ return nodes;
168
+ }
136
169
  }
137
170
 
138
171
  export class ComponentInit {
package/tsdoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../../tsdoc.json"]
4
+ }