@nectary/components 2.6.1 → 2.8.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/button/index.js +23 -9
- package/button/types.d.ts +14 -6
- package/button/utils.js +1 -1
- package/emoji/index.js +3 -3
- package/emoji/utils.d.ts +3 -1
- package/emoji/utils.js +17 -12
- package/emoji-picker/data.json +1 -1
- package/emoji-picker/index.js +7 -3
- package/icon-button/index.js +4 -2
- package/input/index.js +3 -2
- package/link/index.js +20 -2
- package/link/types.d.ts +4 -0
- package/package.json +2 -3
- package/pop/index.js +1 -1
- package/popover/index.js +7 -1
- package/radio-option/types.d.ts +1 -0
- package/readme.md +0 -6
- package/rich-text/index.d.ts +3 -0
- package/rich-text/index.js +35 -8
- package/rich-text/utils.d.ts +5 -0
- package/rich-text/utils.js +107 -1
- package/rich-textarea/index.d.ts +11 -0
- package/rich-textarea/index.js +464 -0
- package/rich-textarea/types.d.ts +48 -0
- package/rich-textarea/types.js +1 -0
- package/rich-textarea/utils.d.ts +39 -0
- package/rich-textarea/utils.js +1730 -0
- package/select-button/index.js +5 -3
- package/textarea/index.js +3 -3
- package/tile-control/index.js +1 -1
- package/tile-control/types.d.ts +7 -5
- package/tooltip/index.js +7 -1
- package/utils/markdown.d.ts +19 -1
- package/utils/markdown.js +128 -113
package/select-button/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../text';
|
|
2
2
|
import '../icon';
|
|
3
|
-
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, subscribeContext, updateAttribute, updateBooleanAttribute,
|
|
3
|
+
import { defineCustomElement, getAttribute, getBooleanAttribute, getLiteralAttribute, getReactEventHandler, isAttrTrue, NectaryElement, setClass, subscribeContext, updateAttribute, updateBooleanAttribute, updateLiteralAttribute, Context, isAttrEqual } from '../utils';
|
|
4
4
|
import { DEFAULT_SIZE, sizeValues } from '../utils/size';
|
|
5
5
|
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0;cursor:pointer}:host([disabled]){cursor:initial}#wrapper{position:relative;display:flex;flex-direction:row;align-items:center;gap:8px;box-sizing:border-box;width:100%;height:var(--sinch-local-size);padding:0 8px 0 12px;background-color:var(--sinch-comp-select-button-color-default-background-initial);border-radius:var(--sinch-local-shape-radius);--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m);--sinch-global-color-icon:var(--sinch-comp-select-button-color-default-icon-initial)}:host([data-size="l"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-l);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-l);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-l)}:host([data-size="m"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-m);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-m);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-m)}:host([data-size="s"])>#wrapper{--sinch-local-size:var(--sinch-comp-select-button-size-container-s);--sinch-global-size-icon:var(--sinch-comp-select-button-size-icon-s);--sinch-local-shape-radius:var(--sinch-comp-select-button-shape-radius-size-s)}:host([data-size="l"]) #wrapper{padding:0 12px}:host([data-size="m"]) #wrapper{padding:0 8px 0 12px}:host([data-size="s"]) #wrapper{padding:0 4px 0 12px}:host([disabled]) #wrapper{--sinch-global-color-icon:var(--sinch-comp-select-button-color-disabled-icon-initial)}#text{flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-input);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-text-initial)}#text:empty{display:none}#placeholder{display:none;flex:1;min-width:0;--sinch-comp-text-font:var(--sinch-comp-select-button-font-placeholder);--sinch-global-color-text:var(--sinch-comp-select-button-color-default-placeholder-initial)}#text:empty+#placeholder{display:block}#border{position:absolute;border:1px solid var(--sinch-comp-select-button-color-default-border-initial);border-radius:var(--sinch-local-shape-radius);inset:0;pointer-events:none}:host(:focus-visible) #border{border-color:var(--sinch-comp-select-button-color-default-border-focus);border-width:2px}:host([invalid]) #border{border-color:var(--sinch-comp-select-button-color-invalid-border-initial)}:host([disabled]) #border{border-color:var(--sinch-comp-select-button-color-disabled-border-initial)}:host([disabled]) #text{--sinch-global-color-text:var(--sinch-comp-select-button-color-disabled-text-initial)}:host([disabled]) #placeholder{--sinch-global-color-text:var(--sinch-comp-select-button-color-disabled-placeholder-initial)}#left{display:flex;flex-direction:row;align-self:stretch;align-items:center;gap:4px;margin-left:-4px}#left.empty{display:none}#dropdown-icon{margin-left:-4px}</style><div id="wrapper" inert><div id="border"></div><div id="left"><slot name="left"></slot></div><slot name="icon"></slot><sinch-text id="text" type="m" ellipsis></sinch-text><sinch-text id="placeholder" type="m" ellipsis></sinch-text><sinch-icon id="dropdown-icon" name="keyboard_arrow_down"></sinch-icon></div>';
|
|
6
6
|
const template = document.createElement('template');
|
|
@@ -87,13 +87,15 @@ defineCustomElement('sinch-select-button', class extends NectaryElement {
|
|
|
87
87
|
case 'invalid':
|
|
88
88
|
{
|
|
89
89
|
const isInvalid = isAttrTrue(newVal);
|
|
90
|
-
|
|
90
|
+
this.ariaInvalid = isInvalid.toString();
|
|
91
91
|
updateBooleanAttribute(this, 'invalid', isInvalid);
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
94
|
case 'disabled':
|
|
95
95
|
{
|
|
96
|
-
|
|
96
|
+
const isDisabled = isAttrTrue(newVal);
|
|
97
|
+
this.ariaDisabled = isDisabled.toString();
|
|
98
|
+
updateBooleanAttribute(this, 'disabled', isDisabled);
|
|
97
99
|
break;
|
|
98
100
|
}
|
|
99
101
|
case 'size':
|
package/textarea/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Context, defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, getRect, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute
|
|
1
|
+
import { Context, defineCustomElement, getAttribute, getBooleanAttribute, getIntegerAttribute, getReactEventHandler, getRect, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
2
2
|
import { DEFAULT_SIZE } from '../utils/size';
|
|
3
|
-
const templateHTML = '<style>:host{
|
|
3
|
+
const templateHTML = '<style>:host{display:block}#wrapper{display:flex;flex-direction:column;position:relative;width:100%;box-sizing:border-box;background-color:var(--sinch-comp-textarea-color-default-background-initial);border-radius:var(--sinch-local-shape-radius);padding-right:2px;overflow:hidden;--sinch-local-shape-radius:var(--sinch-comp-textarea-shape-radius)}#input{all:initial;display:block;font:var(--sinch-comp-textarea-font-input);color:var(--sinch-comp-textarea-color-default-text-initial);resize:none;white-space:pre-wrap;overflow-wrap:break-word;padding:8px 10px 8px 12px;border:none;box-sizing:border-box}#input::placeholder{color:var(--sinch-comp-textarea-color-default-text-placeholder);opacity:1}#input:disabled{color:var(--sinch-comp-textarea-color-disabled-text-initial);-webkit-text-fill-color:var(--sinch-comp-textarea-color-disabled-text-initial)}#border{position:absolute;border:1px solid var(--sinch-comp-textarea-color-default-border-initial);border-radius:var(--sinch-local-shape-radius);inset:0;pointer-events:none}:host([invalid]) #border{border-color:var(--sinch-comp-textarea-color-invalid-border-initial)}#input:focus+#border{border-color:var(--sinch-comp-textarea-color-default-border-focus);border-width:2px}#input:disabled+#border{border-color:var(--sinch-comp-textarea-color-disabled-border-initial)}#bottom{display:flex;flex-direction:row;align-items:center;gap:8px;padding:12px 4px 4px}#bottom.empty{display:none}#resize-handle{display:none;position:absolute;width:20px;height:20px;bottom:36px;right:0;cursor:ns-resize}:host([resizable]) #resize-handle{display:block}#bottom.empty+#resize-handle{bottom:0}#resize-icon{display:block;pointer-events:none;fill:var(--sinch-comp-textarea-color-default-border-initial)}</style><div id="wrapper"><textarea id="input"></textarea><div id="border"></div><div id="bottom"><slot name="bottom"></slot></div><div id="resize-handle"><svg id="resize-icon" width="16" height="16"><path d="m14.833 4.724-9.61 9.61-.942-.944 9.61-9.609.942.943ZM15.443 10 10.5 14.943 9.557 14 14.5 9.057l.943.943Z"/></svg></div></div>';
|
|
4
4
|
const template = document.createElement('template');
|
|
5
5
|
template.innerHTML = templateHTML;
|
|
6
6
|
defineCustomElement('sinch-textarea', class extends NectaryElement {
|
|
@@ -102,7 +102,7 @@ defineCustomElement('sinch-textarea', class extends NectaryElement {
|
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
104
104
|
const isInvalid = isAttrTrue(newVal);
|
|
105
|
-
|
|
105
|
+
this.ariaInvalid = isInvalid.toString();
|
|
106
106
|
updateBooleanAttribute(this, 'invalid', isInvalid);
|
|
107
107
|
break;
|
|
108
108
|
}
|
package/tile-control/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineCustomElement, getAttribute, getBooleanAttribute, unpackCsv, getFirstCsvValue, getIntegerAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateCsv, updateIntegerAttribute, isAttrTrue, isAttrEqual } from '../utils';
|
|
2
|
-
const templateHTML = '<style>:host{display:block;outline:0;--sinch-grid-num-columns:1}#wrapper{display:grid;grid-template-columns:repeat(var(--sinch-grid-num-columns),auto);gap:16px;width:fit-content}:host([small]) #wrapper{gap:8px}:host([cols="2"]){--sinch-grid-num-columns:2}:host([cols="3"]){--sinch-grid-num-columns:3}:host([cols="4"]){--sinch-grid-num-columns:4}:host([cols="5"]){--sinch-grid-num-columns:5}:host([cols="6"]){--sinch-grid-num-columns:6}:host([cols="7"]){--sinch-grid-num-columns:7}:host([cols="8"]){--sinch-grid-num-columns:8}</style><div id="wrapper"><slot></slot></div>';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0;--sinch-grid-num-columns:1}#wrapper{display:grid;grid-template-columns:repeat(var(--sinch-grid-num-columns),auto);gap:16px;width:fit-content}:host([small]) #wrapper{gap:8px}:host([cols="2"]){--sinch-grid-num-columns:2}:host([cols="3"]){--sinch-grid-num-columns:3}:host([cols="4"]){--sinch-grid-num-columns:4}:host([cols="5"]){--sinch-grid-num-columns:5}:host([cols="6"]){--sinch-grid-num-columns:6}:host([cols="7"]){--sinch-grid-num-columns:7}:host([cols="8"]){--sinch-grid-num-columns:8}:host([cols="9"]){--sinch-grid-num-columns:9}:host([cols="10"]){--sinch-grid-num-columns:10}</style><div id="wrapper"><slot></slot></div>';
|
|
3
3
|
const template = document.createElement('template');
|
|
4
4
|
template.innerHTML = templateHTML;
|
|
5
5
|
defineCustomElement('sinch-tile-control', class extends NectaryElement {
|
package/tile-control/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { TSinchElementReact } from '../types';
|
|
2
|
+
/** Number of coumns from 1 to 10 */
|
|
3
|
+
export type TSinchTileControlColumns = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | number;
|
|
2
4
|
export type TSinchTileControlElement = HTMLElement & {
|
|
3
5
|
/** Value */
|
|
4
6
|
value: string;
|
|
@@ -6,8 +8,8 @@ export type TSinchTileControlElement = HTMLElement & {
|
|
|
6
8
|
small: boolean;
|
|
7
9
|
/** Multiple */
|
|
8
10
|
multiple: boolean;
|
|
9
|
-
/** Number of columns from 1 to
|
|
10
|
-
cols:
|
|
11
|
+
/** Number of columns from 1 to 10 */
|
|
12
|
+
cols: TSinchTileControlColumns;
|
|
11
13
|
/** Change value event */
|
|
12
14
|
addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
|
|
13
15
|
/** Value */
|
|
@@ -16,7 +18,7 @@ export type TSinchTileControlElement = HTMLElement & {
|
|
|
16
18
|
setAttribute(name: 'small', value: ''): void;
|
|
17
19
|
/** Multiple */
|
|
18
20
|
setAttribute(name: 'multiple', value: ''): void;
|
|
19
|
-
/** Number of columns from 1 to
|
|
21
|
+
/** Number of columns from 1 to 10 */
|
|
20
22
|
setAttribute(name: 'cols', value: string): void;
|
|
21
23
|
};
|
|
22
24
|
export type TSinchTileControlReact = TSinchElementReact<TSinchTileControlElement> & {
|
|
@@ -26,8 +28,8 @@ export type TSinchTileControlReact = TSinchElementReact<TSinchTileControlElement
|
|
|
26
28
|
multiple?: boolean;
|
|
27
29
|
/** Small */
|
|
28
30
|
small?: boolean;
|
|
29
|
-
/** Number of columns from 1 to
|
|
30
|
-
cols:
|
|
31
|
+
/** Number of columns from 1 to 10 */
|
|
32
|
+
cols: TSinchTileControlColumns;
|
|
31
33
|
/** Label that is used for a11y */
|
|
32
34
|
'aria-label': string;
|
|
33
35
|
/** Change value handler */
|
package/tooltip/index.js
CHANGED
|
@@ -63,7 +63,7 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
|
63
63
|
this.#controller = null;
|
|
64
64
|
}
|
|
65
65
|
static get observedAttributes() {
|
|
66
|
-
return ['text', 'orientation', 'type'];
|
|
66
|
+
return ['text', 'orientation', 'type', 'aria-label', 'aria-description'];
|
|
67
67
|
}
|
|
68
68
|
attributeChangedCallback(name, _, newVal) {
|
|
69
69
|
switch (name) {
|
|
@@ -88,6 +88,12 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
|
88
88
|
});
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
|
+
case 'aria-label':
|
|
92
|
+
case 'aria-description':
|
|
93
|
+
{
|
|
94
|
+
updateAttribute(this.#$pop, name, newVal);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
get text() {
|
package/utils/markdown.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TMarkdownInlineParams = {
|
|
2
|
+
isBold?: boolean;
|
|
3
|
+
isItalic?: boolean;
|
|
4
|
+
isStrikethrough?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type TMarkdownParseVisitor = {
|
|
7
|
+
link(text: string, href: string, attributes?: string[]): void;
|
|
8
|
+
emoji(emojiChar: string): void;
|
|
9
|
+
codetag(text: string): void;
|
|
10
|
+
inline(text: string, params: TMarkdownInlineParams): void;
|
|
11
|
+
linebreak(): void;
|
|
12
|
+
paragraph(): void;
|
|
13
|
+
list(isOrdered: boolean): void;
|
|
14
|
+
endList(): void;
|
|
15
|
+
listItem(): void;
|
|
16
|
+
end(): Node;
|
|
17
|
+
};
|
|
18
|
+
export declare const isEmojiString: (data: string) => boolean;
|
|
19
|
+
export declare const parseMarkdown: (md: string, visitor: TMarkdownParseVisitor) => Node;
|
package/utils/markdown.js
CHANGED
|
@@ -1,128 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case '~~':
|
|
21
|
-
return contextTags.s;
|
|
22
|
-
case 'p':
|
|
23
|
-
return contextTags.p;
|
|
24
|
-
default:
|
|
25
|
-
return null;
|
|
1
|
+
const regLinebreak = /(?:<br>\n|<br>|\n)/;
|
|
2
|
+
const regParagraph = /\n{2,}/;
|
|
3
|
+
const regEm3Star = /\*\*\*(?<em3>.+?)\*\*\*/;
|
|
4
|
+
const regEm2Star = /\*\*(?<em2>.+?)\*\*/;
|
|
5
|
+
const regEm1Star = /\*(?<em1>.+?)\*/;
|
|
6
|
+
const regEm3Underscore = /___(?<em3>.+?)___/;
|
|
7
|
+
const regEm2Underscore = /__(?<em2>.+?)__/;
|
|
8
|
+
const regEm1Underscore = /_(?<em1>.+?)_/;
|
|
9
|
+
const regCodeTag = /`(?<code>.+?)`/;
|
|
10
|
+
const regStrikethrough = /~~(?<strike>.+?)~~/;
|
|
11
|
+
const regLink = /!?\[(?<linktext>[^\]]*?)\]\((?<linkhref>[^)]+?)\)(\{(?<linkattrs>[^)]+?)\})?/;
|
|
12
|
+
const regEmoji = /(?<emoji>(?![0-9*#])\p{Emoji})/u;
|
|
13
|
+
const regUList = /^(?<indent>[\t ]*?)[*+-][\t ]+(?<ultext>.*?)[\t ]*?$/;
|
|
14
|
+
const regOList = /^(?<indent>[\t ]*?)\d+\.[\t ]+(?<oltext>.*?)[\t ]*?$/;
|
|
15
|
+
const allRegs = [regCodeTag, regLink, regEm3Star, regEm2Star, regEm1Star, regEm3Underscore, regEm2Underscore, regEm1Underscore, regStrikethrough, regEmoji];
|
|
16
|
+
export const isEmojiString = data => regEmoji.test(data);
|
|
17
|
+
const excludeRegs = function (regs) {
|
|
18
|
+
for (var _len = arguments.length, excluding = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
19
|
+
excluding[_key - 1] = arguments[_key];
|
|
26
20
|
}
|
|
21
|
+
return regs.filter(r => !excluding.includes(r));
|
|
27
22
|
};
|
|
28
|
-
const
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export const parseMarkdown = md => {
|
|
33
|
-
const context = [];
|
|
34
|
-
let out = '';
|
|
35
|
-
let lastIndex = 0;
|
|
36
|
-
const isContextEnd = token => {
|
|
37
|
-
return context.length > 0 && context.at(-1).token === token;
|
|
38
|
-
};
|
|
39
|
-
const pushContext = token => {
|
|
40
|
-
const desc = getContextTags(token);
|
|
41
|
-
if (desc === null) {
|
|
42
|
-
return;
|
|
23
|
+
const matchClosest = (regs, line) => {
|
|
24
|
+
return regs.map(reg => reg.exec(line)).reduce((res, match) => {
|
|
25
|
+
if (match === null) {
|
|
26
|
+
return res;
|
|
43
27
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
out: ''
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const popContext = (token, prev) => {
|
|
50
|
-
const desc = getContextTags(token);
|
|
51
|
-
if (desc === null) {
|
|
52
|
-
return token;
|
|
28
|
+
if (res === null || res.index > match.index) {
|
|
29
|
+
return match;
|
|
53
30
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (tokens === null) {
|
|
72
|
-
break;
|
|
31
|
+
return res;
|
|
32
|
+
}, null);
|
|
33
|
+
};
|
|
34
|
+
const INITIAL_CONTEXT = {
|
|
35
|
+
isBold: false,
|
|
36
|
+
isItalic: false,
|
|
37
|
+
isStrikethrough: false
|
|
38
|
+
};
|
|
39
|
+
const createLineParser = visitor => function parseLine(regs, md) {
|
|
40
|
+
let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INITIAL_CONTEXT;
|
|
41
|
+
let line = md;
|
|
42
|
+
let match = null;
|
|
43
|
+
while ((match = matchClosest(regs, line)) !== null) {
|
|
44
|
+
const groups = match.groups;
|
|
45
|
+
const matchedStr = match[0];
|
|
46
|
+
if (match.index > 0) {
|
|
47
|
+
visitor.inline(line.substring(0, match.index), context);
|
|
73
48
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
lastIndex = tokenizer.lastIndex;
|
|
78
|
-
if (context.length === 0) {
|
|
79
|
-
pushContext('p');
|
|
49
|
+
line = line.substring(match.index + matchedStr.length);
|
|
50
|
+
if (groups?.linkhref != null) {
|
|
51
|
+
visitor.link(groups.linktext, groups.linkhref, groups.linkattrs?.split(' '));
|
|
80
52
|
}
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
context.at(-1).out += prev + chunk;
|
|
84
|
-
continue;
|
|
53
|
+
if (groups?.code != null) {
|
|
54
|
+
visitor.codetag(groups.code);
|
|
85
55
|
}
|
|
86
|
-
if (groups
|
|
87
|
-
|
|
88
|
-
if (isCloseTag) {
|
|
89
|
-
chunk = popContext(groups.em, prev);
|
|
90
|
-
context.at(-1).out += chunk;
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
context.at(-1).out += prev;
|
|
94
|
-
pushContext(groups.em);
|
|
95
|
-
continue;
|
|
56
|
+
if (groups?.emoji != null) {
|
|
57
|
+
visitor.emoji(groups.emoji);
|
|
96
58
|
}
|
|
97
|
-
if (groups
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
continue;
|
|
59
|
+
if (groups?.em1 != null) {
|
|
60
|
+
parseLine(excludeRegs(regs, regEm1Star, regEm1Underscore), groups.em1, {
|
|
61
|
+
...context,
|
|
62
|
+
isItalic: true
|
|
63
|
+
});
|
|
103
64
|
}
|
|
104
|
-
if (groups
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
65
|
+
if (groups?.em2 != null) {
|
|
66
|
+
parseLine(excludeRegs(regs, regEm2Star, regEm2Underscore), groups.em2, {
|
|
67
|
+
...context,
|
|
68
|
+
isBold: true
|
|
69
|
+
});
|
|
108
70
|
}
|
|
109
|
-
if (groups
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
71
|
+
if (groups?.em3 != null) {
|
|
72
|
+
parseLine(excludeRegs(regs, regEm3Star, regEm3Underscore, regEm2Star, regEm2Underscore, regEm1Star, regEm1Underscore), groups.em3, {
|
|
73
|
+
...context,
|
|
74
|
+
isBold: true,
|
|
75
|
+
isItalic: true
|
|
76
|
+
});
|
|
113
77
|
}
|
|
114
|
-
if (groups
|
|
115
|
-
|
|
116
|
-
|
|
78
|
+
if (groups?.strike != null) {
|
|
79
|
+
parseLine(excludeRegs(regs, regStrikethrough), groups.strike, {
|
|
80
|
+
...context,
|
|
81
|
+
isStrikethrough: true
|
|
82
|
+
});
|
|
117
83
|
}
|
|
118
84
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
85
|
+
if (line.length > 0) {
|
|
86
|
+
visitor.inline(line, context);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const createBlockParser = visitor => {
|
|
90
|
+
const parseLine = createLineParser(visitor);
|
|
91
|
+
const listRegs = [regUList, regOList];
|
|
92
|
+
const getListItemText = match => {
|
|
93
|
+
return match.groups.ultext ?? match.groups.oltext;
|
|
94
|
+
};
|
|
95
|
+
const BLOCK_MODE_PARAGRAPH = 1;
|
|
96
|
+
const BLOCK_MODE_ULIST = 2;
|
|
97
|
+
const BLOCK_MODE_OLIST = 2;
|
|
98
|
+
return function parseBlock(lines) {
|
|
99
|
+
let mode = 0;
|
|
100
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
101
|
+
const listMatch = matchClosest(listRegs, lines[i]);
|
|
102
|
+
const isListLine = listMatch !== null;
|
|
103
|
+
if (isListLine) {
|
|
104
|
+
const groups = listMatch.groups;
|
|
105
|
+
const isOrderedList = groups.oltext != null;
|
|
106
|
+
mode = isOrderedList ? BLOCK_MODE_OLIST : BLOCK_MODE_ULIST;
|
|
107
|
+
visitor.list(isOrderedList);
|
|
108
|
+
const listItemInitialIndent = groups.indent;
|
|
109
|
+
let listItemLines = [getListItemText(listMatch)];
|
|
110
|
+
visitor.listItem();
|
|
111
|
+
for (++i; i < lines.length; ++i) {
|
|
112
|
+
const listItemMatch = isOrderedList ? regOList.exec(lines[i]) : regUList.exec(lines[i]);
|
|
113
|
+
if (listItemMatch !== null && listItemMatch.groups.indent === listItemInitialIndent) {
|
|
114
|
+
parseBlock(listItemLines);
|
|
115
|
+
listItemLines = [getListItemText(listItemMatch)];
|
|
116
|
+
visitor.listItem();
|
|
117
|
+
} else {
|
|
118
|
+
listItemLines.push(lines[i]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
parseBlock(listItemLines);
|
|
122
|
+
visitor.endList();
|
|
123
|
+
mode = 0;
|
|
124
|
+
} else {
|
|
125
|
+
if (mode === BLOCK_MODE_PARAGRAPH) {
|
|
126
|
+
visitor.linebreak();
|
|
127
|
+
}
|
|
128
|
+
if (mode !== BLOCK_MODE_PARAGRAPH) {
|
|
129
|
+
mode = BLOCK_MODE_PARAGRAPH;
|
|
130
|
+
visitor.paragraph();
|
|
131
|
+
}
|
|
132
|
+
parseLine(allRegs, lines[i]);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
|
-
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export const parseMarkdown = (md, visitor) => {
|
|
138
|
+
const parseBlock = createBlockParser(visitor);
|
|
139
|
+
for (const block of md.trim().split(regParagraph)) {
|
|
140
|
+
parseBlock(block.trim().split(regLinebreak));
|
|
141
|
+
}
|
|
142
|
+
return visitor.end();
|
|
128
143
|
};
|