AgentSkillsCN

add-field

为现有 Ybyra 模式新增字段,合理设置类型、配置、i18n 键,以及事件绑定。

SKILL.md
--- frontmatter
name: add-field
description: Adds a new field to an existing Ybyra schema with proper type, configuration, i18n keys, and event wiring.

Skill: Add Field

Add a new field to an existing Ybyra domain schema.

Steps

1. Add Field to Schema (schema.ts)

Choose the right factory function and chain configuration methods:

ts-no-check
fields: {
  // ... existing fields
  newField: text().width(50).required().column().group("basic"),
}

Field Type Reference

TypeFactorySpecific Methods
Texttext().kind(Text.Email|Phone|Url|...), .minLength(n), .maxLength(n), .pattern(regex)
Numbernumber().min(n), .max(n), .precision(n)
Datedate().min(date), .max(date)
Datetimedatetime().min(date), .max(date)
Currencycurrency().min(n), .max(n), .precision(n), .prefix(str)
Toggletoggle()
Checkboxcheckbox()
Selectselect<V>()generic over value type
Filefile().accept(types), .maxSize(bytes)

Common Methods (all fields)

code
.width(n)           — percentage width (100 = full row)
.height(n)          — height in units
.default(value)     — initial value
.required()         — required validation
.hidden()           — hidden by default
.disabled()         — read-only by default
.column()           — show in table
.filterable()       — searchable in table
.group("name")      — visual group
.scopes(Scope.add)  — only in these scopes
.excludeScopes()    — hidden in these scopes

2. Add i18n Key

In locale file (e.g., locales/pt-BR.ts):

ts-no-check
{domain}: {
  // ... existing keys
  fields: {
    // ... existing keys
    "newField": "Label do Campo",
    "newField.placeholder":"Digite...",  // optional
  }
}

3. Add Events (optional, in events.ts)

ts-no-check
export const { domain }
Events = { Domain }
Schema.events({
  // ... existing events
  newField: {
    change ({ state, schema }) {
      // React to field changes
    },
  },
});

4. Add Group (if a new group needed, in schema.ts)

And add i18n key:

ts-no-check
export const ExampleSchema = schema.create("example", {
  // ... existing keys
  groups: {
    // ... existing keys
    newGroup: group(),
  }
  // ... existing keys
}
ts-no-check
{domain}: {
  // ... existing keys
  groups: {
    // ... existing keys
    "newGroup": "The group label",
  }
},