# ContentInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/content_input

Category: Input controls

offers a panel builder for creating and editing a nested content structure (ASTC format) with interactive insertion, removal, and attribute editing of various node types

Public component import: `ContentInput`

Public manager import: `create_content_input_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { ContentInput, create_content_input_manager, markdown_to_astc } from "sveltekit-ui"

  const manager = create_content_input_manager({
    val: markdown_to_astc("## Your article\n\nSelect a text element to edit it."),
  })
</script>

<div style="height: 50rem; max-height: 80vh;">
  <ContentInput {manager} />
</div>
<details>
  <summary>Document data</summary>
  <pre>{JSON.stringify(manager.val, null, 2)}</pre>
</details>
```

## Configuration

### `val`

- type: object
- default: null
- description: the initial top-level ASTC node

### `on_change`

- type: function
- default: null
- description: callback triggered when the ASTC structure changes

### `on_finish`

- type: function
- default: null
- description: callback triggered when the user finishes editing

### `on_event`

- type: function
- default: null
- description: callback invoked for certain child content manager events

### `definition_stack`

- type: any
- default: null
- description: external definition_stack variables object for show_conditions or other variable-based usage

### `mapkit_js_token`

- type: string
- default: null
- description: token for mapkit if needed by location-based nodes

### `storage`

- type: any
- default: null
- description: storage definition used when uploading or managing files

### `storage_default_folder_path`

- type: string
- default: null
- description: default folder path for storage uploads

### `storage_path`

- type: string
- default: /api/storage/{storage_id}
- description: app-provided stored-media URL template used by previews and media pickers; the library provides no storage backend

## Methods

### `init()`

- description: initial setup; stores the initial value, populates managers, and sets the selected version to 0
- parameters:
  - config: object
- returns: void

### `clean_content()`

- description: validates a node's type, ensures allowed attributes, and recursively computes text stats
- parameters:
  - val: object
- returns: object with { warnings, word_count, character_count, embedding_text, total_elements, total_nests, val }

### `add_version()`

- description: inserts a new version of the ASTC into the version stack, triggers on_change if provided
- parameters:
  - version: object
- returns: void

### `finish()`

- description: calls on_finish with the current astc structure
- parameters:
- returns: void

### `copy_markdown()`

- description: copies the entire current ASTC as markdown to clipboard
- parameters:
- returns: void

### `copy_astc()`

- description: copies the entire current ASTC (json) to clipboard
- parameters:
- returns: void

### `copy_text()`

- description: copies an embedding-friendly text representation of the ASTC to clipboard
- parameters:
- returns: void

### `set_focused_selector_id()`

- description: tracks which selector id is currently focused in the UI
- parameters:
  - selector_id: string
- returns: void

### `open_edit_markdown_modal()`

- description: opens a popover with the current ASTC as markdown, allowing direct editing/replacement
- parameters:
- returns: void

### `set_astc_from_markdown()`

- description: parses markdown (or astc) from a text area, updates the current version with that content
- parameters:
- returns: void

### `initiate_add_sibling_el_to_selector()`

- description: prompts the user to add a sibling node right below a given selector id
- parameters:
  - selector_id: string
- returns: void

### `add_sibling_el()`

- description: creates a new sibling node (or uses a provided astc node) below the specified selector id
- parameters:
  - selector_id: string
  - el_type_id: string | null
  - element_to_add: object
- returns: void

### `initiate_add_child_el_to_selector()`

- description: prompts the user to add a child node under a given selector id
- parameters:
  - selector_id: string
- returns: void

### `add_child_el()`

- description: creates a new child node of the specified type, appended to an element’s children array
- parameters:
  - selector_id: string
  - type_id: string
- returns: void

### `add_astc_to_element_children()`

- description: directly appends a parsed ASTC string as a child to a given element’s children array
- parameters:
  - element: object
- returns: void

### `copy_element_astc()`

- description: copies the ASTC json for a specific node identified by selector_id
- parameters:
  - selector_id: string
- returns: void

### `copy_element_markdown()`

- description: copies the markdown representation for a specific node identified by selector_id
- parameters:
  - selector_id: string
- returns: void

### `shift_el()`

- description: moves a node up or down within its siblings by a specified integer offset
- parameters:
  - selector_id: string
  - i_shift: number
- returns: void

### `delete_el()`

- description: removes a node by selector_id from the current ASTC
- parameters:
  - selector_id: string
- returns: void

### `open_edit_element_attributes_popover()`

- description: opens an attribute editor popover for a given node identified by selector_id
- parameters:
  - selector_id: string
- returns: void

### `set_element_attribute()`

- description: sets a single attribute on a node identified by selector_id
- parameters:
  - selector_id: string
  - attribute: string
  - val: any
- returns: void

### `set_element_attributes()`

- description: overwrites the attributes object for a node identified by selector_id
- parameters:
  - selector_id: string
  - new_attributes: object
- returns: void

### `pass_event_down()`

- description: propagates external events through the content manager, used by child components for updates
- parameters:
  - input: object
- returns: void

### `get_new_element_to_add()`

- description: creates a blank node of the specified type, initializing children & attributes from node_types
- parameters:
  - type_id: string
- returns: object

### `calc_child_element_options()`

- description: determines the set of valid child node types that can be appended to a given element
- parameters:
  - element: object
  - is_sibling: boolean
- returns: array of available type_ids

## Returned state

### `id`

- type: string
- description: unique identifier for this content input instance

### `val`

- type: object
- description: the current ASTC version being displayed

### `variables_data_type`

- type: any
- description: the data-type object used for attribute editing

### `variables`

- type: any
- description: the variables reference for conditions or loops

### `versions_len`

- type: number
- description: the total number of versions in the version stack

### `selected_version_prepped`

- type: object
- description: the currently selected version in a processed/prepped form

### `storage`

- type: any
- description: storage definition object if used for file management

### `storage_default_folder_path`

- type: string
- description: default folder path for storage

### `focused_selector_id`

- type: string
- description: tracks the selector id of the currently focused node

### `paste_astc_markdown_popover_manager`

- type: object
- description: popover manager for switching between astc or markdown input

### `paste_astc_markdown_location_to_add_element`

- type: object
- description: stores the context of adding astc/markdown content as child or sibling

### `paste_astc_markdown_dropdown_manager`

- type: object
- description: dropdown manager to select 'astc' or 'markdown' as input

### `paste_astc_markdown_text_input_manager`

- type: object
- description: text input manager containing either markdown or a raw astc object

### `paste_astc_markdown_finish_button_manager`

- type: object
- description: button manager to finalize the markdown/astc insertion

### `location_to_add_element`

- type: string
- description: tracks where a new element is inserted: 'child' or 'sibling'

### `astc_element_string`

- type: string
- description: transient state for storing raw astc text being inserted

### `all_selector_ids`

- type: array
- description: list of all selector ids found in the current ASTC

### `preempt_add_first_element_button_manager`

- type: object
- description: button manager offering to add the very first element if none exists

### `first_el_add_element_manager`

- type: object
- description: add element manager used for adding an initial node

### `content_manager`

- type: object
- description: the underlying content manager that renders the ASTC

### `content_overall_manager`

- type: object
- description: an object with references for handling focus and attribute editing popovers

### `attributes_input`

- type: object
- description: the manager for attributes editing popover
