Skip to content

Commit

Permalink
refactor: rename package name
Browse files Browse the repository at this point in the history
  • Loading branch information
eyuelberga committed Jun 28, 2021
1 parent ab44421 commit e9fdd8e
Show file tree
Hide file tree
Showing 47 changed files with 3,248 additions and 818 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The aim of this project is to enable web developers to add support for typing no

**What does Keywrite do?**

1. It allows you to map keyboard inputs to symbols, which you define in a input-method configuration file.
1. It allows you to translate key strokes to non-latin characters, which you define in a input-method configuration file.
1. It binds with web input controls to add multi-lingual typing to your web application

**Things you can build with Keywrite**
Expand Down
58 changes: 29 additions & 29 deletions docs/input_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const myInputMethod = {
};
```

In the above input-method, the `a` key stroke is translated to the `` symbol.
Pressing `e` will output ``, pressing `e` again will output ``.
In the above input-method, the <kbd>a</kbd> key stroke is translated to the `` symbol.
Pressing <kbd>e</kbd> will output ``, pressing <kbd>e</kbd> again will output ``.

## Components of an Input-method

Expand All @@ -49,7 +49,7 @@ type InputMethod = Record<string, SymbolMap>;
`value` represents the output symbol and `next` represents the next
input-method definition.

From our previous example, the symbol map for the `a` key is this:
From our previous example, the symbol map for the <kbd>a</kbd> key is this:

```javascript
const symbolMapA = { value: '', next: null };
Expand All @@ -76,12 +76,12 @@ const inputMethodWithMoreInputKeys = {

Our inputs and outputs for the above input-method are as follows:

| Input Key | Output Symbol |
| --------- | ------------- |
| `a` ||
| `b` ||
| `c` ||
| `d` ||
| Input Key | Output Symbol |
| ------------ | ------------- |
| <kbd>a</kbd> ||
| <kbd>b</kbd> ||
| <kbd>c</kbd> ||
| <kbd>d</kbd> ||

We would also need to map certain combination of key strokes to a single character.
We can do that by nesting additional input-methods in the symbol map `next` field.
Expand Down Expand Up @@ -157,24 +157,24 @@ const myInputMethod = {

Now our input output table looks like this:

| Input Key | Output Symbol |
| --------------------- | ------------- |
| `a` ||
| `b` ||
| `b` + `l` ||
| `b` + `r` ||
| `c` ||
| `c` + `u` ||
| `c` + `u` + `n` ||
| `c` + `n` ||
| `c` + `n` + `u` ||
| `c` + `l` ||
| `c` + `l` + `n` ||
| `c` + `l` + `n` + `u` ||
| `c` + `l` + `u` ||
| `c` + `u` ||
| `c` + `u` + `n` ||
| `d` ||
| Input Key | Output Symbol |
| --------------------------------------------------------- | ------------- |
| <kbd>a</kbd> ||
| <kbd>b</kbd> ||
| <kbd>b</kbd> + <kbd>l</kbd> ||
| <kbd>b</kbd> + <kbd>r</kbd> ||
| <kbd>c</kbd> ||
| <kbd>c</kbd> + <kbd>u</kbd> ||
| <kbd>c</kbd> + <kbd>u</kbd> + <kbd>n</kbd> ||
| <kbd>c</kbd> + <kbd>n</kbd> ||
| <kbd>c</kbd> + <kbd>n</kbd> + <kbd>u</kbd> ||
| <kbd>c</kbd> + <kbd>l</kbd> ||
| <kbd>c</kbd> + <kbd>l</kbd> + <kbd>n</kbd> ||
| <kbd>c</kbd> + <kbd>l</kbd> + <kbd>n</kbd> + <kbd>u</kbd> ||
| <kbd>c</kbd> + <kbd>l</kbd> + <kbd>u</kbd> ||
| <kbd>c</kbd> + <kbd>u</kbd> ||
| <kbd>c</kbd> + <kbd>u</kbd> + <kbd>n</kbd> ||
| <kbd>d</kbd> ||

The complete code is shown below:

Expand All @@ -189,9 +189,9 @@ The complete code is shown below:

Keyboard Input-method definitions are simple JavaScript objects. It is possible
to manually write a input-method definition that will work with Keywrite,
but a better way would be to use the [Input method Generator](input-method_generator.md).
but a better way would be to use the [Input method Generator](input_method_generator.md).

## Pre-made Input-methods

Some input-methods are available pre-made and you add simply add them to your project.
A list of all available input-methods can be found [here](pre_made_input-methods.md)
A list of all available input-methods can be found [here](pre_made_input_methods.md)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lint-staged": "10.5.3",
"prettier": "2.2.1",
"ts-jest": "26.5.0",
"typescript": "^4.1.3"
"typescript": "4.1.3"
},
"workspaces": [
"packages/*"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"prepack": "yarn build",
"build": "yarn clean && tsc --build && cp \"./package.json\" ./dist/",
"test": "jest --passWithNoTests",
"generate": "ts-node src/generate-from-csv.ts",
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=10"
"generate": "ts-node src/generate-from-csv.ts"
},
"devDependencies": {
"@keywrite/input-method-generator": "^0.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Ethiopic(Language Neutral)', regions: ['ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Amharic', regions: ['am-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Awngi, Blin, Xamtanga', regions: ['awn-ET', 'byn-ER', 'xan-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Bench', regions: ['bcq-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ for (const [code, { name, path, regions }] of Object.entries(inputMethods)) {

fs.writeFileSync(
`${__dirname}/${code}.ts`,
`import { InputMethod } from '@keywrite/core';
import {InputMethodMeta, InputMethodSpec} from './interfaces';
`import {InputMethodSpec} from './interfaces';
const inputMethod : InputMethodSpec = ${JSON.stringify({
meta,
inputMethod: { ...inputMethod, ...punctuation },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: "Ge'ez", regions: ['gez-ET', 'gez-ER'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Harari', regions: ['har-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: "Dizi, Me'en, Mursi, Suri", regions: ['mym-ET', 'muz-ET', 'suq-ET', 'mdx-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Sebatbeit', regions: ['sgw-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Tigrinya(Eritrean)', regions: ['ti-ER'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: 'Tigrinya(Ethiopia)', regions: ['ti-ET'] },
inputMethod: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputMethod } from '@keywrite/core';
import { InputMethodMeta, InputMethodSpec } from './interfaces';
import { InputMethodSpec } from './interfaces';
const inputMethod: InputMethodSpec = {
meta: { name: "Silt'e", regions: ['xst-ET'] },
inputMethod: {
Expand Down
10 changes: 10 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @keywrite/web

## 0.1.1

### Patch Changes

- [`bc3cc2a`](https://github.com/eyuelberga/keywrite/commit/bc3cc2ac88eae4ed543c31e62a551c7d333f8990) [#1](https://github.com/eyuelberga/keywrite/pull/1) Thanks [@eyuelberga](https://github.com/eyuelberga)! - Initial release

- Updated dependencies [[`bc3cc2a`](https://github.com/eyuelberga/keywrite/commit/bc3cc2ac88eae4ed543c31e62a551c7d333f8990)]:
- @keywrite/core@0.1.1
31 changes: 31 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## @keywrite/web

Keywrite is a Javascript library that allows you to type non-latin scripts in any web based application using a standard keyboard.

## Installation

```sh
$ yarn add @keywrite/web

# or

$ npm install @keywrite/web
```

## Basic usage

```javascript
import { KeywriteWeb } from '@keywrite/web';

// input method definition
import layout from './layout';

// add to HTMLInputElement
new KeywriteWeb(document.querySelector('input'));
// add to HTMLTextAreaElement
new KeywriteWeb(document.querySelector('textarea'));
```

## License

MIT © [Eyuel Berga](https://github.com/eyuelberga)
5 changes: 5 additions & 0 deletions packages/react/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const baseConfig = require('../../jest.config');

module.exports = {
...baseConfig,
};
27 changes: 27 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@keywrite/react",
"version": "0.1.1",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"repository": {
"type": "git",
"directory": "packages/react",
"url": "https://github.com/eyuelberga/keywrite.git"
},
"scripts": {
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
"prepack": "yarn build",
"build": "yarn clean && tsc --build && cp \"./package.json\" ./dist/",
"test": "jest --passWithNoTests",
"lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=10"
},
"dependencies": {
"@keywrite/web": "^0.1.1"
},
"devDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
2 changes: 2 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './useKeywrite';
export { default } from './useKeywrite';
33 changes: 33 additions & 0 deletions packages/react/src/useKeywrite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState, useRef, useEffect } from 'react';
import KeywriteWeb, { Input, InputMethod } from '@keywrite/web';
export const useKeywrite = (
inputRef: React.MutableRefObject<Input | null | undefined>,
inputMethods: Record<string, InputMethod>,
isOn = true,
) => {
const KeywriteRef = useRef<KeywriteWeb | null>(null);
const [on, setOn] = useState(false);
const [inputMethodList, setInputMethodList] = useState<string[]>([]);
const [currentInputMethod, setCurrentInputMethod] = useState('');
const toggle = () => {
if (KeywriteRef.current) {
KeywriteRef.current.on = !KeywriteRef.current.on;
setOn(!on);
}
};
const changeLayout = (newInputMethod: string) => {
if (KeywriteRef.current) {
KeywriteRef.current.current = newInputMethod;
setCurrentInputMethod(KeywriteRef.current.current);
}
};
useEffect(() => {
if (inputRef.current) {
KeywriteRef.current = new KeywriteWeb(inputRef.current, inputMethods, isOn);
setOn(KeywriteRef.current.on);
setCurrentInputMethod(KeywriteRef.current.current);
setInputMethodList(KeywriteRef.current.inputMethods);
}
}, [inputRef]);
return { toggle, currentInputMethod, on, changeLayout, inputMethodList, inputRef };
};
Loading

0 comments on commit e9fdd8e

Please sign in to comment.