Skip to main content

Data Binding

A palette section becomes editable in the property panel through two attributes on its elements:

  • data-id: the element's identity. Leave it empty (data-id="") in palette sections. Live.Dnd fills an empty one from the section's own id, in document order (<section id>-1, -2, ...), and the panel and the canvas preview use the same ids. They're written into the source with the first edit to that section, so opening a document doesn't change it.
  • data-binding: an array describing which props of that element the panel can edit, and how.
<h1
data-id=""
data-binding={[{ label: 'Title', property: 'innerText', required: true }]}
>
Welcome
</h1>

Each entry in the array is one field in the panel. The rest of this page lists what an entry can declare.

The default palette (the sections Live.Dnd shows when you pass no items) uses every option on this page. Its Roadmap section is the most complete example, and you can try it in the Drag & Drop demo.

Who owns what​

The library owns what a value is and what it may be: its data kind (type) and its constraints (min, max, pattern, required). The built-in panel picks a default control from those and validates edits against them.

How a field is drawn belongs to the panel. widget is carried through to your panel untouched; the built-in panel never reads it. The library ships no widgets, so a widget value does nothing until your own code handles it (see widget). Switch on it in renderField to replace individual controls while keeping the built-in panel, or in a custom panel.

Fields​

FieldTypeMeaning
labelstringRequired. The field's heading in the panel. Must be unique within one element.
propertystringThe prop to edit. See Properties. Can be omitted only for type: 'richtext', which then edits innerHTML.
typeBindingTypeThe data kind. Picks the default control and how the value is validated and written back. See Types.
options{ label: string; value: string }[]A fixed set of values. The built-in panel shows a select.
optionsOnlybooleanWith options, the only values allowed: anything else but empty is rejected, and the built-in panel always shows the select. It limits the panel, not the code editor.
min / maxnumberRange for a number value.
patternstringA regular expression (as a string) a text value must contain a match for. It isn't anchored: write ^…$ to match the whole value.
patternMessagestringThe message for a failed pattern, instead of the generic one.
requiredbooleanAn empty value is rejected.
minLength / maxLengthnumberLength limits for a text value, in characters.
stepnumberA number value must be min (or 0) plus a whole number of steps. step: 1 allows integers only.
minItems / maxItemsnumberItem count limits for an array value. The built-in editor disables add, duplicate and delete at the limits, and never removes the last item.
minDate / maxDatestringThe earliest and latest date or datetime value, as YYYY-MM-DD or YYYY-MM-DDTHH:mm. A date-only bound includes the whole day.
protocolsstring[]The schemes a url value may use, such as ['https:', 'mailto:']. Unset allows any.
renderBindingRenderMapTypes the keys inside an object or array value. See Nested fields.
widgetstring or { type: string; ...settings }A control name you define, plus any settings your control needs. Not a built-in option; ignored by the built-in panel. See widget.
any other keyunknownKept as-is under binding.meta for your own panel (a group name, a hint, ...).

A malformed value never removes the field. An unknown type, a min that is not a number, or an invalid widget is dropped on its own, and the rest of the entry still works.

Properties​

property names what the field edits:

propertyEdits
innerTextThe element's text content.
innerHTMLThe element's HTML content. Used by type: 'richtext'.
childrenThe element's JSX children, as a reorderable list.
items / dataAn array prop, as a list of items you can add, move, duplicate and delete. With type: 'object', or an object value, an object prop with one field per key instead.
any other nameThat JSX attribute, e.g. size, href, style. It doesn't have to be on the element yet: see below.

innerText and plain innerHTML go between the element's tags, so they need an element with a closing tag. Writing either to a self-closing element such as <img /> is refused with the reason self-closing; clearing it does nothing and succeeds. type: 'richtext' writes dangerouslySetInnerHTML, so it works on a self-closing element too.

Optional attributes​

A binding can name an attribute the element doesn't carry. Committing a value adds it, after the element's last attribute. Committing undefined removes an attribute, and to React a prop that's undefined and one that's missing are the same. So one binding can switch an optional prop off and on:

