tess_edit 0.2.1 → 0.3.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 +4 -4
- data/README.md +31 -3
- data/app/javascript/tess_edit/controllers/editor_controller.js +115 -5
- data/app/javascript/tess_edit/core/translations.js +229 -0
- data/app/javascript/tess_edit/ui/canvas.js +84 -3
- data/app/javascript/tess_edit/ui/dialog.js +103 -0
- data/app/javascript/tess_edit/ui/icons.js +4 -1
- data/app/javascript/tess_edit/ui/inspector.js +75 -8
- data/app/javascript/tess_edit/ui/text_editing.js +114 -13
- data/app/javascript/tess_edit/ui/translate_dialog.js +30 -0
- data/app/javascript/tess_edit/ui/translation_popover.js +165 -0
- data/app/javascript/tess_edit/ui/variable_menu.js +29 -1
- data/lib/tess_edit/version.rb +1 -1
- data/vendor/javascript/tess_edit/tiptap.js +13 -13
- metadata +5 -1
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
// Condition) or "collection" (a Loop's collection)
|
|
11
11
|
// scope the loop variables there (core/variables.js loopScope)
|
|
12
12
|
//
|
|
13
|
-
// See inputAdapter below and TextEditing for Tiptap's.
|
|
13
|
+
// See inputAdapter below and TextEditing for Tiptap's. With the host's
|
|
14
|
+
// translations it also suggests their keys while typing {{ '.
|
|
14
15
|
|
|
16
|
+
import { keyCompletion, keyToken } from "tess_edit/core/translations"
|
|
15
17
|
import { completion, liquidToken } from "tess_edit/core/variables"
|
|
16
18
|
import { h } from "tess_edit/ui/dom"
|
|
17
19
|
|
|
@@ -41,6 +43,9 @@ export class VariableMenu {
|
|
|
41
43
|
|
|
42
44
|
async suggesting(adapter) {
|
|
43
45
|
const before = adapter.before()
|
|
46
|
+
const key = this.editor.translations?.enabled && adapter.mode === "output" && keyToken(before)
|
|
47
|
+
if (key) return this.suggestKeys(adapter, key)
|
|
48
|
+
if (!this.editor.variables?.enabled) return this.close()
|
|
44
49
|
const token = liquidToken(before, adapter.mode === "output" ? "output" : "expression")
|
|
45
50
|
if (!token) return this.close()
|
|
46
51
|
|
|
@@ -64,6 +69,29 @@ export class VariableMenu {
|
|
|
64
69
|
this.show({ adapter, browse: false, items, index: 0, choose: (item) => this.complete(adapter, token, start, item) })
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
// The translation keys with what's typed, those that start with it first,
|
|
73
|
+
// labelled with their text in the editor's language
|
|
74
|
+
suggestKeys(adapter, token) {
|
|
75
|
+
const translations = this.editor.translations
|
|
76
|
+
const locale = this.editor.translationLocale || translations.locales[0]
|
|
77
|
+
const partial = token.partial.toLowerCase()
|
|
78
|
+
const keys = translations.suggestions.filter((key) => key.toLowerCase().includes(partial))
|
|
79
|
+
const sorted = [...keys.filter((key) => key.toLowerCase().startsWith(partial)), ...keys.filter((key) => !key.toLowerCase().startsWith(partial))]
|
|
80
|
+
if (!sorted.length || (sorted.length === 1 && sorted[0] === token.partial)) return this.close()
|
|
81
|
+
this.request++
|
|
82
|
+
const items = sorted.slice(0, 50).map((key) => ({ name: key, label: (locale && translations.value(key, locale)) || key }))
|
|
83
|
+
this.show({
|
|
84
|
+
adapter,
|
|
85
|
+
browse: false,
|
|
86
|
+
items,
|
|
87
|
+
index: 0,
|
|
88
|
+
choose: (item) => {
|
|
89
|
+
adapter.replace(token.start, adapter.before().length, keyCompletion(item.name, token.quote, adapter.after()))
|
|
90
|
+
this.close()
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
67
95
|
async complete(adapter, token, start, item) {
|
|
68
96
|
const before = adapter.before()
|
|
69
97
|
const { text, more } = completion(item, { tag: token.tag, before: before.slice(0, start), after: adapter.after(), collection: adapter.mode === "collection" })
|
data/lib/tess_edit/version.rb
CHANGED