@athenaintel/react 0.14.0 → 0.15.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/dist/chat/ComposerEditorContext.d.ts +6 -0
- package/dist/chat/super-grouping/toolkit-map.d.ts +8 -3
- package/dist/chat-ui/composer/composer-action.d.ts +8 -1
- package/dist/chat-ui/composer/tiptap-composer.d.ts +7 -0
- package/dist/chat-ui/header/chat-header.d.ts +19 -0
- package/dist/chat-ui/header/conversation-history-panel.d.ts +27 -0
- package/dist/chat-ui/index.d.ts +6 -2
- package/dist/chat-ui/messages/message-actions-config.d.ts +12 -0
- package/dist/chat-ui/messages/message-components.d.ts +8 -6
- package/dist/chat-ui/messages/user-edit-composer.d.ts +8 -0
- package/dist/chat-ui/thread/chat-composer-dock.d.ts +13 -1
- package/dist/chat-ui/thread/chat-thread-shell.d.ts +69 -6
- package/dist/chat-ui/thread/composer-send-or-stop.d.ts +25 -2
- package/dist/chat-ui.cjs +564 -4337
- package/dist/chat-ui.cjs.map +1 -1
- package/dist/chat-ui.js +465 -4237
- package/dist/chat-ui.js.map +1 -1
- package/dist/index.cjs +1290 -4391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +862 -3942
- package/dist/index.js.map +1 -1
- package/dist/provider/AthenaProvider.d.ts +4 -1
- package/dist/runtime/statewire-run-config.d.ts +0 -2
- package/dist/runtime/useAthenaStatewireRuntime.d.ts +3 -1
- package/dist/styles.css +1 -1
- package/dist/threads/api.d.ts +7 -0
- package/dist/threads/conversation-list-fetcher.d.ts +5 -1
- package/dist/threads/use-rest-conversation-history.d.ts +43 -0
- package/dist/threads/use-statewire-conversation-history.d.ts +71 -0
- package/dist/{scope-registry-Bti8l_Xy.cjs → use-rest-conversation-history-CBPqoHoe.cjs} +30414 -22105
- package/dist/use-rest-conversation-history-CBPqoHoe.cjs.map +1 -0
- package/dist/{scope-registry-B9XYV-FT.js → use-rest-conversation-history-DYvfgoBF.js} +14856 -6568
- package/dist/use-rest-conversation-history-DYvfgoBF.js.map +1 -0
- package/package.json +2 -2
- package/dist/scope-registry-B9XYV-FT.js.map +0 -1
- package/dist/scope-registry-Bti8l_Xy.cjs.map +0 -1
package/dist/chat-ui.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import "
|
|
8
|
-
import {
|
|
9
|
-
import { a4 as createLucideIcon, w as deriveAthenaAppUrl, aC as createAthenaSpacesUrl, t as cn, as as ChevronRight, aP as ArrowUp, aG as Check, aO as Copy, aF as RefreshCw, aH as ChevronDown, W as Node, z as mergeAttributes, a0 as Extension, av as Suggestion, at as useFloating, au as FloatingPortal, q as autoUpdate, o as offset, k as flip, s as shift, ar as getFilteredItems, aU as getFetchState, aV as getEntry, aW as updateFetchState, az as addItems, ay as registerSource, aX as bindScopes, aq as useStore, ag as FileText, a6 as Workflow, aj as BookOpen, aM as Sheet, aK as Table, ah as Database, ai as Calendar, aa as Mail, aL as Image, a9 as Monitor, aI as Code, aN as Camera, ab as LayoutGrid, ac as HardDrive, a8 as Package, a5 as Wrench, a7 as Users, aJ as Search, ad as Globe, ae as FolderKanban, af as Folder, aQ as File$1, ax as Store, aY as getSearchScope, aB as createScopeRegistry, aA as createItemCache, an as useEditor, ap as StarterKit, aE as Placeholder, ao as EditorContent } from "./scope-registry-B9XYV-FT.js";
|
|
4
|
+
import { au as createLucideIcon, O as cn, bJ as THREAD_HEADER_ACTIONS_CLASS, bK as THREAD_HEADER_PILL_CLASS, bL as THREAD_HEADER_CLASS, b4 as RefreshCw, bm as Plus, b9 as Search, be as LoaderCircle, bx as conversationDisplayTitle, b7 as Archive, bM as assetTypeToThumb, aA as MessageSquare, ak as Node, a2 as mergeAttributes, aq as Extension, aW as Suggestion, aU as useFloating, aV as FloatingPortal, N as autoUpdate, F as offset, I as flip, G as shift, aS as getFilteredItems, bN as getFetchState, bO as getEntry, bP as updateFetchState, a_ as addItems, aZ as registerSource, bQ as bindScopes, aR as useStore, aH as FileText, aw as Workflow, aK as BookOpen, bc as Sheet, ba as Table, aI as Database, aJ as Calendar, aB as Mail, bb as Image, az as Monitor, b8 as Code, bd as Camera, aC as LayoutGrid, aD as HardDrive, ay as Package, av as Wrench, ax as Users, aE as Globe, aF as FolderKanban, aG as Folder, bl as File$1, aY as Store, bR as getSearchScope, bS as fetchGraphQL, bT as PAGINATED_ASSETS_QUERY, bU as WORKSPACE_MEMBERS_QUERY, bV as SIMPLE_SEARCH_QUERY, bW as assetTypeToIcon, bX as useMentionAuth, b0 as createScopeRegistry, a$ as createItemCache, aO as useEditor, aQ as StarterKit, b3 as Placeholder, aP as EditorContent } from "./use-rest-conversation-history-DYvfgoBF.js";
|
|
5
|
+
import { bY, bZ, b_, b$, c0, bh, bg, c1, bi, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm, cn as cn2, co } from "./use-rest-conversation-history-DYvfgoBF.js";
|
|
6
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
7
|
+
import { useMemo, useEffect, useState, useRef, Fragment, useImperativeHandle, forwardRef, useCallback, useId } from "react";
|
|
8
|
+
import { useAui, unstable_useComposerInput } from "@assistant-ui/react";
|
|
10
9
|
import "@assistant-ui/tap";
|
|
11
10
|
import "statewire";
|
|
12
11
|
import "@assistant-ui/store";
|
|
@@ -26,7 +25,22 @@ function registerChatAssetMentionHandler(threadId, handler) {
|
|
|
26
25
|
* This source code is licensed under the ISC license.
|
|
27
26
|
* See the LICENSE file in the root directory of this source tree.
|
|
28
27
|
*/
|
|
29
|
-
const __iconNode$
|
|
28
|
+
const __iconNode$l = [
|
|
29
|
+
["path", { d: "M12 8V4H8", key: "hb8ula" }],
|
|
30
|
+
["rect", { width: "16", height: "12", x: "4", y: "8", rx: "2", key: "enze0r" }],
|
|
31
|
+
["path", { d: "M2 14h2", key: "vft8re" }],
|
|
32
|
+
["path", { d: "M20 14h2", key: "4cs60a" }],
|
|
33
|
+
["path", { d: "M15 13v2", key: "1xurst" }],
|
|
34
|
+
["path", { d: "M9 13v2", key: "rq6x2g" }]
|
|
35
|
+
];
|
|
36
|
+
const Bot = createLucideIcon("bot", __iconNode$l);
|
|
37
|
+
/**
|
|
38
|
+
* @license lucide-react v0.575.0 - ISC
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the ISC license.
|
|
41
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
+
*/
|
|
43
|
+
const __iconNode$k = [
|
|
30
44
|
["path", { d: "M10 12h4", key: "a56b0p" }],
|
|
31
45
|
["path", { d: "M10 8h4", key: "1sr2af" }],
|
|
32
46
|
["path", { d: "M14 21v-3a2 2 0 0 0-4 0v3", key: "1rgiei" }],
|
|
@@ -39,51 +53,24 @@ const __iconNode$n = [
|
|
|
39
53
|
],
|
|
40
54
|
["path", { d: "M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16", key: "16ra0t" }]
|
|
41
55
|
];
|
|
42
|
-
const Building2 = createLucideIcon("building-2", __iconNode$
|
|
43
|
-
/**
|
|
44
|
-
* @license lucide-react v0.575.0 - ISC
|
|
45
|
-
*
|
|
46
|
-
* This source code is licensed under the ISC license.
|
|
47
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
48
|
-
*/
|
|
49
|
-
const __iconNode$m = [["path", { d: "m15 18-6-6 6-6", key: "1wnfg3" }]];
|
|
50
|
-
const ChevronLeft = createLucideIcon("chevron-left", __iconNode$m);
|
|
56
|
+
const Building2 = createLucideIcon("building-2", __iconNode$k);
|
|
51
57
|
/**
|
|
52
58
|
* @license lucide-react v0.575.0 - ISC
|
|
53
59
|
*
|
|
54
60
|
* This source code is licensed under the ISC license.
|
|
55
61
|
* See the LICENSE file in the root directory of this source tree.
|
|
56
62
|
*/
|
|
57
|
-
const __iconNode$
|
|
63
|
+
const __iconNode$j = [
|
|
58
64
|
["path", { d: "M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z", key: "p7xjir" }]
|
|
59
65
|
];
|
|
60
|
-
const Cloud = createLucideIcon("cloud", __iconNode$
|
|
61
|
-
/**
|
|
62
|
-
* @license lucide-react v0.575.0 - ISC
|
|
63
|
-
*
|
|
64
|
-
* This source code is licensed under the ISC license.
|
|
65
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/
|
|
67
|
-
const __iconNode$k = [
|
|
68
|
-
["path", { d: "M21.54 15H17a2 2 0 0 0-2 2v4.54", key: "1djwo0" }],
|
|
69
|
-
[
|
|
70
|
-
"path",
|
|
71
|
-
{
|
|
72
|
-
d: "M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",
|
|
73
|
-
key: "1tzkfa"
|
|
74
|
-
}
|
|
75
|
-
],
|
|
76
|
-
["path", { d: "M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05", key: "14pb5j" }],
|
|
77
|
-
["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }]
|
|
78
|
-
];
|
|
79
|
-
const Earth = createLucideIcon("earth", __iconNode$k);
|
|
66
|
+
const Cloud = createLucideIcon("cloud", __iconNode$j);
|
|
80
67
|
/**
|
|
81
68
|
* @license lucide-react v0.575.0 - ISC
|
|
82
69
|
*
|
|
83
70
|
* This source code is licensed under the ISC license.
|
|
84
71
|
* See the LICENSE file in the root directory of this source tree.
|
|
85
72
|
*/
|
|
86
|
-
const __iconNode$
|
|
73
|
+
const __iconNode$i = [
|
|
87
74
|
[
|
|
88
75
|
"path",
|
|
89
76
|
{
|
|
@@ -93,14 +80,14 @@ const __iconNode$j = [
|
|
|
93
80
|
],
|
|
94
81
|
["circle", { cx: "12", cy: "12", r: "3", key: "1v7zrd" }]
|
|
95
82
|
];
|
|
96
|
-
const Eye = createLucideIcon("eye", __iconNode$
|
|
83
|
+
const Eye = createLucideIcon("eye", __iconNode$i);
|
|
97
84
|
/**
|
|
98
85
|
* @license lucide-react v0.575.0 - ISC
|
|
99
86
|
*
|
|
100
87
|
* This source code is licensed under the ISC license.
|
|
101
88
|
* See the LICENSE file in the root directory of this source tree.
|
|
102
89
|
*/
|
|
103
|
-
const __iconNode$
|
|
90
|
+
const __iconNode$h = [
|
|
104
91
|
[
|
|
105
92
|
"path",
|
|
106
93
|
{
|
|
@@ -112,14 +99,14 @@ const __iconNode$i = [
|
|
|
112
99
|
["path", { d: "M10 12.5 8 15l2 2.5", key: "1tg20x" }],
|
|
113
100
|
["path", { d: "m14 12.5 2 2.5-2 2.5", key: "yinavb" }]
|
|
114
101
|
];
|
|
115
|
-
const FileCode = createLucideIcon("file-code", __iconNode$
|
|
102
|
+
const FileCode = createLucideIcon("file-code", __iconNode$h);
|
|
116
103
|
/**
|
|
117
104
|
* @license lucide-react v0.575.0 - ISC
|
|
118
105
|
*
|
|
119
106
|
* This source code is licensed under the ISC license.
|
|
120
107
|
* See the LICENSE file in the root directory of this source tree.
|
|
121
108
|
*/
|
|
122
|
-
const __iconNode$
|
|
109
|
+
const __iconNode$g = [
|
|
123
110
|
[
|
|
124
111
|
"path",
|
|
125
112
|
{
|
|
@@ -128,26 +115,26 @@ const __iconNode$h = [
|
|
|
128
115
|
}
|
|
129
116
|
]
|
|
130
117
|
];
|
|
131
|
-
const Headphones = createLucideIcon("headphones", __iconNode$
|
|
118
|
+
const Headphones = createLucideIcon("headphones", __iconNode$g);
|
|
132
119
|
/**
|
|
133
120
|
* @license lucide-react v0.575.0 - ISC
|
|
134
121
|
*
|
|
135
122
|
* This source code is licensed under the ISC license.
|
|
136
123
|
* See the LICENSE file in the root directory of this source tree.
|
|
137
124
|
*/
|
|
138
|
-
const __iconNode$
|
|
125
|
+
const __iconNode$f = [
|
|
139
126
|
["path", { d: "m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4", key: "g0fldk" }],
|
|
140
127
|
["path", { d: "m21 2-9.6 9.6", key: "1j0ho8" }],
|
|
141
128
|
["circle", { cx: "7.5", cy: "15.5", r: "5.5", key: "yqb3hr" }]
|
|
142
129
|
];
|
|
143
|
-
const Key = createLucideIcon("key", __iconNode$
|
|
130
|
+
const Key = createLucideIcon("key", __iconNode$f);
|
|
144
131
|
/**
|
|
145
132
|
* @license lucide-react v0.575.0 - ISC
|
|
146
133
|
*
|
|
147
134
|
* This source code is licensed under the ISC license.
|
|
148
135
|
* See the LICENSE file in the root directory of this source tree.
|
|
149
136
|
*/
|
|
150
|
-
const __iconNode$
|
|
137
|
+
const __iconNode$e = [
|
|
151
138
|
["path", { d: "M10 8h.01", key: "1r9ogq" }],
|
|
152
139
|
["path", { d: "M12 12h.01", key: "1mp3jc" }],
|
|
153
140
|
["path", { d: "M14 8h.01", key: "1primd" }],
|
|
@@ -158,47 +145,33 @@ const __iconNode$f = [
|
|
|
158
145
|
["path", { d: "M8 12h.01", key: "czm47f" }],
|
|
159
146
|
["rect", { width: "20", height: "16", x: "2", y: "4", rx: "2", key: "18n3k1" }]
|
|
160
147
|
];
|
|
161
|
-
const Keyboard = createLucideIcon("keyboard", __iconNode$
|
|
148
|
+
const Keyboard = createLucideIcon("keyboard", __iconNode$e);
|
|
162
149
|
/**
|
|
163
150
|
* @license lucide-react v0.575.0 - ISC
|
|
164
151
|
*
|
|
165
152
|
* This source code is licensed under the ISC license.
|
|
166
153
|
* See the LICENSE file in the root directory of this source tree.
|
|
167
154
|
*/
|
|
168
|
-
const __iconNode$
|
|
155
|
+
const __iconNode$d = [
|
|
169
156
|
["rect", { width: "7", height: "9", x: "3", y: "3", rx: "1", key: "10lvy0" }],
|
|
170
157
|
["rect", { width: "7", height: "5", x: "14", y: "3", rx: "1", key: "16une8" }],
|
|
171
158
|
["rect", { width: "7", height: "9", x: "14", y: "12", rx: "1", key: "1hutg5" }],
|
|
172
159
|
["rect", { width: "7", height: "5", x: "3", y: "16", rx: "1", key: "ldoo1y" }]
|
|
173
160
|
];
|
|
174
|
-
const LayoutDashboard = createLucideIcon("layout-dashboard", __iconNode$
|
|
161
|
+
const LayoutDashboard = createLucideIcon("layout-dashboard", __iconNode$d);
|
|
175
162
|
/**
|
|
176
163
|
* @license lucide-react v0.575.0 - ISC
|
|
177
164
|
*
|
|
178
165
|
* This source code is licensed under the ISC license.
|
|
179
166
|
* See the LICENSE file in the root directory of this source tree.
|
|
180
167
|
*/
|
|
181
|
-
const __iconNode$
|
|
168
|
+
const __iconNode$c = [
|
|
182
169
|
["path", { d: "m16 6 4 14", key: "ji33uf" }],
|
|
183
170
|
["path", { d: "M12 6v14", key: "1n7gus" }],
|
|
184
171
|
["path", { d: "M8 8v12", key: "1gg7y9" }],
|
|
185
172
|
["path", { d: "M4 4v16", key: "6qkkli" }]
|
|
186
173
|
];
|
|
187
|
-
const Library = createLucideIcon("library", __iconNode$
|
|
188
|
-
/**
|
|
189
|
-
* @license lucide-react v0.575.0 - ISC
|
|
190
|
-
*
|
|
191
|
-
* This source code is licensed under the ISC license.
|
|
192
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
193
|
-
*/
|
|
194
|
-
const __iconNode$c = [
|
|
195
|
-
["path", { d: "M16 5H3", key: "m91uny" }],
|
|
196
|
-
["path", { d: "M11 12H3", key: "51ecnj" }],
|
|
197
|
-
["path", { d: "M16 19H3", key: "zzsher" }],
|
|
198
|
-
["path", { d: "M18 9v6", key: "1twb98" }],
|
|
199
|
-
["path", { d: "M21 12h-6", key: "bt1uis" }]
|
|
200
|
-
];
|
|
201
|
-
const ListPlus = createLucideIcon("list-plus", __iconNode$c);
|
|
174
|
+
const Library = createLucideIcon("library", __iconNode$c);
|
|
202
175
|
/**
|
|
203
176
|
* @license lucide-react v0.575.0 - ISC
|
|
204
177
|
*
|
|
@@ -337,4147 +310,384 @@ const SquareCheckBig = createLucideIcon("square-check-big", __iconNode$4);
|
|
|
337
310
|
const __iconNode$3 = [
|
|
338
311
|
[
|
|
339
312
|
"path",
|
|
340
|
-
{
|
|
341
|
-
d: "M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",
|
|
342
|
-
key: "r04s7s"
|
|
343
|
-
}
|
|
344
|
-
]
|
|
345
|
-
];
|
|
346
|
-
const Star = createLucideIcon("star", __iconNode$3);
|
|
347
|
-
/**
|
|
348
|
-
* @license lucide-react v0.575.0 - ISC
|
|
349
|
-
*
|
|
350
|
-
* This source code is licensed under the ISC license.
|
|
351
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
352
|
-
*/
|
|
353
|
-
const __iconNode$2 = [
|
|
354
|
-
["path", { d: "M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2", key: "975kel" }],
|
|
355
|
-
["circle", { cx: "12", cy: "7", r: "4", key: "17ys0d" }]
|
|
356
|
-
];
|
|
357
|
-
const User = createLucideIcon("user", __iconNode$2);
|
|
358
|
-
/**
|
|
359
|
-
* @license lucide-react v0.575.0 - ISC
|
|
360
|
-
*
|
|
361
|
-
* This source code is licensed under the ISC license.
|
|
362
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
363
|
-
*/
|
|
364
|
-
const __iconNode$1 = [
|
|
365
|
-
[
|
|
366
|
-
"path",
|
|
367
|
-
{
|
|
368
|
-
d: "m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",
|
|
369
|
-
key: "ftymec"
|
|
370
|
-
}
|
|
371
|
-
],
|
|
372
|
-
["rect", { x: "2", y: "6", width: "14", height: "12", rx: "2", key: "158x01" }]
|
|
373
|
-
];
|
|
374
|
-
const Video = createLucideIcon("video", __iconNode$1);
|
|
375
|
-
/**
|
|
376
|
-
* @license lucide-react v0.575.0 - ISC
|
|
377
|
-
*
|
|
378
|
-
* This source code is licensed under the ISC license.
|
|
379
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
380
|
-
*/
|
|
381
|
-
const __iconNode = [
|
|
382
|
-
[
|
|
383
|
-
"path",
|
|
384
|
-
{
|
|
385
|
-
d: "M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",
|
|
386
|
-
key: "1xq2db"
|
|
387
|
-
}
|
|
388
|
-
]
|
|
389
|
-
];
|
|
390
|
-
const Zap = createLucideIcon("zap", __iconNode);
|
|
391
|
-
function ccount(value, character) {
|
|
392
|
-
const source = String(value);
|
|
393
|
-
if (typeof character !== "string") {
|
|
394
|
-
throw new TypeError("Expected character");
|
|
395
|
-
}
|
|
396
|
-
let count = 0;
|
|
397
|
-
let index = source.indexOf(character);
|
|
398
|
-
while (index !== -1) {
|
|
399
|
-
count++;
|
|
400
|
-
index = source.indexOf(character, index + character.length);
|
|
401
|
-
}
|
|
402
|
-
return count;
|
|
403
|
-
}
|
|
404
|
-
function ok$1() {
|
|
405
|
-
}
|
|
406
|
-
const asciiAlpha = regexCheck(/[A-Za-z]/);
|
|
407
|
-
const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/);
|
|
408
|
-
function asciiControl(code2) {
|
|
409
|
-
return (
|
|
410
|
-
// Special whitespace codes (which have negative values), C0 and Control
|
|
411
|
-
// character DEL
|
|
412
|
-
code2 !== null && (code2 < 32 || code2 === 127)
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
function markdownLineEnding(code2) {
|
|
416
|
-
return code2 !== null && code2 < -2;
|
|
417
|
-
}
|
|
418
|
-
function markdownLineEndingOrSpace(code2) {
|
|
419
|
-
return code2 !== null && (code2 < 0 || code2 === 32);
|
|
420
|
-
}
|
|
421
|
-
function markdownSpace(code2) {
|
|
422
|
-
return code2 === -2 || code2 === -1 || code2 === 32;
|
|
423
|
-
}
|
|
424
|
-
const unicodePunctuation = regexCheck(new RegExp("\\p{P}|\\p{S}", "u"));
|
|
425
|
-
const unicodeWhitespace = regexCheck(/\s/);
|
|
426
|
-
function regexCheck(regex) {
|
|
427
|
-
return check;
|
|
428
|
-
function check(code2) {
|
|
429
|
-
return code2 !== null && code2 > -1 && regex.test(String.fromCharCode(code2));
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
function escapeStringRegexp(string) {
|
|
433
|
-
if (typeof string !== "string") {
|
|
434
|
-
throw new TypeError("Expected a string");
|
|
435
|
-
}
|
|
436
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
437
|
-
}
|
|
438
|
-
const convert = (
|
|
439
|
-
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
440
|
-
/**
|
|
441
|
-
* @type {(
|
|
442
|
-
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
443
|
-
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
444
|
-
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
445
|
-
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
446
|
-
* ((test?: Test) => Check)
|
|
447
|
-
* )}
|
|
448
|
-
*/
|
|
449
|
-
/**
|
|
450
|
-
* @param {Test} [test]
|
|
451
|
-
* @returns {Check}
|
|
452
|
-
*/
|
|
453
|
-
(function(test) {
|
|
454
|
-
if (test === null || test === void 0) {
|
|
455
|
-
return ok;
|
|
456
|
-
}
|
|
457
|
-
if (typeof test === "function") {
|
|
458
|
-
return castFactory(test);
|
|
459
|
-
}
|
|
460
|
-
if (typeof test === "object") {
|
|
461
|
-
return Array.isArray(test) ? anyFactory(test) : (
|
|
462
|
-
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
463
|
-
// narrows to `Array`.
|
|
464
|
-
propertiesFactory(
|
|
465
|
-
/** @type {Props} */
|
|
466
|
-
test
|
|
467
|
-
)
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
if (typeof test === "string") {
|
|
471
|
-
return typeFactory(test);
|
|
472
|
-
}
|
|
473
|
-
throw new Error("Expected function, string, or object as test");
|
|
474
|
-
})
|
|
475
|
-
);
|
|
476
|
-
function anyFactory(tests) {
|
|
477
|
-
const checks = [];
|
|
478
|
-
let index = -1;
|
|
479
|
-
while (++index < tests.length) {
|
|
480
|
-
checks[index] = convert(tests[index]);
|
|
481
|
-
}
|
|
482
|
-
return castFactory(any);
|
|
483
|
-
function any(...parameters) {
|
|
484
|
-
let index2 = -1;
|
|
485
|
-
while (++index2 < checks.length) {
|
|
486
|
-
if (checks[index2].apply(this, parameters)) return true;
|
|
487
|
-
}
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function propertiesFactory(check) {
|
|
492
|
-
const checkAsRecord = (
|
|
493
|
-
/** @type {Record<string, unknown>} */
|
|
494
|
-
check
|
|
495
|
-
);
|
|
496
|
-
return castFactory(all2);
|
|
497
|
-
function all2(node2) {
|
|
498
|
-
const nodeAsRecord = (
|
|
499
|
-
/** @type {Record<string, unknown>} */
|
|
500
|
-
/** @type {unknown} */
|
|
501
|
-
node2
|
|
502
|
-
);
|
|
503
|
-
let key;
|
|
504
|
-
for (key in check) {
|
|
505
|
-
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
506
|
-
}
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
function typeFactory(check) {
|
|
511
|
-
return castFactory(type);
|
|
512
|
-
function type(node2) {
|
|
513
|
-
return node2 && node2.type === check;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function castFactory(testFunction) {
|
|
517
|
-
return check;
|
|
518
|
-
function check(value, index, parent) {
|
|
519
|
-
return Boolean(
|
|
520
|
-
looksLikeANode(value) && testFunction.call(
|
|
521
|
-
this,
|
|
522
|
-
value,
|
|
523
|
-
typeof index === "number" ? index : void 0,
|
|
524
|
-
parent || void 0
|
|
525
|
-
)
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
function ok() {
|
|
530
|
-
return true;
|
|
531
|
-
}
|
|
532
|
-
function looksLikeANode(value) {
|
|
533
|
-
return value !== null && typeof value === "object" && "type" in value;
|
|
534
|
-
}
|
|
535
|
-
function color(d) {
|
|
536
|
-
return d;
|
|
537
|
-
}
|
|
538
|
-
const empty = [];
|
|
539
|
-
const CONTINUE = true;
|
|
540
|
-
const EXIT = false;
|
|
541
|
-
const SKIP = "skip";
|
|
542
|
-
function visitParents(tree, test, visitor, reverse) {
|
|
543
|
-
let check;
|
|
544
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
545
|
-
reverse = visitor;
|
|
546
|
-
visitor = test;
|
|
547
|
-
} else {
|
|
548
|
-
check = test;
|
|
549
|
-
}
|
|
550
|
-
const is = convert(check);
|
|
551
|
-
const step = reverse ? -1 : 1;
|
|
552
|
-
factory(tree, void 0, [])();
|
|
553
|
-
function factory(node2, index, parents) {
|
|
554
|
-
const value = (
|
|
555
|
-
/** @type {Record<string, unknown>} */
|
|
556
|
-
node2 && typeof node2 === "object" ? node2 : {}
|
|
557
|
-
);
|
|
558
|
-
if (typeof value.type === "string") {
|
|
559
|
-
const name = (
|
|
560
|
-
// `hast`
|
|
561
|
-
typeof value.tagName === "string" ? value.tagName : (
|
|
562
|
-
// `xast`
|
|
563
|
-
typeof value.name === "string" ? value.name : void 0
|
|
564
|
-
)
|
|
565
|
-
);
|
|
566
|
-
Object.defineProperty(visit2, "name", {
|
|
567
|
-
value: "node (" + color(node2.type + (name ? "<" + name + ">" : "")) + ")"
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
return visit2;
|
|
571
|
-
function visit2() {
|
|
572
|
-
let result = empty;
|
|
573
|
-
let subresult;
|
|
574
|
-
let offset2;
|
|
575
|
-
let grandparents;
|
|
576
|
-
if (!test || is(node2, index, parents[parents.length - 1] || void 0)) {
|
|
577
|
-
result = toResult(visitor(node2, parents));
|
|
578
|
-
if (result[0] === EXIT) {
|
|
579
|
-
return result;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
if ("children" in node2 && node2.children) {
|
|
583
|
-
const nodeAsParent = (
|
|
584
|
-
/** @type {UnistParent} */
|
|
585
|
-
node2
|
|
586
|
-
);
|
|
587
|
-
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
588
|
-
offset2 = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
589
|
-
grandparents = parents.concat(nodeAsParent);
|
|
590
|
-
while (offset2 > -1 && offset2 < nodeAsParent.children.length) {
|
|
591
|
-
const child = nodeAsParent.children[offset2];
|
|
592
|
-
subresult = factory(child, offset2, grandparents)();
|
|
593
|
-
if (subresult[0] === EXIT) {
|
|
594
|
-
return subresult;
|
|
595
|
-
}
|
|
596
|
-
offset2 = typeof subresult[1] === "number" ? subresult[1] : offset2 + step;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
return result;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
function toResult(value) {
|
|
605
|
-
if (Array.isArray(value)) {
|
|
606
|
-
return value;
|
|
607
|
-
}
|
|
608
|
-
if (typeof value === "number") {
|
|
609
|
-
return [CONTINUE, value];
|
|
610
|
-
}
|
|
611
|
-
return value === null || value === void 0 ? empty : [value];
|
|
612
|
-
}
|
|
613
|
-
function findAndReplace(tree, list2, options) {
|
|
614
|
-
const settings = options || {};
|
|
615
|
-
const ignored = convert(settings.ignore || []);
|
|
616
|
-
const pairs = toPairs(list2);
|
|
617
|
-
let pairIndex = -1;
|
|
618
|
-
while (++pairIndex < pairs.length) {
|
|
619
|
-
visitParents(tree, "text", visitor);
|
|
620
|
-
}
|
|
621
|
-
function visitor(node2, parents) {
|
|
622
|
-
let index = -1;
|
|
623
|
-
let grandparent;
|
|
624
|
-
while (++index < parents.length) {
|
|
625
|
-
const parent = parents[index];
|
|
626
|
-
const siblings = grandparent ? grandparent.children : void 0;
|
|
627
|
-
if (ignored(
|
|
628
|
-
parent,
|
|
629
|
-
siblings ? siblings.indexOf(parent) : void 0,
|
|
630
|
-
grandparent
|
|
631
|
-
)) {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
grandparent = parent;
|
|
635
|
-
}
|
|
636
|
-
if (grandparent) {
|
|
637
|
-
return handler(node2, parents);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
function handler(node2, parents) {
|
|
641
|
-
const parent = parents[parents.length - 1];
|
|
642
|
-
const find = pairs[pairIndex][0];
|
|
643
|
-
const replace2 = pairs[pairIndex][1];
|
|
644
|
-
let start = 0;
|
|
645
|
-
const siblings = parent.children;
|
|
646
|
-
const index = siblings.indexOf(node2);
|
|
647
|
-
let change = false;
|
|
648
|
-
let nodes = [];
|
|
649
|
-
find.lastIndex = 0;
|
|
650
|
-
let match = find.exec(node2.value);
|
|
651
|
-
while (match) {
|
|
652
|
-
const position = match.index;
|
|
653
|
-
const matchObject = {
|
|
654
|
-
index: match.index,
|
|
655
|
-
input: match.input,
|
|
656
|
-
stack: [...parents, node2]
|
|
657
|
-
};
|
|
658
|
-
let value = replace2(...match, matchObject);
|
|
659
|
-
if (typeof value === "string") {
|
|
660
|
-
value = value.length > 0 ? { type: "text", value } : void 0;
|
|
661
|
-
}
|
|
662
|
-
if (value === false) {
|
|
663
|
-
find.lastIndex = position + 1;
|
|
664
|
-
} else {
|
|
665
|
-
if (start !== position) {
|
|
666
|
-
nodes.push({
|
|
667
|
-
type: "text",
|
|
668
|
-
value: node2.value.slice(start, position)
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
if (Array.isArray(value)) {
|
|
672
|
-
nodes.push(...value);
|
|
673
|
-
} else if (value) {
|
|
674
|
-
nodes.push(value);
|
|
675
|
-
}
|
|
676
|
-
start = position + match[0].length;
|
|
677
|
-
change = true;
|
|
678
|
-
}
|
|
679
|
-
if (!find.global) {
|
|
680
|
-
break;
|
|
681
|
-
}
|
|
682
|
-
match = find.exec(node2.value);
|
|
683
|
-
}
|
|
684
|
-
if (change) {
|
|
685
|
-
if (start < node2.value.length) {
|
|
686
|
-
nodes.push({ type: "text", value: node2.value.slice(start) });
|
|
687
|
-
}
|
|
688
|
-
parent.children.splice(index, 1, ...nodes);
|
|
689
|
-
} else {
|
|
690
|
-
nodes = [node2];
|
|
691
|
-
}
|
|
692
|
-
return index + nodes.length;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
function toPairs(tupleOrList) {
|
|
696
|
-
const result = [];
|
|
697
|
-
if (!Array.isArray(tupleOrList)) {
|
|
698
|
-
throw new TypeError("Expected find and replace tuple or list of tuples");
|
|
699
|
-
}
|
|
700
|
-
const list2 = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
|
|
701
|
-
let index = -1;
|
|
702
|
-
while (++index < list2.length) {
|
|
703
|
-
const tuple = list2[index];
|
|
704
|
-
result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
|
|
705
|
-
}
|
|
706
|
-
return result;
|
|
707
|
-
}
|
|
708
|
-
function toExpression(find) {
|
|
709
|
-
return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find;
|
|
710
|
-
}
|
|
711
|
-
function toFunction(replace2) {
|
|
712
|
-
return typeof replace2 === "function" ? replace2 : function() {
|
|
713
|
-
return replace2;
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
const inConstruct = "phrasing";
|
|
717
|
-
const notInConstruct = ["autolink", "link", "image", "label"];
|
|
718
|
-
function gfmAutolinkLiteralFromMarkdown() {
|
|
719
|
-
return {
|
|
720
|
-
transforms: [transformGfmAutolinkLiterals],
|
|
721
|
-
enter: {
|
|
722
|
-
literalAutolink: enterLiteralAutolink,
|
|
723
|
-
literalAutolinkEmail: enterLiteralAutolinkValue,
|
|
724
|
-
literalAutolinkHttp: enterLiteralAutolinkValue,
|
|
725
|
-
literalAutolinkWww: enterLiteralAutolinkValue
|
|
726
|
-
},
|
|
727
|
-
exit: {
|
|
728
|
-
literalAutolink: exitLiteralAutolink,
|
|
729
|
-
literalAutolinkEmail: exitLiteralAutolinkEmail,
|
|
730
|
-
literalAutolinkHttp: exitLiteralAutolinkHttp,
|
|
731
|
-
literalAutolinkWww: exitLiteralAutolinkWww
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
function gfmAutolinkLiteralToMarkdown() {
|
|
736
|
-
return {
|
|
737
|
-
unsafe: [
|
|
738
|
-
{
|
|
739
|
-
character: "@",
|
|
740
|
-
before: "[+\\-.\\w]",
|
|
741
|
-
after: "[\\-.\\w]",
|
|
742
|
-
inConstruct,
|
|
743
|
-
notInConstruct
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
character: ".",
|
|
747
|
-
before: "[Ww]",
|
|
748
|
-
after: "[\\-.\\w]",
|
|
749
|
-
inConstruct,
|
|
750
|
-
notInConstruct
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
character: ":",
|
|
754
|
-
before: "[ps]",
|
|
755
|
-
after: "\\/",
|
|
756
|
-
inConstruct,
|
|
757
|
-
notInConstruct
|
|
758
|
-
}
|
|
759
|
-
]
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
function enterLiteralAutolink(token) {
|
|
763
|
-
this.enter({ type: "link", title: null, url: "", children: [] }, token);
|
|
764
|
-
}
|
|
765
|
-
function enterLiteralAutolinkValue(token) {
|
|
766
|
-
this.config.enter.autolinkProtocol.call(this, token);
|
|
767
|
-
}
|
|
768
|
-
function exitLiteralAutolinkHttp(token) {
|
|
769
|
-
this.config.exit.autolinkProtocol.call(this, token);
|
|
770
|
-
}
|
|
771
|
-
function exitLiteralAutolinkWww(token) {
|
|
772
|
-
this.config.exit.data.call(this, token);
|
|
773
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
774
|
-
ok$1(node2.type === "link");
|
|
775
|
-
node2.url = "http://" + this.sliceSerialize(token);
|
|
776
|
-
}
|
|
777
|
-
function exitLiteralAutolinkEmail(token) {
|
|
778
|
-
this.config.exit.autolinkEmail.call(this, token);
|
|
779
|
-
}
|
|
780
|
-
function exitLiteralAutolink(token) {
|
|
781
|
-
this.exit(token);
|
|
782
|
-
}
|
|
783
|
-
function transformGfmAutolinkLiterals(tree) {
|
|
784
|
-
findAndReplace(
|
|
785
|
-
tree,
|
|
786
|
-
[
|
|
787
|
-
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
|
|
788
|
-
[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)", "gu"), findEmail]
|
|
789
|
-
],
|
|
790
|
-
{ ignore: ["link", "linkReference"] }
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
function findUrl(_, protocol, domain2, path2, match) {
|
|
794
|
-
let prefix = "";
|
|
795
|
-
if (!previous(match)) {
|
|
796
|
-
return false;
|
|
797
|
-
}
|
|
798
|
-
if (/^w/i.test(protocol)) {
|
|
799
|
-
domain2 = protocol + domain2;
|
|
800
|
-
protocol = "";
|
|
801
|
-
prefix = "http://";
|
|
802
|
-
}
|
|
803
|
-
if (!isCorrectDomain(domain2)) {
|
|
804
|
-
return false;
|
|
805
|
-
}
|
|
806
|
-
const parts = splitUrl(domain2 + path2);
|
|
807
|
-
if (!parts[0]) return false;
|
|
808
|
-
const result = {
|
|
809
|
-
type: "link",
|
|
810
|
-
title: null,
|
|
811
|
-
url: prefix + protocol + parts[0],
|
|
812
|
-
children: [{ type: "text", value: protocol + parts[0] }]
|
|
813
|
-
};
|
|
814
|
-
if (parts[1]) {
|
|
815
|
-
return [result, { type: "text", value: parts[1] }];
|
|
816
|
-
}
|
|
817
|
-
return result;
|
|
818
|
-
}
|
|
819
|
-
function findEmail(_, atext, label, match) {
|
|
820
|
-
if (
|
|
821
|
-
// Not an expected previous character.
|
|
822
|
-
!previous(match, true) || // Label ends in not allowed character.
|
|
823
|
-
/[-\d_]$/.test(label)
|
|
824
|
-
) {
|
|
825
|
-
return false;
|
|
826
|
-
}
|
|
827
|
-
return {
|
|
828
|
-
type: "link",
|
|
829
|
-
title: null,
|
|
830
|
-
url: "mailto:" + atext + "@" + label,
|
|
831
|
-
children: [{ type: "text", value: atext + "@" + label }]
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
function isCorrectDomain(domain2) {
|
|
835
|
-
const parts = domain2.split(".");
|
|
836
|
-
if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
|
|
837
|
-
return false;
|
|
838
|
-
}
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
function splitUrl(url) {
|
|
842
|
-
const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url);
|
|
843
|
-
if (!trailExec) {
|
|
844
|
-
return [url, void 0];
|
|
845
|
-
}
|
|
846
|
-
url = url.slice(0, trailExec.index);
|
|
847
|
-
let trail2 = trailExec[0];
|
|
848
|
-
let closingParenIndex = trail2.indexOf(")");
|
|
849
|
-
const openingParens = ccount(url, "(");
|
|
850
|
-
let closingParens = ccount(url, ")");
|
|
851
|
-
while (closingParenIndex !== -1 && openingParens > closingParens) {
|
|
852
|
-
url += trail2.slice(0, closingParenIndex + 1);
|
|
853
|
-
trail2 = trail2.slice(closingParenIndex + 1);
|
|
854
|
-
closingParenIndex = trail2.indexOf(")");
|
|
855
|
-
closingParens++;
|
|
856
|
-
}
|
|
857
|
-
return [url, trail2];
|
|
858
|
-
}
|
|
859
|
-
function previous(match, email) {
|
|
860
|
-
const code2 = match.input.charCodeAt(match.index - 1);
|
|
861
|
-
return (match.index === 0 || unicodeWhitespace(code2) || unicodePunctuation(code2)) && // If it’s an email, the previous character should not be a slash.
|
|
862
|
-
(!email || code2 !== 47);
|
|
863
|
-
}
|
|
864
|
-
function normalizeIdentifier(value) {
|
|
865
|
-
return value.replace(/[\t\n\r ]+/g, " ").replace(/^ | $/g, "").toLowerCase().toUpperCase();
|
|
866
|
-
}
|
|
867
|
-
footnoteReference.peek = footnoteReferencePeek;
|
|
868
|
-
function enterFootnoteCallString() {
|
|
869
|
-
this.buffer();
|
|
870
|
-
}
|
|
871
|
-
function enterFootnoteCall(token) {
|
|
872
|
-
this.enter({ type: "footnoteReference", identifier: "", label: "" }, token);
|
|
873
|
-
}
|
|
874
|
-
function enterFootnoteDefinitionLabelString() {
|
|
875
|
-
this.buffer();
|
|
876
|
-
}
|
|
877
|
-
function enterFootnoteDefinition(token) {
|
|
878
|
-
this.enter(
|
|
879
|
-
{ type: "footnoteDefinition", identifier: "", label: "", children: [] },
|
|
880
|
-
token
|
|
881
|
-
);
|
|
882
|
-
}
|
|
883
|
-
function exitFootnoteCallString(token) {
|
|
884
|
-
const label = this.resume();
|
|
885
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
886
|
-
ok$1(node2.type === "footnoteReference");
|
|
887
|
-
node2.identifier = normalizeIdentifier(
|
|
888
|
-
this.sliceSerialize(token)
|
|
889
|
-
).toLowerCase();
|
|
890
|
-
node2.label = label;
|
|
891
|
-
}
|
|
892
|
-
function exitFootnoteCall(token) {
|
|
893
|
-
this.exit(token);
|
|
894
|
-
}
|
|
895
|
-
function exitFootnoteDefinitionLabelString(token) {
|
|
896
|
-
const label = this.resume();
|
|
897
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
898
|
-
ok$1(node2.type === "footnoteDefinition");
|
|
899
|
-
node2.identifier = normalizeIdentifier(
|
|
900
|
-
this.sliceSerialize(token)
|
|
901
|
-
).toLowerCase();
|
|
902
|
-
node2.label = label;
|
|
903
|
-
}
|
|
904
|
-
function exitFootnoteDefinition(token) {
|
|
905
|
-
this.exit(token);
|
|
906
|
-
}
|
|
907
|
-
function footnoteReferencePeek() {
|
|
908
|
-
return "[";
|
|
909
|
-
}
|
|
910
|
-
function footnoteReference(node2, _, state, info) {
|
|
911
|
-
const tracker = state.createTracker(info);
|
|
912
|
-
let value = tracker.move("[^");
|
|
913
|
-
const exit2 = state.enter("footnoteReference");
|
|
914
|
-
const subexit = state.enter("reference");
|
|
915
|
-
value += tracker.move(
|
|
916
|
-
state.safe(state.associationId(node2), { after: "]", before: value })
|
|
917
|
-
);
|
|
918
|
-
subexit();
|
|
919
|
-
exit2();
|
|
920
|
-
value += tracker.move("]");
|
|
921
|
-
return value;
|
|
922
|
-
}
|
|
923
|
-
function gfmFootnoteFromMarkdown() {
|
|
924
|
-
return {
|
|
925
|
-
enter: {
|
|
926
|
-
gfmFootnoteCallString: enterFootnoteCallString,
|
|
927
|
-
gfmFootnoteCall: enterFootnoteCall,
|
|
928
|
-
gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString,
|
|
929
|
-
gfmFootnoteDefinition: enterFootnoteDefinition
|
|
930
|
-
},
|
|
931
|
-
exit: {
|
|
932
|
-
gfmFootnoteCallString: exitFootnoteCallString,
|
|
933
|
-
gfmFootnoteCall: exitFootnoteCall,
|
|
934
|
-
gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
|
|
935
|
-
gfmFootnoteDefinition: exitFootnoteDefinition
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
function gfmFootnoteToMarkdown(options) {
|
|
940
|
-
let firstLineBlank = false;
|
|
941
|
-
if (options && options.firstLineBlank) {
|
|
942
|
-
firstLineBlank = true;
|
|
943
|
-
}
|
|
944
|
-
return {
|
|
945
|
-
handlers: { footnoteDefinition, footnoteReference },
|
|
946
|
-
// This is on by default already.
|
|
947
|
-
unsafe: [{ character: "[", inConstruct: ["label", "phrasing", "reference"] }]
|
|
948
|
-
};
|
|
949
|
-
function footnoteDefinition(node2, _, state, info) {
|
|
950
|
-
const tracker = state.createTracker(info);
|
|
951
|
-
let value = tracker.move("[^");
|
|
952
|
-
const exit2 = state.enter("footnoteDefinition");
|
|
953
|
-
const subexit = state.enter("label");
|
|
954
|
-
value += tracker.move(
|
|
955
|
-
state.safe(state.associationId(node2), { before: value, after: "]" })
|
|
956
|
-
);
|
|
957
|
-
subexit();
|
|
958
|
-
value += tracker.move("]:");
|
|
959
|
-
if (node2.children && node2.children.length > 0) {
|
|
960
|
-
tracker.shift(4);
|
|
961
|
-
value += tracker.move(
|
|
962
|
-
(firstLineBlank ? "\n" : " ") + state.indentLines(
|
|
963
|
-
state.containerFlow(node2, tracker.current()),
|
|
964
|
-
firstLineBlank ? mapAll : mapExceptFirst
|
|
965
|
-
)
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
exit2();
|
|
969
|
-
return value;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
function mapExceptFirst(line, index, blank) {
|
|
973
|
-
return index === 0 ? line : mapAll(line, index, blank);
|
|
974
|
-
}
|
|
975
|
-
function mapAll(line, index, blank) {
|
|
976
|
-
return (blank ? "" : " ") + line;
|
|
977
|
-
}
|
|
978
|
-
const constructsWithoutStrikethrough = [
|
|
979
|
-
"autolink",
|
|
980
|
-
"destinationLiteral",
|
|
981
|
-
"destinationRaw",
|
|
982
|
-
"reference",
|
|
983
|
-
"titleQuote",
|
|
984
|
-
"titleApostrophe"
|
|
985
|
-
];
|
|
986
|
-
handleDelete.peek = peekDelete;
|
|
987
|
-
function gfmStrikethroughFromMarkdown() {
|
|
988
|
-
return {
|
|
989
|
-
canContainEols: ["delete"],
|
|
990
|
-
enter: { strikethrough: enterStrikethrough },
|
|
991
|
-
exit: { strikethrough: exitStrikethrough }
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
function gfmStrikethroughToMarkdown() {
|
|
995
|
-
return {
|
|
996
|
-
unsafe: [
|
|
997
|
-
{
|
|
998
|
-
character: "~",
|
|
999
|
-
inConstruct: "phrasing",
|
|
1000
|
-
notInConstruct: constructsWithoutStrikethrough
|
|
1001
|
-
}
|
|
1002
|
-
],
|
|
1003
|
-
handlers: { delete: handleDelete }
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function enterStrikethrough(token) {
|
|
1007
|
-
this.enter({ type: "delete", children: [] }, token);
|
|
1008
|
-
}
|
|
1009
|
-
function exitStrikethrough(token) {
|
|
1010
|
-
this.exit(token);
|
|
1011
|
-
}
|
|
1012
|
-
function handleDelete(node2, _, state, info) {
|
|
1013
|
-
const tracker = state.createTracker(info);
|
|
1014
|
-
const exit2 = state.enter("strikethrough");
|
|
1015
|
-
let value = tracker.move("~~");
|
|
1016
|
-
value += state.containerPhrasing(node2, {
|
|
1017
|
-
...tracker.current(),
|
|
1018
|
-
before: value,
|
|
1019
|
-
after: "~"
|
|
1020
|
-
});
|
|
1021
|
-
value += tracker.move("~~");
|
|
1022
|
-
exit2();
|
|
1023
|
-
return value;
|
|
1024
|
-
}
|
|
1025
|
-
function peekDelete() {
|
|
1026
|
-
return "~";
|
|
1027
|
-
}
|
|
1028
|
-
function defaultStringLength(value) {
|
|
1029
|
-
return value.length;
|
|
1030
|
-
}
|
|
1031
|
-
function markdownTable(table, options) {
|
|
1032
|
-
const settings = options || {};
|
|
1033
|
-
const align = (settings.align || []).concat();
|
|
1034
|
-
const stringLength = settings.stringLength || defaultStringLength;
|
|
1035
|
-
const alignments = [];
|
|
1036
|
-
const cellMatrix = [];
|
|
1037
|
-
const sizeMatrix = [];
|
|
1038
|
-
const longestCellByColumn = [];
|
|
1039
|
-
let mostCellsPerRow = 0;
|
|
1040
|
-
let rowIndex = -1;
|
|
1041
|
-
while (++rowIndex < table.length) {
|
|
1042
|
-
const row2 = [];
|
|
1043
|
-
const sizes2 = [];
|
|
1044
|
-
let columnIndex2 = -1;
|
|
1045
|
-
if (table[rowIndex].length > mostCellsPerRow) {
|
|
1046
|
-
mostCellsPerRow = table[rowIndex].length;
|
|
1047
|
-
}
|
|
1048
|
-
while (++columnIndex2 < table[rowIndex].length) {
|
|
1049
|
-
const cell = serialize(table[rowIndex][columnIndex2]);
|
|
1050
|
-
if (settings.alignDelimiters !== false) {
|
|
1051
|
-
const size = stringLength(cell);
|
|
1052
|
-
sizes2[columnIndex2] = size;
|
|
1053
|
-
if (longestCellByColumn[columnIndex2] === void 0 || size > longestCellByColumn[columnIndex2]) {
|
|
1054
|
-
longestCellByColumn[columnIndex2] = size;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
row2.push(cell);
|
|
1058
|
-
}
|
|
1059
|
-
cellMatrix[rowIndex] = row2;
|
|
1060
|
-
sizeMatrix[rowIndex] = sizes2;
|
|
1061
|
-
}
|
|
1062
|
-
let columnIndex = -1;
|
|
1063
|
-
if (typeof align === "object" && "length" in align) {
|
|
1064
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1065
|
-
alignments[columnIndex] = toAlignment(align[columnIndex]);
|
|
1066
|
-
}
|
|
1067
|
-
} else {
|
|
1068
|
-
const code2 = toAlignment(align);
|
|
1069
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1070
|
-
alignments[columnIndex] = code2;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
columnIndex = -1;
|
|
1074
|
-
const row = [];
|
|
1075
|
-
const sizes = [];
|
|
1076
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1077
|
-
const code2 = alignments[columnIndex];
|
|
1078
|
-
let before = "";
|
|
1079
|
-
let after = "";
|
|
1080
|
-
if (code2 === 99) {
|
|
1081
|
-
before = ":";
|
|
1082
|
-
after = ":";
|
|
1083
|
-
} else if (code2 === 108) {
|
|
1084
|
-
before = ":";
|
|
1085
|
-
} else if (code2 === 114) {
|
|
1086
|
-
after = ":";
|
|
1087
|
-
}
|
|
1088
|
-
let size = settings.alignDelimiters === false ? 1 : Math.max(
|
|
1089
|
-
1,
|
|
1090
|
-
longestCellByColumn[columnIndex] - before.length - after.length
|
|
1091
|
-
);
|
|
1092
|
-
const cell = before + "-".repeat(size) + after;
|
|
1093
|
-
if (settings.alignDelimiters !== false) {
|
|
1094
|
-
size = before.length + size + after.length;
|
|
1095
|
-
if (size > longestCellByColumn[columnIndex]) {
|
|
1096
|
-
longestCellByColumn[columnIndex] = size;
|
|
1097
|
-
}
|
|
1098
|
-
sizes[columnIndex] = size;
|
|
1099
|
-
}
|
|
1100
|
-
row[columnIndex] = cell;
|
|
1101
|
-
}
|
|
1102
|
-
cellMatrix.splice(1, 0, row);
|
|
1103
|
-
sizeMatrix.splice(1, 0, sizes);
|
|
1104
|
-
rowIndex = -1;
|
|
1105
|
-
const lines = [];
|
|
1106
|
-
while (++rowIndex < cellMatrix.length) {
|
|
1107
|
-
const row2 = cellMatrix[rowIndex];
|
|
1108
|
-
const sizes2 = sizeMatrix[rowIndex];
|
|
1109
|
-
columnIndex = -1;
|
|
1110
|
-
const line = [];
|
|
1111
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1112
|
-
const cell = row2[columnIndex] || "";
|
|
1113
|
-
let before = "";
|
|
1114
|
-
let after = "";
|
|
1115
|
-
if (settings.alignDelimiters !== false) {
|
|
1116
|
-
const size = longestCellByColumn[columnIndex] - (sizes2[columnIndex] || 0);
|
|
1117
|
-
const code2 = alignments[columnIndex];
|
|
1118
|
-
if (code2 === 114) {
|
|
1119
|
-
before = " ".repeat(size);
|
|
1120
|
-
} else if (code2 === 99) {
|
|
1121
|
-
if (size % 2) {
|
|
1122
|
-
before = " ".repeat(size / 2 + 0.5);
|
|
1123
|
-
after = " ".repeat(size / 2 - 0.5);
|
|
1124
|
-
} else {
|
|
1125
|
-
before = " ".repeat(size / 2);
|
|
1126
|
-
after = before;
|
|
1127
|
-
}
|
|
1128
|
-
} else {
|
|
1129
|
-
after = " ".repeat(size);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
if (settings.delimiterStart !== false && !columnIndex) {
|
|
1133
|
-
line.push("|");
|
|
1134
|
-
}
|
|
1135
|
-
if (settings.padding !== false && // Don’t add the opening space if we’re not aligning and the cell is
|
|
1136
|
-
// empty: there will be a closing space.
|
|
1137
|
-
!(settings.alignDelimiters === false && cell === "") && (settings.delimiterStart !== false || columnIndex)) {
|
|
1138
|
-
line.push(" ");
|
|
1139
|
-
}
|
|
1140
|
-
if (settings.alignDelimiters !== false) {
|
|
1141
|
-
line.push(before);
|
|
1142
|
-
}
|
|
1143
|
-
line.push(cell);
|
|
1144
|
-
if (settings.alignDelimiters !== false) {
|
|
1145
|
-
line.push(after);
|
|
1146
|
-
}
|
|
1147
|
-
if (settings.padding !== false) {
|
|
1148
|
-
line.push(" ");
|
|
1149
|
-
}
|
|
1150
|
-
if (settings.delimiterEnd !== false || columnIndex !== mostCellsPerRow - 1) {
|
|
1151
|
-
line.push("|");
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
lines.push(
|
|
1155
|
-
settings.delimiterEnd === false ? line.join("").replace(/ +$/, "") : line.join("")
|
|
1156
|
-
);
|
|
1157
|
-
}
|
|
1158
|
-
return lines.join("\n");
|
|
1159
|
-
}
|
|
1160
|
-
function serialize(value) {
|
|
1161
|
-
return value === null || value === void 0 ? "" : String(value);
|
|
1162
|
-
}
|
|
1163
|
-
function toAlignment(value) {
|
|
1164
|
-
const code2 = typeof value === "string" ? value.codePointAt(0) : 0;
|
|
1165
|
-
return code2 === 67 || code2 === 99 ? 99 : code2 === 76 || code2 === 108 ? 108 : code2 === 82 || code2 === 114 ? 114 : 0;
|
|
1166
|
-
}
|
|
1167
|
-
function blockquote(node2, _, state, info) {
|
|
1168
|
-
const exit2 = state.enter("blockquote");
|
|
1169
|
-
const tracker = state.createTracker(info);
|
|
1170
|
-
tracker.move("> ");
|
|
1171
|
-
tracker.shift(2);
|
|
1172
|
-
const value = state.indentLines(
|
|
1173
|
-
state.containerFlow(node2, tracker.current()),
|
|
1174
|
-
map$1
|
|
1175
|
-
);
|
|
1176
|
-
exit2();
|
|
1177
|
-
return value;
|
|
1178
|
-
}
|
|
1179
|
-
function map$1(line, _, blank) {
|
|
1180
|
-
return ">" + (blank ? "" : " ") + line;
|
|
1181
|
-
}
|
|
1182
|
-
function patternInScope(stack, pattern) {
|
|
1183
|
-
return listInScope(stack, pattern.inConstruct, true) && !listInScope(stack, pattern.notInConstruct, false);
|
|
1184
|
-
}
|
|
1185
|
-
function listInScope(stack, list2, none) {
|
|
1186
|
-
if (typeof list2 === "string") {
|
|
1187
|
-
list2 = [list2];
|
|
1188
|
-
}
|
|
1189
|
-
if (!list2 || list2.length === 0) {
|
|
1190
|
-
return none;
|
|
1191
|
-
}
|
|
1192
|
-
let index = -1;
|
|
1193
|
-
while (++index < list2.length) {
|
|
1194
|
-
if (stack.includes(list2[index])) {
|
|
1195
|
-
return true;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
return false;
|
|
1199
|
-
}
|
|
1200
|
-
function hardBreak(_, _1, state, info) {
|
|
1201
|
-
let index = -1;
|
|
1202
|
-
while (++index < state.unsafe.length) {
|
|
1203
|
-
if (state.unsafe[index].character === "\n" && patternInScope(state.stack, state.unsafe[index])) {
|
|
1204
|
-
return /[ \t]/.test(info.before) ? "" : " ";
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
return "\\\n";
|
|
1208
|
-
}
|
|
1209
|
-
function longestStreak(value, substring) {
|
|
1210
|
-
const source = String(value);
|
|
1211
|
-
let index = source.indexOf(substring);
|
|
1212
|
-
let expected = index;
|
|
1213
|
-
let count = 0;
|
|
1214
|
-
let max = 0;
|
|
1215
|
-
if (typeof substring !== "string") {
|
|
1216
|
-
throw new TypeError("Expected substring");
|
|
1217
|
-
}
|
|
1218
|
-
while (index !== -1) {
|
|
1219
|
-
if (index === expected) {
|
|
1220
|
-
if (++count > max) {
|
|
1221
|
-
max = count;
|
|
1222
|
-
}
|
|
1223
|
-
} else {
|
|
1224
|
-
count = 1;
|
|
1225
|
-
}
|
|
1226
|
-
expected = index + substring.length;
|
|
1227
|
-
index = source.indexOf(substring, expected);
|
|
1228
|
-
}
|
|
1229
|
-
return max;
|
|
1230
|
-
}
|
|
1231
|
-
function formatCodeAsIndented(node2, state) {
|
|
1232
|
-
return Boolean(
|
|
1233
|
-
state.options.fences === false && node2.value && // If there’s no info…
|
|
1234
|
-
!node2.lang && // And there’s a non-whitespace character…
|
|
1235
|
-
/[^ \r\n]/.test(node2.value) && // And the value doesn’t start or end in a blank…
|
|
1236
|
-
!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node2.value)
|
|
1237
|
-
);
|
|
1238
|
-
}
|
|
1239
|
-
function checkFence(state) {
|
|
1240
|
-
const marker = state.options.fence || "`";
|
|
1241
|
-
if (marker !== "`" && marker !== "~") {
|
|
1242
|
-
throw new Error(
|
|
1243
|
-
"Cannot serialize code with `" + marker + "` for `options.fence`, expected `` ` `` or `~`"
|
|
1244
|
-
);
|
|
1245
|
-
}
|
|
1246
|
-
return marker;
|
|
1247
|
-
}
|
|
1248
|
-
function code$1(node2, _, state, info) {
|
|
1249
|
-
const marker = checkFence(state);
|
|
1250
|
-
const raw = node2.value || "";
|
|
1251
|
-
const suffix = marker === "`" ? "GraveAccent" : "Tilde";
|
|
1252
|
-
if (formatCodeAsIndented(node2, state)) {
|
|
1253
|
-
const exit3 = state.enter("codeIndented");
|
|
1254
|
-
const value2 = state.indentLines(raw, map);
|
|
1255
|
-
exit3();
|
|
1256
|
-
return value2;
|
|
1257
|
-
}
|
|
1258
|
-
const tracker = state.createTracker(info);
|
|
1259
|
-
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3));
|
|
1260
|
-
const exit2 = state.enter("codeFenced");
|
|
1261
|
-
let value = tracker.move(sequence);
|
|
1262
|
-
if (node2.lang) {
|
|
1263
|
-
const subexit = state.enter(`codeFencedLang${suffix}`);
|
|
1264
|
-
value += tracker.move(
|
|
1265
|
-
state.safe(node2.lang, {
|
|
1266
|
-
before: value,
|
|
1267
|
-
after: " ",
|
|
1268
|
-
encode: ["`"],
|
|
1269
|
-
...tracker.current()
|
|
1270
|
-
})
|
|
1271
|
-
);
|
|
1272
|
-
subexit();
|
|
1273
|
-
}
|
|
1274
|
-
if (node2.lang && node2.meta) {
|
|
1275
|
-
const subexit = state.enter(`codeFencedMeta${suffix}`);
|
|
1276
|
-
value += tracker.move(" ");
|
|
1277
|
-
value += tracker.move(
|
|
1278
|
-
state.safe(node2.meta, {
|
|
1279
|
-
before: value,
|
|
1280
|
-
after: "\n",
|
|
1281
|
-
encode: ["`"],
|
|
1282
|
-
...tracker.current()
|
|
1283
|
-
})
|
|
1284
|
-
);
|
|
1285
|
-
subexit();
|
|
1286
|
-
}
|
|
1287
|
-
value += tracker.move("\n");
|
|
1288
|
-
if (raw) {
|
|
1289
|
-
value += tracker.move(raw + "\n");
|
|
1290
|
-
}
|
|
1291
|
-
value += tracker.move(sequence);
|
|
1292
|
-
exit2();
|
|
1293
|
-
return value;
|
|
1294
|
-
}
|
|
1295
|
-
function map(line, _, blank) {
|
|
1296
|
-
return (blank ? "" : " ") + line;
|
|
1297
|
-
}
|
|
1298
|
-
function checkQuote(state) {
|
|
1299
|
-
const marker = state.options.quote || '"';
|
|
1300
|
-
if (marker !== '"' && marker !== "'") {
|
|
1301
|
-
throw new Error(
|
|
1302
|
-
"Cannot serialize title with `" + marker + "` for `options.quote`, expected `\"`, or `'`"
|
|
1303
|
-
);
|
|
1304
|
-
}
|
|
1305
|
-
return marker;
|
|
1306
|
-
}
|
|
1307
|
-
function definition(node2, _, state, info) {
|
|
1308
|
-
const quote = checkQuote(state);
|
|
1309
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1310
|
-
const exit2 = state.enter("definition");
|
|
1311
|
-
let subexit = state.enter("label");
|
|
1312
|
-
const tracker = state.createTracker(info);
|
|
1313
|
-
let value = tracker.move("[");
|
|
1314
|
-
value += tracker.move(
|
|
1315
|
-
state.safe(state.associationId(node2), {
|
|
1316
|
-
before: value,
|
|
1317
|
-
after: "]",
|
|
1318
|
-
...tracker.current()
|
|
1319
|
-
})
|
|
1320
|
-
);
|
|
1321
|
-
value += tracker.move("]: ");
|
|
1322
|
-
subexit();
|
|
1323
|
-
if (
|
|
1324
|
-
// If there’s no url, or…
|
|
1325
|
-
!node2.url || // If there are control characters or whitespace.
|
|
1326
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1327
|
-
) {
|
|
1328
|
-
subexit = state.enter("destinationLiteral");
|
|
1329
|
-
value += tracker.move("<");
|
|
1330
|
-
value += tracker.move(
|
|
1331
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1332
|
-
);
|
|
1333
|
-
value += tracker.move(">");
|
|
1334
|
-
} else {
|
|
1335
|
-
subexit = state.enter("destinationRaw");
|
|
1336
|
-
value += tracker.move(
|
|
1337
|
-
state.safe(node2.url, {
|
|
1338
|
-
before: value,
|
|
1339
|
-
after: node2.title ? " " : "\n",
|
|
1340
|
-
...tracker.current()
|
|
1341
|
-
})
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
subexit();
|
|
1345
|
-
if (node2.title) {
|
|
1346
|
-
subexit = state.enter(`title${suffix}`);
|
|
1347
|
-
value += tracker.move(" " + quote);
|
|
1348
|
-
value += tracker.move(
|
|
1349
|
-
state.safe(node2.title, {
|
|
1350
|
-
before: value,
|
|
1351
|
-
after: quote,
|
|
1352
|
-
...tracker.current()
|
|
1353
|
-
})
|
|
1354
|
-
);
|
|
1355
|
-
value += tracker.move(quote);
|
|
1356
|
-
subexit();
|
|
1357
|
-
}
|
|
1358
|
-
exit2();
|
|
1359
|
-
return value;
|
|
1360
|
-
}
|
|
1361
|
-
function checkEmphasis(state) {
|
|
1362
|
-
const marker = state.options.emphasis || "*";
|
|
1363
|
-
if (marker !== "*" && marker !== "_") {
|
|
1364
|
-
throw new Error(
|
|
1365
|
-
"Cannot serialize emphasis with `" + marker + "` for `options.emphasis`, expected `*`, or `_`"
|
|
1366
|
-
);
|
|
1367
|
-
}
|
|
1368
|
-
return marker;
|
|
1369
|
-
}
|
|
1370
|
-
function encodeCharacterReference(code2) {
|
|
1371
|
-
return "&#x" + code2.toString(16).toUpperCase() + ";";
|
|
1372
|
-
}
|
|
1373
|
-
function classifyCharacter(code2) {
|
|
1374
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
1375
|
-
return 1;
|
|
1376
|
-
}
|
|
1377
|
-
if (unicodePunctuation(code2)) {
|
|
1378
|
-
return 2;
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
function encodeInfo(outside, inside, marker) {
|
|
1382
|
-
const outsideKind = classifyCharacter(outside);
|
|
1383
|
-
const insideKind = classifyCharacter(inside);
|
|
1384
|
-
if (outsideKind === void 0) {
|
|
1385
|
-
return insideKind === void 0 ? (
|
|
1386
|
-
// Letter inside:
|
|
1387
|
-
// we have to encode *both* letters for `_` as it is looser.
|
|
1388
|
-
// it already forms for `*` (and GFMs `~`).
|
|
1389
|
-
marker === "_" ? { inside: true, outside: true } : { inside: false, outside: false }
|
|
1390
|
-
) : insideKind === 1 ? (
|
|
1391
|
-
// Whitespace inside: encode both (letter, whitespace).
|
|
1392
|
-
{ inside: true, outside: true }
|
|
1393
|
-
) : (
|
|
1394
|
-
// Punctuation inside: encode outer (letter)
|
|
1395
|
-
{ inside: false, outside: true }
|
|
1396
|
-
);
|
|
1397
|
-
}
|
|
1398
|
-
if (outsideKind === 1) {
|
|
1399
|
-
return insideKind === void 0 ? (
|
|
1400
|
-
// Letter inside: already forms.
|
|
1401
|
-
{ inside: false, outside: false }
|
|
1402
|
-
) : insideKind === 1 ? (
|
|
1403
|
-
// Whitespace inside: encode both (whitespace).
|
|
1404
|
-
{ inside: true, outside: true }
|
|
1405
|
-
) : (
|
|
1406
|
-
// Punctuation inside: already forms.
|
|
1407
|
-
{ inside: false, outside: false }
|
|
1408
|
-
);
|
|
1409
|
-
}
|
|
1410
|
-
return insideKind === void 0 ? (
|
|
1411
|
-
// Letter inside: already forms.
|
|
1412
|
-
{ inside: false, outside: false }
|
|
1413
|
-
) : insideKind === 1 ? (
|
|
1414
|
-
// Whitespace inside: encode inner (whitespace).
|
|
1415
|
-
{ inside: true, outside: false }
|
|
1416
|
-
) : (
|
|
1417
|
-
// Punctuation inside: already forms.
|
|
1418
|
-
{ inside: false, outside: false }
|
|
1419
|
-
);
|
|
1420
|
-
}
|
|
1421
|
-
emphasis.peek = emphasisPeek;
|
|
1422
|
-
function emphasis(node2, _, state, info) {
|
|
1423
|
-
const marker = checkEmphasis(state);
|
|
1424
|
-
const exit2 = state.enter("emphasis");
|
|
1425
|
-
const tracker = state.createTracker(info);
|
|
1426
|
-
const before = tracker.move(marker);
|
|
1427
|
-
let between = tracker.move(
|
|
1428
|
-
state.containerPhrasing(node2, {
|
|
1429
|
-
after: marker,
|
|
1430
|
-
before,
|
|
1431
|
-
...tracker.current()
|
|
1432
|
-
})
|
|
1433
|
-
);
|
|
1434
|
-
const betweenHead = between.charCodeAt(0);
|
|
1435
|
-
const open = encodeInfo(
|
|
1436
|
-
info.before.charCodeAt(info.before.length - 1),
|
|
1437
|
-
betweenHead,
|
|
1438
|
-
marker
|
|
1439
|
-
);
|
|
1440
|
-
if (open.inside) {
|
|
1441
|
-
between = encodeCharacterReference(betweenHead) + between.slice(1);
|
|
1442
|
-
}
|
|
1443
|
-
const betweenTail = between.charCodeAt(between.length - 1);
|
|
1444
|
-
const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
|
|
1445
|
-
if (close.inside) {
|
|
1446
|
-
between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
|
|
1447
|
-
}
|
|
1448
|
-
const after = tracker.move(marker);
|
|
1449
|
-
exit2();
|
|
1450
|
-
state.attentionEncodeSurroundingInfo = {
|
|
1451
|
-
after: close.outside,
|
|
1452
|
-
before: open.outside
|
|
1453
|
-
};
|
|
1454
|
-
return before + between + after;
|
|
1455
|
-
}
|
|
1456
|
-
function emphasisPeek(_, _1, state) {
|
|
1457
|
-
return state.options.emphasis || "*";
|
|
1458
|
-
}
|
|
1459
|
-
function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
1460
|
-
let reverse;
|
|
1461
|
-
let test;
|
|
1462
|
-
let visitor;
|
|
1463
|
-
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
1464
|
-
test = void 0;
|
|
1465
|
-
visitor = testOrVisitor;
|
|
1466
|
-
reverse = visitorOrReverse;
|
|
1467
|
-
} else {
|
|
1468
|
-
test = testOrVisitor;
|
|
1469
|
-
visitor = visitorOrReverse;
|
|
1470
|
-
reverse = maybeReverse;
|
|
1471
|
-
}
|
|
1472
|
-
visitParents(tree, test, overload, reverse);
|
|
1473
|
-
function overload(node2, parents) {
|
|
1474
|
-
const parent = parents[parents.length - 1];
|
|
1475
|
-
const index = parent ? parent.children.indexOf(node2) : void 0;
|
|
1476
|
-
return visitor(node2, index, parent);
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
const emptyOptions$1 = {};
|
|
1480
|
-
function toString(value, options) {
|
|
1481
|
-
const settings = emptyOptions$1;
|
|
1482
|
-
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
|
|
1483
|
-
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
|
|
1484
|
-
return one(value, includeImageAlt, includeHtml);
|
|
1485
|
-
}
|
|
1486
|
-
function one(value, includeImageAlt, includeHtml) {
|
|
1487
|
-
if (node(value)) {
|
|
1488
|
-
if ("value" in value) {
|
|
1489
|
-
return value.type === "html" && !includeHtml ? "" : value.value;
|
|
1490
|
-
}
|
|
1491
|
-
if (includeImageAlt && "alt" in value && value.alt) {
|
|
1492
|
-
return value.alt;
|
|
1493
|
-
}
|
|
1494
|
-
if ("children" in value) {
|
|
1495
|
-
return all(value.children, includeImageAlt, includeHtml);
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
if (Array.isArray(value)) {
|
|
1499
|
-
return all(value, includeImageAlt, includeHtml);
|
|
1500
|
-
}
|
|
1501
|
-
return "";
|
|
1502
|
-
}
|
|
1503
|
-
function all(values, includeImageAlt, includeHtml) {
|
|
1504
|
-
const result = [];
|
|
1505
|
-
let index = -1;
|
|
1506
|
-
while (++index < values.length) {
|
|
1507
|
-
result[index] = one(values[index], includeImageAlt, includeHtml);
|
|
1508
|
-
}
|
|
1509
|
-
return result.join("");
|
|
1510
|
-
}
|
|
1511
|
-
function node(value) {
|
|
1512
|
-
return Boolean(value && typeof value === "object");
|
|
1513
|
-
}
|
|
1514
|
-
function formatHeadingAsSetext(node2, state) {
|
|
1515
|
-
let literalWithBreak = false;
|
|
1516
|
-
visit(node2, function(node3) {
|
|
1517
|
-
if ("value" in node3 && /\r?\n|\r/.test(node3.value) || node3.type === "break") {
|
|
1518
|
-
literalWithBreak = true;
|
|
1519
|
-
return EXIT;
|
|
1520
|
-
}
|
|
1521
|
-
});
|
|
1522
|
-
return Boolean(
|
|
1523
|
-
(!node2.depth || node2.depth < 3) && toString(node2) && (state.options.setext || literalWithBreak)
|
|
1524
|
-
);
|
|
1525
|
-
}
|
|
1526
|
-
function heading(node2, _, state, info) {
|
|
1527
|
-
const rank = Math.max(Math.min(6, node2.depth || 1), 1);
|
|
1528
|
-
const tracker = state.createTracker(info);
|
|
1529
|
-
if (formatHeadingAsSetext(node2, state)) {
|
|
1530
|
-
const exit3 = state.enter("headingSetext");
|
|
1531
|
-
const subexit2 = state.enter("phrasing");
|
|
1532
|
-
const value2 = state.containerPhrasing(node2, {
|
|
1533
|
-
...tracker.current(),
|
|
1534
|
-
before: "\n",
|
|
1535
|
-
after: "\n"
|
|
1536
|
-
});
|
|
1537
|
-
subexit2();
|
|
1538
|
-
exit3();
|
|
1539
|
-
return value2 + "\n" + (rank === 1 ? "=" : "-").repeat(
|
|
1540
|
-
// The whole size…
|
|
1541
|
-
value2.length - // Minus the position of the character after the last EOL (or
|
|
1542
|
-
// 0 if there is none)…
|
|
1543
|
-
(Math.max(value2.lastIndexOf("\r"), value2.lastIndexOf("\n")) + 1)
|
|
1544
|
-
);
|
|
1545
|
-
}
|
|
1546
|
-
const sequence = "#".repeat(rank);
|
|
1547
|
-
const exit2 = state.enter("headingAtx");
|
|
1548
|
-
const subexit = state.enter("phrasing");
|
|
1549
|
-
tracker.move(sequence + " ");
|
|
1550
|
-
let value = state.containerPhrasing(node2, {
|
|
1551
|
-
before: "# ",
|
|
1552
|
-
after: "\n",
|
|
1553
|
-
...tracker.current()
|
|
1554
|
-
});
|
|
1555
|
-
if (/^[\t ]/.test(value)) {
|
|
1556
|
-
value = encodeCharacterReference(value.charCodeAt(0)) + value.slice(1);
|
|
1557
|
-
}
|
|
1558
|
-
value = value ? sequence + " " + value : sequence;
|
|
1559
|
-
if (state.options.closeAtx) {
|
|
1560
|
-
value += " " + sequence;
|
|
1561
|
-
}
|
|
1562
|
-
subexit();
|
|
1563
|
-
exit2();
|
|
1564
|
-
return value;
|
|
1565
|
-
}
|
|
1566
|
-
html.peek = htmlPeek;
|
|
1567
|
-
function html(node2) {
|
|
1568
|
-
return node2.value || "";
|
|
1569
|
-
}
|
|
1570
|
-
function htmlPeek() {
|
|
1571
|
-
return "<";
|
|
1572
|
-
}
|
|
1573
|
-
image.peek = imagePeek;
|
|
1574
|
-
function image(node2, _, state, info) {
|
|
1575
|
-
const quote = checkQuote(state);
|
|
1576
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1577
|
-
const exit2 = state.enter("image");
|
|
1578
|
-
let subexit = state.enter("label");
|
|
1579
|
-
const tracker = state.createTracker(info);
|
|
1580
|
-
let value = tracker.move("![");
|
|
1581
|
-
value += tracker.move(
|
|
1582
|
-
state.safe(node2.alt, { before: value, after: "]", ...tracker.current() })
|
|
1583
|
-
);
|
|
1584
|
-
value += tracker.move("](");
|
|
1585
|
-
subexit();
|
|
1586
|
-
if (
|
|
1587
|
-
// If there’s no url but there is a title…
|
|
1588
|
-
!node2.url && node2.title || // If there are control characters or whitespace.
|
|
1589
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1590
|
-
) {
|
|
1591
|
-
subexit = state.enter("destinationLiteral");
|
|
1592
|
-
value += tracker.move("<");
|
|
1593
|
-
value += tracker.move(
|
|
1594
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1595
|
-
);
|
|
1596
|
-
value += tracker.move(">");
|
|
1597
|
-
} else {
|
|
1598
|
-
subexit = state.enter("destinationRaw");
|
|
1599
|
-
value += tracker.move(
|
|
1600
|
-
state.safe(node2.url, {
|
|
1601
|
-
before: value,
|
|
1602
|
-
after: node2.title ? " " : ")",
|
|
1603
|
-
...tracker.current()
|
|
1604
|
-
})
|
|
1605
|
-
);
|
|
1606
|
-
}
|
|
1607
|
-
subexit();
|
|
1608
|
-
if (node2.title) {
|
|
1609
|
-
subexit = state.enter(`title${suffix}`);
|
|
1610
|
-
value += tracker.move(" " + quote);
|
|
1611
|
-
value += tracker.move(
|
|
1612
|
-
state.safe(node2.title, {
|
|
1613
|
-
before: value,
|
|
1614
|
-
after: quote,
|
|
1615
|
-
...tracker.current()
|
|
1616
|
-
})
|
|
1617
|
-
);
|
|
1618
|
-
value += tracker.move(quote);
|
|
1619
|
-
subexit();
|
|
1620
|
-
}
|
|
1621
|
-
value += tracker.move(")");
|
|
1622
|
-
exit2();
|
|
1623
|
-
return value;
|
|
1624
|
-
}
|
|
1625
|
-
function imagePeek() {
|
|
1626
|
-
return "!";
|
|
1627
|
-
}
|
|
1628
|
-
imageReference.peek = imageReferencePeek;
|
|
1629
|
-
function imageReference(node2, _, state, info) {
|
|
1630
|
-
const type = node2.referenceType;
|
|
1631
|
-
const exit2 = state.enter("imageReference");
|
|
1632
|
-
let subexit = state.enter("label");
|
|
1633
|
-
const tracker = state.createTracker(info);
|
|
1634
|
-
let value = tracker.move("![");
|
|
1635
|
-
const alt = state.safe(node2.alt, {
|
|
1636
|
-
before: value,
|
|
1637
|
-
after: "]",
|
|
1638
|
-
...tracker.current()
|
|
1639
|
-
});
|
|
1640
|
-
value += tracker.move(alt + "][");
|
|
1641
|
-
subexit();
|
|
1642
|
-
const stack = state.stack;
|
|
1643
|
-
state.stack = [];
|
|
1644
|
-
subexit = state.enter("reference");
|
|
1645
|
-
const reference = state.safe(state.associationId(node2), {
|
|
1646
|
-
before: value,
|
|
1647
|
-
after: "]",
|
|
1648
|
-
...tracker.current()
|
|
1649
|
-
});
|
|
1650
|
-
subexit();
|
|
1651
|
-
state.stack = stack;
|
|
1652
|
-
exit2();
|
|
1653
|
-
if (type === "full" || !alt || alt !== reference) {
|
|
1654
|
-
value += tracker.move(reference + "]");
|
|
1655
|
-
} else if (type === "shortcut") {
|
|
1656
|
-
value = value.slice(0, -1);
|
|
1657
|
-
} else {
|
|
1658
|
-
value += tracker.move("]");
|
|
1659
|
-
}
|
|
1660
|
-
return value;
|
|
1661
|
-
}
|
|
1662
|
-
function imageReferencePeek() {
|
|
1663
|
-
return "!";
|
|
1664
|
-
}
|
|
1665
|
-
inlineCode.peek = inlineCodePeek;
|
|
1666
|
-
function inlineCode(node2, _, state) {
|
|
1667
|
-
let value = node2.value || "";
|
|
1668
|
-
let sequence = "`";
|
|
1669
|
-
let index = -1;
|
|
1670
|
-
while (new RegExp("(^|[^`])" + sequence + "([^`]|$)").test(value)) {
|
|
1671
|
-
sequence += "`";
|
|
1672
|
-
}
|
|
1673
|
-
if (/[^ \r\n]/.test(value) && (/^[ \r\n]/.test(value) && /[ \r\n]$/.test(value) || /^`|`$/.test(value))) {
|
|
1674
|
-
value = " " + value + " ";
|
|
1675
|
-
}
|
|
1676
|
-
while (++index < state.unsafe.length) {
|
|
1677
|
-
const pattern = state.unsafe[index];
|
|
1678
|
-
const expression = state.compilePattern(pattern);
|
|
1679
|
-
let match;
|
|
1680
|
-
if (!pattern.atBreak) continue;
|
|
1681
|
-
while (match = expression.exec(value)) {
|
|
1682
|
-
let position = match.index;
|
|
1683
|
-
if (value.charCodeAt(position) === 10 && value.charCodeAt(position - 1) === 13) {
|
|
1684
|
-
position--;
|
|
1685
|
-
}
|
|
1686
|
-
value = value.slice(0, position) + " " + value.slice(match.index + 1);
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
return sequence + value + sequence;
|
|
1690
|
-
}
|
|
1691
|
-
function inlineCodePeek() {
|
|
1692
|
-
return "`";
|
|
1693
|
-
}
|
|
1694
|
-
function formatLinkAsAutolink(node2, state) {
|
|
1695
|
-
const raw = toString(node2);
|
|
1696
|
-
return Boolean(
|
|
1697
|
-
!state.options.resourceLink && // If there’s a url…
|
|
1698
|
-
node2.url && // And there’s a no title…
|
|
1699
|
-
!node2.title && // And the content of `node` is a single text node…
|
|
1700
|
-
node2.children && node2.children.length === 1 && node2.children[0].type === "text" && // And if the url is the same as the content…
|
|
1701
|
-
(raw === node2.url || "mailto:" + raw === node2.url) && // And that starts w/ a protocol…
|
|
1702
|
-
/^[a-z][a-z+.-]+:/i.test(node2.url) && // And that doesn’t contain ASCII control codes (character escapes and
|
|
1703
|
-
// references don’t work), space, or angle brackets…
|
|
1704
|
-
!/[\0- <>\u007F]/.test(node2.url)
|
|
1705
|
-
);
|
|
1706
|
-
}
|
|
1707
|
-
link.peek = linkPeek;
|
|
1708
|
-
function link(node2, _, state, info) {
|
|
1709
|
-
const quote = checkQuote(state);
|
|
1710
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1711
|
-
const tracker = state.createTracker(info);
|
|
1712
|
-
let exit2;
|
|
1713
|
-
let subexit;
|
|
1714
|
-
if (formatLinkAsAutolink(node2, state)) {
|
|
1715
|
-
const stack = state.stack;
|
|
1716
|
-
state.stack = [];
|
|
1717
|
-
exit2 = state.enter("autolink");
|
|
1718
|
-
let value2 = tracker.move("<");
|
|
1719
|
-
value2 += tracker.move(
|
|
1720
|
-
state.containerPhrasing(node2, {
|
|
1721
|
-
before: value2,
|
|
1722
|
-
after: ">",
|
|
1723
|
-
...tracker.current()
|
|
1724
|
-
})
|
|
1725
|
-
);
|
|
1726
|
-
value2 += tracker.move(">");
|
|
1727
|
-
exit2();
|
|
1728
|
-
state.stack = stack;
|
|
1729
|
-
return value2;
|
|
1730
|
-
}
|
|
1731
|
-
exit2 = state.enter("link");
|
|
1732
|
-
subexit = state.enter("label");
|
|
1733
|
-
let value = tracker.move("[");
|
|
1734
|
-
value += tracker.move(
|
|
1735
|
-
state.containerPhrasing(node2, {
|
|
1736
|
-
before: value,
|
|
1737
|
-
after: "](",
|
|
1738
|
-
...tracker.current()
|
|
1739
|
-
})
|
|
1740
|
-
);
|
|
1741
|
-
value += tracker.move("](");
|
|
1742
|
-
subexit();
|
|
1743
|
-
if (
|
|
1744
|
-
// If there’s no url but there is a title…
|
|
1745
|
-
!node2.url && node2.title || // If there are control characters or whitespace.
|
|
1746
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1747
|
-
) {
|
|
1748
|
-
subexit = state.enter("destinationLiteral");
|
|
1749
|
-
value += tracker.move("<");
|
|
1750
|
-
value += tracker.move(
|
|
1751
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1752
|
-
);
|
|
1753
|
-
value += tracker.move(">");
|
|
1754
|
-
} else {
|
|
1755
|
-
subexit = state.enter("destinationRaw");
|
|
1756
|
-
value += tracker.move(
|
|
1757
|
-
state.safe(node2.url, {
|
|
1758
|
-
before: value,
|
|
1759
|
-
after: node2.title ? " " : ")",
|
|
1760
|
-
...tracker.current()
|
|
1761
|
-
})
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1764
|
-
subexit();
|
|
1765
|
-
if (node2.title) {
|
|
1766
|
-
subexit = state.enter(`title${suffix}`);
|
|
1767
|
-
value += tracker.move(" " + quote);
|
|
1768
|
-
value += tracker.move(
|
|
1769
|
-
state.safe(node2.title, {
|
|
1770
|
-
before: value,
|
|
1771
|
-
after: quote,
|
|
1772
|
-
...tracker.current()
|
|
1773
|
-
})
|
|
1774
|
-
);
|
|
1775
|
-
value += tracker.move(quote);
|
|
1776
|
-
subexit();
|
|
1777
|
-
}
|
|
1778
|
-
value += tracker.move(")");
|
|
1779
|
-
exit2();
|
|
1780
|
-
return value;
|
|
1781
|
-
}
|
|
1782
|
-
function linkPeek(node2, _, state) {
|
|
1783
|
-
return formatLinkAsAutolink(node2, state) ? "<" : "[";
|
|
1784
|
-
}
|
|
1785
|
-
linkReference.peek = linkReferencePeek;
|
|
1786
|
-
function linkReference(node2, _, state, info) {
|
|
1787
|
-
const type = node2.referenceType;
|
|
1788
|
-
const exit2 = state.enter("linkReference");
|
|
1789
|
-
let subexit = state.enter("label");
|
|
1790
|
-
const tracker = state.createTracker(info);
|
|
1791
|
-
let value = tracker.move("[");
|
|
1792
|
-
const text2 = state.containerPhrasing(node2, {
|
|
1793
|
-
before: value,
|
|
1794
|
-
after: "]",
|
|
1795
|
-
...tracker.current()
|
|
1796
|
-
});
|
|
1797
|
-
value += tracker.move(text2 + "][");
|
|
1798
|
-
subexit();
|
|
1799
|
-
const stack = state.stack;
|
|
1800
|
-
state.stack = [];
|
|
1801
|
-
subexit = state.enter("reference");
|
|
1802
|
-
const reference = state.safe(state.associationId(node2), {
|
|
1803
|
-
before: value,
|
|
1804
|
-
after: "]",
|
|
1805
|
-
...tracker.current()
|
|
1806
|
-
});
|
|
1807
|
-
subexit();
|
|
1808
|
-
state.stack = stack;
|
|
1809
|
-
exit2();
|
|
1810
|
-
if (type === "full" || !text2 || text2 !== reference) {
|
|
1811
|
-
value += tracker.move(reference + "]");
|
|
1812
|
-
} else if (type === "shortcut") {
|
|
1813
|
-
value = value.slice(0, -1);
|
|
1814
|
-
} else {
|
|
1815
|
-
value += tracker.move("]");
|
|
1816
|
-
}
|
|
1817
|
-
return value;
|
|
1818
|
-
}
|
|
1819
|
-
function linkReferencePeek() {
|
|
1820
|
-
return "[";
|
|
1821
|
-
}
|
|
1822
|
-
function checkBullet(state) {
|
|
1823
|
-
const marker = state.options.bullet || "*";
|
|
1824
|
-
if (marker !== "*" && marker !== "+" && marker !== "-") {
|
|
1825
|
-
throw new Error(
|
|
1826
|
-
"Cannot serialize items with `" + marker + "` for `options.bullet`, expected `*`, `+`, or `-`"
|
|
1827
|
-
);
|
|
1828
|
-
}
|
|
1829
|
-
return marker;
|
|
1830
|
-
}
|
|
1831
|
-
function checkBulletOther(state) {
|
|
1832
|
-
const bullet = checkBullet(state);
|
|
1833
|
-
const bulletOther = state.options.bulletOther;
|
|
1834
|
-
if (!bulletOther) {
|
|
1835
|
-
return bullet === "*" ? "-" : "*";
|
|
1836
|
-
}
|
|
1837
|
-
if (bulletOther !== "*" && bulletOther !== "+" && bulletOther !== "-") {
|
|
1838
|
-
throw new Error(
|
|
1839
|
-
"Cannot serialize items with `" + bulletOther + "` for `options.bulletOther`, expected `*`, `+`, or `-`"
|
|
1840
|
-
);
|
|
1841
|
-
}
|
|
1842
|
-
if (bulletOther === bullet) {
|
|
1843
|
-
throw new Error(
|
|
1844
|
-
"Expected `bullet` (`" + bullet + "`) and `bulletOther` (`" + bulletOther + "`) to be different"
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
return bulletOther;
|
|
1848
|
-
}
|
|
1849
|
-
function checkBulletOrdered(state) {
|
|
1850
|
-
const marker = state.options.bulletOrdered || ".";
|
|
1851
|
-
if (marker !== "." && marker !== ")") {
|
|
1852
|
-
throw new Error(
|
|
1853
|
-
"Cannot serialize items with `" + marker + "` for `options.bulletOrdered`, expected `.` or `)`"
|
|
1854
|
-
);
|
|
1855
|
-
}
|
|
1856
|
-
return marker;
|
|
1857
|
-
}
|
|
1858
|
-
function checkRule(state) {
|
|
1859
|
-
const marker = state.options.rule || "*";
|
|
1860
|
-
if (marker !== "*" && marker !== "-" && marker !== "_") {
|
|
1861
|
-
throw new Error(
|
|
1862
|
-
"Cannot serialize rules with `" + marker + "` for `options.rule`, expected `*`, `-`, or `_`"
|
|
1863
|
-
);
|
|
1864
|
-
}
|
|
1865
|
-
return marker;
|
|
1866
|
-
}
|
|
1867
|
-
function list(node2, parent, state, info) {
|
|
1868
|
-
const exit2 = state.enter("list");
|
|
1869
|
-
const bulletCurrent = state.bulletCurrent;
|
|
1870
|
-
let bullet = node2.ordered ? checkBulletOrdered(state) : checkBullet(state);
|
|
1871
|
-
const bulletOther = node2.ordered ? bullet === "." ? ")" : "." : checkBulletOther(state);
|
|
1872
|
-
let useDifferentMarker = parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false;
|
|
1873
|
-
if (!node2.ordered) {
|
|
1874
|
-
const firstListItem = node2.children ? node2.children[0] : void 0;
|
|
1875
|
-
if (
|
|
1876
|
-
// Bullet could be used as a thematic break marker:
|
|
1877
|
-
(bullet === "*" || bullet === "-") && // Empty first list item:
|
|
1878
|
-
firstListItem && (!firstListItem.children || !firstListItem.children[0]) && // Directly in two other list items:
|
|
1879
|
-
state.stack[state.stack.length - 1] === "list" && state.stack[state.stack.length - 2] === "listItem" && state.stack[state.stack.length - 3] === "list" && state.stack[state.stack.length - 4] === "listItem" && // That are each the first child.
|
|
1880
|
-
state.indexStack[state.indexStack.length - 1] === 0 && state.indexStack[state.indexStack.length - 2] === 0 && state.indexStack[state.indexStack.length - 3] === 0
|
|
1881
|
-
) {
|
|
1882
|
-
useDifferentMarker = true;
|
|
1883
|
-
}
|
|
1884
|
-
if (checkRule(state) === bullet && firstListItem) {
|
|
1885
|
-
let index = -1;
|
|
1886
|
-
while (++index < node2.children.length) {
|
|
1887
|
-
const item = node2.children[index];
|
|
1888
|
-
if (item && item.type === "listItem" && item.children && item.children[0] && item.children[0].type === "thematicBreak") {
|
|
1889
|
-
useDifferentMarker = true;
|
|
1890
|
-
break;
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
if (useDifferentMarker) {
|
|
1896
|
-
bullet = bulletOther;
|
|
1897
|
-
}
|
|
1898
|
-
state.bulletCurrent = bullet;
|
|
1899
|
-
const value = state.containerFlow(node2, info);
|
|
1900
|
-
state.bulletLastUsed = bullet;
|
|
1901
|
-
state.bulletCurrent = bulletCurrent;
|
|
1902
|
-
exit2();
|
|
1903
|
-
return value;
|
|
1904
|
-
}
|
|
1905
|
-
function checkListItemIndent(state) {
|
|
1906
|
-
const style = state.options.listItemIndent || "one";
|
|
1907
|
-
if (style !== "tab" && style !== "one" && style !== "mixed") {
|
|
1908
|
-
throw new Error(
|
|
1909
|
-
"Cannot serialize items with `" + style + "` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`"
|
|
1910
|
-
);
|
|
1911
|
-
}
|
|
1912
|
-
return style;
|
|
1913
|
-
}
|
|
1914
|
-
function listItem(node2, parent, state, info) {
|
|
1915
|
-
const listItemIndent = checkListItemIndent(state);
|
|
1916
|
-
let bullet = state.bulletCurrent || checkBullet(state);
|
|
1917
|
-
if (parent && parent.type === "list" && parent.ordered) {
|
|
1918
|
-
bullet = (typeof parent.start === "number" && parent.start > -1 ? parent.start : 1) + (state.options.incrementListMarker === false ? 0 : parent.children.indexOf(node2)) + bullet;
|
|
1919
|
-
}
|
|
1920
|
-
let size = bullet.length + 1;
|
|
1921
|
-
if (listItemIndent === "tab" || listItemIndent === "mixed" && (parent && parent.type === "list" && parent.spread || node2.spread)) {
|
|
1922
|
-
size = Math.ceil(size / 4) * 4;
|
|
1923
|
-
}
|
|
1924
|
-
const tracker = state.createTracker(info);
|
|
1925
|
-
tracker.move(bullet + " ".repeat(size - bullet.length));
|
|
1926
|
-
tracker.shift(size);
|
|
1927
|
-
const exit2 = state.enter("listItem");
|
|
1928
|
-
const value = state.indentLines(
|
|
1929
|
-
state.containerFlow(node2, tracker.current()),
|
|
1930
|
-
map2
|
|
1931
|
-
);
|
|
1932
|
-
exit2();
|
|
1933
|
-
return value;
|
|
1934
|
-
function map2(line, index, blank) {
|
|
1935
|
-
if (index) {
|
|
1936
|
-
return (blank ? "" : " ".repeat(size)) + line;
|
|
1937
|
-
}
|
|
1938
|
-
return (blank ? bullet : bullet + " ".repeat(size - bullet.length)) + line;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
function paragraph(node2, _, state, info) {
|
|
1942
|
-
const exit2 = state.enter("paragraph");
|
|
1943
|
-
const subexit = state.enter("phrasing");
|
|
1944
|
-
const value = state.containerPhrasing(node2, info);
|
|
1945
|
-
subexit();
|
|
1946
|
-
exit2();
|
|
1947
|
-
return value;
|
|
1948
|
-
}
|
|
1949
|
-
const phrasing = (
|
|
1950
|
-
/** @type {(node?: unknown) => node is Exclude<PhrasingContent, Html>} */
|
|
1951
|
-
convert([
|
|
1952
|
-
"break",
|
|
1953
|
-
"delete",
|
|
1954
|
-
"emphasis",
|
|
1955
|
-
// To do: next major: removed since footnotes were added to GFM.
|
|
1956
|
-
"footnote",
|
|
1957
|
-
"footnoteReference",
|
|
1958
|
-
"image",
|
|
1959
|
-
"imageReference",
|
|
1960
|
-
"inlineCode",
|
|
1961
|
-
// Enabled by `mdast-util-math`:
|
|
1962
|
-
"inlineMath",
|
|
1963
|
-
"link",
|
|
1964
|
-
"linkReference",
|
|
1965
|
-
// Enabled by `mdast-util-mdx`:
|
|
1966
|
-
"mdxJsxTextElement",
|
|
1967
|
-
// Enabled by `mdast-util-mdx`:
|
|
1968
|
-
"mdxTextExpression",
|
|
1969
|
-
"strong",
|
|
1970
|
-
"text",
|
|
1971
|
-
// Enabled by `mdast-util-directive`:
|
|
1972
|
-
"textDirective"
|
|
1973
|
-
])
|
|
1974
|
-
);
|
|
1975
|
-
function root(node2, _, state, info) {
|
|
1976
|
-
const hasPhrasing = node2.children.some(function(d) {
|
|
1977
|
-
return phrasing(d);
|
|
1978
|
-
});
|
|
1979
|
-
const container = hasPhrasing ? state.containerPhrasing : state.containerFlow;
|
|
1980
|
-
return container.call(state, node2, info);
|
|
1981
|
-
}
|
|
1982
|
-
function checkStrong(state) {
|
|
1983
|
-
const marker = state.options.strong || "*";
|
|
1984
|
-
if (marker !== "*" && marker !== "_") {
|
|
1985
|
-
throw new Error(
|
|
1986
|
-
"Cannot serialize strong with `" + marker + "` for `options.strong`, expected `*`, or `_`"
|
|
1987
|
-
);
|
|
1988
|
-
}
|
|
1989
|
-
return marker;
|
|
1990
|
-
}
|
|
1991
|
-
strong.peek = strongPeek;
|
|
1992
|
-
function strong(node2, _, state, info) {
|
|
1993
|
-
const marker = checkStrong(state);
|
|
1994
|
-
const exit2 = state.enter("strong");
|
|
1995
|
-
const tracker = state.createTracker(info);
|
|
1996
|
-
const before = tracker.move(marker + marker);
|
|
1997
|
-
let between = tracker.move(
|
|
1998
|
-
state.containerPhrasing(node2, {
|
|
1999
|
-
after: marker,
|
|
2000
|
-
before,
|
|
2001
|
-
...tracker.current()
|
|
2002
|
-
})
|
|
2003
|
-
);
|
|
2004
|
-
const betweenHead = between.charCodeAt(0);
|
|
2005
|
-
const open = encodeInfo(
|
|
2006
|
-
info.before.charCodeAt(info.before.length - 1),
|
|
2007
|
-
betweenHead,
|
|
2008
|
-
marker
|
|
2009
|
-
);
|
|
2010
|
-
if (open.inside) {
|
|
2011
|
-
between = encodeCharacterReference(betweenHead) + between.slice(1);
|
|
2012
|
-
}
|
|
2013
|
-
const betweenTail = between.charCodeAt(between.length - 1);
|
|
2014
|
-
const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
|
|
2015
|
-
if (close.inside) {
|
|
2016
|
-
between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
|
|
2017
|
-
}
|
|
2018
|
-
const after = tracker.move(marker + marker);
|
|
2019
|
-
exit2();
|
|
2020
|
-
state.attentionEncodeSurroundingInfo = {
|
|
2021
|
-
after: close.outside,
|
|
2022
|
-
before: open.outside
|
|
2023
|
-
};
|
|
2024
|
-
return before + between + after;
|
|
2025
|
-
}
|
|
2026
|
-
function strongPeek(_, _1, state) {
|
|
2027
|
-
return state.options.strong || "*";
|
|
2028
|
-
}
|
|
2029
|
-
function text$1(node2, _, state, info) {
|
|
2030
|
-
return state.safe(node2.value, info);
|
|
2031
|
-
}
|
|
2032
|
-
function checkRuleRepetition(state) {
|
|
2033
|
-
const repetition = state.options.ruleRepetition || 3;
|
|
2034
|
-
if (repetition < 3) {
|
|
2035
|
-
throw new Error(
|
|
2036
|
-
"Cannot serialize rules with repetition `" + repetition + "` for `options.ruleRepetition`, expected `3` or more"
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
return repetition;
|
|
2040
|
-
}
|
|
2041
|
-
function thematicBreak(_, _1, state) {
|
|
2042
|
-
const value = (checkRule(state) + (state.options.ruleSpaces ? " " : "")).repeat(checkRuleRepetition(state));
|
|
2043
|
-
return state.options.ruleSpaces ? value.slice(0, -1) : value;
|
|
2044
|
-
}
|
|
2045
|
-
const handle = {
|
|
2046
|
-
blockquote,
|
|
2047
|
-
break: hardBreak,
|
|
2048
|
-
code: code$1,
|
|
2049
|
-
definition,
|
|
2050
|
-
emphasis,
|
|
2051
|
-
hardBreak,
|
|
2052
|
-
heading,
|
|
2053
|
-
html,
|
|
2054
|
-
image,
|
|
2055
|
-
imageReference,
|
|
2056
|
-
inlineCode,
|
|
2057
|
-
link,
|
|
2058
|
-
linkReference,
|
|
2059
|
-
list,
|
|
2060
|
-
listItem,
|
|
2061
|
-
paragraph,
|
|
2062
|
-
root,
|
|
2063
|
-
strong,
|
|
2064
|
-
text: text$1,
|
|
2065
|
-
thematicBreak
|
|
2066
|
-
};
|
|
2067
|
-
function gfmTableFromMarkdown() {
|
|
2068
|
-
return {
|
|
2069
|
-
enter: {
|
|
2070
|
-
table: enterTable,
|
|
2071
|
-
tableData: enterCell,
|
|
2072
|
-
tableHeader: enterCell,
|
|
2073
|
-
tableRow: enterRow
|
|
2074
|
-
},
|
|
2075
|
-
exit: {
|
|
2076
|
-
codeText: exitCodeText,
|
|
2077
|
-
table: exitTable,
|
|
2078
|
-
tableData: exit,
|
|
2079
|
-
tableHeader: exit,
|
|
2080
|
-
tableRow: exit
|
|
2081
|
-
}
|
|
2082
|
-
};
|
|
2083
|
-
}
|
|
2084
|
-
function enterTable(token) {
|
|
2085
|
-
const align = token._align;
|
|
2086
|
-
this.enter(
|
|
2087
|
-
{
|
|
2088
|
-
type: "table",
|
|
2089
|
-
align: align.map(function(d) {
|
|
2090
|
-
return d === "none" ? null : d;
|
|
2091
|
-
}),
|
|
2092
|
-
children: []
|
|
2093
|
-
},
|
|
2094
|
-
token
|
|
2095
|
-
);
|
|
2096
|
-
this.data.inTable = true;
|
|
2097
|
-
}
|
|
2098
|
-
function exitTable(token) {
|
|
2099
|
-
this.exit(token);
|
|
2100
|
-
this.data.inTable = void 0;
|
|
2101
|
-
}
|
|
2102
|
-
function enterRow(token) {
|
|
2103
|
-
this.enter({ type: "tableRow", children: [] }, token);
|
|
2104
|
-
}
|
|
2105
|
-
function exit(token) {
|
|
2106
|
-
this.exit(token);
|
|
2107
|
-
}
|
|
2108
|
-
function enterCell(token) {
|
|
2109
|
-
this.enter({ type: "tableCell", children: [] }, token);
|
|
2110
|
-
}
|
|
2111
|
-
function exitCodeText(token) {
|
|
2112
|
-
let value = this.resume();
|
|
2113
|
-
if (this.data.inTable) {
|
|
2114
|
-
value = value.replace(/\\([\\|])/g, replace);
|
|
2115
|
-
}
|
|
2116
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
2117
|
-
ok$1(node2.type === "inlineCode");
|
|
2118
|
-
node2.value = value;
|
|
2119
|
-
this.exit(token);
|
|
2120
|
-
}
|
|
2121
|
-
function replace($0, $1) {
|
|
2122
|
-
return $1 === "|" ? $1 : $0;
|
|
2123
|
-
}
|
|
2124
|
-
function gfmTableToMarkdown(options) {
|
|
2125
|
-
const settings = options || {};
|
|
2126
|
-
const padding = settings.tableCellPadding;
|
|
2127
|
-
const alignDelimiters = settings.tablePipeAlign;
|
|
2128
|
-
const stringLength = settings.stringLength;
|
|
2129
|
-
const around = padding ? " " : "|";
|
|
2130
|
-
return {
|
|
2131
|
-
unsafe: [
|
|
2132
|
-
{ character: "\r", inConstruct: "tableCell" },
|
|
2133
|
-
{ character: "\n", inConstruct: "tableCell" },
|
|
2134
|
-
// A pipe, when followed by a tab or space (padding), or a dash or colon
|
|
2135
|
-
// (unpadded delimiter row), could result in a table.
|
|
2136
|
-
{ atBreak: true, character: "|", after: "[ :-]" },
|
|
2137
|
-
// A pipe in a cell must be encoded.
|
|
2138
|
-
{ character: "|", inConstruct: "tableCell" },
|
|
2139
|
-
// A colon must be followed by a dash, in which case it could start a
|
|
2140
|
-
// delimiter row.
|
|
2141
|
-
{ atBreak: true, character: ":", after: "-" },
|
|
2142
|
-
// A delimiter row can also start with a dash, when followed by more
|
|
2143
|
-
// dashes, a colon, or a pipe.
|
|
2144
|
-
// This is a stricter version than the built in check for lists, thematic
|
|
2145
|
-
// breaks, and setex heading underlines though:
|
|
2146
|
-
// <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
|
|
2147
|
-
{ atBreak: true, character: "-", after: "[:|-]" }
|
|
2148
|
-
],
|
|
2149
|
-
handlers: {
|
|
2150
|
-
inlineCode: inlineCodeWithTable,
|
|
2151
|
-
table: handleTable,
|
|
2152
|
-
tableCell: handleTableCell,
|
|
2153
|
-
tableRow: handleTableRow
|
|
2154
|
-
}
|
|
2155
|
-
};
|
|
2156
|
-
function handleTable(node2, _, state, info) {
|
|
2157
|
-
return serializeData(handleTableAsData(node2, state, info), node2.align);
|
|
2158
|
-
}
|
|
2159
|
-
function handleTableRow(node2, _, state, info) {
|
|
2160
|
-
const row = handleTableRowAsData(node2, state, info);
|
|
2161
|
-
const value = serializeData([row]);
|
|
2162
|
-
return value.slice(0, value.indexOf("\n"));
|
|
2163
|
-
}
|
|
2164
|
-
function handleTableCell(node2, _, state, info) {
|
|
2165
|
-
const exit2 = state.enter("tableCell");
|
|
2166
|
-
const subexit = state.enter("phrasing");
|
|
2167
|
-
const value = state.containerPhrasing(node2, {
|
|
2168
|
-
...info,
|
|
2169
|
-
before: around,
|
|
2170
|
-
after: around
|
|
2171
|
-
});
|
|
2172
|
-
subexit();
|
|
2173
|
-
exit2();
|
|
2174
|
-
return value;
|
|
2175
|
-
}
|
|
2176
|
-
function serializeData(matrix, align) {
|
|
2177
|
-
return markdownTable(matrix, {
|
|
2178
|
-
align,
|
|
2179
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2180
|
-
alignDelimiters,
|
|
2181
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2182
|
-
padding,
|
|
2183
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2184
|
-
stringLength
|
|
2185
|
-
});
|
|
2186
|
-
}
|
|
2187
|
-
function handleTableAsData(node2, state, info) {
|
|
2188
|
-
const children = node2.children;
|
|
2189
|
-
let index = -1;
|
|
2190
|
-
const result = [];
|
|
2191
|
-
const subexit = state.enter("table");
|
|
2192
|
-
while (++index < children.length) {
|
|
2193
|
-
result[index] = handleTableRowAsData(children[index], state, info);
|
|
2194
|
-
}
|
|
2195
|
-
subexit();
|
|
2196
|
-
return result;
|
|
2197
|
-
}
|
|
2198
|
-
function handleTableRowAsData(node2, state, info) {
|
|
2199
|
-
const children = node2.children;
|
|
2200
|
-
let index = -1;
|
|
2201
|
-
const result = [];
|
|
2202
|
-
const subexit = state.enter("tableRow");
|
|
2203
|
-
while (++index < children.length) {
|
|
2204
|
-
result[index] = handleTableCell(children[index], node2, state, info);
|
|
2205
|
-
}
|
|
2206
|
-
subexit();
|
|
2207
|
-
return result;
|
|
2208
|
-
}
|
|
2209
|
-
function inlineCodeWithTable(node2, parent, state) {
|
|
2210
|
-
let value = handle.inlineCode(node2, parent, state);
|
|
2211
|
-
if (state.stack.includes("tableCell")) {
|
|
2212
|
-
value = value.replace(/\|/g, "\\$&");
|
|
2213
|
-
}
|
|
2214
|
-
return value;
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
function gfmTaskListItemFromMarkdown() {
|
|
2218
|
-
return {
|
|
2219
|
-
exit: {
|
|
2220
|
-
taskListCheckValueChecked: exitCheck,
|
|
2221
|
-
taskListCheckValueUnchecked: exitCheck,
|
|
2222
|
-
paragraph: exitParagraphWithTaskListItem
|
|
2223
|
-
}
|
|
2224
|
-
};
|
|
2225
|
-
}
|
|
2226
|
-
function gfmTaskListItemToMarkdown() {
|
|
2227
|
-
return {
|
|
2228
|
-
unsafe: [{ atBreak: true, character: "-", after: "[:|-]" }],
|
|
2229
|
-
handlers: { listItem: listItemWithTaskListItem }
|
|
2230
|
-
};
|
|
2231
|
-
}
|
|
2232
|
-
function exitCheck(token) {
|
|
2233
|
-
const node2 = this.stack[this.stack.length - 2];
|
|
2234
|
-
ok$1(node2.type === "listItem");
|
|
2235
|
-
node2.checked = token.type === "taskListCheckValueChecked";
|
|
2236
|
-
}
|
|
2237
|
-
function exitParagraphWithTaskListItem(token) {
|
|
2238
|
-
const parent = this.stack[this.stack.length - 2];
|
|
2239
|
-
if (parent && parent.type === "listItem" && typeof parent.checked === "boolean") {
|
|
2240
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
2241
|
-
ok$1(node2.type === "paragraph");
|
|
2242
|
-
const head = node2.children[0];
|
|
2243
|
-
if (head && head.type === "text") {
|
|
2244
|
-
const siblings = parent.children;
|
|
2245
|
-
let index = -1;
|
|
2246
|
-
let firstParaghraph;
|
|
2247
|
-
while (++index < siblings.length) {
|
|
2248
|
-
const sibling = siblings[index];
|
|
2249
|
-
if (sibling.type === "paragraph") {
|
|
2250
|
-
firstParaghraph = sibling;
|
|
2251
|
-
break;
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
if (firstParaghraph === node2) {
|
|
2255
|
-
head.value = head.value.slice(1);
|
|
2256
|
-
if (head.value.length === 0) {
|
|
2257
|
-
node2.children.shift();
|
|
2258
|
-
} else if (node2.position && head.position && typeof head.position.start.offset === "number") {
|
|
2259
|
-
head.position.start.column++;
|
|
2260
|
-
head.position.start.offset++;
|
|
2261
|
-
node2.position.start = Object.assign({}, head.position.start);
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
this.exit(token);
|
|
2267
|
-
}
|
|
2268
|
-
function listItemWithTaskListItem(node2, parent, state, info) {
|
|
2269
|
-
const head = node2.children[0];
|
|
2270
|
-
const checkable = typeof node2.checked === "boolean" && head && head.type === "paragraph";
|
|
2271
|
-
const checkbox = "[" + (node2.checked ? "x" : " ") + "] ";
|
|
2272
|
-
const tracker = state.createTracker(info);
|
|
2273
|
-
if (checkable) {
|
|
2274
|
-
tracker.move(checkbox);
|
|
2275
|
-
}
|
|
2276
|
-
let value = handle.listItem(node2, parent, state, {
|
|
2277
|
-
...info,
|
|
2278
|
-
...tracker.current()
|
|
2279
|
-
});
|
|
2280
|
-
if (checkable) {
|
|
2281
|
-
value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check);
|
|
2282
|
-
}
|
|
2283
|
-
return value;
|
|
2284
|
-
function check($0) {
|
|
2285
|
-
return $0 + checkbox;
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
function gfmFromMarkdown() {
|
|
2289
|
-
return [
|
|
2290
|
-
gfmAutolinkLiteralFromMarkdown(),
|
|
2291
|
-
gfmFootnoteFromMarkdown(),
|
|
2292
|
-
gfmStrikethroughFromMarkdown(),
|
|
2293
|
-
gfmTableFromMarkdown(),
|
|
2294
|
-
gfmTaskListItemFromMarkdown()
|
|
2295
|
-
];
|
|
2296
|
-
}
|
|
2297
|
-
function gfmToMarkdown(options) {
|
|
2298
|
-
return {
|
|
2299
|
-
extensions: [
|
|
2300
|
-
gfmAutolinkLiteralToMarkdown(),
|
|
2301
|
-
gfmFootnoteToMarkdown(options),
|
|
2302
|
-
gfmStrikethroughToMarkdown(),
|
|
2303
|
-
gfmTableToMarkdown(options),
|
|
2304
|
-
gfmTaskListItemToMarkdown()
|
|
2305
|
-
]
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
function splice(list2, start, remove, items) {
|
|
2309
|
-
const end = list2.length;
|
|
2310
|
-
let chunkStart = 0;
|
|
2311
|
-
let parameters;
|
|
2312
|
-
if (start < 0) {
|
|
2313
|
-
start = -start > end ? 0 : end + start;
|
|
2314
|
-
} else {
|
|
2315
|
-
start = start > end ? end : start;
|
|
2316
|
-
}
|
|
2317
|
-
remove = remove > 0 ? remove : 0;
|
|
2318
|
-
if (items.length < 1e4) {
|
|
2319
|
-
parameters = Array.from(items);
|
|
2320
|
-
parameters.unshift(start, remove);
|
|
2321
|
-
list2.splice(...parameters);
|
|
2322
|
-
} else {
|
|
2323
|
-
if (remove) list2.splice(start, remove);
|
|
2324
|
-
while (chunkStart < items.length) {
|
|
2325
|
-
parameters = items.slice(chunkStart, chunkStart + 1e4);
|
|
2326
|
-
parameters.unshift(start, 0);
|
|
2327
|
-
list2.splice(...parameters);
|
|
2328
|
-
chunkStart += 1e4;
|
|
2329
|
-
start += 1e4;
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
const hasOwnProperty = {}.hasOwnProperty;
|
|
2334
|
-
function combineExtensions(extensions) {
|
|
2335
|
-
const all2 = {};
|
|
2336
|
-
let index = -1;
|
|
2337
|
-
while (++index < extensions.length) {
|
|
2338
|
-
syntaxExtension(all2, extensions[index]);
|
|
2339
|
-
}
|
|
2340
|
-
return all2;
|
|
2341
|
-
}
|
|
2342
|
-
function syntaxExtension(all2, extension) {
|
|
2343
|
-
let hook;
|
|
2344
|
-
for (hook in extension) {
|
|
2345
|
-
const maybe = hasOwnProperty.call(all2, hook) ? all2[hook] : void 0;
|
|
2346
|
-
const left = maybe || (all2[hook] = {});
|
|
2347
|
-
const right = extension[hook];
|
|
2348
|
-
let code2;
|
|
2349
|
-
if (right) {
|
|
2350
|
-
for (code2 in right) {
|
|
2351
|
-
if (!hasOwnProperty.call(left, code2)) left[code2] = [];
|
|
2352
|
-
const value = right[code2];
|
|
2353
|
-
constructs(
|
|
2354
|
-
// @ts-expect-error Looks like a list.
|
|
2355
|
-
left[code2],
|
|
2356
|
-
Array.isArray(value) ? value : value ? [value] : []
|
|
2357
|
-
);
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
function constructs(existing, list2) {
|
|
2363
|
-
let index = -1;
|
|
2364
|
-
const before = [];
|
|
2365
|
-
while (++index < list2.length) {
|
|
2366
|
-
(list2[index].add === "after" ? existing : before).push(list2[index]);
|
|
2367
|
-
}
|
|
2368
|
-
splice(existing, 0, 0, before);
|
|
2369
|
-
}
|
|
2370
|
-
const wwwPrefix = {
|
|
2371
|
-
tokenize: tokenizeWwwPrefix,
|
|
2372
|
-
partial: true
|
|
2373
|
-
};
|
|
2374
|
-
const domain = {
|
|
2375
|
-
tokenize: tokenizeDomain,
|
|
2376
|
-
partial: true
|
|
2377
|
-
};
|
|
2378
|
-
const path = {
|
|
2379
|
-
tokenize: tokenizePath,
|
|
2380
|
-
partial: true
|
|
2381
|
-
};
|
|
2382
|
-
const trail = {
|
|
2383
|
-
tokenize: tokenizeTrail,
|
|
2384
|
-
partial: true
|
|
2385
|
-
};
|
|
2386
|
-
const emailDomainDotTrail = {
|
|
2387
|
-
tokenize: tokenizeEmailDomainDotTrail,
|
|
2388
|
-
partial: true
|
|
2389
|
-
};
|
|
2390
|
-
const wwwAutolink = {
|
|
2391
|
-
name: "wwwAutolink",
|
|
2392
|
-
tokenize: tokenizeWwwAutolink,
|
|
2393
|
-
previous: previousWww
|
|
2394
|
-
};
|
|
2395
|
-
const protocolAutolink = {
|
|
2396
|
-
name: "protocolAutolink",
|
|
2397
|
-
tokenize: tokenizeProtocolAutolink,
|
|
2398
|
-
previous: previousProtocol
|
|
2399
|
-
};
|
|
2400
|
-
const emailAutolink = {
|
|
2401
|
-
name: "emailAutolink",
|
|
2402
|
-
tokenize: tokenizeEmailAutolink,
|
|
2403
|
-
previous: previousEmail
|
|
2404
|
-
};
|
|
2405
|
-
const text = {};
|
|
2406
|
-
function gfmAutolinkLiteral() {
|
|
2407
|
-
return {
|
|
2408
|
-
text
|
|
2409
|
-
};
|
|
2410
|
-
}
|
|
2411
|
-
let code = 48;
|
|
2412
|
-
while (code < 123) {
|
|
2413
|
-
text[code] = emailAutolink;
|
|
2414
|
-
code++;
|
|
2415
|
-
if (code === 58) code = 65;
|
|
2416
|
-
else if (code === 91) code = 97;
|
|
2417
|
-
}
|
|
2418
|
-
text[43] = emailAutolink;
|
|
2419
|
-
text[45] = emailAutolink;
|
|
2420
|
-
text[46] = emailAutolink;
|
|
2421
|
-
text[95] = emailAutolink;
|
|
2422
|
-
text[72] = [emailAutolink, protocolAutolink];
|
|
2423
|
-
text[104] = [emailAutolink, protocolAutolink];
|
|
2424
|
-
text[87] = [emailAutolink, wwwAutolink];
|
|
2425
|
-
text[119] = [emailAutolink, wwwAutolink];
|
|
2426
|
-
function tokenizeEmailAutolink(effects, ok2, nok) {
|
|
2427
|
-
const self = this;
|
|
2428
|
-
let dot;
|
|
2429
|
-
let data;
|
|
2430
|
-
return start;
|
|
2431
|
-
function start(code2) {
|
|
2432
|
-
if (!gfmAtext(code2) || !previousEmail.call(self, self.previous) || previousUnbalanced(self.events)) {
|
|
2433
|
-
return nok(code2);
|
|
2434
|
-
}
|
|
2435
|
-
effects.enter("literalAutolink");
|
|
2436
|
-
effects.enter("literalAutolinkEmail");
|
|
2437
|
-
return atext(code2);
|
|
2438
|
-
}
|
|
2439
|
-
function atext(code2) {
|
|
2440
|
-
if (gfmAtext(code2)) {
|
|
2441
|
-
effects.consume(code2);
|
|
2442
|
-
return atext;
|
|
2443
|
-
}
|
|
2444
|
-
if (code2 === 64) {
|
|
2445
|
-
effects.consume(code2);
|
|
2446
|
-
return emailDomain;
|
|
2447
|
-
}
|
|
2448
|
-
return nok(code2);
|
|
2449
|
-
}
|
|
2450
|
-
function emailDomain(code2) {
|
|
2451
|
-
if (code2 === 46) {
|
|
2452
|
-
return effects.check(emailDomainDotTrail, emailDomainAfter, emailDomainDot)(code2);
|
|
2453
|
-
}
|
|
2454
|
-
if (code2 === 45 || code2 === 95 || asciiAlphanumeric(code2)) {
|
|
2455
|
-
data = true;
|
|
2456
|
-
effects.consume(code2);
|
|
2457
|
-
return emailDomain;
|
|
2458
|
-
}
|
|
2459
|
-
return emailDomainAfter(code2);
|
|
2460
|
-
}
|
|
2461
|
-
function emailDomainDot(code2) {
|
|
2462
|
-
effects.consume(code2);
|
|
2463
|
-
dot = true;
|
|
2464
|
-
return emailDomain;
|
|
2465
|
-
}
|
|
2466
|
-
function emailDomainAfter(code2) {
|
|
2467
|
-
if (data && dot && asciiAlpha(self.previous)) {
|
|
2468
|
-
effects.exit("literalAutolinkEmail");
|
|
2469
|
-
effects.exit("literalAutolink");
|
|
2470
|
-
return ok2(code2);
|
|
2471
|
-
}
|
|
2472
|
-
return nok(code2);
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
function tokenizeWwwAutolink(effects, ok2, nok) {
|
|
2476
|
-
const self = this;
|
|
2477
|
-
return wwwStart;
|
|
2478
|
-
function wwwStart(code2) {
|
|
2479
|
-
if (code2 !== 87 && code2 !== 119 || !previousWww.call(self, self.previous) || previousUnbalanced(self.events)) {
|
|
2480
|
-
return nok(code2);
|
|
2481
|
-
}
|
|
2482
|
-
effects.enter("literalAutolink");
|
|
2483
|
-
effects.enter("literalAutolinkWww");
|
|
2484
|
-
return effects.check(wwwPrefix, effects.attempt(domain, effects.attempt(path, wwwAfter), nok), nok)(code2);
|
|
2485
|
-
}
|
|
2486
|
-
function wwwAfter(code2) {
|
|
2487
|
-
effects.exit("literalAutolinkWww");
|
|
2488
|
-
effects.exit("literalAutolink");
|
|
2489
|
-
return ok2(code2);
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
function tokenizeProtocolAutolink(effects, ok2, nok) {
|
|
2493
|
-
const self = this;
|
|
2494
|
-
let buffer = "";
|
|
2495
|
-
let seen = false;
|
|
2496
|
-
return protocolStart;
|
|
2497
|
-
function protocolStart(code2) {
|
|
2498
|
-
if ((code2 === 72 || code2 === 104) && previousProtocol.call(self, self.previous) && !previousUnbalanced(self.events)) {
|
|
2499
|
-
effects.enter("literalAutolink");
|
|
2500
|
-
effects.enter("literalAutolinkHttp");
|
|
2501
|
-
buffer += String.fromCodePoint(code2);
|
|
2502
|
-
effects.consume(code2);
|
|
2503
|
-
return protocolPrefixInside;
|
|
2504
|
-
}
|
|
2505
|
-
return nok(code2);
|
|
2506
|
-
}
|
|
2507
|
-
function protocolPrefixInside(code2) {
|
|
2508
|
-
if (asciiAlpha(code2) && buffer.length < 5) {
|
|
2509
|
-
buffer += String.fromCodePoint(code2);
|
|
2510
|
-
effects.consume(code2);
|
|
2511
|
-
return protocolPrefixInside;
|
|
2512
|
-
}
|
|
2513
|
-
if (code2 === 58) {
|
|
2514
|
-
const protocol = buffer.toLowerCase();
|
|
2515
|
-
if (protocol === "http" || protocol === "https") {
|
|
2516
|
-
effects.consume(code2);
|
|
2517
|
-
return protocolSlashesInside;
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
return nok(code2);
|
|
2521
|
-
}
|
|
2522
|
-
function protocolSlashesInside(code2) {
|
|
2523
|
-
if (code2 === 47) {
|
|
2524
|
-
effects.consume(code2);
|
|
2525
|
-
if (seen) {
|
|
2526
|
-
return afterProtocol;
|
|
2527
|
-
}
|
|
2528
|
-
seen = true;
|
|
2529
|
-
return protocolSlashesInside;
|
|
2530
|
-
}
|
|
2531
|
-
return nok(code2);
|
|
2532
|
-
}
|
|
2533
|
-
function afterProtocol(code2) {
|
|
2534
|
-
return code2 === null || asciiControl(code2) || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || unicodePunctuation(code2) ? nok(code2) : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code2);
|
|
2535
|
-
}
|
|
2536
|
-
function protocolAfter(code2) {
|
|
2537
|
-
effects.exit("literalAutolinkHttp");
|
|
2538
|
-
effects.exit("literalAutolink");
|
|
2539
|
-
return ok2(code2);
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
function tokenizeWwwPrefix(effects, ok2, nok) {
|
|
2543
|
-
let size = 0;
|
|
2544
|
-
return wwwPrefixInside;
|
|
2545
|
-
function wwwPrefixInside(code2) {
|
|
2546
|
-
if ((code2 === 87 || code2 === 119) && size < 3) {
|
|
2547
|
-
size++;
|
|
2548
|
-
effects.consume(code2);
|
|
2549
|
-
return wwwPrefixInside;
|
|
2550
|
-
}
|
|
2551
|
-
if (code2 === 46 && size === 3) {
|
|
2552
|
-
effects.consume(code2);
|
|
2553
|
-
return wwwPrefixAfter;
|
|
2554
|
-
}
|
|
2555
|
-
return nok(code2);
|
|
2556
|
-
}
|
|
2557
|
-
function wwwPrefixAfter(code2) {
|
|
2558
|
-
return code2 === null ? nok(code2) : ok2(code2);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
function tokenizeDomain(effects, ok2, nok) {
|
|
2562
|
-
let underscoreInLastSegment;
|
|
2563
|
-
let underscoreInLastLastSegment;
|
|
2564
|
-
let seen;
|
|
2565
|
-
return domainInside;
|
|
2566
|
-
function domainInside(code2) {
|
|
2567
|
-
if (code2 === 46 || code2 === 95) {
|
|
2568
|
-
return effects.check(trail, domainAfter, domainAtPunctuation)(code2);
|
|
2569
|
-
}
|
|
2570
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || code2 !== 45 && unicodePunctuation(code2)) {
|
|
2571
|
-
return domainAfter(code2);
|
|
2572
|
-
}
|
|
2573
|
-
seen = true;
|
|
2574
|
-
effects.consume(code2);
|
|
2575
|
-
return domainInside;
|
|
2576
|
-
}
|
|
2577
|
-
function domainAtPunctuation(code2) {
|
|
2578
|
-
if (code2 === 95) {
|
|
2579
|
-
underscoreInLastSegment = true;
|
|
2580
|
-
} else {
|
|
2581
|
-
underscoreInLastLastSegment = underscoreInLastSegment;
|
|
2582
|
-
underscoreInLastSegment = void 0;
|
|
2583
|
-
}
|
|
2584
|
-
effects.consume(code2);
|
|
2585
|
-
return domainInside;
|
|
2586
|
-
}
|
|
2587
|
-
function domainAfter(code2) {
|
|
2588
|
-
if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) {
|
|
2589
|
-
return nok(code2);
|
|
2590
|
-
}
|
|
2591
|
-
return ok2(code2);
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
function tokenizePath(effects, ok2) {
|
|
2595
|
-
let sizeOpen = 0;
|
|
2596
|
-
let sizeClose = 0;
|
|
2597
|
-
return pathInside;
|
|
2598
|
-
function pathInside(code2) {
|
|
2599
|
-
if (code2 === 40) {
|
|
2600
|
-
sizeOpen++;
|
|
2601
|
-
effects.consume(code2);
|
|
2602
|
-
return pathInside;
|
|
2603
|
-
}
|
|
2604
|
-
if (code2 === 41 && sizeClose < sizeOpen) {
|
|
2605
|
-
return pathAtPunctuation(code2);
|
|
2606
|
-
}
|
|
2607
|
-
if (code2 === 33 || code2 === 34 || code2 === 38 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 60 || code2 === 63 || code2 === 93 || code2 === 95 || code2 === 126) {
|
|
2608
|
-
return effects.check(trail, ok2, pathAtPunctuation)(code2);
|
|
2609
|
-
}
|
|
2610
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
2611
|
-
return ok2(code2);
|
|
2612
|
-
}
|
|
2613
|
-
effects.consume(code2);
|
|
2614
|
-
return pathInside;
|
|
2615
|
-
}
|
|
2616
|
-
function pathAtPunctuation(code2) {
|
|
2617
|
-
if (code2 === 41) {
|
|
2618
|
-
sizeClose++;
|
|
2619
|
-
}
|
|
2620
|
-
effects.consume(code2);
|
|
2621
|
-
return pathInside;
|
|
2622
|
-
}
|
|
2623
|
-
}
|
|
2624
|
-
function tokenizeTrail(effects, ok2, nok) {
|
|
2625
|
-
return trail2;
|
|
2626
|
-
function trail2(code2) {
|
|
2627
|
-
if (code2 === 33 || code2 === 34 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 63 || code2 === 95 || code2 === 126) {
|
|
2628
|
-
effects.consume(code2);
|
|
2629
|
-
return trail2;
|
|
2630
|
-
}
|
|
2631
|
-
if (code2 === 38) {
|
|
2632
|
-
effects.consume(code2);
|
|
2633
|
-
return trailCharacterReferenceStart;
|
|
2634
|
-
}
|
|
2635
|
-
if (code2 === 93) {
|
|
2636
|
-
effects.consume(code2);
|
|
2637
|
-
return trailBracketAfter;
|
|
2638
|
-
}
|
|
2639
|
-
if (
|
|
2640
|
-
// `<` is an end.
|
|
2641
|
-
code2 === 60 || // So is whitespace.
|
|
2642
|
-
code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)
|
|
2643
|
-
) {
|
|
2644
|
-
return ok2(code2);
|
|
2645
|
-
}
|
|
2646
|
-
return nok(code2);
|
|
2647
|
-
}
|
|
2648
|
-
function trailBracketAfter(code2) {
|
|
2649
|
-
if (code2 === null || code2 === 40 || code2 === 91 || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
2650
|
-
return ok2(code2);
|
|
2651
|
-
}
|
|
2652
|
-
return trail2(code2);
|
|
2653
|
-
}
|
|
2654
|
-
function trailCharacterReferenceStart(code2) {
|
|
2655
|
-
return asciiAlpha(code2) ? trailCharacterReferenceInside(code2) : nok(code2);
|
|
2656
|
-
}
|
|
2657
|
-
function trailCharacterReferenceInside(code2) {
|
|
2658
|
-
if (code2 === 59) {
|
|
2659
|
-
effects.consume(code2);
|
|
2660
|
-
return trail2;
|
|
2661
|
-
}
|
|
2662
|
-
if (asciiAlpha(code2)) {
|
|
2663
|
-
effects.consume(code2);
|
|
2664
|
-
return trailCharacterReferenceInside;
|
|
2665
|
-
}
|
|
2666
|
-
return nok(code2);
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
function tokenizeEmailDomainDotTrail(effects, ok2, nok) {
|
|
2670
|
-
return start;
|
|
2671
|
-
function start(code2) {
|
|
2672
|
-
effects.consume(code2);
|
|
2673
|
-
return after;
|
|
2674
|
-
}
|
|
2675
|
-
function after(code2) {
|
|
2676
|
-
return asciiAlphanumeric(code2) ? nok(code2) : ok2(code2);
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
function previousWww(code2) {
|
|
2680
|
-
return code2 === null || code2 === 40 || code2 === 42 || code2 === 95 || code2 === 91 || code2 === 93 || code2 === 126 || markdownLineEndingOrSpace(code2);
|
|
2681
|
-
}
|
|
2682
|
-
function previousProtocol(code2) {
|
|
2683
|
-
return !asciiAlpha(code2);
|
|
2684
|
-
}
|
|
2685
|
-
function previousEmail(code2) {
|
|
2686
|
-
return !(code2 === 47 || gfmAtext(code2));
|
|
2687
|
-
}
|
|
2688
|
-
function gfmAtext(code2) {
|
|
2689
|
-
return code2 === 43 || code2 === 45 || code2 === 46 || code2 === 95 || asciiAlphanumeric(code2);
|
|
2690
|
-
}
|
|
2691
|
-
function previousUnbalanced(events) {
|
|
2692
|
-
let index = events.length;
|
|
2693
|
-
let result = false;
|
|
2694
|
-
while (index--) {
|
|
2695
|
-
const token = events[index][1];
|
|
2696
|
-
if ((token.type === "labelLink" || token.type === "labelImage") && !token._balanced) {
|
|
2697
|
-
result = true;
|
|
2698
|
-
break;
|
|
2699
|
-
}
|
|
2700
|
-
if (token._gfmAutolinkLiteralWalkedInto) {
|
|
2701
|
-
result = false;
|
|
2702
|
-
break;
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
if (events.length > 0 && !result) {
|
|
2706
|
-
events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true;
|
|
2707
|
-
}
|
|
2708
|
-
return result;
|
|
2709
|
-
}
|
|
2710
|
-
function resolveAll(constructs2, events, context) {
|
|
2711
|
-
const called = [];
|
|
2712
|
-
let index = -1;
|
|
2713
|
-
while (++index < constructs2.length) {
|
|
2714
|
-
const resolve = constructs2[index].resolveAll;
|
|
2715
|
-
if (resolve && !called.includes(resolve)) {
|
|
2716
|
-
events = resolve(events, context);
|
|
2717
|
-
called.push(resolve);
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
return events;
|
|
2721
|
-
}
|
|
2722
|
-
function factorySpace(effects, ok2, type, max) {
|
|
2723
|
-
const limit = max ? max - 1 : Number.POSITIVE_INFINITY;
|
|
2724
|
-
let size = 0;
|
|
2725
|
-
return start;
|
|
2726
|
-
function start(code2) {
|
|
2727
|
-
if (markdownSpace(code2)) {
|
|
2728
|
-
effects.enter(type);
|
|
2729
|
-
return prefix(code2);
|
|
2730
|
-
}
|
|
2731
|
-
return ok2(code2);
|
|
2732
|
-
}
|
|
2733
|
-
function prefix(code2) {
|
|
2734
|
-
if (markdownSpace(code2) && size++ < limit) {
|
|
2735
|
-
effects.consume(code2);
|
|
2736
|
-
return prefix;
|
|
2737
|
-
}
|
|
2738
|
-
effects.exit(type);
|
|
2739
|
-
return ok2(code2);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
const blankLine = {
|
|
2743
|
-
partial: true,
|
|
2744
|
-
tokenize: tokenizeBlankLine
|
|
2745
|
-
};
|
|
2746
|
-
function tokenizeBlankLine(effects, ok2, nok) {
|
|
2747
|
-
return start;
|
|
2748
|
-
function start(code2) {
|
|
2749
|
-
return markdownSpace(code2) ? factorySpace(effects, after, "linePrefix")(code2) : after(code2);
|
|
2750
|
-
}
|
|
2751
|
-
function after(code2) {
|
|
2752
|
-
return code2 === null || markdownLineEnding(code2) ? ok2(code2) : nok(code2);
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
const indent = {
|
|
2756
|
-
tokenize: tokenizeIndent,
|
|
2757
|
-
partial: true
|
|
2758
|
-
};
|
|
2759
|
-
function gfmFootnote() {
|
|
2760
|
-
return {
|
|
2761
|
-
document: {
|
|
2762
|
-
[91]: {
|
|
2763
|
-
name: "gfmFootnoteDefinition",
|
|
2764
|
-
tokenize: tokenizeDefinitionStart,
|
|
2765
|
-
continuation: {
|
|
2766
|
-
tokenize: tokenizeDefinitionContinuation
|
|
2767
|
-
},
|
|
2768
|
-
exit: gfmFootnoteDefinitionEnd
|
|
2769
|
-
}
|
|
2770
|
-
},
|
|
2771
|
-
text: {
|
|
2772
|
-
[91]: {
|
|
2773
|
-
name: "gfmFootnoteCall",
|
|
2774
|
-
tokenize: tokenizeGfmFootnoteCall
|
|
2775
|
-
},
|
|
2776
|
-
[93]: {
|
|
2777
|
-
name: "gfmPotentialFootnoteCall",
|
|
2778
|
-
add: "after",
|
|
2779
|
-
tokenize: tokenizePotentialGfmFootnoteCall,
|
|
2780
|
-
resolveTo: resolveToPotentialGfmFootnoteCall
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
};
|
|
2784
|
-
}
|
|
2785
|
-
function tokenizePotentialGfmFootnoteCall(effects, ok2, nok) {
|
|
2786
|
-
const self = this;
|
|
2787
|
-
let index = self.events.length;
|
|
2788
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2789
|
-
let labelStart;
|
|
2790
|
-
while (index--) {
|
|
2791
|
-
const token = self.events[index][1];
|
|
2792
|
-
if (token.type === "labelImage") {
|
|
2793
|
-
labelStart = token;
|
|
2794
|
-
break;
|
|
2795
|
-
}
|
|
2796
|
-
if (token.type === "gfmFootnoteCall" || token.type === "labelLink" || token.type === "label" || token.type === "image" || token.type === "link") {
|
|
2797
|
-
break;
|
|
2798
|
-
}
|
|
2799
|
-
}
|
|
2800
|
-
return start;
|
|
2801
|
-
function start(code2) {
|
|
2802
|
-
if (!labelStart || !labelStart._balanced) {
|
|
2803
|
-
return nok(code2);
|
|
2804
|
-
}
|
|
2805
|
-
const id = normalizeIdentifier(self.sliceSerialize({
|
|
2806
|
-
start: labelStart.end,
|
|
2807
|
-
end: self.now()
|
|
2808
|
-
}));
|
|
2809
|
-
if (id.codePointAt(0) !== 94 || !defined.includes(id.slice(1))) {
|
|
2810
|
-
return nok(code2);
|
|
2811
|
-
}
|
|
2812
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2813
|
-
effects.consume(code2);
|
|
2814
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2815
|
-
return ok2(code2);
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
function resolveToPotentialGfmFootnoteCall(events, context) {
|
|
2819
|
-
let index = events.length;
|
|
2820
|
-
while (index--) {
|
|
2821
|
-
if (events[index][1].type === "labelImage" && events[index][0] === "enter") {
|
|
2822
|
-
events[index][1];
|
|
2823
|
-
break;
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
events[index + 1][1].type = "data";
|
|
2827
|
-
events[index + 3][1].type = "gfmFootnoteCallLabelMarker";
|
|
2828
|
-
const call = {
|
|
2829
|
-
type: "gfmFootnoteCall",
|
|
2830
|
-
start: Object.assign({}, events[index + 3][1].start),
|
|
2831
|
-
end: Object.assign({}, events[events.length - 1][1].end)
|
|
2832
|
-
};
|
|
2833
|
-
const marker = {
|
|
2834
|
-
type: "gfmFootnoteCallMarker",
|
|
2835
|
-
start: Object.assign({}, events[index + 3][1].end),
|
|
2836
|
-
end: Object.assign({}, events[index + 3][1].end)
|
|
2837
|
-
};
|
|
2838
|
-
marker.end.column++;
|
|
2839
|
-
marker.end.offset++;
|
|
2840
|
-
marker.end._bufferIndex++;
|
|
2841
|
-
const string = {
|
|
2842
|
-
type: "gfmFootnoteCallString",
|
|
2843
|
-
start: Object.assign({}, marker.end),
|
|
2844
|
-
end: Object.assign({}, events[events.length - 1][1].start)
|
|
2845
|
-
};
|
|
2846
|
-
const chunk = {
|
|
2847
|
-
type: "chunkString",
|
|
2848
|
-
contentType: "string",
|
|
2849
|
-
start: Object.assign({}, string.start),
|
|
2850
|
-
end: Object.assign({}, string.end)
|
|
2851
|
-
};
|
|
2852
|
-
const replacement = [
|
|
2853
|
-
// Take the `labelImageMarker` (now `data`, the `!`)
|
|
2854
|
-
events[index + 1],
|
|
2855
|
-
events[index + 2],
|
|
2856
|
-
["enter", call, context],
|
|
2857
|
-
// The `[`
|
|
2858
|
-
events[index + 3],
|
|
2859
|
-
events[index + 4],
|
|
2860
|
-
// The `^`.
|
|
2861
|
-
["enter", marker, context],
|
|
2862
|
-
["exit", marker, context],
|
|
2863
|
-
// Everything in between.
|
|
2864
|
-
["enter", string, context],
|
|
2865
|
-
["enter", chunk, context],
|
|
2866
|
-
["exit", chunk, context],
|
|
2867
|
-
["exit", string, context],
|
|
2868
|
-
// The ending (`]`, properly parsed and labelled).
|
|
2869
|
-
events[events.length - 2],
|
|
2870
|
-
events[events.length - 1],
|
|
2871
|
-
["exit", call, context]
|
|
2872
|
-
];
|
|
2873
|
-
events.splice(index, events.length - index + 1, ...replacement);
|
|
2874
|
-
return events;
|
|
2875
|
-
}
|
|
2876
|
-
function tokenizeGfmFootnoteCall(effects, ok2, nok) {
|
|
2877
|
-
const self = this;
|
|
2878
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2879
|
-
let size = 0;
|
|
2880
|
-
let data;
|
|
2881
|
-
return start;
|
|
2882
|
-
function start(code2) {
|
|
2883
|
-
effects.enter("gfmFootnoteCall");
|
|
2884
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2885
|
-
effects.consume(code2);
|
|
2886
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2887
|
-
return callStart;
|
|
2888
|
-
}
|
|
2889
|
-
function callStart(code2) {
|
|
2890
|
-
if (code2 !== 94) return nok(code2);
|
|
2891
|
-
effects.enter("gfmFootnoteCallMarker");
|
|
2892
|
-
effects.consume(code2);
|
|
2893
|
-
effects.exit("gfmFootnoteCallMarker");
|
|
2894
|
-
effects.enter("gfmFootnoteCallString");
|
|
2895
|
-
effects.enter("chunkString").contentType = "string";
|
|
2896
|
-
return callData;
|
|
2897
|
-
}
|
|
2898
|
-
function callData(code2) {
|
|
2899
|
-
if (
|
|
2900
|
-
// Too long.
|
|
2901
|
-
size > 999 || // Closing brace with nothing.
|
|
2902
|
-
code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
|
|
2903
|
-
// `\n` and `[` not being supported makes sense.
|
|
2904
|
-
code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
|
|
2905
|
-
) {
|
|
2906
|
-
return nok(code2);
|
|
2907
|
-
}
|
|
2908
|
-
if (code2 === 93) {
|
|
2909
|
-
effects.exit("chunkString");
|
|
2910
|
-
const token = effects.exit("gfmFootnoteCallString");
|
|
2911
|
-
if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) {
|
|
2912
|
-
return nok(code2);
|
|
2913
|
-
}
|
|
2914
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2915
|
-
effects.consume(code2);
|
|
2916
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2917
|
-
effects.exit("gfmFootnoteCall");
|
|
2918
|
-
return ok2;
|
|
2919
|
-
}
|
|
2920
|
-
if (!markdownLineEndingOrSpace(code2)) {
|
|
2921
|
-
data = true;
|
|
2922
|
-
}
|
|
2923
|
-
size++;
|
|
2924
|
-
effects.consume(code2);
|
|
2925
|
-
return code2 === 92 ? callEscape : callData;
|
|
2926
|
-
}
|
|
2927
|
-
function callEscape(code2) {
|
|
2928
|
-
if (code2 === 91 || code2 === 92 || code2 === 93) {
|
|
2929
|
-
effects.consume(code2);
|
|
2930
|
-
size++;
|
|
2931
|
-
return callData;
|
|
2932
|
-
}
|
|
2933
|
-
return callData(code2);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
function tokenizeDefinitionStart(effects, ok2, nok) {
|
|
2937
|
-
const self = this;
|
|
2938
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2939
|
-
let identifier;
|
|
2940
|
-
let size = 0;
|
|
2941
|
-
let data;
|
|
2942
|
-
return start;
|
|
2943
|
-
function start(code2) {
|
|
2944
|
-
effects.enter("gfmFootnoteDefinition")._container = true;
|
|
2945
|
-
effects.enter("gfmFootnoteDefinitionLabel");
|
|
2946
|
-
effects.enter("gfmFootnoteDefinitionLabelMarker");
|
|
2947
|
-
effects.consume(code2);
|
|
2948
|
-
effects.exit("gfmFootnoteDefinitionLabelMarker");
|
|
2949
|
-
return labelAtMarker;
|
|
2950
|
-
}
|
|
2951
|
-
function labelAtMarker(code2) {
|
|
2952
|
-
if (code2 === 94) {
|
|
2953
|
-
effects.enter("gfmFootnoteDefinitionMarker");
|
|
2954
|
-
effects.consume(code2);
|
|
2955
|
-
effects.exit("gfmFootnoteDefinitionMarker");
|
|
2956
|
-
effects.enter("gfmFootnoteDefinitionLabelString");
|
|
2957
|
-
effects.enter("chunkString").contentType = "string";
|
|
2958
|
-
return labelInside;
|
|
2959
|
-
}
|
|
2960
|
-
return nok(code2);
|
|
2961
|
-
}
|
|
2962
|
-
function labelInside(code2) {
|
|
2963
|
-
if (
|
|
2964
|
-
// Too long.
|
|
2965
|
-
size > 999 || // Closing brace with nothing.
|
|
2966
|
-
code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
|
|
2967
|
-
// `\n` and `[` not being supported makes sense.
|
|
2968
|
-
code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
|
|
2969
|
-
) {
|
|
2970
|
-
return nok(code2);
|
|
2971
|
-
}
|
|
2972
|
-
if (code2 === 93) {
|
|
2973
|
-
effects.exit("chunkString");
|
|
2974
|
-
const token = effects.exit("gfmFootnoteDefinitionLabelString");
|
|
2975
|
-
identifier = normalizeIdentifier(self.sliceSerialize(token));
|
|
2976
|
-
effects.enter("gfmFootnoteDefinitionLabelMarker");
|
|
2977
|
-
effects.consume(code2);
|
|
2978
|
-
effects.exit("gfmFootnoteDefinitionLabelMarker");
|
|
2979
|
-
effects.exit("gfmFootnoteDefinitionLabel");
|
|
2980
|
-
return labelAfter;
|
|
2981
|
-
}
|
|
2982
|
-
if (!markdownLineEndingOrSpace(code2)) {
|
|
2983
|
-
data = true;
|
|
2984
|
-
}
|
|
2985
|
-
size++;
|
|
2986
|
-
effects.consume(code2);
|
|
2987
|
-
return code2 === 92 ? labelEscape : labelInside;
|
|
2988
|
-
}
|
|
2989
|
-
function labelEscape(code2) {
|
|
2990
|
-
if (code2 === 91 || code2 === 92 || code2 === 93) {
|
|
2991
|
-
effects.consume(code2);
|
|
2992
|
-
size++;
|
|
2993
|
-
return labelInside;
|
|
2994
|
-
}
|
|
2995
|
-
return labelInside(code2);
|
|
2996
|
-
}
|
|
2997
|
-
function labelAfter(code2) {
|
|
2998
|
-
if (code2 === 58) {
|
|
2999
|
-
effects.enter("definitionMarker");
|
|
3000
|
-
effects.consume(code2);
|
|
3001
|
-
effects.exit("definitionMarker");
|
|
3002
|
-
if (!defined.includes(identifier)) {
|
|
3003
|
-
defined.push(identifier);
|
|
3004
|
-
}
|
|
3005
|
-
return factorySpace(effects, whitespaceAfter, "gfmFootnoteDefinitionWhitespace");
|
|
3006
|
-
}
|
|
3007
|
-
return nok(code2);
|
|
3008
|
-
}
|
|
3009
|
-
function whitespaceAfter(code2) {
|
|
3010
|
-
return ok2(code2);
|
|
3011
|
-
}
|
|
3012
|
-
}
|
|
3013
|
-
function tokenizeDefinitionContinuation(effects, ok2, nok) {
|
|
3014
|
-
return effects.check(blankLine, ok2, effects.attempt(indent, ok2, nok));
|
|
3015
|
-
}
|
|
3016
|
-
function gfmFootnoteDefinitionEnd(effects) {
|
|
3017
|
-
effects.exit("gfmFootnoteDefinition");
|
|
3018
|
-
}
|
|
3019
|
-
function tokenizeIndent(effects, ok2, nok) {
|
|
3020
|
-
const self = this;
|
|
3021
|
-
return factorySpace(effects, afterPrefix, "gfmFootnoteDefinitionIndent", 4 + 1);
|
|
3022
|
-
function afterPrefix(code2) {
|
|
3023
|
-
const tail = self.events[self.events.length - 1];
|
|
3024
|
-
return tail && tail[1].type === "gfmFootnoteDefinitionIndent" && tail[2].sliceSerialize(tail[1], true).length === 4 ? ok2(code2) : nok(code2);
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
function gfmStrikethrough(options) {
|
|
3028
|
-
const options_ = options || {};
|
|
3029
|
-
let single = options_.singleTilde;
|
|
3030
|
-
const tokenizer = {
|
|
3031
|
-
name: "strikethrough",
|
|
3032
|
-
tokenize: tokenizeStrikethrough,
|
|
3033
|
-
resolveAll: resolveAllStrikethrough
|
|
3034
|
-
};
|
|
3035
|
-
if (single === null || single === void 0) {
|
|
3036
|
-
single = true;
|
|
3037
|
-
}
|
|
3038
|
-
return {
|
|
3039
|
-
text: {
|
|
3040
|
-
[126]: tokenizer
|
|
3041
|
-
},
|
|
3042
|
-
insideSpan: {
|
|
3043
|
-
null: [tokenizer]
|
|
3044
|
-
},
|
|
3045
|
-
attentionMarkers: {
|
|
3046
|
-
null: [126]
|
|
3047
|
-
}
|
|
3048
|
-
};
|
|
3049
|
-
function resolveAllStrikethrough(events, context) {
|
|
3050
|
-
let index = -1;
|
|
3051
|
-
while (++index < events.length) {
|
|
3052
|
-
if (events[index][0] === "enter" && events[index][1].type === "strikethroughSequenceTemporary" && events[index][1]._close) {
|
|
3053
|
-
let open = index;
|
|
3054
|
-
while (open--) {
|
|
3055
|
-
if (events[open][0] === "exit" && events[open][1].type === "strikethroughSequenceTemporary" && events[open][1]._open && // If the sizes are the same:
|
|
3056
|
-
events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) {
|
|
3057
|
-
events[index][1].type = "strikethroughSequence";
|
|
3058
|
-
events[open][1].type = "strikethroughSequence";
|
|
3059
|
-
const strikethrough = {
|
|
3060
|
-
type: "strikethrough",
|
|
3061
|
-
start: Object.assign({}, events[open][1].start),
|
|
3062
|
-
end: Object.assign({}, events[index][1].end)
|
|
3063
|
-
};
|
|
3064
|
-
const text2 = {
|
|
3065
|
-
type: "strikethroughText",
|
|
3066
|
-
start: Object.assign({}, events[open][1].end),
|
|
3067
|
-
end: Object.assign({}, events[index][1].start)
|
|
3068
|
-
};
|
|
3069
|
-
const nextEvents = [["enter", strikethrough, context], ["enter", events[open][1], context], ["exit", events[open][1], context], ["enter", text2, context]];
|
|
3070
|
-
const insideSpan = context.parser.constructs.insideSpan.null;
|
|
3071
|
-
if (insideSpan) {
|
|
3072
|
-
splice(nextEvents, nextEvents.length, 0, resolveAll(insideSpan, events.slice(open + 1, index), context));
|
|
3073
|
-
}
|
|
3074
|
-
splice(nextEvents, nextEvents.length, 0, [["exit", text2, context], ["enter", events[index][1], context], ["exit", events[index][1], context], ["exit", strikethrough, context]]);
|
|
3075
|
-
splice(events, open - 1, index - open + 3, nextEvents);
|
|
3076
|
-
index = open + nextEvents.length - 2;
|
|
3077
|
-
break;
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
}
|
|
3081
|
-
}
|
|
3082
|
-
index = -1;
|
|
3083
|
-
while (++index < events.length) {
|
|
3084
|
-
if (events[index][1].type === "strikethroughSequenceTemporary") {
|
|
3085
|
-
events[index][1].type = "data";
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
return events;
|
|
3089
|
-
}
|
|
3090
|
-
function tokenizeStrikethrough(effects, ok2, nok) {
|
|
3091
|
-
const previous2 = this.previous;
|
|
3092
|
-
const events = this.events;
|
|
3093
|
-
let size = 0;
|
|
3094
|
-
return start;
|
|
3095
|
-
function start(code2) {
|
|
3096
|
-
if (previous2 === 126 && events[events.length - 1][1].type !== "characterEscape") {
|
|
3097
|
-
return nok(code2);
|
|
3098
|
-
}
|
|
3099
|
-
effects.enter("strikethroughSequenceTemporary");
|
|
3100
|
-
return more(code2);
|
|
3101
|
-
}
|
|
3102
|
-
function more(code2) {
|
|
3103
|
-
const before = classifyCharacter(previous2);
|
|
3104
|
-
if (code2 === 126) {
|
|
3105
|
-
if (size > 1) return nok(code2);
|
|
3106
|
-
effects.consume(code2);
|
|
3107
|
-
size++;
|
|
3108
|
-
return more;
|
|
3109
|
-
}
|
|
3110
|
-
if (size < 2 && !single) return nok(code2);
|
|
3111
|
-
const token = effects.exit("strikethroughSequenceTemporary");
|
|
3112
|
-
const after = classifyCharacter(code2);
|
|
3113
|
-
token._open = !after || after === 2 && Boolean(before);
|
|
3114
|
-
token._close = !before || before === 2 && Boolean(after);
|
|
3115
|
-
return ok2(code2);
|
|
3116
|
-
}
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
|
-
class EditMap {
|
|
3120
|
-
/**
|
|
3121
|
-
* Create a new edit map.
|
|
3122
|
-
*/
|
|
3123
|
-
constructor() {
|
|
3124
|
-
this.map = [];
|
|
3125
|
-
}
|
|
3126
|
-
/**
|
|
3127
|
-
* Create an edit: a remove and/or add at a certain place.
|
|
3128
|
-
*
|
|
3129
|
-
* @param {number} index
|
|
3130
|
-
* @param {number} remove
|
|
3131
|
-
* @param {Array<Event>} add
|
|
3132
|
-
* @returns {undefined}
|
|
3133
|
-
*/
|
|
3134
|
-
add(index, remove, add) {
|
|
3135
|
-
addImplementation(this, index, remove, add);
|
|
3136
|
-
}
|
|
3137
|
-
// To do: add this when moving to `micromark`.
|
|
3138
|
-
// /**
|
|
3139
|
-
// * Create an edit: but insert `add` before existing additions.
|
|
3140
|
-
// *
|
|
3141
|
-
// * @param {number} index
|
|
3142
|
-
// * @param {number} remove
|
|
3143
|
-
// * @param {Array<Event>} add
|
|
3144
|
-
// * @returns {undefined}
|
|
3145
|
-
// */
|
|
3146
|
-
// addBefore(index, remove, add) {
|
|
3147
|
-
// addImplementation(this, index, remove, add, true)
|
|
3148
|
-
// }
|
|
3149
|
-
/**
|
|
3150
|
-
* Done, change the events.
|
|
3151
|
-
*
|
|
3152
|
-
* @param {Array<Event>} events
|
|
3153
|
-
* @returns {undefined}
|
|
3154
|
-
*/
|
|
3155
|
-
consume(events) {
|
|
3156
|
-
this.map.sort(function(a, b) {
|
|
3157
|
-
return a[0] - b[0];
|
|
3158
|
-
});
|
|
3159
|
-
if (this.map.length === 0) {
|
|
3160
|
-
return;
|
|
3161
|
-
}
|
|
3162
|
-
let index = this.map.length;
|
|
3163
|
-
const vecs = [];
|
|
3164
|
-
while (index > 0) {
|
|
3165
|
-
index -= 1;
|
|
3166
|
-
vecs.push(events.slice(this.map[index][0] + this.map[index][1]), this.map[index][2]);
|
|
3167
|
-
events.length = this.map[index][0];
|
|
3168
|
-
}
|
|
3169
|
-
vecs.push(events.slice());
|
|
3170
|
-
events.length = 0;
|
|
3171
|
-
let slice = vecs.pop();
|
|
3172
|
-
while (slice) {
|
|
3173
|
-
for (const element of slice) {
|
|
3174
|
-
events.push(element);
|
|
3175
|
-
}
|
|
3176
|
-
slice = vecs.pop();
|
|
3177
|
-
}
|
|
3178
|
-
this.map.length = 0;
|
|
3179
|
-
}
|
|
3180
|
-
}
|
|
3181
|
-
function addImplementation(editMap, at, remove, add) {
|
|
3182
|
-
let index = 0;
|
|
3183
|
-
if (remove === 0 && add.length === 0) {
|
|
3184
|
-
return;
|
|
3185
|
-
}
|
|
3186
|
-
while (index < editMap.map.length) {
|
|
3187
|
-
if (editMap.map[index][0] === at) {
|
|
3188
|
-
editMap.map[index][1] += remove;
|
|
3189
|
-
editMap.map[index][2].push(...add);
|
|
3190
|
-
return;
|
|
3191
|
-
}
|
|
3192
|
-
index += 1;
|
|
3193
|
-
}
|
|
3194
|
-
editMap.map.push([at, remove, add]);
|
|
3195
|
-
}
|
|
3196
|
-
function gfmTableAlign(events, index) {
|
|
3197
|
-
let inDelimiterRow = false;
|
|
3198
|
-
const align = [];
|
|
3199
|
-
while (index < events.length) {
|
|
3200
|
-
const event = events[index];
|
|
3201
|
-
if (inDelimiterRow) {
|
|
3202
|
-
if (event[0] === "enter") {
|
|
3203
|
-
if (event[1].type === "tableContent") {
|
|
3204
|
-
align.push(events[index + 1][1].type === "tableDelimiterMarker" ? "left" : "none");
|
|
3205
|
-
}
|
|
3206
|
-
} else if (event[1].type === "tableContent") {
|
|
3207
|
-
if (events[index - 1][1].type === "tableDelimiterMarker") {
|
|
3208
|
-
const alignIndex = align.length - 1;
|
|
3209
|
-
align[alignIndex] = align[alignIndex] === "left" ? "center" : "right";
|
|
3210
|
-
}
|
|
3211
|
-
} else if (event[1].type === "tableDelimiterRow") {
|
|
3212
|
-
break;
|
|
3213
|
-
}
|
|
3214
|
-
} else if (event[0] === "enter" && event[1].type === "tableDelimiterRow") {
|
|
3215
|
-
inDelimiterRow = true;
|
|
3216
|
-
}
|
|
3217
|
-
index += 1;
|
|
3218
|
-
}
|
|
3219
|
-
return align;
|
|
3220
|
-
}
|
|
3221
|
-
function gfmTable() {
|
|
3222
|
-
return {
|
|
3223
|
-
flow: {
|
|
3224
|
-
null: {
|
|
3225
|
-
name: "table",
|
|
3226
|
-
tokenize: tokenizeTable,
|
|
3227
|
-
resolveAll: resolveTable
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
};
|
|
3231
|
-
}
|
|
3232
|
-
function tokenizeTable(effects, ok2, nok) {
|
|
3233
|
-
const self = this;
|
|
3234
|
-
let size = 0;
|
|
3235
|
-
let sizeB = 0;
|
|
3236
|
-
let seen;
|
|
3237
|
-
return start;
|
|
3238
|
-
function start(code2) {
|
|
3239
|
-
let index = self.events.length - 1;
|
|
3240
|
-
while (index > -1) {
|
|
3241
|
-
const type = self.events[index][1].type;
|
|
3242
|
-
if (type === "lineEnding" || // Note: markdown-rs uses `whitespace` instead of `linePrefix`
|
|
3243
|
-
type === "linePrefix") index--;
|
|
3244
|
-
else break;
|
|
3245
|
-
}
|
|
3246
|
-
const tail = index > -1 ? self.events[index][1].type : null;
|
|
3247
|
-
const next = tail === "tableHead" || tail === "tableRow" ? bodyRowStart : headRowBefore;
|
|
3248
|
-
if (next === bodyRowStart && self.parser.lazy[self.now().line]) {
|
|
3249
|
-
return nok(code2);
|
|
3250
|
-
}
|
|
3251
|
-
return next(code2);
|
|
3252
|
-
}
|
|
3253
|
-
function headRowBefore(code2) {
|
|
3254
|
-
effects.enter("tableHead");
|
|
3255
|
-
effects.enter("tableRow");
|
|
3256
|
-
return headRowStart(code2);
|
|
3257
|
-
}
|
|
3258
|
-
function headRowStart(code2) {
|
|
3259
|
-
if (code2 === 124) {
|
|
3260
|
-
return headRowBreak(code2);
|
|
3261
|
-
}
|
|
3262
|
-
seen = true;
|
|
3263
|
-
sizeB += 1;
|
|
3264
|
-
return headRowBreak(code2);
|
|
3265
|
-
}
|
|
3266
|
-
function headRowBreak(code2) {
|
|
3267
|
-
if (code2 === null) {
|
|
3268
|
-
return nok(code2);
|
|
3269
|
-
}
|
|
3270
|
-
if (markdownLineEnding(code2)) {
|
|
3271
|
-
if (sizeB > 1) {
|
|
3272
|
-
sizeB = 0;
|
|
3273
|
-
self.interrupt = true;
|
|
3274
|
-
effects.exit("tableRow");
|
|
3275
|
-
effects.enter("lineEnding");
|
|
3276
|
-
effects.consume(code2);
|
|
3277
|
-
effects.exit("lineEnding");
|
|
3278
|
-
return headDelimiterStart;
|
|
3279
|
-
}
|
|
3280
|
-
return nok(code2);
|
|
3281
|
-
}
|
|
3282
|
-
if (markdownSpace(code2)) {
|
|
3283
|
-
return factorySpace(effects, headRowBreak, "whitespace")(code2);
|
|
3284
|
-
}
|
|
3285
|
-
sizeB += 1;
|
|
3286
|
-
if (seen) {
|
|
3287
|
-
seen = false;
|
|
3288
|
-
size += 1;
|
|
3289
|
-
}
|
|
3290
|
-
if (code2 === 124) {
|
|
3291
|
-
effects.enter("tableCellDivider");
|
|
3292
|
-
effects.consume(code2);
|
|
3293
|
-
effects.exit("tableCellDivider");
|
|
3294
|
-
seen = true;
|
|
3295
|
-
return headRowBreak;
|
|
3296
|
-
}
|
|
3297
|
-
effects.enter("data");
|
|
3298
|
-
return headRowData(code2);
|
|
3299
|
-
}
|
|
3300
|
-
function headRowData(code2) {
|
|
3301
|
-
if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
|
|
3302
|
-
effects.exit("data");
|
|
3303
|
-
return headRowBreak(code2);
|
|
3304
|
-
}
|
|
3305
|
-
effects.consume(code2);
|
|
3306
|
-
return code2 === 92 ? headRowEscape : headRowData;
|
|
3307
|
-
}
|
|
3308
|
-
function headRowEscape(code2) {
|
|
3309
|
-
if (code2 === 92 || code2 === 124) {
|
|
3310
|
-
effects.consume(code2);
|
|
3311
|
-
return headRowData;
|
|
3312
|
-
}
|
|
3313
|
-
return headRowData(code2);
|
|
3314
|
-
}
|
|
3315
|
-
function headDelimiterStart(code2) {
|
|
3316
|
-
self.interrupt = false;
|
|
3317
|
-
if (self.parser.lazy[self.now().line]) {
|
|
3318
|
-
return nok(code2);
|
|
3319
|
-
}
|
|
3320
|
-
effects.enter("tableDelimiterRow");
|
|
3321
|
-
seen = false;
|
|
3322
|
-
if (markdownSpace(code2)) {
|
|
3323
|
-
return factorySpace(effects, headDelimiterBefore, "linePrefix", self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4)(code2);
|
|
3324
|
-
}
|
|
3325
|
-
return headDelimiterBefore(code2);
|
|
3326
|
-
}
|
|
3327
|
-
function headDelimiterBefore(code2) {
|
|
3328
|
-
if (code2 === 45 || code2 === 58) {
|
|
3329
|
-
return headDelimiterValueBefore(code2);
|
|
3330
|
-
}
|
|
3331
|
-
if (code2 === 124) {
|
|
3332
|
-
seen = true;
|
|
3333
|
-
effects.enter("tableCellDivider");
|
|
3334
|
-
effects.consume(code2);
|
|
3335
|
-
effects.exit("tableCellDivider");
|
|
3336
|
-
return headDelimiterCellBefore;
|
|
3337
|
-
}
|
|
3338
|
-
return headDelimiterNok(code2);
|
|
3339
|
-
}
|
|
3340
|
-
function headDelimiterCellBefore(code2) {
|
|
3341
|
-
if (markdownSpace(code2)) {
|
|
3342
|
-
return factorySpace(effects, headDelimiterValueBefore, "whitespace")(code2);
|
|
3343
|
-
}
|
|
3344
|
-
return headDelimiterValueBefore(code2);
|
|
3345
|
-
}
|
|
3346
|
-
function headDelimiterValueBefore(code2) {
|
|
3347
|
-
if (code2 === 58) {
|
|
3348
|
-
sizeB += 1;
|
|
3349
|
-
seen = true;
|
|
3350
|
-
effects.enter("tableDelimiterMarker");
|
|
3351
|
-
effects.consume(code2);
|
|
3352
|
-
effects.exit("tableDelimiterMarker");
|
|
3353
|
-
return headDelimiterLeftAlignmentAfter;
|
|
3354
|
-
}
|
|
3355
|
-
if (code2 === 45) {
|
|
3356
|
-
sizeB += 1;
|
|
3357
|
-
return headDelimiterLeftAlignmentAfter(code2);
|
|
3358
|
-
}
|
|
3359
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3360
|
-
return headDelimiterCellAfter(code2);
|
|
3361
|
-
}
|
|
3362
|
-
return headDelimiterNok(code2);
|
|
3363
|
-
}
|
|
3364
|
-
function headDelimiterLeftAlignmentAfter(code2) {
|
|
3365
|
-
if (code2 === 45) {
|
|
3366
|
-
effects.enter("tableDelimiterFiller");
|
|
3367
|
-
return headDelimiterFiller(code2);
|
|
3368
|
-
}
|
|
3369
|
-
return headDelimiterNok(code2);
|
|
3370
|
-
}
|
|
3371
|
-
function headDelimiterFiller(code2) {
|
|
3372
|
-
if (code2 === 45) {
|
|
3373
|
-
effects.consume(code2);
|
|
3374
|
-
return headDelimiterFiller;
|
|
3375
|
-
}
|
|
3376
|
-
if (code2 === 58) {
|
|
3377
|
-
seen = true;
|
|
3378
|
-
effects.exit("tableDelimiterFiller");
|
|
3379
|
-
effects.enter("tableDelimiterMarker");
|
|
3380
|
-
effects.consume(code2);
|
|
3381
|
-
effects.exit("tableDelimiterMarker");
|
|
3382
|
-
return headDelimiterRightAlignmentAfter;
|
|
3383
|
-
}
|
|
3384
|
-
effects.exit("tableDelimiterFiller");
|
|
3385
|
-
return headDelimiterRightAlignmentAfter(code2);
|
|
3386
|
-
}
|
|
3387
|
-
function headDelimiterRightAlignmentAfter(code2) {
|
|
3388
|
-
if (markdownSpace(code2)) {
|
|
3389
|
-
return factorySpace(effects, headDelimiterCellAfter, "whitespace")(code2);
|
|
3390
|
-
}
|
|
3391
|
-
return headDelimiterCellAfter(code2);
|
|
3392
|
-
}
|
|
3393
|
-
function headDelimiterCellAfter(code2) {
|
|
3394
|
-
if (code2 === 124) {
|
|
3395
|
-
return headDelimiterBefore(code2);
|
|
3396
|
-
}
|
|
3397
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3398
|
-
if (!seen || size !== sizeB) {
|
|
3399
|
-
return headDelimiterNok(code2);
|
|
3400
|
-
}
|
|
3401
|
-
effects.exit("tableDelimiterRow");
|
|
3402
|
-
effects.exit("tableHead");
|
|
3403
|
-
return ok2(code2);
|
|
3404
|
-
}
|
|
3405
|
-
return headDelimiterNok(code2);
|
|
3406
|
-
}
|
|
3407
|
-
function headDelimiterNok(code2) {
|
|
3408
|
-
return nok(code2);
|
|
3409
|
-
}
|
|
3410
|
-
function bodyRowStart(code2) {
|
|
3411
|
-
effects.enter("tableRow");
|
|
3412
|
-
return bodyRowBreak(code2);
|
|
3413
|
-
}
|
|
3414
|
-
function bodyRowBreak(code2) {
|
|
3415
|
-
if (code2 === 124) {
|
|
3416
|
-
effects.enter("tableCellDivider");
|
|
3417
|
-
effects.consume(code2);
|
|
3418
|
-
effects.exit("tableCellDivider");
|
|
3419
|
-
return bodyRowBreak;
|
|
3420
|
-
}
|
|
3421
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3422
|
-
effects.exit("tableRow");
|
|
3423
|
-
return ok2(code2);
|
|
3424
|
-
}
|
|
3425
|
-
if (markdownSpace(code2)) {
|
|
3426
|
-
return factorySpace(effects, bodyRowBreak, "whitespace")(code2);
|
|
3427
|
-
}
|
|
3428
|
-
effects.enter("data");
|
|
3429
|
-
return bodyRowData(code2);
|
|
3430
|
-
}
|
|
3431
|
-
function bodyRowData(code2) {
|
|
3432
|
-
if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
|
|
3433
|
-
effects.exit("data");
|
|
3434
|
-
return bodyRowBreak(code2);
|
|
3435
|
-
}
|
|
3436
|
-
effects.consume(code2);
|
|
3437
|
-
return code2 === 92 ? bodyRowEscape : bodyRowData;
|
|
3438
|
-
}
|
|
3439
|
-
function bodyRowEscape(code2) {
|
|
3440
|
-
if (code2 === 92 || code2 === 124) {
|
|
3441
|
-
effects.consume(code2);
|
|
3442
|
-
return bodyRowData;
|
|
3443
|
-
}
|
|
3444
|
-
return bodyRowData(code2);
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
function resolveTable(events, context) {
|
|
3448
|
-
let index = -1;
|
|
3449
|
-
let inFirstCellAwaitingPipe = true;
|
|
3450
|
-
let rowKind = 0;
|
|
3451
|
-
let lastCell = [0, 0, 0, 0];
|
|
3452
|
-
let cell = [0, 0, 0, 0];
|
|
3453
|
-
let afterHeadAwaitingFirstBodyRow = false;
|
|
3454
|
-
let lastTableEnd = 0;
|
|
3455
|
-
let currentTable;
|
|
3456
|
-
let currentBody;
|
|
3457
|
-
let currentCell;
|
|
3458
|
-
const map2 = new EditMap();
|
|
3459
|
-
while (++index < events.length) {
|
|
3460
|
-
const event = events[index];
|
|
3461
|
-
const token = event[1];
|
|
3462
|
-
if (event[0] === "enter") {
|
|
3463
|
-
if (token.type === "tableHead") {
|
|
3464
|
-
afterHeadAwaitingFirstBodyRow = false;
|
|
3465
|
-
if (lastTableEnd !== 0) {
|
|
3466
|
-
flushTableEnd(map2, context, lastTableEnd, currentTable, currentBody);
|
|
3467
|
-
currentBody = void 0;
|
|
3468
|
-
lastTableEnd = 0;
|
|
3469
|
-
}
|
|
3470
|
-
currentTable = {
|
|
3471
|
-
type: "table",
|
|
3472
|
-
start: Object.assign({}, token.start),
|
|
3473
|
-
// Note: correct end is set later.
|
|
3474
|
-
end: Object.assign({}, token.end)
|
|
3475
|
-
};
|
|
3476
|
-
map2.add(index, 0, [["enter", currentTable, context]]);
|
|
3477
|
-
} else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
|
|
3478
|
-
inFirstCellAwaitingPipe = true;
|
|
3479
|
-
currentCell = void 0;
|
|
3480
|
-
lastCell = [0, 0, 0, 0];
|
|
3481
|
-
cell = [0, index + 1, 0, 0];
|
|
3482
|
-
if (afterHeadAwaitingFirstBodyRow) {
|
|
3483
|
-
afterHeadAwaitingFirstBodyRow = false;
|
|
3484
|
-
currentBody = {
|
|
3485
|
-
type: "tableBody",
|
|
3486
|
-
start: Object.assign({}, token.start),
|
|
3487
|
-
// Note: correct end is set later.
|
|
3488
|
-
end: Object.assign({}, token.end)
|
|
3489
|
-
};
|
|
3490
|
-
map2.add(index, 0, [["enter", currentBody, context]]);
|
|
3491
|
-
}
|
|
3492
|
-
rowKind = token.type === "tableDelimiterRow" ? 2 : currentBody ? 3 : 1;
|
|
3493
|
-
} else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
|
|
3494
|
-
inFirstCellAwaitingPipe = false;
|
|
3495
|
-
if (cell[2] === 0) {
|
|
3496
|
-
if (lastCell[1] !== 0) {
|
|
3497
|
-
cell[0] = cell[1];
|
|
3498
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, void 0, currentCell);
|
|
3499
|
-
lastCell = [0, 0, 0, 0];
|
|
3500
|
-
}
|
|
3501
|
-
cell[2] = index;
|
|
3502
|
-
}
|
|
3503
|
-
} else if (token.type === "tableCellDivider") {
|
|
3504
|
-
if (inFirstCellAwaitingPipe) {
|
|
3505
|
-
inFirstCellAwaitingPipe = false;
|
|
3506
|
-
} else {
|
|
3507
|
-
if (lastCell[1] !== 0) {
|
|
3508
|
-
cell[0] = cell[1];
|
|
3509
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, void 0, currentCell);
|
|
3510
|
-
}
|
|
3511
|
-
lastCell = cell;
|
|
3512
|
-
cell = [lastCell[1], index, 0, 0];
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
} else if (token.type === "tableHead") {
|
|
3516
|
-
afterHeadAwaitingFirstBodyRow = true;
|
|
3517
|
-
lastTableEnd = index;
|
|
3518
|
-
} else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
|
|
3519
|
-
lastTableEnd = index;
|
|
3520
|
-
if (lastCell[1] !== 0) {
|
|
3521
|
-
cell[0] = cell[1];
|
|
3522
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, index, currentCell);
|
|
3523
|
-
} else if (cell[1] !== 0) {
|
|
3524
|
-
currentCell = flushCell(map2, context, cell, rowKind, index, currentCell);
|
|
3525
|
-
}
|
|
3526
|
-
rowKind = 0;
|
|
3527
|
-
} else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
|
|
3528
|
-
cell[3] = index;
|
|
3529
|
-
}
|
|
3530
|
-
}
|
|
3531
|
-
if (lastTableEnd !== 0) {
|
|
3532
|
-
flushTableEnd(map2, context, lastTableEnd, currentTable, currentBody);
|
|
3533
|
-
}
|
|
3534
|
-
map2.consume(context.events);
|
|
3535
|
-
index = -1;
|
|
3536
|
-
while (++index < context.events.length) {
|
|
3537
|
-
const event = context.events[index];
|
|
3538
|
-
if (event[0] === "enter" && event[1].type === "table") {
|
|
3539
|
-
event[1]._align = gfmTableAlign(context.events, index);
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
return events;
|
|
3543
|
-
}
|
|
3544
|
-
function flushCell(map2, context, range, rowKind, rowEnd, previousCell) {
|
|
3545
|
-
const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData";
|
|
3546
|
-
const valueName = "tableContent";
|
|
3547
|
-
if (range[0] !== 0) {
|
|
3548
|
-
previousCell.end = Object.assign({}, getPoint(context.events, range[0]));
|
|
3549
|
-
map2.add(range[0], 0, [["exit", previousCell, context]]);
|
|
3550
|
-
}
|
|
3551
|
-
const now = getPoint(context.events, range[1]);
|
|
3552
|
-
previousCell = {
|
|
3553
|
-
type: groupName,
|
|
3554
|
-
start: Object.assign({}, now),
|
|
3555
|
-
// Note: correct end is set later.
|
|
3556
|
-
end: Object.assign({}, now)
|
|
3557
|
-
};
|
|
3558
|
-
map2.add(range[1], 0, [["enter", previousCell, context]]);
|
|
3559
|
-
if (range[2] !== 0) {
|
|
3560
|
-
const relatedStart = getPoint(context.events, range[2]);
|
|
3561
|
-
const relatedEnd = getPoint(context.events, range[3]);
|
|
3562
|
-
const valueToken = {
|
|
3563
|
-
type: valueName,
|
|
3564
|
-
start: Object.assign({}, relatedStart),
|
|
3565
|
-
end: Object.assign({}, relatedEnd)
|
|
3566
|
-
};
|
|
3567
|
-
map2.add(range[2], 0, [["enter", valueToken, context]]);
|
|
3568
|
-
if (rowKind !== 2) {
|
|
3569
|
-
const start = context.events[range[2]];
|
|
3570
|
-
const end = context.events[range[3]];
|
|
3571
|
-
start[1].end = Object.assign({}, end[1].end);
|
|
3572
|
-
start[1].type = "chunkText";
|
|
3573
|
-
start[1].contentType = "text";
|
|
3574
|
-
if (range[3] > range[2] + 1) {
|
|
3575
|
-
const a = range[2] + 1;
|
|
3576
|
-
const b = range[3] - range[2] - 1;
|
|
3577
|
-
map2.add(a, b, []);
|
|
3578
|
-
}
|
|
3579
|
-
}
|
|
3580
|
-
map2.add(range[3] + 1, 0, [["exit", valueToken, context]]);
|
|
3581
|
-
}
|
|
3582
|
-
if (rowEnd !== void 0) {
|
|
3583
|
-
previousCell.end = Object.assign({}, getPoint(context.events, rowEnd));
|
|
3584
|
-
map2.add(rowEnd, 0, [["exit", previousCell, context]]);
|
|
3585
|
-
previousCell = void 0;
|
|
3586
|
-
}
|
|
3587
|
-
return previousCell;
|
|
3588
|
-
}
|
|
3589
|
-
function flushTableEnd(map2, context, index, table, tableBody) {
|
|
3590
|
-
const exits = [];
|
|
3591
|
-
const related = getPoint(context.events, index);
|
|
3592
|
-
if (tableBody) {
|
|
3593
|
-
tableBody.end = Object.assign({}, related);
|
|
3594
|
-
exits.push(["exit", tableBody, context]);
|
|
3595
|
-
}
|
|
3596
|
-
table.end = Object.assign({}, related);
|
|
3597
|
-
exits.push(["exit", table, context]);
|
|
3598
|
-
map2.add(index + 1, 0, exits);
|
|
3599
|
-
}
|
|
3600
|
-
function getPoint(events, index) {
|
|
3601
|
-
const event = events[index];
|
|
3602
|
-
const side = event[0] === "enter" ? "start" : "end";
|
|
3603
|
-
return event[1][side];
|
|
3604
|
-
}
|
|
3605
|
-
const tasklistCheck = {
|
|
3606
|
-
name: "tasklistCheck",
|
|
3607
|
-
tokenize: tokenizeTasklistCheck
|
|
3608
|
-
};
|
|
3609
|
-
function gfmTaskListItem() {
|
|
3610
|
-
return {
|
|
3611
|
-
text: {
|
|
3612
|
-
[91]: tasklistCheck
|
|
3613
|
-
}
|
|
3614
|
-
};
|
|
3615
|
-
}
|
|
3616
|
-
function tokenizeTasklistCheck(effects, ok2, nok) {
|
|
3617
|
-
const self = this;
|
|
3618
|
-
return open;
|
|
3619
|
-
function open(code2) {
|
|
3620
|
-
if (
|
|
3621
|
-
// Exit if there’s stuff before.
|
|
3622
|
-
self.previous !== null || // Exit if not in the first content that is the first child of a list
|
|
3623
|
-
// item.
|
|
3624
|
-
!self._gfmTasklistFirstContentOfListItem
|
|
3625
|
-
) {
|
|
3626
|
-
return nok(code2);
|
|
3627
|
-
}
|
|
3628
|
-
effects.enter("taskListCheck");
|
|
3629
|
-
effects.enter("taskListCheckMarker");
|
|
3630
|
-
effects.consume(code2);
|
|
3631
|
-
effects.exit("taskListCheckMarker");
|
|
3632
|
-
return inside;
|
|
3633
|
-
}
|
|
3634
|
-
function inside(code2) {
|
|
3635
|
-
if (markdownLineEndingOrSpace(code2)) {
|
|
3636
|
-
effects.enter("taskListCheckValueUnchecked");
|
|
3637
|
-
effects.consume(code2);
|
|
3638
|
-
effects.exit("taskListCheckValueUnchecked");
|
|
3639
|
-
return close;
|
|
3640
|
-
}
|
|
3641
|
-
if (code2 === 88 || code2 === 120) {
|
|
3642
|
-
effects.enter("taskListCheckValueChecked");
|
|
3643
|
-
effects.consume(code2);
|
|
3644
|
-
effects.exit("taskListCheckValueChecked");
|
|
3645
|
-
return close;
|
|
3646
|
-
}
|
|
3647
|
-
return nok(code2);
|
|
3648
|
-
}
|
|
3649
|
-
function close(code2) {
|
|
3650
|
-
if (code2 === 93) {
|
|
3651
|
-
effects.enter("taskListCheckMarker");
|
|
3652
|
-
effects.consume(code2);
|
|
3653
|
-
effects.exit("taskListCheckMarker");
|
|
3654
|
-
effects.exit("taskListCheck");
|
|
3655
|
-
return after;
|
|
313
|
+
{
|
|
314
|
+
d: "M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",
|
|
315
|
+
key: "r04s7s"
|
|
3656
316
|
}
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
317
|
+
]
|
|
318
|
+
];
|
|
319
|
+
const Star = createLucideIcon("star", __iconNode$3);
|
|
320
|
+
/**
|
|
321
|
+
* @license lucide-react v0.575.0 - ISC
|
|
322
|
+
*
|
|
323
|
+
* This source code is licensed under the ISC license.
|
|
324
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
325
|
+
*/
|
|
326
|
+
const __iconNode$2 = [
|
|
327
|
+
["path", { d: "M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2", key: "975kel" }],
|
|
328
|
+
["circle", { cx: "12", cy: "7", r: "4", key: "17ys0d" }]
|
|
329
|
+
];
|
|
330
|
+
const User = createLucideIcon("user", __iconNode$2);
|
|
331
|
+
/**
|
|
332
|
+
* @license lucide-react v0.575.0 - ISC
|
|
333
|
+
*
|
|
334
|
+
* This source code is licensed under the ISC license.
|
|
335
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
336
|
+
*/
|
|
337
|
+
const __iconNode$1 = [
|
|
338
|
+
[
|
|
339
|
+
"path",
|
|
340
|
+
{
|
|
341
|
+
d: "m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",
|
|
342
|
+
key: "ftymec"
|
|
3662
343
|
}
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
344
|
+
],
|
|
345
|
+
["rect", { x: "2", y: "6", width: "14", height: "12", rx: "2", key: "158x01" }]
|
|
346
|
+
];
|
|
347
|
+
const Video = createLucideIcon("video", __iconNode$1);
|
|
348
|
+
/**
|
|
349
|
+
* @license lucide-react v0.575.0 - ISC
|
|
350
|
+
*
|
|
351
|
+
* This source code is licensed under the ISC license.
|
|
352
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
353
|
+
*/
|
|
354
|
+
const __iconNode = [
|
|
355
|
+
[
|
|
356
|
+
"path",
|
|
357
|
+
{
|
|
358
|
+
d: "M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",
|
|
359
|
+
key: "1xq2db"
|
|
3667
360
|
}
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
function
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
return code2 === null ? nok(code2) : ok2(code2);
|
|
3675
|
-
}
|
|
3676
|
-
}
|
|
3677
|
-
function gfm(options) {
|
|
3678
|
-
return combineExtensions([
|
|
3679
|
-
gfmAutolinkLiteral(),
|
|
3680
|
-
gfmFootnote(),
|
|
3681
|
-
gfmStrikethrough(options),
|
|
3682
|
-
gfmTable(),
|
|
3683
|
-
gfmTaskListItem()
|
|
3684
|
-
]);
|
|
3685
|
-
}
|
|
3686
|
-
const emptyOptions = {};
|
|
3687
|
-
function remarkGfm(options) {
|
|
3688
|
-
const self = (
|
|
3689
|
-
/** @type {Processor<Root>} */
|
|
3690
|
-
this
|
|
3691
|
-
);
|
|
3692
|
-
const settings = options || emptyOptions;
|
|
3693
|
-
const data = self.data();
|
|
3694
|
-
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
|
|
3695
|
-
const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
|
|
3696
|
-
const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
|
|
3697
|
-
micromarkExtensions.push(gfm(settings));
|
|
3698
|
-
fromMarkdownExtensions.push(gfmFromMarkdown());
|
|
3699
|
-
toMarkdownExtensions.push(gfmToMarkdown(settings));
|
|
3700
|
-
}
|
|
3701
|
-
function createOlympusAssetUrl({
|
|
3702
|
-
appUrl,
|
|
3703
|
-
backendUrl,
|
|
3704
|
-
assetIds
|
|
361
|
+
]
|
|
362
|
+
];
|
|
363
|
+
const Zap = createLucideIcon("zap", __iconNode);
|
|
364
|
+
function ChatHeaderRoot({
|
|
365
|
+
children,
|
|
366
|
+
className
|
|
3705
367
|
}) {
|
|
3706
|
-
|
|
3707
|
-
if (!resolvedAppUrl) return null;
|
|
3708
|
-
const url = createAthenaSpacesUrl({
|
|
3709
|
-
appUrl: resolvedAppUrl,
|
|
3710
|
-
assetIds
|
|
3711
|
-
});
|
|
3712
|
-
return new URL(url).toString();
|
|
3713
|
-
}
|
|
3714
|
-
function authorizationHeaders(auth) {
|
|
3715
|
-
if (auth.accessToken) {
|
|
3716
|
-
return { Authorization: `Bearer ${auth.accessToken}` };
|
|
3717
|
-
}
|
|
3718
|
-
if (auth.apiKey) return { "X-API-KEY": auth.apiKey };
|
|
3719
|
-
throw new Error("MentionAuthCtx needs either an accessToken or an apiKey");
|
|
3720
|
-
}
|
|
3721
|
-
const MentionAuthCtx = createContext(null);
|
|
3722
|
-
function useMentionAuth() {
|
|
3723
|
-
const ctx = useContext(MentionAuthCtx);
|
|
3724
|
-
if (!ctx) throw new Error("MentionAuthCtx not provided");
|
|
3725
|
-
return ctx;
|
|
3726
|
-
}
|
|
3727
|
-
async function fetchGraphQL(auth, query, variables = {}) {
|
|
3728
|
-
var _a;
|
|
3729
|
-
const url = `${auth.backendUrl.replace(/\/+$/, "")}/graphql`;
|
|
3730
|
-
const response = await fetch(url, {
|
|
3731
|
-
method: "POST",
|
|
3732
|
-
headers: {
|
|
3733
|
-
"Content-Type": "application/json",
|
|
3734
|
-
...authorizationHeaders(auth)
|
|
3735
|
-
},
|
|
3736
|
-
body: JSON.stringify({ query, variables })
|
|
3737
|
-
});
|
|
3738
|
-
if (!response.ok) {
|
|
3739
|
-
throw new Error(`GraphQL HTTP ${response.status}: ${response.statusText}`);
|
|
3740
|
-
}
|
|
3741
|
-
const result = await response.json();
|
|
3742
|
-
if ((_a = result.errors) == null ? void 0 : _a.length) {
|
|
3743
|
-
throw new Error(`GraphQL error: ${result.errors[0].message}`);
|
|
3744
|
-
}
|
|
3745
|
-
return result.data;
|
|
368
|
+
return /* @__PURE__ */ jsx("div", { className: cn(THREAD_HEADER_CLASS, className), children });
|
|
3746
369
|
}
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
athenaOriginalType
|
|
3751
|
-
athenaConvertedType
|
|
3752
|
-
parentFolderId
|
|
3753
|
-
updatedAt
|
|
3754
|
-
isFavorited
|
|
3755
|
-
isArchived
|
|
3756
|
-
isHidden
|
|
3757
|
-
`;
|
|
3758
|
-
const SIMPLE_SEARCH_QUERY = `
|
|
3759
|
-
query SimpleSearch($input: SimpleSearchRequestInput!) {
|
|
3760
|
-
simpleSearch(input: $input) {
|
|
3761
|
-
assets {
|
|
3762
|
-
${MENTION_ASSET_FIELDS}
|
|
3763
|
-
}
|
|
3764
|
-
totalCount
|
|
3765
|
-
}
|
|
3766
|
-
}
|
|
3767
|
-
`;
|
|
3768
|
-
const PAGINATED_ASSETS_QUERY = `
|
|
3769
|
-
query GetPaginatedAssetsForWorkspace(
|
|
3770
|
-
$limit: Int!
|
|
3771
|
-
$offset: Int!
|
|
3772
|
-
$parentFolderId: String
|
|
3773
|
-
$filterTypes: [String!]
|
|
3774
|
-
$filterColumns: ColumnFilter
|
|
3775
|
-
) {
|
|
3776
|
-
getPaginatedAssetsForWorkspace(
|
|
3777
|
-
limit: $limit
|
|
3778
|
-
offset: $offset
|
|
3779
|
-
parentFolderId: $parentFolderId
|
|
3780
|
-
filterTypes: $filterTypes
|
|
3781
|
-
filterColumns: $filterColumns
|
|
3782
|
-
) {
|
|
3783
|
-
${MENTION_ASSET_FIELDS}
|
|
3784
|
-
}
|
|
3785
|
-
}
|
|
3786
|
-
`;
|
|
3787
|
-
const WORKSPACE_MEMBERS_QUERY = `
|
|
3788
|
-
query GetUsersInWorkspace($workspaceId: String!) {
|
|
3789
|
-
getUsersInWorkspace(workspaceId: $workspaceId) {
|
|
3790
|
-
id
|
|
3791
|
-
email
|
|
3792
|
-
firstName
|
|
3793
|
-
lastName
|
|
3794
|
-
isAdmin
|
|
3795
|
-
avatarUrl
|
|
3796
|
-
}
|
|
3797
|
-
}
|
|
3798
|
-
`;
|
|
3799
|
-
let iconBasePath = null;
|
|
3800
|
-
function configureAssetIconBasePath({
|
|
3801
|
-
basePath
|
|
370
|
+
function ChatHeaderIdentity({
|
|
371
|
+
children,
|
|
372
|
+
className
|
|
3802
373
|
}) {
|
|
3803
|
-
|
|
3804
|
-
}
|
|
3805
|
-
const ASSET_TYPE_ICON_FILE = {
|
|
3806
|
-
// Documents
|
|
3807
|
-
folder: "ic-folder",
|
|
3808
|
-
txt: "ic-txt",
|
|
3809
|
-
document: "ic-word",
|
|
3810
|
-
word_document: "ic-word",
|
|
3811
|
-
markdown: "ic-md",
|
|
3812
|
-
pdf: "ic-pdf",
|
|
3813
|
-
html: "ic-html",
|
|
3814
|
-
web_page: "ic-html",
|
|
3815
|
-
yaml: "ic-yaml",
|
|
3816
|
-
json: "ic-json",
|
|
3817
|
-
// Spreadsheets
|
|
3818
|
-
spreadsheet: "ic-excel",
|
|
3819
|
-
table: "ic-table",
|
|
3820
|
-
// Media
|
|
3821
|
-
image: "ic-img",
|
|
3822
|
-
audio: "ic-audio",
|
|
3823
|
-
video: "ic-video",
|
|
3824
|
-
voice_memo: "ic-audio",
|
|
3825
|
-
// Presentations
|
|
3826
|
-
presentation: "ic-power_point",
|
|
3827
|
-
office_presentation: "ic-power_point",
|
|
3828
|
-
powerpoint_deck: "ic-power_point",
|
|
3829
|
-
presentation_pptx_studio: "ic-power_point",
|
|
3830
|
-
presentation_onlyoffice: "ic-power_point",
|
|
3831
|
-
pptx: "ic-power_point",
|
|
3832
|
-
// Email & Calendar
|
|
3833
|
-
email: "ic-mail",
|
|
3834
|
-
email_message: "ic-mail",
|
|
3835
|
-
live_email_thread: "ic-mail",
|
|
3836
|
-
live_calendar_event: "ic-mail",
|
|
3837
|
-
// Code
|
|
3838
|
-
python: "ic-py",
|
|
3839
|
-
javascript: "ic-js",
|
|
3840
|
-
typescript: "ic-code",
|
|
3841
|
-
jsx: "ic-code",
|
|
3842
|
-
tsx: "ic-code",
|
|
3843
|
-
css: "ic-code",
|
|
3844
|
-
java: "ic-code",
|
|
3845
|
-
c: "ic-code",
|
|
3846
|
-
cpp: "ic-code",
|
|
3847
|
-
csharp: "ic-code",
|
|
3848
|
-
ruby: "ic-code",
|
|
3849
|
-
go: "ic-code",
|
|
3850
|
-
swift: "ic-code",
|
|
3851
|
-
php: "ic-code",
|
|
3852
|
-
rust: "ic-code",
|
|
3853
|
-
vue: "ic-code",
|
|
3854
|
-
wm_script: "ic-code",
|
|
3855
|
-
// Structured data
|
|
3856
|
-
database: "ic-snippet",
|
|
3857
|
-
schema: "ic-schema",
|
|
3858
|
-
catalog: "ic-db",
|
|
3859
|
-
drive: "ic-db",
|
|
3860
|
-
query_snippet: "ic-snippet",
|
|
3861
|
-
semantic_model: "ic-db",
|
|
3862
|
-
// Meetings & Calls
|
|
3863
|
-
meeting: "ic-meeting",
|
|
3864
|
-
video_session: "ic-meeting",
|
|
3865
|
-
phone_call: "ic-phonecall",
|
|
3866
|
-
// Sessions & Devices
|
|
3867
|
-
session: "ic-session",
|
|
3868
|
-
browse_session: "ic-html",
|
|
3869
|
-
virtual_machine: "ic-html",
|
|
3870
|
-
computer: "ic-computer",
|
|
3871
|
-
desktop_session: "ic-desktop_session",
|
|
3872
|
-
mobile_session: "ic-mobile_session",
|
|
3873
|
-
// Projects & Profiles
|
|
3874
|
-
project: "ic-project",
|
|
3875
|
-
browse_profile: "ic-profile",
|
|
3876
|
-
// Workflows & Automation
|
|
3877
|
-
aop: "ic-flow",
|
|
3878
|
-
playbook: "ic-flow",
|
|
3879
|
-
flow: "ic-flow",
|
|
3880
|
-
transform_project: "ic-flow",
|
|
3881
|
-
// Collections & Notebooks
|
|
3882
|
-
collection: "ic-collection",
|
|
3883
|
-
notebook: "ic-notebook",
|
|
3884
|
-
// UI & Apps
|
|
3885
|
-
user_interface: "ic-app",
|
|
3886
|
-
canvas: "ic-canvas",
|
|
3887
|
-
dashboard: "ic-dashboard",
|
|
3888
|
-
figure: "ic_figure",
|
|
3889
|
-
// People & Companies
|
|
3890
|
-
person: "ic-person",
|
|
3891
|
-
company: "ic-company",
|
|
3892
|
-
// Misc
|
|
3893
|
-
prompt: "ic-ai",
|
|
3894
|
-
task_item: "ic-task",
|
|
3895
|
-
spaces: "ic-spaces",
|
|
3896
|
-
secret: "ic-secret",
|
|
3897
|
-
photoshop: "ic-pts",
|
|
3898
|
-
illustrator: "ic-ai",
|
|
3899
|
-
zip: "ic-zip",
|
|
3900
|
-
sevenzip: "ic-zip",
|
|
3901
|
-
// Google Drive / SharePoint / Salesforce
|
|
3902
|
-
gdrive_folder: "ic-folder",
|
|
3903
|
-
gdrive_file: "ic-file",
|
|
3904
|
-
salesforce_record: "ic-db",
|
|
3905
|
-
salesforce_file: "ic-db"
|
|
3906
|
-
};
|
|
3907
|
-
const ASSET_TYPE_LUCIDE_FALLBACK = {
|
|
3908
|
-
folder: "folder",
|
|
3909
|
-
spreadsheet: "sheet",
|
|
3910
|
-
image: "image",
|
|
3911
|
-
video: "video",
|
|
3912
|
-
audio: "headphones",
|
|
3913
|
-
email: "mail",
|
|
3914
|
-
database: "database",
|
|
3915
|
-
project: "folder-kanban",
|
|
3916
|
-
meeting: "video",
|
|
3917
|
-
user_interface: "layout"
|
|
3918
|
-
};
|
|
3919
|
-
function assetTypeToThumb(assetType) {
|
|
3920
|
-
if (!iconBasePath) return void 0;
|
|
3921
|
-
const name = (assetType ? ASSET_TYPE_ICON_FILE[assetType.toLowerCase()] : void 0) ?? "ic-file";
|
|
3922
|
-
return `${iconBasePath}${name}.svg`;
|
|
374
|
+
return /* @__PURE__ */ jsx("div", { className: cn(THREAD_HEADER_PILL_CLASS, className), children });
|
|
3923
375
|
}
|
|
3924
|
-
function
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
}
|
|
3928
|
-
|
|
3929
|
-
function isSpacesMentionUrl(url) {
|
|
3930
|
-
return SPACES_MENTION_PATH.test(url);
|
|
3931
|
-
}
|
|
3932
|
-
function getSpacesAssetType(url) {
|
|
3933
|
-
const assetType = url.searchParams.get("assetType") || url.searchParams.get("asset_type") || url.searchParams.get("type");
|
|
3934
|
-
return assetType === "sheet" ? "spreadsheet" : assetType;
|
|
376
|
+
function ChatHeaderActions({
|
|
377
|
+
children,
|
|
378
|
+
className
|
|
379
|
+
}) {
|
|
380
|
+
return /* @__PURE__ */ jsx("div", { className: cn(THREAD_HEADER_ACTIONS_CLASS, className), children });
|
|
3935
381
|
}
|
|
3936
|
-
const
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
return /* @__PURE__ */ jsx(
|
|
3941
|
-
MentionChip,
|
|
3942
|
-
{
|
|
3943
|
-
name: name || parsed.name,
|
|
3944
|
-
type: parsed.type,
|
|
3945
|
-
assetIds: parsed.assetIds,
|
|
3946
|
-
thumbnailUrl: parsed.thumbnailUrl,
|
|
3947
|
-
sourceHref: isSpacesMentionUrl(href) ? href : void 0
|
|
3948
|
-
}
|
|
3949
|
-
);
|
|
3950
|
-
}
|
|
3951
|
-
if (href == null ? void 0 : href.startsWith("chrome-extension://")) {
|
|
3952
|
-
return /* @__PURE__ */ jsx("span", { children });
|
|
3953
|
-
}
|
|
3954
|
-
return /* @__PURE__ */ jsx("a", { href, target: "_blank", rel: "noopener noreferrer", children });
|
|
382
|
+
const ChatHeader = {
|
|
383
|
+
Root: ChatHeaderRoot,
|
|
384
|
+
Identity: ChatHeaderIdentity,
|
|
385
|
+
Actions: ChatHeaderActions
|
|
3955
386
|
};
|
|
3956
|
-
const
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
const
|
|
3978
|
-
|
|
3979
|
-
|
|
387
|
+
const TIME_GROUPS = [
|
|
388
|
+
"Today",
|
|
389
|
+
"Yesterday",
|
|
390
|
+
"This Week",
|
|
391
|
+
"This Month",
|
|
392
|
+
"Older"
|
|
393
|
+
];
|
|
394
|
+
const AUTOMATED_SOURCE_CHANNELS = /* @__PURE__ */ new Set([
|
|
395
|
+
"api",
|
|
396
|
+
"email",
|
|
397
|
+
"orchestration",
|
|
398
|
+
"slack",
|
|
399
|
+
"sms",
|
|
400
|
+
"task",
|
|
401
|
+
"teams"
|
|
402
|
+
]);
|
|
403
|
+
function isAutomatedConversation(conversation) {
|
|
404
|
+
var _a, _b;
|
|
405
|
+
const sourceChannel = (_a = conversation.sourceChannel) == null ? void 0 : _a.trim().toLowerCase();
|
|
406
|
+
if (sourceChannel && AUTOMATED_SOURCE_CHANNELS.has(sourceChannel))
|
|
407
|
+
return true;
|
|
408
|
+
const triggerType = (_b = conversation.triggerType) == null ? void 0 : _b.trim().toLowerCase();
|
|
409
|
+
return Boolean(triggerType && triggerType !== "manual");
|
|
410
|
+
}
|
|
411
|
+
function conversationTimeGroup(value, now = /* @__PURE__ */ new Date()) {
|
|
412
|
+
const date = new Date(value);
|
|
413
|
+
if (Number.isNaN(date.getTime())) return "Older";
|
|
414
|
+
const startOfToday = new Date(
|
|
415
|
+
now.getFullYear(),
|
|
416
|
+
now.getMonth(),
|
|
417
|
+
now.getDate()
|
|
3980
418
|
);
|
|
3981
|
-
const
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
419
|
+
const startOfYesterday = new Date(startOfToday.getTime() - 864e5);
|
|
420
|
+
const startOfWeek = new Date(
|
|
421
|
+
startOfToday.getTime() - startOfToday.getDay() * 864e5
|
|
422
|
+
);
|
|
423
|
+
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
424
|
+
if (date >= startOfToday) return "Today";
|
|
425
|
+
if (date >= startOfYesterday) return "Yesterday";
|
|
426
|
+
if (date >= startOfWeek) return "This Week";
|
|
427
|
+
if (date >= startOfMonth) return "This Month";
|
|
428
|
+
return "Older";
|
|
429
|
+
}
|
|
430
|
+
function originKey(conversation) {
|
|
431
|
+
return conversation.appId ?? conversation.sourceChannel ?? "unknown";
|
|
432
|
+
}
|
|
433
|
+
function originLabel(value) {
|
|
434
|
+
const normalized = value.toLowerCase();
|
|
435
|
+
if (normalized.includes("chrome")) return "Chrome";
|
|
436
|
+
if (normalized.includes("powerpoint")) return "PowerPoint";
|
|
437
|
+
if (normalized.includes("word")) return "Word";
|
|
438
|
+
if (normalized.includes("excel")) return "Excel";
|
|
439
|
+
if (normalized.includes("office")) return "Office";
|
|
440
|
+
if (normalized === "web" || normalized.includes("olympus")) return "Athena";
|
|
441
|
+
if (normalized.includes("mobile")) return "Mobile";
|
|
442
|
+
if (value === "unknown") return "Legacy";
|
|
443
|
+
return value.replace(/^athena[-_]/, "").replaceAll("_", " ");
|
|
444
|
+
}
|
|
445
|
+
function relativeTime(value) {
|
|
446
|
+
const timestamp = Date.parse(value);
|
|
447
|
+
if (!Number.isFinite(timestamp)) return "";
|
|
448
|
+
const elapsed = Math.max(0, Date.now() - timestamp);
|
|
449
|
+
const minutes = Math.floor(elapsed / 6e4);
|
|
450
|
+
if (minutes < 1) return "<1m ago";
|
|
451
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
452
|
+
const hours = Math.floor(minutes / 60);
|
|
453
|
+
if (hours < 24) return `${hours}h ${minutes % 60}m ago`;
|
|
454
|
+
const days = Math.floor(hours / 24);
|
|
455
|
+
return days < 7 ? `${days}d ago` : new Date(timestamp).toLocaleDateString();
|
|
456
|
+
}
|
|
457
|
+
function ConversationTypeIcon({
|
|
458
|
+
conversation,
|
|
459
|
+
automated
|
|
460
|
+
}) {
|
|
461
|
+
if (conversation.state === "running") {
|
|
3995
462
|
return /* @__PURE__ */ jsx(
|
|
3996
|
-
|
|
463
|
+
LoaderCircle,
|
|
3997
464
|
{
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
rel: "noopener noreferrer",
|
|
4001
|
-
className,
|
|
4002
|
-
"aria-label": `Open ${name} in Spaces`,
|
|
4003
|
-
title: `Open ${name} in Spaces`,
|
|
4004
|
-
children: contents
|
|
4005
|
-
}
|
|
4006
|
-
);
|
|
4007
|
-
}
|
|
4008
|
-
return /* @__PURE__ */ jsx("span", { className, children: contents });
|
|
4009
|
-
};
|
|
4010
|
-
function parseMentionUrl(url) {
|
|
4011
|
-
try {
|
|
4012
|
-
if (isSpacesMentionUrl(url)) {
|
|
4013
|
-
const parsed = new URL(url, "https://app.athenaintel.com");
|
|
4014
|
-
const assetIds = (parsed.searchParams.get("asset_ids") ?? "").split(",").map((id3) => id3.trim()).filter(Boolean);
|
|
4015
|
-
const id2 = assetIds[0] ?? "";
|
|
4016
|
-
const assetType = getSpacesAssetType(parsed);
|
|
4017
|
-
return {
|
|
4018
|
-
type: "asset",
|
|
4019
|
-
name: assetIds.length > 1 ? `${assetIds.length} assets` : "Asset",
|
|
4020
|
-
id: id2,
|
|
4021
|
-
assetIds,
|
|
4022
|
-
thumbnailUrl: assetTypeToThumb(assetType)
|
|
4023
|
-
};
|
|
4024
|
-
}
|
|
4025
|
-
const u = new URL(url);
|
|
4026
|
-
const type = u.hostname || u.pathname.replace(/^\/\//, "").split("?")[0];
|
|
4027
|
-
const isWebpage = type === "webpage";
|
|
4028
|
-
const id = isWebpage ? u.searchParams.get("tab_id") || "" : u.searchParams.get("id") || u.searchParams.get("name") || "";
|
|
4029
|
-
const name = isWebpage ? u.searchParams.get("title") || "This webpage" : u.searchParams.get("name") || id;
|
|
4030
|
-
let thumbnailUrl = u.searchParams.get("thumb") || void 0;
|
|
4031
|
-
if (!thumbnailUrl) {
|
|
4032
|
-
const assetType = u.searchParams.get("assetType");
|
|
4033
|
-
if (assetType) {
|
|
4034
|
-
thumbnailUrl = assetTypeToThumb(assetType);
|
|
4035
|
-
} else if (type === "asset" || type === "folder") {
|
|
4036
|
-
thumbnailUrl = assetTypeToThumb(type === "folder" ? "folder" : null);
|
|
4037
|
-
}
|
|
4038
|
-
}
|
|
4039
|
-
return {
|
|
4040
|
-
type,
|
|
4041
|
-
name,
|
|
4042
|
-
id,
|
|
4043
|
-
assetIds: type === "asset" && id ? [id] : void 0,
|
|
4044
|
-
thumbnailUrl
|
|
4045
|
-
};
|
|
4046
|
-
} catch {
|
|
4047
|
-
return { type: "unknown", name: "", id: "" };
|
|
4048
|
-
}
|
|
4049
|
-
}
|
|
4050
|
-
function htmlAttribute(attributes, name) {
|
|
4051
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4052
|
-
const match = new RegExp(
|
|
4053
|
-
`(?:^|\\s)${escapedName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
4054
|
-
"i"
|
|
4055
|
-
).exec(attributes);
|
|
4056
|
-
return (match == null ? void 0 : match[1]) ?? (match == null ? void 0 : match[2]) ?? (match == null ? void 0 : match[3]) ?? null;
|
|
4057
|
-
}
|
|
4058
|
-
function decodeHtmlAttribute(value) {
|
|
4059
|
-
return value.replace(/&/gi, "&").replace(/"/gi, '"').replace(/'|'/gi, "'").replace(/</gi, "<").replace(/>/gi, ">");
|
|
4060
|
-
}
|
|
4061
|
-
function normalizeAthenaMentionHtml(text2) {
|
|
4062
|
-
return text2.replace(
|
|
4063
|
-
/<a\b([^>]*)>([\s\S]*?)<\/a>/gi,
|
|
4064
|
-
(original, attributes, rawLabel) => {
|
|
4065
|
-
const className = htmlAttribute(attributes, "class") ?? "";
|
|
4066
|
-
const type = htmlAttribute(attributes, "data-type") ?? "";
|
|
4067
|
-
if (!className.split(/\s+/).includes("mention") || type !== "url") {
|
|
4068
|
-
return original;
|
|
4069
|
-
}
|
|
4070
|
-
const rawUrl = htmlAttribute(attributes, "data-url") ?? htmlAttribute(attributes, "href");
|
|
4071
|
-
if (!rawUrl) return original;
|
|
4072
|
-
const url = decodeHtmlAttribute(rawUrl);
|
|
4073
|
-
let normalizedUrl;
|
|
4074
|
-
try {
|
|
4075
|
-
const parsed = new URL(url);
|
|
4076
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
4077
|
-
return original;
|
|
4078
|
-
}
|
|
4079
|
-
normalizedUrl = parsed.toString();
|
|
4080
|
-
} catch {
|
|
4081
|
-
return original;
|
|
465
|
+
"aria-label": "Conversation running",
|
|
466
|
+
className: "mt-0.5 size-4 shrink-0 animate-spin text-primary"
|
|
4082
467
|
}
|
|
4083
|
-
const label = decodeHtmlAttribute(rawLabel.replace(/<[^>]*>/g, "")).trim().replace(/([\\[\]])/g, "\\$1");
|
|
4084
|
-
return label ? `[${label}](<${normalizedUrl}>)` : original;
|
|
4085
|
-
}
|
|
4086
|
-
);
|
|
4087
|
-
}
|
|
4088
|
-
const MENTION_RE = /\[@([^\]]*)\]\(((?:mention:\/\/|(?:https?:\/\/[^)\s]+)?\/dashboard\/spaces\/?\?)[^)]+)\)/g;
|
|
4089
|
-
function parseMentionsInText(text2) {
|
|
4090
|
-
const parts = [];
|
|
4091
|
-
let lastIndex = 0;
|
|
4092
|
-
let match;
|
|
4093
|
-
MENTION_RE.lastIndex = 0;
|
|
4094
|
-
while ((match = MENTION_RE.exec(text2)) !== null) {
|
|
4095
|
-
if (match.index > lastIndex) {
|
|
4096
|
-
parts.push(text2.slice(lastIndex, match.index));
|
|
4097
|
-
}
|
|
4098
|
-
const name = match[1];
|
|
4099
|
-
const url = match[2];
|
|
4100
|
-
const parsed = parseMentionUrl(url);
|
|
4101
|
-
parts.push(
|
|
4102
|
-
/* @__PURE__ */ jsx(
|
|
4103
|
-
MentionChip,
|
|
4104
|
-
{
|
|
4105
|
-
name: name || parsed.name,
|
|
4106
|
-
type: parsed.type,
|
|
4107
|
-
assetIds: parsed.assetIds,
|
|
4108
|
-
thumbnailUrl: parsed.thumbnailUrl,
|
|
4109
|
-
sourceHref: isSpacesMentionUrl(url) ? url : void 0
|
|
4110
|
-
},
|
|
4111
|
-
`mention-${match.index}`
|
|
4112
|
-
)
|
|
4113
468
|
);
|
|
4114
|
-
lastIndex = match.index + match[0].length;
|
|
4115
|
-
}
|
|
4116
|
-
if (lastIndex < text2.length) {
|
|
4117
|
-
parts.push(text2.slice(lastIndex));
|
|
4118
|
-
}
|
|
4119
|
-
return parts.length > 0 ? parts : [text2];
|
|
4120
|
-
}
|
|
4121
|
-
function hasVisibleContent(content) {
|
|
4122
|
-
return content.some(
|
|
4123
|
-
(part) => part.type === "tool-call" || part.type === "text" && part.text.trim().length > 0 || part.type === "reasoning" && part.text.trim().length > 0
|
|
4124
|
-
);
|
|
4125
|
-
}
|
|
4126
|
-
const TextShimmerLoader = ({
|
|
4127
|
-
text: text2 = "Thinking...",
|
|
4128
|
-
className
|
|
4129
|
-
}) => /* @__PURE__ */ jsx(
|
|
4130
|
-
"span",
|
|
4131
|
-
{
|
|
4132
|
-
className: cn(
|
|
4133
|
-
"inline-block w-min animate-shimmer-ltr bg-gradient-to-r from-gray-500 via-gray-300 to-gray-500 bg-[200%_auto] bg-clip-text !text-transparent",
|
|
4134
|
-
className
|
|
4135
|
-
),
|
|
4136
|
-
children: text2
|
|
4137
469
|
}
|
|
4138
|
-
);
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
}
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
tooltip,
|
|
4164
|
-
className,
|
|
4165
|
-
...props
|
|
4166
|
-
}) {
|
|
4167
|
-
return /* @__PURE__ */ jsx(
|
|
4168
|
-
"button",
|
|
4169
|
-
{
|
|
4170
|
-
type: "button",
|
|
4171
|
-
title: tooltip,
|
|
4172
|
-
"aria-label": tooltip,
|
|
4173
|
-
className: cn(
|
|
4174
|
-
"inline-flex size-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
|
|
4175
|
-
className
|
|
4176
|
-
),
|
|
4177
|
-
...props,
|
|
4178
|
-
children
|
|
4179
|
-
}
|
|
4180
|
-
);
|
|
4181
|
-
}
|
|
4182
|
-
function SmallIconButton({
|
|
4183
|
-
children,
|
|
4184
|
-
tooltip,
|
|
4185
|
-
className,
|
|
4186
|
-
...props
|
|
470
|
+
const thumbnail = assetTypeToThumb(conversation.assetType ?? "session");
|
|
471
|
+
if (thumbnail) {
|
|
472
|
+
return /* @__PURE__ */ jsx("img", { src: thumbnail, alt: "", className: "mt-0.5 size-4 shrink-0" });
|
|
473
|
+
}
|
|
474
|
+
return automated ? /* @__PURE__ */ jsx(Bot, { className: "mt-0.5 size-4 shrink-0 text-primary" }) : /* @__PURE__ */ jsx(MessageSquare, { className: "mt-0.5 size-4 shrink-0 text-emerald-500" });
|
|
475
|
+
}
|
|
476
|
+
function ConversationHistoryPanel({
|
|
477
|
+
conversations,
|
|
478
|
+
activeThreadId,
|
|
479
|
+
search,
|
|
480
|
+
onSearchChange,
|
|
481
|
+
activityFilter,
|
|
482
|
+
onActivityFilterChange,
|
|
483
|
+
originFilter,
|
|
484
|
+
onOriginFilterChange,
|
|
485
|
+
onSelect,
|
|
486
|
+
onNewChat,
|
|
487
|
+
onRefresh,
|
|
488
|
+
onArchive,
|
|
489
|
+
onSetReadState,
|
|
490
|
+
isLoading = false,
|
|
491
|
+
isRefreshing = false,
|
|
492
|
+
hasNextPage = false,
|
|
493
|
+
isFetchingNextPage = false,
|
|
494
|
+
onLoadMore
|
|
4187
495
|
}) {
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
type: "button",
|
|
4192
|
-
title: tooltip,
|
|
4193
|
-
className: cn(
|
|
4194
|
-
"inline-flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",
|
|
4195
|
-
className
|
|
4196
|
-
),
|
|
4197
|
-
...props,
|
|
4198
|
-
children
|
|
4199
|
-
}
|
|
496
|
+
const origins = useMemo(
|
|
497
|
+
() => [...new Set(conversations.map(originKey))].sort(),
|
|
498
|
+
[conversations]
|
|
4200
499
|
);
|
|
4201
|
-
|
|
4202
|
-
const
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
]
|
|
4224
|
-
}
|
|
4225
|
-
);
|
|
4226
|
-
const CopyActionButton = () => /* @__PURE__ */ jsx(ActionBarPrimitive.Copy, { asChild: true, children: /* @__PURE__ */ jsxs(SmallIconButton, { tooltip: "Copy", children: [
|
|
4227
|
-
/* @__PURE__ */ jsx(AuiIf, { condition: (state) => state.message.isCopied, children: /* @__PURE__ */ jsx(Check, { className: "size-3" }) }),
|
|
4228
|
-
/* @__PURE__ */ jsx(AuiIf, { condition: (state) => !state.message.isCopied, children: /* @__PURE__ */ jsx(Copy, { className: "size-3" }) })
|
|
4229
|
-
] }) });
|
|
4230
|
-
function CodeBlock({ language, code: code2 }) {
|
|
4231
|
-
return /* @__PURE__ */ jsxs("div", { className: "not-prose my-2 overflow-hidden rounded-lg border border-border bg-muted/30", children: [
|
|
4232
|
-
language && /* @__PURE__ */ jsx("div", { className: "border-b border-border bg-muted/50 px-3 py-1 text-[10px] font-medium text-muted-foreground", children: language }),
|
|
4233
|
-
/* @__PURE__ */ jsx("pre", { className: "overflow-x-auto p-3", children: /* @__PURE__ */ jsx("code", { className: "font-mono text-xs leading-relaxed text-foreground", children: code2 }) })
|
|
4234
|
-
] });
|
|
4235
|
-
}
|
|
4236
|
-
const MARKDOWN_CLASS = "aui-md prose prose-sm max-w-none text-foreground prose-p:my-1.5 prose-p:leading-relaxed prose-headings:mt-3 prose-headings:mb-1.5 prose-headings:font-semibold prose-h1:text-sm prose-h2:text-sm prose-h3:text-xs prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-blockquote:border-l-2 prose-blockquote:border-border prose-blockquote:text-muted-foreground prose-code:rounded prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:text-xs prose-code:font-mono prose-code:before:content-none prose-code:after:content-none prose-pre:my-0 prose-pre:p-0 prose-pre:bg-transparent prose-pre:border-0 prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-strong:font-semibold prose-hr:border-border";
|
|
4237
|
-
const MarkdownText = () => /* @__PURE__ */ jsx(
|
|
4238
|
-
MarkdownTextPrimitive,
|
|
4239
|
-
{
|
|
4240
|
-
className: MARKDOWN_CLASS,
|
|
4241
|
-
remarkPlugins: [remarkGfm],
|
|
4242
|
-
smooth: true,
|
|
4243
|
-
preprocess: normalizeAthenaMentionHtml,
|
|
4244
|
-
components: {
|
|
4245
|
-
SyntaxHighlighter: CodeBlock,
|
|
4246
|
-
a: MentionLink
|
|
4247
|
-
}
|
|
4248
|
-
}
|
|
4249
|
-
);
|
|
4250
|
-
const UserMessageText = ({ text: text2 }) => /* @__PURE__ */ jsx(Fragment, { children: parseMentionsInText(text2) });
|
|
4251
|
-
const UserActionBar = () => /* @__PURE__ */ jsx(
|
|
4252
|
-
ActionBarPrimitive.Root,
|
|
4253
|
-
{
|
|
4254
|
-
autohide: "never",
|
|
4255
|
-
className: "pointer-events-none flex min-h-6 items-center gap-0.5 opacity-0 transition-opacity group-hover/user-message:pointer-events-auto group-hover/user-message:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100",
|
|
4256
|
-
children: /* @__PURE__ */ jsx(CopyActionButton, {})
|
|
4257
|
-
}
|
|
4258
|
-
);
|
|
4259
|
-
const UserMessage = () => /* @__PURE__ */ jsx(MessagePrimitive.Root, { className: "group/user-message mb-3 flex justify-end", children: /* @__PURE__ */ jsxs("div", { className: "flex max-w-[85%] flex-col items-end gap-1", children: [
|
|
4260
|
-
/* @__PURE__ */ jsx("div", { className: "rounded-2xl rounded-br-md bg-muted px-3.5 py-2 text-sm text-foreground", children: /* @__PURE__ */ jsx(MessagePrimitive.Content, { components: { Text: UserMessageText } }) }),
|
|
4261
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-h-6 items-center gap-1", children: [
|
|
4262
|
-
/* @__PURE__ */ jsx(BranchPicker, {}),
|
|
4263
|
-
/* @__PURE__ */ jsx(UserActionBar, {})
|
|
4264
|
-
] })
|
|
4265
|
-
] }) });
|
|
4266
|
-
function createAssistantMessage({
|
|
4267
|
-
toolFallback,
|
|
4268
|
-
extraActions,
|
|
4269
|
-
content: Content
|
|
4270
|
-
}) {
|
|
4271
|
-
const AssistantActionBar = () => /* @__PURE__ */ jsxs(
|
|
4272
|
-
ActionBarPrimitive.Root,
|
|
4273
|
-
{
|
|
4274
|
-
autohide: "never",
|
|
4275
|
-
className: "mt-1 flex min-h-6 items-center gap-0.5",
|
|
4276
|
-
children: [
|
|
4277
|
-
/* @__PURE__ */ jsx(CopyActionButton, {}),
|
|
4278
|
-
/* @__PURE__ */ jsx(ActionBarPrimitive.Reload, { asChild: true, children: /* @__PURE__ */ jsx(SmallIconButton, { tooltip: "Regenerate", children: /* @__PURE__ */ jsx(RefreshCw, { className: "size-3" }) }) }),
|
|
4279
|
-
extraActions
|
|
4280
|
-
]
|
|
4281
|
-
}
|
|
500
|
+
const grouped = useMemo(() => {
|
|
501
|
+
const visible = conversations.filter((conversation) => {
|
|
502
|
+
const automated = isAutomatedConversation(conversation);
|
|
503
|
+
if (activityFilter === "chat" && automated) return false;
|
|
504
|
+
if (activityFilter === "automated" && !automated) return false;
|
|
505
|
+
return originFilter === "all" || originKey(conversation) === originFilter;
|
|
506
|
+
});
|
|
507
|
+
const byGroup = /* @__PURE__ */ new Map();
|
|
508
|
+
for (const conversation of visible) {
|
|
509
|
+
const group = conversationTimeGroup(conversation.updatedAt);
|
|
510
|
+
const items = byGroup.get(group) ?? [];
|
|
511
|
+
items.push(conversation);
|
|
512
|
+
byGroup.set(group, items);
|
|
513
|
+
}
|
|
514
|
+
return TIME_GROUPS.flatMap((group) => {
|
|
515
|
+
const items = byGroup.get(group);
|
|
516
|
+
return items ? [{ group, items }] : [];
|
|
517
|
+
});
|
|
518
|
+
}, [activityFilter, conversations, originFilter]);
|
|
519
|
+
const visibleCount = grouped.reduce(
|
|
520
|
+
(count, group) => count + group.items.length,
|
|
521
|
+
0
|
|
4282
522
|
);
|
|
4283
|
-
const
|
|
4284
|
-
const showActions = useAuiState(
|
|
4285
|
-
(state) => hasVisibleContent(state.message.content)
|
|
4286
|
-
);
|
|
4287
|
-
return /* @__PURE__ */ jsx(MessagePrimitive.Root, { className: "group mb-3", children: /* @__PURE__ */ jsxs("div", { className: "max-w-[95%]", children: [
|
|
4288
|
-
Content ? /* @__PURE__ */ jsx(Content, {}) : /* @__PURE__ */ jsx(
|
|
4289
|
-
MessagePrimitive.Content,
|
|
4290
|
-
{
|
|
4291
|
-
components: {
|
|
4292
|
-
Text: MarkdownText,
|
|
4293
|
-
tools: { Fallback: toolFallback }
|
|
4294
|
-
}
|
|
4295
|
-
}
|
|
4296
|
-
),
|
|
4297
|
-
showActions ? /* @__PURE__ */ jsxs("div", { className: "flex min-h-6 items-center gap-1", children: [
|
|
4298
|
-
/* @__PURE__ */ jsx(BranchPicker, {}),
|
|
4299
|
-
/* @__PURE__ */ jsx(AssistantActionBar, {})
|
|
4300
|
-
] }) : null
|
|
4301
|
-
] }) });
|
|
4302
|
-
};
|
|
4303
|
-
return AssistantMessage;
|
|
4304
|
-
}
|
|
4305
|
-
const THREAD_PANEL_CLASS = "m-1 flex min-h-0 flex-1 flex-col overflow-hidden rounded-[18px] border border-dashed border-amber-500 bg-background shadow-[0_1px_10px_rgba(54,45,33,0.08)]";
|
|
4306
|
-
const THREAD_HEADER_CLASS = "flex items-center justify-between gap-2 px-3 py-2";
|
|
4307
|
-
const THREAD_HEADER_ACTIONS_CLASS = "flex min-w-0 items-center justify-end gap-1.5";
|
|
4308
|
-
const THREAD_HEADER_PILL_CLASS = "inline-flex h-7 max-w-[170px] items-center gap-1.5 rounded-md border border-neutral-200 bg-white px-2 text-xs font-medium text-neutral-800 shadow-sm";
|
|
4309
|
-
const THREAD_HEADER_ICON_CLASS = "size-[18px]";
|
|
4310
|
-
const COMPOSER_DOCK_CLASS = "bg-background px-2.5 pb-2 pt-1.5";
|
|
4311
|
-
const COMPOSER_SURFACE_CLASS = "relative flex flex-col gap-1 rounded-xl border border-neutral-200 bg-white shadow-[0_2px_10px_rgba(54,45,33,0.08)]";
|
|
4312
|
-
const COMPOSER_EDITOR_ROW_CLASS = "px-2.5 pt-1";
|
|
4313
|
-
const COMPOSER_TOOLBAR_CLASS = "flex items-center gap-1 border-t border-neutral-100 px-2 py-1.5";
|
|
4314
|
-
const THREAD_SCROLL_TO_BOTTOM_CLASS = "inline-flex items-center justify-center rounded-full border bg-background/80 p-1 shadow-sm backdrop-blur transition-opacity hover:bg-accent disabled:invisible";
|
|
4315
|
-
const ComposerStopIcon = () => /* @__PURE__ */ jsx(
|
|
4316
|
-
"svg",
|
|
4317
|
-
{
|
|
4318
|
-
"aria-hidden": "true",
|
|
4319
|
-
className: "size-4",
|
|
4320
|
-
viewBox: "0 0 16 16",
|
|
4321
|
-
fill: "currentColor",
|
|
4322
|
-
children: /* @__PURE__ */ jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" })
|
|
4323
|
-
}
|
|
4324
|
-
);
|
|
4325
|
-
const ComposerStopButton = ({ onStop, disabled = false, title = "Stop generation" }) => /* @__PURE__ */ jsx(
|
|
4326
|
-
"button",
|
|
4327
|
-
{
|
|
4328
|
-
type: "button",
|
|
4329
|
-
onClick: onStop,
|
|
4330
|
-
disabled,
|
|
4331
|
-
title,
|
|
4332
|
-
className: cn(
|
|
4333
|
-
"inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-foreground text-background shadow-sm transition-colors hover:bg-foreground/80",
|
|
4334
|
-
disabled && "cursor-not-allowed opacity-60"
|
|
4335
|
-
),
|
|
4336
|
-
children: /* @__PURE__ */ jsx(ComposerStopIcon, {})
|
|
4337
|
-
}
|
|
4338
|
-
);
|
|
4339
|
-
const ComposerSendButton = ({ action, onSend, disabled = false, title }) => /* @__PURE__ */ jsx(
|
|
4340
|
-
"button",
|
|
4341
|
-
{
|
|
4342
|
-
type: "button",
|
|
4343
|
-
onClick: onSend,
|
|
4344
|
-
disabled,
|
|
4345
|
-
title: title ?? (action === "queue" ? "Queue message" : "Send"),
|
|
4346
|
-
className: cn(
|
|
4347
|
-
"inline-flex size-8 shrink-0 items-center justify-center rounded-full shadow-sm transition-colors",
|
|
4348
|
-
disabled ? "cursor-not-allowed bg-muted text-muted-foreground opacity-60" : "bg-foreground text-background hover:bg-foreground/80"
|
|
4349
|
-
),
|
|
4350
|
-
children: action === "queue" ? /* @__PURE__ */ jsx(ListPlus, { className: "size-4" }) : /* @__PURE__ */ jsx(ArrowUp, { className: "size-4" })
|
|
4351
|
-
}
|
|
4352
|
-
);
|
|
4353
|
-
function ChatThreadShell({
|
|
4354
|
-
header,
|
|
4355
|
-
banners,
|
|
4356
|
-
viewportOverlay,
|
|
4357
|
-
welcome,
|
|
4358
|
-
components,
|
|
4359
|
-
renderMessages,
|
|
4360
|
-
belowViewport,
|
|
4361
|
-
composer
|
|
4362
|
-
}) {
|
|
4363
|
-
const messages = /* @__PURE__ */ jsx(ThreadPrimitive.Messages, { components });
|
|
523
|
+
const handleSearch = (event) => onSearchChange(event.target.value);
|
|
4364
524
|
return /* @__PURE__ */ jsxs(
|
|
4365
|
-
|
|
525
|
+
"section",
|
|
4366
526
|
{
|
|
4367
|
-
|
|
4368
|
-
|
|
527
|
+
"aria-label": "Conversation history",
|
|
528
|
+
className: "border-b border-border bg-background px-2 pb-2",
|
|
529
|
+
"data-testid": "conversation-history-panel",
|
|
4369
530
|
children: [
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
531
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-10 items-center gap-1.5 px-1", children: [
|
|
532
|
+
/* @__PURE__ */ jsx("h2", { className: "text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground", children: "Sessions" }),
|
|
533
|
+
/* @__PURE__ */ jsx(
|
|
534
|
+
"button",
|
|
535
|
+
{
|
|
536
|
+
type: "button",
|
|
537
|
+
"aria-label": "Refresh sessions",
|
|
538
|
+
title: "Refresh sessions",
|
|
539
|
+
disabled: isRefreshing,
|
|
540
|
+
onClick: onRefresh,
|
|
541
|
+
className: "ml-auto rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50",
|
|
542
|
+
children: /* @__PURE__ */ jsx(
|
|
543
|
+
RefreshCw,
|
|
544
|
+
{
|
|
545
|
+
className: cn("size-3.5", isRefreshing && "animate-spin")
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
),
|
|
550
|
+
/* @__PURE__ */ jsxs(
|
|
551
|
+
"button",
|
|
552
|
+
{
|
|
553
|
+
type: "button",
|
|
554
|
+
onClick: onNewChat,
|
|
555
|
+
className: "flex h-7 shrink-0 items-center gap-1 rounded-md bg-primary px-2 text-[11px] font-medium text-primary-foreground",
|
|
556
|
+
children: [
|
|
557
|
+
/* @__PURE__ */ jsx(Plus, { className: "size-3" }),
|
|
558
|
+
" New"
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
)
|
|
562
|
+
] }),
|
|
563
|
+
/* @__PURE__ */ jsxs("label", { className: "relative block min-w-0 px-1 pb-2", children: [
|
|
564
|
+
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-[calc(50%+0.25rem)] text-muted-foreground" }),
|
|
565
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Search sessions" }),
|
|
566
|
+
/* @__PURE__ */ jsx(
|
|
567
|
+
"input",
|
|
568
|
+
{
|
|
569
|
+
value: search,
|
|
570
|
+
onChange: handleSearch,
|
|
571
|
+
placeholder: "Search sessions...",
|
|
572
|
+
className: "h-8 w-full rounded-md border border-border bg-muted/40 pl-7 pr-2 text-xs outline-none focus:border-primary focus:bg-background"
|
|
573
|
+
}
|
|
574
|
+
)
|
|
575
|
+
] }),
|
|
576
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1 overflow-x-auto px-1 pb-2 text-[11px]", children: [
|
|
577
|
+
["all", "chat", "automated"].map((filter) => /* @__PURE__ */ jsx(
|
|
578
|
+
"button",
|
|
579
|
+
{
|
|
580
|
+
type: "button",
|
|
581
|
+
onClick: () => onActivityFilterChange(filter),
|
|
582
|
+
className: cn(
|
|
583
|
+
"rounded-full border px-2 py-1 capitalize",
|
|
584
|
+
activityFilter === filter ? "border-primary bg-primary/10 text-primary" : "border-border text-muted-foreground"
|
|
585
|
+
),
|
|
586
|
+
children: filter === "chat" ? "Chats" : filter === "automated" ? "Automations" : "All"
|
|
587
|
+
},
|
|
588
|
+
filter
|
|
589
|
+
)),
|
|
590
|
+
/* @__PURE__ */ jsxs(
|
|
591
|
+
"select",
|
|
4381
592
|
{
|
|
4382
|
-
"aria-label": "
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
593
|
+
"aria-label": "Filter by origin",
|
|
594
|
+
value: originFilter,
|
|
595
|
+
onChange: (event) => onOriginFilterChange(event.target.value),
|
|
596
|
+
className: "ml-auto rounded-full border border-border bg-background px-2 text-[11px] text-muted-foreground",
|
|
597
|
+
children: [
|
|
598
|
+
/* @__PURE__ */ jsx("option", { value: "all", children: "All origins" }),
|
|
599
|
+
origins.map((origin) => /* @__PURE__ */ jsx("option", { value: origin, children: originLabel(origin) }, origin))
|
|
600
|
+
]
|
|
4386
601
|
}
|
|
4387
|
-
)
|
|
602
|
+
)
|
|
4388
603
|
] }),
|
|
4389
|
-
|
|
4390
|
-
|
|
604
|
+
/* @__PURE__ */ jsxs("div", { className: "max-h-[min(60vh,28rem)] overflow-y-auto px-0.5", children: [
|
|
605
|
+
isLoading ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-2 py-4 text-xs text-muted-foreground", children: [
|
|
606
|
+
/* @__PURE__ */ jsx(LoaderCircle, { className: "size-3.5 animate-spin" }),
|
|
607
|
+
" Loading sessions…"
|
|
608
|
+
] }) : visibleCount === 0 ? /* @__PURE__ */ jsx("p", { className: "px-2 py-4 text-xs text-muted-foreground", children: "No matching sessions." }) : grouped.map(({ group, items }) => /* @__PURE__ */ jsxs("div", { children: [
|
|
609
|
+
/* @__PURE__ */ jsx("h3", { className: "px-2 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/75", children: group }),
|
|
610
|
+
items.map((conversation) => {
|
|
611
|
+
const automated = isAutomatedConversation(conversation);
|
|
612
|
+
return /* @__PURE__ */ jsxs(
|
|
613
|
+
"div",
|
|
614
|
+
{
|
|
615
|
+
className: cn(
|
|
616
|
+
"group flex items-start gap-2 rounded-md px-2 py-2 hover:bg-accent",
|
|
617
|
+
conversation.threadId === activeThreadId && "bg-primary/10 text-primary"
|
|
618
|
+
),
|
|
619
|
+
children: [
|
|
620
|
+
/* @__PURE__ */ jsxs(
|
|
621
|
+
"button",
|
|
622
|
+
{
|
|
623
|
+
type: "button",
|
|
624
|
+
onClick: () => {
|
|
625
|
+
onSelect(conversation.threadId);
|
|
626
|
+
if (conversation.isUnread) {
|
|
627
|
+
onSetReadState(conversation.threadId, false);
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
className: "flex min-w-0 flex-1 items-start gap-2 text-left",
|
|
631
|
+
children: [
|
|
632
|
+
/* @__PURE__ */ jsx(
|
|
633
|
+
ConversationTypeIcon,
|
|
634
|
+
{
|
|
635
|
+
conversation,
|
|
636
|
+
automated
|
|
637
|
+
}
|
|
638
|
+
),
|
|
639
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
640
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-start gap-1", children: [
|
|
641
|
+
/* @__PURE__ */ jsx("span", { className: "line-clamp-2 flex-1 text-xs font-medium leading-snug", children: conversationDisplayTitle(conversation) }),
|
|
642
|
+
conversation.isUnread ? /* @__PURE__ */ jsx(
|
|
643
|
+
"span",
|
|
644
|
+
{
|
|
645
|
+
"aria-label": "Unread",
|
|
646
|
+
className: "mt-1 size-1.5 shrink-0 rounded-full bg-primary"
|
|
647
|
+
}
|
|
648
|
+
) : null
|
|
649
|
+
] }),
|
|
650
|
+
/* @__PURE__ */ jsxs("span", { className: "mt-0.5 flex items-center gap-1.5 text-[10px] text-muted-foreground", children: [
|
|
651
|
+
/* @__PURE__ */ jsx("span", { children: relativeTime(conversation.updatedAt) }),
|
|
652
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "·" }),
|
|
653
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: originLabel(originKey(conversation)) })
|
|
654
|
+
] })
|
|
655
|
+
] })
|
|
656
|
+
]
|
|
657
|
+
}
|
|
658
|
+
),
|
|
659
|
+
/* @__PURE__ */ jsx(
|
|
660
|
+
"button",
|
|
661
|
+
{
|
|
662
|
+
type: "button",
|
|
663
|
+
"aria-label": `Archive ${conversationDisplayTitle(conversation)}`,
|
|
664
|
+
title: "Archive conversation",
|
|
665
|
+
onClick: () => onArchive(conversation.threadId),
|
|
666
|
+
className: "invisible rounded p-1 text-muted-foreground hover:bg-background hover:text-foreground group-hover:visible focus:visible",
|
|
667
|
+
children: /* @__PURE__ */ jsx(Archive, { className: "size-3.5" })
|
|
668
|
+
}
|
|
669
|
+
)
|
|
670
|
+
]
|
|
671
|
+
},
|
|
672
|
+
conversation.threadId
|
|
673
|
+
);
|
|
674
|
+
})
|
|
675
|
+
] }, group)),
|
|
676
|
+
hasNextPage ? /* @__PURE__ */ jsx(
|
|
677
|
+
"button",
|
|
678
|
+
{
|
|
679
|
+
type: "button",
|
|
680
|
+
disabled: isFetchingNextPage,
|
|
681
|
+
onClick: onLoadMore,
|
|
682
|
+
className: "mt-1 w-full rounded-lg py-2 text-xs text-muted-foreground hover:bg-accent disabled:opacity-50",
|
|
683
|
+
children: isFetchingNextPage ? "Loading…" : "Load older sessions"
|
|
684
|
+
}
|
|
685
|
+
) : visibleCount > 0 ? /* @__PURE__ */ jsx("p", { className: "py-2 text-center text-[10px] text-muted-foreground/70", children: "No more sessions" }) : null
|
|
686
|
+
] })
|
|
4391
687
|
]
|
|
4392
688
|
}
|
|
4393
689
|
);
|
|
4394
690
|
}
|
|
4395
|
-
function ChatComposerDock({
|
|
4396
|
-
aboveSurface,
|
|
4397
|
-
beforeEditor,
|
|
4398
|
-
editor,
|
|
4399
|
-
toolbarStart,
|
|
4400
|
-
toolbarEnd
|
|
4401
|
-
}) {
|
|
4402
|
-
return /* @__PURE__ */ jsxs("div", { className: COMPOSER_DOCK_CLASS, children: [
|
|
4403
|
-
aboveSurface,
|
|
4404
|
-
/* @__PURE__ */ jsxs(ComposerPrimitive.Root, { className: COMPOSER_SURFACE_CLASS, children: [
|
|
4405
|
-
beforeEditor,
|
|
4406
|
-
/* @__PURE__ */ jsx("div", { className: COMPOSER_EDITOR_ROW_CLASS, children: editor }),
|
|
4407
|
-
/* @__PURE__ */ jsxs("div", { className: COMPOSER_TOOLBAR_CLASS, children: [
|
|
4408
|
-
toolbarStart,
|
|
4409
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
4410
|
-
toolbarEnd
|
|
4411
|
-
] })
|
|
4412
|
-
] })
|
|
4413
|
-
] });
|
|
4414
|
-
}
|
|
4415
|
-
function resolveComposerAction({
|
|
4416
|
-
hasDraft,
|
|
4417
|
-
isRunning
|
|
4418
|
-
}) {
|
|
4419
|
-
if (!isRunning) return "send";
|
|
4420
|
-
return hasDraft ? "queue" : "stop";
|
|
4421
|
-
}
|
|
4422
|
-
const ComposerSendOrStop = ({
|
|
4423
|
-
composerRef,
|
|
4424
|
-
hasDraft,
|
|
4425
|
-
disabled = false,
|
|
4426
|
-
sendBlockedReason = null,
|
|
4427
|
-
sendDisabledTitle,
|
|
4428
|
-
stopDisabledTitle,
|
|
4429
|
-
onBeforeSend,
|
|
4430
|
-
onStop
|
|
4431
|
-
}) => {
|
|
4432
|
-
const aui = useAui();
|
|
4433
|
-
const isRunning = useAuiState(
|
|
4434
|
-
(state) => {
|
|
4435
|
-
var _a;
|
|
4436
|
-
return ((_a = state.optional.thread) == null ? void 0 : _a.isRunning) ?? false;
|
|
4437
|
-
}
|
|
4438
|
-
);
|
|
4439
|
-
const action = resolveComposerAction({ hasDraft, isRunning });
|
|
4440
|
-
const cancelRun = useCallback(() => {
|
|
4441
|
-
try {
|
|
4442
|
-
aui.thread.cancelRun();
|
|
4443
|
-
return true;
|
|
4444
|
-
} catch (error) {
|
|
4445
|
-
console.warn("[chat-ui] cancelRun failed", error);
|
|
4446
|
-
return false;
|
|
4447
|
-
}
|
|
4448
|
-
}, [aui]);
|
|
4449
|
-
if (action === "stop") {
|
|
4450
|
-
return /* @__PURE__ */ jsx(
|
|
4451
|
-
ComposerStopButton,
|
|
4452
|
-
{
|
|
4453
|
-
onStop: () => {
|
|
4454
|
-
if (onStop) {
|
|
4455
|
-
onStop({ cancelRun });
|
|
4456
|
-
} else {
|
|
4457
|
-
cancelRun();
|
|
4458
|
-
}
|
|
4459
|
-
},
|
|
4460
|
-
disabled,
|
|
4461
|
-
title: disabled && stopDisabledTitle ? stopDisabledTitle : void 0
|
|
4462
|
-
}
|
|
4463
|
-
);
|
|
4464
|
-
}
|
|
4465
|
-
const handleSend = async () => {
|
|
4466
|
-
var _a;
|
|
4467
|
-
await (onBeforeSend == null ? void 0 : onBeforeSend({ action }));
|
|
4468
|
-
await ((_a = composerRef.current) == null ? void 0 : _a.submit());
|
|
4469
|
-
};
|
|
4470
|
-
const sendTitle = disabled && sendDisabledTitle ? sendDisabledTitle : sendBlockedReason ?? void 0;
|
|
4471
|
-
return /* @__PURE__ */ jsx(
|
|
4472
|
-
ComposerSendButton,
|
|
4473
|
-
{
|
|
4474
|
-
action,
|
|
4475
|
-
onSend: () => void handleSend(),
|
|
4476
|
-
disabled: disabled || !hasDraft || sendBlockedReason != null,
|
|
4477
|
-
title: sendTitle
|
|
4478
|
-
}
|
|
4479
|
-
);
|
|
4480
|
-
};
|
|
4481
691
|
function makeMentionUrl(attrs) {
|
|
4482
692
|
if (attrs.type === "tool") {
|
|
4483
693
|
return `mention://tool?name=${encodeURIComponent(attrs.id)}&description=${encodeURIComponent(attrs.description ?? "")}`;
|
|
@@ -4570,8 +780,8 @@ const MentionExtension = Node.create({
|
|
|
4570
780
|
}
|
|
4571
781
|
];
|
|
4572
782
|
},
|
|
4573
|
-
renderHTML({ node
|
|
4574
|
-
const thumbnailUrl =
|
|
783
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
784
|
+
const thumbnailUrl = node.attrs.thumbnailUrl;
|
|
4575
785
|
const children = [];
|
|
4576
786
|
if (thumbnailUrl) {
|
|
4577
787
|
children.push([
|
|
@@ -4584,35 +794,35 @@ const MentionExtension = Node.create({
|
|
|
4584
794
|
}
|
|
4585
795
|
]);
|
|
4586
796
|
}
|
|
4587
|
-
children.push(["span", { class: "mention-chip-text" },
|
|
797
|
+
children.push(["span", { class: "mention-chip-text" }, node.attrs.name]);
|
|
4588
798
|
return [
|
|
4589
799
|
"span",
|
|
4590
800
|
mergeAttributes(HTMLAttributes, {
|
|
4591
801
|
"data-mention": "",
|
|
4592
|
-
"data-type":
|
|
4593
|
-
"data-name":
|
|
4594
|
-
"data-id":
|
|
4595
|
-
"data-title":
|
|
4596
|
-
"data-url":
|
|
4597
|
-
"data-thumbnail-url":
|
|
4598
|
-
"data-asset-type":
|
|
802
|
+
"data-type": node.attrs.type,
|
|
803
|
+
"data-name": node.attrs.name,
|
|
804
|
+
"data-id": node.attrs.id,
|
|
805
|
+
"data-title": node.attrs.title || "",
|
|
806
|
+
"data-url": node.attrs.url || "",
|
|
807
|
+
"data-thumbnail-url": node.attrs.thumbnailUrl || "",
|
|
808
|
+
"data-asset-type": node.attrs.assetType || "",
|
|
4599
809
|
class: "mention-chip"
|
|
4600
810
|
}),
|
|
4601
811
|
...children
|
|
4602
812
|
];
|
|
4603
813
|
},
|
|
4604
|
-
renderText({ node
|
|
814
|
+
renderText({ node }) {
|
|
4605
815
|
const url = makeMentionUrl({
|
|
4606
|
-
id:
|
|
4607
|
-
type:
|
|
4608
|
-
name:
|
|
4609
|
-
title:
|
|
4610
|
-
url:
|
|
4611
|
-
description:
|
|
4612
|
-
thumbnailUrl:
|
|
4613
|
-
assetType:
|
|
816
|
+
id: node.attrs.id,
|
|
817
|
+
type: node.attrs.type,
|
|
818
|
+
name: node.attrs.name,
|
|
819
|
+
title: node.attrs.title,
|
|
820
|
+
url: node.attrs.url,
|
|
821
|
+
description: node.attrs.description,
|
|
822
|
+
thumbnailUrl: node.attrs.thumbnailUrl,
|
|
823
|
+
assetType: node.attrs.assetType
|
|
4614
824
|
});
|
|
4615
|
-
return `[@${
|
|
825
|
+
return `[@${node.attrs.name}](${url})`;
|
|
4616
826
|
}
|
|
4617
827
|
});
|
|
4618
828
|
const MentionSuggestionsExtension = Extension.create({
|
|
@@ -5030,7 +1240,7 @@ function MenuList({
|
|
|
5030
1240
|
const previousSection = (_a = items[index - 1]) == null ? void 0 : _a.menuSection;
|
|
5031
1241
|
const startsOtherWebpages = item.menuSection === MentionMenuSection.OTHER_WEBPAGES && previousSection !== MentionMenuSection.OTHER_WEBPAGES;
|
|
5032
1242
|
const startsLibrary = item.menuSection === MentionMenuSection.LIBRARY && (previousSection === MentionMenuSection.CURRENT_WEBPAGE || previousSection === MentionMenuSection.OTHER_WEBPAGES);
|
|
5033
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
1243
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5034
1244
|
startsOtherWebpages && /* @__PURE__ */ jsx("div", { className: "px-2 pb-1 pt-2 text-[11px] font-medium uppercase tracking-wide text-gray-400", children: "Other webpages in this group" }),
|
|
5035
1245
|
startsLibrary && /* @__PURE__ */ jsx("div", { className: "mx-2 my-1 border-t border-gray-100" }),
|
|
5036
1246
|
/* @__PURE__ */ jsx("div", { ref: index === selectedIndex ? selectedRef : void 0, children: /* @__PURE__ */ jsx(
|
|
@@ -5827,17 +2037,17 @@ const MENTION_STYLES = `
|
|
|
5827
2037
|
height: 0;
|
|
5828
2038
|
}
|
|
5829
2039
|
`;
|
|
5830
|
-
function plainTextToTiptapContent(
|
|
2040
|
+
function plainTextToTiptapContent(text) {
|
|
5831
2041
|
return {
|
|
5832
2042
|
type: "doc",
|
|
5833
|
-
content:
|
|
2043
|
+
content: text.split("\n").map((line) => ({
|
|
5834
2044
|
type: "paragraph",
|
|
5835
2045
|
...line.length > 0 ? { content: [{ type: "text", text: line }] } : {}
|
|
5836
2046
|
}))
|
|
5837
2047
|
};
|
|
5838
2048
|
}
|
|
5839
2049
|
const NO_WEBPAGES = [];
|
|
5840
|
-
const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to mention)", threadId, disabled = false, webpages = NO_WEBPAGES, rootCategories, onDraftStateChange }, outerRef) => {
|
|
2050
|
+
const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to mention)", threadId, disabled = false, webpages = NO_WEBPAGES, rootCategories, onDraftStateChange, interceptSubmit }, outerRef) => {
|
|
5841
2051
|
const aui = useAui();
|
|
5842
2052
|
const composerInput = unstable_useComposerInput();
|
|
5843
2053
|
const applyingRuntimeTextRef = useRef(false);
|
|
@@ -5869,6 +2079,7 @@ const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to
|
|
|
5869
2079
|
});
|
|
5870
2080
|
const editorRef = useRef(null);
|
|
5871
2081
|
const handleSubmit = useCallback(async () => {
|
|
2082
|
+
var _a;
|
|
5872
2083
|
if (disabled) return;
|
|
5873
2084
|
if (submitInFlightRef.current) return;
|
|
5874
2085
|
submitInFlightRef.current = true;
|
|
@@ -5876,17 +2087,25 @@ const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to
|
|
|
5876
2087
|
await pendingUploadsRef.current.waitForIdle();
|
|
5877
2088
|
const ed = editorRef.current;
|
|
5878
2089
|
if (!ed) return;
|
|
5879
|
-
const
|
|
5880
|
-
if (!
|
|
2090
|
+
const text = ed.getText({ blockSeparator: "\n" }).trim();
|
|
2091
|
+
if (!text) return;
|
|
5881
2092
|
if (!composerInput.canSend) return;
|
|
5882
|
-
|
|
2093
|
+
if (interceptSubmit) {
|
|
2094
|
+
const hasAttachments = (((_a = aui.composer.getState().attachments) == null ? void 0 : _a.length) ?? 0) > 0;
|
|
2095
|
+
if (!hasAttachments && await interceptSubmit(text)) {
|
|
2096
|
+
ed.commands.clearContent();
|
|
2097
|
+
onDraftStateChange == null ? void 0 : onDraftStateChange(false);
|
|
2098
|
+
return;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
composerInput.setText(text);
|
|
5883
2102
|
composerInput.send({ steer: false });
|
|
5884
2103
|
ed.commands.clearContent();
|
|
5885
2104
|
onDraftStateChange == null ? void 0 : onDraftStateChange(false);
|
|
5886
2105
|
} finally {
|
|
5887
2106
|
submitInFlightRef.current = false;
|
|
5888
2107
|
}
|
|
5889
|
-
}, [composerInput, disabled, onDraftStateChange]);
|
|
2108
|
+
}, [composerInput, disabled, interceptSubmit, onDraftStateChange]);
|
|
5890
2109
|
const handleSubmitRef = useRef(handleSubmit);
|
|
5891
2110
|
handleSubmitRef.current = handleSubmit;
|
|
5892
2111
|
const addAttachment = useCallback(
|
|
@@ -5960,7 +2179,8 @@ const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to
|
|
|
5960
2179
|
],
|
|
5961
2180
|
editorProps: {
|
|
5962
2181
|
attributes: {
|
|
5963
|
-
class: "w-full resize-none bg-transparent px-1.5 py-2 text-sm leading-snug outline-none"
|
|
2182
|
+
class: "w-full resize-none bg-transparent px-1.5 py-2 text-sm leading-snug outline-none",
|
|
2183
|
+
"data-testid": "athena-chat-composer"
|
|
5964
2184
|
},
|
|
5965
2185
|
handlePaste,
|
|
5966
2186
|
handleDrop
|
|
@@ -6009,7 +2229,7 @@ const TiptapComposer = forwardRef(({ placeholder = "Message Athena... (type @ to
|
|
|
6009
2229
|
() => ({ submit: handleSubmit, addAttachment, insertAssetMention }),
|
|
6010
2230
|
[addAttachment, handleSubmit, insertAssetMention]
|
|
6011
2231
|
);
|
|
6012
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2232
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
6013
2233
|
/* @__PURE__ */ jsx("style", { children: MENTION_STYLES }),
|
|
6014
2234
|
/* @__PURE__ */ jsx(
|
|
6015
2235
|
"div",
|
|
@@ -6154,28 +2374,34 @@ const SignInConsent = ({ checked, onChange, children }) => /* @__PURE__ */ jsxs(
|
|
|
6154
2374
|
/* @__PURE__ */ jsx("span", { children })
|
|
6155
2375
|
] });
|
|
6156
2376
|
export {
|
|
6157
|
-
BranchPicker,
|
|
6158
|
-
COMPOSER_DOCK_CLASS,
|
|
6159
|
-
COMPOSER_EDITOR_ROW_CLASS,
|
|
6160
|
-
COMPOSER_SURFACE_CLASS,
|
|
6161
|
-
COMPOSER_TOOLBAR_CLASS,
|
|
6162
|
-
ChatComposerDock,
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
2377
|
+
bY as BranchPicker,
|
|
2378
|
+
bZ as COMPOSER_DOCK_CLASS,
|
|
2379
|
+
b_ as COMPOSER_EDITOR_ROW_CLASS,
|
|
2380
|
+
b$ as COMPOSER_SURFACE_CLASS,
|
|
2381
|
+
c0 as COMPOSER_TOOLBAR_CLASS,
|
|
2382
|
+
bh as ChatComposerDock,
|
|
2383
|
+
ChatHeader,
|
|
2384
|
+
ChatHeaderActions,
|
|
2385
|
+
ChatHeaderIdentity,
|
|
2386
|
+
ChatHeaderRoot,
|
|
2387
|
+
bg as ChatThreadShell,
|
|
2388
|
+
c1 as ComposerSendButton,
|
|
2389
|
+
bi as ComposerSendOrStop,
|
|
2390
|
+
c2 as ComposerStopButton,
|
|
2391
|
+
ConversationHistoryPanel,
|
|
2392
|
+
c3 as IconButton,
|
|
2393
|
+
c4 as MarkdownText,
|
|
2394
|
+
c5 as MentionAuthCtx,
|
|
2395
|
+
c6 as MentionChip,
|
|
6171
2396
|
MentionExtension,
|
|
6172
2397
|
MentionIcon,
|
|
6173
|
-
MentionLink,
|
|
2398
|
+
c7 as MentionLink,
|
|
6174
2399
|
MentionMenuSection,
|
|
6175
2400
|
MentionSuggestionList,
|
|
6176
2401
|
MentionSuggestionPopup,
|
|
6177
2402
|
MentionSuggestionsExtension,
|
|
6178
2403
|
MenuList,
|
|
2404
|
+
c8 as MessageActionsReadOnlyProvider,
|
|
6179
2405
|
PendingAttachmentUploads,
|
|
6180
2406
|
ROOT_MENTION_CATEGORIES,
|
|
6181
2407
|
SIMPLE_SEARCH_QUERY,
|
|
@@ -6185,33 +2411,35 @@ export {
|
|
|
6185
2411
|
SignInSecondaryButton,
|
|
6186
2412
|
SignInSelect,
|
|
6187
2413
|
SignInTextField,
|
|
6188
|
-
SmallIconButton,
|
|
2414
|
+
c9 as SmallIconButton,
|
|
6189
2415
|
THREAD_HEADER_ACTIONS_CLASS,
|
|
6190
2416
|
THREAD_HEADER_CLASS,
|
|
6191
|
-
THREAD_HEADER_ICON_CLASS,
|
|
2417
|
+
ca as THREAD_HEADER_ICON_CLASS,
|
|
6192
2418
|
THREAD_HEADER_PILL_CLASS,
|
|
6193
|
-
THREAD_PANEL_CLASS,
|
|
6194
|
-
THREAD_SCROLL_TO_BOTTOM_CLASS,
|
|
6195
|
-
TextShimmerLoader,
|
|
6196
|
-
ThreadRunningIndicator,
|
|
2419
|
+
cb as THREAD_PANEL_CLASS,
|
|
2420
|
+
cc as THREAD_SCROLL_TO_BOTTOM_CLASS,
|
|
2421
|
+
cd as TextShimmerLoader,
|
|
2422
|
+
ce as ThreadRunningIndicator,
|
|
6197
2423
|
TiptapComposer,
|
|
6198
|
-
|
|
2424
|
+
cf as UserEditComposer,
|
|
2425
|
+
cg as UserMessage,
|
|
6199
2426
|
assetTypeToIcon,
|
|
6200
2427
|
assetTypeToThumb,
|
|
6201
2428
|
buildRootMenuItems,
|
|
6202
|
-
configureAssetIconBasePath,
|
|
6203
|
-
createAssistantMessage,
|
|
6204
|
-
createOlympusAssetUrl,
|
|
2429
|
+
ch as configureAssetIconBasePath,
|
|
2430
|
+
ci as createAssistantMessage,
|
|
2431
|
+
cj as createOlympusAssetUrl,
|
|
6205
2432
|
fetchGraphQL,
|
|
6206
2433
|
makeMentionUrl,
|
|
6207
|
-
normalizeAthenaMentionHtml,
|
|
2434
|
+
ck as normalizeAthenaMentionHtml,
|
|
6208
2435
|
parseMentionAnchorAttributes,
|
|
6209
|
-
parseMentionUrl,
|
|
6210
|
-
parseMentionsInText,
|
|
2436
|
+
cl as parseMentionUrl,
|
|
2437
|
+
cm as parseMentionsInText,
|
|
6211
2438
|
plainTextToTiptapContent,
|
|
6212
|
-
resolveComposerAction,
|
|
2439
|
+
cn2 as resolveComposerAction,
|
|
6213
2440
|
useMentionAuth,
|
|
6214
2441
|
useMentionSuggestions,
|
|
2442
|
+
co as useMessageActionsReadOnly,
|
|
6215
2443
|
webpageMentionFingerprint
|
|
6216
2444
|
};
|
|
6217
2445
|
//# sourceMappingURL=chat-ui.js.map
|