onChange(undefined); // <a title="Docs" target="_blank"> → <a title="Docs">
onChange('_blank'); // <a title="Docs"> → <a title="Docs" target="_blank">
  • An empty string writes prop="" on an attribute that's there, and leaves a missing one missing.
  • For innerText and innerHTML, undefined empties the content. children can't be removed as a whole.
  • A binding with required: true can't be removed. The edit is refused.
  • PanelBinding.present is false while the attribute is missing, which is what a custom panel reads to draw an on/off switch. prop="" counts as present.

Because a missing attribute is added instead of reported, a typo in property shows up as an unexpected attribute in the source rather than as an error.

data-id, data-name, data-binding and data-binding-key are managed by the editor, so a binding can't target them. A field on one of these is shown as read-only, and an edit to it is refused with an error naming the property.

Binding the section itself​

The <section> element takes a data-binding like any other element, which is how a panel edits the section's own background, padding or spacing. Its fields come first in the panel, ahead of the elements inside it.

<section
data-name="Banner"
data-binding={[
{
label: 'Section Style',
property: 'style',
type: 'object',
render: {
backgroundColor: { type: 'color', label: 'Background' },
paddingBlock: {
type: 'number',
label: 'Vertical Padding',
min: 0,
max: 160,
widget: 'slider',
},
},
},
]}
style={{ backgroundColor: '#4f46e5', paddingBlock: 64 }}
>
{/* ... */}
</section>

Try it in the Drag & Drop demo: the Banner (bound section) at the end of the palette is this section. Add it, select it, and change its background or padding from the panel.

The library ships no bindings on the default sections: which properties of a section are editable, and what they're called, is up to you. Because the binding is part of the section's source, it's copied and moved along with the section, and each copy stays editable.

Binding every element of a component​

Repeating the same data-binding on every button or title gets long, and the array stays in the code the editor produces. Pass bindings to Live.Dnd instead: a map from a component's tag name to the entries every element of that component gets. The markup then only needs a data-id.

import type { BindingRegistry } from '@jbpark/live-editor/utils/ast';

// Defined once, outside the component.
const bindings = {
'ui.Button': [
{ label: 'Button Text', property: 'innerText' },
{
label: 'Size',
property: 'size',
options: [
{ label: 'Small', value: 'small' },
{ label: 'Large', value: 'large' },
],
},
],
'ui.Typography.Title': [
{ label: 'Heading', property: 'innerText', required: true },
],
} satisfies BindingRegistry;

<Live.Dnd value={code} onChange={setCode} bindings={bindings} />;
<section data-name="Intro">
<ui.Typography.Title data-id="" level={2}>
Welcome
</ui.Typography.Title>
<ui.Button data-id="" size="small">
Get Started
</ui.Button>
</section>
  • Components only. A key is a component's name: a member path (ui.Button) or a name that doesn't start with a lowercase letter (Button). HTML elements such as p or h2 can't be keys, since an entry for one would make every paragraph or heading in every section editable. satisfies BindingRegistry rejects those keys, and Live.Dnd ignores them at runtime with a console warning. Bind an HTML element with its own data-binding, or by key.
  • Names are matched as written. <ui.Button> matches 'ui.Button'. The same component imported as import { Button } from ... is <Button> and needs a 'Button' entry.
  • An element's own data-binding wins, whole: its entries replace the registry's for that element instead of being merged with them. Use it for the one element that should be edited differently. data-binding={[]} makes an element not editable at all.
  • Every element still needs a data-id, as with an inline binding.
  • Entries take everything an inline entry does, and are validated the same way. That includes keys of your own, such as group or tab, which arrive in binding.meta (see Common meta keys). The type of one entry is BindingSchema.
  • It applies everywhere bindings are read: the built-in panel, useDndPanel(), Live.Dnd.Field, and the elements found inside items and children values. The AST helpers take it as an option too: extract(source, { bindings }) and update(..., { bindings }) / updateAll(..., { bindings }).
  • Define it once, outside render. A new object on every render makes Live.Dnd read every section again.

