@nectary/components 4.6.8 → 4.7.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/package.json +3 -3
- package/radio/index.js +1 -1
- package/radio/types.d.ts +4 -0
- package/rich-text/index.js +27 -1
- package/rich-text/types.d.ts +7 -0
- package/rich-text/utils.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"**/*/*.css",
|
|
6
6
|
"**/*/*.json",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/runtime": "^7.22.15",
|
|
23
|
-
"@nectary/assets": "2.2.
|
|
23
|
+
"@nectary/assets": "2.2.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/cli": "^7.22.15",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"typescript": "^5.2.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@nectary/theme-base": "1.4.
|
|
37
|
+
"@nectary/theme-base": "1.4.1"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/radio/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getTargetByAttribute, isAttrTrue, NectaryElement, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;gap:8px;box-sizing:border-box;width:100%}</style><div id="wrapper"><slot></slot></div>';
|
|
2
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:var(--sinch-comp-radio-direction,column);gap:var(--sinch-comp-radio-gap,8px);box-sizing:border-box;width:100%}</style><div id="wrapper"><slot></slot></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-radio', class extends NectaryElement {
|
package/radio/types.d.ts
CHANGED
|
@@ -11,4 +11,8 @@ export type TSinchRadioReact = TSinchElementReact<TSinchRadioElement> & {
|
|
|
11
11
|
invalid?: boolean;
|
|
12
12
|
'aria-label': string;
|
|
13
13
|
'on-change'?: (e: CustomEvent<string>) => void;
|
|
14
|
+
style?: {
|
|
15
|
+
'--sinch-comp-radio-direction'?: 'row' | 'column';
|
|
16
|
+
'--sinch-comp-radio-gap'?: number | string;
|
|
17
|
+
};
|
|
14
18
|
};
|
package/rich-text/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getEmojiBaseUrl } from '../emoji/utils';
|
|
|
2
2
|
import '../emoji';
|
|
3
3
|
import '../code-tag';
|
|
4
4
|
import '../link';
|
|
5
|
-
import { defineCustomElement, NectaryElement, getLiteralAttribute, updateLiteralAttribute, getAttribute, updateAttribute, parseMarkdown } from '../utils';
|
|
5
|
+
import { defineCustomElement, NectaryElement, getLiteralAttribute, updateLiteralAttribute, getAttribute, updateAttribute, parseMarkdown, getReactEventHandler } from '../utils';
|
|
6
6
|
const templateHTML = '<style>:host{display:block;--sinch-comp-rich-text-font:var(--sinch-sys-font-body-m)}:host([size="s"]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-s)}:host([size=xs]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-xs)}:host([size=xxs]){--sinch-comp-rich-text-font:var(--sinch-sys-font-body-xxs)}#wrapper{font:var(--sinch-comp-rich-text-font);color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default))}.em1{font-style:italic}.em2{font-weight:var(--sinch-ref-typography-font-weight-700)}.strikethrough{text-decoration:line-through}.link{font:var(--sinch-comp-link-default-font-initial);color:var(--sinch-comp-link-color-default-text-initial);text-decoration:underline}.link:hover{color:var(--sinch-comp-link-color-default-text-hover);text-decoration:none}.code{font:var(--sinch-comp-code-tag-font-text);line-height:inherit;font-size:inherit;border:1px solid var(--sinch-comp-code-tag-color-default-border-initial);background-color:var(--sinch-comp-code-tag-color-default-background-initial);padding:0 .25em;border-radius:var(--sinch-comp-code-tag-shape-radius)}.emoji{--sinch-global-size-icon:1em;--sinch-comp-emoji-vertical-align:-0.2em}.ol,.p,.ul{margin:0}.ol,.ul{padding-left:1.5em}.ol+.p,.p+.ol,.p+.p,.p+.ul,.ul+.p{margin-top:.5em}.li>.p+.ol,.li>.p+.ul{margin-top:0}</style><div id="wrapper"></div>';
|
|
7
7
|
import { createParseVisitor, sizeValues } from './utils';
|
|
8
8
|
const template = document.createElement('template');
|
|
@@ -10,6 +10,7 @@ template.innerHTML = templateHTML;
|
|
|
10
10
|
defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
11
11
|
#wrapper;
|
|
12
12
|
#parseVisitor;
|
|
13
|
+
#controller = null;
|
|
13
14
|
constructor() {
|
|
14
15
|
super();
|
|
15
16
|
const shadowRoot = this.attachShadow();
|
|
@@ -29,12 +30,26 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
29
30
|
this.#parseVisitor = createParseVisitor(shadowRoot);
|
|
30
31
|
}
|
|
31
32
|
connectedCallback() {
|
|
33
|
+
this.#controller = new AbortController();
|
|
34
|
+
const {
|
|
35
|
+
signal
|
|
36
|
+
} = this.#controller;
|
|
32
37
|
super.connectedCallback();
|
|
33
38
|
this.setAttribute('role', 'paragraph');
|
|
34
39
|
this.#parseVisitor.updateEmojiBaseUrl(getEmojiBaseUrl(this));
|
|
35
40
|
this.#updateText();
|
|
41
|
+
this.#wrapper.addEventListener('click', this.#handleElementClick, {
|
|
42
|
+
signal
|
|
43
|
+
});
|
|
44
|
+
this.addEventListener('-element-click', this.#onClickReactHandler, {
|
|
45
|
+
signal
|
|
46
|
+
});
|
|
36
47
|
}
|
|
37
48
|
disconnectedCallback() {
|
|
49
|
+
this.#controller?.abort();
|
|
50
|
+
this.#controller = null;
|
|
51
|
+
this.#wrapper.removeEventListener('click', this.#handleElementClick);
|
|
52
|
+
this.removeEventListener('-element-click', this.#onClickReactHandler);
|
|
38
53
|
super.disconnectedCallback();
|
|
39
54
|
}
|
|
40
55
|
static get observedAttributes() {
|
|
@@ -61,6 +76,14 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
61
76
|
set text(value) {
|
|
62
77
|
updateAttribute(this, 'text', value);
|
|
63
78
|
}
|
|
79
|
+
#handleElementClick = e => {
|
|
80
|
+
const eventTarget = e.target;
|
|
81
|
+
const elementClickEvent = new CustomEvent('-element-click');
|
|
82
|
+
Object.defineProperty(elementClickEvent, 'currentTarget', {
|
|
83
|
+
value: eventTarget
|
|
84
|
+
});
|
|
85
|
+
this.dispatchEvent(elementClickEvent);
|
|
86
|
+
};
|
|
64
87
|
#updateText() {
|
|
65
88
|
if (!this.isDomConnected) {
|
|
66
89
|
return;
|
|
@@ -72,4 +95,7 @@ defineCustomElement('sinch-rich-text', class extends NectaryElement {
|
|
|
72
95
|
this.#wrapper.replaceChildren(parseMarkdown(text, this.#parseVisitor.createVisitor()));
|
|
73
96
|
}
|
|
74
97
|
}
|
|
98
|
+
#onClickReactHandler = e => {
|
|
99
|
+
getReactEventHandler(this, 'on-element-click')?.(e);
|
|
100
|
+
};
|
|
75
101
|
});
|
package/rich-text/types.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import type { TSinchTextType } from '../text/types';
|
|
2
2
|
import type { TSinchElementReact } from '../types';
|
|
3
|
+
export type ElementClickedEvent = CustomEvent & {
|
|
4
|
+
currentTarget: HTMLElement;
|
|
5
|
+
};
|
|
3
6
|
export type TSinchRichTextElement = HTMLElement & {
|
|
4
7
|
size: TSinchTextType;
|
|
5
8
|
text: string;
|
|
6
9
|
setAttribute(name: 'size', value: TSinchTextType): void;
|
|
7
10
|
setAttribute(name: 'text', value: string): void;
|
|
11
|
+
/** Click event */
|
|
12
|
+
addEventListener(type: '-element-click', listener: (e: ElementClickedEvent) => void): void;
|
|
8
13
|
};
|
|
9
14
|
export type TSinchRichTextReact = TSinchElementReact<TSinchRichTextElement> & {
|
|
10
15
|
size?: TSinchTextType;
|
|
11
16
|
text: string;
|
|
17
|
+
/** Click event handler */
|
|
18
|
+
'on-element-click'?: (e: ElementClickedEvent) => void;
|
|
12
19
|
} & {
|
|
13
20
|
style?: {
|
|
14
21
|
'--sinch-comp-rich-text-font'?: string;
|
package/rich-text/utils.js
CHANGED
|
@@ -53,7 +53,13 @@ export const createParseVisitor = doc => {
|
|
|
53
53
|
$link.href = href;
|
|
54
54
|
if (attributes != null) {
|
|
55
55
|
attributes.forEach(attr => {
|
|
56
|
+
if (attr.startsWith('#')) {
|
|
57
|
+
$link.id = attr.slice(1);
|
|
58
|
+
}
|
|
56
59
|
switch (attr) {
|
|
60
|
+
case 'prevent-default':
|
|
61
|
+
$link.preventDefault = true;
|
|
62
|
+
break;
|
|
57
63
|
case 'use-history':
|
|
58
64
|
$link['use-history'] = true;
|
|
59
65
|
break;
|