@digital-realty/ui-knowledgebase 0.1.1 → 0.1.2-IXUAT-11233.560235

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.
@@ -1,18 +1,68 @@
1
- import{LitElement as e,css as t,html as n,nothing as r}from"lit";import{customElement as i,property as a,state as o}from"lit/decorators.js";import{Router as s}from"@vaadin/router";var c=null;function l(e,t,n){c=new s(e,{baseUrl:t}),c.setRoutes(n)}function u(){return c}function d(){c?.unsubscribe(),c?.removeRoutes(),c=null}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var p=class extends e{static{this.styles=t`
1
+ import{LitElement as e,css as t,html as n,nothing as r}from"lit";import{customElement as i,property as a,state as o}from"lit/decorators.js";import{Router as s}from"@vaadin/router";var c=null;function l(e,t,n){c=new s(e,{baseUrl:t}),c.setRoutes(n)}function u(){return c}function d(){c?.unsubscribe(),c?.removeRoutes(),c=null}function f(e,t,n){if(e!=null){if(Array.isArray(e)){e.forEach((e,r)=>f(e,`${t}[${r}]`,n));return}if(typeof e==`object`){for(let[r,i]of Object.entries(e))i!==void 0&&f(i,`${t}[${r}]`,n);return}n.push(`${encodeURIComponent(t)}=${encodeURIComponent(String(e))}`)}}function p(e){let t=[];for(let[n,r]of Object.entries(e))r!==void 0&&f(r,n,t);return t.length?`?${t.join(`&`)}`:``}function m(e,t){return e?/^https?:\/\//i.test(e)?e:`${t.replace(/\/+$/,``)}${e.startsWith(`/`)?e:`/${e}`}`:``}function h(e,t){if(!e||!e.url)return null;let n;if(e.formats){n={};for(let[r,i]of Object.entries(e.formats))i?.url&&(n[r]={url:m(i.url,t),width:i.width,height:i.height})}return{url:m(e.url,t),alternativeText:e.alternativeText??null,mime:e.mime,name:e.name,width:e.width,height:e.height,formats:n}}var g=e=>e===`text`||e===`accordion`||e===`video_card`||e===`document_card`?e:void 0;function _(e){return{documentId:e.documentId??``,code:e.code??``,name:e.name??``,icon:e.icon}}function v(e,t){return{documentId:e.documentId??``,uid:e.uid??``,title:e.title??``,subtitle:e.subtitle,icon:e.icon,image:h(e.image,t),behavior:g(e.behavior),order:e.order,showSortBy:e.showSortBy??!1,showFilterByTopic:e.showFilterByTopic??!1}}function y(e,t){return{documentId:e.documentId??``,uid:e.uid??``,title:e.title??``,abstract:e.abstract,text:e.text,behavior:g(e.behavior),featured:e.featured??!1,duration:e.duration,dateAdded:e.dateAdded,publishedAt:e.publishedAt??null,topics:(e.topics??[]).map(_),category:e.category?v(e.category,t):null,thumbnail:h(e.thumbnail,t),video:h(e.video,t),documents:(e.documents??[]).map(e=>h(e,t)).filter(e=>e!==null)}}function b(e,t){return e?{heading:e.heading??``,description:e.description??``,backgroundImage:h(e.backgroundImage,t)}:null}var x=class extends Error{constructor(e,t){super(e,t?.cause===void 0?void 0:{cause:t.cause}),this.name=`KbApiError`,this.status=t?.status}},S=`whats-new`,C=100,w={thumbnail:!0,video:!0,documents:!0,topics:!0,category:!0};function T(e){let t=e.apiBaseUrl.replace(/\/+$/,``),n=e.mediaBaseUrl,r=e.previewDrafts?`draft`:`published`,i=e.locale,a=e.fetch??globalThis.fetch.bind(globalThis);async function o(e,n){let o=p({...n,status:r,locale:i}),s=`${t}/api/${e}${o}`,c;try{c=await a(s)}catch(t){throw new x(`Network error fetching ${e}`,{cause:t})}if(!c.ok)throw new x(`Strapi responded ${c.status} for ${e}`,{status:c.status});let l;try{l=await c.json()}catch(t){throw new x(`Invalid JSON from ${e}`,{cause:t})}return l.data}async function s(e,t){return await o(e,t)??[]}return{async getLanding(){let[e,t,r,i,a]=await Promise.all([o(`index-page`,{populate:{backgroundImage:!0}}),s(`categories`,{populate:{image:!0},sort:[`order:asc`],pagination:{pageSize:C}}),s(`topics`,{sort:[`order:asc`],pagination:{pageSize:C}}),s(`posts`,{filters:{featured:{$eq:!0}},populate:w,sort:[`dateAdded:desc`],pagination:{pageSize:C}}),s(`posts`,{filters:{category:{uid:{$eq:S}}},populate:w,sort:[`dateAdded:desc`],pagination:{pageSize:C}})]);return{indexPage:b(e,n),categories:t.map(e=>v(e,n)),topics:r.map(e=>_(e)),featured:i.map(e=>y(e,n)),whatsNew:a.map(e=>y(e,n))}},async getCategory(e){let[t,r]=await Promise.all([s(`categories`,{filters:{uid:{$eq:e}},populate:{image:!0},pagination:{pageSize:1}}),s(`posts`,{filters:{category:{uid:{$eq:e}}},populate:w,sort:[`dateAdded:desc`],pagination:{pageSize:C}})]);return{category:t[0]?v(t[0],n):null,posts:r.map(e=>y(e,n))}},async getTopic(e){let[t,r]=await Promise.all([s(`topics`,{filters:{code:{$eq:e}},pagination:{pageSize:1}}),s(`posts`,{filters:{topics:{code:{$eq:e}}},populate:w,sort:[`dateAdded:desc`],pagination:{pageSize:C}})]);return{topic:t[0]?_(t[0]):null,posts:r.map(e=>y(e,n))}},async getPost(e){let t=await s(`posts`,{filters:{uid:{$eq:e}},populate:w,pagination:{pageSize:1}});return t[0]?y(t[0],n):null}}}function E(e){let t=new Map;function n(e,n){let r=t.get(e);if(r)return r;let i=n().catch(n=>{throw t.delete(e),n});return t.set(e,i),i}return{getLanding:()=>n(`landing`,()=>e.getLanding()),getCategory:t=>n(`category:${t}`,()=>e.getCategory(t)),getTopic:t=>n(`topic:${t}`,()=>e.getTopic(t)),getPost:t=>n(`post:${t}`,()=>e.getPost(t)),invalidate:e=>{e?t.delete(e):t.clear()}}}function D(){let e=window.gpConfig?.[`ui-knowledgebase`],t=e?.[`KB:strapiBaseUrl`];if(!t)throw Error(`ui-knowledgebase config not loaded: window.gpConfig['ui-knowledgebase']['KB:strapiBaseUrl'] is missing. Ensure config.json is fetched before the KB route renders.`);return{apiBaseUrl:t,mediaBaseUrl:t,previewDrafts:e?.[`KB:previewDraftContent`]??!1,locale:`en`}}var O;function k(){return O||=E(T(D())),O}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var j=class extends e{constructor(...e){super(...e),this.loading=!0,this.error=!1,this.data=null}static{this.styles=t`
2
2
  :host {
3
3
  display: block;
4
4
  padding: 1rem;
5
5
  }
6
- `}render(){return n`
7
- <h1>Knowledge Base</h1>
8
- <nav>
6
+ h2 {
7
+ margin-top: 1.5rem;
8
+ }
9
+ ul {
10
+ list-style: none;
11
+ padding: 0;
12
+ }
13
+ .muted {
14
+ color: #666;
15
+ }
16
+ button {
17
+ cursor: pointer;
18
+ }
19
+ `}connectedCallback(){super.connectedCallback(),this.load()}async load(){this.loading=!0,this.error=!1;try{this.data=await k().getLanding()}catch{this.error=!0}finally{this.loading=!1}}render(){if(this.loading)return n`<p class="muted">Loading…</p>`;if(this.error||!this.data)return n`
20
+ <p role="alert">Couldn't load the Knowledge Base.</p>
21
+ <button @click=${()=>void this.load()}>Retry</button>
22
+ `;let{indexPage:e,categories:t,topics:i,featured:a,whatsNew:o}=this.data;return n`
23
+ <header>
24
+ <h1>${e?.heading??`Knowledge Base`}</h1>
25
+ ${e?.description?n`<p class="muted">${e.description}</p>`:r}
26
+ </header>
27
+
28
+ <section>
29
+ <h2>Categories</h2>
30
+ <ul>
31
+ ${t.map(e=>n`
32
+ <li>
33
+ <a href="${F}/category/${e.uid}">${e.title}</a>
34
+ ${e.subtitle?n`<span class="muted"> — ${e.subtitle}</span>`:r}
35
+ </li>
36
+ `)}
37
+ </ul>
38
+ </section>
39
+
40
+ <section>
41
+ <h2>Topics</h2>
9
42
  <ul>
10
- <li><a href="/knowledge-base/category/demo">Category: demo</a></li>
11
- <li><a href="/knowledge-base/topic/demo">Topic: demo</a></li>
12
- <li><a href="/knowledge-base/details/demo">Details: demo</a></li>
43
+ ${i.map(e=>n`<li><a href="${F}/topic/${e.code}">${e.name}</a></li>`)}
13
44
  </ul>
14
- </nav>
15
- `}};p=f([i(`kb-landing-view`)],p);var m=class extends e{constructor(...e){super(...e),this.uid=``}static{this.styles=t`
45
+ </section>
46
+
47
+ <section>
48
+ <h2>Featured Resources</h2>
49
+ ${this.renderPostList(a)}
50
+ </section>
51
+
52
+ <section>
53
+ <h2>What's New</h2>
54
+ ${this.renderPostList(o)}
55
+ </section>
56
+ `}renderPostList(e){return e.length===0?n`<p class="muted">Nothing here yet.</p>`:n`
57
+ <ul>
58
+ ${e.map(e=>n`
59
+ <li>
60
+ <a href="${F}/details/${e.uid}">${e.title}</a>
61
+ ${e.abstract?n`<span class="muted"> — ${e.abstract}</span>`:r}
62
+ </li>
63
+ `)}
64
+ </ul>
65
+ `}};A([o()],j.prototype,`loading`,void 0),A([o()],j.prototype,`error`,void 0),A([o()],j.prototype,`data`,void 0),j=A([i(`kb-landing-view`)],j);var M=class extends e{constructor(...e){super(...e),this.uid=``}static{this.styles=t`
16
66
  :host {
17
67
  display: block;
18
68
  padding: 1rem;
@@ -20,7 +70,7 @@ import{LitElement as e,css as t,html as n,nothing as r}from"lit";import{customEl
20
70
  `}onAfterEnter(e){this.uid=String(e.params.uid??``)}render(){return n`
21
71
  <a href="/knowledge-base">&larr; Knowledge Base</a>
22
72
  <h1>Category: ${this.uid}</h1>
23
- `}};f([o()],m.prototype,`uid`,void 0),m=f([i(`kb-category-view`)],m);var h=class extends e{constructor(...e){super(...e),this.code=``}static{this.styles=t`
73
+ `}};A([o()],M.prototype,`uid`,void 0),M=A([i(`kb-category-view`)],M);var N=class extends e{constructor(...e){super(...e),this.code=``}static{this.styles=t`
24
74
  :host {
25
75
  display: block;
26
76
  padding: 1rem;
@@ -28,7 +78,7 @@ import{LitElement as e,css as t,html as n,nothing as r}from"lit";import{customEl
28
78
  `}onAfterEnter(e){this.code=String(e.params.code??``)}render(){return n`
29
79
  <a href="/knowledge-base">&larr; Knowledge Base</a>
30
80
  <h1>Topic: ${this.code}</h1>
31
- `}};f([o()],h.prototype,`code`,void 0),h=f([i(`kb-topic-view`)],h);var g=class extends e{constructor(...e){super(...e),this.uid=``}static{this.styles=t`
81
+ `}};A([o()],N.prototype,`code`,void 0),N=A([i(`kb-topic-view`)],N);var P=class extends e{constructor(...e){super(...e),this.uid=``}static{this.styles=t`
32
82
  :host {
33
83
  display: block;
34
84
  padding: 1rem;
@@ -36,4 +86,4 @@ import{LitElement as e,css as t,html as n,nothing as r}from"lit";import{customEl
36
86
  `}onAfterEnter(e){this.uid=String(e.params.uid??``)}render(){return n`
37
87
  <a href="/knowledge-base">&larr; Knowledge Base</a>
38
88
  <h1>Details: ${this.uid}</h1>
39
- `}};f([o()],g.prototype,`uid`,void 0),g=f([i(`kb-details-view`)],g);var _=`/knowledge-base`,v=e=>e===`/knowledge-base`||e.startsWith(`/knowledge-base/`),y={Landing:`kb-landing`,Category:`kb-category`,Topic:`kb-topic`,Details:`kb-details`},b=[{path:_,children:[{name:y.Landing,path:`/`,component:`kb-landing-view`},{name:y.Category,path:`/category/:uid`,component:`kb-category-view`},{name:y.Topic,path:`/topic/:code`,component:`kb-topic-view`},{name:y.Details,path:`/details/:uid`,component:`kb-details-view`}]},{path:`(.*)`,component:`no-elem`}],x=class extends e{constructor(...e){super(...e),this.baseUrl=`/`,this.active=!1,this.outlet=document.createElement(`main`),this.onLocationChanged=e=>{let{router:t,location:n}=e.detail;t===u()&&(this.active=v(n.pathname))}}connectedCallback(){super.connectedCallback(),window.addEventListener(`vaadin-router-location-changed`,this.onLocationChanged),l(this.outlet,this.baseUrl,b),this.dispatchEvent(new CustomEvent(`mfe-loaded`,{detail:{routes:b}}))}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(`vaadin-router-location-changed`,this.onLocationChanged),d(),this.active=!1}render(){return this.active?n`${this.outlet}`:r}};f([a({type:String})],x.prototype,`baseUrl`,void 0),f([o()],x.prototype,`active`,void 0),x=f([i(`ui-knowledgebase`)],x);export{x as UiKnowledgebase};
89
+ `}};A([o()],P.prototype,`uid`,void 0),P=A([i(`kb-details-view`)],P);var F=`/knowledge-base`,I=e=>e===`/knowledge-base`||e.startsWith(`/knowledge-base/`),L={Landing:`kb-landing`,Category:`kb-category`,Topic:`kb-topic`,Details:`kb-details`},R=[{path:F,children:[{name:L.Landing,path:`/`,component:`kb-landing-view`},{name:L.Category,path:`/category/:uid`,component:`kb-category-view`},{name:L.Topic,path:`/topic/:code`,component:`kb-topic-view`},{name:L.Details,path:`/details/:uid`,component:`kb-details-view`}]},{path:`(.*)`,component:`no-elem`}],z=class extends e{constructor(...e){super(...e),this.baseUrl=`/`,this.active=!1,this.outlet=document.createElement(`main`),this.onLocationChanged=e=>{let{router:t,location:n}=e.detail;t===u()&&(this.active=I(n.pathname))}}connectedCallback(){super.connectedCallback(),window.addEventListener(`vaadin-router-location-changed`,this.onLocationChanged),l(this.outlet,this.baseUrl,R),this.dispatchEvent(new CustomEvent(`mfe-loaded`,{detail:{routes:R}}))}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(`vaadin-router-location-changed`,this.onLocationChanged),d(),this.active=!1}render(){return this.active?n`${this.outlet}`:r}};A([a({type:String})],z.prototype,`baseUrl`,void 0),A([o()],z.prototype,`active`,void 0),z=A([i(`ui-knowledgebase`)],z);export{z as UiKnowledgebase};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-realty/ui-knowledgebase",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-IXUAT-11233.560235",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,6 +24,7 @@
24
24
  "scripts": {
25
25
  "dev": "vite",
26
26
  "build": "tsc --noEmit && vite build",
27
+ "build:watch": "vite build --watch",
27
28
  "build:workspace": "pnpm run build",
28
29
  "test": "echo \"ui-knowledgebase: no test suite yet\"",
29
30
  "preview": "vite preview",