Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugins/fast-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
40 changes: 40 additions & 0 deletions plugins/fast-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# fast-data

> ZTools 快速处理数据插件。

## 功能

- 使用 `fast` 或 `快速处理数据` 打开插件。
- 在输入框粘贴文本或调整规则后,立即生成处理结果。
- 支持换行符、逗号、引号、去空、大小写、普通替换、正则替换、去重、前后拼接等常用操作。
- 每个按钮分组内保持单选,再次点击已选按钮会取消选择。
- 替换区填写查找和替换内容后自动计算,点击 `.*` 可切换为正则替换。
- 前后拼接区填写前缀或后缀后自动计算,不需要额外点击拼接按钮。
- 点击底部 `处理数据` 将当前输出复制到剪贴板。
- 点击底部 `重置设置` 清空输入、输出和参数。

## 开发

```bash
npm install
npm run dev
```

ZTools 开发模式入口配置在 `public/plugin.json` 的 `development.main` 中。

## 构建

```bash
npm run build
```

构建产物输出到 `dist/`。

## 结构

```text
public/plugin.json # ZTools 插件配置
src/App.vue # ZTools feature 路由
src/Fast/index.vue # 快速处理数据界面
src/Fast/transformers.ts # 纯文本处理函数
```
309 changes: 309 additions & 0 deletions plugins/fast-data/docs/superpowers/plans/2026-06-29-fast-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
# Fast Data Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Build the `快速处理数据` ZTools feature that transforms pasted text through immediate button actions and copies output on demand.

**Architecture:** Keep plugin registration in `public/plugin.json`, route ZTools activations through `src/App.vue`, place all UI state and interaction in `src/Fast/index.vue`, and isolate transformation behavior in pure functions under `src/Fast/transformers.ts`. No preload or Node.js services are used.

**Tech Stack:** Vue 3 single-file components, Vite 6, TypeScript, ZTools plugin APIs, browser Clipboard API fallback.

## Global Constraints

- Trigger commands are exactly `fast` and `快速处理数据`.
- Plugin feature code is exactly `fast`.
- The plugin opens with empty input on every ZTools activation.
- Operation buttons and inline replacement/affix fields process immediately.
- Every operation reads from the input textarea, not previous output.
- Operation output never overwrites input automatically.
- Bottom `处理数据` copies current output to the clipboard.
- Bottom `重置设置` clears input, output, replacement fields, prefix, suffix, and regex mode.
- Replacement is plain string global replacement by default and supports global regex replacement when regex mode is enabled.
- Do not add or ship preload services for this feature.
- Do not introduce a test framework because this project currently has none.
- Current directory is not a git repository, so commit steps are skipped in this environment.

---

## File Structure

- `public/plugin.json`: exposes only the production `fast` feature entry and has no `preload` declaration.
- `src/App.vue`: routes the `fast` feature to the Fast component and forces a remount on every ZTools activation so state resets.
- `src/Fast/transformers.ts`: pure text transformation functions with stable names used by the component.
- `src/Fast/index.vue`: UI, state, event handlers, clipboard copy with ZTools-first fallback chain, reset, and notification fallback.
- `src/env.d.ts`: Vue module declarations and ZTools API types only; no unused `window.services` declaration.
- `README.md`: describes the actual Fast Data plugin instead of generated template examples.

---

### Task 1: Register Fast Feature And Route

**Files:**
- Modify: `public/plugin.json`
- Modify: `src/App.vue`
- Delete: `public/preload/`
- Delete: `src/Hello/`
- Delete: `src/Read/`
- Delete: `src/Write/`

**Interfaces:**
- Consumes: ZTools plugin enter event with `action.code`.
- Produces: `Fast` component receives prop `enterAction: Record<string, unknown>` and remounts with `enterKey` on each activation.

- [x] **Step 1: Replace active plugin feature configuration**

Set `public/plugin.json` to this content:

```json
{
"$schema": "node_modules/@ztools-center/ztools-api-types/resource/ztools.schema.json",
"name": "fast-data",
"title": "快速处理数据",
"description": "快速处理数据",
"author": "onezylee",
"version": "1.0.0",
"main": "index.html",
"logo": "logo.png",
"development": {
"main": "http://localhost:5173"
},
"features": [
{
"code": "fast",
"explain": "快速处理数据",
"icon": "logo.png",
"cmds": [
"fast",
"快速处理数据"
]
}
],
"platform": [
"darwin",
"win32",
"linux"
]
}
```

- [x] **Step 2: Route `fast` to the Fast component and reset on activation**

Set `src/App.vue` to this content:

```vue
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import Fast from './Fast/index.vue'

const route = ref('fast')
const enterAction = ref<Record<string, unknown>>({})
const enterKey = ref(0)

onMounted(() => {
if (!window.ztools?.onPluginEnter) return

window.ztools.onPluginEnter((action) => {
route.value = action.code
enterAction.value = action
enterKey.value += 1
})

window.ztools.onPluginOut(() => {
route.value = ''
enterAction.value = {}
})
})
</script>

<template>
<Fast v-if="route === 'fast'" :key="enterKey" :enter-action="enterAction" />
</template>
```

- [x] **Step 3: Remove unused preload-backed template features**

Run:

```bash
rm -rf public/preload src/Hello src/Read src/Write
```

Expected: preload services and unused template feature components are removed.

---

### Task 2: Add Pure Text Transformers

**Files:**
- Create: `src/Fast/transformers.ts`

**Interfaces:**
- Consumes: `text: string`, `findText: string`, `replacement: string`, `prefix: string`, `suffix: string`, `useRegex: boolean`.
- Produces:
- `removeLineBreaks(text: string): string`
- `addBlankLines(text: string): string`
- `linesToComma(text: string): string`
- `dedupeLines(text: string): string`
- `removeCommas(text: string): string`
- `addCommasByLine(text: string): string`
- `commasToLines(text: string): string`
- `removeQuotes(text: string): string`
- `wrapLinesWithSingleQuotes(text: string): string`
- `wrapLinesWithDoubleQuotes(text: string): string`
- `trimLineEdges(text: string): string`
- `removeAllWhitespace(text: string): string`
- `removeCommentLines(text: string): string`
- `toLowerCaseText(text: string): string`
- `toUpperCaseText(text: string): string`
- `replacePlainText(text: string, findText: string, replacement: string): string`
- regex replacement handled in `src/Fast/index.vue` with browser `RegExp`
- `wrapLinesWithAffixes(text: string, prefix: string, suffix: string): string`

- [x] **Step 1: Create transformer module**

Create `src/Fast/transformers.ts` with pure functions for every approved operation. The module splits lines with CRLF/LF/CR support, trims and skips empty lines for line-based operations, deduplicates while preserving first occurrence order, and performs plain string replacement with `text.split(findText).join(replacement)`.

- [x] **Step 2: Verify transformer module compiles**

Run: `npm run build`

Expected before the component exists: FAIL because `src/Fast/index.vue` does not exist. Expected after the component exists: PASS.

---

### Task 3: Build Fast Data UI Component

**Files:**
- Create: `src/Fast/index.vue`

**Interfaces:**
- Consumes: all functions exported by `src/Fast/transformers.ts`.
- Produces: rendered Fast Data UI for `src/App.vue`.

- [x] **Step 1: Create Fast component state and handlers**

`src/Fast/index.vue` defines these refs:

```ts
const inputText = ref('')
const outputText = ref('')
const findText = ref('')
const replacementText = ref('')
const prefixText = ref('')
const suffixText = ref('')
```

It defines immediate recomputation, regex matcher creation, replacement application, reset, and copy helpers.

- [x] **Step 2: Use ZTools-first copy with ordered fallbacks**

`copyOutput()` calls this helper so each method is attempted until one succeeds:

```ts
const copyWithFallbacks = async (text: string) => {
if (window.ztools?.copyText) {
try {
if (window.ztools.copyText(text)) return true
} catch (_err) {}
}

if (navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(text)
return true
} catch (_err) {}
}

try {
return fallbackCopy(text)
} catch (_err) {
return false
}
}
```

Expected behavior:

- Empty output shows `请先处理数据`.
- Successful copy shows `已复制到剪贴板`.
- Failed copy shows `复制失败,请手动复制`.

- [x] **Step 3: Create approved UI layout**

The component renders:

- top input textarea
- grouped operation controls for 换行符、逗号、引号、去除、转换、替换、两边拼
- output textarea
- bottom buttons `重置设置` and `处理数据`

- [x] **Step 4: Run build**

Run: `npm run build`

Expected: PASS.

---

### Task 4: Update Declarations, README, And Final Validation

**Files:**
- Modify: `src/env.d.ts`
- Modify: `README.md`

**Interfaces:**
- Consumes: implemented feature behavior from previous tasks.
- Produces: declarations and documentation matching the shipped plugin.

- [x] **Step 1: Clean environment declarations**

Set `src/env.d.ts` to Vue and ZTools type references only. Do not declare `window.services` because the shipped plugin does not use preload services.

- [x] **Step 2: Replace template README**

Set `README.md` to describe:

- commands `fast` and `快速处理数据`
- immediate text processing buttons
- supported transformations
- `处理数据` copy behavior
- `重置设置` reset behavior
- development command `npm run dev`
- build command `npm run build`
- relevant files `public/plugin.json`, `src/App.vue`, `src/Fast/index.vue`, `src/Fast/transformers.ts`

- [x] **Step 3: Run final build**

Run: `npm run build`

Expected: PASS with Vite build output and files under `dist/`.

- [ ] **Step 4: Manual smoke test in ZTools**

Run: `npm run dev`

Expected:

- ZTools can open the feature with `fast`.
- Input area is empty on repeated activation.
- Pasting `a\nb\na` and clicking `换行符 > 去重` outputs `a\nb`.
- Pasting `a,b, c` and clicking `逗号 > 转换行` outputs `a\nb\nc`.
- Pasting `AbC` and clicking `转换 > 小写` outputs `abc`.
- Clicking `处理数据` after output exists copies output and shows `已复制到剪贴板`.

- [ ] **Step 5: Commit if repository is initialized**

Current environment is not a git repository. If the project is later placed inside a git repository, run:

```bash
git add public/plugin.json src/App.vue src/Fast/index.vue src/Fast/transformers.ts src/env.d.ts README.md docs/superpowers/specs/2026-06-29-fast-data-design.md docs/superpowers/plans/2026-06-29-fast-data.md package-lock.json
git commit -m "feat: add fast data processor"
```

---

## Self-Review

- Spec coverage: plugin trigger, empty repeated activation, immediate processing, input-original behavior, copy action, reset action, transformer isolation, no preload services, and build validation are each covered by tasks above.
- Placeholder scan: this plan does not contain deferred implementation markers or undefined future work.
- Type consistency: all functions consumed by `src/Fast/index.vue` are produced by `src/Fast/transformers.ts` with matching names and string signatures.
Loading