tess_edit 0.5.15 → 0.5.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c654049e87e3662224ddb773e9efaf0dd26a2859adfae9fdf19e1939e7bc6fc
4
- data.tar.gz: a9cb5adaf4965eb613f61a0853ebeb1e2cd97d5fe0fa1a0fa3bfcdcff4c3213f
3
+ metadata.gz: 81bf024320e1b26b908b234509c20f2d3d0b28486246f677f697a73c004ec464
4
+ data.tar.gz: 6fee53efa892077a3ab1e55111de4d67a827f52091cff03e3c052bae15fc108f
5
5
  SHA512:
6
- metadata.gz: 6f10b1aafa30420f47b3af255166f6e9665b5c1baa689f399196495cb34913103d009df6972205e61cd571bd0ce9cbb25f8dd593cdbbbb1e163c3470a4437d0c
7
- data.tar.gz: 44c9f3bceafe310d0b73e1f067be40c9fa8555cff266d44dff5ec7723d30b0d67b0680054135afa7b385b464d21ad0b7b98dcdb57bb9857d0b8b7153e87cf529
6
+ metadata.gz: ba363c92cb29469719787c21fe62d2d4d2d0fa0c53d9d9764eee878e546ba5e675c9434335f45fb4a1bfb2c5f84de258e7946276743b893a8ceb93d2e8c7e312
7
+ data.tar.gz: 9fa13068fed9c8fe57d31f0abe2834a0f0aa981b5f1cf1600fc700e6c6af2217e7e812105ca7784fcbba74d653b1e8abdd40177de83f007764c99137a023672d
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"`) or one of them (`"item"`); 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.
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`, or `liquid: "expression"` (an Assign's value), `liquid: "condition"` (with its operators) or `liquid: "collection"` (what a loop goes over) for Liquid without braces.
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
- if (!call) return problems
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: t("%{filter} takes %{count} arguments, not %{given}", { filter: name, count: takes, given: positional.length }) })
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)))
@@ -246,7 +256,7 @@ async function checkPath(path, context, local) {
246
256
  if (!own) {
247
257
  context.roots ||= await variables.options("", context.scope).catch(() => [])
248
258
  if (!context.roots.length) return null
249
- if (!context.roots.some((variable) => variable.name === root)) return { at: 0, length: root.length, message: t("There's no variable %{name}", { name: root }) }
259
+ if (!context.roots.some((variable) => [root, names[0]].includes(variable.name))) return { at: 0, length: root.length, message: t("There's no variable %{name}", { name: root }) }
250
260
  }
251
261
  // Each name after it, as far as its parent's variables are known
252
262
  let at = names[0].length + 1
@@ -256,8 +266,9 @@ async function checkPath(path, context, local) {
256
266
  if (!variable?.children) return null
257
267
  const options = await variables.options(parent, scope).catch(() => [])
258
268
  if (!options.length) return null
269
+ // A method's name may end in ? (screening.payment_needed?), as Liquid allows, with or without it
259
270
  const name = names[i].replace(/\?$/, "")
260
- if (name !== "size" && !options.some((option) => option.name === name)) return { at, length: names[i].length, message: t("%{path} has no %{name}", { path: parent, name }) }
271
+ if (name !== "size" && !options.some((option) => [name, `${name}?`].includes(option.name))) return { at, length: names[i].length, message: t("%{path} has no %{name}", { path: parent, name }) }
261
272
  at += names[i].length + 1
262
273
  }
263
274
  return null
@@ -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, or one
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
- for (const name of parts.filters) {
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
- if (keeps === "item" && !item) item = true
110
- else if (keeps !== "collection") return []
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
- return [item ? { variable: entry.variable, collection: parts.path } : { variable: entry.variable, path: parts.path }]
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
- return codeInput({ value, language: field.language, oninput: set, class: "h-60" })
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.addEventListener("keydown", (event) => menu.key(event))
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
 
@@ -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"
@@ -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"
@@ -1,3 +1,3 @@
1
1
  module TessEdit
2
- VERSION = "0.5.15"
2
+ VERSION = "0.5.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tess_edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.15
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt