@xwiki/cristal-navigation-tree-xwiki 0.24.0 → 0.25.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/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { name as d } from "@xwiki/cristal-navigation-tree-api";
1
+ import { name as d } from "@xwiki/platform-navigation-tree-api";
2
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
4
  for (var r = e > 1 ? void 0 : e ? m(i, a) : i, n = t.length - 1, c; n >= 0; n--)
@@ -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 // 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,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,IAC3BC,GACe;AACf,UAAMC,IAASD,IAAkB,CAAC,EAAE,IAAI,CAAA;AACxC,QAAIF,EAAK,OAAO;AACd,UAAII,IAAgB;AACpB,iBAAWC,KAAUL,EAAK,MAAO;AAC/B,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AAA,QAAA;AAExC,QAAAL,EAAM,KAAK;AAAA,UACT,IAAIK,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;AAIF,WAAID,EAAa,UAAUF,KACzBF,EAAM;AAAA,MACJ,GAAI,MAAM,KAAK,WAAWZ,GAAWG,GAASQ,IAASG,CAAK;AAAA,IAAA,GAIzDF;AAAA,EACT;AACF;AAhJMnB,IAAN0B,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,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;"}
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/platform-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger } from \"@xwiki/platform-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/platform-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/platform-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/platform-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/platform-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/platform-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,UAAM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OAAO,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(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"})}));
1
+ (function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@xwiki/platform-navigation-tree-api"),require("inversify")):typeof define=="function"&&define.amd?define(["exports","@xwiki/platform-navigation-tree-api","inversify"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s["cristal_navigation-tree-xwiki"]={},s.platformNavigationTreeApi,s.inversify))})(this,(function(s,h,c){"use strict";var g=Object.getOwnPropertyDescriptor,m=(t,i,a,e)=>{for(var n=e>1?void 0:e?g(i,a):i,r=t.length-1,p;r>=0;r--)(p=t[r])&&(n=p(n)||n);return n},l=(t,i)=>(a,e)=>i(a,e,t);let u=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,p=new URL(`${this.cristalApp.getWikiConfig().baseURL}/bin/get`);p.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(p,{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 f=this.urlParser.parse(`${n}${o.a_attr.href}`);e.push({id:o.id,label:o.text,location:f.space,url:this.cristalApp.getRouter().resolve({name:"view",params:{page:this.referenceSerializer.serialize(f)}}).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}};u=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"))],u);class w{constructor(i){i.bind(h.name).to(u).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 // 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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B,CAAA,EACjCA,YAAM,OAAO,CAAA,CAAA,EAVZ5B,CAAA,EAqJC,MAAM6B,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAA2BC,EAAAA,IAAwB,EACnD,GAAG/B,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/platform-navigation-tree-api\";\nimport { Container, inject, injectable, named } from \"inversify\";\nimport type { CristalApp, Logger } from \"@xwiki/platform-api\";\nimport type { AuthenticationManagerProvider } from \"@xwiki/platform-authentication-api\";\nimport type { DocumentReference } from \"@xwiki/platform-model-api\";\nimport type { ModelReferenceSerializer } from \"@xwiki/platform-model-reference-api\";\nimport type { RemoteURLParser } from \"@xwiki/platform-model-remote-url-api\";\nimport type {\n NavigationTreeNode,\n NavigationTreeSource,\n} from \"@xwiki/platform-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":"gkBAuCA,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,CAIA,MAAM,cAAcC,EAAiD,CACnE,MAAMC,EAAYD,GAAU,IACtBE,EAA4C,CAAA,EAElD,GAAI,CACF,MAAMC,EAAgB,MAAM,KAAK,8BAC9B,IAAA,GACC,uBAAA,EACEC,EAAsD,CAC1D,OAAQ,kBAAA,EAGND,IACFC,EAAQ,cAAgBD,GAG1BD,EAAe,KAAK,GAAI,MAAM,KAAK,WAAWD,EAAWG,EAAS,CAAC,CAAE,CACvE,OAASC,EAAO,CACd,KAAK,OAAO,MAAMA,CAAK,EACvB,KAAK,OAAO,MAAM,iCAAiC,CACrD,CACA,OAAOH,CACT,CAEA,iBACEI,EACAC,EAA2B,GAC3BC,EACe,CACf,MAAMC,EAASD,EAAkB,CAAC,EAAE,EAAI,CAAA,EACxC,GAAIF,EAAK,MAAO,CACd,IAAII,EAAgB,GACpB,UAAWC,KAAUL,EAAK,MAAO,MAC/BI,GAAiBC,EAEjBF,EAAO,KAAK,kBAAkBC,CAAa,UAAU,EACrDA,GAAiB,IAEfJ,EAAK,MAAQ,WAAaC,GAC5BE,EAAO,KACL,kBAAkB,KAAK,oBAAoB,UAAUH,CAAI,CAAC,EAAA,CAGhE,CACA,OAAOG,CACT,CAIA,MAAc,WACZR,EACAG,EACAQ,EACoC,CACpC,MAAMC,EAAmC,CAAA,EACnCC,EAAe,KAAK,WACvB,cAAA,EACA,QAAQ,QAAQ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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,EAVZ5B,CAAA,EAqJC,MAAM6B,CAAc,CACzB,YAAYC,EAAsB,CAChCA,EACG,KAA2BC,EAAAA,IAAwB,EACnD,GAAG/B,CAAyB,EAC5B,iBAAA,EACA,UAAU,OAAO,CACtB,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-navigation-tree-xwiki",
3
- "version": "0.24.0",
3
+ "version": "0.25.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-authentication-api": "0.24.0",
32
- "@xwiki/cristal-api": "0.24.0",
33
- "@xwiki/cristal-model-remote-url-api": "0.24.0",
34
- "@xwiki/cristal-navigation-tree-api": "0.24.0",
35
- "@xwiki/cristal-model-api": "0.24.0",
36
- "@xwiki/cristal-model-reference-api": "0.24.0"
31
+ "@xwiki/platform-api": "18.0.0-1766398944",
32
+ "@xwiki/platform-authentication-api": "18.0.0-1766398944",
33
+ "@xwiki/platform-model-api": "18.0.0-1766398944",
34
+ "@xwiki/platform-model-reference-api": "18.0.0-1766398944",
35
+ "@xwiki/platform-model-remote-url-api": "18.0.0-1766398944",
36
+ "@xwiki/platform-navigation-tree-api": "18.0.0-1766398944"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "inversify": "7.x",
40
40
  "reflect-metadata": "0.x"
41
41
  },
42
42
  "devDependencies": {
43
- "inversify": "7.10.4",
43
+ "inversify": "7.10.6",
44
44
  "reflect-metadata": "0.2.2",
45
45
  "typescript": "5.9.3",
46
- "vite": "7.1.12",
47
- "@xwiki/cristal-dev-config": "0.24.0"
46
+ "vite": "7.2.7",
47
+ "@xwiki/cristal-dev-config": "0.25.0"
48
48
  },
49
49
  "scripts": {
50
50
  "api-extractor:local": "api-extractor run --local",
@@ -18,17 +18,17 @@
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
+ import { name as NavigationTreeSourceName } from "@xwiki/platform-navigation-tree-api";
22
22
  import { Container, inject, injectable, named } from "inversify";
23
- import type { CristalApp, Logger } from "@xwiki/cristal-api";
24
- import type { AuthenticationManagerProvider } from "@xwiki/cristal-authentication-api";
25
- import type { DocumentReference } from "@xwiki/cristal-model-api";
26
- import type { ModelReferenceSerializer } from "@xwiki/cristal-model-reference-api";
27
- import type { RemoteURLParser } from "@xwiki/cristal-model-remote-url-api";
23
+ import type { CristalApp, Logger } from "@xwiki/platform-api";
24
+ import type { AuthenticationManagerProvider } from "@xwiki/platform-authentication-api";
25
+ import type { DocumentReference } from "@xwiki/platform-model-api";
26
+ import type { ModelReferenceSerializer } from "@xwiki/platform-model-reference-api";
27
+ import type { RemoteURLParser } from "@xwiki/platform-model-remote-url-api";
28
28
  import type {
29
29
  NavigationTreeNode,
30
30
  NavigationTreeSource,
31
- } from "@xwiki/cristal-navigation-tree-api";
31
+ } from "@xwiki/platform-navigation-tree-api";
32
32
 
33
33
  /**
34
34
  * Implementation of NavigationTreeSource for the XWiki backend.
package/CHANGELOG.md DELETED
@@ -1,231 +0,0 @@
1
- # @xwiki/cristal-navigation-tree-xwiki
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
-
19
- ## 0.22.0
20
-
21
- ### Minor Changes
22
-
23
- - Cristal 0.22 Release
24
-
25
- ### Patch Changes
26
-
27
- - Updated dependencies
28
- - @xwiki/cristal-api@0.22.0
29
- - @xwiki/cristal-authentication-api@0.22.0
30
- - @xwiki/cristal-model-api@0.22.0
31
- - @xwiki/cristal-model-reference-api@0.22.0
32
- - @xwiki/cristal-model-remote-url-api@0.22.0
33
- - @xwiki/cristal-navigation-tree-api@0.22.0
34
-
35
- ## 0.21.0
36
-
37
- ### Minor Changes
38
-
39
- - Cristal 0.21 Release
40
-
41
- ### Patch Changes
42
-
43
- - Updated dependencies
44
- - @xwiki/cristal-api@0.21.0
45
- - @xwiki/cristal-authentication-api@0.21.0
46
- - @xwiki/cristal-model-api@0.21.0
47
- - @xwiki/cristal-model-reference-api@0.21.0
48
- - @xwiki/cristal-model-remote-url-api@0.21.0
49
- - @xwiki/cristal-navigation-tree-api@0.21.0
50
-
51
- ## 0.20.0
52
-
53
- ### Minor Changes
54
-
55
- - Cristal 0.20 Release
56
-
57
- ### Patch Changes
58
-
59
- - Updated dependencies
60
- - @xwiki/cristal-api@0.20.0
61
- - @xwiki/cristal-authentication-api@0.20.0
62
- - @xwiki/cristal-model-api@0.20.0
63
- - @xwiki/cristal-model-reference-api@0.20.0
64
- - @xwiki/cristal-model-remote-url-api@0.20.0
65
- - @xwiki/cristal-navigation-tree-api@0.20.0
66
-
67
- ## 0.20.0-rc.0
68
-
69
- ### Minor Changes
70
-
71
- - Cristal 0.20-rc-1 Release
72
-
73
- ### Patch Changes
74
-
75
- - Updated dependencies
76
- - @xwiki/cristal-api@0.20.0-rc.0
77
- - @xwiki/cristal-authentication-api@0.20.0-rc.0
78
- - @xwiki/cristal-model-api@0.20.0-rc.0
79
- - @xwiki/cristal-model-reference-api@0.20.0-rc.0
80
- - @xwiki/cristal-model-remote-url-api@0.20.0-rc.0
81
- - @xwiki/cristal-navigation-tree-api@0.20.0-rc.0
82
-
83
- ## 0.19.0
84
-
85
- ### Minor Changes
86
-
87
- - 3eea53e: Cristal 0.19 Release
88
-
89
- ### Patch Changes
90
-
91
- - Updated dependencies [3eea53e]
92
- - @xwiki/cristal-api@0.19.0
93
- - @xwiki/cristal-authentication-api@0.19.0
94
- - @xwiki/cristal-model-api@0.19.0
95
- - @xwiki/cristal-model-reference-api@0.19.0
96
- - @xwiki/cristal-model-remote-url-api@0.19.0
97
- - @xwiki/cristal-navigation-tree-api@0.19.0
98
-
99
- ## 0.18.0
100
-
101
- ### Minor Changes
102
-
103
- - Cristal 0.18 Release
104
-
105
- ### Patch Changes
106
-
107
- - Updated dependencies
108
- - @xwiki/cristal-api@0.18.0
109
- - @xwiki/cristal-authentication-api@0.18.0
110
- - @xwiki/cristal-model-api@0.18.0
111
- - @xwiki/cristal-model-reference-api@0.18.0
112
- - @xwiki/cristal-model-remote-url-api@0.18.0
113
- - @xwiki/cristal-navigation-tree-api@0.18.0
114
-
115
- ## 0.17.0
116
-
117
- ### Minor Changes
118
-
119
- - Cristal 0.17 Release
120
-
121
- ### Patch Changes
122
-
123
- - Updated dependencies
124
- - @xwiki/cristal-api@0.17.0
125
- - @xwiki/cristal-authentication-api@0.17.0
126
- - @xwiki/cristal-model-api@0.17.0
127
- - @xwiki/cristal-model-reference-api@0.17.0
128
- - @xwiki/cristal-model-remote-url-api@0.17.0
129
- - @xwiki/cristal-navigation-tree-api@0.17.0
130
-
131
- ## 0.16.0
132
-
133
- ### Minor Changes
134
-
135
- - Cristal 0.16 Release
136
-
137
- ### Patch Changes
138
-
139
- - Updated dependencies
140
- - @xwiki/cristal-api@0.16.0
141
- - @xwiki/cristal-authentication-api@0.16.0
142
- - @xwiki/cristal-model-api@0.16.0
143
- - @xwiki/cristal-model-reference-api@0.16.0
144
- - @xwiki/cristal-model-remote-url-api@0.16.0
145
- - @xwiki/cristal-navigation-tree-api@0.16.0
146
-
147
- ## 0.15.0
148
-
149
- ### Minor Changes
150
-
151
- - Cristal 0.15 Release
152
-
153
- ### Patch Changes
154
-
155
- - Updated dependencies
156
- - @xwiki/cristal-api@0.15.0
157
- - @xwiki/cristal-authentication-api@0.15.0
158
- - @xwiki/cristal-model-api@0.15.0
159
- - @xwiki/cristal-model-reference-api@0.15.0
160
- - @xwiki/cristal-model-remote-url-api@0.15.0
161
- - @xwiki/cristal-navigation-tree-api@0.15.0
162
-
163
- ## 0.14.0
164
-
165
- ### Minor Changes
166
-
167
- - 3e5f853: Cristal 0.14 Release
168
-
169
- ### Patch Changes
170
-
171
- - Updated dependencies [3e5f853]
172
- - @xwiki/cristal-api@0.14.0
173
- - @xwiki/cristal-authentication-api@0.14.0
174
- - @xwiki/cristal-model-api@0.14.0
175
- - @xwiki/cristal-model-reference-api@0.14.0
176
- - @xwiki/cristal-model-remote-url-api@0.14.0
177
- - @xwiki/cristal-navigation-tree-api@0.14.0
178
-
179
- ## 0.13.0
180
-
181
- ### Minor Changes
182
-
183
- - 06a5d1b: Cristal 0.13 Release
184
-
185
- ### Patch Changes
186
-
187
- - Updated dependencies [06a5d1b]
188
- - @xwiki/cristal-api@0.13.0
189
- - @xwiki/cristal-authentication-api@0.13.0
190
- - @xwiki/cristal-model-api@0.13.0
191
- - @xwiki/cristal-model-reference-api@0.13.0
192
- - @xwiki/cristal-model-remote-url-api@0.13.0
193
- - @xwiki/cristal-navigation-tree-api@0.13.0
194
-
195
- ## 0.12.0
196
-
197
- ### Minor Changes
198
-
199
- - 681a9b7: Cristal 0.12 Release
200
-
201
- ### Patch Changes
202
-
203
- - Updated dependencies [681a9b7]
204
- - @xwiki/cristal-api@0.12.0
205
- - @xwiki/cristal-authentication-api@0.12.0
206
- - @xwiki/cristal-navigation-tree-api@0.12.0
207
-
208
- ## 0.11.0
209
-
210
- ### Minor Changes
211
-
212
- - d54422d: Cristal 0.11 Release
213
-
214
- ### Patch Changes
215
-
216
- - Updated dependencies [d54422d]
217
- - @xwiki/cristal-api@0.11.0
218
- - @xwiki/cristal-authentication-api@0.11.0
219
- - @xwiki/cristal-navigation-tree-api@0.11.0
220
-
221
- ## 0.10.0
222
-
223
- ### Minor Changes
224
-
225
- - fa7fe9f: Cristal 0.10 Release
226
-
227
- ### Patch Changes
228
-
229
- - Updated dependencies [fa7fe9f]
230
- - @xwiki/cristal-api@0.10.0
231
- - @xwiki/cristal-navigation-tree-api@0.10.0