lean4monaco 1.0.2 → 1.0.4

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.
Files changed (42) hide show
  1. package/dist/monaco-lean4/lean4-infoview/src/index.d.ts +16 -0
  2. package/dist/monaco-lean4/lean4-infoview/src/index.js +29 -0
  3. package/dist/monaco-lean4/lean4-infoview/src/infoview/collapsing.d.ts +12 -0
  4. package/dist/monaco-lean4/lean4-infoview/src/infoview/collapsing.js +37 -0
  5. package/dist/monaco-lean4/lean4-infoview/src/infoview/contexts.d.ts +40 -0
  6. package/dist/monaco-lean4/lean4-infoview/src/infoview/contexts.js +44 -0
  7. package/dist/monaco-lean4/lean4-infoview/src/infoview/editorConnection.d.ts +22 -0
  8. package/dist/monaco-lean4/lean4-infoview/src/infoview/editorConnection.js +41 -0
  9. package/dist/monaco-lean4/lean4-infoview/src/infoview/errors.d.ts +14 -0
  10. package/dist/monaco-lean4/lean4-infoview/src/infoview/errors.js +24 -0
  11. package/dist/monaco-lean4/lean4-infoview/src/infoview/event.d.ts +33 -0
  12. package/dist/monaco-lean4/lean4-infoview/src/infoview/event.js +57 -0
  13. package/dist/monaco-lean4/lean4-infoview/src/infoview/goalLocation.d.ts +61 -0
  14. package/dist/monaco-lean4/lean4-infoview/src/infoview/goalLocation.js +87 -0
  15. package/dist/monaco-lean4/lean4-infoview/src/infoview/goals.d.ts +11 -0
  16. package/dist/monaco-lean4/lean4-infoview/src/infoview/goals.js +141 -0
  17. package/dist/monaco-lean4/lean4-infoview/src/infoview/info.d.ts +18 -0
  18. package/dist/monaco-lean4/lean4-infoview/src/infoview/info.js +278 -0
  19. package/dist/monaco-lean4/lean4-infoview/src/infoview/infos.d.ts +2 -0
  20. package/dist/monaco-lean4/lean4-infoview/src/infoview/infos.js +113 -0
  21. package/dist/monaco-lean4/lean4-infoview/src/infoview/interactiveCode.d.ts +18 -0
  22. package/dist/monaco-lean4/lean4-infoview/src/infoview/interactiveCode.js +164 -0
  23. package/dist/monaco-lean4/lean4-infoview/src/infoview/main.d.ts +13 -0
  24. package/dist/monaco-lean4/lean4-infoview/src/infoview/main.js +97 -0
  25. package/dist/monaco-lean4/lean4-infoview/src/infoview/messages.d.ts +16 -0
  26. package/dist/monaco-lean4/lean4-infoview/src/infoview/messages.js +151 -0
  27. package/dist/monaco-lean4/lean4-infoview/src/infoview/rpcSessions.d.ts +21 -0
  28. package/dist/monaco-lean4/lean4-infoview/src/infoview/rpcSessions.js +67 -0
  29. package/dist/monaco-lean4/lean4-infoview/src/infoview/serverVersion.d.ts +10 -0
  30. package/dist/monaco-lean4/lean4-infoview/src/infoview/serverVersion.js +25 -0
  31. package/dist/monaco-lean4/lean4-infoview/src/infoview/tooltips.d.ts +23 -0
  32. package/dist/monaco-lean4/lean4-infoview/src/infoview/tooltips.js +231 -0
  33. package/dist/monaco-lean4/lean4-infoview/src/infoview/traceExplorer.d.ts +11 -0
  34. package/dist/monaco-lean4/lean4-infoview/src/infoview/traceExplorer.js +115 -0
  35. package/dist/monaco-lean4/lean4-infoview/src/infoview/userWidget.d.ts +48 -0
  36. package/dist/monaco-lean4/lean4-infoview/src/infoview/userWidget.js +54 -0
  37. package/dist/monaco-lean4/lean4-infoview/src/infoview/util.d.ts +144 -0
  38. package/dist/monaco-lean4/lean4-infoview/src/infoview/util.js +366 -0
  39. package/dist/monaco-lean4/vscode-lean4/src/utils/batch.d.ts +0 -1
  40. package/dist/monaco-lean4/vscode-lean4/src/utils/envPath.d.ts +0 -1
  41. package/dist/monaco-lean4/vscode-lean4/src/utils/fsHelper.d.ts +0 -1
  42. package/package.json +3 -4
