tess_edit 0.5.15 → 0.5.16
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 +3 -3
- data/app/javascript/tess_edit/blocks/raw.js +1 -1
- data/app/javascript/tess_edit/core/liquid_check.js +14 -4
- data/app/javascript/tess_edit/core/variables.js +32 -7
- data/app/javascript/tess_edit/ui/code_input.js +2 -0
- data/app/javascript/tess_edit/ui/inspector.js +6 -2
- data/app/javascript/tess_edit/ui/variable_menu.js +2 -1
- data/config/locales/en.yml +3 -0
- data/config/locales/nl.yml +3 -0
- data/lib/tess_edit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f94d3bf110ca08ee76b35571622ff9637dc1c0bd2ebe6959429da9bc37de14ce
|
|
4
|
+
data.tar.gz: fe49f2095f43a1238c6a9b4a58ef8e7f099453325a25090ea831821c2573b8d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7e299e82c79d5c321ac33c305305a3398bed106c6b2060eeaebf7fee01370b1dec5f8c859195eaca41912d7c37b85ede67cd21715f490999496c820201a6d56
|
|
7
|
+
data.tar.gz: 2f5fbac84e32432ab410de4b731d91fd664be39ba0bd5145707d9418f07380f20b354004137de2cf77c555d4e97dfadd67131397cf7aed326e77290a06a60218
|
data/README.md
CHANGED
|
@@ -265,7 +265,7 @@ With `data-tess-edit-filters-url-value` the editor also completes filters: after
|
|
|
265
265
|
{"filters": [{"name": "where", "label": "Those whose property has the value", "arguments": [{"name": "property", "kind": "property"}, {"name": "value", "kind": "value"}], "keeps": "collection"}]}
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
An argument's `kind` is `property`, `value` (one the property before it can have), `format` (a date's: the editor suggests strftime formats, the host's `values` first, as Liquidum gives your app's `date.formats` and `time.formats`, then common ones, each with today in it, in the language a `locale` argument before it names) or anything else, where the editor suggests variables; an argument with `values` (`[{"value": "nl", "label": "nl"}]`, as Liquidum gives `localize`'s locales) gets those, quoted. `keeps` says what a filter on a collection leaves: the same items (`"collection"`)
|
|
268
|
+
An argument's `kind` is `property`, `value` (one the property before it can have), `format` (a date's: the editor suggests strftime formats, the host's `values` first, as Liquidum gives your app's `date.formats` and `time.formats`, then common ones, each with today in it, in the language a `locale` argument before it names) or anything else, where the editor suggests variables; an argument with `values` (`[{"value": "nl", "label": "nl"}]`, as Liquidum gives `localize`'s locales) gets those, quoted. `keeps` says what a filter on a collection leaves: the same items (`"collection"`), one of them (`"item"`) or a list of the property its first argument names (`"property"`, as `map: "name"` gives, whose `first` is a name); without the endpoint Liquid's own are known. Liquidum's `/liquidum/filters` answers this way, with your app's filters as well; the dummy app's `VariablesController#filters` is an example.
|
|
269
269
|
|
|
270
270
|
With `data-tess-edit-tags-url-value` the editor completes tags after `{%`: first what goes in the block it's in (`elsif`, `else`, `when`, `endif`), then the tags, each with its label. Choosing a block writes its end tag too, with the caret where its arguments go: `{% if | %}{% endif %}`. The endpoint answers `GET` with:
|
|
271
271
|
|
|
@@ -277,9 +277,9 @@ A tag whose `syntax` is more than its name takes arguments. Liquidum's `/liquidu
|
|
|
277
277
|
|
|
278
278
|
The endpoint can change while the editor is open, say when the record a template is for changes: set `data-tess-edit-variables-url-value` again and the editor asks the new one.
|
|
279
279
|
|
|
280
|
-
A field of your own gets the `{ }` button with `liquid: true
|
|
280
|
+
A field of your own gets the `{ }` button with `liquid: true` (a text, textarea or code field, as the HTML block's), or `liquid: "expression"` (an Assign's value), `liquid: "condition"` (with its operators) or `liquid: "collection"` (what a loop goes over) for Liquid without braces.
|
|
281
281
|
|
|
282
|
-
The editor also says what's wrong with the Liquid, a moment after it's typed: a block left open (`{% if %}` without `{% endif %}`) or closed without being opened, `elsif`, `else`, `when`, `break` where they can't be, and, with the endpoints above, a variable, filter or tag that isn't there (`order.numbr`), a filter given more arguments than it takes, and a compared value a variable can't have (`line.kind == "shiping"`). Text being edited gets a wavy line under it, the reason on hover; a field the reason under it; the block a red dot in Layers (on a closed block also for the blocks in it). What only rendering can tell, a value of the wrong type or nil, isn't checked, nor what your own tags take. `core/liquid_check.js` has the checks.
|
|
282
|
+
The editor also says what's wrong with the Liquid, a moment after it's typed: a block left open (`{% if %}` without `{% endif %}`) or closed without being opened, `elsif`, `else`, `when`, `break` where they can't be, and, with the endpoints above, a variable, filter or tag that isn't there (`order.numbr`), a filter given more arguments than it takes or fewer than it needs (when the endpoint says of each argument whether it's `optional`), and a compared value a variable can't have (`line.kind == "shiping"`). Text being edited gets a wavy line under it, the reason on hover; a field the reason under it; the block a red dot in Layers (on a closed block also for the blocks in it). What only rendering can tell, a value of the wrong type or nil, isn't checked, nor what your own tags take. `core/liquid_check.js` has the checks.
|
|
283
283
|
|
|
284
284
|
### Translations
|
|
285
285
|
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
category: "content",
|
|
6
6
|
roles: ["body", "content"],
|
|
7
7
|
defaults: () => ({ data: { html: '<p style="margin:0;padding:10px 25px;">Custom HTML</p>' } }),
|
|
8
|
-
fields: [{ title: "HTML", fields: [{ key: "data.html", label: "HTML", type: "code", hint: "Copied into the email as-is. Liquid works here too." }] }],
|
|
8
|
+
fields: [{ title: "HTML", fields: [{ key: "data.html", label: "HTML", type: "code", liquid: true, hint: "Copied into the email as-is. Liquid works here too." }] }],
|
|
9
9
|
render: {
|
|
10
10
|
mjml(node, { editor, context }) {
|
|
11
11
|
const html = node.data.html || ""
|
|
@@ -76,6 +76,11 @@ export function checkStructure(text, { blocks = BLOCKS } = {}) {
|
|
|
76
76
|
return problems
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// A message with a number, its own text for 1
|
|
80
|
+
function count(many, one, number, values) {
|
|
81
|
+
return number === 1 ? t(one, values) : t(many, { ...values, count: number })
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
function problem({ start, end }, message) {
|
|
80
85
|
return { start, end, message }
|
|
81
86
|
}
|
|
@@ -192,15 +197,20 @@ async function checkFilter(piece, offset, context, local) {
|
|
|
192
197
|
|
|
193
198
|
const problems = []
|
|
194
199
|
const call = piece.slice(named[0].length).match(/^(\s*:)([\s\S]*)$/)
|
|
195
|
-
|
|
196
|
-
const argsAt = offset + named[0].length + call[1].length
|
|
197
|
-
const args = splitOutside(call[2], ",")
|
|
200
|
+
const args = call ? splitOutside(call[2], ",") : []
|
|
198
201
|
// Named arguments (t: name: user.name) aren't counted
|
|
199
202
|
const positional = args.filter((arg) => arg.trim() && !/^\s*\w+\s*:/.test(arg))
|
|
200
203
|
const takes = filter?.arguments?.length || 0
|
|
204
|
+
// Those it needs, when the host says of each whether it can be left out
|
|
205
|
+
const known = takes > 0 && filter.arguments.every((argument) => typeof argument.optional === "boolean")
|
|
206
|
+
const needs = known ? filter.arguments.filter((argument) => !argument.optional).length : 0
|
|
201
207
|
if (takes && positional.length > takes) {
|
|
202
|
-
problems.push({ start, end: start + name.length, message:
|
|
208
|
+
problems.push({ start, end: start + name.length, message: count("%{filter} takes %{count} arguments, not %{given}", "%{filter} takes 1 argument, not %{given}", takes, { filter: name, given: positional.length }) })
|
|
209
|
+
} else if (positional.length < needs) {
|
|
210
|
+
problems.push({ start, end: start + name.length, message: count("%{filter} needs %{count} arguments, not %{given}", "%{filter} needs 1 argument", needs, { filter: name, given: positional.length }) })
|
|
203
211
|
}
|
|
212
|
+
if (!call) return problems
|
|
213
|
+
const argsAt = offset + named[0].length + call[1].length
|
|
204
214
|
let at = argsAt
|
|
205
215
|
for (const arg of args) {
|
|
206
216
|
problems.push(...(await checkPaths(arg.replace(/^\s*\w+\s*:/, (key) => " ".repeat(key.length)), at, context, local)))
|
|
@@ -30,11 +30,12 @@
|
|
|
30
30
|
|
|
31
31
|
import { ancestors } from "tess_edit/core/document"
|
|
32
32
|
import { t } from "tess_edit/core/i18n"
|
|
33
|
-
import { expressionParts } from "tess_edit/core/liquid"
|
|
33
|
+
import { expressionParts, splitOutside, unquote } from "tess_edit/core/liquid"
|
|
34
34
|
|
|
35
|
-
// What filters on a collection leave, without the host's: the same items,
|
|
35
|
+
// What filters on a collection leave, without the host's: the same items, one,
|
|
36
|
+
// or a list of the property map names
|
|
36
37
|
export const KEEPS = {
|
|
37
|
-
where: "collection", where_exp: "collection", reject: "collection", sort: "collection", sort_natural: "collection",
|
|
38
|
+
map: "property", where: "collection", where_exp: "collection", reject: "collection", sort: "collection", sort_natural: "collection",
|
|
38
39
|
reverse: "collection", uniq: "collection", compact: "collection", concat: "collection",
|
|
39
40
|
first: "item", last: "item", find: "item"
|
|
40
41
|
}
|
|
@@ -104,12 +105,26 @@ export class Variables {
|
|
|
104
105
|
const parts = expressionParts(entry.expression)
|
|
105
106
|
if (!parts) return []
|
|
106
107
|
let item = false
|
|
107
|
-
|
|
108
|
+
let path = parts.path
|
|
109
|
+
let list = false
|
|
110
|
+
// Each filter with its first argument: map: "name"
|
|
111
|
+
const pieces = splitOutside(entry.expression, "|").slice(1)
|
|
112
|
+
for (const [index, name] of parts.filters.entries()) {
|
|
108
113
|
const keeps = filters.get(name)?.keeps ?? KEEPS[name]
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
const property = unquote(pieces[index]?.split(":")[1]?.split(",")[0] || "")
|
|
115
|
+
if (keeps === "property" && !item && !list && /^\w+$/.test(property)) {
|
|
116
|
+
// A list of each item's property
|
|
117
|
+
path = `${path}.first.${property}`
|
|
118
|
+
list = true
|
|
119
|
+
} else if (keeps === "item" && !item) {
|
|
120
|
+
item = true
|
|
121
|
+
} else if (keeps !== "collection") {
|
|
122
|
+
return []
|
|
123
|
+
}
|
|
111
124
|
}
|
|
112
|
-
|
|
125
|
+
// One of a list of properties is that property
|
|
126
|
+
if (list) return [item ? { variable: entry.variable, path } : { variable: entry.variable, path, list: true }]
|
|
127
|
+
return [item ? { variable: entry.variable, collection: path } : { variable: entry.variable, path }]
|
|
113
128
|
})
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -149,6 +164,7 @@ export class Variables {
|
|
|
149
164
|
// What it stands for, of the scope around it
|
|
150
165
|
const target = entry.path && (await this.variable(entry.path.split("."), scope.slice(index + 1)))
|
|
151
166
|
if (entry.captured) own.push(capturedVariable(entry))
|
|
167
|
+
else if (entry.list) own.push(listVariable(entry))
|
|
152
168
|
else own.push(entry.path ? { ...(target || { children: false }), name: entry.variable, label: t("Assigned %{path}", { path: entry.path }), assign: true } : loopVariable(entry))
|
|
153
169
|
}
|
|
154
170
|
if (scope.some((entry) => entry.collection)) own.push(FORLOOP)
|
|
@@ -175,10 +191,14 @@ export class Variables {
|
|
|
175
191
|
if (!parent.length) {
|
|
176
192
|
const own = scope.find((entry) => entry.variable === last)
|
|
177
193
|
if (last === "forloop" && !own && scope.some((entry) => entry.collection)) return FORLOOP
|
|
194
|
+
if (own?.list) return listVariable(own)
|
|
178
195
|
if (own?.path) return { ...(await this.variable(own.path.split("."), scope.slice(scope.indexOf(own) + 1))), name: last }
|
|
179
196
|
if (own?.captured) return capturedVariable(own)
|
|
180
197
|
if (own) return loopVariable(own)
|
|
181
198
|
} else if (ELEMENT.has(last)) {
|
|
199
|
+
// first and last of a list of properties: that property
|
|
200
|
+
const list = parent.length === 1 && scope.find((entry) => entry.variable === parent[0] && entry.list)
|
|
201
|
+
if (list) return { ...(await this.variable(list.path.split("."), scope.slice(scope.indexOf(list) + 1))), name: last }
|
|
182
202
|
const collection = await this.variable(parent, scope)
|
|
183
203
|
return collection?.collection ? { name: last, children: true } : null
|
|
184
204
|
}
|
|
@@ -189,6 +209,11 @@ export class Variables {
|
|
|
189
209
|
|
|
190
210
|
const FORLOOP = { name: "forloop", label: "This loop", type: "object", children: true, forloop: true }
|
|
191
211
|
|
|
212
|
+
// A map's: a list of an item's property (lines | map: "name")
|
|
213
|
+
function listVariable({ variable, path }) {
|
|
214
|
+
return { name: variable, label: t("Assigned %{path}", { path }), type: "object", collection: true, children: true, list: true }
|
|
215
|
+
}
|
|
216
|
+
|
|
192
217
|
// A {% capture %}'s variable: the text between it and its endcapture
|
|
193
218
|
function capturedVariable({ variable }) {
|
|
194
219
|
return { name: variable, label: t("Captured text"), type: "string", children: false, captured: true }
|
|
@@ -97,6 +97,8 @@ function insert(textarea, text) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function onKeydown(event) {
|
|
100
|
+
// Taken by the variable menu
|
|
101
|
+
if (event.defaultPrevented) return
|
|
100
102
|
const textarea = event.target
|
|
101
103
|
const { value, selectionStart: start, selectionEnd: end } = textarea
|
|
102
104
|
if (event.key === "Tab" && !event.altKey && !event.metaKey && !event.ctrlKey) {
|
|
@@ -234,8 +234,12 @@ export class Inspector {
|
|
|
234
234
|
case "textarea":
|
|
235
235
|
return this.variables(h("textarea", { class: `${INPUT} min-h-32`, rows: 4, value, oninput: (event) => set(event.target.value) }), node, field)
|
|
236
236
|
|
|
237
|
-
case "code":
|
|
238
|
-
|
|
237
|
+
case "code": {
|
|
238
|
+
const code = codeInput({ value, language: field.language, oninput: set, class: "h-60" })
|
|
239
|
+
// Liquid in it is completed as in a text field
|
|
240
|
+
if (field.liquid) this.variables(code.querySelector("textarea"), node, field)
|
|
241
|
+
return code
|
|
242
|
+
}
|
|
239
243
|
|
|
240
244
|
case "size":
|
|
241
245
|
return h("input", {
|
|
@@ -405,7 +405,8 @@ export function inputAdapter(input, { mode = "output", scope = [] } = {}) {
|
|
|
405
405
|
// Suggestions while typing in an input or textarea
|
|
406
406
|
export function suggestIn(menu, input, adapter) {
|
|
407
407
|
input.addEventListener("input", (event) => event.isTrusted && menu.suggest(adapter))
|
|
408
|
-
input
|
|
408
|
+
// Before the input's own keys (a code field's Tab and Enter)
|
|
409
|
+
input.addEventListener("keydown", (event) => menu.key(event), true)
|
|
409
410
|
input.addEventListener("blur", () => !menu.state?.browse && menu.close())
|
|
410
411
|
}
|
|
411
412
|
|
data/config/locales/en.yml
CHANGED
|
@@ -210,6 +210,8 @@ en:
|
|
|
210
210
|
name_doesn_t_fit_anywhere_yet_add_a_block_it_goes_in_first_o: "%{name} doesn't fit anywhere yet. Add a block it goes in first, or drag it onto the canvas."
|
|
211
211
|
name_doesn_t_fit_here_select_where_it_goes_first_or_drag_it: "%{name} doesn't fit here. Select where it goes first, or drag it onto the canvas."
|
|
212
212
|
navbar: "Navbar"
|
|
213
|
+
needs_1_argument: "%{filter} needs 1 argument"
|
|
214
|
+
needs_arguments_not: "%{filter} needs %{count} arguments, not %{given}"
|
|
213
215
|
network: "Network"
|
|
214
216
|
new_tab: "New tab"
|
|
215
217
|
no_argument_for_names_in_the_t_filter: "No argument for %{names} in the t filter"
|
|
@@ -271,6 +273,7 @@ en:
|
|
|
271
273
|
style: "Style"
|
|
272
274
|
subject: "Subject"
|
|
273
275
|
table: "Table"
|
|
276
|
+
takes_1_argument_not: "%{filter} takes 1 argument, not %{given}"
|
|
274
277
|
takes_arguments_not: "%{filter} takes %{count} arguments, not %{given}"
|
|
275
278
|
text: "Text"
|
|
276
279
|
text_color: "Text color"
|
data/config/locales/nl.yml
CHANGED
|
@@ -210,6 +210,8 @@ nl:
|
|
|
210
210
|
name_doesn_t_fit_anywhere_yet_add_a_block_it_goes_in_first_o: "%{name} past nog nergens. Voeg eerst een blok toe waar het in kan, of sleep het naar het canvas."
|
|
211
211
|
name_doesn_t_fit_here_select_where_it_goes_first_or_drag_it: "%{name} past hier niet. Selecteer eerst waar het moet komen, of sleep het naar het canvas."
|
|
212
212
|
navbar: "Navigatiebalk"
|
|
213
|
+
needs_1_argument: "%{filter} heeft 1 argument nodig"
|
|
214
|
+
needs_arguments_not: "%{filter} heeft %{count} argumenten nodig, niet %{given}"
|
|
213
215
|
network: "Netwerk"
|
|
214
216
|
new_tab: "Nieuw tabblad"
|
|
215
217
|
no_argument_for_names_in_the_t_filter: "Geen argument voor %{names} in het t-filter"
|
|
@@ -271,6 +273,7 @@ nl:
|
|
|
271
273
|
style: "Stijl"
|
|
272
274
|
subject: "Onderwerp"
|
|
273
275
|
table: "Tabel"
|
|
276
|
+
takes_1_argument_not: "%{filter} neemt 1 argument, niet %{given}"
|
|
274
277
|
takes_arguments_not: "%{filter} neemt %{count} argumenten, niet %{given}"
|
|
275
278
|
text: "Tekst"
|
|
276
279
|
text_color: "Tekstkleur"
|
data/lib/tess_edit/version.rb
CHANGED