tess_edit 0.5.1 → 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: 2e8e699ec0535d088fb8af93ebf5a716dd4cf58aa97f156733ad00a49ddad69d
4
- data.tar.gz: 34958abf1b83a4f5d156743a38a321f60c978595e63451cc69fabbd89c718b3d
3
+ metadata.gz: 56237e4ae78a71ad87e395e50e51b32b7d5b45c36643aea13bf39e55fb731dcf
4
+ data.tar.gz: 269a64d4e87297bbd25f3827b3c762b50e29e78d8fdfff86c11a6f950a0eb309
5
5
  SHA512:
6
- metadata.gz: 9b9a028a683a104b691f70951baaf7eb1fcfaa2f804b22ca1250620821f57e43f755f1a27a683134c4d4c5ffa9ca10c2eb8c8f30bb48713eea5b13ab3dba6a95
7
- data.tar.gz: 493e8cef76f375607f1db1bc84c8ca843a7adb6303f415d4bb2ccf6acab7f7afc6b12a7eed42f986eca1970ef84deead11ba9ac90cf7b2312874cb5e017fec36
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",
@@ -476,6 +480,24 @@ export class Inspector {
476
480
  input.textarea.focus()
477
481
  }
478
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
+
479
501
  color(value, set) {
480
502
  const text = h("input", {
481
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.1"
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.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt