Skip to content

Commit

Permalink
Avoid relative imports whenever possible (#8074)
Browse files Browse the repository at this point in the history
- Change imports from `'./'` relative imports to `@/` or `shared/` whenever possible
- Imports in `shared/` and `ydoc-server` have been avoided for now in case they don't work with `@/` imports.
- Deduplicate `events.ts`, remove `useDocumentEvent` in favor of `useEvent(document,` (and same for `useDocumentEventConditional`
- Replace incorrect doc comments (`//*` and `///`) with correct doc comments (`/**`)

# Important Notes
None
  • Loading branch information
somebody1234 authored Oct 16, 2023
1 parent a85a576 commit 1fd3a03
Show file tree
Hide file tree
Showing 38 changed files with 157 additions and 470 deletions.
2 changes: 1 addition & 1 deletion app/gui2/parser-codegen/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function isSimpleRead(reader: ts.Expression): reader is ts.CallExpression {
)
}

function dbg<T extends ts.Node | undefined>(node: T): T {
function _dbg<T extends ts.Node | undefined>(node: T): T {
if (node == null) {
console.log(node)
return node
Expand Down
25 changes: 0 additions & 25 deletions app/gui2/shared/events.ts

This file was deleted.

10 changes: 7 additions & 3 deletions app/gui2/src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { usePointer } from '@/util/events'
import { useLocalStorage } from '@vueuse/core'
import { computed, onMounted, ref, watchEffect } from 'vue'
import * as Y from 'yjs'
import { qnJoin, tryQualifiedName } from '../util/qualifiedName'
import { unwrap } from '../util/result'
// Use dynamic imports to aid code splitting. The codemirror dependency is quite large.
const {
Expand Down Expand Up @@ -80,9 +82,11 @@ watchEffect(() => {
.appendChild(document.createTextNode(`Type: ${expressionInfo.typename ?? 'Unknown'}`))
const method = expressionInfo?.methodCall?.methodPointer
if (method != null) {
const suggestionEntry = suggestionDbStore.methodPointerToEntry
.get(method.module)
?.get(method.name)
const moduleName = tryQualifiedName(method.module)
const methodName = tryQualifiedName(method.name)
const qualifiedName = qnJoin(unwrap(moduleName), unwrap(methodName))
const [id] = suggestionDbStore.entries.nameToId.lookup(qualifiedName)
const suggestionEntry = id != null ? suggestionDbStore.entries.get(id) : undefined
if (suggestionEntry != null) {
const groupNode = dom.appendChild(document.createElement('div'))
groupNode.appendChild(document.createTextNode('Group: '))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
labelOfEntry,
type MatchedSuggestion,
} from '@/components/ComponentBrowser/component'
import { Filtering } from '@/components/ComponentBrowser/filtering'
import {
makeCon,
makeMethod,
Expand All @@ -13,7 +14,6 @@ import {
makeStaticMethod,
} from '@/stores/suggestionDatabase/entry'
import shuffleSeed from 'shuffle-seed'
import { Filtering } from '../filtering'

test.each([
[makeModuleMethod('Standard.Base.Data.read'), 'Data.read'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from 'vitest'

import { Filtering } from '@/components/ComponentBrowser/filtering'
import {
makeCon,
makeFunction,
Expand All @@ -11,7 +12,6 @@ import {
makeType,
} from '@/stores/suggestionDatabase/entry'
import type { QualifiedName } from '@/util/qualifiedName'
import { Filtering } from '../filtering'

test.each([
{ ...makeModuleMethod('Standard.Base.Data.read'), groupIndex: 0 },
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/components/ComponentBrowser/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Filtering, type MatchResult } from '@/components/ComponentBrowser/filtering'
import { SuggestionDb } from '@/stores/suggestionDatabase'
import {
SuggestionKind,
Expand All @@ -7,7 +8,6 @@ import {
import { compareOpt } from '@/util/compare'
import { isSome } from '@/util/opt'
import { qnIsTopElement, qnLastSegment } from '@/util/qualifiedName'
import { Filtering, type MatchResult } from './filtering'

export interface Component {
suggestionId: SuggestionId
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/components/ComponentBrowser/input.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Filter } from '@/components/ComponentBrowser/filtering'
import { Ast, astContainingChar, parseEnso, readAstSpan, readTokenSpan } from '@/util/ast'
import { GeneralOprApp } from '@/util/ast/opr'
import { tryQualifiedName, type QualifiedName } from '@/util/qualifiedName'
import { computed, ref, type ComputedRef, type Ref } from 'vue'
import type { Filter } from './filtering'

/** Input's editing context.
*
Expand Down
6 changes: 2 additions & 4 deletions app/gui2/src/components/ExecutionModeSelector.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script setup lang="ts">
import SvgIcon from '@/components/SvgIcon.vue'
import { useDocumentEvent } from '@/util/events'
import { useEvent } from '@/util/events'
import { ref } from 'vue'
const props = defineProps<{ modes: string[]; modelValue: string }>()
Expand All @@ -21,7 +19,7 @@ function onDocumentClick(event: MouseEvent) {
}
}
useDocumentEvent('click', onDocumentClick)
useEvent(document, 'click', onDocumentClick)
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions app/gui2/src/components/GraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useProjectStore } from '@/stores/project'
import type { Rect } from '@/stores/rect'
import { useSuggestionDbStore } from '@/stores/suggestionDatabase'
import { colorFromString } from '@/util/colors'
import { keyboardBusy, keyboardBusyExceptIn, usePointer, useWindowEvent } from '@/util/events'
import { keyboardBusy, keyboardBusyExceptIn, useEvent, usePointer } from '@/util/events'
import { useNavigator } from '@/util/navigator'
import { Vec2 } from '@/util/vec2'
import * as set from 'lib0/set'
Expand Down Expand Up @@ -44,7 +44,7 @@ function updateExprRect(id: ExprId, rect: Rect) {
exprRects.set(id, rect)
}
useWindowEvent('keydown', (event) => {
useEvent(window, 'keydown', (event) => {
graphBindingsHandler(event) || nodeSelectionHandler(event) || codeEditorHandler(event)
})
Expand Down
9 changes: 3 additions & 6 deletions app/gui2/src/components/GraphNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import type { Node } from '@/stores/graph'
import { useProjectStore } from '@/stores/project'
import { Rect } from '@/stores/rect'
import { useSuggestionDbStore } from '@/stores/suggestionDatabase'
import {
DEFAULT_VISUALIZATION_CONFIGURATION,
DEFAULT_VISUALIZATION_IDENTIFIER,
Expand All @@ -27,7 +28,6 @@ import { unwrap } from '@/util/result'
import type { Vec2 } from '@/util/vec2'
import type { ContentRange, ExprId, VisualizationIdentifier } from 'shared/yjsModel'
import { computed, onUpdated, reactive, ref, shallowRef, watch, watchEffect } from 'vue'
import { useSuggestionDbStore } from '../stores/suggestionDatabase'
const MAXIMUM_CLICK_LENGTH_MS = 300
Expand Down Expand Up @@ -432,11 +432,8 @@ const suggestionEntry = computed(() => {
if (!moduleName.ok || !methodName.ok) return undefined
const qualifiedName = qnJoin(unwrap(moduleName), unwrap(methodName))
const [id] = suggestionDbStore.entries.nameToId.lookup(qualifiedName)
if (id) {
return suggestionDbStore.entries.get(id)
} else {
return undefined
}
if (id == null) return undefined
return suggestionDbStore.entries.get(id)
})
const icon = computed(() => {
if (suggestionEntry.value?.iconName) {
Expand Down
7 changes: 3 additions & 4 deletions app/gui2/src/components/SelectionBrush.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script setup lang="ts">
import { computed, ref, watch, type Ref } from 'vue'
import { useApproach } from '@/util/animation'
import { useDocumentEvent } from '@/util/events'
import { useEvent } from '@/util/events'
import type { Vec2 } from '@/util/vec2'
import { computed, ref, watch, type Ref } from 'vue'
const props = defineProps<{
position: Vec2
Expand All @@ -20,7 +19,7 @@ watch(
)
let lastEventTarget: Element | null
useDocumentEvent('mouseover', (event) => {
useEvent(document, 'mouseover', (event) => {
if (event.target instanceof Element) {
if (event.target === lastEventTarget) {
return
Expand Down
4 changes: 1 addition & 3 deletions app/gui2/src/components/VisualizationContainer.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<script setup lang="ts">
import SvgIcon from '@/components/SvgIcon.vue'
import VisualizationSelector from '@/components/VisualizationSelector.vue'
import { useVisualizationConfig } from '@/providers/visualizationConfig'
import { PointerButtonMask, usePointer } from '@/util/events'
import { ref } from 'vue'
import { useVisualizationConfig } from '../providers/visualizationConfig'
const props = defineProps<{
/** If true, the visualization should be `overflow: visible` instead of `overflow: hidden`. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ import * as d3 from 'd3'
import SvgIcon from '@/components/SvgIcon.vue'
import VisualizationContainer from '@/components/VisualizationContainer.vue'
import { useVisualizationConfig } from '@/providers/visualizationConfig.ts'
import { useVisualizationConfig } from '@/providers/visualizationConfig'
import { useEvent, useEventConditional } from './events.ts'
import { getTextWidth } from './measurement.ts'
import { useEvent, useEventConditional } from '@/util/events'
import { getTextWidth } from '@/util/measurement'
const MARGIN = 25
const AXIS_LABEL_HEIGHT = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { computed } from 'vue'
import * as sqlFormatter from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
import VisualizationContainer from '@/components/VisualizationContainer.vue'
import { DEFAULT_THEME, type RGBA, type Theme } from './builtins.ts'
import { DEFAULT_THEME, type RGBA, type Theme } from '@/components/visualizations/builtins'
const props = defineProps<{ data: Data }>()
Expand Down
Loading

0 comments on commit 1fd3a03

Please sign in to comment.