Skip to content

Commit

Permalink
fix: use correct asdf setup (#4)
Browse files Browse the repository at this point in the history
* use tools.sh

* basic contributing docs

* fix tsup

* fix package ref

* fix types

* use dist build in demo

* separate steps

* fix build
  • Loading branch information
airtonix authored Jun 24, 2024
1 parent 5559db1 commit 1d0b54e
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 62 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ jobs:
- name: Asdf
uses: ./.github/actions/setup-tooling
with:
SetupCommand: ./setup.sh
SetupCommand: ./tools.sh

- name: Install Node Modules
uses: ./.github/actions/setup-yarn

- name: lint
run: just lint

- name: test
run: |
just unittest
just build
just integrationtest
- name: unit test
run: just unittest

- name: build
run: just build

- name: integration test
run: just integrationtest

- name: docs
run: just docs
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Asdf
uses: ./.github/actions/setup-tooling
with:
SetupCommand: ./setup.sh
SetupCommand: ./tools.sh

- name: Yarn
uses: ./.github/actions/setup-yarn
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ render(<App />);

<!--- @@inject-end: dist/docs/modules.md#Functions --->

## Contributing

This project uses ASDF and Yarn.

1. clone repo
2. make branch: `git checkout [fix|feat|docs|chore]/blah-blah` (see [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
3. run `./tools.sh`
4. run `just setup`
5. run `just demo`
6. run `just unittest`
7. run `just lint`

## Todo

- [ ] Add tests.
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@zenobius/ink-mouse",
"version": "0.0.1",
"type": "module",
"dependencies": {
"hast-util-from-html-isomorphic": "2.0.0",
"hast-util-to-html": "^9.0.0",
Expand Down Expand Up @@ -48,13 +47,13 @@
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"main": "./dist/ink-mouse/.js",
"types": "./dist/ink-mouse/.d.ts",
"main": "./dist/ink-mouse.js",
"types": "./dist/ink-mouse.d.ts",
"exports": {
".": {
"import": "./dist/ink-mouse/.js",
"require": "./dist/ink-mouse/.js",
"types": "./dist/ink-mouse/.d.ts"
"import": "./dist/ink-mouse.js",
"require": "./dist/ink-mouse.js",
"types": "./dist/ink-mouse.d.ts"
}
},
"files": [
Expand All @@ -75,4 +74,4 @@
"type": "github",
"url": "http://github.com/zenobi-us/ink-mouse"
}
}
}
13 changes: 8 additions & 5 deletions src/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import type { ComponentProps, PropsWithChildren } from 'react';
import { render, Box, Text, useStdout } from 'ink';
import type { DOMElement } from 'ink';

import { MouseProvider, useElementPosition } from '../ink-mouse';
import { useMousePosition } from '../ink-mouse';
import { useMouseAction } from '../ink-mouse';
import { useOnMouseHover } from '../ink-mouse';
import { useOnMouseClick } from '../ink-mouse';
import {
MouseProvider,
useElementPosition,
useMousePosition,
useMouseAction,
useOnMouseHover,
useOnMouseClick,
} from '../..';

function App() {
return (
Expand Down
16 changes: 8 additions & 8 deletions src/ink-mouse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { MouseProvider } from './ink-mouse/MouseProvider.js';
export { useMouse } from './ink-mouse/useMouse.js';
export { useOnMouseClick } from './ink-mouse/useOnMouseClick.js';
export { useOnMouseHover } from './ink-mouse/useOnMouseHover.js';
export { useOnMouseState } from './ink-mouse/useOnMouseState.js';
export { useMousePosition } from './ink-mouse/useMousePosition.js';
export { useElementPosition } from './ink-mouse/useElementPosition.js';
export { useMouseAction } from './ink-mouse/useMouseAction.js';
export { MouseProvider } from './ink-mouse/MouseProvider';
export { useMouse } from './ink-mouse/useMouse';
export { useOnMouseClick } from './ink-mouse/useOnMouseClick';
export { useOnMouseHover } from './ink-mouse/useOnMouseHover';
export { useOnMouseState } from './ink-mouse/useOnMouseState';
export { useMousePosition } from './ink-mouse/useMousePosition';
export { useElementPosition } from './ink-mouse/useElementPosition';
export { useMouseAction } from './ink-mouse/useMouseAction';
4 changes: 2 additions & 2 deletions src/ink-mouse/MouseContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';

import type { XtermMouseState } from './useXtermMouse.js';
import type { XtermMouseEvents } from './createXtermMouseEvents.js';
import type { XtermMouseState } from './useXtermMouse';
import type { XtermMouseEvents } from './createXtermMouseEvents';
type MousePosition = {
x: number;
y: number;
Expand Down
7 changes: 4 additions & 3 deletions src/ink-mouse/MouseProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import type { PropsWithChildren } from 'react';

import { useXtermMouse } from './useXtermMouse.js';
import { MouseContext } from './MouseContext.js';
import { useXtermMouse } from './useXtermMouse';
import { MouseContext } from './MouseContext';

function MouseProvider({ children }: PropsWithChildren) {
const mouse = useXtermMouse();
Expand All @@ -11,7 +11,8 @@ function MouseProvider({ children }: PropsWithChildren) {
<MouseContext.Provider
value={{
events: mouse.events,
action: mouse.action,
click: mouse.click,
drag: mouse.drag,
position: mouse.position,
scroll: mouse.scroll,
}}
Expand Down
2 changes: 1 addition & 1 deletion src/ink-mouse/ansiParser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from 'vitest';

import { AnsiSgrParser } from './ansiParser.js';
import { AnsiSgrParser } from './ansiParser';

test('scroll', async () => {
expect(AnsiSgrParser.isScroll('[<64;1;1M')).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion src/ink-mouse/ansiParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI_RESPONSE_PATTERNS } from './constants.js';
import { ANSI_RESPONSE_PATTERNS } from './constants';

const parseXYCoordinates = (input: string, pattern: RegExp) => {
if (!pattern.test(input)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ink-mouse/createXtermMouseEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {
MouseDragAction,
MousePosition,
MouseScrollAction,
} from './MouseContext.js';
import { TypedEventEmitter } from './createEventEmitter.js';
} from './MouseContext';
import { TypedEventEmitter } from './createEventEmitter';

const createXtermMouseEvents = () => {
return new TypedEventEmitter<{
Expand Down
2 changes: 1 addition & 1 deletion src/ink-mouse/isIntersecting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MousePosition } from './MouseContext.js';
import type { MousePosition } from './MouseContext';

// const LEFT_ADJUSTMENT = 13;
// const TOP_ADJUSTMENT = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/ink-mouse/useMouse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from 'react';

import { MouseContext } from './MouseContext.js';
import { MouseContext } from './MouseContext';

export function useMouse() {
const context = useContext(MouseContext);
Expand Down
4 changes: 2 additions & 2 deletions src/ink-mouse/useMouseAction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useState } from 'react';

import { useMouse } from './useMouse.js';
import { useMouse } from './useMouse';
import type {
MouseClickAction,
MouseDragAction,
MouseScrollAction,
} from './MouseContext.js';
} from './MouseContext';

function useMouseAction() {
const mouse = useMouse();
Expand Down
2 changes: 1 addition & 1 deletion src/ink-mouse/useMousePosition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

import { useMouse } from './useMouse.js';
import { useMouse } from './useMouse';

function useMousePosition() {
const mouse = useMouse();
Expand Down
8 changes: 4 additions & 4 deletions src/ink-mouse/useOnMouseClick.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback, useEffect, type RefObject } from 'react';
import { type DOMElement } from 'ink';

import { useMouse } from './useMouse.js';
import type { MouseClickAction, MousePosition } from './MouseContext.js';
import { isIntersecting } from './isIntersecting.js';
import { useElementPosition } from './useElementPosition.js';
import { useMouse } from './useMouse';
import type { MouseClickAction, MousePosition } from './MouseContext';
import { isIntersecting } from './isIntersecting';
import { useElementPosition } from './useElementPosition';

function useOnMouseClick(
ref: RefObject<DOMElement>,
Expand Down
8 changes: 4 additions & 4 deletions src/ink-mouse/useOnMouseHover.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback, useEffect, type RefObject } from 'react';
import { type DOMElement } from 'ink';

import { useMouse } from './useMouse.js';
import type { MousePosition } from './MouseContext.js';
import { isIntersecting } from './isIntersecting.js';
import { getElemenetPosition } from './useElementPosition.js';
import { useMouse } from './useMouse';
import type { MousePosition } from './MouseContext';
import { isIntersecting } from './isIntersecting';
import { getElemenetPosition } from './useElementPosition';

function useOnMouseHover(
ref: RefObject<DOMElement>,
Expand Down
4 changes: 2 additions & 2 deletions src/ink-mouse/useOnMouseState.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState, type RefObject } from 'react';
import { type DOMElement } from 'ink';

import { useOnMouseClick } from './useOnMouseClick.js';
import { useOnMouseHover } from './useOnMouseHover.js';
import { useOnMouseClick } from './useOnMouseClick';
import { useOnMouseHover } from './useOnMouseHover';

function useOnMouseState(ref: RefObject<DOMElement>) {
const [hovering, setHovering] = useState(false);
Expand Down
6 changes: 3 additions & 3 deletions src/ink-mouse/useXtermMouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type {
MouseDragAction,
MousePosition,
MouseScrollAction,
} from './MouseContext.js';
} from './MouseContext';
import {
createXtermMouseEvents,
type XtermMouseEvents,
} from './createXtermMouseEvents.js';
import { xtermMouse } from './xtermMouse.js';
} from './createXtermMouseEvents';
import { xtermMouse } from './xtermMouse';

function useXtermMouse() {
const events = useRef<XtermMouseEvents>(createXtermMouseEvents());
Expand Down
6 changes: 3 additions & 3 deletions src/ink-mouse/xtermMouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type {
MouseDragAction,
MousePosition,
MouseScrollAction,
} from './MouseContext.js';
import { ANSI_CODES } from './constants.js';
import { AnsiSgrParser } from './ansiParser.js';
} from './MouseContext';
import { ANSI_CODES } from './constants';
import { AnsiSgrParser } from './ansiParser';

export function xtermMouse({
onPosition,
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"rootDir": ".",
"sourceMap": true,
"declaration": true,
"moduleResolution": "node16",
"jsx": "react",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"moduleResolution": "Bundler",
"target": "es2019",
"module": "commonjs",
"module": "ES2015",
"lib": ["es2020"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "Node16",
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"esModuleInterop": true,
Expand Down
6 changes: 4 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { defineConfig } from 'tsup';

export default defineConfig((options) => {
return {
name: 'reactink-mouse',
name: 'ink-mouse',

shims: true,

entry: ['src/package_name/@/.ts'],
entry: ['src/ink-mouse.ts'],

external: ['react', 'ink'],

minify: !options.watch,
splitting: false,
Expand Down

0 comments on commit 1d0b54e

Please sign in to comment.