openprototype 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/AGENTS.md +58 -0
  2. package/CONVENTIONS.md +54 -0
  3. package/LICENSE +21 -0
  4. package/README.md +233 -2
  5. package/bin/cli.js +297 -0
  6. package/lib/config.js +162 -0
  7. package/package.json +32 -10
  8. package/product/demo/pc/customer/customer_form.html +134 -0
  9. package/product/demo/pc/customer/customer_form.md +33 -0
  10. package/product/demo/pc/customer/customer_list.html +129 -0
  11. package/product/demo/pc/customer/customer_list.md +35 -0
  12. package/product/demo/pc/demo-data.js +23 -0
  13. package/product/demo/pc/index.html +1069 -0
  14. package/product/demo/pc/nav-tree.json +15 -0
  15. package/proto-kit.config.json +13 -0
  16. package/runtime/server.js +664 -0
  17. package/runtime/shared/ai-polish.js +159 -0
  18. package/runtime/shared/base-manager.js +168 -0
  19. package/runtime/shared/common/component-renderer.js +917 -0
  20. package/runtime/shared/common/copy-manager.js +134 -0
  21. package/runtime/shared/common/data-bridge.js +45 -0
  22. package/runtime/shared/common/form-renderer.js +211 -0
  23. package/runtime/shared/common/form.js +357 -0
  24. package/runtime/shared/common/formatter.js +78 -0
  25. package/runtime/shared/common/index.js +37 -0
  26. package/runtime/shared/common/line-chart.js +357 -0
  27. package/runtime/shared/common/modal-manager.js +82 -0
  28. package/runtime/shared/common/prd-panel.js +1014 -0
  29. package/runtime/shared/common/prd-popup.js +168 -0
  30. package/runtime/shared/common/search-renderer.js +95 -0
  31. package/runtime/shared/common/table-renderer.js +177 -0
  32. package/runtime/shared/common/table.js +160 -0
  33. package/runtime/shared/common/toast.js +99 -0
  34. package/runtime/shared/common/ui-preference-manager.js +74 -0
  35. package/runtime/shared/common/view-mode.js +30 -0
  36. package/runtime/shared/common.js +43 -0
  37. package/runtime/shared/constants/icons.js +28 -0
  38. package/runtime/shared/constants/status.js +67 -0
  39. package/runtime/shared/libs/marked.min.js +69 -0
  40. package/runtime/shared/prd-content.js +9 -0
  41. package/runtime/shared/styles.css +7673 -0
  42. package/runtime/shared/utils.js +110 -0
  43. package/runtime/shared/view-controls.js +148 -0
  44. package/runtime/shell/agent-panel.css +429 -0
  45. package/runtime/shell/agent-panel.js +629 -0
  46. package/scripts/check/run-checks.js +58 -0
  47. package/scripts/check/smoke-test.js +244 -0
  48. package/scripts/check/static-check.js +248 -0
  49. package/scripts/check/sync-nav-tree.js +139 -0
  50. package/templates/AGENTS.md +58 -0
  51. package/templates/CONVENTIONS.md +54 -0
  52. package/templates/gitignore +10 -0
  53. package/templates/product-shell/index.html +1069 -0
  54. package/templates/skills/auto-test/SKILL.md +62 -0
  55. package/templates/skills/xiaojia/SKILL.md +299 -0
  56. package/cli.js +0 -4
@@ -0,0 +1,159 @@
1
+ /**
2
+ * AI 润色组件
3
+ * 为多行文本框提供 AI 润色、扩写、缩写、总结功能
4
+ *
5
+ * API:
6
+ * - initAIPolish() - 初始化页面上所有 AI 润色文本框
7
+ * - handleAIAction(action, textarea) - 处理 AI 操作
8
+ *
9
+ * action 可选值: polish(润色)、expand(扩写)、shorten(缩写)、summary(总结)
10
+ *
11
+ * 依赖: shared/styles.css(提供 .textarea-wrapper、.ai-polish-btn、.ai-polish-menu 样式)
12
+ */
13
+
14
+ var AIPolish = (function() {
15
+ 'use strict';
16
+
17
+ var ACTION_LABELS = {
18
+ polish: 'AI 润色',
19
+ expand: '扩写',
20
+ shorten: '缩写',
21
+ summary: '总结'
22
+ };
23
+
24
+ var ACTION_ICONS = {
25
+ polish: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><path d="M12 3l1.912 3.874L18 8l-4.088 1.126L12 13l-1.912-3.874L6 8l4.088-1.126L12 3z"></path></svg>',
26
+ expand: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" y1="3" x2="14" y2="10"></line><line x1="3" y1="21" x2="10" y2="14"></line></svg>',
27
+ shorten: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><polyline points="4 14 10 14 10 20"></polyline><polyline points="20 10 14 10 14 4"></polyline><line x1="14" y1="10" x2="21" y2="3"></line><line x1="3" y1="21" x2="10" y2="14"></line></svg>',
28
+ summary: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:14px;height:14px;"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>'
29
+ };
30
+
31
+ /**
32
+ * 模拟 AI 处理(前端原型无真实后端,模拟延迟后返回结果)
33
+ */
34
+ function simulateAI(action, text, callback) {
35
+ var result;
36
+ switch (action) {
37
+ case 'polish':
38
+ result = text.replace(/\s+/g, ' ').trim();
39
+ break;
40
+ case 'expand':
41
+ result = text + '\n(扩写内容:以上描述可进一步细化,包含更多背景信息和具体细节。)';
42
+ break;
43
+ case 'shorten':
44
+ result = text.length > 50 ? text.substring(0, Math.floor(text.length / 2)) + '…' : text;
45
+ break;
46
+ case 'summary':
47
+ result = '摘要:' + (text.length > 30 ? text.substring(0, 30) + '…' : text);
48
+ break;
49
+ default:
50
+ result = text;
51
+ }
52
+
53
+ setTimeout(function() {
54
+ callback(result);
55
+ }, 800);
56
+ }
57
+
58
+ /**
59
+ * 处理 AI 操作
60
+ * @param {string} action - 操作类型: polish | expand | shorten | summary
61
+ * @param {HTMLTextAreaElement} textarea - 目标文本框
62
+ */
63
+ function handleAIAction(action, textarea) {
64
+ var originalText = textarea.value.trim();
65
+ if (!originalText) {
66
+ if (typeof UI !== 'undefined' && UI.toast) {
67
+ UI.toast('请先输入内容', 'warning');
68
+ }
69
+ return;
70
+ }
71
+
72
+ var label = ACTION_LABELS[action] || action;
73
+ textarea.disabled = true;
74
+ textarea.style.opacity = '0.6';
75
+
76
+ simulateAI(action, originalText, function(result) {
77
+ textarea.value = result;
78
+ textarea.disabled = false;
79
+ textarea.style.opacity = '1';
80
+ textarea.dispatchEvent(new Event('input', { bubbles: true }));
81
+
82
+ if (typeof UI !== 'undefined' && UI.toast) {
83
+ UI.toast(label + '完成', 'success');
84
+ }
85
+ });
86
+ }
87
+
88
+ /**
89
+ * 创建 AI 按钮和菜单
90
+ */
91
+ function createAIButton(textarea) {
92
+ var wrapper = document.createElement('div');
93
+ wrapper.className = 'textarea-wrapper';
94
+ textarea.parentNode.insertBefore(wrapper, textarea);
95
+ wrapper.appendChild(textarea);
96
+ textarea.classList.add('ai-textarea');
97
+
98
+ var btn = document.createElement('button');
99
+ btn.type = 'button';
100
+ btn.className = 'ai-polish-btn';
101
+ btn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#9254de" stroke-width="2" style="width:18px;height:18px;"><path d="M12 3l1.912 3.874L18 8l-4.088 1.126L12 13l-1.912-3.874L6 8l4.088-1.126L12 3z"></path><path d="M5 15l.5 1 1 .5-1 .5-.5 1-.5-1-1-.5 1-.5.5-1z"></path><path d="M19 11l.5 1 1 .5-1 .5-.5 1-.5-1-1-.5 1-.5.5-1z"></path><path d="M17 17l.3 1 1 .3-1 .3-.3 1-.3-1-1-.3 1-.3.3-1z"></path></svg>';
102
+ wrapper.appendChild(btn);
103
+
104
+ var menu = document.createElement('div');
105
+ menu.className = 'ai-polish-menu';
106
+ var actions = ['polish', 'expand', 'shorten', 'summary'];
107
+ actions.forEach(function(action) {
108
+ var item = document.createElement('div');
109
+ item.className = 'ai-polish-menu-item';
110
+ item.dataset.action = action;
111
+ item.innerHTML = ACTION_ICONS[action] + ' ' + ACTION_LABELS[action];
112
+ item.addEventListener('click', function(e) {
113
+ e.stopPropagation();
114
+ menu.classList.remove('active');
115
+ handleAIAction(action, textarea);
116
+ });
117
+ menu.appendChild(item);
118
+ });
119
+ wrapper.appendChild(menu);
120
+
121
+ btn.addEventListener('click', function(e) {
122
+ e.stopPropagation();
123
+ menu.classList.toggle('active');
124
+ });
125
+
126
+ document.addEventListener('click', function(e) {
127
+ if (!wrapper.contains(e.target)) {
128
+ menu.classList.remove('active');
129
+ }
130
+ });
131
+ }
132
+
133
+ /**
134
+ * 初始化页面上所有 AI 润色文本框
135
+ * 自动查找所有带 .ai-textarea 类的 textarea,为其添加 AI 润色按钮
136
+ */
137
+ function initAIPolish() {
138
+ var textareas = document.querySelectorAll('textarea.ai-textarea');
139
+ textareas.forEach(function(textarea) {
140
+ if (!textarea.parentNode.classList.contains('textarea-wrapper')) {
141
+ createAIButton(textarea);
142
+ }
143
+ });
144
+ }
145
+
146
+ return {
147
+ init: initAIPolish,
148
+ handleAction: handleAIAction,
149
+ ACTION_LABELS: ACTION_LABELS
150
+ };
151
+ })();
152
+
153
+ function initAIPolish() {
154
+ AIPolish.init();
155
+ }
156
+
157
+ function handleAIAction(action, textarea) {
158
+ AIPolish.handleAction(action, textarea);
159
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * BaseDataManager - 数据管理基类
3
+ *
4
+ * 提供统一的数据存储和 CRUD 操作,子类只需定义 STORAGE_KEY 即可继承所有基础功能。
5
+ *
6
+ * 使用示例:
7
+ * class MyDataManager extends BaseDataManager {
8
+ * constructor() {
9
+ * super('my_data_storage_key');
10
+ * }
11
+ *
12
+ * initSampleData() {
13
+ * return [{ id: '001', name: '示例数据' }];
14
+ * }
15
+ * }
16
+ */
17
+ class BaseDataManager {
18
+ /**
19
+ * 构造函数
20
+ * @param {string} storageKey - localStorage 存储键名
21
+ */
22
+ constructor(storageKey) {
23
+ if (!storageKey) {
24
+ throw new Error('BaseDataManager: storageKey is required');
25
+ }
26
+ this.STORAGE_KEY = storageKey;
27
+ }
28
+
29
+ /**
30
+ * 获取所有数据
31
+ * @returns {Array} 数据数组
32
+ */
33
+ getData() {
34
+ const data = localStorage.getItem(this.STORAGE_KEY);
35
+ if (data) {
36
+ try {
37
+ const parsed = JSON.parse(data);
38
+ if (Array.isArray(parsed)) {
39
+ return parsed;
40
+ }
41
+ } catch (e) {
42
+ console.error(`Failed to parse ${this.STORAGE_KEY} data:`, e);
43
+ }
44
+ }
45
+ return this.initSampleData();
46
+ }
47
+
48
+ /**
49
+ * 保存所有数据
50
+ * @param {Array} data - 要保存的数据数组
51
+ */
52
+ saveData(data) {
53
+ localStorage.setItem(this.STORAGE_KEY, JSON.stringify(data));
54
+ }
55
+
56
+ /**
57
+ * 根据 ID 获取单个数据项
58
+ * @param {string|number} id - 数据项 ID
59
+ * @returns {Object|undefined} 找到的数据项或 undefined
60
+ */
61
+ getItemById(id) {
62
+ const data = this.getData();
63
+ return data.find(item => item.id === id);
64
+ }
65
+
66
+ /**
67
+ * 保存或更新单个数据项
68
+ * @param {Object} item - 要保存的数据项(必须包含 id 字段)
69
+ */
70
+ saveItem(item) {
71
+ const data = this.getData();
72
+ const index = data.findIndex(i => i.id === item.id);
73
+ if (index !== -1) {
74
+ data[index] = item;
75
+ } else {
76
+ data.push(item);
77
+ }
78
+ this.saveData(data);
79
+ }
80
+
81
+ /**
82
+ * 更新单个数据项
83
+ * @param {string|number} id - 数据项 ID
84
+ * @param {Object} newData - 要更新的数据
85
+ */
86
+ updateItem(id, newData) {
87
+ const data = this.getData();
88
+ const index = data.findIndex(i => i.id === id);
89
+ if (index !== -1) {
90
+ data[index] = { ...data[index], ...newData, updateTime: new Date().toISOString() };
91
+ this.saveData(data);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * 删除单个数据项
97
+ * @param {string|number} id - 数据项 ID
98
+ */
99
+ deleteItem(id) {
100
+ const data = this.getData();
101
+ const filtered = data.filter(i => i.id !== id);
102
+ this.saveData(filtered);
103
+ }
104
+
105
+ /**
106
+ * 清空所有数据
107
+ */
108
+ clearAll() {
109
+ localStorage.removeItem(this.STORAGE_KEY);
110
+ }
111
+
112
+ /**
113
+ * 通用过滤方法 - 支持多条件搜索
114
+ * @param {Object} criteria - 过滤条件对象,例如 { status: 'approved', year: '2026' }
115
+ * @returns {Array} 符合条件的数据数组
116
+ *
117
+ * 使用示例:
118
+ * manager.filter({ status: 'approved', year: '2026' })
119
+ * manager.filter({ channel: 'B2C', platform: '京东' })
120
+ */
121
+ filter(criteria) {
122
+ const data = this.getData();
123
+ if (!criteria || Object.keys(criteria).length === 0) {
124
+ return data;
125
+ }
126
+
127
+ return data.filter(item => {
128
+ return Object.keys(criteria).every(key => {
129
+ const criteriaValue = criteria[key];
130
+ const itemValue = item[key];
131
+
132
+ if (criteriaValue === undefined || criteriaValue === null || criteriaValue === '') {
133
+ return true;
134
+ }
135
+
136
+ if (itemValue === undefined || itemValue === null) {
137
+ return false;
138
+ }
139
+
140
+ return itemValue === criteriaValue;
141
+ });
142
+ });
143
+ }
144
+
145
+ /**
146
+ * 获取下一个 ID (默认实现,子类可重写)
147
+ * @returns {string} 新的 ID
148
+ */
149
+ getNextId() {
150
+ const data = this.getData();
151
+ if (data.length === 0) return '000001';
152
+
153
+ const validIds = data.map(i => parseInt(i.id, 10)).filter(id => !isNaN(id));
154
+ if (validIds.length === 0) return '000001';
155
+
156
+ const maxId = Math.max(...validIds);
157
+ return String(maxId + 1).padStart(6, '0');
158
+ }
159
+
160
+ /**
161
+ * 初始化示例数据 (子类必须实现)
162
+ * @returns {Array} 示例数据数组
163
+ */
164
+ initSampleData() {
165
+ console.warn(`BaseDataManager: initSampleData() should be implemented by subclass for ${this.STORAGE_KEY}`);
166
+ return [];
167
+ }
168
+ }