kintone-plugin-ide 0.3.0 → 0.3.1
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/LICENSE +21 -21
- package/README.md +123 -123
- package/dist/index.js +1 -1
- package/dist/kintone-plugin-ide.iife.js +1 -1
- package/package.json +59 -59
- package/src/build/build.js +87 -87
- package/src/build/http-plugin.js +32 -32
- package/src/build/transformers.js +168 -168
- package/src/build/vfs-plugin.js +60 -60
- package/src/config.js +58 -58
- package/src/deps.js +41 -41
- package/src/ide/actions/misc.js +74 -74
- package/src/ide/actions/npm.js +103 -103
- package/src/ide/actions/release.js +57 -57
- package/src/ide/actions/save.js +54 -54
- package/src/ide/actions/zip.js +59 -59
- package/src/ide/commands.js +96 -96
- package/src/ide/css.js +50 -50
- package/src/ide/dialog.js +51 -51
- package/src/ide/editor.js +155 -155
- package/src/ide/index.js +94 -94
- package/src/ide/layout.js +89 -89
- package/src/ide/sample.js +168 -168
- package/src/ide/state.js +58 -58
- package/src/ide/terminal.js +57 -57
- package/src/ide/tree.js +224 -224
- package/src/ide/workspace-fs.js +173 -173
- package/src/index.js +48 -48
- package/src/kintone/api.js +24 -24
- package/src/kintone/plugin.js +37 -37
- package/src/npm/registry.js +32 -32
- package/src/npm/vendor.js +69 -69
- package/src/packer/packer.js +50 -50
- package/src/util/bytes.js +15 -15
- package/src/util/dom.js +15 -15
- package/src/util/idb.js +18 -18
- package/src/util/path.js +14 -14
- package/src/util/settings.js +5 -5
- package/types/index.d.ts +49 -49
package/src/ide/index.js
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
// IDE を組み立てる。各部品は ctx(共有の入れ物)に自分の関数を足していく
|
|
2
|
-
import { F } from '../config.js';
|
|
3
|
-
import { api } from '../kintone/api.js';
|
|
4
|
-
import { canInstall } from '../kintone/api.js';
|
|
5
|
-
import { loadSettings } from '../util/settings.js';
|
|
6
|
-
import { createState, readSources } from './state.js';
|
|
7
|
-
import { setupDialog } from './dialog.js';
|
|
8
|
-
import { setupLayout } from './layout.js';
|
|
9
|
-
import { setupTerminal } from './terminal.js';
|
|
10
|
-
import { setupTree } from './tree.js';
|
|
11
|
-
import { setupEditor } from './editor.js';
|
|
12
|
-
import { setupSave } from './actions/save.js';
|
|
13
|
-
import { setupRelease } from './actions/release.js';
|
|
14
|
-
import { setupZip } from './actions/zip.js';
|
|
15
|
-
import { setupNpm } from './actions/npm.js';
|
|
16
|
-
import { setupMisc } from './actions/misc.js';
|
|
17
|
-
import { setupCommands } from './commands.js';
|
|
18
|
-
import { SAMPLE } from './sample.js';
|
|
19
|
-
|
|
20
|
-
export async function openIDE() {
|
|
21
|
-
if (document.querySelector('.kpi-root')) return;
|
|
22
|
-
const appId = kintone.app.getId();
|
|
23
|
-
const recordId = kintone.app.record.getId();
|
|
24
|
-
const ctx = {
|
|
25
|
-
appId, recordId,
|
|
26
|
-
draftKey: `kintone-plugin-ide:draft:${location.host}:${appId}:${recordId}`,
|
|
27
|
-
settings: loadSettings(),
|
|
28
|
-
problems: { errors: 0, warnings: 0 },
|
|
29
|
-
savedOnce: false,
|
|
30
|
-
current: null,
|
|
31
|
-
// ターミナルができるまではコンソールに出す
|
|
32
|
-
log: Object.fromEntries(['info', 'ok', 'warn', 'error', 'plain'].map((k) => [k, (t) => console.log(`[IDE ${k}]`, t)])),
|
|
33
|
-
};
|
|
34
|
-
ctx.loadRecord = async () => (await api('/k/v1/record.json', 'GET', { app: appId, id: recordId })).record;
|
|
35
|
-
ctx.record = await ctx.loadRecord();
|
|
36
|
-
const sources = await readSources(ctx.record);
|
|
37
|
-
ctx.state = createState(sources);
|
|
38
|
-
ctx.testApp = () => Number(ctx.record[F.testApp] && ctx.record[F.testApp].value) || 0;
|
|
39
|
-
ctx.pluginIdValue = () => ctx.record[F.id] && ctx.record[F.id].value;
|
|
40
|
-
ctx.manifestInfo = () => { try { const m = JSON.parse(ctx.state.files.get('manifest.json')); return { name: m.name.ja || m.name.en, version: m.version }; } catch { return null; } };
|
|
41
|
-
|
|
42
|
-
setupLayout(ctx);
|
|
43
|
-
setupDialog(ctx);
|
|
44
|
-
setupCommands(ctx);
|
|
45
|
-
await setupTerminal(ctx);
|
|
46
|
-
await setupTree(ctx);
|
|
47
|
-
setupSave(ctx);
|
|
48
|
-
await setupEditor(ctx);
|
|
49
|
-
setupRelease(ctx);
|
|
50
|
-
setupZip(ctx);
|
|
51
|
-
setupNpm(ctx);
|
|
52
|
-
setupMisc(ctx);
|
|
53
|
-
|
|
54
|
-
// ---- 閉じる ----
|
|
55
|
-
const onKey = (e) => {
|
|
56
|
-
if (e.key === 'Escape' && !document.querySelector('.kpi-menu, .kpi-dialog') && !ctx.ui.termEl.contains(document.activeElement) && !ctx.isDiffOpen()) ctx.close();
|
|
57
|
-
};
|
|
58
|
-
const guard = (e) => { if (ctx.state.dirty().length) { e.preventDefault(); e.returnValue = ''; } };
|
|
59
|
-
ctx.close = async () => {
|
|
60
|
-
if (ctx.state.dirty().length && !(await ctx.confirm('保存していない変更があります', '閉じても、下書きはこのブラウザに残ります', { ok: '閉じる' }))) return;
|
|
61
|
-
ctx.disposeTerminal(); ctx.disposeEditor(); ctx.closeMenu();
|
|
62
|
-
ctx.tree.cleanUp?.();
|
|
63
|
-
window.removeEventListener('beforeunload', guard);
|
|
64
|
-
document.removeEventListener('keydown', onKey);
|
|
65
|
-
ctx.ui.root.remove();
|
|
66
|
-
document.body.style.overflow = '';
|
|
67
|
-
// URL に ide=1 が残っていると、読み込み直した時にまた開いてしまう
|
|
68
|
-
const clean = location.href.replace(/([?&#])ide=1(&|$)/, (_, a, b) => (b ? a : '')).replace(/[?&#]$/, '');
|
|
69
|
-
if (clean !== location.href) history.replaceState(history.state, '', clean);
|
|
70
|
-
// 保存した時だけ、詳細画面を新しい内容にするために読み込み直す
|
|
71
|
-
if (ctx.savedOnce) location.reload();
|
|
72
|
-
};
|
|
73
|
-
window.addEventListener('beforeunload', guard);
|
|
74
|
-
document.addEventListener('keydown', onKey);
|
|
75
|
-
|
|
76
|
-
// ---- 最初の表示 ----
|
|
77
|
-
const { files } = ctx.state;
|
|
78
|
-
if (!ctx.state.sourcePaths().length) {
|
|
79
|
-
ctx.log.info('ファイルがありません。サンプル(TypeScript + npm + 設定画面)を入れました。保存すると残ります');
|
|
80
|
-
ctx.addFiles(Object.entries(SAMPLE));
|
|
81
|
-
}
|
|
82
|
-
if (sources.from === 'legacy') ctx.log.warn('ソースは前の形式(サブテーブル)です。保存すると zip のフィールドに移ります');
|
|
83
|
-
await ctx.restoreDraft();
|
|
84
|
-
ctx.preloadModels();
|
|
85
|
-
ctx.refreshStatus();
|
|
86
|
-
ctx.openFile(['src/desktop.ts', 'src/desktop.js', 'manifest.json'].find((p) => files.has(p)) || ctx.state.sourcePaths()[0]);
|
|
87
|
-
ctx.log.ok('準備ができました。help でコマンド一覧。Ctrl/Cmd+S 保存 / Ctrl/Cmd+B ビルド / Ctrl/Cmd+Enter インストール');
|
|
88
|
-
if (!canInstall()) ctx.log.warn(`${location.hostname} は INSTALL_HOSTS に無いので、インストールはできません(パッケージとダウンロードはできます)`);
|
|
89
|
-
ctx.startRepl();
|
|
90
|
-
// package.json の通りに node_modules をそろえる(2回目からはブラウザのキャッシュから)
|
|
91
|
-
ctx.run(() => ctx.npmRestore({ quiet: true }));
|
|
92
|
-
window.__kintonePluginIDE = ctx;
|
|
93
|
-
return ctx;
|
|
94
|
-
}
|
|
1
|
+
// IDE を組み立てる。各部品は ctx(共有の入れ物)に自分の関数を足していく
|
|
2
|
+
import { F } from '../config.js';
|
|
3
|
+
import { api } from '../kintone/api.js';
|
|
4
|
+
import { canInstall } from '../kintone/api.js';
|
|
5
|
+
import { loadSettings } from '../util/settings.js';
|
|
6
|
+
import { createState, readSources } from './state.js';
|
|
7
|
+
import { setupDialog } from './dialog.js';
|
|
8
|
+
import { setupLayout } from './layout.js';
|
|
9
|
+
import { setupTerminal } from './terminal.js';
|
|
10
|
+
import { setupTree } from './tree.js';
|
|
11
|
+
import { setupEditor } from './editor.js';
|
|
12
|
+
import { setupSave } from './actions/save.js';
|
|
13
|
+
import { setupRelease } from './actions/release.js';
|
|
14
|
+
import { setupZip } from './actions/zip.js';
|
|
15
|
+
import { setupNpm } from './actions/npm.js';
|
|
16
|
+
import { setupMisc } from './actions/misc.js';
|
|
17
|
+
import { setupCommands } from './commands.js';
|
|
18
|
+
import { SAMPLE } from './sample.js';
|
|
19
|
+
|
|
20
|
+
export async function openIDE() {
|
|
21
|
+
if (document.querySelector('.kpi-root')) return;
|
|
22
|
+
const appId = kintone.app.getId();
|
|
23
|
+
const recordId = kintone.app.record.getId();
|
|
24
|
+
const ctx = {
|
|
25
|
+
appId, recordId,
|
|
26
|
+
draftKey: `kintone-plugin-ide:draft:${location.host}:${appId}:${recordId}`,
|
|
27
|
+
settings: loadSettings(),
|
|
28
|
+
problems: { errors: 0, warnings: 0 },
|
|
29
|
+
savedOnce: false,
|
|
30
|
+
current: null,
|
|
31
|
+
// ターミナルができるまではコンソールに出す
|
|
32
|
+
log: Object.fromEntries(['info', 'ok', 'warn', 'error', 'plain'].map((k) => [k, (t) => console.log(`[IDE ${k}]`, t)])),
|
|
33
|
+
};
|
|
34
|
+
ctx.loadRecord = async () => (await api('/k/v1/record.json', 'GET', { app: appId, id: recordId })).record;
|
|
35
|
+
ctx.record = await ctx.loadRecord();
|
|
36
|
+
const sources = await readSources(ctx.record);
|
|
37
|
+
ctx.state = createState(sources);
|
|
38
|
+
ctx.testApp = () => Number(ctx.record[F.testApp] && ctx.record[F.testApp].value) || 0;
|
|
39
|
+
ctx.pluginIdValue = () => ctx.record[F.id] && ctx.record[F.id].value;
|
|
40
|
+
ctx.manifestInfo = () => { try { const m = JSON.parse(ctx.state.files.get('manifest.json')); return { name: m.name.ja || m.name.en, version: m.version }; } catch { return null; } };
|
|
41
|
+
|
|
42
|
+
setupLayout(ctx);
|
|
43
|
+
setupDialog(ctx);
|
|
44
|
+
setupCommands(ctx);
|
|
45
|
+
await setupTerminal(ctx);
|
|
46
|
+
await setupTree(ctx);
|
|
47
|
+
setupSave(ctx);
|
|
48
|
+
await setupEditor(ctx);
|
|
49
|
+
setupRelease(ctx);
|
|
50
|
+
setupZip(ctx);
|
|
51
|
+
setupNpm(ctx);
|
|
52
|
+
setupMisc(ctx);
|
|
53
|
+
|
|
54
|
+
// ---- 閉じる ----
|
|
55
|
+
const onKey = (e) => {
|
|
56
|
+
if (e.key === 'Escape' && !document.querySelector('.kpi-menu, .kpi-dialog') && !ctx.ui.termEl.contains(document.activeElement) && !ctx.isDiffOpen()) ctx.close();
|
|
57
|
+
};
|
|
58
|
+
const guard = (e) => { if (ctx.state.dirty().length) { e.preventDefault(); e.returnValue = ''; } };
|
|
59
|
+
ctx.close = async () => {
|
|
60
|
+
if (ctx.state.dirty().length && !(await ctx.confirm('保存していない変更があります', '閉じても、下書きはこのブラウザに残ります', { ok: '閉じる' }))) return;
|
|
61
|
+
ctx.disposeTerminal(); ctx.disposeEditor(); ctx.closeMenu();
|
|
62
|
+
ctx.tree.cleanUp?.();
|
|
63
|
+
window.removeEventListener('beforeunload', guard);
|
|
64
|
+
document.removeEventListener('keydown', onKey);
|
|
65
|
+
ctx.ui.root.remove();
|
|
66
|
+
document.body.style.overflow = '';
|
|
67
|
+
// URL に ide=1 が残っていると、読み込み直した時にまた開いてしまう
|
|
68
|
+
const clean = location.href.replace(/([?&#])ide=1(&|$)/, (_, a, b) => (b ? a : '')).replace(/[?&#]$/, '');
|
|
69
|
+
if (clean !== location.href) history.replaceState(history.state, '', clean);
|
|
70
|
+
// 保存した時だけ、詳細画面を新しい内容にするために読み込み直す
|
|
71
|
+
if (ctx.savedOnce) location.reload();
|
|
72
|
+
};
|
|
73
|
+
window.addEventListener('beforeunload', guard);
|
|
74
|
+
document.addEventListener('keydown', onKey);
|
|
75
|
+
|
|
76
|
+
// ---- 最初の表示 ----
|
|
77
|
+
const { files } = ctx.state;
|
|
78
|
+
if (!ctx.state.sourcePaths().length) {
|
|
79
|
+
ctx.log.info('ファイルがありません。サンプル(TypeScript + npm + 設定画面)を入れました。保存すると残ります');
|
|
80
|
+
ctx.addFiles(Object.entries(SAMPLE));
|
|
81
|
+
}
|
|
82
|
+
if (sources.from === 'legacy') ctx.log.warn('ソースは前の形式(サブテーブル)です。保存すると zip のフィールドに移ります');
|
|
83
|
+
await ctx.restoreDraft();
|
|
84
|
+
ctx.preloadModels();
|
|
85
|
+
ctx.refreshStatus();
|
|
86
|
+
ctx.openFile(['src/desktop.ts', 'src/desktop.js', 'manifest.json'].find((p) => files.has(p)) || ctx.state.sourcePaths()[0]);
|
|
87
|
+
ctx.log.ok('準備ができました。help でコマンド一覧。Ctrl/Cmd+S 保存 / Ctrl/Cmd+B ビルド / Ctrl/Cmd+Enter インストール');
|
|
88
|
+
if (!canInstall()) ctx.log.warn(`${location.hostname} は INSTALL_HOSTS に無いので、インストールはできません(パッケージとダウンロードはできます)`);
|
|
89
|
+
ctx.startRepl();
|
|
90
|
+
// package.json の通りに node_modules をそろえる(2回目からはブラウザのキャッシュから)
|
|
91
|
+
ctx.run(() => ctx.npmRestore({ quiet: true }));
|
|
92
|
+
window.__kintonePluginIDE = ctx;
|
|
93
|
+
return ctx;
|
|
94
|
+
}
|
package/src/ide/layout.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
// 画面の骨組み・大きさの調整・状態バー・処理の直列化
|
|
2
|
-
import { canInstall } from '../kintone/api.js';
|
|
3
|
-
import { el, downloadBlob } from '../util/dom.js';
|
|
4
|
-
import { saveSettings } from '../util/settings.js';
|
|
5
|
-
import { CSS, DIALOG_CSS } from './css.js';
|
|
6
|
-
|
|
7
|
-
export function setupLayout(ctx) {
|
|
8
|
-
const { log, settings, recordId } = ctx;
|
|
9
|
-
if (!document.getElementById('kpi-style')) document.head.append(el('style', { id: 'kpi-style', textContent: CSS + DIALOG_CSS }));
|
|
10
|
-
|
|
11
|
-
const btn = (label, title, onClick, cls = '') => { const b = el('button', { className: `kpi-btn ${cls}`, textContent: label, title }); b.onclick = onClick; return b; };
|
|
12
|
-
const sideBtn = (label, title, fn) => { const b = el('button', { textContent: label, title }); b.onclick = fn; return b; };
|
|
13
|
-
const titleEl = el('div', { className: 'kpi-title' });
|
|
14
|
-
const editorEl = el('div', { className: 'kpi-editor' }, el('div', { className: 'kpi-empty', innerHTML: '左のファイルを選んでください<br><small>zip をここにドロップすると取り込めます</small>' }));
|
|
15
|
-
const treeEl = el('div', { className: 'kpi-tree' });
|
|
16
|
-
const side = el('div', { className: 'kpi-side' },
|
|
17
|
-
el('div', { className: 'kpi-side-head' }, el('span', { textContent: 'エクスプローラー' }),
|
|
18
|
-
sideBtn('+', '新しいファイル', () => ctx.newFile('')),
|
|
19
|
-
sideBtn('⊞', '新しいフォルダ', () => ctx.newFolder('')),
|
|
20
|
-
sideBtn('⤒', 'ファイルをアップロード(画像など)', () => ctx.uploadFiles('')),
|
|
21
|
-
sideBtn('⇩', 'zip を取り込む', () => run(ctx.importZip)),
|
|
22
|
-
sideBtn('⇧', 'ソースを zip で書き出す', () => run(ctx.exportZip))),
|
|
23
|
-
treeEl);
|
|
24
|
-
const split = el('div', { className: 'kpi-split' });
|
|
25
|
-
const termEl = el('div', { className: 'kpi-term' });
|
|
26
|
-
const termSplit = el('div', { className: 'kpi-term-split' });
|
|
27
|
-
const termWrap = el('div', { className: 'kpi-term-wrap' }, termSplit, termEl);
|
|
28
|
-
const statusEl = el('div', { className: 'kpi-status' });
|
|
29
|
-
const buttons = {
|
|
30
|
-
save: btn('保存', 'Ctrl/Cmd+S', () => run(ctx.save)),
|
|
31
|
-
build: btn('ビルド', 'Ctrl/Cmd+B', () => run(() => ctx.buildOnly())),
|
|
32
|
-
zip: btn('ダウンロード', 'プラグインの zip をダウンロード', () => run(async () => { const r = await ctx.buildAndPack(); downloadBlob(r.plugin, r.zipName); })),
|
|
33
|
-
install: btn('インストール', 'Ctrl/Cmd+Enter: 保存 → ビルド → パッケージ → インストール → テスト用アプリに反映', () => run(ctx.buildAndInstall), 'primary'),
|
|
34
|
-
close: btn('閉じる', 'Esc', () => ctx.close()),
|
|
35
|
-
};
|
|
36
|
-
if (!canInstall()) buttons.install.style.display = 'none';
|
|
37
|
-
const root = el('div', { className: 'kpi-root' },
|
|
38
|
-
el('div', { className: 'kpi-bar' }, titleEl, ...Object.values(buttons)),
|
|
39
|
-
side, split, editorEl, termWrap, statusEl);
|
|
40
|
-
document.body.append(root);
|
|
41
|
-
document.body.style.overflow = 'hidden';
|
|
42
|
-
|
|
43
|
-
const drag = (handle, onMove) => {
|
|
44
|
-
handle.onpointerdown = (e) => {
|
|
45
|
-
handle.setPointerCapture(e.pointerId); handle.classList.add('on');
|
|
46
|
-
handle.onpointermove = (ev) => onMove(ev);
|
|
47
|
-
handle.onpointerup = () => { handle.onpointermove = null; handle.classList.remove('on'); };
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
drag(split, (ev) => root.style.setProperty('--kpi-side', `${Math.min(600, Math.max(140, ev.clientX))}px`));
|
|
51
|
-
drag(termSplit, (ev) => root.style.setProperty('--kpi-term', `${Math.min(innerHeight - 200, Math.max(80, innerHeight - 24 - ev.clientY))}px`));
|
|
52
|
-
|
|
53
|
-
// ---- 状態バー ----
|
|
54
|
-
const toggle = (key, label) => {
|
|
55
|
-
const b = el('button', { textContent: `${label}: ${settings[key] ? 'ON' : 'OFF'}`, title: `クリックで切り替え(${key})` });
|
|
56
|
-
b.onclick = () => { settings[key] = !settings[key]; saveSettings(settings); updateStatus(); };
|
|
57
|
-
return b;
|
|
58
|
-
};
|
|
59
|
-
function updateStatus() {
|
|
60
|
-
const m = ctx.manifestInfo();
|
|
61
|
-
const n = ctx.state.dirty().length;
|
|
62
|
-
titleEl.replaceChildren(m ? `${m.name} v${m.version}` : '(manifest.json なし)', el('small', { textContent: `レコード ${recordId}${n ? ` ・ 未保存 ${n}` : ''}` }));
|
|
63
|
-
const testApp = ctx.testApp();
|
|
64
|
-
const pid = ctx.pluginIdValue();
|
|
65
|
-
const probBtn = el('button', { textContent: `⨂ ${ctx.problems.errors} ⚠ ${ctx.problems.warnings}`, title: '型チェックの結果(クリックで一覧)' });
|
|
66
|
-
probBtn.onclick = () => run(() => ctx.command('check'));
|
|
67
|
-
statusEl.replaceChildren(
|
|
68
|
-
el('span', {}, ctx.current || ''),
|
|
69
|
-
probBtn,
|
|
70
|
-
el('span', { className: 'sp' }),
|
|
71
|
-
toggle('prod', '本番ビルド'), toggle('typecheck', '型チェック'), toggle('format', '保存時に整形'), toggle('watch', '保存でインストール'),
|
|
72
|
-
el('span', {}, 'テスト用アプリ: ', el('b', { textContent: testApp ? `#${testApp}` : '未設定' })),
|
|
73
|
-
el('span', {}, 'ID: ', el('b', { textContent: pid ? pid.slice(0, 8) + '…' : '未作成' })),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ---- 重い処理を1つずつ ----
|
|
78
|
-
let busy = false;
|
|
79
|
-
async function run(fn) {
|
|
80
|
-
if (busy) { log.warn('ほかの処理が終わるまで待ってください'); return; }
|
|
81
|
-
busy = true;
|
|
82
|
-
Object.values(buttons).forEach((b) => { b.disabled = b !== buttons.close; });
|
|
83
|
-
try { await fn(); } catch (e) { console.error(e); log.error(e.message || String(e)); }
|
|
84
|
-
finally { busy = false; Object.values(buttons).forEach((b) => { b.disabled = false; }); }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
ctx.ui = { root, editorEl, treeEl, termEl, statusEl, buttons };
|
|
88
|
-
Object.assign(ctx, { run, updateStatus });
|
|
89
|
-
}
|
|
1
|
+
// 画面の骨組み・大きさの調整・状態バー・処理の直列化
|
|
2
|
+
import { canInstall } from '../kintone/api.js';
|
|
3
|
+
import { el, downloadBlob } from '../util/dom.js';
|
|
4
|
+
import { saveSettings } from '../util/settings.js';
|
|
5
|
+
import { CSS, DIALOG_CSS } from './css.js';
|
|
6
|
+
|
|
7
|
+
export function setupLayout(ctx) {
|
|
8
|
+
const { log, settings, recordId } = ctx;
|
|
9
|
+
if (!document.getElementById('kpi-style')) document.head.append(el('style', { id: 'kpi-style', textContent: CSS + DIALOG_CSS }));
|
|
10
|
+
|
|
11
|
+
const btn = (label, title, onClick, cls = '') => { const b = el('button', { className: `kpi-btn ${cls}`, textContent: label, title }); b.onclick = onClick; return b; };
|
|
12
|
+
const sideBtn = (label, title, fn) => { const b = el('button', { textContent: label, title }); b.onclick = fn; return b; };
|
|
13
|
+
const titleEl = el('div', { className: 'kpi-title' });
|
|
14
|
+
const editorEl = el('div', { className: 'kpi-editor' }, el('div', { className: 'kpi-empty', innerHTML: '左のファイルを選んでください<br><small>zip をここにドロップすると取り込めます</small>' }));
|
|
15
|
+
const treeEl = el('div', { className: 'kpi-tree' });
|
|
16
|
+
const side = el('div', { className: 'kpi-side' },
|
|
17
|
+
el('div', { className: 'kpi-side-head' }, el('span', { textContent: 'エクスプローラー' }),
|
|
18
|
+
sideBtn('+', '新しいファイル', () => ctx.newFile('')),
|
|
19
|
+
sideBtn('⊞', '新しいフォルダ', () => ctx.newFolder('')),
|
|
20
|
+
sideBtn('⤒', 'ファイルをアップロード(画像など)', () => ctx.uploadFiles('')),
|
|
21
|
+
sideBtn('⇩', 'zip を取り込む', () => run(ctx.importZip)),
|
|
22
|
+
sideBtn('⇧', 'ソースを zip で書き出す', () => run(ctx.exportZip))),
|
|
23
|
+
treeEl);
|
|
24
|
+
const split = el('div', { className: 'kpi-split' });
|
|
25
|
+
const termEl = el('div', { className: 'kpi-term' });
|
|
26
|
+
const termSplit = el('div', { className: 'kpi-term-split' });
|
|
27
|
+
const termWrap = el('div', { className: 'kpi-term-wrap' }, termSplit, termEl);
|
|
28
|
+
const statusEl = el('div', { className: 'kpi-status' });
|
|
29
|
+
const buttons = {
|
|
30
|
+
save: btn('保存', 'Ctrl/Cmd+S', () => run(ctx.save)),
|
|
31
|
+
build: btn('ビルド', 'Ctrl/Cmd+B', () => run(() => ctx.buildOnly())),
|
|
32
|
+
zip: btn('ダウンロード', 'プラグインの zip をダウンロード', () => run(async () => { const r = await ctx.buildAndPack(); downloadBlob(r.plugin, r.zipName); })),
|
|
33
|
+
install: btn('インストール', 'Ctrl/Cmd+Enter: 保存 → ビルド → パッケージ → インストール → テスト用アプリに反映', () => run(ctx.buildAndInstall), 'primary'),
|
|
34
|
+
close: btn('閉じる', 'Esc', () => ctx.close()),
|
|
35
|
+
};
|
|
36
|
+
if (!canInstall()) buttons.install.style.display = 'none';
|
|
37
|
+
const root = el('div', { className: 'kpi-root' },
|
|
38
|
+
el('div', { className: 'kpi-bar' }, titleEl, ...Object.values(buttons)),
|
|
39
|
+
side, split, editorEl, termWrap, statusEl);
|
|
40
|
+
document.body.append(root);
|
|
41
|
+
document.body.style.overflow = 'hidden';
|
|
42
|
+
|
|
43
|
+
const drag = (handle, onMove) => {
|
|
44
|
+
handle.onpointerdown = (e) => {
|
|
45
|
+
handle.setPointerCapture(e.pointerId); handle.classList.add('on');
|
|
46
|
+
handle.onpointermove = (ev) => onMove(ev);
|
|
47
|
+
handle.onpointerup = () => { handle.onpointermove = null; handle.classList.remove('on'); };
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
drag(split, (ev) => root.style.setProperty('--kpi-side', `${Math.min(600, Math.max(140, ev.clientX))}px`));
|
|
51
|
+
drag(termSplit, (ev) => root.style.setProperty('--kpi-term', `${Math.min(innerHeight - 200, Math.max(80, innerHeight - 24 - ev.clientY))}px`));
|
|
52
|
+
|
|
53
|
+
// ---- 状態バー ----
|
|
54
|
+
const toggle = (key, label) => {
|
|
55
|
+
const b = el('button', { textContent: `${label}: ${settings[key] ? 'ON' : 'OFF'}`, title: `クリックで切り替え(${key})` });
|
|
56
|
+
b.onclick = () => { settings[key] = !settings[key]; saveSettings(settings); updateStatus(); };
|
|
57
|
+
return b;
|
|
58
|
+
};
|
|
59
|
+
function updateStatus() {
|
|
60
|
+
const m = ctx.manifestInfo();
|
|
61
|
+
const n = ctx.state.dirty().length;
|
|
62
|
+
titleEl.replaceChildren(m ? `${m.name} v${m.version}` : '(manifest.json なし)', el('small', { textContent: `レコード ${recordId}${n ? ` ・ 未保存 ${n}` : ''}` }));
|
|
63
|
+
const testApp = ctx.testApp();
|
|
64
|
+
const pid = ctx.pluginIdValue();
|
|
65
|
+
const probBtn = el('button', { textContent: `⨂ ${ctx.problems.errors} ⚠ ${ctx.problems.warnings}`, title: '型チェックの結果(クリックで一覧)' });
|
|
66
|
+
probBtn.onclick = () => run(() => ctx.command('check'));
|
|
67
|
+
statusEl.replaceChildren(
|
|
68
|
+
el('span', {}, ctx.current || ''),
|
|
69
|
+
probBtn,
|
|
70
|
+
el('span', { className: 'sp' }),
|
|
71
|
+
toggle('prod', '本番ビルド'), toggle('typecheck', '型チェック'), toggle('format', '保存時に整形'), toggle('watch', '保存でインストール'),
|
|
72
|
+
el('span', {}, 'テスト用アプリ: ', el('b', { textContent: testApp ? `#${testApp}` : '未設定' })),
|
|
73
|
+
el('span', {}, 'ID: ', el('b', { textContent: pid ? pid.slice(0, 8) + '…' : '未作成' })),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---- 重い処理を1つずつ ----
|
|
78
|
+
let busy = false;
|
|
79
|
+
async function run(fn) {
|
|
80
|
+
if (busy) { log.warn('ほかの処理が終わるまで待ってください'); return; }
|
|
81
|
+
busy = true;
|
|
82
|
+
Object.values(buttons).forEach((b) => { b.disabled = b !== buttons.close; });
|
|
83
|
+
try { await fn(); } catch (e) { console.error(e); log.error(e.message || String(e)); }
|
|
84
|
+
finally { busy = false; Object.values(buttons).forEach((b) => { b.disabled = false; }); }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
ctx.ui = { root, editorEl, treeEl, termEl, statusEl, buttons };
|
|
88
|
+
Object.assign(ctx, { run, updateStatus });
|
|
89
|
+
}
|