@inkbar/react 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.d.mts +123 -81
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +238 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["DecorateAnnotation","InkPlugin","DecorateAnnotation","AnnotationSlotProps","AnnotationSlotProps","AnnotationSlotProps","ThreadPopoverSlotProps"],"sources":["../src/context.ts","../src/use-readable.ts","../src/hooks/useDocument.ts","../src/hooks/useAnnotations.ts","../src/hooks/useTool.ts","../src/hooks/useToolStyle.ts","../src/hooks/useToolOptions.ts","../src/hooks/useSelection.ts","../src/hooks/useZoom.ts","../src/hooks/usePage.ts","../src/hooks/useHistory.ts","../src/hooks/useEmbedded.ts","../src/hooks/useCommand.ts","../src/components/InkRoot.tsx","../src/components/InkViewport.tsx","../src/components/InkPage.tsx","../src/components/InkAnnotation.tsx","../src/components/InkToolbar.tsx","../src/components/InkIcon.tsx","../src/components/InkToolButton.tsx","../src/components/InkCommand.tsx","../src/components/InkToolbarSeparator.tsx","../src/components/history-button.ts","../src/components/InkUndo.tsx","../src/components/InkRedo.tsx","../src/components/zoom-button.ts","../src/components/InkZoomIn.tsx","../src/components/InkZoomOut.tsx","../src/components/InkZoomSelect.tsx","../src/components/InkPageInput.tsx","../src/components/InkPageCount.tsx","../src/components/page-button.ts","../src/components/InkPrevPage.tsx","../src/components/InkNextPage.tsx","../src/components/InkColorMenu.tsx","../src/components/InkShapeMenu.tsx","../src/components/InkSignatureMenu.tsx","../src/components/InkSignatureDialog.tsx","../src/components/InkHighlightMenu.tsx","../src/components/InkTextStyleMenu.tsx","../src/components/InkLineStyleMenu.tsx","../src/components/InkThreadPopover.tsx"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["DecorateAnnotation","InkPlugin","DecorateAnnotation","AnnotationSlotProps","AnnotationSlotProps","AnnotationSlotProps","ThreadPopoverSlotProps"],"sources":["../src/context.ts","../src/use-readable.ts","../src/hooks/useDocument.ts","../src/hooks/useAnnotations.ts","../src/hooks/useTool.ts","../src/hooks/useToolStyle.ts","../src/hooks/useToolOptions.ts","../src/hooks/useSelection.ts","../src/hooks/useZoom.ts","../src/hooks/useSearch.ts","../src/hooks/usePage.ts","../src/hooks/useHistory.ts","../src/hooks/useEmbedded.ts","../src/hooks/useCommand.ts","../src/components/InkRoot.tsx","../src/components/InkViewport.tsx","../src/components/InkPage.tsx","../src/components/InkAnnotation.tsx","../src/components/InkToolbar.tsx","../src/components/InkIcon.tsx","../src/components/InkToolButton.tsx","../src/components/InkCommand.tsx","../src/components/InkToolbarSeparator.tsx","../src/components/history-button.ts","../src/components/InkUndo.tsx","../src/components/InkRedo.tsx","../src/components/InkSearchButton.tsx","../src/components/InkFindBar.tsx","../src/components/zoom-button.ts","../src/components/InkZoomIn.tsx","../src/components/InkZoomOut.tsx","../src/components/InkZoomSelect.tsx","../src/components/InkPageInput.tsx","../src/components/InkPageCount.tsx","../src/components/page-button.ts","../src/components/InkPrevPage.tsx","../src/components/InkNextPage.tsx","../src/components/InkColorMenu.tsx","../src/components/InkShapeMenu.tsx","../src/components/InkSignatureMenu.tsx","../src/components/InkSignatureDialog.tsx","../src/components/InkHighlightMenu.tsx","../src/components/InkTextStyleMenu.tsx","../src/components/InkLineStyleMenu.tsx","../src/components/InkThreadPopover.tsx"],"mappings":";;;;;;;;;;UA8BiB,mBAAmB;EAClC;EACA;EACA;EACA;EACA;;;;;;;EAOA,QAAQ;;UAGO;EACf,QAAQ;EACR,UAAU;;EAEV,QAAQ;EACR,sBAAsB;EACtB;;;;;;EAMA,YAAY;;;;;;EAMZ,QAAQ;;EAER,YAAY,SAAS;;EAErB,UAAU;EACV,OAAO;;EAEP,MAAM;EACN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11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { InkError, createMemorySignatureStore, createSignatureLibrary, createSnapshotHistory, isAbandonedNote, openDocument, readonly, repliesTo, threadOf, threadRoot, writable } from "@inkbar/core";
|
|
4
|
-
import { COLOR_COLUMNS, FONT_FAMILIES, MARKUP_ICONS, MARKUP_KINDS, SHAPE_COLUMNS, SHAPE_ICONS, SHAPE_KINDS, SIGNATURE_FONTS, SIGNATURE_LABELS, SIGNATURE_TABS, TOOL_LABELS, ZOOM_LEVELS, colorMenuModel, createFocusReturn, createPluginHost, createSignatureDraft, createToolOptions, cssVariableDefaults, focusInitialMenuItem, fontFamilyValue, handleMenuKeys, handleRadioKeys, handleTabKeys, highlightMenuModel, lineStyleMenuModel, menuItems, mountViewer, observeAnnotationElement, shapeMenuModel, shouldKeepOpenOnAnnotation, signatureMenuModel, signaturePreview, textStyleMenuModel, threadDeleteLabel, threadPopoverLabel, trackToolStyle, unknownCommand } from "@inkbar/core/dom";
|
|
4
|
+
import { COLOR_COLUMNS, FONT_FAMILIES, MARKUP_ICONS, MARKUP_KINDS, SHAPE_COLUMNS, SHAPE_ICONS, SHAPE_KINDS, SIGNATURE_FONTS, SIGNATURE_LABELS, SIGNATURE_TABS, TOOL_LABELS, ZOOM_LEVELS, colorMenuModel, createFocusReturn, createPluginHost, createSearchController, createSignatureDraft, createToolOptions, cssVariableDefaults, findAnnouncer, findCountText, focusInitialMenuItem, fontFamilyValue, handleFindKey, handleMenuKeys, handleRadioKeys, handleTabKeys, highlightMenuModel, lineStyleMenuModel, menuItems, mountViewer, observeAnnotationElement, pageSelectionText, shapeMenuModel, shouldKeepOpenOnAnnotation, signatureMenuModel, signaturePreview, textStyleMenuModel, threadDeleteLabel, threadPopoverLabel, trackToolStyle, unknownCommand, viewerSearchOf } from "@inkbar/core/dom";
|
|
5
5
|
import { Dialog, Popover, Select, Slot, Toolbar } from "radix-ui";
|
|
6
6
|
import { createPortal, flushSync } from "react-dom";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { ALargeSmall, AlignCenter, AlignJustify, AlignLeft, AlignRight, Bold, Check, ChevronDown, ChevronLeft, ChevronRight, Highlighter, ICON_ATTRIBUTES, Italic, MessageSquare, Minus, PenLine, PenTool, Plus, Redo2, Signature, Square, SquareDashedMousePointer, TextCursor, Trash2, Type, Underline, Undo2, ZoomIn, ZoomOut } from "@inkbar/icons";
|
|
8
|
+
import { ALargeSmall, AlignCenter, AlignJustify, AlignLeft, AlignRight, Bold, CaseSensitive, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Highlighter, ICON_ATTRIBUTES, Italic, MessageSquare, Minus, PenLine, PenTool, Plus, Redo2, Search, Signature, Square, SquareDashedMousePointer, TextCursor, Trash2, Type, Underline, Undo2, X, ZoomIn, ZoomOut } from "@inkbar/icons";
|
|
9
9
|
//#region src/context.ts
|
|
10
10
|
const InkContextObject = createContext(null);
|
|
11
11
|
/**
|
|
@@ -19,14 +19,14 @@ function useInkContext(consumer) {
|
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/use-readable.ts
|
|
22
|
-
const noop$
|
|
22
|
+
const noop$2 = () => void 0;
|
|
23
23
|
/**
|
|
24
24
|
* Mirrors a core `Readable` into React. A missing readable yields `fallback`, which must be a
|
|
25
25
|
* stable reference (a module constant): `useSyncExternalStore` compares snapshots by identity
|
|
26
26
|
* and loops on a fresh value. On the server the fallback is rendered.
|
|
27
27
|
*/
|
|
28
28
|
function useReadable(readable, fallback) {
|
|
29
|
-
const subscribe = useCallback((onChange) => readable ? readable.subscribe(() => onChange()) : noop$
|
|
29
|
+
const subscribe = useCallback((onChange) => readable ? readable.subscribe(() => onChange()) : noop$2, [readable]);
|
|
30
30
|
const get = useCallback(() => readable ? readable.get() : fallback, [readable, fallback]);
|
|
31
31
|
const server = useCallback(() => fallback, [fallback]);
|
|
32
32
|
return useSyncExternalStore(subscribe, get, server);
|
|
@@ -147,6 +147,35 @@ function useZoom() {
|
|
|
147
147
|
]);
|
|
148
148
|
}
|
|
149
149
|
//#endregion
|
|
150
|
+
//#region src/hooks/useSearch.ts
|
|
151
|
+
const CLOSED = {
|
|
152
|
+
open: false,
|
|
153
|
+
query: "",
|
|
154
|
+
matchCase: false,
|
|
155
|
+
hits: [],
|
|
156
|
+
current: -1,
|
|
157
|
+
scanning: false
|
|
158
|
+
};
|
|
159
|
+
const noop$1 = () => void 0;
|
|
160
|
+
/**
|
|
161
|
+
* The document search for hosts building their own control: the state, and the actions the
|
|
162
|
+
* find bar uses. Search is set up once InkRoot has mounted, so until then (and on the server)
|
|
163
|
+
* the state is closed and the actions do nothing. `open()` runs the search and draws the
|
|
164
|
+
* highlights even when no find bar is mounted.
|
|
165
|
+
*/
|
|
166
|
+
function useSearch() {
|
|
167
|
+
const search = useInkContext("useSearch()").search;
|
|
168
|
+
return {
|
|
169
|
+
state: useReadable(search?.state, CLOSED),
|
|
170
|
+
open: search ? (query) => search.open(query) : noop$1,
|
|
171
|
+
setQuery: search ? (query) => search.setQuery(query) : noop$1,
|
|
172
|
+
setMatchCase: search ? (on) => search.setMatchCase(on) : noop$1,
|
|
173
|
+
next: search ? () => search.next() : noop$1,
|
|
174
|
+
previous: search ? () => search.previous() : noop$1,
|
|
175
|
+
close: search ? () => search.close() : noop$1
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
150
179
|
//#region src/hooks/usePage.ts
|
|
151
180
|
function usePage() {
|
|
152
181
|
const { viewport, document } = useInkContext("usePage()");
|
|
@@ -347,10 +376,15 @@ function InkRoot({ src, assets, password, defaults, annotations, onAnnotationsCh
|
|
|
347
376
|
}, [snapshotHistory]);
|
|
348
377
|
const hostRef = useRef(null);
|
|
349
378
|
const [pluginHost, setPluginHost] = useState(null);
|
|
379
|
+
const [search, setSearch] = useState(null);
|
|
350
380
|
const hostMounts = useRef(0);
|
|
351
381
|
useLayoutEffect(() => {
|
|
352
382
|
hostMounts.current += 1;
|
|
353
383
|
if (!hostRef.current || hostRef.current.destroyed) {
|
|
384
|
+
const search = createSearchController({
|
|
385
|
+
document: readonly(plugins.document),
|
|
386
|
+
viewport: () => viewportRef.current
|
|
387
|
+
});
|
|
354
388
|
const host = createPluginHost({
|
|
355
389
|
plugins: latest.current.plugins ?? [],
|
|
356
390
|
document: readonly(plugins.document),
|
|
@@ -361,13 +395,16 @@ function InkRoot({ src, assets, password, defaults, annotations, onAnnotationsCh
|
|
|
361
395
|
},
|
|
362
396
|
root: readonly(plugins.root),
|
|
363
397
|
decorate: () => latest.current.decorateAnnotation,
|
|
364
|
-
viewport: () => viewportRef.current
|
|
398
|
+
viewport: () => viewportRef.current,
|
|
399
|
+
search: viewerSearchOf(search)
|
|
365
400
|
});
|
|
366
401
|
hostRef.current = {
|
|
367
402
|
host,
|
|
403
|
+
search,
|
|
368
404
|
destroyed: false
|
|
369
405
|
};
|
|
370
406
|
setPluginHost(host);
|
|
407
|
+
setSearch(search);
|
|
371
408
|
}
|
|
372
409
|
return () => {
|
|
373
410
|
hostMounts.current -= 1;
|
|
@@ -376,6 +413,7 @@ function InkRoot({ src, assets, password, defaults, annotations, onAnnotationsCh
|
|
|
376
413
|
if (hostMounts.current > 0 || !current || current.destroyed) return;
|
|
377
414
|
current.destroyed = true;
|
|
378
415
|
current.host.destroy();
|
|
416
|
+
current.search.destroy();
|
|
379
417
|
});
|
|
380
418
|
};
|
|
381
419
|
}, []);
|
|
@@ -582,6 +620,7 @@ function InkRoot({ src, assets, password, defaults, annotations, onAnnotationsCh
|
|
|
582
620
|
activated,
|
|
583
621
|
setActivated,
|
|
584
622
|
pluginHost,
|
|
623
|
+
search,
|
|
585
624
|
viewportEl: plugins.root,
|
|
586
625
|
history: inkHistory,
|
|
587
626
|
rootEl,
|
|
@@ -611,11 +650,20 @@ function InkRoot({ src, assets, password, defaults, annotations, onAnnotationsCh
|
|
|
611
650
|
activated,
|
|
612
651
|
setActivated,
|
|
613
652
|
pluginHost,
|
|
653
|
+
search,
|
|
614
654
|
plugins,
|
|
615
655
|
inkHistory,
|
|
616
656
|
rootEl,
|
|
617
657
|
setViewport
|
|
618
658
|
]);
|
|
659
|
+
useEffect(() => {
|
|
660
|
+
if (!rootEl || !search) return;
|
|
661
|
+
const onKeyDown = (e) => {
|
|
662
|
+
handleFindKey(e, search, () => pageSelectionText(rootEl));
|
|
663
|
+
};
|
|
664
|
+
rootEl.addEventListener("keydown", onKeyDown);
|
|
665
|
+
return () => rootEl.removeEventListener("keydown", onKeyDown);
|
|
666
|
+
}, [rootEl, search]);
|
|
619
667
|
const Comp = asChild ? Slot.Root : "div";
|
|
620
668
|
return /* @__PURE__ */ jsx(InkContextObject.Provider, {
|
|
621
669
|
value: ctx,
|
|
@@ -788,6 +836,7 @@ function InkViewport({ mode = "continuous", rotation = 0, gap = 16, buffer = 2,
|
|
|
788
836
|
tool: c.tool,
|
|
789
837
|
...c.hostTools ? { tools: c.hostTools } : {},
|
|
790
838
|
...c.pluginHost ? { plugins: c.pluginHost } : {},
|
|
839
|
+
...c.search ? { search: c.search } : {},
|
|
791
840
|
decorateAnnotation: (a) => latest.current.ctx.decorateAnnotation(a),
|
|
792
841
|
...c.toolStyle ? { toolStyle: c.toolStyle } : {},
|
|
793
842
|
toolHistory: { batch: (fn) => latest.current.ctx.history.batch(fn) },
|
|
@@ -856,6 +905,7 @@ function InkViewport({ mode = "continuous", rotation = 0, gap = 16, buffer = 2,
|
|
|
856
905
|
ctx.document,
|
|
857
906
|
ctx.status.state,
|
|
858
907
|
ctx.pluginHost,
|
|
908
|
+
ctx.search,
|
|
859
909
|
latest
|
|
860
910
|
]);
|
|
861
911
|
const { viewportEl } = ctx;
|
|
@@ -1117,6 +1167,188 @@ function InkRedo({ asChild = false, className, children, disabled, onClick, ...r
|
|
|
1117
1167
|
});
|
|
1118
1168
|
}
|
|
1119
1169
|
//#endregion
|
|
1170
|
+
//#region src/components/InkSearchButton.tsx
|
|
1171
|
+
/**
|
|
1172
|
+
* Opens the find bar; pressed while it is open. Pressing it again focuses the field. Place it
|
|
1173
|
+
* in a toolbar next to `InkFindBar`, which it needs for the field to focus. Disabled until a
|
|
1174
|
+
* document is open.
|
|
1175
|
+
*/
|
|
1176
|
+
function InkSearchButton({ asChild = false, className, children, disabled, onClick, ...rest }) {
|
|
1177
|
+
const { rootEl } = useInkContext("InkSearchButton");
|
|
1178
|
+
const { state, open } = useSearch();
|
|
1179
|
+
const { isReady } = useDocument();
|
|
1180
|
+
return /* @__PURE__ */ jsx(Toolbar.Button, {
|
|
1181
|
+
...rest,
|
|
1182
|
+
asChild,
|
|
1183
|
+
className: cx("ink-search-button", className),
|
|
1184
|
+
"data-ink-search-button": "",
|
|
1185
|
+
"aria-label": "Find",
|
|
1186
|
+
title: "Find",
|
|
1187
|
+
"aria-pressed": state.open,
|
|
1188
|
+
"data-state": state.open ? "on" : "off",
|
|
1189
|
+
disabled: !isReady || !!disabled,
|
|
1190
|
+
onClick: (e) => {
|
|
1191
|
+
onClick?.(e);
|
|
1192
|
+
if (e.defaultPrevented) return;
|
|
1193
|
+
flushSync(() => open());
|
|
1194
|
+
const field = rootEl?.querySelector("[data-ink-find-bar] input");
|
|
1195
|
+
field?.focus();
|
|
1196
|
+
field?.select();
|
|
1197
|
+
},
|
|
1198
|
+
children: children ?? /* @__PURE__ */ jsx(InkIcon, { icon: Search })
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region src/components/InkFindBar.tsx
|
|
1203
|
+
/**
|
|
1204
|
+
* The find bar: a field, the match count, previous and next, a match-case toggle and close,
|
|
1205
|
+
* a view of the root's search state. Place it anywhere inside `InkRoot`: it portals itself
|
|
1206
|
+
* into `[data-ink-viewport-root]`, the positioned ancestor the theme floats it from over the
|
|
1207
|
+
* top-right of the pages (as `InkThreadPopover` anchors to the root's overlay rather than
|
|
1208
|
+
* where it is written). It renders nothing until `InkViewport` has mounted, and is hidden
|
|
1209
|
+
* while the search is closed. While it is mounted it registers with the search controller,
|
|
1210
|
+
* which is what lets Ctrl/Cmd+F open it.
|
|
1211
|
+
*
|
|
1212
|
+
* Enter in the field steps to the next match, Shift+Enter to the previous, Escape closes.
|
|
1213
|
+
* Closing returns focus to where it was before the bar opened, else to the document.
|
|
1214
|
+
*/
|
|
1215
|
+
function InkFindBar({ className, ...rest }) {
|
|
1216
|
+
const ctx = useInkContext("InkFindBar");
|
|
1217
|
+
const { state, setQuery, setMatchCase, next, previous, close } = useSearch();
|
|
1218
|
+
const scroll = useReadable(ctx.viewportEl, null);
|
|
1219
|
+
/** The viewport root: the scroll element's parent, once InkViewport has mounted. */
|
|
1220
|
+
const target = scroll?.parentElement ?? null;
|
|
1221
|
+
const bar = useRef(null);
|
|
1222
|
+
const field = useRef(null);
|
|
1223
|
+
const live = useRef(null);
|
|
1224
|
+
/** Where focus was when the bar opened, and whether it was open on the last pass. */
|
|
1225
|
+
const before = useRef(null);
|
|
1226
|
+
const wasOpen = useRef(false);
|
|
1227
|
+
useLayoutEffect(() => {
|
|
1228
|
+
const el = bar.current;
|
|
1229
|
+
const input = field.current;
|
|
1230
|
+
if (!el || !input) return;
|
|
1231
|
+
if (state.open !== wasOpen.current) {
|
|
1232
|
+
wasOpen.current = state.open;
|
|
1233
|
+
const doc = el.ownerDocument;
|
|
1234
|
+
if (state.open) {
|
|
1235
|
+
const active = doc.activeElement;
|
|
1236
|
+
before.current = active instanceof HTMLElement && active !== doc.body && !el.contains(active) ? active : null;
|
|
1237
|
+
input.focus();
|
|
1238
|
+
input.select();
|
|
1239
|
+
} else {
|
|
1240
|
+
if (el.contains(doc.activeElement) || doc.activeElement === doc.body) (before.current?.isConnected && !el.contains(before.current) ? before.current : scroll)?.focus({ preventScroll: true });
|
|
1241
|
+
before.current = null;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
if (input.value !== state.query) {
|
|
1245
|
+
input.value = state.query;
|
|
1246
|
+
if (el.ownerDocument.activeElement === input) input.select();
|
|
1247
|
+
}
|
|
1248
|
+
}, [
|
|
1249
|
+
state.open,
|
|
1250
|
+
state.query,
|
|
1251
|
+
scroll
|
|
1252
|
+
]);
|
|
1253
|
+
const { search } = ctx;
|
|
1254
|
+
useEffect(() => {
|
|
1255
|
+
if (!search || !target) return;
|
|
1256
|
+
return search.attachBar();
|
|
1257
|
+
}, [search, target]);
|
|
1258
|
+
useEffect(() => {
|
|
1259
|
+
const el = live.current;
|
|
1260
|
+
if (!search || !el) return;
|
|
1261
|
+
const announce = findAnnouncer();
|
|
1262
|
+
const say = (s) => {
|
|
1263
|
+
const text = announce(s);
|
|
1264
|
+
if (el.textContent !== text) el.textContent = text;
|
|
1265
|
+
};
|
|
1266
|
+
say(search.state.get());
|
|
1267
|
+
return search.state.subscribe(say);
|
|
1268
|
+
}, [search, target]);
|
|
1269
|
+
useEffect(() => {
|
|
1270
|
+
const el = bar.current;
|
|
1271
|
+
if (!search || !el) return;
|
|
1272
|
+
const onKeyDown = (e) => {
|
|
1273
|
+
if (e.key !== "Escape" || e.defaultPrevented || e.isComposing) return;
|
|
1274
|
+
e.preventDefault();
|
|
1275
|
+
e.stopPropagation();
|
|
1276
|
+
search.close();
|
|
1277
|
+
};
|
|
1278
|
+
el.addEventListener("keydown", onKeyDown);
|
|
1279
|
+
return () => el.removeEventListener("keydown", onKeyDown);
|
|
1280
|
+
}, [search, target]);
|
|
1281
|
+
if (!target) return null;
|
|
1282
|
+
return createPortal(/* @__PURE__ */ jsxs("div", {
|
|
1283
|
+
...rest,
|
|
1284
|
+
ref: bar,
|
|
1285
|
+
className: cx("ink-find-bar", className),
|
|
1286
|
+
"data-ink-find-bar": "",
|
|
1287
|
+
role: "search",
|
|
1288
|
+
hidden: !state.open,
|
|
1289
|
+
children: [
|
|
1290
|
+
/* @__PURE__ */ jsx("input", {
|
|
1291
|
+
ref: field,
|
|
1292
|
+
type: "text",
|
|
1293
|
+
"aria-label": "Find in document",
|
|
1294
|
+
autoComplete: "off",
|
|
1295
|
+
spellCheck: false,
|
|
1296
|
+
onInput: (e) => setQuery(e.currentTarget.value),
|
|
1297
|
+
onKeyDown: (e) => {
|
|
1298
|
+
if (e.key !== "Enter" || e.nativeEvent.isComposing) return;
|
|
1299
|
+
e.preventDefault();
|
|
1300
|
+
if (e.shiftKey) previous();
|
|
1301
|
+
else next();
|
|
1302
|
+
}
|
|
1303
|
+
}),
|
|
1304
|
+
/* @__PURE__ */ jsx("span", {
|
|
1305
|
+
className: "ink-find-count",
|
|
1306
|
+
"data-ink-find-count": "",
|
|
1307
|
+
children: findCountText(state)
|
|
1308
|
+
}),
|
|
1309
|
+
/* @__PURE__ */ jsx("button", {
|
|
1310
|
+
type: "button",
|
|
1311
|
+
"data-ink-find-previous": "",
|
|
1312
|
+
"aria-label": "Previous match",
|
|
1313
|
+
title: "Previous match",
|
|
1314
|
+
onClick: () => previous(),
|
|
1315
|
+
children: /* @__PURE__ */ jsx(InkIcon, { icon: ChevronUp })
|
|
1316
|
+
}),
|
|
1317
|
+
/* @__PURE__ */ jsx("button", {
|
|
1318
|
+
type: "button",
|
|
1319
|
+
"data-ink-find-next": "",
|
|
1320
|
+
"aria-label": "Next match",
|
|
1321
|
+
title: "Next match",
|
|
1322
|
+
onClick: () => next(),
|
|
1323
|
+
children: /* @__PURE__ */ jsx(InkIcon, { icon: ChevronDown })
|
|
1324
|
+
}),
|
|
1325
|
+
/* @__PURE__ */ jsx("button", {
|
|
1326
|
+
type: "button",
|
|
1327
|
+
"data-ink-find-match-case": "",
|
|
1328
|
+
"aria-label": "Match case",
|
|
1329
|
+
title: "Match case",
|
|
1330
|
+
"aria-pressed": state.matchCase,
|
|
1331
|
+
onClick: () => setMatchCase(!state.matchCase),
|
|
1332
|
+
children: /* @__PURE__ */ jsx(InkIcon, { icon: CaseSensitive })
|
|
1333
|
+
}),
|
|
1334
|
+
/* @__PURE__ */ jsx("button", {
|
|
1335
|
+
type: "button",
|
|
1336
|
+
"data-ink-find-close": "",
|
|
1337
|
+
"aria-label": "Close find",
|
|
1338
|
+
title: "Close find",
|
|
1339
|
+
onClick: () => close(),
|
|
1340
|
+
children: /* @__PURE__ */ jsx(InkIcon, { icon: X })
|
|
1341
|
+
}),
|
|
1342
|
+
/* @__PURE__ */ jsx("div", {
|
|
1343
|
+
ref: live,
|
|
1344
|
+
className: "ink-visually-hidden",
|
|
1345
|
+
"data-ink-find-status": "",
|
|
1346
|
+
"aria-live": "polite"
|
|
1347
|
+
})
|
|
1348
|
+
]
|
|
1349
|
+
}), target);
|
|
1350
|
+
}
|
|
1351
|
+
//#endregion
|
|
1120
1352
|
//#region src/components/InkZoomIn.tsx
|
|
1121
1353
|
function InkZoomIn({ asChild = false, className, children, onClick, ...rest }) {
|
|
1122
1354
|
const { zoomIn } = useZoom();
|
|
@@ -2634,6 +2866,6 @@ function ThreadForm({ editingRoot, locked, deleteLabel, onSubmit, onRemove, onCl
|
|
|
2634
2866
|
});
|
|
2635
2867
|
}
|
|
2636
2868
|
//#endregion
|
|
2637
|
-
export { InkAnnotation, InkColorMenu, InkCommand, InkHighlightMenu, InkIcon, InkLineStyleMenu, InkNextPage, InkPage, InkPageCount, InkPageInput, InkPrevPage, InkRedo, InkRoot, InkShapeMenu, InkSignatureDialog, InkSignatureMenu, InkTextStyleMenu, InkThreadPopover, InkToolButton, InkToolbar, InkToolbarSeparator, InkUndo, InkViewport, InkZoomIn, InkZoomOut, InkZoomSelect, useAnnotations, useCommand, useDocument, useEmbedded, useHistory, useInkContext, usePage, useReadable, useSelection, useTool, useToolOptions, useToolStyle, useZoom };
|
|
2869
|
+
export { InkAnnotation, InkColorMenu, InkCommand, InkFindBar, InkHighlightMenu, InkIcon, InkLineStyleMenu, InkNextPage, InkPage, InkPageCount, InkPageInput, InkPrevPage, InkRedo, InkRoot, InkSearchButton, InkShapeMenu, InkSignatureDialog, InkSignatureMenu, InkTextStyleMenu, InkThreadPopover, InkToolButton, InkToolbar, InkToolbarSeparator, InkUndo, InkViewport, InkZoomIn, InkZoomOut, InkZoomSelect, useAnnotations, useCommand, useDocument, useEmbedded, useHistory, useInkContext, usePage, useReadable, useSearch, useSelection, useTool, useToolOptions, useToolStyle, useZoom };
|
|
2638
2870
|
|
|
2639
2871
|
//# sourceMappingURL=index.mjs.map
|