Binding by key​

The component registry gives every element of a component the same fields. For an HTML element, or for one element whose fields or labels differ from the rest, name the schema in the markup with data-binding-key and define it in bindingKeys:

import type { BindingKeyMap } from '@jbpark/live-editor/utils/ast';

// Defined once, outside the component. Plain data, so it can come from JSON
// or a CMS.
const bindingKeys = {
'hero-title': [
{ label: 'Hero Title', property: 'innerText', required: true },
],
'hero-cta': [
{ label: 'CTA Text', property: 'innerText' },
{ label: 'CTA Link', property: 'href', type: 'url' },
],
} satisfies BindingKeyMap;

<Live.Dnd
value={code}
onChange={setCode}
bindings={bindings}
bindingKeys={bindingKeys}
/>;
<section data-name="Hero">
<h1 data-id="" data-binding-key="hero-title">
Welcome
</h1>
<a data-id="" data-binding-key="hero-cta" href="/start">
Get started
</a>
</section>
  • Any element. HTML elements and components alike, since an element only gets fields when its markup names a key.
  • Precedence. An element's own data-binding comes first, then the key its data-binding-key names, then its component's registry entry. Each replaces the next whole. An element with both data-binding and data-binding-key uses its data-binding, and the console warns about it.
  • A key that isn't in bindingKeys gives the element no fields, without falling back to the registry, and the console names the key once. So does a data-binding-key that isn't a plain string.
  • Every element still needs a data-id, and data-binding-key can't be the target of a binding.
  • Entries are BindingSchemas, as in the registry, so keys of your own arrive in binding.meta here too.
  • The AST helpers take both maps in one options object: extract(source, { bindings, bindingKeys }), and the same for update() and updateAll(). A custom panel gets that object from useDndPanel().bindingOptions.

Where the schema lives​

An inline data-binding travels with the section's source, so a saved document stays editable wherever it's opened. With bindings or bindingKeys, the schema lives in your code instead, and a saved document is only editable where the same maps are passed. Keep the maps with the documents that use them, and keep a key's name once documents refer to it.

Types​

typeBuilt-in controlValidation
stringText arearequired, pattern, minLength, maxLength
numberNumber inputrequired, min, max, step
booleanCheckbox—
colorColor input—
dateDate input (value stored as YYYY-MM-DD)required, a real YYYY-MM-DD day, minDate, maxDate
timeTime input (value stored as HH:mm, 24-hour)required, a valid HH:mm
datetimeDate and time input (value stored as YYYY-MM-DDTHH:mm, local, no zone)required, a real day and time, minDate, maxDate
urlURL inputrequired, pattern, valid URL, protocols
imageURL input with a thumbnail, and a file picker with onUpload. See Imagesrequired, pattern, minLength, maxLength, protocols on an absolute URL
emailEmail inputrequired, pattern, a name@domain.tld shape, minLength, maxLength
telPhone inputrequired, pattern, minLength, maxLength (no built-in format, since phone formats differ by country)
richtextText area with the HTML source—
jsxCode editor—
functionCode editor, or a select with optionsa function expression or a reference to one. See Function props
objectOne nested field per keyper nested field
arrayItem listminItems, maxItems, and per nested field

Without a type, the built-in panel picks a control from the current value (a checkbox for true, a number input for 42, and so on). A property whose name contains color also gets a color input. An attribute that holds an arrow function or a function expression is edited as type: 'function'. options replaces the text, number, color, date, time, URL, email and phone controls with a select.

The built-in controls are native inputs, selects and text areas. For a date picker, a time picker, a color picker and a rich text editor from @jbpark/ui-kit, pass uiKitFields as renderField.

Images​

type: 'image' is for an image's URL, such as an <img>'s src. The panel shows a URL input that commits when it loses focus, and above it a thumbnail of the value as written. The thumbnail is hidden while the value is empty or the image doesn't load. Unlike url, any image source passes: a relative path such as /images/hero.png, an absolute URL, or a data: URL. protocols applies to an absolute URL only.

