kreftjs 0.0.0-stage → 0.0.2-beta
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 +103 -2
- package/bin/add.js +1074 -0
- package/bin/artisan-more.js +994 -0
- package/bin/artisan.js +1877 -0
- package/bin/backend/app.js +161 -0
- package/bin/backend/cache.js +196 -0
- package/bin/backend/collection.js +117 -0
- package/bin/backend/command.js +45 -0
- package/bin/backend/config.js +234 -0
- package/bin/backend/error-page.js +773 -0
- package/bin/backend/events.js +49 -0
- package/bin/backend/factory.js +223 -0
- package/bin/backend/fake.js +180 -0
- package/bin/backend/form.js +102 -0
- package/bin/backend/gate.js +79 -0
- package/bin/backend/gc.js +69 -0
- package/bin/backend/html.js +322 -0
- package/bin/backend/http.js +652 -0
- package/bin/backend/index.js +452 -0
- package/bin/backend/mail.js +77 -0
- package/bin/backend/mcp.js +433 -0
- package/bin/backend/migrator.js +370 -0
- package/bin/backend/model.js +781 -0
- package/bin/backend/namespace.js +213 -0
- package/bin/backend/notifications.js +68 -0
- package/bin/backend/qr.js +164 -0
- package/bin/backend/query.js +387 -0
- package/bin/backend/queue.js +412 -0
- package/bin/backend/redis.js +479 -0
- package/bin/backend/schedule.js +112 -0
- package/bin/backend/schema.js +321 -0
- package/bin/backend/seo-pages.js +100 -0
- package/bin/backend/storage.js +153 -0
- package/bin/backend/support.js +567 -0
- package/bin/backend/typescript.js +166 -0
- package/bin/build.js +540 -0
- package/bin/db-api.js +249 -0
- package/bin/db.js +275 -0
- package/bin/deps.js +138 -0
- package/bin/electron.js +509 -0
- package/bin/env.js +97 -0
- package/bin/guard.js +80 -0
- package/bin/kreftjs-config.js +40 -0
- package/bin/kreftjs.js +1373 -0
- package/bin/lang.js +241 -0
- package/bin/layout.js +74 -0
- package/bin/no-auth.js +162 -0
- package/bin/prerender.js +258 -0
- package/bin/safe-json.js +24 -0
- package/bin/server-routes.js +154 -0
- package/bin/ssr.js +133 -0
- package/bin/terminal.js +195 -0
- package/bin/to-ts.js +36 -0
- package/bin/update.js +237 -0
- package/bin/urls-file.js +27 -0
- package/bin/vite.js +228 -0
- package/docs/Docs.kreftjs +557 -0
- package/docs/README.md +2302 -0
- package/docs/markdown.js +186 -0
- package/editors/vscode/README.md +13 -0
- package/editors/vscode/extension.js +183 -0
- package/editors/vscode/language-configuration.json +17 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/snippets/kreftjs.json +21 -0
- package/editors/vscode/syntaxes/kreftjs.tmLanguage.json +207 -0
- package/kreftjs.d.ts +579 -0
- package/kreftjs.js +5108 -0
- package/package.json +97 -4
- package/server.d.ts +1028 -0
- package/server.js +8 -0
- package/templates/app/README.md +127 -0
- package/templates/app/_env.example +64 -0
- package/templates/app/_gitignore +5 -0
- package/templates/app/_vscode/settings.json +9 -0
- package/templates/app/backend/app/Auth/Session.js +177 -0
- package/templates/app/backend/app/Auth/Throttle.js +29 -0
- package/templates/app/backend/app/Console/Commands/.gitkeep +0 -0
- package/templates/app/backend/app/Events/.gitkeep +0 -0
- package/templates/app/backend/app/Http/Controllers/Admin/DashboardController.js +34 -0
- package/templates/app/backend/app/Http/Controllers/Admin/UserController.js +53 -0
- package/templates/app/backend/app/Http/Controllers/Auth/ApiTokenController.js +47 -0
- package/templates/app/backend/app/Http/Controllers/Auth/AuthenticatedSessionController.js +41 -0
- package/templates/app/backend/app/Http/Controllers/Auth/ConfirmablePasswordController.js +14 -0
- package/templates/app/backend/app/Http/Controllers/Auth/EmailVerificationController.js +23 -0
- package/templates/app/backend/app/Http/Controllers/Auth/NewPasswordController.js +29 -0
- package/templates/app/backend/app/Http/Controllers/Auth/PasswordResetLinkController.js +20 -0
- package/templates/app/backend/app/Http/Controllers/Auth/RegisteredUserController.js +19 -0
- package/templates/app/backend/app/Http/Controllers/Auth/SessionController.js +36 -0
- package/templates/app/backend/app/Http/Controllers/Auth/TwoFactorChallengeController.js +41 -0
- package/templates/app/backend/app/Http/Controllers/Auth/TwoFactorController.js +63 -0
- package/templates/app/backend/app/Http/Controllers/ProfileController.js +66 -0
- package/templates/app/backend/app/Http/Kernel.js +8 -0
- package/templates/app/backend/app/Http/Middleware/Authenticate.js +84 -0
- package/templates/app/backend/app/Http/Middleware/CheckAbilities.js +17 -0
- package/templates/app/backend/app/Http/Middleware/CheckForAnyAbility.js +12 -0
- package/templates/app/backend/app/Http/Middleware/EnsureEmailIsVerified.js +11 -0
- package/templates/app/backend/app/Http/Middleware/EnsureHasRole.js +11 -0
- package/templates/app/backend/app/Http/Middleware/EnsureIsAdmin.js +11 -0
- package/templates/app/backend/app/Http/Middleware/RequirePassword.js +15 -0
- package/templates/app/backend/app/Http/Requests/Auth/LoginRequest.js +45 -0
- package/templates/app/backend/app/Http/Resources/.gitkeep +1 -0
- package/templates/app/backend/app/Jobs/.gitkeep +0 -0
- package/templates/app/backend/app/Listeners/.gitkeep +0 -0
- package/templates/app/backend/app/Mail/.gitkeep +0 -0
- package/templates/app/backend/app/Models/PersonalAccessToken.js +21 -0
- package/templates/app/backend/app/Models/User.js +64 -0
- package/templates/app/backend/app/Notifications/.gitkeep +0 -0
- package/templates/app/backend/app/Observers/.gitkeep +0 -0
- package/templates/app/backend/app/Policies/.gitkeep +0 -0
- package/templates/app/backend/app/Providers/AppServiceProvider.js +12 -0
- package/templates/app/backend/app/Rules/.gitkeep +1 -0
- package/templates/app/backend/config/app.js +16 -0
- package/templates/app/backend/config/auth.js +34 -0
- package/templates/app/backend/config/database.js +38 -0
- package/templates/app/backend/config/redis.js +28 -0
- package/templates/app/backend/config/session.js +36 -0
- package/templates/app/backend/database/migrations/0001_01_01_000000_create_users_table.js +49 -0
- package/templates/app/backend/database/migrations/0001_01_01_000001_create_cache_table.js +13 -0
- package/templates/app/backend/database/migrations/0001_01_01_000002_create_jobs_table.js +26 -0
- package/templates/app/backend/database/migrations/0001_01_01_000003_create_notifications_table.js +18 -0
- package/templates/app/backend/database/seeders/DatabaseSeeder.js +15 -0
- package/templates/app/backend/lang/ar/messages.json +10 -0
- package/templates/app/backend/lang/ar/validation.json +21 -0
- package/templates/app/backend/lang/en/messages.json +10 -0
- package/templates/app/backend/lang/en/validation.json +19 -0
- package/templates/app/backend/routes/api.js +25 -0
- package/templates/app/backend/routes/auth.js +52 -0
- package/templates/app/backend/routes/console.js +15 -0
- package/templates/app/frontend/App.kreftjs +4 -0
- package/templates/app/frontend/components/Field.kreftjs +19 -0
- package/templates/app/frontend/components/StatCard.kreftjs +47 -0
- package/templates/app/frontend/components/profile/ApiTokens.kreftjs +70 -0
- package/templates/app/frontend/components/profile/Sessions.kreftjs +42 -0
- package/templates/app/frontend/components/profile/TwoFactor.kreftjs +90 -0
- package/templates/app/frontend/errors/ErrorMonitor.kreftjs +264 -0
- package/templates/app/frontend/index.html +79 -0
- package/templates/app/frontend/kreftjs.d.ts +579 -0
- package/templates/app/frontend/kreftjs.js +5108 -0
- package/templates/app/frontend/layouts/app.kreftjs +718 -0
- package/templates/app/frontend/layouts/docs.kreftjs +37 -0
- package/templates/app/frontend/layouts/guest.kreftjs +18 -0
- package/templates/app/frontend/pages/Dashboard.kreftjs +273 -0
- package/templates/app/frontend/pages/ErrorMonitor.kreftjs +96 -0
- package/templates/app/frontend/pages/Home.kreftjs +617 -0
- package/templates/app/frontend/pages/Profile.kreftjs +104 -0
- package/templates/app/frontend/pages/Users.kreftjs +240 -0
- package/templates/app/frontend/pages/auth/ConfirmPassword.kreftjs +33 -0
- package/templates/app/frontend/pages/auth/ForgotPassword.kreftjs +36 -0
- package/templates/app/frontend/pages/auth/Login.kreftjs +89 -0
- package/templates/app/frontend/pages/auth/Register.kreftjs +48 -0
- package/templates/app/frontend/pages/auth/ResetPassword.kreftjs +45 -0
- package/templates/app/frontend/pages/auth/VerifyEmail.kreftjs +59 -0
- package/templates/app/frontend/routes/web.kreftjs +34 -0
- package/templates/app/frontend/tests/components/Counter.kreftjs +15 -0
- package/templates/app/frontend/tests/pages/About.kreftjs +12 -0
- package/templates/app/frontend/tests/pages/Test.kreftjs +31 -0
- package/templates/app/frontend/ui.css +517 -0
- package/templates/app/lang/ar/auth.json +6 -0
- package/templates/app/lang/ar/messages.json +6 -0
- package/templates/app/lang/ar/pagination.json +5 -0
- package/templates/app/lang/ar/passwords.json +8 -0
- package/templates/app/lang/ar/validation.json +22 -0
- package/templates/app/lang/ar.json +10 -0
- package/templates/app/lang/en/auth.json +6 -0
- package/templates/app/lang/en/messages.json +6 -0
- package/templates/app/lang/en/pagination.json +5 -0
- package/templates/app/lang/en/passwords.json +8 -0
- package/templates/app/lang/en/validation.json +22 -0
- package/templates/app/lang/en.json +10 -0
- package/templates/errors/401.kreftjs +11 -0
- package/templates/errors/402.kreftjs +11 -0
- package/templates/errors/403.kreftjs +11 -0
- package/templates/errors/404.kreftjs +11 -0
- package/templates/errors/419.kreftjs +11 -0
- package/templates/errors/429.kreftjs +11 -0
- package/templates/errors/500.kreftjs +11 -0
- package/templates/errors/503.kreftjs +11 -0
- package/templates/errors/ErrorMonitor.kreftjs +502 -0
- package/templates/errors/error.kreftjs +11 -0
- package/templates/errors/minimal.kreftjs +25 -0
- package/tools/dev-client.js +125 -0
- package/tools/devtools.js +172 -0
- package/tools/vite-plugin-kreftjs.d.ts +52 -0
- package/tools/vite-plugin-kreftjs.js +466 -0
package/docs/markdown.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// A small Markdown reader for the documentation page: headings, paragraphs, lists, tables,
|
|
2
|
+
// code blocks, quotes, links, **bold**, *italic* and `code`. Everything is escaped first,
|
|
3
|
+
// so a .md file can't put its own scripts on the page.
|
|
4
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
5
|
+
|
|
6
|
+
export function slug(text) {
|
|
7
|
+
return text.toLowerCase().replace(/<[^>]+>/g, '').replace(/[`*]/g, '').trim()
|
|
8
|
+
.replace(/[^\p{L}\p{M}\p{N}\s-]/gu, '').replace(/\s/g, '-');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function inline(text) {
|
|
12
|
+
const codes = [];
|
|
13
|
+
let s = text.replace(/`([^`]+)`/g, (_, c) => { codes.push(c); return `\u0000${codes.length - 1}\u0000`; });
|
|
14
|
+
s = esc(s)
|
|
15
|
+
.replace(/<kbd>(.*?)<\/kbd>/g, '<kbd>$1</kbd>')
|
|
16
|
+
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
17
|
+
.replace(/(^|[^\w*])\*([^*\s][^*]*?)\*(?!\w)/g, '$1<em>$2</em>')
|
|
18
|
+
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, label, href) => {
|
|
19
|
+
// only safe URLs: http/https, page anchors, or safe relative paths (no protocol-relative // or javascript:)
|
|
20
|
+
let safe = '#';
|
|
21
|
+
if (/^https?:\/\/[^\s"'<>]+$/i.test(href)) safe = href;
|
|
22
|
+
else if (/^#[a-z0-9_\u0080-\uffff-]+$/i.test(href)) safe = href;
|
|
23
|
+
else if (/^(?!\/\/)(?:\.{0,2}\/)?[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*(?:#[a-z0-9_\u0080-\uffff-]+)?$/i.test(href)) safe = href;
|
|
24
|
+
return `<a href="${esc(safe)}"${/^https?:/i.test(safe) ? ' target="_blank" rel="noopener noreferrer"' : ''}>${label}</a>`;
|
|
25
|
+
});
|
|
26
|
+
return s.replace(/\u0000(\d+)\u0000/g, (_, i) => `<code>${esc(codes[i])}</code>`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function markdown(source) {
|
|
30
|
+
const lines = source.replace(/\r\n?/g, '\n').split('\n');
|
|
31
|
+
const out = [], toc = [], sections = [], parts = [], usedIds = new Map();
|
|
32
|
+
let currentPart = null;
|
|
33
|
+
let i = 0;
|
|
34
|
+
let currentSection = null;
|
|
35
|
+
let currentH2Id = null;
|
|
36
|
+
let currentH2Title = null;
|
|
37
|
+
let totalWords = 0;
|
|
38
|
+
|
|
39
|
+
const addTextToCurrent = (txt) => {
|
|
40
|
+
if (!txt) return;
|
|
41
|
+
const clean = txt.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
42
|
+
if (!clean) return;
|
|
43
|
+
totalWords += clean.split(/\s+/).length;
|
|
44
|
+
if (currentSection) {
|
|
45
|
+
if (currentSection.content.length < 1500) {
|
|
46
|
+
currentSection.content += (currentSection.content ? ' ' : '') + clean;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const isBlockStart = (l) => /^(#{1,6}\s|```|>|\s*[-*]\s|\s*\d+\.\s|\||---\s*$)/.test(l);
|
|
52
|
+
while (i < lines.length) {
|
|
53
|
+
const line = lines[i];
|
|
54
|
+
if (!line.trim()) { i++; continue; }
|
|
55
|
+
let m;
|
|
56
|
+
if ((m = line.match(/^(#{1,6})\s+(.*)$/))) {
|
|
57
|
+
const level = m[1].length, text = m[2];
|
|
58
|
+
let id = slug(text);
|
|
59
|
+
// the same heading text twice (two "Example" sections) must not share an id
|
|
60
|
+
const seen = usedIds.get(id) || 0;
|
|
61
|
+
usedIds.set(id, seen + 1);
|
|
62
|
+
if (seen) id = `${id}-${seen + 1}`;
|
|
63
|
+
const cleanTitle = text.replace(/[`*]/g, '').trim();
|
|
64
|
+
const item = {
|
|
65
|
+
level,
|
|
66
|
+
id,
|
|
67
|
+
text: cleanTitle,
|
|
68
|
+
title: cleanTitle,
|
|
69
|
+
parentId: level === 3 && currentH2Id ? currentH2Id : null,
|
|
70
|
+
parentTitle: level === 3 && currentH2Title ? currentH2Title : null,
|
|
71
|
+
group: currentPart ? currentPart.title : '',
|
|
72
|
+
content: '',
|
|
73
|
+
};
|
|
74
|
+
if (level === 1) {
|
|
75
|
+
// a "part" of the manual (Start here, Backend…): it groups the chapters that follow
|
|
76
|
+
currentPart = { id, title: cleanTitle, items: [] };
|
|
77
|
+
parts.push(currentPart);
|
|
78
|
+
}
|
|
79
|
+
if (level === 2 || level === 3) {
|
|
80
|
+
toc.push(item);
|
|
81
|
+
sections.push(item);
|
|
82
|
+
if (level === 2 && currentPart) currentPart.items.push(item);
|
|
83
|
+
currentSection = item;
|
|
84
|
+
if (level === 2) {
|
|
85
|
+
currentH2Id = id;
|
|
86
|
+
currentH2Title = cleanTitle;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
out.push(`<h${level} id="${esc(id)}" class="doc-heading doc-h${level}" data-id="${esc(id)}"><a href="#${esc(id)}" class="heading-anchor" aria-label="Link to section">#</a><span class="heading-title">${inline(text)}</span></h${level}>`);
|
|
90
|
+
i++; continue;
|
|
91
|
+
}
|
|
92
|
+
if ((m = line.match(/^```(\w*)/))) {
|
|
93
|
+
const lang = m[1], body = [];
|
|
94
|
+
i++;
|
|
95
|
+
while (i < lines.length && !/^```\s*$/.test(lines[i])) body.push(lines[i++]);
|
|
96
|
+
i++;
|
|
97
|
+
const codeStr = body.join('\n');
|
|
98
|
+
addTextToCurrent(codeStr);
|
|
99
|
+
out.push(
|
|
100
|
+
`<div class="code-box" data-lang="${esc(lang || 'code')}">` +
|
|
101
|
+
`<div class="code-head"><span class="code-lang">${esc((lang || 'code').toUpperCase())}</span><button type="button" class="copy-btn" data-action="copy" aria-label="Copy code block">Copy</button></div>` +
|
|
102
|
+
`<pre dir="ltr"${lang ? ` data-lang="${esc(lang)}"` : ''}><code>${esc(codeStr)}</code></pre>` +
|
|
103
|
+
`</div>`
|
|
104
|
+
);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (/^---\s*$/.test(line)) { out.push('<hr>'); i++; continue; }
|
|
108
|
+
if (/^\|/.test(line)) {
|
|
109
|
+
const rows = [];
|
|
110
|
+
while (i < lines.length && /^\|/.test(lines[i])) rows.push(lines[i++]);
|
|
111
|
+
const cells = (r) => r.replace(/^\||\|\s*$/g, '').split(/(?<!\\)\|/).map((c) => inline(c.trim().replace(/\\\|/g, '|')));
|
|
112
|
+
const head = cells(rows[0]);
|
|
113
|
+
const body = rows.slice(/^\|[\s:|-]+\|?\s*$/.test(rows[1] || '') ? 2 : 1).map(cells);
|
|
114
|
+
addTextToCurrent(head.join(' '));
|
|
115
|
+
out.push(`<div class="table"><table><thead><tr>${head.map((c) => `<th>${c}</th>`).join('')}</tr></thead><tbody>${body.map((r) => `<tr>${r.map((c) => `<td>${c}</td>`).join('')}</tr>`).join('')}</tbody></table></div>`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (/^>/.test(line)) {
|
|
119
|
+
const body = [];
|
|
120
|
+
while (i < lines.length && /^>/.test(lines[i])) body.push(lines[i++].replace(/^>\s?/, ''));
|
|
121
|
+
const quoteText = body.join(' ');
|
|
122
|
+
addTextToCurrent(quoteText);
|
|
123
|
+
// > [!NOTE] / [!TIP] / [!WARNING] / [!DANGER] / [!IMPORTANT] makes a labelled callout box
|
|
124
|
+
const call = quoteText.match(/^\[!(NOTE|TIP|WARNING|DANGER|IMPORTANT)\]\s*(.*)$/i);
|
|
125
|
+
if (call) {
|
|
126
|
+
const kind = call[1].toLowerCase();
|
|
127
|
+
out.push(`<aside class="callout callout-${kind}" role="note"><p class="callout-title">${kind.charAt(0).toUpperCase() + kind.slice(1)}</p><p>${inline(call[2])}</p></aside>`);
|
|
128
|
+
} else out.push(`<blockquote>${inline(quoteText)}</blockquote>`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if ((m = line.match(/^(\s*)([-*]|\d+\.)\s+/))) {
|
|
132
|
+
const ordered = /\d/.test(m[2]);
|
|
133
|
+
const items = [];
|
|
134
|
+
while (i < lines.length && /^\s*([-*]|\d+\.)\s+/.test(lines[i])) {
|
|
135
|
+
let item = lines[i++].replace(/^\s*([-*]|\d+\.)\s+/, '');
|
|
136
|
+
while (i < lines.length && lines[i].trim() && /^\s{2,}\S/.test(lines[i]) && !/^\s*([-*]|\d+\.)\s+/.test(lines[i]) && !/^\s*```/.test(lines[i])) item += ' ' + lines[i++].trim();
|
|
137
|
+
items.push(inline(item));
|
|
138
|
+
addTextToCurrent(item);
|
|
139
|
+
// more of the same item, indented under it (after blank lines too): text or a code block
|
|
140
|
+
for (;;) {
|
|
141
|
+
let j = i;
|
|
142
|
+
while (j < lines.length && !lines[j].trim()) j++;
|
|
143
|
+
const next = lines[j];
|
|
144
|
+
if (next === undefined || !/^\s{2,}\S/.test(next) || /^\s*([-*]|\d+\.)\s+/.test(next)) break;
|
|
145
|
+
i = j;
|
|
146
|
+
if (/^\s+```/.test(next)) {
|
|
147
|
+
const indent = next.match(/^\s*/)[0].length, body = [];
|
|
148
|
+
i++;
|
|
149
|
+
while (i < lines.length && !/^\s*```\s*$/.test(lines[i])) body.push(lines[i++].slice(indent));
|
|
150
|
+
i++;
|
|
151
|
+
const snippet = body.join('\n');
|
|
152
|
+
addTextToCurrent(snippet);
|
|
153
|
+
items[items.length - 1] += `<pre dir="ltr"><code>${esc(snippet)}</code></pre>`;
|
|
154
|
+
} else {
|
|
155
|
+
const para = [];
|
|
156
|
+
while (i < lines.length && /^\s{2,}\S/.test(lines[i]) && !/^\s*([-*]|\d+\.)\s+/.test(lines[i]) && !/^\s+```/.test(lines[i])) para.push(lines[i++].trim());
|
|
157
|
+
const textPara = para.join(' ');
|
|
158
|
+
addTextToCurrent(textPara);
|
|
159
|
+
items[items.length - 1] += `<p>${inline(textPara)}</p>`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
while (i < lines.length && !lines[i].trim() && /^\s*([-*]|\d+\.)\s+/.test(lines[i + 1] || '')) i++;
|
|
163
|
+
}
|
|
164
|
+
const tag = ordered ? 'ol' : 'ul';
|
|
165
|
+
out.push(`<${tag}>${items.map((x) => `<li>${x}</li>`).join('')}</${tag}>`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const para = [line];
|
|
169
|
+
i++;
|
|
170
|
+
while (i < lines.length && lines[i].trim() && !isBlockStart(lines[i])) para.push(lines[i++]);
|
|
171
|
+
const pText = para.join(' ');
|
|
172
|
+
addTextToCurrent(pText);
|
|
173
|
+
out.push(`<p>${inline(pText)}</p>`);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
html: out.join('\n'),
|
|
177
|
+
toc,
|
|
178
|
+
parts,
|
|
179
|
+
sections,
|
|
180
|
+
stats: {
|
|
181
|
+
words: totalWords,
|
|
182
|
+
readTimeMinutes: Math.max(1, Math.ceil(totalWords / 200)),
|
|
183
|
+
totalSections: toc.length,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Kreft for VS Code
|
|
2
|
+
|
|
3
|
+
Colors, bracket matching, comments (Ctrl+/), folding and snippets for `.kreftjs` files.
|
|
4
|
+
|
|
5
|
+
Install from a Kreft project or the Kreft folder:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
kreftjs vscode
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then restart VS Code. Type `kreftjs` in an empty `.kreftjs` file for a starter component, or `state`, `action`, `for`, `kreft-wait` …
|
|
12
|
+
|
|
13
|
+
Files from older projects (`.kreft`, and `.som` from Som.js) get the same colors. Both `s-` and `k-` directives, and both `<som-…>` and `<kreft-…>` tags, are highlighted.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
let vscode;
|
|
2
|
+
try {
|
|
3
|
+
vscode = require('vscode');
|
|
4
|
+
} catch {}
|
|
5
|
+
|
|
6
|
+
function formatKreft(text, options = {}) {
|
|
7
|
+
const tabSize = options.tabSize || 2;
|
|
8
|
+
const indentStr = options.insertSpaces !== false ? ' '.repeat(tabSize) : '\t';
|
|
9
|
+
|
|
10
|
+
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
|
11
|
+
const result = [];
|
|
12
|
+
|
|
13
|
+
let inView = false;
|
|
14
|
+
let inStyle = false;
|
|
15
|
+
let inScriptTag = false;
|
|
16
|
+
let viewIndent = 0;
|
|
17
|
+
let scriptBraceDepth = 0;
|
|
18
|
+
let styleBraceDepth = 0;
|
|
19
|
+
|
|
20
|
+
const VOID_TAGS = new Set([
|
|
21
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
22
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr'
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < lines.length; i++) {
|
|
26
|
+
const rawLine = lines[i];
|
|
27
|
+
const trimmed = rawLine.trim();
|
|
28
|
+
|
|
29
|
+
if (!trimmed) {
|
|
30
|
+
if (result.length > 0 && result[result.length - 1] !== '') {
|
|
31
|
+
result.push('');
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (/^<view(\s[^>]*)?>/i.test(trimmed)) {
|
|
37
|
+
inView = true;
|
|
38
|
+
viewIndent = 1;
|
|
39
|
+
result.push(trimmed);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (/^<\/view>/i.test(trimmed)) {
|
|
43
|
+
inView = false;
|
|
44
|
+
viewIndent = 0;
|
|
45
|
+
result.push('</view>');
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (/^<style(\s[^>]*)?>/i.test(trimmed)) {
|
|
49
|
+
inStyle = true;
|
|
50
|
+
styleBraceDepth = 0;
|
|
51
|
+
result.push(trimmed);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (/^<\/style>/i.test(trimmed)) {
|
|
55
|
+
inStyle = false;
|
|
56
|
+
result.push('</style>');
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (/^<script(\s[^>]*)?>/i.test(trimmed)) {
|
|
60
|
+
inScriptTag = true;
|
|
61
|
+
scriptBraceDepth = 0;
|
|
62
|
+
result.push(trimmed);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (/^<\/script>/i.test(trimmed)) {
|
|
66
|
+
inScriptTag = false;
|
|
67
|
+
result.push('</script>');
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (inView) {
|
|
72
|
+
const startsWithCloseTag = /^<\/[A-Za-z0-9_-]+>/.test(trimmed);
|
|
73
|
+
const startsWithCloseLoop = /^\{\/(?:for|if)\}/.test(trimmed);
|
|
74
|
+
const startsWithEmpty = /^\{empty\}/.test(trimmed);
|
|
75
|
+
|
|
76
|
+
if (startsWithCloseTag || startsWithCloseLoop || startsWithEmpty) {
|
|
77
|
+
viewIndent = Math.max(1, viewIndent - 1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
result.push(indentStr.repeat(viewIndent) + trimmed);
|
|
81
|
+
|
|
82
|
+
if (startsWithEmpty) {
|
|
83
|
+
viewIndent++;
|
|
84
|
+
} else {
|
|
85
|
+
const tagRegex = /<([A-Za-z0-9_-]+)(?:\s[^>]*)?(\/?)>|<\/([A-Za-z0-9_-]+)>|\{(for\b[^}]*|\/for|empty)\}/gi;
|
|
86
|
+
let openCount = 0;
|
|
87
|
+
let closeCount = 0;
|
|
88
|
+
|
|
89
|
+
const tagTokens = [...trimmed.matchAll(tagRegex)];
|
|
90
|
+
for (const t of tagTokens) {
|
|
91
|
+
if (t[0].startsWith('</')) {
|
|
92
|
+
closeCount++;
|
|
93
|
+
} else if (t[4] === '/for') {
|
|
94
|
+
closeCount++;
|
|
95
|
+
} else if (t[4] === 'empty') {
|
|
96
|
+
// no net change
|
|
97
|
+
} else if (t[4] && t[4].startsWith('for')) {
|
|
98
|
+
openCount++;
|
|
99
|
+
} else if (t[1]) {
|
|
100
|
+
const tagName = t[1].toLowerCase();
|
|
101
|
+
const isSelfClosing = t[2] === '/' || VOID_TAGS.has(tagName);
|
|
102
|
+
if (!isSelfClosing) openCount++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const netChange = openCount - closeCount;
|
|
107
|
+
if (!startsWithCloseTag && !startsWithCloseLoop) {
|
|
108
|
+
viewIndent = Math.max(1, viewIndent + netChange);
|
|
109
|
+
} else {
|
|
110
|
+
viewIndent = Math.max(1, viewIndent + openCount);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (inStyle) {
|
|
117
|
+
const startsWithClosingBrace = /^\}/.test(trimmed);
|
|
118
|
+
if (startsWithClosingBrace) styleBraceDepth = Math.max(0, styleBraceDepth - 1);
|
|
119
|
+
|
|
120
|
+
result.push(indentStr.repeat(styleBraceDepth) + trimmed);
|
|
121
|
+
|
|
122
|
+
const openBraces = (trimmed.match(/\{/g) || []).length;
|
|
123
|
+
const closeBraces = (trimmed.match(/\}/g) || []).length;
|
|
124
|
+
if (!startsWithClosingBrace) {
|
|
125
|
+
styleBraceDepth = Math.max(0, styleBraceDepth + (openBraces - closeBraces));
|
|
126
|
+
} else {
|
|
127
|
+
styleBraceDepth = Math.max(0, styleBraceDepth + openBraces);
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Top-level script section (outside view and style)
|
|
133
|
+
const startsWithClosingBrace = /^[\}\]\)]/.test(trimmed);
|
|
134
|
+
if (startsWithClosingBrace) {
|
|
135
|
+
scriptBraceDepth = Math.max(0, scriptBraceDepth - 1);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let formattedLine = trimmed;
|
|
139
|
+
// Normalize spacing on single-line declaration keywords
|
|
140
|
+
const declMatch = trimmed.match(/^(state|prop|saved|derive|load|use|share)\s+([A-Za-z_$][\w$]*)\s*=\s*(.*)$/);
|
|
141
|
+
if (declMatch) {
|
|
142
|
+
formattedLine = `${declMatch[1]} ${declMatch[2]} = ${declMatch[3]}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Format action/when/watch opening braces with consistent space before brace
|
|
146
|
+
formattedLine = formattedLine.replace(/^(\s*action\s+[A-Za-z_$][\w$]*\s*(?:\([^)]*\))?)\s*\{/, '$1 {');
|
|
147
|
+
formattedLine = formattedLine.replace(/^(\s*(?:when|watch|on\s+\w+)\s*[^{]*?)\s*\{/, '$1 {');
|
|
148
|
+
|
|
149
|
+
result.push(indentStr.repeat(scriptBraceDepth) + formattedLine);
|
|
150
|
+
|
|
151
|
+
const openBraces = (trimmed.match(/[\{\[\(]/g) || []).length;
|
|
152
|
+
const closeBraces = (trimmed.match(/[\}\]\)]/g) || []).length;
|
|
153
|
+
if (!startsWithClosingBrace) {
|
|
154
|
+
scriptBraceDepth = Math.max(0, scriptBraceDepth + (openBraces - closeBraces));
|
|
155
|
+
} else {
|
|
156
|
+
scriptBraceDepth = Math.max(0, scriptBraceDepth + openBraces);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return result.join('\n') + '\n';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function activate(context) {
|
|
164
|
+
if (!vscode || !vscode.languages) return;
|
|
165
|
+
|
|
166
|
+
const provider = vscode.languages.registerDocumentFormattingEditProvider('kreftjs', {
|
|
167
|
+
provideDocumentFormattingEdits(document, options) {
|
|
168
|
+
const text = document.getText();
|
|
169
|
+
const formatted = formatKreft(text, options);
|
|
170
|
+
if (formatted === text) return [];
|
|
171
|
+
const firstLine = document.lineAt(0);
|
|
172
|
+
const lastLine = document.lineAt(document.lineCount - 1);
|
|
173
|
+
const fullRange = new vscode.Range(firstLine.range.start, lastLine.range.end);
|
|
174
|
+
return [vscode.TextEdit.replace(fullRange, formatted)];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
context.subscriptions.push(provider);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function deactivate() {}
|
|
182
|
+
|
|
183
|
+
module.exports = { activate, deactivate, formatKreft };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"comments": { "lineComment": "//", "blockComment": ["/*", "*/"] },
|
|
3
|
+
"brackets": [["{", "}"], ["[", "]"], ["(", ")"], ["<", ">"]],
|
|
4
|
+
"autoClosingPairs": [
|
|
5
|
+
{ "open": "{", "close": "}" }, { "open": "[", "close": "]" }, { "open": "(", "close": ")" },
|
|
6
|
+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
|
|
7
|
+
{ "open": "\"", "close": "\"", "notIn": ["string"] },
|
|
8
|
+
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
|
|
9
|
+
{ "open": "<!--", "close": "-->", "notIn": ["comment", "string"] }
|
|
10
|
+
],
|
|
11
|
+
"surroundingPairs": [["{", "}"], ["[", "]"], ["(", ")"], ["'", "'"], ["\"", "\""], ["`", "`"], ["<", ">"]],
|
|
12
|
+
"folding": { "markers": { "start": "^\\s*<(view|style)\\b", "end": "^\\s*</(view|style)>" } },
|
|
13
|
+
"indentationRules": {
|
|
14
|
+
"increaseIndentPattern": "(\\{[^}\"'`]*$)|(<(?!(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\\b)[a-zA-Z][\\w-]*(?:\\s[^>]*)?>\\s*$)",
|
|
15
|
+
"decreaseIndentPattern": "^\\s*(\\}|</[a-zA-Z][\\w-]*>)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kreftjs",
|
|
3
|
+
"displayName": "Kreft (.kreftjs files)",
|
|
4
|
+
"description": "Colors, brackets, formatting and snippets for Kreft .kreftjs component files (and .kreft and .som files from older projects).",
|
|
5
|
+
"version": "2.3.0",
|
|
6
|
+
"publisher": "kreft",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"vscode": "^1.60.0"
|
|
10
|
+
},
|
|
11
|
+
"categories": [
|
|
12
|
+
"Programming Languages",
|
|
13
|
+
"Formatters",
|
|
14
|
+
"Snippets"
|
|
15
|
+
],
|
|
16
|
+
"main": "./extension.js",
|
|
17
|
+
"activationEvents": [
|
|
18
|
+
"onLanguage:kreftjs"
|
|
19
|
+
],
|
|
20
|
+
"contributes": {
|
|
21
|
+
"languages": [
|
|
22
|
+
{
|
|
23
|
+
"id": "kreftjs",
|
|
24
|
+
"aliases": [
|
|
25
|
+
"Kreft",
|
|
26
|
+
"kreftjs"
|
|
27
|
+
],
|
|
28
|
+
"extensions": [
|
|
29
|
+
".kreftjs",
|
|
30
|
+
".kreft",
|
|
31
|
+
".som"
|
|
32
|
+
],
|
|
33
|
+
"configuration": "./language-configuration.json"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"grammars": [
|
|
37
|
+
{
|
|
38
|
+
"language": "kreftjs",
|
|
39
|
+
"scopeName": "source.kreftjs",
|
|
40
|
+
"path": "./syntaxes/kreftjs.tmLanguage.json",
|
|
41
|
+
"embeddedLanguages": {
|
|
42
|
+
"meta.embedded.block.html": "html",
|
|
43
|
+
"source.css": "css",
|
|
44
|
+
"meta.embedded.expression.kreftjs": "javascript",
|
|
45
|
+
"meta.embedded.block.javascript": "javascript",
|
|
46
|
+
"source.js": "javascript"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"snippets": [
|
|
51
|
+
{
|
|
52
|
+
"language": "kreftjs",
|
|
53
|
+
"path": "./snippets/kreftjs.json"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Component": {
|
|
3
|
+
"prefix": "kreftjs",
|
|
4
|
+
"body": ["state ${1:count} = ${2:0}", "", "action ${3:add}() {", " ${1:count}++", "}", "", "<view>", " <button @click={${3:add}}>{${1:count}}</button>", "</view>", "", "<style scoped>", " $0", "</style>"],
|
|
5
|
+
"description": "A new .kreftjs component"
|
|
6
|
+
},
|
|
7
|
+
"state": { "prefix": "state", "body": "state ${1:name} = ${2:0}", "description": "A value the view follows" },
|
|
8
|
+
"saved": { "prefix": "saved", "body": "saved ${1:name} = ${2:[]}", "description": "A value kept after a reload (localStorage)" },
|
|
9
|
+
"derive": { "prefix": "derive", "body": "derive ${1:name} = ${2:expression}", "description": "A value worked out from others" },
|
|
10
|
+
"load": { "prefix": "load", "body": "load ${1:posts} = api.get('${2:/api/posts}')", "description": "Load data: .data, .loading, .error" },
|
|
11
|
+
"action": { "prefix": "action", "body": ["action ${1:name}(${2}) {", " $0", "}"], "description": "A function the view can call" },
|
|
12
|
+
"when": { "prefix": "when", "body": ["when ${1:condition} {", " $0", "}"], "description": "Run when a condition becomes true" },
|
|
13
|
+
"watch": { "prefix": "watch", "body": ["watch ${1:value} {", " $0", "}"], "description": "Run when a value changes (value, old)" },
|
|
14
|
+
"on": { "prefix": "on", "body": ["on ${1|start,ready,update,show,hide,destroy|} {", " $0", "}"], "description": "Lifecycle" },
|
|
15
|
+
"layout": { "prefix": "layout", "body": "layout ${1:app}", "description": "This page goes inside layouts/<name>.kreftjs (layout none: no layout)" },
|
|
16
|
+
"section": { "prefix": "kreft-section", "body": ["<kreft-section name=\"${1:actions}\">", " $0", "</kreft-section>"], "description": "Content for the layout's <kreft-yield name>" },
|
|
17
|
+
"yield": { "prefix": "kreft-yield", "body": "<kreft-yield name=\"${1:actions}\">${0}</kreft-yield>", "description": "In a layout: where a page's <kreft-section> goes" },
|
|
18
|
+
"for": { "prefix": "for", "body": ["{for ${1:item} in ${2:items} key ${1:item}.id}", " $0", "{empty}", " <p>Nothing yet.</p>", "{/for}"], "description": "Loop over a list" },
|
|
19
|
+
"k-if": { "prefix": "k-if", "body": "k-if={${1:condition}}", "description": "Show only when true" },
|
|
20
|
+
"kreft-wait": { "prefix": "kreft-wait", "body": ["<kreft-wait>", " $0", " <p k-waiting>Loading…</p>", " <p k-failed=\"error\">Could not load: {error.message}</p>", "</kreft-wait>"], "description": "Show something until everything inside has loaded" }
|
|
21
|
+
}
|