@nectary/components 5.46.0 → 5.47.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/bundle.js +47 -2
- package/package.json +1 -1
- package/rich-text/index.d.ts +4 -0
- package/rich-text/index.js +48 -3
- package/rich-text/types.d.ts +12 -0
package/bundle.js
CHANGED
|
@@ -1952,6 +1952,11 @@ class RichText extends NectaryElement {
|
|
|
1952
1952
|
#parseVisitor;
|
|
1953
1953
|
#controller = null;
|
|
1954
1954
|
#chipResolver = null;
|
|
1955
|
+
/* @internal
|
|
1956
|
+
* Regex used to recognise a chip when parsing markdown (capture group 1 is
|
|
1957
|
+
* the chip name). When null the default `{{name}}` form is used.
|
|
1958
|
+
*/
|
|
1959
|
+
#chipPattern = null;
|
|
1955
1960
|
constructor() {
|
|
1956
1961
|
super();
|
|
1957
1962
|
const shadowRoot = this.attachShadow();
|
|
@@ -1991,7 +1996,7 @@ class RichText extends NectaryElement {
|
|
|
1991
1996
|
super.disconnectedCallback();
|
|
1992
1997
|
}
|
|
1993
1998
|
static get observedAttributes() {
|
|
1994
|
-
return ["text", "chip-color", "chip-icon"];
|
|
1999
|
+
return ["text", "chip-color", "chip-icon", "chip-delimiter"];
|
|
1995
2000
|
}
|
|
1996
2001
|
attributeChangedCallback(name, _oldVal, _newVal) {
|
|
1997
2002
|
switch (name) {
|
|
@@ -2009,6 +2014,10 @@ class RichText extends NectaryElement {
|
|
|
2009
2014
|
this.#updateText();
|
|
2010
2015
|
break;
|
|
2011
2016
|
}
|
|
2017
|
+
case "chip-delimiter": {
|
|
2018
|
+
this.#updateText();
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2012
2021
|
}
|
|
2013
2022
|
}
|
|
2014
2023
|
get size() {
|
|
@@ -2035,6 +2044,12 @@ class RichText extends NectaryElement {
|
|
|
2035
2044
|
set chipIcon(value) {
|
|
2036
2045
|
updateAttribute(this, "chip-icon", value);
|
|
2037
2046
|
}
|
|
2047
|
+
set chipDelimiter(value) {
|
|
2048
|
+
updateAttribute(this, "chip-delimiter", value);
|
|
2049
|
+
}
|
|
2050
|
+
get chipDelimiter() {
|
|
2051
|
+
return getAttribute(this, "chip-delimiter");
|
|
2052
|
+
}
|
|
2038
2053
|
get chipResolver() {
|
|
2039
2054
|
return this.#chipResolver;
|
|
2040
2055
|
}
|
|
@@ -2043,6 +2058,31 @@ class RichText extends NectaryElement {
|
|
|
2043
2058
|
this.#parseVisitor.updateChipResolver(value);
|
|
2044
2059
|
this.#updateText();
|
|
2045
2060
|
}
|
|
2061
|
+
set chipPattern(pattern) {
|
|
2062
|
+
this.#chipPattern = pattern;
|
|
2063
|
+
this.#updateText();
|
|
2064
|
+
}
|
|
2065
|
+
get chipPattern() {
|
|
2066
|
+
return this.#chipPattern;
|
|
2067
|
+
}
|
|
2068
|
+
#getChipPattern() {
|
|
2069
|
+
if (this.#chipPattern !== null) {
|
|
2070
|
+
return this.#chipPattern;
|
|
2071
|
+
}
|
|
2072
|
+
const delimiter = this.chipDelimiter;
|
|
2073
|
+
if (delimiter !== null && delimiter !== "") {
|
|
2074
|
+
const escaped = delimiter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2075
|
+
return new RegExp(`(?<!\\\\)${escaped}([a-zA-Z0-9_-]+)${escaped}`);
|
|
2076
|
+
}
|
|
2077
|
+
return null;
|
|
2078
|
+
}
|
|
2079
|
+
#getEscapePattern() {
|
|
2080
|
+
const delimiter = this.chipDelimiter;
|
|
2081
|
+
if (delimiter !== null && delimiter !== "") {
|
|
2082
|
+
return buildEscapedCharsReg(delimiter);
|
|
2083
|
+
}
|
|
2084
|
+
return void 0;
|
|
2085
|
+
}
|
|
2046
2086
|
#handleElementClick = (e) => {
|
|
2047
2087
|
const eventTarget = e.target;
|
|
2048
2088
|
const elementClickEvent = new CustomEvent("-element-click");
|
|
@@ -2059,7 +2099,12 @@ class RichText extends NectaryElement {
|
|
|
2059
2099
|
this.#wrapper.innerHTML = "";
|
|
2060
2100
|
} else {
|
|
2061
2101
|
this.#wrapper.replaceChildren(
|
|
2062
|
-
parseMarkdown(
|
|
2102
|
+
parseMarkdown(
|
|
2103
|
+
text,
|
|
2104
|
+
this.#parseVisitor.createVisitor(),
|
|
2105
|
+
this.#getChipPattern() ?? void 0,
|
|
2106
|
+
this.#getEscapePattern()
|
|
2107
|
+
)
|
|
2063
2108
|
);
|
|
2064
2109
|
}
|
|
2065
2110
|
}
|
package/package.json
CHANGED
package/rich-text/index.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export declare class RichText extends NectaryElement {
|
|
|
21
21
|
set chipColor(value: string | null);
|
|
22
22
|
get chipIcon(): string | null;
|
|
23
23
|
set chipIcon(value: string | null);
|
|
24
|
+
set chipDelimiter(value: string | null);
|
|
25
|
+
get chipDelimiter(): string | null;
|
|
24
26
|
get chipResolver(): TChipResolver | null;
|
|
25
27
|
set chipResolver(value: TChipResolver | null);
|
|
28
|
+
set chipPattern(pattern: RegExp | null);
|
|
29
|
+
get chipPattern(): RegExp | null;
|
|
26
30
|
}
|
package/rich-text/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import "../rich-textarea-chip/index.js";
|
|
|
6
6
|
import { getLiteralAttribute, updateLiteralAttribute, getAttribute, updateAttribute } from "../utils/dom.js";
|
|
7
7
|
import { defineCustomElement, NectaryElement } from "../utils/element.js";
|
|
8
8
|
import { getReactEventHandler } from "../utils/get-react-event-handler.js";
|
|
9
|
-
import { parseMarkdown } from "../utils/markdown.js";
|
|
9
|
+
import { buildEscapedCharsReg, parseMarkdown } from "../utils/markdown.js";
|
|
10
10
|
import { createParseVisitor, sizeValues } from "./utils.js";
|
|
11
11
|
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>';
|
|
12
12
|
const template = document.createElement("template");
|
|
@@ -16,6 +16,11 @@ class RichText extends NectaryElement {
|
|
|
16
16
|
#parseVisitor;
|
|
17
17
|
#controller = null;
|
|
18
18
|
#chipResolver = null;
|
|
19
|
+
/* @internal
|
|
20
|
+
* Regex used to recognise a chip when parsing markdown (capture group 1 is
|
|
21
|
+
* the chip name). When null the default `{{name}}` form is used.
|
|
22
|
+
*/
|
|
23
|
+
#chipPattern = null;
|
|
19
24
|
constructor() {
|
|
20
25
|
super();
|
|
21
26
|
const shadowRoot = this.attachShadow();
|
|
@@ -55,7 +60,7 @@ class RichText extends NectaryElement {
|
|
|
55
60
|
super.disconnectedCallback();
|
|
56
61
|
}
|
|
57
62
|
static get observedAttributes() {
|
|
58
|
-
return ["text", "chip-color", "chip-icon"];
|
|
63
|
+
return ["text", "chip-color", "chip-icon", "chip-delimiter"];
|
|
59
64
|
}
|
|
60
65
|
attributeChangedCallback(name, _oldVal, _newVal) {
|
|
61
66
|
switch (name) {
|
|
@@ -73,6 +78,10 @@ class RichText extends NectaryElement {
|
|
|
73
78
|
this.#updateText();
|
|
74
79
|
break;
|
|
75
80
|
}
|
|
81
|
+
case "chip-delimiter": {
|
|
82
|
+
this.#updateText();
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
get size() {
|
|
@@ -99,6 +108,12 @@ class RichText extends NectaryElement {
|
|
|
99
108
|
set chipIcon(value) {
|
|
100
109
|
updateAttribute(this, "chip-icon", value);
|
|
101
110
|
}
|
|
111
|
+
set chipDelimiter(value) {
|
|
112
|
+
updateAttribute(this, "chip-delimiter", value);
|
|
113
|
+
}
|
|
114
|
+
get chipDelimiter() {
|
|
115
|
+
return getAttribute(this, "chip-delimiter");
|
|
116
|
+
}
|
|
102
117
|
get chipResolver() {
|
|
103
118
|
return this.#chipResolver;
|
|
104
119
|
}
|
|
@@ -107,6 +122,31 @@ class RichText extends NectaryElement {
|
|
|
107
122
|
this.#parseVisitor.updateChipResolver(value);
|
|
108
123
|
this.#updateText();
|
|
109
124
|
}
|
|
125
|
+
set chipPattern(pattern) {
|
|
126
|
+
this.#chipPattern = pattern;
|
|
127
|
+
this.#updateText();
|
|
128
|
+
}
|
|
129
|
+
get chipPattern() {
|
|
130
|
+
return this.#chipPattern;
|
|
131
|
+
}
|
|
132
|
+
#getChipPattern() {
|
|
133
|
+
if (this.#chipPattern !== null) {
|
|
134
|
+
return this.#chipPattern;
|
|
135
|
+
}
|
|
136
|
+
const delimiter = this.chipDelimiter;
|
|
137
|
+
if (delimiter !== null && delimiter !== "") {
|
|
138
|
+
const escaped = delimiter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
139
|
+
return new RegExp(`(?<!\\\\)${escaped}([a-zA-Z0-9_-]+)${escaped}`);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
#getEscapePattern() {
|
|
144
|
+
const delimiter = this.chipDelimiter;
|
|
145
|
+
if (delimiter !== null && delimiter !== "") {
|
|
146
|
+
return buildEscapedCharsReg(delimiter);
|
|
147
|
+
}
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
110
150
|
#handleElementClick = (e) => {
|
|
111
151
|
const eventTarget = e.target;
|
|
112
152
|
const elementClickEvent = new CustomEvent("-element-click");
|
|
@@ -123,7 +163,12 @@ class RichText extends NectaryElement {
|
|
|
123
163
|
this.#wrapper.innerHTML = "";
|
|
124
164
|
} else {
|
|
125
165
|
this.#wrapper.replaceChildren(
|
|
126
|
-
parseMarkdown(
|
|
166
|
+
parseMarkdown(
|
|
167
|
+
text,
|
|
168
|
+
this.#parseVisitor.createVisitor(),
|
|
169
|
+
this.#getChipPattern() ?? void 0,
|
|
170
|
+
this.#getEscapePattern()
|
|
171
|
+
)
|
|
127
172
|
);
|
|
128
173
|
}
|
|
129
174
|
}
|
package/rich-text/types.d.ts
CHANGED
|
@@ -12,10 +12,22 @@ export type TSinchRichTextProps = {
|
|
|
12
12
|
'chip-color'?: TSinchTagColor;
|
|
13
13
|
/** Default icon for chips */
|
|
14
14
|
'chip-icon'?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Symmetric wrapping delimiter for chips in markdown, e.g. "#" produces
|
|
17
|
+
* `#name#`. A shorthand that derives chipPattern; the explicit chipPattern
|
|
18
|
+
* property overrides it.
|
|
19
|
+
*/
|
|
20
|
+
'chip-delimiter'?: string;
|
|
15
21
|
};
|
|
16
22
|
export type TSinchRichTextMethods = {
|
|
17
23
|
/** Resolver callback for chip icon and color based on tag name */
|
|
18
24
|
chipResolver: TChipResolver | null;
|
|
25
|
+
/**
|
|
26
|
+
* Regex used to recognise a chip when parsing markdown. Capture group 1 is
|
|
27
|
+
* the chip name. When null the default `{{name}}` form is used. Overrides
|
|
28
|
+
* the `chip-delimiter` attribute.
|
|
29
|
+
*/
|
|
30
|
+
chipPattern: RegExp | null;
|
|
19
31
|
};
|
|
20
32
|
export type TSinchRichTextEvents = {
|
|
21
33
|
/** Click event handler */
|