﻿# nf-keywords {#keywords}

Keyword batches support #-separated input, regex validation, case-insensitive deduplication, per-item/total limits, protected items, copying and virtualized rendering.

## Examples {#examples}

### Basic usage {#example-1}

### Basic usage
```vue
<script setup>
import { ref } from 'vue'
import { NfConfigProvider, NfKeywords } from '@94ai-plus/common-ui'
const data = ref([{ content: 'Vue', type: 2 }, { content: 'Element Plus', type: 2 }])
</script>

<template>
  <NfConfigProvider theme="chalk" locale="en-US">
    <NfKeywords :data="data" @del-all="data = []" />
    <pre>{{ data }}</pre>
  </NfConfigProvider>
</template>
```

### Advanced usage {#example-2}

### Advanced usage
```vue
<script setup>
import { ref } from 'vue'
import { NfConfigProvider, NfKeywords } from '@94ai-plus/common-ui'
const data = ref([{ content: 'Protected', locked: true }, { content: 'Editable' }])
</script>

<template>
  <NfConfigProvider theme="chalk" locale="en-US">
    <NfKeywords v-model="data" :single-limit="12" :total-limit="40" :get-item-disabled-status="row => !!row.locked" @del-all="data = data.filter(row => row.locked)" />
  </NfConfigProvider>
</template>
```

## Props {#props}

Text props follow the library language when omitted; defaults below use this language.

| Parameter | Description | Type | Options | Default |
| --- | --- | --- | --- | --- |
| `data` | Data to display or restore. | `KeyWordItem[]` | — | `[]` |
| `modelValue` | Current value; Vue 3 v-model takes precedence over the compatibility prop. | `KeyWordItem[]` | — | `undefined` |
| `disabled` | Whether to disable the component. | `boolean` | — | `false` |
| `getItemDisabledStatus` | Whether a keyword is protected from deletion; true prevents removal. | `(item: KeyWordItem) => boolean` | — | `() => false` |
| `size` | Control size; mini maps to small and medium to default. | `string` | mini / small / medium / default / large | `'mini'` |
| `singleLimit` | Character limit per keyword. | `number` | — | `3000` |
| `totalLimit` | Total character limit across keywords. | `number` | — | `60000` |
| `placeholder` | Customize the “Enter keywords and press Enter to confirm. Separate multiple keywords with #” text. | `string` | — | `Enter keywords and press Enter to confirm. Separate multiple keywords with #` |
| `someLimitDesc` | Customize the “A keyword exceeds the character limit” text. | `string` | — | `A keyword exceeds the character limit` |
| `allLimitDesc` | Customize the “Total keyword character limit exceeded” text. | `string` | — | `Total keyword character limit exceeded` |
| `matchDesc` | Customize the “Keywords matching this branch” text. | `string` | — | `Keywords matching this branch` |
| `priorityRecommendDesc` | Customize the “(Keywords are recommended)” text. | `string` | — | `(Keywords are recommended)` |
| `copyAllDesc` | Customize the “Copy all” text. | `string` | — | `Copy all` |
| `delAllDesc` | Customize the “Delete all” text. | `string` | — | `Delete all` |
| `noKeywordDesc` | Customize the “No keywords” text. | `string` | — | `No keywords` |
| `copySucessDesc` | Customize the “Copied successfully” text. | `string` | — | `Copied successfully` |
| `alreadyExistDesc` | Customize the “Keyword already exists in this branch” text. | `string` | — | `Keyword already exists in this branch` |
| `correctDesc` | Customize the “Please correct it” text. | `string` | — | `Please correct it` |
| `incorrectRegDesc` | Customize the “The keyword contains an invalid regular expression” text. | `string` | — | `The keyword contains an invalid regular expression` |

## Events {#events}

| Event | Description | Payload |
| --- | --- | --- |
| `delAll` | Request to delete all keywords; the parent decides whether to clear them, preserving confirmation flows. | `(items: KeyWordItem[])` |
| `delItem` | Fires when a keyword is deleted; returns that keyword object. | `(item: KeyWordItem)` |
| `copySuccess` | Fires after a successful copy; returns #-separated text with the trailing #. | `(text: string)` |
| `copyError` | Fires when copying fails; returns the error. | `(error: unknown)` |
| `change` | Fires when keyword data changes; returns the current array. | `(items: KeyWordItem[])` |
| `update:data` | Update the bound value. | `(items: KeyWordItem[])` |
| `update:modelValue` | Update the bound value. | `(items: KeyWordItem[])` |

## Slots {#slots}

No custom slots.

## Exposed methods and state {#methods}

- `tags`
- `copyVal`
- `keyword`
- `delKeywords()`
- `addFn()`
- `someKey`
- `allKey`

## Migration notes {#migration}

Vue 3 uses `modelValue` / `update:modelValue`; legacy `value`, `update:value` and `input` remain available on selection components. The implementation uses public Element Plus APIs, not Element UI internals. `mini` maps to `small`; `medium` maps to `default`.

`delAll` is a notification: the parent decides whether to clear the array. Clipboard errors never emit a success message.
