# `Alternera.Plugin.Editor.ByMatch`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_editor/lib/alternera/plugin/editor/by_match.ex#L1)

How a step editor shows a setting a Configuration step may fill
(`Alternera.Plugin.configurable?/2`, "Settings by match" in the
plugin contract): a step that leaves it empty runs with the value of the
last Configuration step before it, so the empty field says so.

  * A text or number input takes `placeholder/3`: "From Configuration"
    with the value the step runs with in brackets ("From Configuration
    (60)"), and an example where it has neither.
  * A select or a segmented control gets a first choice
    (`choice_label/5`, "From Configuration (GET)") that stores the key
    left out; picking the default itself stores it, and the step's own
    value then wins over any Configuration step.
  * Both name the effective value: the values the Configuration steps
    that may run before the step set (the editor's `configured` prop,
    passed as the `configured:` option), and the plugin's default when
    none of them is certain to ("From Configuration (5000 or 30000, else
    60000)"). Which one applies depends on the request, so `title/3`
    says where each comes from, for the field's hover, while the step
    leaves the field empty.
  * An editor builds one `context/3` per render (its plugin, its
    `configured` prop and its stored settings) and passes it in place of
    the plugin: an input then takes `field/3`, its placeholder and hover
    as attributes to spread (`<input {ByMatch.field(@by_match, "ttl",
    default: "60")} />`), a select its first choice from
    `choice_label/5` and its hover from `title/3`.
  * A required field that is configurable may be left empty: `note/1`
    says a Configuration step must set it, or the step fails
    `not_configured` when it runs.
  * A list with no entries says a Configuration step may set it
    (`empty_hint/1`); it is set whole, never merged.

A field that is not configurable keeps the editor's own placeholder and
choices: every function here falls back to them.

# `configured`

```elixir
@type configured() :: %{optional(String.t()) =&gt; [source()]}
```

The editor's `configured` prop: by key, the steps that may set it.

# `source`

```elixir
@type source() :: %{value: term(), from: String.t(), certain?: boolean()}
```

A Configuration step that may set a key before the step: the `value` it
sets, `from` where it is (pipeline, host, conditions, step), and
`certain?` whether it runs on every request the step runs on.

# `t`

```elixir
@type t() :: %Alternera.Plugin.Editor.ByMatch{
  configured: configured(),
  plugin: module(),
  settings: map()
}
```

What every field of one editor shares (`context/3`): the plugin, the
editor's `configured` prop and the step's stored settings.

# `choice_label`

```elixir
@spec choice_label(
  module() | t(),
  String.t(),
  String.t() | nil,
  String.t() | nil,
  keyword()
) ::
  String.t() | nil
```

The label of the choice that leaves `key` out: "From Configuration
(GET)" with the plugin's default, "From Configuration" without one and
nothing that sets it, and `fallback` (the editor's own empty choice, or
nil for none) when the field is not configurable. Options as
`placeholder/3`'s `configured:` and `labels:`.

# `configurable?`

```elixir
@spec configurable?(module(), String.t()) :: boolean()
```

Whether a Configuration step may set `key` of `plugin`'s settings.

# `context`

```elixir
@spec context(module(), configured() | nil, map() | nil) :: t()
```

The `t:t/0` an editor passes to this module's functions in place of the
plugin: `configured` the editor's prop (nil reads as none), `settings`
the step's stored settings, so a field the step sets itself shows no
hover.

# `empty_hint`

Under a list or map a configurable field holds none of: a Configuration
step may set it whole. Nothing when it holds entries or is not
configurable.

## Attributes

* `id` (`:string`) (required)
* `plugin` (`:atom`) (required)
* `key` (`:string`) (required)
* `value` (`:any`) (required) - the step's stored value.
* `class` (`:any`) - Defaults to `"mt-1 text-xs text-gray-500 dark:text-gray-300"`.

# `field`

```elixir
@spec field(t(), String.t(), keyword()) :: %{
  placeholder: String.t() | nil,
  title: String.t() | nil
}
```

The placeholder and hover of `key`'s input as attributes to spread on
it: `placeholder/3` and `title/3` with the same options.

# `note`

Under a required, configurable field left empty: a Configuration step for
these requests must set it, or the step fails `not_configured`. Nothing
for a field that holds a value, is not required or is not configurable.

## Attributes

* `id` (`:string`) (required)
* `plugin` (`:atom`) (required)
* `key` (`:string`) (required)
* `value` (`:any`) (required) - the step's stored value.
* `class` (`:any`) - Defaults to `"mt-1 text-xs text-gray-500 dark:text-gray-300"`.

# `placeholder`

```elixir
@spec placeholder(module() | t(), String.t(), keyword()) :: String.t() | nil
```

The placeholder of `key`'s input. Options: `default:` the value the
plugin uses when nothing sets it ("From Configuration (60)"),
`example:` a value to show the shape of, when nothing sets it and there
is no default ("From Configuration, e.g. orders-service"), `fallback:`
the placeholder when the field is not configurable (the default or the
example otherwise), `configured:` the editor's `configured` prop and
`labels:` the words for stored values (`value_text/2`).

# `required_by_match?`

```elixir
@spec required_by_match?(module(), String.t(), term()) :: boolean()
```

Whether `key` is required, configurable and empty in `value` (`note/1` shows).

# `title`

```elixir
@spec title(module() | t(), String.t(), keyword()) :: String.t() | nil
```

The hover of `key`'s field while it is left to a Configuration step:
each value a Configuration step that may run before the step sets, with
where it is, and the default when none is certain to. Nil when the field
is not configurable, and, given a `t:t/0`, when the step sets `key`
itself: its own value wins, whatever a Configuration step sets. Options
as `placeholder/3`'s `default:`, `configured:` and `labels:`.

# `value_text`

```elixir
@spec value_text(term(), map()) :: String.t()
```

A stored value as a field shows it: `labels` first (a map from the
stored value as text to its words, such as a select's choices), on and
off for a boolean, a list joined with commas, cut at 40 characters.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
