@leeoohoo/ui-apps-devkit 0.1.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.
- package/README.md +70 -0
- package/bin/chatos-uiapp.js +5 -0
- package/package.json +22 -0
- package/src/cli.js +53 -0
- package/src/commands/dev.js +14 -0
- package/src/commands/init.js +141 -0
- package/src/commands/install.js +55 -0
- package/src/commands/pack.js +72 -0
- package/src/commands/validate.js +103 -0
- package/src/lib/args.js +49 -0
- package/src/lib/config.js +29 -0
- package/src/lib/fs.js +78 -0
- package/src/lib/path-boundary.js +16 -0
- package/src/lib/plugin.js +45 -0
- package/src/lib/template.js +168 -0
- package/src/sandbox/server.js +861 -0
- package/templates/basic/README.md +58 -0
- package/templates/basic/chatos.config.json +5 -0
- package/templates/basic/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +181 -0
- package/templates/basic/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +74 -0
- package/templates/basic/docs/CHATOS_UI_APPS_HOST_API.md +123 -0
- package/templates/basic/docs/CHATOS_UI_APPS_OVERVIEW.md +110 -0
- package/templates/basic/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +227 -0
- package/templates/basic/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -0
- package/templates/basic/plugin/apps/app/index.mjs +263 -0
- package/templates/basic/plugin/apps/app/mcp-prompt.en.md +7 -0
- package/templates/basic/plugin/apps/app/mcp-prompt.zh.md +7 -0
- package/templates/basic/plugin/apps/app/mcp-server.mjs +15 -0
- package/templates/basic/plugin/backend/index.mjs +37 -0
- package/templates/basic/template.json +7 -0
- package/templates/notepad/README.md +36 -0
- package/templates/notepad/chatos.config.json +4 -0
- package/templates/notepad/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +181 -0
- package/templates/notepad/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +74 -0
- package/templates/notepad/docs/CHATOS_UI_APPS_HOST_API.md +123 -0
- package/templates/notepad/docs/CHATOS_UI_APPS_OVERVIEW.md +110 -0
- package/templates/notepad/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +227 -0
- package/templates/notepad/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -0
- package/templates/notepad/plugin/apps/app/api.mjs +30 -0
- package/templates/notepad/plugin/apps/app/dom.mjs +14 -0
- package/templates/notepad/plugin/apps/app/ds-tree.mjs +35 -0
- package/templates/notepad/plugin/apps/app/index.mjs +1056 -0
- package/templates/notepad/plugin/apps/app/layers.mjs +338 -0
- package/templates/notepad/plugin/apps/app/markdown.mjs +120 -0
- package/templates/notepad/plugin/apps/app/mcp-prompt.en.md +22 -0
- package/templates/notepad/plugin/apps/app/mcp-prompt.zh.md +22 -0
- package/templates/notepad/plugin/apps/app/mcp-server.mjs +200 -0
- package/templates/notepad/plugin/apps/app/styles.mjs +355 -0
- package/templates/notepad/plugin/apps/app/tags.mjs +21 -0
- package/templates/notepad/plugin/apps/app/ui.mjs +280 -0
- package/templates/notepad/plugin/backend/index.mjs +99 -0
- package/templates/notepad/plugin/plugin.json +23 -0
- package/templates/notepad/plugin/shared/notepad-paths.mjs +62 -0
- package/templates/notepad/plugin/shared/notepad-store.mjs +765 -0
- package/templates/notepad/template.json +8 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { DS_TREE_STYLES } from './ds-tree.mjs';
|
|
2
|
+
|
|
3
|
+
export const NOTEPAD_MANAGER_STYLES = `
|
|
4
|
+
${DS_TREE_STYLES}
|
|
5
|
+
.np-root {
|
|
6
|
+
height: 100%;
|
|
7
|
+
min-height: 0;
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
gap: 10px;
|
|
11
|
+
padding: 12px;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
.np-header {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
gap: 12px;
|
|
19
|
+
}
|
|
20
|
+
.np-title {
|
|
21
|
+
font-weight: 750;
|
|
22
|
+
letter-spacing: 0.2px;
|
|
23
|
+
}
|
|
24
|
+
.np-meta {
|
|
25
|
+
font-size: 12px;
|
|
26
|
+
opacity: 0.72;
|
|
27
|
+
}
|
|
28
|
+
.np-pill {
|
|
29
|
+
font-size: 12px;
|
|
30
|
+
padding: 6px 10px;
|
|
31
|
+
border-radius: 999px;
|
|
32
|
+
border: 1px solid var(--ds-panel-border);
|
|
33
|
+
background: var(--ds-subtle-bg);
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
user-select: none;
|
|
36
|
+
}
|
|
37
|
+
.np-pill[data-tone='ok'] { box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.12); }
|
|
38
|
+
.np-pill[data-tone='bad'] { box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.12); }
|
|
39
|
+
.np-btn {
|
|
40
|
+
border: 1px solid var(--ds-panel-border);
|
|
41
|
+
background: transparent;
|
|
42
|
+
border-radius: 10px;
|
|
43
|
+
padding: 6px 8px;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
font-weight: 600;
|
|
46
|
+
font-size: 12px;
|
|
47
|
+
line-height: 1.2;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
}
|
|
50
|
+
.np-btn:hover { background: var(--ds-subtle-bg); }
|
|
51
|
+
.np-btn:focus-visible {
|
|
52
|
+
outline: 2px solid var(--ds-focus-ring, rgba(0, 212, 255, 0.32));
|
|
53
|
+
outline-offset: 1px;
|
|
54
|
+
}
|
|
55
|
+
.np-btn:disabled,
|
|
56
|
+
.np-btn[data-disabled='1'] {
|
|
57
|
+
opacity: 0.55;
|
|
58
|
+
cursor: not-allowed;
|
|
59
|
+
box-shadow: none !important;
|
|
60
|
+
}
|
|
61
|
+
.np-input, .np-select, .np-textarea {
|
|
62
|
+
border: 1px solid var(--ds-panel-border);
|
|
63
|
+
background: var(--ds-subtle-bg);
|
|
64
|
+
color: inherit;
|
|
65
|
+
border-radius: 10px;
|
|
66
|
+
padding: 7px 9px;
|
|
67
|
+
outline: none;
|
|
68
|
+
box-sizing: border-box;
|
|
69
|
+
}
|
|
70
|
+
.np-input { width: 100%; }
|
|
71
|
+
.np-select { width: 100%; }
|
|
72
|
+
.np-textarea {
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
resize: none;
|
|
76
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
|
77
|
+
font-size: 13px;
|
|
78
|
+
line-height: 1.45;
|
|
79
|
+
background: var(--ds-code-bg);
|
|
80
|
+
border-color: var(--ds-code-border);
|
|
81
|
+
}
|
|
82
|
+
.np-grid {
|
|
83
|
+
flex: 1;
|
|
84
|
+
min-height: 0;
|
|
85
|
+
display: grid;
|
|
86
|
+
grid-template-columns: 300px 1fr;
|
|
87
|
+
gap: 10px;
|
|
88
|
+
}
|
|
89
|
+
.np-card {
|
|
90
|
+
border: 1px solid var(--ds-panel-border);
|
|
91
|
+
background: var(--ds-panel-bg);
|
|
92
|
+
border-radius: 12px;
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
min-height: 0;
|
|
95
|
+
display: flex;
|
|
96
|
+
flex-direction: column;
|
|
97
|
+
}
|
|
98
|
+
.np-card-header {
|
|
99
|
+
padding: 8px 10px;
|
|
100
|
+
border-bottom: 1px solid var(--ds-panel-border);
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: space-between;
|
|
104
|
+
gap: 10px;
|
|
105
|
+
font-size: 12px;
|
|
106
|
+
font-weight: 650;
|
|
107
|
+
}
|
|
108
|
+
.np-card-body {
|
|
109
|
+
padding: 10px;
|
|
110
|
+
flex: 1;
|
|
111
|
+
min-height: 0;
|
|
112
|
+
overflow: auto;
|
|
113
|
+
display: flex;
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
gap: 10px;
|
|
116
|
+
}
|
|
117
|
+
.np-section-title {
|
|
118
|
+
font-size: 12px;
|
|
119
|
+
font-weight: 750;
|
|
120
|
+
opacity: 0.85;
|
|
121
|
+
margin-bottom: 6px;
|
|
122
|
+
}
|
|
123
|
+
.np-section-title-row {
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: space-between;
|
|
127
|
+
gap: 8px;
|
|
128
|
+
}
|
|
129
|
+
.np-section-actions {
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: center;
|
|
132
|
+
gap: 6px;
|
|
133
|
+
}
|
|
134
|
+
.np-btn-icon {
|
|
135
|
+
width: 30px;
|
|
136
|
+
height: 30px;
|
|
137
|
+
padding: 0;
|
|
138
|
+
display: inline-flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
}
|
|
142
|
+
.np-btn-icon .ds-tree-icon {
|
|
143
|
+
opacity: 0.86;
|
|
144
|
+
}
|
|
145
|
+
.np-create-hint {
|
|
146
|
+
margin-top: 6px;
|
|
147
|
+
}
|
|
148
|
+
.np-list {
|
|
149
|
+
display: flex;
|
|
150
|
+
flex-direction: column;
|
|
151
|
+
gap: 6px;
|
|
152
|
+
}
|
|
153
|
+
.np-item {
|
|
154
|
+
border: 1px solid var(--ds-panel-border);
|
|
155
|
+
background: var(--ds-subtle-bg);
|
|
156
|
+
border-radius: 12px;
|
|
157
|
+
padding: 8px 10px;
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
display: flex;
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
gap: 2px;
|
|
162
|
+
}
|
|
163
|
+
.np-item:hover { box-shadow: 0 0 0 3px var(--ds-focus-ring); }
|
|
164
|
+
.np-item[data-active='1'] {
|
|
165
|
+
border-color: rgba(46, 160, 67, 0.55);
|
|
166
|
+
box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.18);
|
|
167
|
+
}
|
|
168
|
+
.np-item-title { font-weight: 700; }
|
|
169
|
+
.np-item-meta { font-size: 12px; opacity: 0.72; }
|
|
170
|
+
.np-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
171
|
+
.np-chip {
|
|
172
|
+
font-size: 12px;
|
|
173
|
+
padding: 6px 10px;
|
|
174
|
+
border-radius: 999px;
|
|
175
|
+
border: 1px solid var(--ds-panel-border);
|
|
176
|
+
background: var(--ds-subtle-bg);
|
|
177
|
+
cursor: pointer;
|
|
178
|
+
user-select: none;
|
|
179
|
+
}
|
|
180
|
+
.np-chip:hover { box-shadow: 0 0 0 3px var(--ds-focus-ring); }
|
|
181
|
+
.np-chip[data-active='1'] {
|
|
182
|
+
border-color: rgba(46, 160, 67, 0.55);
|
|
183
|
+
box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.18);
|
|
184
|
+
}
|
|
185
|
+
.np-row {
|
|
186
|
+
display: flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
gap: 6px;
|
|
189
|
+
flex-wrap: wrap;
|
|
190
|
+
}
|
|
191
|
+
.np-row-compact {
|
|
192
|
+
flex-wrap: nowrap;
|
|
193
|
+
}
|
|
194
|
+
.np-row-compact > .np-input {
|
|
195
|
+
width: auto;
|
|
196
|
+
flex: 1 1 auto;
|
|
197
|
+
min-width: 0;
|
|
198
|
+
}
|
|
199
|
+
.np-editor-top {
|
|
200
|
+
display: grid;
|
|
201
|
+
grid-template-columns: 1fr 220px;
|
|
202
|
+
gap: 8px;
|
|
203
|
+
}
|
|
204
|
+
.np-editor-top-row {
|
|
205
|
+
display: grid;
|
|
206
|
+
grid-template-columns: 1fr 220px;
|
|
207
|
+
gap: 8px;
|
|
208
|
+
align-items: center;
|
|
209
|
+
}
|
|
210
|
+
.np-editor-split {
|
|
211
|
+
flex: 1;
|
|
212
|
+
min-height: 0;
|
|
213
|
+
display: grid;
|
|
214
|
+
grid-template-columns: 1fr 1fr;
|
|
215
|
+
gap: 10px;
|
|
216
|
+
}
|
|
217
|
+
.np-root[data-editor-mode='preview'] .np-textarea {
|
|
218
|
+
display: none;
|
|
219
|
+
}
|
|
220
|
+
.np-root[data-editor-mode='preview'] .np-editor-split {
|
|
221
|
+
grid-template-columns: 1fr;
|
|
222
|
+
}
|
|
223
|
+
.np-preview {
|
|
224
|
+
border: 1px solid var(--ds-code-border);
|
|
225
|
+
background: var(--ds-code-bg);
|
|
226
|
+
border-radius: 10px;
|
|
227
|
+
padding: 10px;
|
|
228
|
+
overflow: auto;
|
|
229
|
+
min-height: 0;
|
|
230
|
+
font-size: 13px;
|
|
231
|
+
line-height: 1.6;
|
|
232
|
+
}
|
|
233
|
+
.np-preview h1, .np-preview h2, .np-preview h3, .np-preview h4, .np-preview h5, .np-preview h6 {
|
|
234
|
+
margin: 12px 0 8px;
|
|
235
|
+
font-weight: 750;
|
|
236
|
+
}
|
|
237
|
+
.np-preview p { margin: 0 0 10px; }
|
|
238
|
+
.np-preview code {
|
|
239
|
+
padding: 2px 6px;
|
|
240
|
+
border-radius: 6px;
|
|
241
|
+
border: 1px solid var(--ds-code-border);
|
|
242
|
+
background: rgba(110, 118, 129, 0.18);
|
|
243
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
|
244
|
+
font-size: 12px;
|
|
245
|
+
}
|
|
246
|
+
.np-preview pre {
|
|
247
|
+
padding: 10px 12px;
|
|
248
|
+
border-radius: 10px;
|
|
249
|
+
border: 1px solid var(--ds-code-border);
|
|
250
|
+
overflow: auto;
|
|
251
|
+
background: rgba(110, 118, 129, 0.18);
|
|
252
|
+
}
|
|
253
|
+
.np-preview pre code { border: none; padding: 0; background: transparent; }
|
|
254
|
+
.np-preview blockquote {
|
|
255
|
+
margin: 0 0 10px;
|
|
256
|
+
padding: 8px 10px;
|
|
257
|
+
border-left: 3px solid var(--ds-panel-border);
|
|
258
|
+
background: rgba(110, 118, 129, 0.14);
|
|
259
|
+
border-radius: 10px;
|
|
260
|
+
}
|
|
261
|
+
.np-preview ul, .np-preview ol { margin: 0 0 10px 22px; }
|
|
262
|
+
.np-preview img { max-width: 100%; border-radius: 10px; border: 1px solid var(--ds-panel-border); }
|
|
263
|
+
.np-menu-overlay {
|
|
264
|
+
position: fixed;
|
|
265
|
+
inset: 0;
|
|
266
|
+
z-index: 999;
|
|
267
|
+
}
|
|
268
|
+
.np-menu {
|
|
269
|
+
position: absolute;
|
|
270
|
+
min-width: 220px;
|
|
271
|
+
background: var(--ds-panel-bg);
|
|
272
|
+
border: 1px solid var(--ds-panel-border);
|
|
273
|
+
border-radius: 12px;
|
|
274
|
+
padding: 6px;
|
|
275
|
+
box-shadow: 0 18px 48px rgba(0,0,0,0.22);
|
|
276
|
+
}
|
|
277
|
+
.np-menu-item {
|
|
278
|
+
width: 100%;
|
|
279
|
+
border: none;
|
|
280
|
+
background: transparent;
|
|
281
|
+
color: inherit;
|
|
282
|
+
text-align: left;
|
|
283
|
+
padding: 8px 10px;
|
|
284
|
+
border-radius: 10px;
|
|
285
|
+
cursor: pointer;
|
|
286
|
+
font-size: 13px;
|
|
287
|
+
font-weight: 600;
|
|
288
|
+
}
|
|
289
|
+
.np-menu-item:hover { background: var(--ds-subtle-bg); }
|
|
290
|
+
.np-menu-item:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
291
|
+
.np-menu-item[data-danger='1'] { color: #f85149; }
|
|
292
|
+
:root[data-theme='dark'] .np-menu-item[data-danger='1'] { color: #ff7b72; }
|
|
293
|
+
.np-modal-overlay {
|
|
294
|
+
position: fixed;
|
|
295
|
+
inset: 0;
|
|
296
|
+
z-index: 1000;
|
|
297
|
+
display: flex;
|
|
298
|
+
align-items: center;
|
|
299
|
+
justify-content: center;
|
|
300
|
+
padding: 18px;
|
|
301
|
+
background: rgba(0,0,0,0.35);
|
|
302
|
+
}
|
|
303
|
+
.np-modal {
|
|
304
|
+
width: min(520px, 100%);
|
|
305
|
+
border: 1px solid var(--ds-panel-border);
|
|
306
|
+
background: var(--ds-panel-bg);
|
|
307
|
+
border-radius: 14px;
|
|
308
|
+
overflow: hidden;
|
|
309
|
+
display: flex;
|
|
310
|
+
flex-direction: column;
|
|
311
|
+
box-shadow: 0 18px 48px rgba(0,0,0,0.25);
|
|
312
|
+
}
|
|
313
|
+
.np-modal-header {
|
|
314
|
+
padding: 12px 14px;
|
|
315
|
+
border-bottom: 1px solid var(--ds-panel-border);
|
|
316
|
+
font-weight: 750;
|
|
317
|
+
font-size: 14px;
|
|
318
|
+
}
|
|
319
|
+
.np-modal-body {
|
|
320
|
+
padding: 14px;
|
|
321
|
+
display: flex;
|
|
322
|
+
flex-direction: column;
|
|
323
|
+
gap: 12px;
|
|
324
|
+
}
|
|
325
|
+
.np-modal-desc {
|
|
326
|
+
font-size: 13px;
|
|
327
|
+
opacity: 0.85;
|
|
328
|
+
white-space: pre-wrap;
|
|
329
|
+
}
|
|
330
|
+
.np-modal-field {
|
|
331
|
+
display: flex;
|
|
332
|
+
flex-direction: column;
|
|
333
|
+
gap: 6px;
|
|
334
|
+
}
|
|
335
|
+
.np-modal-label {
|
|
336
|
+
font-size: 12px;
|
|
337
|
+
font-weight: 700;
|
|
338
|
+
opacity: 0.85;
|
|
339
|
+
}
|
|
340
|
+
.np-modal-error {
|
|
341
|
+
font-size: 12px;
|
|
342
|
+
color: #f85149;
|
|
343
|
+
}
|
|
344
|
+
:root[data-theme='dark'] .np-modal-error { color: #ff7b72; }
|
|
345
|
+
.np-modal-actions {
|
|
346
|
+
padding: 12px 14px;
|
|
347
|
+
border-top: 1px solid var(--ds-panel-border);
|
|
348
|
+
display: flex;
|
|
349
|
+
align-items: center;
|
|
350
|
+
justify-content: flex-end;
|
|
351
|
+
gap: 8px;
|
|
352
|
+
}
|
|
353
|
+
.np-btn[data-variant='danger'] { border-color: rgba(248, 81, 73, 0.5); }
|
|
354
|
+
.np-btn[data-variant='danger']:hover { box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.24); }
|
|
355
|
+
`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function tagsToText(tags) {
|
|
2
|
+
return (Array.isArray(tags) ? tags : []).join(', ');
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function parseTags(input) {
|
|
6
|
+
const raw = String(input ?? '');
|
|
7
|
+
const parts = raw
|
|
8
|
+
.split(',')
|
|
9
|
+
.map((p) => p.trim())
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
const out = [];
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
for (const tag of parts) {
|
|
14
|
+
const key = tag.toLowerCase();
|
|
15
|
+
if (seen.has(key)) continue;
|
|
16
|
+
seen.add(key);
|
|
17
|
+
out.push(tag);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { isElement } from './dom.mjs';
|
|
2
|
+
import { NOTEPAD_MANAGER_STYLES } from './styles.mjs';
|
|
3
|
+
|
|
4
|
+
export function createNotepadManagerUi({ container, slots, ctx, bridgeEnabled }) {
|
|
5
|
+
if (!container) throw new Error('container is required');
|
|
6
|
+
|
|
7
|
+
const headerSlot = isElement(slots?.header) ? slots.header : null;
|
|
8
|
+
|
|
9
|
+
const style = document.createElement('style');
|
|
10
|
+
style.textContent = NOTEPAD_MANAGER_STYLES;
|
|
11
|
+
|
|
12
|
+
const root = document.createElement('div');
|
|
13
|
+
root.className = 'np-root';
|
|
14
|
+
root.dataset.editorMode = 'preview';
|
|
15
|
+
root.appendChild(style);
|
|
16
|
+
|
|
17
|
+
const header = document.createElement('div');
|
|
18
|
+
header.className = 'np-header';
|
|
19
|
+
|
|
20
|
+
const headerLeft = document.createElement('div');
|
|
21
|
+
headerLeft.style.display = 'flex';
|
|
22
|
+
headerLeft.style.flexDirection = 'column';
|
|
23
|
+
headerLeft.style.gap = '2px';
|
|
24
|
+
|
|
25
|
+
const title = document.createElement('div');
|
|
26
|
+
title.className = 'np-title';
|
|
27
|
+
title.textContent = '记事本';
|
|
28
|
+
|
|
29
|
+
const meta = document.createElement('div');
|
|
30
|
+
meta.className = 'np-meta';
|
|
31
|
+
meta.textContent = `${ctx?.pluginId || ''}:${ctx?.appId || ''} · bridge=${bridgeEnabled ? 'enabled' : 'disabled'}`;
|
|
32
|
+
|
|
33
|
+
headerLeft.appendChild(title);
|
|
34
|
+
headerLeft.appendChild(meta);
|
|
35
|
+
|
|
36
|
+
const headerRight = document.createElement('div');
|
|
37
|
+
headerRight.style.display = 'flex';
|
|
38
|
+
headerRight.style.alignItems = 'center';
|
|
39
|
+
headerRight.style.gap = '8px';
|
|
40
|
+
headerRight.style.flexWrap = 'wrap';
|
|
41
|
+
|
|
42
|
+
const btnNewFolder = document.createElement('button');
|
|
43
|
+
btnNewFolder.type = 'button';
|
|
44
|
+
btnNewFolder.className = 'np-btn np-btn-icon';
|
|
45
|
+
btnNewFolder.title = '新建文件夹';
|
|
46
|
+
btnNewFolder.setAttribute('aria-label', '新建文件夹');
|
|
47
|
+
const btnNewFolderIcon = document.createElement('span');
|
|
48
|
+
btnNewFolderIcon.className = 'ds-tree-icon ds-tree-icon-new-folder';
|
|
49
|
+
btnNewFolder.appendChild(btnNewFolderIcon);
|
|
50
|
+
|
|
51
|
+
const btnNewNote = document.createElement('button');
|
|
52
|
+
btnNewNote.type = 'button';
|
|
53
|
+
btnNewNote.className = 'np-btn np-btn-icon';
|
|
54
|
+
btnNewNote.title = '新建笔记';
|
|
55
|
+
btnNewNote.setAttribute('aria-label', '新建笔记');
|
|
56
|
+
const btnNewNoteIcon = document.createElement('span');
|
|
57
|
+
btnNewNoteIcon.className = 'ds-tree-icon ds-tree-icon-new-note';
|
|
58
|
+
btnNewNote.appendChild(btnNewNoteIcon);
|
|
59
|
+
|
|
60
|
+
const btnSave = document.createElement('button');
|
|
61
|
+
btnSave.type = 'button';
|
|
62
|
+
btnSave.className = 'np-btn';
|
|
63
|
+
btnSave.textContent = '保存';
|
|
64
|
+
|
|
65
|
+
const btnDelete = document.createElement('button');
|
|
66
|
+
btnDelete.type = 'button';
|
|
67
|
+
btnDelete.className = 'np-btn';
|
|
68
|
+
btnDelete.textContent = '删除';
|
|
69
|
+
|
|
70
|
+
const btnCopy = document.createElement('button');
|
|
71
|
+
btnCopy.type = 'button';
|
|
72
|
+
btnCopy.className = 'np-btn';
|
|
73
|
+
btnCopy.textContent = '复制';
|
|
74
|
+
btnCopy.title = '复制当前笔记内容';
|
|
75
|
+
|
|
76
|
+
const btnToggleEdit = document.createElement('button');
|
|
77
|
+
btnToggleEdit.type = 'button';
|
|
78
|
+
btnToggleEdit.className = 'np-btn';
|
|
79
|
+
btnToggleEdit.textContent = '编辑';
|
|
80
|
+
btnToggleEdit.title = '切换编辑/预览';
|
|
81
|
+
|
|
82
|
+
const statusPill = document.createElement('div');
|
|
83
|
+
statusPill.className = 'np-pill';
|
|
84
|
+
statusPill.dataset.tone = 'bad';
|
|
85
|
+
statusPill.textContent = 'Notes: initializing...';
|
|
86
|
+
|
|
87
|
+
headerRight.appendChild(statusPill);
|
|
88
|
+
|
|
89
|
+
header.appendChild(headerLeft);
|
|
90
|
+
header.appendChild(headerRight);
|
|
91
|
+
|
|
92
|
+
const grid = document.createElement('div');
|
|
93
|
+
grid.className = 'np-grid';
|
|
94
|
+
|
|
95
|
+
const leftCard = document.createElement('div');
|
|
96
|
+
leftCard.className = 'np-card';
|
|
97
|
+
const leftHeader = document.createElement('div');
|
|
98
|
+
leftHeader.className = 'np-card-header';
|
|
99
|
+
leftHeader.textContent = '分类与检索';
|
|
100
|
+
const leftBody = document.createElement('div');
|
|
101
|
+
leftBody.className = 'np-card-body';
|
|
102
|
+
|
|
103
|
+
const createHint = document.createElement('div');
|
|
104
|
+
createHint.className = 'np-meta np-create-hint';
|
|
105
|
+
createHint.textContent = '新笔记将创建在:根目录';
|
|
106
|
+
|
|
107
|
+
const searchInput = document.createElement('input');
|
|
108
|
+
searchInput.className = 'np-input';
|
|
109
|
+
searchInput.type = 'text';
|
|
110
|
+
searchInput.placeholder = '搜索标题/文件夹/内容…';
|
|
111
|
+
|
|
112
|
+
const btnClearSearch = document.createElement('button');
|
|
113
|
+
btnClearSearch.type = 'button';
|
|
114
|
+
btnClearSearch.className = 'np-btn np-btn-icon';
|
|
115
|
+
btnClearSearch.title = '清空搜索';
|
|
116
|
+
btnClearSearch.setAttribute('aria-label', '清空搜索');
|
|
117
|
+
btnClearSearch.textContent = '×';
|
|
118
|
+
|
|
119
|
+
const searchRow = document.createElement('div');
|
|
120
|
+
searchRow.className = 'np-row np-row-compact';
|
|
121
|
+
searchRow.appendChild(searchInput);
|
|
122
|
+
searchRow.appendChild(btnClearSearch);
|
|
123
|
+
|
|
124
|
+
const folderSection = document.createElement('div');
|
|
125
|
+
const folderTitle = document.createElement('div');
|
|
126
|
+
folderTitle.className = 'np-section-title np-section-title-row';
|
|
127
|
+
const folderTitleLabel = document.createElement('div');
|
|
128
|
+
folderTitleLabel.textContent = '笔记';
|
|
129
|
+
const folderTitleActions = document.createElement('div');
|
|
130
|
+
folderTitleActions.className = 'np-section-actions';
|
|
131
|
+
folderTitleActions.appendChild(btnNewNote);
|
|
132
|
+
folderTitleActions.appendChild(btnNewFolder);
|
|
133
|
+
folderTitle.appendChild(folderTitleLabel);
|
|
134
|
+
folderTitle.appendChild(folderTitleActions);
|
|
135
|
+
const folderList = document.createElement('div');
|
|
136
|
+
folderList.className = 'ds-tree';
|
|
137
|
+
folderSection.appendChild(folderTitle);
|
|
138
|
+
folderSection.appendChild(folderList);
|
|
139
|
+
folderSection.appendChild(createHint);
|
|
140
|
+
|
|
141
|
+
const tagSection = document.createElement('div');
|
|
142
|
+
const tagTitle = document.createElement('div');
|
|
143
|
+
tagTitle.className = 'np-section-title';
|
|
144
|
+
tagTitle.textContent = '标签过滤';
|
|
145
|
+
const tagRow = document.createElement('div');
|
|
146
|
+
tagRow.className = 'np-chip-row';
|
|
147
|
+
tagSection.appendChild(tagTitle);
|
|
148
|
+
tagSection.appendChild(tagRow);
|
|
149
|
+
|
|
150
|
+
leftBody.appendChild(searchRow);
|
|
151
|
+
leftBody.appendChild(folderSection);
|
|
152
|
+
|
|
153
|
+
leftCard.appendChild(leftHeader);
|
|
154
|
+
leftCard.appendChild(leftBody);
|
|
155
|
+
|
|
156
|
+
const rightCard = document.createElement('div');
|
|
157
|
+
rightCard.className = 'np-card';
|
|
158
|
+
const rightHeader = document.createElement('div');
|
|
159
|
+
rightHeader.className = 'np-card-header';
|
|
160
|
+
rightHeader.textContent = '';
|
|
161
|
+
const rightHeaderTitle = document.createElement('div');
|
|
162
|
+
rightHeaderTitle.textContent = '编辑与预览';
|
|
163
|
+
const rightHeaderActions = document.createElement('div');
|
|
164
|
+
rightHeaderActions.className = 'np-row';
|
|
165
|
+
rightHeaderActions.appendChild(btnToggleEdit);
|
|
166
|
+
rightHeaderActions.appendChild(btnCopy);
|
|
167
|
+
rightHeaderActions.appendChild(btnSave);
|
|
168
|
+
rightHeaderActions.appendChild(btnDelete);
|
|
169
|
+
rightHeader.appendChild(rightHeaderTitle);
|
|
170
|
+
rightHeader.appendChild(rightHeaderActions);
|
|
171
|
+
const rightBody = document.createElement('div');
|
|
172
|
+
rightBody.className = 'np-card-body';
|
|
173
|
+
|
|
174
|
+
const editorTop = document.createElement('div');
|
|
175
|
+
editorTop.className = 'np-editor-top';
|
|
176
|
+
|
|
177
|
+
const titleInput = document.createElement('input');
|
|
178
|
+
titleInput.className = 'np-input';
|
|
179
|
+
titleInput.type = 'text';
|
|
180
|
+
titleInput.placeholder = '标题';
|
|
181
|
+
|
|
182
|
+
const folderSelect = document.createElement('select');
|
|
183
|
+
folderSelect.className = 'np-select';
|
|
184
|
+
folderSelect.title = '选择文件夹';
|
|
185
|
+
|
|
186
|
+
editorTop.appendChild(titleInput);
|
|
187
|
+
editorTop.appendChild(folderSelect);
|
|
188
|
+
|
|
189
|
+
const editorTopRow = document.createElement('div');
|
|
190
|
+
editorTopRow.className = 'np-editor-top-row';
|
|
191
|
+
|
|
192
|
+
const tagsInput = document.createElement('input');
|
|
193
|
+
tagsInput.className = 'np-input';
|
|
194
|
+
tagsInput.type = 'text';
|
|
195
|
+
tagsInput.placeholder = '标签(逗号分隔)';
|
|
196
|
+
|
|
197
|
+
const infoBox = document.createElement('div');
|
|
198
|
+
infoBox.className = 'np-meta';
|
|
199
|
+
infoBox.style.alignSelf = 'center';
|
|
200
|
+
infoBox.textContent = '未选择笔记';
|
|
201
|
+
|
|
202
|
+
editorTopRow.appendChild(tagsInput);
|
|
203
|
+
editorTopRow.appendChild(infoBox);
|
|
204
|
+
|
|
205
|
+
const split = document.createElement('div');
|
|
206
|
+
split.className = 'np-editor-split';
|
|
207
|
+
|
|
208
|
+
const textarea = document.createElement('textarea');
|
|
209
|
+
textarea.className = 'np-textarea';
|
|
210
|
+
textarea.placeholder = '开始写 Markdown…';
|
|
211
|
+
|
|
212
|
+
const preview = document.createElement('div');
|
|
213
|
+
preview.className = 'np-preview';
|
|
214
|
+
preview.innerHTML = '<div class=\"np-meta\">预览区</div>';
|
|
215
|
+
|
|
216
|
+
split.appendChild(textarea);
|
|
217
|
+
split.appendChild(preview);
|
|
218
|
+
|
|
219
|
+
rightBody.appendChild(editorTop);
|
|
220
|
+
rightBody.appendChild(editorTopRow);
|
|
221
|
+
rightBody.appendChild(split);
|
|
222
|
+
|
|
223
|
+
rightCard.appendChild(rightHeader);
|
|
224
|
+
rightCard.appendChild(rightBody);
|
|
225
|
+
|
|
226
|
+
grid.appendChild(leftCard);
|
|
227
|
+
grid.appendChild(rightCard);
|
|
228
|
+
|
|
229
|
+
if (headerSlot) {
|
|
230
|
+
try {
|
|
231
|
+
headerSlot.textContent = '';
|
|
232
|
+
} catch {
|
|
233
|
+
// ignore
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
headerSlot.appendChild(header);
|
|
237
|
+
} catch {
|
|
238
|
+
root.appendChild(header);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
root.appendChild(header);
|
|
242
|
+
}
|
|
243
|
+
root.appendChild(grid);
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
container.textContent = '';
|
|
247
|
+
} catch {
|
|
248
|
+
// ignore
|
|
249
|
+
}
|
|
250
|
+
container.appendChild(root);
|
|
251
|
+
|
|
252
|
+
const setStatus = (text, tone) => {
|
|
253
|
+
statusPill.textContent = text;
|
|
254
|
+
statusPill.dataset.tone = tone === 'ok' ? 'ok' : 'bad';
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
root,
|
|
259
|
+
header,
|
|
260
|
+
btnNewFolder,
|
|
261
|
+
btnNewNote,
|
|
262
|
+
btnSave,
|
|
263
|
+
btnDelete,
|
|
264
|
+
btnCopy,
|
|
265
|
+
btnToggleEdit,
|
|
266
|
+
statusPill,
|
|
267
|
+
createHint,
|
|
268
|
+
searchInput,
|
|
269
|
+
btnClearSearch,
|
|
270
|
+
folderList,
|
|
271
|
+
tagRow,
|
|
272
|
+
titleInput,
|
|
273
|
+
folderSelect,
|
|
274
|
+
tagsInput,
|
|
275
|
+
infoBox,
|
|
276
|
+
textarea,
|
|
277
|
+
preview,
|
|
278
|
+
setStatus,
|
|
279
|
+
};
|
|
280
|
+
}
|