To let users pick a file, pass onUpload to Live.Dnd. It gets the file and the field that asked, and resolves to the URL to write:

<img
data-id="hero"
data-binding={[{ label: 'Image', property: 'src', type: 'image' }]}
src="/images/hero.png"
/>

<Live.Dnd
value={value}
onChange={setValue}
onUpload={async (file, { binding }) => {
const { url } = await api.upload(file);

return url;
}}
/>
  • The field gets a "Choose image" button that opens a file picker for image/*. It's disabled and marked busy until the upload settles.
  • The resolved URL is validated and written like a typed one.
  • A rejection is reported through onEditError as an upload error, with the rejection as error. The value stays as it was.
  • A result is dropped if another upload started in the field since, the field now edits another binding, or it's gone. A slow upload never writes into a different section.
  • To check a file's type or size, read file.type and file.size in onUpload and reject.
  • An array item's property takes the same control through its render leaf: render: { src: { type: 'image' } }.

With options, an image binding gets a select of the listed images instead. Without type: 'image', a src attribute is a plain text field: the property name isn't used to guess, since <script>, <iframe> and <video> have a src too.

Function props​

type: 'function' edits a prop that takes a function, such as an event handler. The value is source text, read and written without being run:

// A code editor for the handler's source
<button
data-binding={[{ label: 'On click', property: 'onClick', type: 'function' }]}
onClick={() => console.log('clicked')}
/>

// A select of handlers the host provides
<button
data-binding={[{
label: 'On click',
property: 'onClick',
type: 'function',
options: [
{ label: 'Open modal', value: 'actions.openModal' },
{ label: 'Track click', value: 'actions.track' },
],
}]}
onClick={actions.openModal}
/>
  • An edit takes an arrow function, a function expression, or a reference such as handleClick or actions.openModal. Anything else is refused, including a call such as alert('hi'), which would run on every render.
  • A referenced name must be in scope when the section runs: declared in the document, or passed through Live.Dnd's modules. The editor doesn't check that it exists.
  • A handler doesn't run from a click on the canvas, and state it changes in App is per section there. To change what another section shows, see State across sections.
  • Clearing the value removes the attribute, since onClick={} isn't valid JSX. A required binding can't be cleared.
  • With options, the select shows while the value is one of them or empty. A handler written in the code editor that isn't one of them gets the code editor instead, so it isn't replaced by the first option.
  • With optionsOnly: true as well, the select always shows, so users of the panel can only pick one of your handlers or none. A handler written elsewhere shows as a disabled "Current" entry until another is picked. This limits the panel, not the code: whoever edits the source can still write anything, so it isn't a sandbox.
  • pattern, minLength, maxLength and required apply to the source text, as on any text field. pattern: '^actions\\.' keeps hand-written handlers to references into actions, for example.
  • Without a type, an attribute that holds an arrow function or a function expression is treated the same way. A bare reference such as onClick={handleClick} needs type: 'function', since nothing says what it refers to (className={styles.root} looks the same).
  • An array item's property works the same way in the Items editor: declare it in render (render: { onClick: { type: 'function' } }), or leave it untyped when it holds a function expression. Clearing it is refused there, since removing a key would change the item's shape. An item that is itself a function expression, as in actions={[() => open()]}, is edited the same way.
  • A key of an object-valued prop works the same way: declare it in render (render: { onClick: { type: 'function' } }), or leave it untyped when it holds a function expression. The object editor then edits each key on its own, so config={{ label: 'Go', onClick: () => go() }} gets a text field for label and a code editor for onClick. Clearing a function key is refused, as for array items. A key holding another expression, such as a call or an untyped reference, is shown read-only by itself, and the other keys stay editable.
  • An object with a spread, a computed key or a method (onClick() {}) is edited in the code editor, since its keys can't be addressed one by one. Function and expression keys aren't in the binding's value; a custom panel finds them in rawValue, or renders the object with Live.Dnd.Field.

Handlers from your app​

Keep what a handler does in your app, and let the panel choose which one an element runs. Pass the handlers in modules, import them in the document, and list them in options:

// Your app, defined once outside render
const actions = {
openModal: () => modal.open(),
navigate: (to: string) => router.push(to),
};
const modules = { actions };

<Live.Dnd value={value} onChange={setValue} modules={modules} />;
// The document
import actions from 'actions';

<button
data-id=""
data-binding={[{
label: 'On click',
property: 'onClick',
type: 'function',
options: [
{ label: 'Open modal', value: 'actions.openModal' },
{ label: 'Go to pricing', value: "() => actions.navigate('/pricing')" },
],
}]}
onClick={actions.openModal}
>
Start
</button>
  • Put the import in the document you start from, so sections dropped from the palette find it too.
  • An option's value can be an arrow function, so a handler that takes arguments still comes from the list.
  • Add optionsOnly: true to keep the panel's users to this list.
  • Handlers don't run on the canvas; click through in Live.Preview.

Constraints​

The constraints in the table above are checked before an edit is committed. A rejected edit shows its message under the field and leaves the source unchanged:

{
label: 'Content Spacing',
property: 'size',
type: 'number',
min: 0,
max: 40,
}

Typing 99 shows Must be at most 40. A pattern can say what it expects:

{
label: 'Link URL',
property: 'href',
type: 'url',
pattern: '^https://',
patternMessage: 'Use an https:// link.',
}

Custom panels can run the same check with validateBindingValue(binding, value). To show these messages in another language, see Localization.

Nested fields​

For an object or array value, render describes the keys inside it. An entry that declares type is a leaf, and a leaf accepts every field a top-level entry does: label, options, constraints, widget, a nested render, and extra keys for meta. label and property fall back to the key.

An object binding, from the default Hero section:

<ui.Space
data-id=""
data-binding={[
{
label: 'Background Style',
property: 'style',
type: 'object',
render: {
backgroundColor: { type: 'color', label: 'Background Color' },
},
},
]}
style={{ backgroundColor: '#6366f1' }}
/>

An array binding, trimmed from the default Roadmap section. Each item gets one field per key, labeled and validated by its leaf. link is itself an object leaf with its own render map:

<ui.List
data-id=""
data-binding={[
{
label: 'Milestones',
property: 'data',
type: 'array',
render: {
title: { type: 'string', label: 'Title', required: true },
date: { type: 'date', label: 'Release Date', required: true },
status: {
type: 'string',
label: 'Status',
options: [
{ label: 'Planned', value: 'planned' },
{ label: 'Shipped', value: 'shipped' },
],
},
progress: { type: 'number', label: 'Progress', min: 0, max: 100 },
color: { type: 'color', label: 'Accent Color' },
highlight: { type: 'boolean', label: 'Highlight' },
link: {
type: 'object',
label: 'Link',
render: {
text: { type: 'string', label: 'Link Text' },
href: { type: 'url', label: 'Link URL', pattern: '^https://' },
},
},
},
},
]}
data={[
{
title: 'Visual editing',
date: '2026-03-02',
status: 'shipped',
progress: 100,
color: '#22c55e',
highlight: false,
link: { text: 'Release notes', href: 'https://github.com' },
},
]}
renderItem={item => <div>{/* ... */}</div>}
/>

