marathi_typing 0.1.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.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a972fdc675dc4f764df511984f1f61bef95845d9545affce413f3626f0fc0036
|
4
|
+
data.tar.gz: cb4c9eb324f4e6c47d6c4837223cea98ce211ec960193415d4fa4bbc9d5a8962
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6faa10db25acb067951a28886f5e1147b43648bdc2e13748b6e69cabef2a57ee4408af53baeff57d331d1885858a520f84fcc097daf4fc261794a6d44981d6b0
|
7
|
+
data.tar.gz: 7ee3789aa33c9eb2d18c2ce5e03ccd553e0543c10814501ba9c488e5289c497c2c74bff3e3fb931ca8049a3475031c0e8fda550c02015dda540065cd157e4f1a
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# lib/generators/marathi_typing/install_generator.rb
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module MarathiTyping
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
desc 'Installs the marathi_typing Stimulus controller'
|
8
|
+
|
9
|
+
def copy_controller
|
10
|
+
copy_file 'marathi_typing_controller.js', 'app/javascript/controllers/marathi_typing_controller.js'
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_instructions
|
14
|
+
say '✅ Marathi Typing installed!'
|
15
|
+
say '👉 Add `data-controller="marathi-typing"` and class `marathi-typing` to your input fields.'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ["input"]
|
5
|
+
timeout = null
|
6
|
+
|
7
|
+
|
8
|
+
connect() {
|
9
|
+
|
10
|
+
this.apiUrl = "https://inputtools.google.com/request"
|
11
|
+
|
12
|
+
const input = this.inputTarget
|
13
|
+
|
14
|
+
this.suggestionsTarget = this.buildSuggestionsBox()
|
15
|
+
|
16
|
+
input.addEventListener("keydown", (e) => {
|
17
|
+
|
18
|
+
if (e.key === " ") {
|
19
|
+
this.skipNextSuggestionFetch = true;
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
input.addEventListener("input", (e) => {
|
24
|
+
|
25
|
+
if (this.skipNextSuggestionFetch) {
|
26
|
+
|
27
|
+
this.skipNextSuggestionFetch = false;
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
this.fetchSuggestions(e);
|
31
|
+
});
|
32
|
+
|
33
|
+
input.addEventListener("keyup", (e) => {
|
34
|
+
|
35
|
+
if (e.key === " ") {
|
36
|
+
|
37
|
+
this.selectFirstSuggestion();
|
38
|
+
}
|
39
|
+
});
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
fetchSuggestions(event) {
|
44
|
+
const value = event.target.value.trim()
|
45
|
+
if (!value) return
|
46
|
+
|
47
|
+
clearTimeout(this.timeout)
|
48
|
+
this.timeout = setTimeout(() => {
|
49
|
+
const lastWord = value.split(" ").pop()
|
50
|
+
|
51
|
+
fetch(`${this.apiUrl}?text=${lastWord}&itc=mr-t-i0-und&num=5&cp=0&cs=1&ie=utf-8&oe=utf-8&app=demopage`)
|
52
|
+
.then(res => res.json())
|
53
|
+
.then(data => {
|
54
|
+
if (data[0] === "SUCCESS") {
|
55
|
+
const suggestions = data[1][0][1]
|
56
|
+
this.showSuggestions(suggestions, lastWord)
|
57
|
+
}
|
58
|
+
})
|
59
|
+
}, 300)
|
60
|
+
}
|
61
|
+
|
62
|
+
buildSuggestionsBox() {
|
63
|
+
|
64
|
+
const box = document.createElement("div")
|
65
|
+
box.className = "marathi-suggestions";
|
66
|
+
box.style.position = "absolute";
|
67
|
+
box.style.background = "#fff";
|
68
|
+
box.style.border = "0px solid #ccc";
|
69
|
+
box.style.zIndex = "9999";
|
70
|
+
box.style.padding = "0px";
|
71
|
+
box.style.color = "black";
|
72
|
+
|
73
|
+
// Get the position of the input field
|
74
|
+
const rect = this.inputTarget.getBoundingClientRect();
|
75
|
+
const scrollOffset = window.scrollY || window.pageYOffset;
|
76
|
+
|
77
|
+
box.style.top = `${rect.bottom + scrollOffset}px`;
|
78
|
+
box.style.left = `${rect.left}px`; //
|
79
|
+
|
80
|
+
this.element.parentElement.appendChild(box)
|
81
|
+
|
82
|
+
return box
|
83
|
+
}
|
84
|
+
|
85
|
+
showSuggestions(suggestions, lastWord) {
|
86
|
+
this.suggestionsTarget.innerHTML = ""
|
87
|
+
this.suggestionsTarget.style.border = "1px solid #ccc";
|
88
|
+
this.suggestionsTarget.style.border = "4px";
|
89
|
+
|
90
|
+
|
91
|
+
suggestions.forEach(suggestion => {
|
92
|
+
const option = document.createElement("div")
|
93
|
+
option.textContent = suggestion
|
94
|
+
option.className = "marathi-suggestion"
|
95
|
+
option.style.cursor = "pointer"
|
96
|
+
option.onclick = () => this.selectSuggestion(suggestion, lastWord)
|
97
|
+
this.suggestionsTarget.appendChild(option)
|
98
|
+
})
|
99
|
+
|
100
|
+
const originalOption = document.createElement("div");
|
101
|
+
originalOption.textContent = lastWord;
|
102
|
+
originalOption.className = "marathi-suggestion";
|
103
|
+
originalOption.style.cursor = "pointer";
|
104
|
+
originalOption.onclick = () => this.selectSuggestion(lastWord, lastWord);
|
105
|
+
this.suggestionsTarget.appendChild(originalOption);
|
106
|
+
}
|
107
|
+
|
108
|
+
selectFirstSuggestion() {
|
109
|
+
|
110
|
+
if (!this.suggestionsTarget || this.suggestionsTarget.children.length === 0) return;
|
111
|
+
|
112
|
+
const firstOption = this.suggestionsTarget.querySelector(".marathi-suggestion");
|
113
|
+
|
114
|
+
if (firstOption) {
|
115
|
+
const suggestion = firstOption.textContent;
|
116
|
+
const value = this.inputTarget.value.trim();
|
117
|
+
const lastWord = value.split(" ").pop();
|
118
|
+
this.selectSuggestion(suggestion, lastWord);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
selectSuggestion(selected, lastWord) {
|
124
|
+
let currentValue = this.inputTarget.value;
|
125
|
+
const trailingSpace = currentValue.endsWith(" ") ? " " : "";
|
126
|
+
|
127
|
+
// Remove trailing space temporarily
|
128
|
+
currentValue = currentValue.trimEnd();
|
129
|
+
|
130
|
+
// Replace the last word
|
131
|
+
const newValue = currentValue.replace(new RegExp(`${lastWord}$`), selected);
|
132
|
+
|
133
|
+
// Re-apply trailing space if needed
|
134
|
+
this.inputTarget.value = newValue + trailingSpace;
|
135
|
+
|
136
|
+
this.suggestionsTarget.innerHTML = "";
|
137
|
+
this.suggestionsTarget.style.border = "0";
|
138
|
+
this.suggestionsTarget.style.padding = "0";
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marathi_typing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ajit Dhanje
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
email:
|
13
|
+
- ajitdhanje@gmail.com
|
14
|
+
executables: []
|
15
|
+
extensions: []
|
16
|
+
extra_rdoc_files: []
|
17
|
+
files:
|
18
|
+
- lib/generators/marathi_typing/install_generator.rb
|
19
|
+
- lib/generators/marathi_typing/templates/marathi_typing_controller.js
|
20
|
+
- lib/marathi_typing.rb
|
21
|
+
- lib/marathi_typing/engine.rb
|
22
|
+
- lib/marathi_typing/version.rb
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.1.0
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.6.6
|
41
|
+
specification_version: 4
|
42
|
+
summary: Enable Marathi transliteration typing with Stimulus
|
43
|
+
test_files: []
|