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,357 @@
1
+ var LineChart = {
2
+ render: function(containerId, options) {
3
+ options = options || {};
4
+ var container = document.getElementById(containerId);
5
+ if (!container) return null;
6
+
7
+ var series = options.series || [];
8
+ var title = options.title || '';
9
+ var height = options.height || 260;
10
+ var padding = options.padding || { top: 40, right: 40, bottom: 50, left: 60 };
11
+ var legendConfig = options.legend || {};
12
+ var tooltipConfig = options.tooltip || {};
13
+ var xAxisConfig = options.xAxis || {};
14
+ var yAxisConfig = options.yAxis || {};
15
+ var showLegend = legendConfig.enabled !== false;
16
+ var showTooltip = tooltipConfig.enabled !== false;
17
+ var legendPosition = legendConfig.position || 'top';
18
+
19
+ var wrapper = document.createElement('div');
20
+ wrapper.className = 'line-chart-container';
21
+
22
+ if (title) {
23
+ var titleEl = document.createElement('div');
24
+ titleEl.className = 'line-chart-title';
25
+ titleEl.textContent = title;
26
+ wrapper.appendChild(titleEl);
27
+ }
28
+
29
+ if (showLegend && legendPosition === 'top' && series.length > 0) {
30
+ var legendEl = document.createElement('div');
31
+ legendEl.className = 'line-chart-legend';
32
+ series.forEach(function(s, i) {
33
+ var item = document.createElement('div');
34
+ item.className = 'line-chart-legend-item';
35
+ item.setAttribute('data-index', i);
36
+ var dot = document.createElement('span');
37
+ dot.className = 'line-chart-legend-dot';
38
+ dot.style.backgroundColor = s.color || '#1677ff';
39
+ if (s.dash) {
40
+ dot.style.backgroundImage = 'repeating-linear-gradient(90deg, ' + (s.color || '#1677ff') + ' 0, ' + (s.color || '#1677ff') + ' 4px, transparent 4px, transparent 8px)';
41
+ dot.style.backgroundColor = 'transparent';
42
+ }
43
+ var label = document.createElement('span');
44
+ label.className = 'line-chart-legend-label';
45
+ label.textContent = s.name || ('Series ' + (i + 1));
46
+ item.appendChild(dot);
47
+ item.appendChild(label);
48
+ legendEl.appendChild(item);
49
+ });
50
+ wrapper.appendChild(legendEl);
51
+ }
52
+
53
+ var canvasWrapper = document.createElement('div');
54
+ canvasWrapper.className = 'line-chart-canvas-wrapper';
55
+ var canvas = document.createElement('canvas');
56
+ canvas.className = 'line-chart-canvas';
57
+ canvas.style.height = height + 'px';
58
+ canvasWrapper.appendChild(canvas);
59
+ wrapper.appendChild(canvasWrapper);
60
+
61
+ if (showTooltip) {
62
+ var tooltipEl = document.createElement('div');
63
+ tooltipEl.className = 'line-chart-tooltip';
64
+ tooltipEl.style.display = 'none';
65
+ wrapper.appendChild(tooltipEl);
66
+ }
67
+
68
+ container.innerHTML = '';
69
+ container.appendChild(wrapper);
70
+
71
+ var instance = {
72
+ container: container,
73
+ canvas: canvas,
74
+ series: series,
75
+ padding: padding,
76
+ height: height,
77
+ xAxisConfig: xAxisConfig,
78
+ yAxisConfig: yAxisConfig,
79
+ showLegend: showLegend,
80
+ showTooltip: showTooltip,
81
+ tooltipEl: tooltipEl,
82
+ hiddenSeries: {},
83
+ _resizeHandler: null,
84
+
85
+ draw: function() {
86
+ var ctx = canvas.getContext('2d');
87
+ var rect = canvasWrapper.getBoundingClientRect();
88
+ canvas.width = rect.width * 2;
89
+ canvas.height = rect.height * 2;
90
+ ctx.scale(2, 2);
91
+
92
+ var width = rect.width;
93
+ var height = rect.height;
94
+ var p = this.padding;
95
+ var chartWidth = width - p.left - p.right;
96
+ var chartHeight = height - p.top - p.bottom;
97
+
98
+ ctx.clearRect(0, 0, width, height);
99
+
100
+ var allData = [];
101
+ this.series.forEach(function(s, i) {
102
+ if (!this.hiddenSeries[i]) {
103
+ allData = allData.concat(s.data || []);
104
+ }
105
+ }.bind(this));
106
+
107
+ if (allData.length === 0) {
108
+ ctx.fillStyle = '#999';
109
+ ctx.font = '14px sans-serif';
110
+ ctx.textAlign = 'center';
111
+ ctx.fillText('暂无数据', width / 2, height / 2);
112
+ return;
113
+ }
114
+
115
+ var yValues = allData.map(function(d) { return d.y; });
116
+ var maxVal = Math.max.apply(null, yValues.concat([1]));
117
+ var minVal = Math.min.apply(null, yValues.concat([0]));
118
+ var yRange = maxVal - minVal || 1;
119
+ maxVal = maxVal + yRange * 0.1;
120
+ minVal = Math.max(0, minVal - yRange * 0.1);
121
+ yRange = maxVal - minVal;
122
+
123
+ ctx.strokeStyle = '#e8e8e8';
124
+ ctx.lineWidth = 1;
125
+ for (var i = 0; i <= 5; i++) {
126
+ var y = p.top + (chartHeight / 5) * i;
127
+ ctx.beginPath();
128
+ ctx.moveTo(p.left, y);
129
+ ctx.lineTo(width - p.right, y);
130
+ ctx.stroke();
131
+
132
+ var val = maxVal - (yRange / 5) * i;
133
+ ctx.fillStyle = '#999';
134
+ ctx.font = '12px sans-serif';
135
+ ctx.textAlign = 'right';
136
+ var yLabel = '';
137
+ if (yAxisConfig.format === 'currency') {
138
+ yLabel = val >= 10000 ? (val / 10000).toFixed(1) + '万' : val >= 1000 ? (val / 1000).toFixed(1) + 'k' : val.toFixed(0);
139
+ } else {
140
+ yLabel = val >= 10000 ? (val / 10000).toFixed(1) + '万' : val >= 1000 ? (val / 1000).toFixed(0) + 'k' : val.toFixed(0);
141
+ }
142
+ ctx.fillText(yLabel, p.left - 10, y + 4);
143
+ }
144
+
145
+ if (yAxisConfig.label) {
146
+ ctx.fillStyle = '#333';
147
+ ctx.font = '12px sans-serif';
148
+ ctx.textAlign = 'center';
149
+ ctx.save();
150
+ ctx.translate(14, p.top + chartHeight / 2);
151
+ ctx.rotate(-Math.PI / 2);
152
+ ctx.fillText(yAxisConfig.label, 0, 0);
153
+ ctx.restore();
154
+ }
155
+
156
+ var xLabels = [];
157
+ this.series.forEach(function(s) {
158
+ if (!this.hiddenSeries[s._index !== undefined ? s._index : 0]) {
159
+ (s.data || []).forEach(function(d) {
160
+ if (xLabels.indexOf(d.x) === -1) xLabels.push(d.x);
161
+ });
162
+ }
163
+ }.bind(this));
164
+ xLabels.sort();
165
+
166
+ var xStep = chartWidth / Math.max(xLabels.length - 1, 1);
167
+ var labelFormat = xAxisConfig.labelFormat || 'month';
168
+ var monthCount = xAxisConfig.monthCount || 12;
169
+
170
+ ctx.fillStyle = '#666';
171
+ ctx.font = '12px sans-serif';
172
+ ctx.textAlign = 'center';
173
+ var labelStep = Math.max(1, Math.floor(xLabels.length / 12));
174
+ for (var i = 0; i < xLabels.length; i++) {
175
+ if (i % labelStep === 0 || i === xLabels.length - 1) {
176
+ var x = p.left + xStep * i;
177
+ var labelText = '';
178
+ if (labelFormat === 'month') {
179
+ labelText = xLabels[i].substring(5, 7) + '月';
180
+ } else {
181
+ labelText = xLabels[i].substring(5);
182
+ }
183
+ ctx.fillText(labelText, x, height - p.bottom + 20);
184
+ }
185
+ }
186
+
187
+ this.series.forEach(function(s, idx) {
188
+ if (this.hiddenSeries[idx]) return;
189
+ var data = s.data || [];
190
+ if (data.length === 0) return;
191
+
192
+ var color = s.color || '#1677ff';
193
+ var lineWidth = s.lineWidth || 3;
194
+ var pointRadius = s.pointRadius || 6;
195
+ var isDash = s.dash || false;
196
+
197
+ ctx.beginPath();
198
+ if (isDash) {
199
+ ctx.setLineDash([8, 4]);
200
+ } else {
201
+ ctx.setLineDash([]);
202
+ }
203
+ ctx.strokeStyle = color;
204
+ ctx.lineWidth = lineWidth;
205
+
206
+ var points = [];
207
+ data.forEach(function(d, di) {
208
+ var xi = xLabels.indexOf(d.x);
209
+ if (xi === -1) return;
210
+ var px = p.left + xStep * xi;
211
+ var py = p.top + chartHeight - ((d.y - minVal) / yRange) * chartHeight;
212
+ points.push({ x: px, y: py, data: d });
213
+ if (di === 0) {
214
+ ctx.moveTo(px, py);
215
+ } else {
216
+ ctx.lineTo(px, py);
217
+ }
218
+ });
219
+ ctx.stroke();
220
+ ctx.setLineDash([]);
221
+
222
+ if (!isDash) {
223
+ points.forEach(function(pt) {
224
+ ctx.beginPath();
225
+ ctx.arc(pt.x, pt.y, pointRadius, 0, Math.PI * 2);
226
+ ctx.fillStyle = color;
227
+ ctx.fill();
228
+ ctx.strokeStyle = '#fff';
229
+ ctx.lineWidth = 2;
230
+ ctx.stroke();
231
+ });
232
+ } else {
233
+ points.forEach(function(pt) {
234
+ ctx.beginPath();
235
+ ctx.arc(pt.x, pt.y, Math.max(pointRadius - 2, 3), 0, Math.PI * 2);
236
+ ctx.fillStyle = color;
237
+ ctx.fill();
238
+ });
239
+ }
240
+
241
+ s._points = points;
242
+ }.bind(this));
243
+
244
+ this._xLabels = xLabels;
245
+ this._xStep = xStep;
246
+ this._chartWidth = chartWidth;
247
+ this._chartHeight = chartHeight;
248
+ this._minVal = minVal;
249
+ this._yRange = yRange;
250
+ },
251
+
252
+ update: function(newOptions) {
253
+ if (newOptions && newOptions.series) {
254
+ this.series = newOptions.series;
255
+ }
256
+ this.hiddenSeries = {};
257
+ this.draw();
258
+ },
259
+
260
+ resize: function() {
261
+ this.draw();
262
+ },
263
+
264
+ destroy: function() {
265
+ if (this._resizeHandler) {
266
+ window.removeEventListener('resize', this._resizeHandler);
267
+ }
268
+ this.container.innerHTML = '';
269
+ },
270
+
271
+ _handleMouseMove: function(e) {
272
+ if (!this.showTooltip || !this.tooltipEl) return;
273
+
274
+ var rect = this.canvas.getBoundingClientRect();
275
+ var mouseX = e.clientX - rect.left;
276
+ var mouseY = e.clientY - rect.top;
277
+ var p = this.padding;
278
+
279
+ if (mouseX < p.left || mouseX > rect.width - p.right || mouseY < p.top || mouseY > rect.height - p.bottom) {
280
+ this.tooltipEl.style.display = 'none';
281
+ return;
282
+ }
283
+
284
+ var closestPoint = null;
285
+ var closestDist = Infinity;
286
+ var closestSeries = null;
287
+
288
+ this.series.forEach(function(s, idx) {
289
+ if (this.hiddenSeries[idx]) return;
290
+ var points = s._points || [];
291
+ points.forEach(function(pt) {
292
+ var dist = Math.abs(pt.x - mouseX);
293
+ if (dist < closestDist) {
294
+ closestDist = dist;
295
+ closestPoint = pt;
296
+ closestSeries = s;
297
+ }
298
+ });
299
+ }.bind(this));
300
+
301
+ if (closestPoint && closestDist < 30) {
302
+ var html = '<div class="line-chart-tooltip-date">' + closestPoint.data.x + '</div>';
303
+ html += '<div class="line-chart-tooltip-series">' + closestSeries.name + '</div>';
304
+ html += '<div class="line-chart-tooltip-value">' + (yAxisConfig.format === 'currency' ? '¥' : '') + closestPoint.data.y.toLocaleString() + '</div>';
305
+
306
+ this.tooltipEl.innerHTML = html;
307
+ this.tooltipEl.style.display = 'block';
308
+
309
+ var tooltipRect = this.tooltipEl.getBoundingClientRect();
310
+ var left = closestPoint.x + 12;
311
+ if (left + tooltipRect.width > rect.width - p.right) {
312
+ left = closestPoint.x - tooltipRect.width - 12;
313
+ }
314
+ this.tooltipEl.style.left = left + 'px';
315
+ this.tooltipEl.style.top = (closestPoint.y - 10) + 'px';
316
+ } else {
317
+ this.tooltipEl.style.display = 'none';
318
+ }
319
+ },
320
+
321
+ _handleLegendClick: function(e) {
322
+ var item = e.target.closest('.line-chart-legend-item');
323
+ if (!item) return;
324
+ var idx = parseInt(item.getAttribute('data-index'));
325
+ this.hiddenSeries[idx] = !this.hiddenSeries[idx];
326
+ item.classList.toggle('disabled', this.hiddenSeries[idx]);
327
+ this.draw();
328
+ }
329
+ };
330
+
331
+ instance.series.forEach(function(s, i) { s._index = i; });
332
+
333
+ instance.draw();
334
+
335
+ if (showLegend) {
336
+ var legendEl = wrapper.querySelector('.line-chart-legend');
337
+ if (legendEl) {
338
+ legendEl.addEventListener('click', instance._handleLegendClick.bind(instance));
339
+ }
340
+ }
341
+
342
+ if (showTooltip) {
343
+ canvas.addEventListener('mousemove', instance._handleMouseMove.bind(instance));
344
+ canvas.addEventListener('mouseleave', function() {
345
+ if (instance.tooltipEl) instance.tooltipEl.style.display = 'none';
346
+ });
347
+ }
348
+
349
+ instance._resizeHandler = function() {
350
+ instance.resize();
351
+ };
352
+ window.addEventListener('resize', instance._resizeHandler);
353
+
354
+ container._lineChartInstance = instance;
355
+ return instance;
356
+ }
357
+ };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * ModalManager 模块
3
+ * 模态框管理器,统一管理模态框的打开、关闭和保存操作
4
+ */
5
+
6
+ var ModalManager = {
7
+ modals: {},
8
+
9
+ register: function(modalId, config) {
10
+ this.modals[modalId] = {
11
+ element: document.getElementById(modalId),
12
+ config: config || {}
13
+ };
14
+ },
15
+
16
+ open: function(modalId, options) {
17
+ options = options || {};
18
+ var modal = this.modals[modalId];
19
+ if (!modal || !modal.element) {
20
+ modal = {
21
+ element: document.getElementById(modalId),
22
+ config: {}
23
+ };
24
+ this.modals[modalId] = modal;
25
+ }
26
+
27
+ var config = modal.config;
28
+
29
+ if (config.titleId && options.title) {
30
+ var titleEl = document.getElementById(config.titleId);
31
+ if (titleEl) titleEl.textContent = options.title;
32
+ }
33
+
34
+ if (config.onOpen) {
35
+ config.onOpen(options);
36
+ }
37
+
38
+ modal.element.classList.add('active');
39
+ },
40
+
41
+ close: function(modalId) {
42
+ var modal = this.modals[modalId];
43
+ if (!modal) {
44
+ var element = document.getElementById(modalId);
45
+ if (element) {
46
+ element.classList.remove('active');
47
+ }
48
+ return;
49
+ }
50
+
51
+ if (modal.config.onClose) {
52
+ modal.config.onClose();
53
+ }
54
+
55
+ modal.element.classList.remove('active');
56
+ },
57
+
58
+ save: function(modalId, callback) {
59
+ var modal = this.modals[modalId];
60
+ if (!modal) return;
61
+
62
+ if (modal.config.onSave) {
63
+ modal.config.onSave(callback);
64
+ } else if (callback) {
65
+ callback();
66
+ }
67
+ },
68
+
69
+ clearForm: function(formId) {
70
+ var form = document.getElementById(formId);
71
+ if (!form) return;
72
+
73
+ var inputs = form.querySelectorAll('input, select, textarea');
74
+ inputs.forEach(function(input) {
75
+ if (input.type === 'checkbox' || input.type === 'radio') {
76
+ input.checked = false;
77
+ } else {
78
+ input.value = '';
79
+ }
80
+ });
81
+ }
82
+ };