A render entry without type is treated as a plain group of further entries. It cannot have a label of its own, so prefer an object leaf as above.

JSX-valued keys inside an item (children, or a key holding an element) are not typed through render. The panel shows the bindings declared on those elements instead, or a code editor when they declare none.

Document settings​

Settings that belong to the whole document rather than one element, such as a theme or an analytics id, go in a top-level object, and the code reads them from there:

import { useAnalytics, useAutoplay } from 'behaviors'; // from `modules`

const settings = {
theme: 'dark',
autoplay: true,
autoplayDelay: 5000,
analyticsId: 'G-XXXX',
};

const App = () => {
const [theme, setTheme] = useState(settings.theme);

useAutoplay({ enabled: settings.autoplay, delay: settings.autoplayDelay });
useAnalytics(settings.analyticsId);
// ...
};

Live.Dnd's documentBindings makes them editable from the panel. Each key names a top-level const holding an object literal, and its bindings take the same shape as bindingKeys, with property naming a key of that object:

// Outside the component, like `bindingKeys`.
const DOCUMENT_BINDINGS = {
settings: [
{
label: 'Theme',
property: 'theme',
options: [
{ label: 'Dark', value: 'dark' },
{ label: 'Light', value: 'light' },
],
},
{ label: 'Autoplay', property: 'autoplay', type: 'boolean' },
{ label: 'Delay (ms)', property: 'autoplayDelay', type: 'number', min: 1000 },
{ label: 'Analytics ID', property: 'analyticsId', pattern: '^G-' },
],
};

