tess_edit 0.5.0 → 0.5.2

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: 1401c4a6e315c3ae6d07dc4ee7cf80ae9b384fb532a570d09f5e6a1593da12a0
4
- data.tar.gz: f0045ef4c910b201fade5d8f10245d61636a69f4bafd4fd6200beaaf29db6243
3
+ metadata.gz: 56237e4ae78a71ad87e395e50e51b32b7d5b45c36643aea13bf39e55fb731dcf
4
+ data.tar.gz: 269a64d4e87297bbd25f3827b3c762b50e29e78d8fdfff86c11a6f950a0eb309
5
5
  SHA512:
6
- metadata.gz: 4a35b96d1c0696e3b1152c06392efa789256443651aaac7705f2df5c58924dc281d25b23b17e23509e6b18fd88bc0c7a7a9d8d693d0a049cfe365887299bf265
7
- data.tar.gz: c6fbba58d1b069991db8aef3111950958cbbf6011ab38027cc347a8e7dd67c807a3427b0bdcbcac9ffc23637de25fdab63cbd80db92692a07a15c5eb6f8aa5d3
6
+ metadata.gz: 3063da8d408f7337c482b9e6f0f0bd0a6f5efa04519683a38a96d1e1a2cb4945900210c022d350f946652ffffc33d88b8debe0faeb0676a47a0694e9dbe179a8
7
+ data.tar.gz: 28393958e0d69c307e87b9b1ca9053d75ecc30e200cbe93c2272a4d4ecfdfffd06ced51350598ff89ac2a38d9127f9bf1e7e7fad34cd457db27cfbbb7119e295
data/README.md CHANGED
@@ -304,7 +304,7 @@ extendBlock("email", {
304
304
 
305
305
  With a `summary` the field shows collapsed to it, with a button to edit it; without one the element always shows. Its values are your form fields, submitted with the form; without the element the field doesn't show. The element moves into Inspect once and stays there, hidden while another block is selected, so your Stimulus controllers in it keep their state. Combining or splitting the panels moves it again: its controllers reconnect then, with the values typed and chosen written into the fields' attributes first. The demo has one at `/?slots=1` (`test/dummy/app/javascript/slots.js`).
306
306
 
307
- A select field's `options` can be a function of the editor, `options: (editor) => [...]`, for choices from your app. Give the editor those with `data-tess-edit-options-value` (JSON), which blocks read as `editor.options`.
307
+ A select field's `options` can be a function of the editor, `options: (editor) => [...]`, for choices from your app. Give the editor those with `data-tess-edit-options-value` (JSON), which blocks read as `editor.options`. Font family fields are a select of `editor.options.fonts`: CSS font families as text, `"Maytra"` or `"'EB Garamond', serif"`, or `{ value, label }`; without them, common web fonts (`fields.FONTS`). A font a design has that isn't among them stays selected.
308
308
 
309
309
  ## Kits
310
310
 
@@ -39,7 +39,7 @@ export default {
39
39
  {
40
40
  title: "Theme",
41
41
  fields: [
42
- { key: "data.fontFamily", label: "Font family", type: "text" },
42
+ { key: "data.fontFamily", label: "Font family", type: "font" },
43
43
  { key: "data.fontSize", label: "Font size", type: "size" },
44
44
  { key: "data.lineHeight", label: "Line height", type: "text" },
45
45
  { key: "data.textColor", label: "Text color", type: "color" }
@@ -1,7 +1,9 @@
1
1
  // Field definitions shared by the built-in blocks, and usable by custom ones.
2
2
  // A field: { key: "attributes.padding" | "data.subject", label, type, ... }.
3
- // Types: text, textarea, code, size, color, select, segmented, toggle,
4
- // spacing, list and slot (an element of the host's); see ui/inspector.js. A select's options can be a
3
+ // Types: text, textarea, code, size, color, select, font, segmented, toggle,
4
+ // spacing, list and slot (an element of the host's); see ui/inspector.js. A
5
+ // font field is a select of the host's fonts, the editor's options.fonts, or
6
+ // FONTS without them. A select's options can be a
5
7
  // function of the editor, options(editor), for choices the host gives. A
6
8
  // field's hint can be a function of its value, hint(value, node), shown as
7
9
  // it's typed (a counter).
@@ -20,6 +22,26 @@ export const VERTICAL_ALIGN = [
20
22
  { value: "bottom", label: "Bottom" }
21
23
  ]
22
24
 
25
+ // Fonts every browser and mail client has, with fallbacks
26
+ export const FONTS = [
27
+ { value: "Arial, Helvetica, sans-serif", label: "Arial" },
28
+ { value: "Helvetica, Arial, sans-serif", label: "Helvetica" },
29
+ { value: "Verdana, Geneva, sans-serif", label: "Verdana" },
30
+ { value: "Tahoma, Geneva, sans-serif", label: "Tahoma" },
31
+ { value: "'Trebuchet MS', Helvetica, sans-serif", label: "Trebuchet MS" },
32
+ { value: "Georgia, serif", label: "Georgia" },
33
+ { value: "'Times New Roman', Times, serif", label: "Times New Roman" },
34
+ { value: "'Courier New', Courier, monospace", label: "Courier New" }
35
+ ]
36
+
37
+ // A font field's options: none (the placeholder, inherited), the host's
38
+ // fonts or FONTS, and a value that is neither, as it is
39
+ export function fontOptions(fonts, value, placeholder = "Default") {
40
+ const options = (fonts?.length ? fonts : FONTS).map((font) => (typeof font === "string" ? { value: font, label: font.split(",")[0].replace(/['"]/g, "").trim() } : font))
41
+ const other = value && !options.some((option) => option.value === value) ? [{ value, label: value }] : []
42
+ return [{ value: "", label: placeholder }, ...options, ...other]
43
+ }
44
+
23
45
  export const padding = { key: "attributes.padding", label: "Padding", type: "spacing" }
24
46
  export const align = { key: "attributes.align", label: "Align", type: "segmented", options: ALIGN }
25
47
  export const background = { key: "attributes.background-color", label: "Background", type: "color" }
@@ -27,7 +49,7 @@ export const background = { key: "attributes.background-color", label: "Backgrou
27
49
  export const typography = (extra = []) => ({
28
50
  title: "Typography",
29
51
  fields: [
30
- { key: "attributes.font-family", label: "Font family", type: "text", placeholder: "Inherit" },
52
+ { key: "attributes.font-family", label: "Font family", type: "font", placeholder: "Inherit" },
31
53
  { key: "attributes.font-size", label: "Font size", type: "size", placeholder: "13px" },
32
54
  { key: "attributes.line-height", label: "Line height", type: "text", placeholder: "1" },
33
55
  { key: "attributes.letter-spacing", label: "Letter spacing", type: "size" },
@@ -33,7 +33,7 @@ export default {
33
33
  fields: [
34
34
  { key: "data.color", label: "Color", type: "color" },
35
35
  { key: "data.fontSize", label: "Font size", type: "size" },
36
- { key: "data.fontFamily", label: "Font family", type: "text", placeholder: "Inherit" },
36
+ { key: "data.fontFamily", label: "Font family", type: "font", placeholder: "Inherit" },
37
37
  { key: "data.linkPadding", label: "Padding", type: "spacing" }
38
38
  ]
39
39
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { imageSource } from "tess_edit/core/media"
18
18
  import { getBlock, label } from "tess_edit/core/registry"
19
+ import { fontOptions } from "tess_edit/blocks/fields"
19
20
  import { find, getValue } from "tess_edit/core/document"
20
21
  import { translationCalls } from "tess_edit/core/translations"
21
22
  import { loopScope } from "tess_edit/core/variables"
@@ -227,6 +228,9 @@ export class Inspector {
227
228
  })
228
229
  )
229
230
 
231
+ case "font":
232
+ return this.font(field, value, set)
233
+
230
234
  case "segmented":
231
235
  return h(
232
236
  "div",
@@ -249,7 +253,8 @@ export class Inspector {
249
253
  )
250
254
  )
251
255
 
252
- case "toggle":
256
+ case "toggle": {
257
+ const state = h("span", { class: "text-xs text-gray-600 dark:text-gray-300" }, value === field.on ? "On" : "Off")
253
258
  return h(
254
259
  "span",
255
260
  { class: "flex items-center gap-2" },
@@ -257,10 +262,14 @@ export class Inspector {
257
262
  type: "checkbox",
258
263
  class: "h-4 w-4 rounded border-gray-300 dark:border-gray-600 dark:bg-gray-700 text-blue-600 dark:text-blue-400",
259
264
  checked: value === field.on,
260
- onchange: (event) => set(event.target.checked ? field.on : field.off)
265
+ onchange: (event) => {
266
+ set(event.target.checked ? field.on : field.off)
267
+ state.textContent = event.target.checked ? "On" : "Off"
268
+ }
261
269
  }),
262
- h("span", { class: "text-xs text-gray-600 dark:text-gray-300" }, value === field.on ? "On" : "Off")
270
+ state
263
271
  )
272
+ }
264
273
 
265
274
  case "spacing":
266
275
  return this.spacing(value, set)
@@ -471,6 +480,24 @@ export class Inspector {
471
480
  input.textarea.focus()
472
481
  }
473
482
 
483
+ // The host's fonts (options.fonts) or common ones, each shown in itself
484
+ font(field, value, set) {
485
+ return h(
486
+ "select",
487
+ {
488
+ class: `${INPUT} pr-7`,
489
+ style: value ? `font-family: ${value}` : "",
490
+ onchange: (event) => {
491
+ event.target.style.fontFamily = event.target.value
492
+ set(event.target.value)
493
+ }
494
+ },
495
+ fontOptions(this.editor.options?.fonts, value, field.placeholder).map((option) =>
496
+ h("option", { value: option.value, selected: option.value === (value || ""), style: option.value ? `font-family: ${option.value}` : "" }, option.label)
497
+ )
498
+ )
499
+ }
500
+
474
501
  color(value, set) {
475
502
  const text = h("input", {
476
503
  type: "text", class: `${INPUT} font-mono text-xs`, value, placeholder: "Default", oninput: (event) => {
@@ -1,3 +1,3 @@
1
1
  module TessEdit
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
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.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt