@tooee/renderers 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chooser/choose-filter.d.ts.map +1 -1
- package/dist/chooser/choose-filter.js.map +1 -1
- package/dist/chooser/choose-highlighted-text.d.ts.map +1 -1
- package/dist/chooser/choose-highlighted-text.js.map +1 -1
- package/dist/chooser/choose-list.d.ts.map +1 -1
- package/dist/chooser/choose-list.js.map +1 -1
- package/dist/chooser/choose-store.d.ts +3 -3
- package/dist/chooser/choose-store.d.ts.map +1 -1
- package/dist/chooser/choose-store.js.map +1 -1
- package/dist/chooser/chooser.d.ts.map +1 -1
- package/dist/chooser/chooser.js.map +1 -1
- package/dist/chooser/source.d.ts.map +1 -1
- package/dist/chooser/source.js.map +1 -1
- package/dist/chooser/use-choose.d.ts.map +1 -1
- package/dist/chooser/use-choose.js.map +1 -1
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js.map +1 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -1
- package/dist/markdown/blocks/blockquote.js.map +1 -1
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -1
- package/dist/markdown/blocks/flat-block.js.map +1 -1
- package/dist/markdown/blocks/heading.d.ts.map +1 -1
- package/dist/markdown/blocks/heading.js.map +1 -1
- package/dist/markdown/blocks/list-line.d.ts.map +1 -1
- package/dist/markdown/blocks/list-line.js.map +1 -1
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -1
- package/dist/markdown/blocks/paragraph.js.map +1 -1
- package/dist/markdown/blocks/table.d.ts.map +1 -1
- package/dist/markdown/blocks/table.js.map +1 -1
- package/dist/markdown/links.d.ts.map +1 -1
- package/dist/markdown/links.js.map +1 -1
- package/dist/markdown/plain-text.d.ts.map +1 -1
- package/dist/markdown/plain-text.js.map +1 -1
- package/dist/markdown/table-links.d.ts.map +1 -1
- package/dist/markdown/table-links.js.map +1 -1
- package/dist/markdown/tokens.d.ts.map +1 -1
- package/dist/markdown/tokens.js.map +1 -1
- package/dist/markdown/visit-inline.d.ts.map +1 -1
- package/dist/markdown/visit-inline.js.map +1 -1
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +8 -4
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js.map +1 -1
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js.map +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js.map +1 -1
- package/dist/text-table-internals.d.ts.map +1 -1
- package/dist/text-table-internals.js.map +1 -1
- package/package.json +6 -6
- package/src/chooser/choose-filter.tsx +1 -0
- package/src/chooser/choose-highlighted-text.tsx +2 -0
- package/src/chooser/choose-list.tsx +6 -0
- package/src/chooser/choose-store.ts +20 -3
- package/src/chooser/chooser.tsx +2 -0
- package/src/chooser/source.ts +5 -0
- package/src/chooser/use-choose.ts +44 -0
- package/src/code-blocks.tsx +14 -0
- package/src/command-palette.tsx +4 -0
- package/src/context-menu.tsx +13 -0
- package/src/index.ts +42 -0
- package/src/markdown/blocks/blockquote.tsx +2 -0
- package/src/markdown/blocks/flat-block.tsx +13 -0
- package/src/markdown/blocks/heading.tsx +1 -0
- package/src/markdown/blocks/list-line.tsx +3 -0
- package/src/markdown/blocks/paragraph.tsx +1 -0
- package/src/markdown/blocks/table.tsx +7 -0
- package/src/markdown/links.ts +26 -0
- package/src/markdown/plain-text.ts +5 -0
- package/src/markdown/table-links.ts +12 -0
- package/src/markdown/tokens.ts +2 -0
- package/src/markdown/visit-inline.ts +20 -0
- package/src/markdown-blocks.ts +31 -0
- package/src/markdown-images.ts +21 -0
- package/src/markdown-view.tsx +4 -0
- package/src/mermaid.ts +21 -4
- package/src/parsers.ts +39 -0
- package/src/row-document-renderable.ts +53 -0
- package/src/source.ts +18 -0
- package/src/table.tsx +32 -0
- package/src/text-table-internals.ts +12 -0
|
@@ -16,16 +16,17 @@ export interface ChooseStoreContext {
|
|
|
16
16
|
reloadRevision: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// An event without a payload uses `object`. xstate treats it the same as `{}`, which lint rejects.
|
|
19
20
|
interface ChooseStoreEventDefinitions {
|
|
20
21
|
filterChanged: { query: string };
|
|
21
22
|
activeIndexSet: { index: number };
|
|
22
23
|
moved: { delta: number };
|
|
23
|
-
activeToggled:
|
|
24
|
-
requestStarted:
|
|
24
|
+
activeToggled: object;
|
|
25
|
+
requestStarted: object;
|
|
25
26
|
loadingStarted: { requestId: number };
|
|
26
27
|
loadSucceeded: { requestId: number; items: ChooseItem[] };
|
|
27
28
|
loadFailed: { requestId: number; error: string };
|
|
28
|
-
reloadRequested:
|
|
29
|
+
reloadRequested: object;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export type ChooseStoreEvents = {
|
|
@@ -73,25 +74,31 @@ export const createChooseStore = function createChooseStore(options: {
|
|
|
73
74
|
on: {
|
|
74
75
|
activeIndexSet: (ctx, event) => {
|
|
75
76
|
const activeIndex = clampActiveIndex(event.index, ctx.matches.length);
|
|
77
|
+
|
|
76
78
|
return activeIndex === ctx.activeIndex ? ctx : { ...ctx, activeIndex };
|
|
77
79
|
},
|
|
78
80
|
activeToggled: (ctx) => {
|
|
79
81
|
const originalIndex = ctx.matches[ctx.activeIndex]?.originalIndex;
|
|
82
|
+
|
|
80
83
|
if (originalIndex === undefined) {
|
|
81
84
|
return ctx;
|
|
82
85
|
}
|
|
86
|
+
|
|
83
87
|
const selectedOriginalIndices = new Set(ctx.selectedOriginalIndices);
|
|
88
|
+
|
|
84
89
|
if (selectedOriginalIndices.has(originalIndex)) {
|
|
85
90
|
selectedOriginalIndices.delete(originalIndex);
|
|
86
91
|
} else {
|
|
87
92
|
selectedOriginalIndices.add(originalIndex);
|
|
88
93
|
}
|
|
94
|
+
|
|
89
95
|
return { ...ctx, selectedOriginalIndices };
|
|
90
96
|
},
|
|
91
97
|
filterChanged: (ctx, event) => {
|
|
92
98
|
if (event.query === ctx.filterQuery) {
|
|
93
99
|
return ctx;
|
|
94
100
|
}
|
|
101
|
+
|
|
95
102
|
return {
|
|
96
103
|
...ctx,
|
|
97
104
|
activeIndex: 0,
|
|
@@ -103,6 +110,7 @@ export const createChooseStore = function createChooseStore(options: {
|
|
|
103
110
|
if (event.requestId !== ctx.requestId) {
|
|
104
111
|
return ctx;
|
|
105
112
|
}
|
|
113
|
+
|
|
106
114
|
return {
|
|
107
115
|
...replaceItems(ctx, []),
|
|
108
116
|
error: event.error,
|
|
@@ -113,6 +121,7 @@ export const createChooseStore = function createChooseStore(options: {
|
|
|
113
121
|
if (event.requestId !== ctx.requestId) {
|
|
114
122
|
return ctx;
|
|
115
123
|
}
|
|
124
|
+
|
|
116
125
|
return {
|
|
117
126
|
...replaceItems(ctx, event.items),
|
|
118
127
|
error: null,
|
|
@@ -123,6 +132,7 @@ export const createChooseStore = function createChooseStore(options: {
|
|
|
123
132
|
event.requestId === ctx.requestId && !ctx.loading ? { ...ctx, loading: true } : ctx,
|
|
124
133
|
moved: (ctx, event) => {
|
|
125
134
|
const activeIndex = clampActiveIndex(ctx.activeIndex + event.delta, ctx.matches.length);
|
|
135
|
+
|
|
126
136
|
return activeIndex === ctx.activeIndex ? ctx : { ...ctx, activeIndex };
|
|
127
137
|
},
|
|
128
138
|
reloadRequested: (ctx) => ({ ...ctx, reloadRevision: ctx.reloadRevision + 1 }),
|
|
@@ -138,11 +148,18 @@ export const createChooseStore = function createChooseStore(options: {
|
|
|
138
148
|
export type ChooseStore = ReturnType<typeof createChooseStore>;
|
|
139
149
|
|
|
140
150
|
export const selectItems = (ctx: ChooseStoreContext): ChooseItem[] => ctx.items;
|
|
151
|
+
|
|
141
152
|
export const selectMatches = (ctx: ChooseStoreContext): FuzzyMatch[] => ctx.matches;
|
|
153
|
+
|
|
142
154
|
export const selectFilterQuery = (ctx: ChooseStoreContext): string => ctx.filterQuery;
|
|
155
|
+
|
|
143
156
|
export const selectActiveIndex = (ctx: ChooseStoreContext): number => ctx.activeIndex;
|
|
157
|
+
|
|
144
158
|
export const selectSelectedOriginalIndices = (ctx: ChooseStoreContext): ReadonlySet<number> =>
|
|
145
159
|
ctx.selectedOriginalIndices;
|
|
160
|
+
|
|
146
161
|
export const selectLoading = (ctx: ChooseStoreContext): boolean => ctx.loading;
|
|
162
|
+
|
|
147
163
|
export const selectError = (ctx: ChooseStoreContext): string | null => ctx.error;
|
|
164
|
+
|
|
148
165
|
export const selectReloadRevision = (ctx: ChooseStoreContext): number => ctx.reloadRevision;
|
package/src/chooser/chooser.tsx
CHANGED
|
@@ -34,6 +34,7 @@ export const Chooser = function Chooser({
|
|
|
34
34
|
emptyContent,
|
|
35
35
|
}: ChooserProps): ReactNode {
|
|
36
36
|
const { theme } = useTheme();
|
|
37
|
+
|
|
37
38
|
const choose = useChoose({
|
|
38
39
|
commandScope,
|
|
39
40
|
escapeToCursor: false,
|
|
@@ -42,6 +43,7 @@ export const Chooser = function Chooser({
|
|
|
42
43
|
onCancel,
|
|
43
44
|
onSubmit: async ({ items: selectedItems }) => {
|
|
44
45
|
const [item] = selectedItems;
|
|
46
|
+
|
|
45
47
|
if (item !== undefined) {
|
|
46
48
|
await onSelect(item);
|
|
47
49
|
}
|
package/src/chooser/source.ts
CHANGED
|
@@ -9,10 +9,12 @@ const decodeChooseSource = function decodeChooseSource(source: ChooseSource): De
|
|
|
9
9
|
if (Array.isArray(source)) {
|
|
10
10
|
return { items: source, kind: "items" };
|
|
11
11
|
}
|
|
12
|
+
|
|
12
13
|
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- public source boundary distinguishes the documented loader callback from a provider
|
|
13
14
|
if (typeof source === "function") {
|
|
14
15
|
return { kind: "loader", load: source };
|
|
15
16
|
}
|
|
17
|
+
|
|
16
18
|
return { kind: "provider", provider: source };
|
|
17
19
|
};
|
|
18
20
|
|
|
@@ -21,12 +23,15 @@ export const loadChooseSource = function loadChooseSource(
|
|
|
21
23
|
source: ChooseSource
|
|
22
24
|
): ChooseItem[] | Promise<ChooseItem[]> {
|
|
23
25
|
const decoded = decodeChooseSource(source);
|
|
26
|
+
|
|
24
27
|
if (decoded.kind === "items") {
|
|
25
28
|
return decoded.items;
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
if (decoded.kind === "loader") {
|
|
28
32
|
return decoded.load();
|
|
29
33
|
}
|
|
34
|
+
|
|
30
35
|
return decoded.provider.load();
|
|
31
36
|
};
|
|
32
37
|
|
|
@@ -130,7 +130,9 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
130
130
|
commandScope = "choose",
|
|
131
131
|
escapeToCursor = true,
|
|
132
132
|
} = options;
|
|
133
|
+
|
|
133
134
|
const initialItems = Array.isArray(source) ? source : [];
|
|
135
|
+
|
|
134
136
|
const store = useLazyRef(() =>
|
|
135
137
|
createChooseStore({
|
|
136
138
|
initialActiveIndex,
|
|
@@ -139,34 +141,44 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
139
141
|
loading: !Array.isArray(source),
|
|
140
142
|
})
|
|
141
143
|
).current;
|
|
144
|
+
|
|
142
145
|
const filterRef = useRef<InputRenderable>(null);
|
|
146
|
+
|
|
143
147
|
const initialArraySourceRef = useLazyRef<ChooseItem[] | null>(() =>
|
|
144
148
|
Array.isArray(source) ? source : null
|
|
145
149
|
);
|
|
150
|
+
|
|
146
151
|
const didHandleInitialSourceRef = useRef(false);
|
|
147
152
|
|
|
148
153
|
const items = useSelector(store, (snapshot) => selectItems(snapshot.context));
|
|
149
154
|
const matches = useSelector(store, (snapshot) => selectMatches(snapshot.context));
|
|
150
155
|
const filterQuery = useSelector(store, (snapshot) => selectFilterQuery(snapshot.context));
|
|
151
156
|
const activeIndex = useSelector(store, (snapshot) => selectActiveIndex(snapshot.context));
|
|
157
|
+
|
|
152
158
|
const selectedOriginalIndices = useSelector(store, (snapshot) =>
|
|
153
159
|
selectSelectedOriginalIndices(snapshot.context)
|
|
154
160
|
);
|
|
161
|
+
|
|
155
162
|
const loading = useSelector(store, (snapshot) => selectLoading(snapshot.context));
|
|
156
163
|
const error = useSelector(store, (snapshot) => selectError(snapshot.context));
|
|
157
164
|
const reloadRevision = useSelector(store, (snapshot) => selectReloadRevision(snapshot.context));
|
|
158
165
|
const activeItem = matches[activeIndex]?.item;
|
|
166
|
+
|
|
159
167
|
const selectedItems = useMemo(() => {
|
|
160
168
|
if (!multi) {
|
|
161
169
|
return activeItem === undefined ? [] : [activeItem];
|
|
162
170
|
}
|
|
171
|
+
|
|
163
172
|
const selected = [...selectedOriginalIndices].flatMap((index) => {
|
|
164
173
|
const item = items[index];
|
|
174
|
+
|
|
165
175
|
return item === undefined ? [] : [item];
|
|
166
176
|
});
|
|
177
|
+
|
|
167
178
|
if (selected.length > 0) {
|
|
168
179
|
return selected;
|
|
169
180
|
}
|
|
181
|
+
|
|
170
182
|
return activeItem === undefined ? [] : [activeItem];
|
|
171
183
|
}, [multi, activeItem, selectedOriginalIndices, items]);
|
|
172
184
|
|
|
@@ -182,6 +194,7 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
182
194
|
|
|
183
195
|
useEffect(() => {
|
|
184
196
|
let active = true;
|
|
197
|
+
|
|
185
198
|
const deactivate = () => {
|
|
186
199
|
active = false;
|
|
187
200
|
};
|
|
@@ -194,17 +207,21 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
194
207
|
source === initialArraySourceRef.current
|
|
195
208
|
) {
|
|
196
209
|
didHandleInitialSourceRef.current = true;
|
|
210
|
+
|
|
197
211
|
return deactivate;
|
|
198
212
|
}
|
|
213
|
+
|
|
199
214
|
didHandleInitialSourceRef.current = true;
|
|
200
215
|
|
|
201
216
|
store.trigger.requestStarted({});
|
|
202
217
|
const { requestId } = store.getSnapshot().context;
|
|
203
218
|
let result: ChooseItem[] | Promise<ChooseItem[]>;
|
|
219
|
+
|
|
204
220
|
try {
|
|
205
221
|
result = loadChooseSource(source);
|
|
206
222
|
} catch (loadError) {
|
|
207
223
|
store.trigger.loadFailed({ error: chooseSourceError(loadError), requestId });
|
|
224
|
+
|
|
208
225
|
return deactivate;
|
|
209
226
|
}
|
|
210
227
|
|
|
@@ -213,6 +230,7 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
213
230
|
void (async () => {
|
|
214
231
|
try {
|
|
215
232
|
const loaded = await result;
|
|
233
|
+
|
|
216
234
|
if (active) {
|
|
217
235
|
store.trigger.loadSucceeded({ items: loaded, requestId });
|
|
218
236
|
}
|
|
@@ -222,10 +240,12 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
222
240
|
}
|
|
223
241
|
}
|
|
224
242
|
})();
|
|
243
|
+
|
|
225
244
|
return deactivate;
|
|
226
245
|
}
|
|
227
246
|
|
|
228
247
|
store.trigger.loadSucceeded({ items: result, requestId });
|
|
248
|
+
|
|
229
249
|
return deactivate;
|
|
230
250
|
}, [source, reloadRevision, store, initialArraySourceRef]);
|
|
231
251
|
|
|
@@ -235,49 +255,65 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
235
255
|
},
|
|
236
256
|
[store]
|
|
237
257
|
);
|
|
258
|
+
|
|
238
259
|
const updateActiveIndex = useCallback(
|
|
239
260
|
(index: number) => {
|
|
240
261
|
store.trigger.activeIndexSet({ index });
|
|
241
262
|
},
|
|
242
263
|
[store]
|
|
243
264
|
);
|
|
265
|
+
|
|
244
266
|
const moveUp = useCallback(() => {
|
|
245
267
|
store.trigger.moved({ delta: -1 });
|
|
246
268
|
}, [store]);
|
|
269
|
+
|
|
247
270
|
const moveDown = useCallback(() => {
|
|
248
271
|
store.trigger.moved({ delta: 1 });
|
|
249
272
|
}, [store]);
|
|
273
|
+
|
|
250
274
|
const getActiveItem = useCallback(() => {
|
|
251
275
|
const { context } = store.getSnapshot();
|
|
276
|
+
|
|
252
277
|
return context.matches[context.activeIndex]?.item;
|
|
253
278
|
}, [store]);
|
|
279
|
+
|
|
254
280
|
const getSelectedItems = useCallback((): ChooseItem[] => {
|
|
255
281
|
const { context } = store.getSnapshot();
|
|
256
282
|
const active = context.matches[context.activeIndex]?.item;
|
|
283
|
+
|
|
257
284
|
if (!multiRef.current) {
|
|
258
285
|
return active === undefined ? [] : [active];
|
|
259
286
|
}
|
|
287
|
+
|
|
260
288
|
const selected = [...context.selectedOriginalIndices].flatMap((index) => {
|
|
261
289
|
const item = context.items[index];
|
|
290
|
+
|
|
262
291
|
return item === undefined ? [] : [item];
|
|
263
292
|
});
|
|
293
|
+
|
|
264
294
|
if (selected.length > 0) {
|
|
265
295
|
return selected;
|
|
266
296
|
}
|
|
297
|
+
|
|
267
298
|
return active === undefined ? [] : [active];
|
|
268
299
|
}, [multiRef, store]);
|
|
300
|
+
|
|
269
301
|
const toggleActive = useCallback(() => {
|
|
270
302
|
if (multiRef.current) {
|
|
271
303
|
store.trigger.activeToggled({});
|
|
272
304
|
}
|
|
273
305
|
}, [multiRef, store]);
|
|
306
|
+
|
|
274
307
|
const submit = useCallback(() => {
|
|
275
308
|
void optionsRef.current.onSubmit({ items: getSelectedItems() });
|
|
276
309
|
}, [getSelectedItems, optionsRef]);
|
|
310
|
+
|
|
277
311
|
const cancel = useCallback(() => optionsRef.current.onCancel?.(), [optionsRef]);
|
|
312
|
+
|
|
278
313
|
const reload = useCallback(() => {
|
|
279
314
|
store.trigger.reloadRequested({});
|
|
280
315
|
}, [store]);
|
|
316
|
+
|
|
281
317
|
const setModeExternal = useCallback(
|
|
282
318
|
(nextMode: Mode) => {
|
|
283
319
|
setMode(nextMode);
|
|
@@ -293,9 +329,11 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
293
329
|
selectedItems: getSelectedItems(),
|
|
294
330
|
},
|
|
295
331
|
};
|
|
332
|
+
|
|
296
333
|
if (optionsRef.current.onCancel !== undefined) {
|
|
297
334
|
context.exit = cancel;
|
|
298
335
|
}
|
|
336
|
+
|
|
299
337
|
return context;
|
|
300
338
|
});
|
|
301
339
|
|
|
@@ -305,6 +343,7 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
305
343
|
(group: ChooseCommandGroup) => !(optionsRef.current.disable?.includes(group) ?? false),
|
|
306
344
|
[optionsRef]
|
|
307
345
|
);
|
|
346
|
+
|
|
308
347
|
const builtInActions = useMemo<ActionDefinition[]>(() => {
|
|
309
348
|
const definitions: ChooseKeymapDefinition[] = [
|
|
310
349
|
{
|
|
@@ -448,6 +487,7 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
448
487
|
when: () => multiRef.current,
|
|
449
488
|
},
|
|
450
489
|
];
|
|
490
|
+
|
|
451
491
|
return definitions.map(({ group, when, ...definition }) => ({
|
|
452
492
|
...definition,
|
|
453
493
|
when: () => enabled(group()) && (when?.() ?? true),
|
|
@@ -466,10 +506,12 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
466
506
|
submit,
|
|
467
507
|
toggleActive,
|
|
468
508
|
]);
|
|
509
|
+
|
|
469
510
|
useActions(builtInActions);
|
|
470
511
|
|
|
471
512
|
const surfaceId = useCommandSurfaceId();
|
|
472
513
|
const activeSurface = useActiveCommandSurface();
|
|
514
|
+
|
|
473
515
|
const suspended =
|
|
474
516
|
(options.suspended ?? false) || (activeSurface !== null && activeSurface.id !== surfaceId);
|
|
475
517
|
|
|
@@ -483,8 +525,10 @@ export const useChoose = function useChoose(options: UseChooseOptions): UseChoos
|
|
|
483
525
|
) {
|
|
484
526
|
return;
|
|
485
527
|
}
|
|
528
|
+
|
|
486
529
|
event.preventDefault();
|
|
487
530
|
toggleActive();
|
|
531
|
+
|
|
488
532
|
if (event.shift) {
|
|
489
533
|
moveUp();
|
|
490
534
|
} else {
|
package/src/code-blocks.tsx
CHANGED
|
@@ -130,6 +130,7 @@ export const defaultCodeBlockRenderer: CodeBlockRenderer = ({
|
|
|
130
130
|
}): ReactNode => {
|
|
131
131
|
const { register, onMouseScroll: handleMouseScroll } = hScroll;
|
|
132
132
|
const lineCount = text.split("\n").length;
|
|
133
|
+
|
|
133
134
|
// Code lines never wrap (wrapMode "none") — wide code blocks and ASCII
|
|
134
135
|
// diagrams pan horizontally via the renderable's own viewport (`scrollX`)
|
|
135
136
|
// instead of word-wrapping into an unreadable mess. Blocks that fit render
|
|
@@ -166,6 +167,7 @@ export const mermaidCodeBlockRenderer: CodeBlockRenderer = ({
|
|
|
166
167
|
hScroll,
|
|
167
168
|
}): ReactNode => {
|
|
168
169
|
const { register, onMouseScroll: handleMouseScroll } = hScroll;
|
|
170
|
+
|
|
169
171
|
const mermaidTheme = {
|
|
170
172
|
accent: theme.accent,
|
|
171
173
|
arrow: theme.accent,
|
|
@@ -176,6 +178,7 @@ export const mermaidCodeBlockRenderer: CodeBlockRenderer = ({
|
|
|
176
178
|
junction: theme.borderSubtle,
|
|
177
179
|
line: theme.textMuted,
|
|
178
180
|
};
|
|
181
|
+
|
|
179
182
|
const result = renderMermaidForTerminal(text, { mode: "ansi", theme: mermaidTheme });
|
|
180
183
|
|
|
181
184
|
if (!result.ok) {
|
|
@@ -183,6 +186,7 @@ export const mermaidCodeBlockRenderer: CodeBlockRenderer = ({
|
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
const lineCount = result.text.split("\n").length;
|
|
189
|
+
|
|
186
190
|
// Diagram lines never wrap (wrapMode "none"). Wide diagrams pan via the
|
|
187
191
|
// text renderable's own viewport (`scrollX`), which the native renderer
|
|
188
192
|
// clips with correct style-run alignment. Translating a natural-width text
|
|
@@ -210,6 +214,7 @@ const DEFAULT_CODE_BLOCK_RENDERER_ENTRIES = {
|
|
|
210
214
|
/** Built-in code block renderers, merged under user-provided entries. */
|
|
211
215
|
// oxlint-disable-next-line anti-slop/no-known-value-widening -- public registry contract permits arbitrary fence-type lookup
|
|
212
216
|
const defaultRendererMap: Record<string, CodeBlockRenderer> = DEFAULT_CODE_BLOCK_RENDERER_ENTRIES;
|
|
217
|
+
|
|
213
218
|
export { defaultRendererMap as DEFAULT_CODE_BLOCK_RENDERERS };
|
|
214
219
|
|
|
215
220
|
// ---------------------------------------------------------------------------
|
|
@@ -234,13 +239,16 @@ const useHScrollableBlock = function useHScrollableBlock(
|
|
|
234
239
|
hScrollableBlocksRef?: RefObject<Map<number, TextBufferRenderable>>
|
|
235
240
|
) {
|
|
236
241
|
const nodeRef = useRef<TextBufferRenderable | null>(null);
|
|
242
|
+
|
|
237
243
|
const register = useCallback(
|
|
238
244
|
(node: TextBufferRenderable | null) => {
|
|
239
245
|
nodeRef.current = node;
|
|
240
246
|
const map = hScrollableBlocksRef?.current;
|
|
247
|
+
|
|
241
248
|
if (!map) {
|
|
242
249
|
return;
|
|
243
250
|
}
|
|
251
|
+
|
|
244
252
|
if (node) {
|
|
245
253
|
map.set(blockIndex, node);
|
|
246
254
|
} else {
|
|
@@ -252,10 +260,13 @@ const useHScrollableBlock = function useHScrollableBlock(
|
|
|
252
260
|
|
|
253
261
|
const handleMouseScroll = useCallback((event: MouseEvent) => {
|
|
254
262
|
const node = nodeRef.current;
|
|
263
|
+
|
|
255
264
|
if (!node || !event.scroll || !event.modifiers.shift) {
|
|
256
265
|
return;
|
|
257
266
|
}
|
|
267
|
+
|
|
258
268
|
const { direction, delta } = event.scroll;
|
|
269
|
+
|
|
259
270
|
if (direction === "up") {
|
|
260
271
|
node.scrollX -= delta;
|
|
261
272
|
} else if (direction === "down") {
|
|
@@ -283,11 +294,13 @@ const CustomCodeBlock = function CustomCodeBlock({
|
|
|
283
294
|
rendererProps: CodeBlockRendererProps;
|
|
284
295
|
}): ReactNode {
|
|
285
296
|
let node: ReactNode = null;
|
|
297
|
+
|
|
286
298
|
try {
|
|
287
299
|
node = renderer(rendererProps);
|
|
288
300
|
} catch {
|
|
289
301
|
node = null;
|
|
290
302
|
}
|
|
303
|
+
|
|
291
304
|
return node ?? defaultCodeBlockRenderer(rendererProps);
|
|
292
305
|
};
|
|
293
306
|
|
|
@@ -332,6 +345,7 @@ export const CodeBlock = function CodeBlock({
|
|
|
332
345
|
};
|
|
333
346
|
|
|
334
347
|
const custom = rendererProps.lang === "" ? undefined : renderers?.[rendererProps.lang];
|
|
348
|
+
|
|
335
349
|
if (custom && custom !== defaultCodeBlockRenderer) {
|
|
336
350
|
// Keyed by fence type so a type change remounts the custom renderer
|
|
337
351
|
// (renderers may use hooks; see CodeBlockRenderer docs).
|
package/src/command-palette.tsx
CHANGED
|
@@ -26,14 +26,17 @@ export const CommandPalette = function CommandPalette({
|
|
|
26
26
|
onClose,
|
|
27
27
|
}: CommandPaletteProps): ReactNode {
|
|
28
28
|
const { theme } = useTheme();
|
|
29
|
+
|
|
29
30
|
const entriesById = useMemo(
|
|
30
31
|
() => new Map(commands.map((entry) => [entry.id, entry])),
|
|
31
32
|
[commands]
|
|
32
33
|
);
|
|
34
|
+
|
|
33
35
|
const items = useMemo<ChooseItem[]>(
|
|
34
36
|
() => commands.map((entry) => ({ text: entry.title, value: entry.id })),
|
|
35
37
|
[commands]
|
|
36
38
|
);
|
|
39
|
+
|
|
37
40
|
const handleSelect = (item: ChooseItem): void => {
|
|
38
41
|
if (item.value !== undefined) {
|
|
39
42
|
onSelect(item.value);
|
|
@@ -50,6 +53,7 @@ export const CommandPalette = function CommandPalette({
|
|
|
50
53
|
onSelect={handleSelect}
|
|
51
54
|
renderItem={({ item, positions }): ReactNode => {
|
|
52
55
|
const entry = item.value === undefined ? undefined : entriesById.get(item.value);
|
|
56
|
+
|
|
53
57
|
return (
|
|
54
58
|
<>
|
|
55
59
|
<text fg={theme.text} style={{ flexGrow: 1 }}>
|
package/src/context-menu.tsx
CHANGED
|
@@ -20,7 +20,9 @@ interface ContextMenuProps {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const MIN_WIDTH = 16;
|
|
23
|
+
|
|
23
24
|
const HORIZONTAL_PADDING = 2;
|
|
25
|
+
|
|
24
26
|
const BORDER = 2;
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -45,6 +47,7 @@ export const ContextMenu = function ContextMenu({
|
|
|
45
47
|
const select = useCallback(
|
|
46
48
|
(index: number) => {
|
|
47
49
|
const entry = entries[index];
|
|
50
|
+
|
|
48
51
|
if (entry !== undefined) {
|
|
49
52
|
onSelect(entry.id);
|
|
50
53
|
}
|
|
@@ -55,9 +58,11 @@ export const ContextMenu = function ContextMenu({
|
|
|
55
58
|
const moveUp = useCallback(() => {
|
|
56
59
|
setActiveIndex((index) => Math.max(0, index - 1));
|
|
57
60
|
}, []);
|
|
61
|
+
|
|
58
62
|
const moveDown = useCallback(() => {
|
|
59
63
|
setActiveIndex((index) => Math.min(entries.length - 1, index + 1));
|
|
60
64
|
}, [entries.length]);
|
|
65
|
+
|
|
61
66
|
const selectActive = useCallback(() => {
|
|
62
67
|
select(activeIndex);
|
|
63
68
|
}, [activeIndex, select]);
|
|
@@ -107,25 +112,32 @@ export const ContextMenu = function ContextMenu({
|
|
|
107
112
|
// so wide glyphs like CJK and emoji are counted correctly).
|
|
108
113
|
let longest = 0;
|
|
109
114
|
const entryCount = entries.length;
|
|
115
|
+
|
|
110
116
|
for (let index = 0; index < entryCount; index += 1) {
|
|
111
117
|
if (index in entries) {
|
|
112
118
|
const entry = entries[index];
|
|
119
|
+
|
|
113
120
|
const width =
|
|
114
121
|
Bun.stringWidth(entry.title) +
|
|
115
122
|
(entry.hotkey !== undefined && entry.hotkey !== "" ? Bun.stringWidth(entry.hotkey) + 2 : 0);
|
|
123
|
+
|
|
116
124
|
longest = Math.max(longest, width);
|
|
117
125
|
}
|
|
118
126
|
}
|
|
127
|
+
|
|
119
128
|
const innerWidth = Math.max(MIN_WIDTH, longest);
|
|
120
129
|
const panelWidth = innerWidth + HORIZONTAL_PADDING + BORDER;
|
|
121
130
|
const panelHeight = Math.max(1, entries.length) + BORDER;
|
|
122
131
|
|
|
123
132
|
// Clamp on-screen: flip left/up when the anchor is near the right/bottom edge.
|
|
124
133
|
let left = x;
|
|
134
|
+
|
|
125
135
|
if (left + panelWidth > termWidth) {
|
|
126
136
|
left = Math.max(0, termWidth - panelWidth);
|
|
127
137
|
}
|
|
138
|
+
|
|
128
139
|
let top = y;
|
|
140
|
+
|
|
129
141
|
if (top + panelHeight > termHeight) {
|
|
130
142
|
top = Math.max(0, termHeight - panelHeight);
|
|
131
143
|
}
|
|
@@ -172,6 +184,7 @@ export const ContextMenu = function ContextMenu({
|
|
|
172
184
|
if (event.button !== 0) {
|
|
173
185
|
return;
|
|
174
186
|
}
|
|
187
|
+
|
|
175
188
|
event.preventDefault();
|
|
176
189
|
event.stopPropagation();
|
|
177
190
|
onSelect(entry.id);
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
export { MarkdownView } from "./markdown-view.js";
|
|
2
|
+
|
|
2
3
|
export type { MarkdownLinkHandler } from "./markdown-view.js";
|
|
4
|
+
|
|
3
5
|
export { flattenMarkdown, getFlatBlockText } from "./markdown-blocks.js";
|
|
6
|
+
|
|
4
7
|
export { getPlainText } from "./markdown/plain-text.js";
|
|
8
|
+
|
|
5
9
|
export type { FlatBlock, FlattenMarkdownOptions } from "./markdown-blocks.js";
|
|
10
|
+
|
|
6
11
|
export {
|
|
7
12
|
parseObsidianImageEmbed,
|
|
8
13
|
resolveMarkdownImageSource,
|
|
9
14
|
splitMarkdownImages,
|
|
10
15
|
} from "./markdown-images.js";
|
|
16
|
+
|
|
11
17
|
export type { MarkdownImageEmbed, MarkdownInlineSegment } from "./markdown-images.js";
|
|
18
|
+
|
|
12
19
|
export { sourceLines, sourceLineAdapter, SourceIndex } from "./source.js";
|
|
20
|
+
|
|
13
21
|
export type {
|
|
14
22
|
DocumentRowAnchor,
|
|
15
23
|
DocumentRowSource,
|
|
@@ -17,6 +25,7 @@ export type {
|
|
|
17
25
|
SourcePoint,
|
|
18
26
|
SourceSpan,
|
|
19
27
|
} from "./source.js";
|
|
28
|
+
|
|
20
29
|
export {
|
|
21
30
|
CodeBlockChrome,
|
|
22
31
|
defaultCodeBlockRenderer,
|
|
@@ -24,21 +33,37 @@ export {
|
|
|
24
33
|
DEFAULT_CODE_BLOCK_RENDERERS,
|
|
25
34
|
getFenceType,
|
|
26
35
|
} from "./code-blocks.js";
|
|
36
|
+
|
|
27
37
|
export type { CodeBlockRenderer, CodeBlockRendererProps, CodeBlockHScroll } from "./code-blocks.js";
|
|
38
|
+
|
|
28
39
|
export { CodeView } from "./code-view.js";
|
|
40
|
+
|
|
29
41
|
export { Table, computeColumnWidths, formatTableCell, isNumeric, sampleRows } from "./table.js";
|
|
42
|
+
|
|
30
43
|
export type { TableProps, ColumnWidthOptions } from "./table.js";
|
|
44
|
+
|
|
31
45
|
export type { ColumnDef, TableRow } from "./table-types.js";
|
|
46
|
+
|
|
32
47
|
export { CommandPalette } from "./command-palette.js";
|
|
48
|
+
|
|
33
49
|
export type { CommandPaletteEntry } from "./command-palette.js";
|
|
50
|
+
|
|
34
51
|
export { Chooser } from "./chooser/chooser.js";
|
|
52
|
+
|
|
35
53
|
export type { ChooserProps } from "./chooser/chooser.js";
|
|
54
|
+
|
|
36
55
|
export { ChooseFilter } from "./chooser/choose-filter.js";
|
|
56
|
+
|
|
37
57
|
export type { ChooseFilterProps } from "./chooser/choose-filter.js";
|
|
58
|
+
|
|
38
59
|
export { ChooseHighlightedText } from "./chooser/choose-highlighted-text.js";
|
|
60
|
+
|
|
39
61
|
export type { ChooseHighlightedTextProps } from "./chooser/choose-highlighted-text.js";
|
|
62
|
+
|
|
40
63
|
export { ChooseList } from "./chooser/choose-list.js";
|
|
64
|
+
|
|
41
65
|
export type { ChooseItemRenderContext, ChooseListProps } from "./chooser/choose-list.js";
|
|
66
|
+
|
|
42
67
|
export {
|
|
43
68
|
createChooseStore,
|
|
44
69
|
selectActiveIndex,
|
|
@@ -50,11 +75,17 @@ export {
|
|
|
50
75
|
selectReloadRevision,
|
|
51
76
|
selectSelectedOriginalIndices,
|
|
52
77
|
} from "./chooser/choose-store.js";
|
|
78
|
+
|
|
53
79
|
export type { ChooseStore, ChooseStoreContext, ChooseStoreEvents } from "./chooser/choose-store.js";
|
|
80
|
+
|
|
54
81
|
export { fuzzyFilter } from "./chooser/fuzzy.js";
|
|
82
|
+
|
|
55
83
|
export type { FuzzyMatch } from "./chooser/fuzzy.js";
|
|
84
|
+
|
|
56
85
|
export { loadChooseSource } from "./chooser/source.js";
|
|
86
|
+
|
|
57
87
|
export { useChoose } from "./chooser/use-choose.js";
|
|
88
|
+
|
|
58
89
|
export type {
|
|
59
90
|
ChooseCommandGroup,
|
|
60
91
|
ChooseController,
|
|
@@ -63,6 +94,7 @@ export type {
|
|
|
63
94
|
UseChooseOptions,
|
|
64
95
|
UseChooseResult,
|
|
65
96
|
} from "./chooser/use-choose.js";
|
|
97
|
+
|
|
66
98
|
export type {
|
|
67
99
|
ChooseContentProvider,
|
|
68
100
|
ChooseItem,
|
|
@@ -70,21 +102,31 @@ export type {
|
|
|
70
102
|
ChooseResult,
|
|
71
103
|
ChooseSource,
|
|
72
104
|
} from "./chooser/types.js";
|
|
105
|
+
|
|
73
106
|
export { ContextMenu } from "./context-menu.js";
|
|
107
|
+
|
|
74
108
|
export type { ContextMenuEntry } from "./context-menu.js";
|
|
109
|
+
|
|
75
110
|
export { parseCSV, parseTSV, parseJSON, parseAuto, detectFormat } from "./parsers.js";
|
|
111
|
+
|
|
76
112
|
export type { Format, ParsedTable, TableData } from "./parsers.js";
|
|
113
|
+
|
|
77
114
|
export { RowDocumentRenderable } from "./row-document-renderable.js";
|
|
115
|
+
|
|
78
116
|
export {
|
|
79
117
|
DEFAULT_SIGN_COLUMN_WIDTH,
|
|
80
118
|
computeRowDocumentGutterWidth,
|
|
81
119
|
} from "./row-document-renderable.js";
|
|
120
|
+
|
|
82
121
|
export type {
|
|
83
122
|
RowDocumentOptions,
|
|
84
123
|
RowDocumentPalette,
|
|
85
124
|
RowScrollAlign,
|
|
86
125
|
VisibleRowRange,
|
|
87
126
|
} from "./row-document-renderable.js";
|
|
127
|
+
|
|
88
128
|
export type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
|
|
129
|
+
|
|
89
130
|
export type { DocumentBindings } from "./document-bindings.js";
|
|
131
|
+
|
|
90
132
|
export { useGutterPalette } from "./use-gutter-palette.js";
|
|
@@ -19,11 +19,13 @@ export const BlockquoteRenderer = function BlockquoteRenderer({
|
|
|
19
19
|
onLinkActivate?: MarkdownLinkHandler;
|
|
20
20
|
}): ReactNode {
|
|
21
21
|
const inlineTokens: Token[] = [];
|
|
22
|
+
|
|
22
23
|
for (const child of token.tokens) {
|
|
23
24
|
if ("tokens" in child && Array.isArray(child.tokens)) {
|
|
24
25
|
if (inlineTokens.length > 0) {
|
|
25
26
|
inlineTokens.push({ raw: "\n", type: "br" });
|
|
26
27
|
}
|
|
28
|
+
|
|
27
29
|
inlineTokens.push(...child.tokens);
|
|
28
30
|
} else if (hasMarkedText(child)) {
|
|
29
31
|
inlineTokens.push(child);
|