<Live.Dnd value={value} onChange={setValue} documentBindings={DOCUMENT_BINDINGS} />;
  • The built-in panel shows them under "Document" while no section is selected. A custom panel reads them with useDndDocument().
  • An edit replaces only that key's value, so comments and the other keys stay as written, and it's one onChange with { source: 'dnd' }, one step in useLiveHistory. The binding's constraints apply as on any field.
  • A key holding a function edits as source, as for an object prop. A key holding another expression, such as a call, and a key the object doesn't have, are shown but can't be edited; add the key in the code editor first.
  • The object must be a const in module scope (or export const), and an object literal without spreads, computed keys or methods. Anything else gives no fields, and an edit that can't be written is reported through onEditError as a document error.
  • On the canvas each section runs the whole document, so effects that read these settings run once per section there. See Side effects while editing.

Presentation and metadata​

Two ways to pass information to a custom panel without the library acting on it:

{
label: 'Scroll Speed',
property: 'speed',
type: 'number',
min: 20,
max: 300,
widget: { type: 'slider', step: 10 },
group: 'motion',
}
  • widget names the control your panel should draw. See below.
  • Any key the library does not define (group above) arrives under binding.meta.group.

Both reach your code the same way, so you could put the control name in meta too (control: 'slider' arrives as binding.meta.control). Use widget for it anyway. It's a reserved field, so it keeps its place if the library adds new fields later, while a meta key that becomes a library field moves out of meta. It's also the one name renderField, custom panels and nested fields all check for the control. Use meta for the other information about a field, such as a group or help text.

The built-in panel shows a number input for this field and ignores both. With metaPanelLayout, it boxes this field with the element's other motion fields.

widget: a hint for your own controls​

widget is not a list of built-in controls to choose from. The library ships no widgets, and 'slider' is not a built-in option either; it's just the name these docs and the demos use. Nothing happens to a widget value until your own code reads it:

  1. You pick a name for the control you want and write it on the binding.
  2. Your code checks binding.widget.type in renderField or in a custom panel and draws that control.
  3. Anywhere the name isn't handled, including the built-in panel, the field gets the default control for its type.

Any string works, so name controls after what your panel actually draws. For example:

widgetOn a field withYour panel might draw
'slider'type: 'number'A range slider using min, max and step
'switch'type: 'boolean'A toggle switch instead of a checkbox
'radio'optionsRadio buttons instead of a select
'textarea'type: 'string'A multi-line text box with a given height
'icon-picker'type: 'string'Your own icon set, writing the chosen icon name

None of these are built in; they only show the kind of names that fit.

widget is authored either as a bare string or as an object that also carries the control's own settings:

widget: 'slider' // arrives as { type: 'slider' }
widget: { type: 'slider', step: 4, unit: 'px' } // settings for your slider
widget: { type: 'textarea', rows: 6 } // settings for your textarea

The bare string is normalized to { type }, so your code always checks widget.type.

The settings are yours too; the library reads none of them. step and unit are the only two that come typed. That isn't because the library uses them. They're common enough that your code gets them as number and string instead of unknown. Every other setting (rows above) arrives as unknown, so check its type before using it. A typed setting with the wrong type (step: '4') drops the whole widget, so your code sees no widget on that field and draws its default control.