@@ -0,0 +1,16 @@
1
+ import { MessageData } from '@leanprover/infoview-api';
2
+ export * from '@leanprover/infoview-api';
3
+ export { EditorContext, EnvPosContext, VersionContext } from './infoview/contexts';
4
+ export { EditorConnection } from './infoview/editorConnection';
5
+ export { GoalLocation, GoalsLocation, LocationsContext } from './infoview/goalLocation';
6
+ export { InteractiveCode, InteractiveCodeProps } from './infoview/interactiveCode';
7
+ export { renderInfoview } from './infoview/main';
8
+ export { RpcContext, useRpcSession } from './infoview/rpcSessions';
9
+ export { ServerVersion } from './infoview/serverVersion';
10
+ export { DynamicComponent, DynamicComponentProps, PanelWidgetProps, importWidgetModule } from './infoview/userWidget';
11
+ export { DocumentPosition, mapRpcError, useAsync, useAsyncPersistent, useAsyncWithTrigger, useClientNotificationEffect, useClientNotificationState, useEvent, useEventResult, useServerNotificationEffect, useServerNotificationState, } from './infoview/util';
12
+ export { MessageData };
13
+ /** Display the given message data as interactive, pretty-printed text. */
14
+ export declare function InteractiveMessageData({ msg }: {
15
+ msg: MessageData;
16
+ }): any;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { InteractiveDiagnostics_msgToInteractive } from '@leanprover/infoview-api';
3
+ import { useRpcSession } from './infoview/rpcSessions';
4
+ import { InteractiveMessage } from './infoview/traceExplorer';
5
+ import { mapRpcError, useAsync } from './infoview/util';
6
+ export * from '@leanprover/infoview-api';
7
+ export { EditorContext, EnvPosContext, VersionContext } from './infoview/contexts';
8
+ export { EditorConnection } from './infoview/editorConnection';
9
+ export { GoalLocation, GoalsLocation, LocationsContext } from './infoview/goalLocation';
10
+ export { InteractiveCode } from './infoview/interactiveCode';
11
+ export { renderInfoview } from './infoview/main';
12
+ export { RpcContext, useRpcSession } from './infoview/rpcSessions';
13
+ export { ServerVersion } from './infoview/serverVersion';
14
+ export { DynamicComponent, importWidgetModule } from './infoview/userWidget';
15
+ export { DocumentPosition, mapRpcError, useAsync, useAsyncPersistent, useAsyncWithTrigger, useClientNotificationEffect, useClientNotificationState, useEvent, useEventResult, useServerNotificationEffect, useServerNotificationState, } from './infoview/util';
16
+ /** Display the given message data as interactive, pretty-printed text. */
17
+ export function InteractiveMessageData({ msg }) {
18
+ const rs = useRpcSession();
19
+ const interactive = useAsync(() => InteractiveDiagnostics_msgToInteractive(rs, msg, 0), [rs, msg]);
20
+ if (interactive.state === 'resolved') {
21
+ return _jsx(InteractiveMessage, { fmt: interactive.value });
22
+ }
23
+ else if (interactive.state === 'loading') {
24
+ return _jsx(_Fragment, { children: "..." });
25
+ }
26
+ else {
27
+ return (_jsxs("div", { children: ["Failed to display message:", _jsx("span", { children: mapRpcError(interactive.error).message })] }));
28
+ }
29
+ }
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ /** Returns `[node, isVisible]`. Attach `node` to the dom element you care about as `<div ref={node}>...</div>` and
3
+ * `isVisible` will change depending on whether the node is visible in the viewport or not. */
4
+ export declare function useIsVisible(): [(element: HTMLElement) => void, boolean];
5
+ interface DetailsProps {
6
+ initiallyOpen?: boolean;
7
+ children: [React.ReactNode, ...React.ReactNode[]];
8
+ setOpenRef?: (_: React.Dispatch<React.SetStateAction<boolean>>) => void;
9
+ }
10
+ /** Like `<details>` but can be programatically revealed using `setOpenRef`. */
11
+ export declare function Details({ initiallyOpen, children: [summary, ...children], setOpenRef }: DetailsProps): JSX.Element;
12
+ export {};
@@ -0,0 +1,37 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ /** Returns `[node, isVisible]`. Attach `node` to the dom element you care about as `<div ref={node}>...</div>` and
4
+ * `isVisible` will change depending on whether the node is visible in the viewport or not. */
5
+ // NOTE: Unused.
6
+ export function useIsVisible() {
7
+ const [isVisible, setIsVisible] = React.useState(false);
8
+ const observer = React.useRef(null);
9
+ const node = React.useCallback(n => {
10
+ if (observer.current) {
11
+ observer.current.disconnect();
12
+ }
13
+ if (n !== null) {
14
+ // this is called when the given element is mounted.
15
+ observer.current = new IntersectionObserver(([x]) => {
16
+ setIsVisible(x.isIntersecting);
17
+ }, { threshold: 0, root: null, rootMargin: '0px' });
18
+ observer.current.observe(n);
19
+ }
20
+ else {
21
+ // when unmounted
22
+ }
23
+ }, []);
24
+ return [node, isVisible];
25
+ }
26
+ /** Like `<details>` but can be programatically revealed using `setOpenRef`. */
27
+ export function Details({ initiallyOpen, children: [summary, ...children], setOpenRef }) {
28
+ const [isOpen, setOpen] = React.useState(initiallyOpen === undefined ? false : initiallyOpen);
29
+ const setupEventListener = React.useCallback((node) => {
30
+ if (node !== undefined && node !== null) {
31
+ node.addEventListener('toggle', () => setOpen(node.open));
32
+ }
33
+ }, []);
34
+ if (setOpenRef)
35
+ setOpenRef(setOpen);
36
+ return (_jsxs("details", { ref: setupEventListener, open: isOpen, children: [summary, isOpen && children] }));
37
+ }
@@ -0,0 +1,40 @@
1
+ export declare const EditorContext: any;
2
+ export declare const VersionContext: any;
3
+ export declare const ConfigContext: any;
4
+ export declare const LspDiagnosticsContext: any;
5
+ export declare const ProgressContext: any;
6
+ /**
7
+ * Certain infoview components and widget instances
8
+ * utilize data that has been introduced above a specific position
9
+ * in a Lean source file.
10
+ *
11
+ * For instance, if we declare a global constant with `def foo` on line 10,
12
+ * we can immediately display it in a widget on line 11.
13
+ * To achieve this, the widget code needs to have access
14
+ * to the environment on line 11 as that environment contains `foo`.
15
+ *
16
+ * {@link EnvPosContext} stores the position in the file
17
+ * from which an appropriate environment can be retrieved.
18
+ * This is used to look up global constants,
19
+ * in particular RPC methods (`@[server_rpc_method]`)
20
+ * and widget modules (`@[widget_module]`).
21
+ *
22
+ * Note that {@link EnvPosContext} may, but need not,
23
+ * be equal to any of the positions which the infoview keeps track of
24
+ * (such as the editor cursor position).
25
+ *
26
+ * #### Infoview implementation details
27
+ *
28
+ * In the infoview, {@link EnvPosContext} is set as follows:
29
+ * - in an `<InfoDisplay>`,
30
+ * it is the position at which the info block is being displayed:
31
+ * either a recent editor cursor position
32
+ * (when shown in the at-cursor `<InfoDisplay>`,
33
+ * this will lag behind the current editor cursor position
34
+ * while the `<InfoDisplay>` is in the process of updating),
35
+ * or a pinned position.
36
+ * - in an `<InteractiveMessage>` that comes from a diagnostic
37
+ * emitted with a syntactic range,
38
+ * it is the start of the diagnostic's `fullRange`.
39
+ */
40
+ export declare const EnvPosContext: any;
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import { defaultInfoviewConfig } from '@leanprover/infoview-api';
3
+ // Type-unsafe initializers for contexts which we immediately set up at the top-level.
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
5
+ export const EditorContext = React.createContext(null);
6
+ export const VersionContext = React.createContext(undefined);
7
+ export const ConfigContext = React.createContext(defaultInfoviewConfig);
8
+ export const LspDiagnosticsContext = React.createContext(new Map());
9
+ export const ProgressContext = React.createContext(new Map());
10
+ /**
11
+ * Certain infoview components and widget instances
12
+ * utilize data that has been introduced above a specific position
13
+ * in a Lean source file.
14
+ *
15
+ * For instance, if we declare a global constant with `def foo` on line 10,
16
+ * we can immediately display it in a widget on line 11.
17
+ * To achieve this, the widget code needs to have access
18
+ * to the environment on line 11 as that environment contains `foo`.
19
+ *
20
+ * {@link EnvPosContext} stores the position in the file
21
+ * from which an appropriate environment can be retrieved.
22
+ * This is used to look up global constants,
23
+ * in particular RPC methods (`@[server_rpc_method]`)
24
+ * and widget modules (`@[widget_module]`).
25
+ *
26
+ * Note that {@link EnvPosContext} may, but need not,
27
+ * be equal to any of the positions which the infoview keeps track of
28
+ * (such as the editor cursor position).
29
+ *
30
+ * #### Infoview implementation details
31
+ *
32
+ * In the infoview, {@link EnvPosContext} is set as follows:
33
+ * - in an `<InfoDisplay>`,
34
+ * it is the position at which the info block is being displayed:
35
+ * either a recent editor cursor position
36
+ * (when shown in the at-cursor `<InfoDisplay>`,
37
+ * this will lag behind the current editor cursor position
38
+ * while the `<InfoDisplay>` is in the process of updating),
39
+ * or a pinned position.
40
+ * - in an `<InteractiveMessage>` that comes from a diagnostic
41
+ * emitted with a syntactic range,
42
+ * it is the start of the diagnostic's `fullRange`.
43
+ */
44
+ export const EnvPosContext = React.createContext(undefined);
@@ -0,0 +1,22 @@
1
+ import type { Location } from 'vscode-languageserver-protocol';
2
+ import { EditorApi, InfoviewAction, InfoviewActionKind, InfoviewApi, PlainGoal, PlainTermGoal } from '@leanprover/infoview-api';
3
+ import { EventEmitter, Eventify } from './event';
4
+ import { DocumentPosition } from './util';
5
+ export type EditorEvents = Omit<Eventify<InfoviewApi>, 'requestedAction' | 'goToDefinition'> & {
6
+ requestedAction: EventEmitter<InfoviewAction, InfoviewActionKind>;
7
+ goToDefinition: EventEmitter<string, string>;
8
+ };
9
+ /** Provides higher-level wrappers around functionality provided by the editor,
10
+ * e.g. to insert a comment. See also {@link EditorApi}. */
11
+ export declare class EditorConnection {
12
+ readonly api: EditorApi;
13
+ readonly events: EditorEvents;
14
+ constructor(api: EditorApi, events: EditorEvents);
15
+ /** Highlights the given range in a document in the editor. */
16
+ revealLocation(loc: Location): Promise<void>;
17
+ revealPosition(pos: DocumentPosition): Promise<void>;
18
+ /** Copies the text to a comment at the cursor position. */
19
+ copyToComment(text: string): Promise<void>;
20
+ requestPlainGoal(pos: DocumentPosition): Promise<PlainGoal | undefined>;
21
+ requestPlainTermGoal(pos: DocumentPosition): Promise<PlainTermGoal | undefined>;
22
+ }
@@ -0,0 +1,41 @@
1
+ import { DocumentPosition } from './util';
2
+ /** Provides higher-level wrappers around functionality provided by the editor,
3
+ * e.g. to insert a comment. See also {@link EditorApi}. */
4
+ export class EditorConnection {
5
+ api;
6
+ events;
7
+ constructor(api, events) {
8
+ this.api = api;
9
+ this.events = events;
10
+ }
11
+ /** Highlights the given range in a document in the editor. */
12
+ async revealLocation(loc) {
13
+ const show = {
14
+ uri: loc.uri,
15
+ selection: loc.range,
16
+ };
17
+ await this.api.showDocument(show);
18
+ }
19
+ async revealPosition(pos) {
20
+ const loc = {
21
+ uri: pos.uri,
22
+ range: {
23
+ start: pos,
24
+ end: pos,
25
+ },
26
+ };
27
+ await this.revealLocation(loc);
28
+ }
29
+ /** Copies the text to a comment at the cursor position. */
30
+ async copyToComment(text) {
31
+ await this.api.insertText(`/-\n${text}\n-/`, 'above');
32
+ }
33
+ requestPlainGoal(pos) {
34
+ const params = DocumentPosition.toTdpp(pos);
35
+ return this.api.sendClientRequest(pos.uri, '$/lean/plainGoal', params);
36
+ }
37
+ requestPlainTermGoal(pos) {
38
+ const params = DocumentPosition.toTdpp(pos);
39
+ return this.api.sendClientRequest(pos.uri, '$/lean/plainTermGoal', params);
40
+ }
41
+ }
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ /** Error boundary as described in https://reactjs.org/docs/error-boundaries.html */
3
+ export declare class ErrorBoundary extends React.Component<{
4
+ children?: React.ReactNode;
5
+ }, {
6
+ error: string | undefined;
7
+ }> {
8
+ constructor(props: {});
9
+ static getDerivedStateFromError(error: any): {
10
+ error: any;
11
+ };
12
+ componentDidCatch(error: any, errorInfo: any): void;
13
+ render(): any;
14
+ }
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ /** Error boundary as described in https://reactjs.org/docs/error-boundaries.html */
4
+ export class ErrorBoundary extends React.Component {
5
+ constructor(props) {
6
+ super(props);
7
+ this.state = { error: undefined };
8
+ }
9
+ static getDerivedStateFromError(error) {
10
+ // Update state so the next render will show the fallback UI.
11
+ return { error: error.toString() };
12
+ }
13
+ componentDidCatch(error, errorInfo) {
14
+ // You can also log the error to an error reporting service
15
+ return;
16
+ }
17
+ render() {
18
+ if (this.state.error) {
19
+ // You can render any custom fallback UI
20
+ return (_jsxs("div", { children: [_jsx("h1", { children: "Error:" }), this.state.error, _jsx("br", {}), _jsx("br", {}), _jsx("a", { className: "link pointer dim ", onClick: () => this.setState({ error: undefined }), children: "Click to reload." })] }));
21
+ }
22
+ return this.props.children;
23
+ }
24
+ }
@@ -0,0 +1,33 @@
1
+ import type { Disposable } from 'vscode-languageserver-protocol';
2
+ export declare class EventEmitter<E, in out K> {
3
+ private freshId;
4
+ private handlers;
5
+ private handlersWithKey;
6
+ current?: E;
7
+ /**
8
+ * Register a handler that will receive events from this emitter
9
+ * and return a closure that removes the handler registration.
10
+ *
11
+ * If `key` is specified, only events fired with that key
12
+ * will be propagated to this handler.
13
+ */
14
+ on(handler: (_: E) => void, key?: K): Disposable;
15
+ /**
16
+ * Propagate the event to registered handlers.
17
+ *
18
+ * The event is propagated to all keyless handlers.
19
+ * Furthermore if `key` is provided,
20
+ * the event is also propagated to handlers registered with that key.
21
+ */
22
+ fire(event: E, key?: K): void;
23
+ }
24
+ type ExcludeNonEvent<T, U> = T extends (...args: any) => Promise<void> ? U : never;
25
+ /**
26
+ * Turn all fields in `T` which extend `(...args: As) => Promise<void>`
27
+ * into event emitter fields `f: EventEmitter<As>`.
28
+ * Other fields are removed.
29
+ */
30
+ export type Eventify<T> = {
31
+ [P in keyof T as ExcludeNonEvent<T[P], P>]: T[P] extends (arg: infer A) => Promise<void> ? EventEmitter<A, never> : T[P] extends (...args: infer As) => Promise<void> ? EventEmitter<As, never> : never;
32
+ };
33
+ export {};
@@ -0,0 +1,57 @@
1
+ export class EventEmitter {
2
+ freshId = 0;
3
+ handlers = new Map();
4
+ handlersWithKey = new Map();
5
+ current;
6
+ /**
7
+ * Register a handler that will receive events from this emitter
8
+ * and return a closure that removes the handler registration.
9
+ *
10
+ * If `key` is specified, only events fired with that key
11
+ * will be propagated to this handler.
12
+ */
13
+ on(handler, key) {
14
+ const id = this.freshId;
15
+ this.freshId += 1;
16
+ if (key) {
17
+ const handlersForKey = this.handlersWithKey.get(key) ?? [];
18
+ handlersForKey.push(handler);
19
+ this.handlersWithKey.set(key, handlersForKey);
20
+ }
21
+ else {
22
+ this.handlers.set(id, handler);
23
+ }
24
+ return {
25
+ dispose: () => {
26
+ if (key) {
27
+ const handlersForKey = this.handlersWithKey.get(key) ?? [];
28
+ // We assume that no key has so many handlers registered
29
+ // that the linear `filter` operation becomes a perf issue.
30
+ this.handlersWithKey.set(key, handlersForKey.filter(h => h !== handler));
31
+ }
32
+ else {
33
+ this.handlers.delete(id);
34
+ }
35
+ },
36
+ };
37
+ }
38
+ /**
39
+ * Propagate the event to registered handlers.
40
+ *
41
+ * The event is propagated to all keyless handlers.
42
+ * Furthermore if `key` is provided,
43
+ * the event is also propagated to handlers registered with that key.
44
+ */
45
+ fire(event, key) {
46
+ this.current = event;
47
+ for (const h of this.handlers.values()) {
48
+ h(event);
49
+ }
50
+ if (key) {
51
+ const handlersForKey = this.handlersWithKey.get(key) ?? [];
52
+ for (const h of handlersForKey) {
53
+ h(event);
54
+ }
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,61 @@
1
+ import { FVarId, MVarId, SubexprPos } from '@leanprover/infoview-api';
2
+ import * as React from 'react';
3
+ import { HoverState } from './tooltips';
4
+ /**
5
+ * A location within a goal. It is either:
6
+ * - one of the hypotheses; or
7
+ * - (a subexpression of) the type of one of the hypotheses; or
8
+ * - (a subexpression of) the value of one of the let-bound hypotheses; or
9
+ * - (a subexpression of) the goal type. */
10
+ export type GoalLocation = {
11
+ hyp: FVarId;
12
+ } | {
13
+ hypType: [FVarId, SubexprPos];
14
+ } | {
15
+ hypValue: [FVarId, SubexprPos];
16
+ } | {
17
+ target: SubexprPos;
18
+ };
19
+ export declare namespace GoalLocation {
20
+ function isEqual(l1: GoalLocation, l2: GoalLocation): boolean;
21
+ function withSubexprPos(l: GoalLocation, p: SubexprPos): GoalLocation;
22
+ }
23
+ /**
24
+ * A location within a goal state. It identifies a specific goal together with a {@link GoalLocation}
25
+ * within it. */
26
+ export interface GoalsLocation {
27
+ /** Which goal the location is in. */
28
+ mvarId: MVarId;
29
+ loc: GoalLocation;
30
+ }
31
+ export declare namespace GoalsLocation {
32
+ function isEqual(l1: GoalsLocation, l2: GoalsLocation): boolean;
33
+ function withSubexprPos(l: GoalsLocation, p: SubexprPos): GoalsLocation;
34
+ }
35
+ /**
36
+ * An interface available through a React context in components where selecting subexpressions
37
+ * makes sense. Currently this is only the goal state display. There, {@link GoalLocation}s can be
38
+ * selected. */
39
+ export interface Locations {
40
+ isSelected: (l: GoalsLocation) => boolean;
41
+ setSelected: (l: GoalsLocation, fn: React.SetStateAction<boolean>) => void;
42
+ /**
43
+ * A template for the location of the current component. It is defined if and only if the current
44
+ * component is a subexpression of a selectable expression. We use
45
+ * {@link GoalsLocation.withSubexprPos} to map this template to a complete location. */
46
+ subexprTemplate?: GoalsLocation;
47
+ }
48
+ export declare const LocationsContext: any;
49
+ type SelectableLocationProps = React.PropsWithoutRef<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>> & {
50
+ locs?: Locations;
51
+ loc?: GoalsLocation;
52
+ alwaysHighlight: boolean;
53
+ setHoverState?: React.Dispatch<React.SetStateAction<HoverState>>;
54
+ };
55
+ /**
56
+ * A `<span>` with a corresponding {@link GoalsLocation} which can be (un)selected using shift-click.
57
+ * If `locs` or `loc` is `undefined`, selection functionality is turned off. The element is also
58
+ * highlighted when hovered over if `alwaysHighlight` is `true` or `locs` and `loc` are both defined.
59
+ * `setHoverState` is passed through to {@link DetectHoverSpan}. */
60
+ export declare function SelectableLocation(props_: SelectableLocationProps): JSX.Element;
61
+ export {};
@@ -0,0 +1,87 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from 'react';
3
+ import { DetectHoverSpan } from './tooltips';
4
+ // eslint-disable-next-line @typescript-eslint/no-namespace
5
+ export var GoalLocation;
6
+ (function (GoalLocation) {
7
+ function isEqual(l1, l2) {
8
+ if ('hyp' in l1)
9
+ return 'hyp' in l2 ? l1.hyp === l2.hyp : false;
10
+ else if ('hypType' in l1)
11
+ return 'hypType' in l2 ? l1.hypType[0] === l2.hypType[0] && l1.hypType[1] === l2.hypType[1] : false;
12
+ else if ('hypValue' in l1)
13
+ return 'hypValue' in l2 ? l1.hypValue[0] === l2.hypValue[0] && l1.hypValue[1] === l2.hypValue[1] : false;
14
+ else if ('target' in l1)
15
+ return 'target' in l2 ? l1.target === l2.target : false;
16
+ else
17
+ return false;
18
+ }
19
+ GoalLocation.isEqual = isEqual;
20
+ function withSubexprPos(l, p) {
21
+ if ('hyp' in l)
22
+ return l;
23
+ else if ('hypType' in l)
24
+ return { hypType: [l.hypType[0], p] };
25
+ else if ('hypValue' in l)
26
+ return { hypValue: [l.hypValue[0], p] };
27
+ else if ('target' in l)
28
+ return { target: p };
29
+ else
30
+ throw new Error(`unrecognized GoalLocation variant ${JSON.stringify(l)}`);
31
+ }
32
+ GoalLocation.withSubexprPos = withSubexprPos;
33
+ })(GoalLocation || (GoalLocation = {}));
34
+ // eslint-disable-next-line @typescript-eslint/no-namespace
35
+ export var GoalsLocation;
36
+ (function (GoalsLocation) {
37
+ function isEqual(l1, l2) {
38
+ return l1.mvarId === l2.mvarId && GoalLocation.isEqual(l1.loc, l2.loc);
39
+ }
40
+ GoalsLocation.isEqual = isEqual;
41
+ function withSubexprPos(l, p) {
42
+ return { ...l, loc: GoalLocation.withSubexprPos(l.loc, p) };
43
+ }
44
+ GoalsLocation.withSubexprPos = withSubexprPos;
45
+ })(GoalsLocation || (GoalsLocation = {}));
46
+ export const LocationsContext = React.createContext(undefined);
47
+ /**
48
+ * A `<span>` with a corresponding {@link GoalsLocation} which can be (un)selected using shift-click.
49
+ * If `locs` or `loc` is `undefined`, selection functionality is turned off. The element is also
50
+ * highlighted when hovered over if `alwaysHighlight` is `true` or `locs` and `loc` are both defined.
51
+ * `setHoverState` is passed through to {@link DetectHoverSpan}. */
52
+ export function SelectableLocation(props_) {
53
+ const { locs, loc, alwaysHighlight, setHoverState: setParentHoverState, ...props } = props_;
54
+ const shouldHighlight = alwaysHighlight || (!!locs && !!loc);
55
+ const [hoverState, setHoverState] = React.useState('off');
56
+ let spanClassName = '';
57
+ if (shouldHighlight) {
58
+ spanClassName += 'highlightable ';
59
+ if (hoverState !== 'off')
60
+ spanClassName += 'highlight ';
61
+ if (props.className)
62
+ spanClassName += props.className;
63
+ }
64
+ const innerSpanClassName = 'highlightable ' + (locs && loc && locs.isSelected(loc) ? 'highlight-selected ' : '');
65
+ const setHoverStateAll = React.useCallback(val => {
66
+ setHoverState(val);
67
+ if (setParentHoverState)
68
+ setParentHoverState(val);
69
+ }, [setParentHoverState]);
70
+ return (_jsx(DetectHoverSpan, { ...props, setHoverState: setHoverStateAll, className: spanClassName, onClick: e => {
71
+ // On shift-click, if we are in a context where selecting subexpressions makes sense,
72
+ // (un)select the current subexpression.
73
+ if (e.shiftKey && locs && loc) {
74
+ locs.setSelected(loc, on => !on);
75
+ e.stopPropagation();
76
+ }
77
+ if (props.onClick)
78
+ props.onClick(e);
79
+ }, onPointerDown: e => {
80
+ // Since shift-click on this component is a custom selection, when shift is held prevent
81
+ // the default action which on text is to start a text selection.
82
+ if (e.shiftKey)
83
+ e.preventDefault();
84
+ if (props.onPointerDown)
85
+ props.onPointerDown(e);
86
+ }, children: _jsx("span", { className: innerSpanClassName, children: props.children }) }));
87
+ }
@@ -0,0 +1,11 @@
1
+ import { InteractiveGoals } from '@leanprover/infoview-api';
2
+ export declare function goalsToString(goals: InteractiveGoals): string;
3
+ /**
4
+ * Displays the hypotheses, target type and optional case label of a goal according to the
5
+ * provided `filter`. */
6
+ export declare const Goal: any;
7
+ /**
8
+ * Display goals together with a header containing the provided children as well as buttons
9
+ * to control how the goals are displayed.
10
+ */
11
+ export declare const FilteredGoals: any;