@telia-ace/knowledge-widget-components-guide 0.0.1
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/answer-version-picker.d.ts +11 -0
- package/categories.d.ts +9 -0
- package/feedback.d.ts +8 -0
- package/functions.d.ts +30 -0
- package/guide-9d79906b.js +196 -0
- package/guide-bea67580.mjs +923 -0
- package/guide-component.d.ts +70 -0
- package/guide.d.ts +8 -0
- package/index.d.ts +3 -0
- package/index.js +2 -0
- package/index.mjs +141 -0
- package/package.json +30 -0
- package/toolbar.d.ts +9 -0
- package/use-feedback.d.ts +5 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { DataError } from '../../../knowledge/data-client/src/index.ts';
|
|
2
|
+
import { ContactMethodType } from '../../../knowledge/adapters/src/index.ts';
|
|
3
|
+
import { FavoriteProperties, LanguageProperties, MetaDataProperties } from '../../utilities/src/index.ts';
|
|
4
|
+
import { DialogItem, PickerTypes } from '../../../knowledge/core/src/index.ts';
|
|
5
|
+
import { FormComponentInstanceProperties } from '../../../forms/src/index.ts';
|
|
6
|
+
import { Container } from '@webprovisions/platform';
|
|
7
|
+
|
|
8
|
+
export type GuideProps = {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
body: string;
|
|
12
|
+
connection: string;
|
|
13
|
+
categories: number[];
|
|
14
|
+
hasHandover: boolean;
|
|
15
|
+
allowFeedback: boolean;
|
|
16
|
+
perspectives: {
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
};
|
|
19
|
+
translations?: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
modified?: string;
|
|
23
|
+
published?: string;
|
|
24
|
+
publishedBy?: string | null;
|
|
25
|
+
modifiedBy?: string | null;
|
|
26
|
+
perspective: string | null;
|
|
27
|
+
};
|
|
28
|
+
export type AvailablePerspectives = {
|
|
29
|
+
name: string;
|
|
30
|
+
title: string;
|
|
31
|
+
};
|
|
32
|
+
export type GuideComponentProps = {
|
|
33
|
+
showHeader?: boolean;
|
|
34
|
+
showFeedback?: boolean;
|
|
35
|
+
feedbackDirection?: 'horizontal' | 'vertical';
|
|
36
|
+
feedbackGiven?: 'positive' | 'negative';
|
|
37
|
+
contactMethods?: ContactMethodType[];
|
|
38
|
+
handoverContactMethods?: ContactMethodType[];
|
|
39
|
+
showAnswerVersions?: boolean;
|
|
40
|
+
feedbackHeader?: string;
|
|
41
|
+
contactHeader?: string;
|
|
42
|
+
toolbarFunctionsHeader?: string;
|
|
43
|
+
toolbarLanguageHeader?: string;
|
|
44
|
+
positiveFeedbackLabel?: string;
|
|
45
|
+
negativeFeedbackLabel?: string;
|
|
46
|
+
contactFeedbackLabel?: string;
|
|
47
|
+
feedbackRecognitionLabel?: string;
|
|
48
|
+
defaultAnswerVersionLabel?: string;
|
|
49
|
+
backButtonLabel?: string;
|
|
50
|
+
toolbarFunctionsTooltip?: string;
|
|
51
|
+
toolbarFunctionsCloseButtonAriaLabel?: string;
|
|
52
|
+
copyActionLabel?: string;
|
|
53
|
+
printActionLabel?: string;
|
|
54
|
+
toolbarLanguageTooltip?: string;
|
|
55
|
+
toolbar?: ToolbarProps;
|
|
56
|
+
guide?: GuideProps;
|
|
57
|
+
dialog?: DialogItem[];
|
|
58
|
+
error?: DataError;
|
|
59
|
+
availablePerspectives?: AvailablePerspectives[];
|
|
60
|
+
} & FormComponentInstanceProperties & FavoriteProperties & MetaDataProperties & LanguageProperties;
|
|
61
|
+
export type ToolbarProps = {
|
|
62
|
+
language?: boolean;
|
|
63
|
+
guideCategories?: boolean;
|
|
64
|
+
allowCopy?: boolean;
|
|
65
|
+
allowPrint?: boolean;
|
|
66
|
+
showFavoriteToggle?: boolean;
|
|
67
|
+
picker?: PickerTypes;
|
|
68
|
+
};
|
|
69
|
+
export declare const GuideComponent: (container: Container) => Promise<void>;
|
|
70
|
+
export default GuideComponent;
|
package/guide.d.ts
ADDED
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const u=require("@telia-ace/knowledge-data-client"),l=require("@telia-ace/knowledge-widget-component-utilities"),b=require("@telia-ace/knowledge-widget-core"),v=require("@telia-ace/knowledge-widget-ui"),k=require("clipboard-polyfill");function w(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(r,a,s.get?s:{enumerable:!0,get:()=>e[a]})}}return r.default=e,Object.freeze(r)}const m=w(k),y=(e,r)=>{r.actions.create("feedback",a=>{const s=a==="negative"?u.FeedbackType.Negative:u.FeedbackType.Positive,{guide:i,submitButtonLabel:c="Submit"}=r.properties();if(i){const{connection:t,id:n,hasHandover:o}=i;r.writeProperties({feedbackGiven:a,loading:o&&s===u.FeedbackType.Negative});const{events:d}=e.get("$widget");return d.dispatch("tracking:feedback-given",{guide:i,categories:i.categories,feedbackType:s.toLowerCase()}),u.DataClient.getInstance(e).then(h=>h.feedback(n,t,s).then(()=>{if(o&&s===u.FeedbackType.Negative)return h.fetch(u.DataType.ContactMethods,{guideId:n}).then(({contactMethods:p})=>r.actions.dispatch("handover",{handoverContactMethods:p.map(g=>({...g,body:l.updateForm(g,{submit:c})})),loading:!1}))}))}}),r.actions.create("handover",a=>r.writeProperties({...a,loading:!1}))},T=({title:e,body:r})=>{let a="";e&&e.length&&(a=e.trim()),r&&r.length&&(a=`${a.trim()}
|
|
2
|
+
${r.trim()}`);const s=document.createElement("div");s.innerHTML=a;const i=Array.from(s.getElementsByTagName("a"));let c=s.innerText;return i.forEach(t=>{c=c.replace(t.innerText,`[${t.href}] (${t.innerText})`)}),c},C=({title:e,body:r})=>{let a="";return e&&e.length&&(a=`<h2>${e.trim()}</h2>`),r&&r.length&&(a=`${a.trim()}${r.trim()}`),a.trim()},x=e=>{const{events:r}=e.get("$widget"),[a,s]=b.createEventSubscriber(r);return v.createReactComponent(e,"guide",Promise.resolve().then(()=>require("./guide-9d79906b.js")),i=>{const c=t=>{i.writeProperties({loading:!0,error:void 0,guide:void 0,dialog:void 0,contactMethods:void 0,feedbackGiven:void 0}),i.actions.dispatch("fetch",{params:t})};i.actions.create("copy",t=>{const n=new m.ClipboardItem({"text/html":new Blob([C(t)],{type:"text/html"}),"text/plain":new Blob([T(t)],{type:"text/plain"})});return m.write([n]).then(()=>{r.dispatch("widget:menu-toggled",null)})}),i.actions.create("print",()=>{const t=document.querySelector(".humany-guide .humany-paragraph"),n=window.open("","","height=500, width=500");r.dispatch("widget:menu-toggled",null),t&&n&&(n.document.write(`<html><body>${t.innerHTML}</body></html>`),n.document.close(),n.print())}),i.actions.create("back",(t,n)=>{if(!n.preventDefault)return e.getAsync("router").then(o=>{o.goBack()})}),i.actions.create("fetch",({contactMethods:t=[],dialog:n=[],guide:o,error:d})=>{if(d)return i.actions.dispatch("fetched",{error:d,guide:void 0,contactMethods:[],feedbackGiven:void 0,handoverContactMethods:[],showFeedback:!1,loading:!0});const{showFeedback:h=!0,submitButtonLabel:p="Submit"}=i.properties(),g={showFeedback:h,dialog:n,guide:o,feedbackGiven:void 0,handoverContactMethods:[],contactMethods:t.map(f=>({...f,body:l.updateForm(f,{submit:p})}))};return i.actions.dispatch("fetched",{...g,loading:!0})}),i.actions.create("fetched",t=>i.writeProperties({...t,feedbackGiven:void 0,loading:!1})),e.getAsync("router").then(t=>{const{params:n}=t.getRouteData();c(n)}),a("router:changed",(t,{current:n})=>{c(n.routeData.params)}),y(e,i),l.useForm(e,i),l.useExpand(i)}).then(()=>b.extendComponent(e,"guide",i=>{i.actions.watch("guide.fetch",(c,t)=>{const{params:{guide:n,connection:o}}=c;return n?u.DataClient.getInstance(e).then(d=>d.fetch(u.DataType.Guide,{connection:o,guideId:n})).then(t).catch(d=>{if(d)return t(d)}):t(c)})})).then(()=>{s()})};module.exports=x;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { FeedbackType as g, DataClient as l, DataType as b } from "@telia-ace/knowledge-data-client";
|
|
2
|
+
import { updateForm as v, useForm as w, useExpand as k } from "@telia-ace/knowledge-widget-component-utilities";
|
|
3
|
+
import { createEventSubscriber as y, extendComponent as T } from "@telia-ace/knowledge-widget-core";
|
|
4
|
+
import { createReactComponent as x } from "@telia-ace/knowledge-widget-ui";
|
|
5
|
+
import * as p from "clipboard-polyfill";
|
|
6
|
+
const $ = (a, r) => {
|
|
7
|
+
r.actions.create("feedback", (n) => {
|
|
8
|
+
const d = n === "negative" ? g.Negative : g.Positive, { guide: t, submitButtonLabel: s = "Submit" } = r.properties();
|
|
9
|
+
if (t) {
|
|
10
|
+
const { connection: e, id: i, hasHandover: c } = t;
|
|
11
|
+
r.writeProperties({
|
|
12
|
+
feedbackGiven: n,
|
|
13
|
+
loading: c && d === g.Negative
|
|
14
|
+
});
|
|
15
|
+
const { events: o } = a.get("$widget");
|
|
16
|
+
return o.dispatch("tracking:feedback-given", {
|
|
17
|
+
guide: t,
|
|
18
|
+
categories: t.categories,
|
|
19
|
+
feedbackType: d.toLowerCase()
|
|
20
|
+
}), l.getInstance(a).then((u) => u.feedback(i, e, d).then(() => {
|
|
21
|
+
if (c && d === g.Negative)
|
|
22
|
+
return u.fetch(b.ContactMethods, { guideId: i }).then(({ contactMethods: f }) => r.actions.dispatch("handover", {
|
|
23
|
+
handoverContactMethods: f.map((h) => ({
|
|
24
|
+
...h,
|
|
25
|
+
body: v(h, {
|
|
26
|
+
submit: s
|
|
27
|
+
})
|
|
28
|
+
})),
|
|
29
|
+
loading: !1
|
|
30
|
+
}));
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
}), r.actions.create("handover", (n) => r.writeProperties({ ...n, loading: !1 }));
|
|
34
|
+
}, C = ({ title: a, body: r }) => {
|
|
35
|
+
let n = "";
|
|
36
|
+
a && a.length && (n = a.trim()), r && r.length && (n = `${n.trim()}
|
|
37
|
+
${r.trim()}`);
|
|
38
|
+
const d = document.createElement("div");
|
|
39
|
+
d.innerHTML = n;
|
|
40
|
+
const t = Array.from(d.getElementsByTagName("a"));
|
|
41
|
+
let s = d.innerText;
|
|
42
|
+
return t.forEach((e) => {
|
|
43
|
+
s = s.replace(e.innerText, `[${e.href}] (${e.innerText})`);
|
|
44
|
+
}), s;
|
|
45
|
+
}, M = ({ title: a, body: r }) => {
|
|
46
|
+
let n = "";
|
|
47
|
+
return a && a.length && (n = `<h2>${a.trim()}</h2>`), r && r.length && (n = `${n.trim()}${r.trim()}`), n.trim();
|
|
48
|
+
}, P = (a) => {
|
|
49
|
+
const { events: r } = a.get("$widget"), [n, d] = y(r);
|
|
50
|
+
return x(
|
|
51
|
+
a,
|
|
52
|
+
"guide",
|
|
53
|
+
import("./guide-bea67580.mjs"),
|
|
54
|
+
(t) => {
|
|
55
|
+
const s = (e) => {
|
|
56
|
+
t.writeProperties({
|
|
57
|
+
loading: !0,
|
|
58
|
+
error: void 0,
|
|
59
|
+
guide: void 0,
|
|
60
|
+
dialog: void 0,
|
|
61
|
+
contactMethods: void 0,
|
|
62
|
+
feedbackGiven: void 0
|
|
63
|
+
}), t.actions.dispatch("fetch", { params: e });
|
|
64
|
+
};
|
|
65
|
+
t.actions.create("copy", (e) => {
|
|
66
|
+
const i = new p.ClipboardItem({
|
|
67
|
+
"text/html": new Blob([M(e)], { type: "text/html" }),
|
|
68
|
+
"text/plain": new Blob([C(e)], {
|
|
69
|
+
type: "text/plain"
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
return p.write([i]).then(() => {
|
|
73
|
+
r.dispatch("widget:menu-toggled", null);
|
|
74
|
+
});
|
|
75
|
+
}), t.actions.create("print", () => {
|
|
76
|
+
const e = document.querySelector(".humany-guide .humany-paragraph"), i = window.open("", "", "height=500, width=500");
|
|
77
|
+
r.dispatch("widget:menu-toggled", null), e && i && (i.document.write(`<html><body>${e.innerHTML}</body></html>`), i.document.close(), i.print());
|
|
78
|
+
}), t.actions.create("back", (e, i) => {
|
|
79
|
+
if (!i.preventDefault)
|
|
80
|
+
return a.getAsync("router").then((c) => {
|
|
81
|
+
c.goBack();
|
|
82
|
+
});
|
|
83
|
+
}), t.actions.create(
|
|
84
|
+
"fetch",
|
|
85
|
+
({ contactMethods: e = [], dialog: i = [], guide: c, error: o }) => {
|
|
86
|
+
if (o)
|
|
87
|
+
return t.actions.dispatch("fetched", {
|
|
88
|
+
error: o,
|
|
89
|
+
guide: void 0,
|
|
90
|
+
contactMethods: [],
|
|
91
|
+
feedbackGiven: void 0,
|
|
92
|
+
handoverContactMethods: [],
|
|
93
|
+
showFeedback: !1,
|
|
94
|
+
loading: !0
|
|
95
|
+
});
|
|
96
|
+
const { showFeedback: u = !0, submitButtonLabel: f = "Submit" } = t.properties(), h = {
|
|
97
|
+
showFeedback: u,
|
|
98
|
+
dialog: i,
|
|
99
|
+
guide: c,
|
|
100
|
+
feedbackGiven: void 0,
|
|
101
|
+
handoverContactMethods: [],
|
|
102
|
+
contactMethods: e.map((m) => ({
|
|
103
|
+
...m,
|
|
104
|
+
body: v(m, { submit: f })
|
|
105
|
+
}))
|
|
106
|
+
};
|
|
107
|
+
return t.actions.dispatch("fetched", {
|
|
108
|
+
...h,
|
|
109
|
+
loading: !0
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
), t.actions.create("fetched", (e) => t.writeProperties({
|
|
113
|
+
...e,
|
|
114
|
+
feedbackGiven: void 0,
|
|
115
|
+
loading: !1
|
|
116
|
+
})), a.getAsync("router").then((e) => {
|
|
117
|
+
const { params: i } = e.getRouteData();
|
|
118
|
+
s(i);
|
|
119
|
+
}), n("router:changed", (e, { current: i }) => {
|
|
120
|
+
s(i.routeData.params);
|
|
121
|
+
}), $(a, t), w(a, t), k(t);
|
|
122
|
+
}
|
|
123
|
+
).then(() => T(a, "guide", (t) => {
|
|
124
|
+
t.actions.watch("guide.fetch", (s, e) => {
|
|
125
|
+
const {
|
|
126
|
+
params: { guide: i, connection: c }
|
|
127
|
+
} = s;
|
|
128
|
+
return i ? l.getInstance(a).then(
|
|
129
|
+
(o) => o.fetch(b.Guide, { connection: c, guideId: i })
|
|
130
|
+
).then(e).catch((o) => {
|
|
131
|
+
if (o)
|
|
132
|
+
return e(o);
|
|
133
|
+
}) : e(s);
|
|
134
|
+
});
|
|
135
|
+
})).then(() => {
|
|
136
|
+
d();
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
export {
|
|
140
|
+
P as default
|
|
141
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/knowledge-widget-components-guide",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@telia-ace/knowledge-widget-ui": "*",
|
|
14
|
+
"@telia-ace/widget-utilities": "*",
|
|
15
|
+
"@telia-ace/knowledge-widget-core": "*",
|
|
16
|
+
"@telia-ace/knowledge-widget-adapters": "*",
|
|
17
|
+
"@telia-ace/knowledge-widget-component-utilities": "*",
|
|
18
|
+
"@telia-ace/widget-forms": "*",
|
|
19
|
+
"@telia-ace/widget-routing": "*",
|
|
20
|
+
"@telia-ace/widget-types-grid": "*",
|
|
21
|
+
"@telia-ace/knowledge-data-client": "*",
|
|
22
|
+
"@webprovisions/platform": "^1.1.4",
|
|
23
|
+
"clipboard-polyfill": "4.0.0-rc1"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@emotion/react": "11.11.1",
|
|
27
|
+
"@emotion/styled": "11.11.0",
|
|
28
|
+
"react": "18.2.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/toolbar.d.ts
ADDED