Keep value rules out of widget. min, max, step, pattern, required and the other constraints belong on the binding itself, where the library enforces them whatever control draws the field.

The two steps differ. widget.step is how far your control moves per tick, and the library ignores it. The binding's own step is a rule: a value off the step is rejected, whatever control produced it.

Common meta keys​

The library defines no presentation fields beyond widget, so help text, grouping and visibility all go in meta. Nothing stops each app from inventing its own names for them, so these docs suggest a shared set. The library reads none of them: their meaning is yours. To have the built-in panel use three of them, pass metaPanelLayout as Live.Dnd's panelLayout:

import { metaPanelLayout } from '@jbpark/live-editor/dnd';

<Live.Dnd value={value} onChange={setValue} panelLayout={metaPanelLayout} />;

Without it, the built-in panel ignores every meta key. To use other names or rules, write a panelLayout of your own: see Arranging the built-in panel.

KeyValueMeaningWith metaPanelLayout
descriptionstringGuidance the user always needs. Show it next to the field.Shows it under the label, as the control's description for screen readers.
hintstringExtra detail the user can choose to open, such as a tooltip or an info icon.Ignores it.
groupstringFields with the same name belong in one box.Puts an element's fields with the same name in one box headed by the name, where the first of them was. Fields without a group keep their place.
tabstringFields with the same name go on one tab.Ignores it.
visibleboolean or a ruleWhether to show the field. Leaving it out means visible. See below.Leaves a hidden field out, and an element whose fields are all hidden.

Keep description and hint apart. Text the user has to read is a description. Putting it in a hint hides it behind a hover.

data-binding={[
{
label: 'Link',
property: 'mode',
options: [
{ label: 'None', value: 'none' },
{ label: 'URL', value: 'url' },
],
group: 'link',
},
{
label: 'URL',
property: 'href',
type: 'url',
description: 'Opens in the same tab.',
group: 'link',
visible: { property: 'mode', in: ['url'], default: 'none' },
},
]}

visible​

visible: false always hides the field. A rule shows it only while another binding's value is one of a list:

type VisibleRule = {
property: string; // the binding this field depends on
id?: string; // that binding's element, when it isn't this field's own
in: unknown[]; // show while the value is one of these
default?: unknown; // the value to assume when the attribute is missing
};
  • property refers to this field's own element by default. A section can carry the same property on several elements, so name another element with id, its data-id.

  • When the value is an array, the field shows while any of its entries is in in.

  • Set default whenever the property may be missing. Documents written before the property existed don't carry it. Without default, those documents would hide the field for good.

  • Only bindings reach the panel, so the property a rule reads must have a binding of its own.

  • A rule that isn't false and doesn't have this shape (a string, no property, an in that isn't an array) leaves the field visible, so a typo never hides a field for good.

  • With metaPanelLayout, the built-in panel applies rules to the top-level fields of a section. A visible on a key of an object or an array item's property isn't applied.

A hidden field is still in bindings, with its value and onChange, so a custom panel can decide whether to leave it out or show it disabled. isBindingVisible is the check metaPanelLayout uses:

import { isBindingVisible, useDndPanel } from '@jbpark/live-editor/dnd';

const { bindings } = useDndPanel();
const shown = bindings.filter(binding => isBindingVisible(binding, bindings));

VisibleRule is exported as a type too.

A panel that reads them​

The demo below is a custom panel built on useDndPanel() that reads all five keys. The section's schema lives in bindingKeys, so the markup only carries data-binding-key.

  • tab puts the fields on a Content or a Style tab. A field without one goes on a General tab, and the tab bar only shows when there's more than one tab.
  • group puts the button's fields in one Button box. On the Style tab, that box holds only the variant. A field without a group sits in a box for its element, the way the built-in panel groups fields.
  • description shows under its field, and hint behind the icon next to the Text label.
  • visible hides URL when Link is set to None.

Each field is still drawn by Live.Dnd.Field, so only the arrangement is the demo's own. Its source is in demos/panel-meta.