mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-atelier.git
synced 2026-11-29 06:02:06 +00:00
1256 lines
86 KiB
PHP
1256 lines
86 KiB
PHP
{{-- PL0XION atelier 🛠 — LA PORTE DE CONTRIBUTION DANS LE XER (braindump RS-7 16.08 :
|
||
« prendre un ploxion, le modifier comme on veut, et ENVOYER LE TSOIN — c'est ça le
|
||
commit »). La boucle complète, mobile-first : prends un ploxion (registre /dev/ploxions.json,
|
||
🎯 missions du jour, ✨ crée un nouveau) → l'éditeur (moteur premier-ploxion : textarea +
|
||
numéros de ligne + coloration légère, gros sur téléphone, undo/indent/recherche, autosave
|
||
brouillon 5 s via POST /atelier/draft/{id}) → ▶ la preview (iframe sandbox srcdoc, bions
|
||
core stubbés, < échappés — le pattern premier-ploxion ; les erreurs JS remontent sous
|
||
l'éditeur) → les checks verify-lite (manifest, mount/unmount, esc(), describe, séquence
|
||
de fermeture de script) → « ⧗ ENVOYER LE TSOIN » (note obligatoire, POST /atelier/tsoin/{id},
|
||
diff calculé serveur, la file + /coord topic contributions) → onglet « la file » (mes tsoins
|
||
+ statuts ; admin : tout + repasser le statut ; diff simple surligné, zéro lib).
|
||
SÉCURITÉ : on n'exécute QUE le brouillon de l'utilisateur connecté (self-XSS acceptable,
|
||
XSS des autres jamais) — la file, elle, n'est jamais montée : rendue en diff TEXTE.
|
||
window.jOSApps['atelier'] = { manifest, mount, describe, shareParams }. --}}
|
||
<style>
|
||
/* racine AU CONTRAT du xer (comme digestion/universal-suit/premier-ploxion) :
|
||
position:absolute;inset:0 dans le conteneur positionné du host — jamais height:100%
|
||
(dans un conteneur non contraint, 100% s'effondre et le layout part en vrille). */
|
||
.atl{position:absolute;inset:0;display:flex;flex-direction:column;background:var(--xr-bg,#070b12);color:var(--xr-text,#e7f0ff);font-family:var(--xr-font-ui,ui-sans-serif,system-ui);font-size:.86rem}
|
||
.atl *{box-sizing:border-box;min-width:0;-webkit-tap-highlight-color:transparent}
|
||
.atl button{font:inherit;color:inherit}
|
||
/* ---- header compact ---- */
|
||
.atl__h{flex:0 0 auto;padding:calc(env(safe-area-inset-top,0px) + 10px) 12px 8px;border-bottom:1px solid var(--xr-border,#22324f)}
|
||
.atl__ht{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
|
||
.atl__ht b{font-size:1rem;font-weight:800;color:var(--xr-accent,#3fe0d0);letter-spacing:.02em;margin-right:6px}
|
||
.atl__ht small{font-weight:400;font-size:.68rem;opacity:.55;line-height:1.4}
|
||
.atl__tabs{display:flex;gap:6px;margin-top:8px}
|
||
.atl__tab{flex:0 1 auto;font-size:.76rem;font-weight:700;opacity:.55;background:none;border:1px solid var(--xr-border,#22324f);border-radius:99px;padding:7px 14px;min-height:36px;cursor:pointer;white-space:nowrap;transition:opacity .15s,border-color .15s}
|
||
.atl__tab:hover{opacity:.85}
|
||
.atl__tab.on{opacity:1;color:var(--xr-accent,#3fe0d0);border-color:var(--xr-accent,#3fe0d0);background:rgba(63,224,208,.07)}
|
||
.atl__b{flex:1 1 auto;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:12px 12px calc(16px + env(safe-area-inset-bottom))}
|
||
.atl__b>*{max-width:860px;margin-left:auto;margin-right:auto}
|
||
.atl__msg{padding:26px 10px;text-align:center;opacity:.65;line-height:1.6}
|
||
.atl__msg a{color:var(--xr-accent,#3fe0d0)}
|
||
.atl__note{font-size:.72rem;opacity:.6;line-height:1.5;margin:8px 0}
|
||
.atl__sec{margin:16px 0 8px;font-size:.72rem;font-weight:800;letter-spacing:.08em;text-transform:uppercase;color:var(--xr-accent,#3fe0d0)}
|
||
.atl__sec small{font-weight:400;text-transform:none;letter-spacing:0;opacity:.6;margin-left:6px}
|
||
/* ---- champs & boutons ---- */
|
||
.atl__in{display:block;width:100%;padding:11px 12px;border-radius:11px;border:1px solid var(--xr-border,#22324f);background:rgba(255,255,255,.04);color:var(--xr-text,#e7f0ff);font:inherit}
|
||
.atl__in:focus{outline:none;border-color:var(--xr-accent,#3fe0d0)}
|
||
.atl__btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:10px 14px;min-height:42px;border-radius:11px;border:1px solid var(--xr-border,#22324f);background:transparent;font-size:.8rem;cursor:pointer;transition:border-color .15s,background .15s}
|
||
.atl__btn:hover{border-color:var(--xr-accent,#3fe0d0)}
|
||
.atl__btn:active{transform:scale(.985)}
|
||
.atl__btn--go{background:var(--xr-accent,#3fe0d0);color:var(--xr-bg,#070b12);border-color:var(--xr-accent,#3fe0d0);font-weight:800}
|
||
.atl__btn--go:hover{filter:brightness(1.08)}
|
||
.atl__btn:disabled{opacity:.35;cursor:not-allowed;transform:none}
|
||
/* ---- tuiles d'entrée (✨ nouveau / ⧗ mes tsoins) ---- */
|
||
.atl__tiles{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin:10px 0}
|
||
.atl__tile{display:flex;flex-direction:column;align-items:flex-start;gap:2px;text-align:left;border:1px solid var(--xr-border,#22324f);border-radius:13px;background:rgba(255,255,255,.025);padding:11px 13px;cursor:pointer;transition:border-color .15s,background .15s}
|
||
.atl__tile:hover{border-color:var(--xr-accent,#3fe0d0);background:rgba(63,224,208,.05)}
|
||
.atl__tile:active{transform:scale(.985)}
|
||
.atl__tile b{font-size:.84rem}
|
||
.atl__tile small{font-size:.68rem;opacity:.55;line-height:1.4}
|
||
/* ---- cartes du registre (résultats de recherche) ---- */
|
||
.atl__row{position:relative;display:flex;align-items:center;gap:10px;width:100%;text-align:left;border:1px solid var(--xr-border,#22324f);border-radius:12px;background:rgba(255,255,255,.02);padding:11px 12px;margin:6px 0;cursor:pointer;transition:border-color .15s,background .15s}
|
||
.atl__row:hover{border-color:var(--xr-accent,#3fe0d0);background:rgba(63,224,208,.04)}
|
||
.atl__row:active{transform:scale(.99)}
|
||
.atl__row .ic{flex:0 0 auto;font-size:1.2rem}
|
||
.atl__row .mid{flex:1 1 auto;min-width:0}
|
||
.atl__row .mid b{display:block;font-size:.82rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
.atl__row .mid small{display:block;opacity:.55;font-size:.7rem;line-height:1.4;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
.atl__chip{flex:0 0 auto;font-size:.62rem;font-weight:700;border:1px solid var(--xr-border,#22324f);border-radius:99px;padding:2px 8px;opacity:.85;white-space:nowrap}
|
||
.atl__chip--v{color:#7de6a0;border-color:rgba(120,230,160,.5)}
|
||
.atl__chip--o{color:#e8cf8a;border-color:#5a4a1e}
|
||
.atl__vcmd{margin:6px 0;padding:9px 11px;border-radius:9px;background:rgba(0,0,0,.35);border:1px solid var(--xr-border,#22324f);font:.74rem/1.45 var(--xr-font-mono,ui-monospace,monospace);white-space:pre-wrap;word-break:break-all;user-select:all}
|
||
.atl__chip--r{color:#ff9d9d;border-color:#5a2e1e}
|
||
/* ---- cartes MISSION : flux statique STRICT, position:relative ancrée, la CARTE
|
||
ENTIÈRE est le bouton (plus jamais un bouton qui flotte hors de sa carte) ---- */
|
||
.atl__mi{position:relative;display:block;width:100%;text-align:left;border:1px solid #3d3218;border-radius:13px;background:rgba(224,166,63,.05);padding:11px 13px;margin:8px 0;cursor:pointer;transition:border-color .15s,background .15s;overflow:hidden}
|
||
.atl__mi:hover{border-color:#e8cf8a;background:rgba(224,166,63,.09)}
|
||
.atl__mi:active{transform:scale(.99)}
|
||
.atl__mit{display:flex;align-items:flex-start;gap:8px}
|
||
.atl__mit .ic{flex:0 0 auto;font-size:1.05rem;line-height:1.35}
|
||
.atl__mit b{flex:1 1 auto;min-width:0;color:#e8cf8a;font-size:.8rem;line-height:1.4;overflow-wrap:break-word}
|
||
.atl__miw{margin:4px 0 0 calc(1.05rem + 8px);font-size:.7rem;opacity:.62;line-height:1.5;overflow-wrap:break-word}
|
||
.atl__mia{display:flex;justify-content:flex-end;margin-top:9px}
|
||
.atl__take{display:inline-flex;align-items:center;gap:6px;font-size:.76rem;font-weight:700;color:var(--xr-accent,#3fe0d0);border:1px solid rgba(63,224,208,.45);border-radius:10px;padding:8px 13px;min-height:38px}
|
||
.atl__mi:hover .atl__take{background:rgba(63,224,208,.1)}
|
||
.atl__diffb{flex:0 0 auto;font-size:.6rem;font-weight:700;border-radius:99px;padding:2px 8px;margin-left:4px;align-self:center}
|
||
.atl__diffb--facile{color:#7de6a0;border:1px solid rgba(120,230,160,.5)}
|
||
.atl__diffb--moyen{color:#e8cf8a;border:1px solid #5a4a1e}
|
||
.atl__diffb--dur{color:#ff9d9d;border:1px solid #5a2e1e}
|
||
@media (max-width:559px){
|
||
.atl__mia{justify-content:stretch}
|
||
.atl__take{width:100%;justify-content:center;min-height:44px}
|
||
.atl__tiles{grid-template-columns:1fr}
|
||
}
|
||
/* ---- toast maison ---- */
|
||
.atl__toast{position:absolute;left:50%;bottom:calc(18px + env(safe-area-inset-bottom));transform:translateX(-50%);z-index:60;background:rgba(7,14,22,.94);border:1px solid var(--xr-accent,#3fe0d0);color:var(--xr-text,#e7f0ff);border-radius:99px;padding:9px 16px;font-size:.78rem;white-space:nowrap;max-width:92%;overflow:hidden;text-overflow:ellipsis;pointer-events:none;animation:atlToast 2.2s ease forwards}
|
||
@keyframes atlToast{0%{opacity:0;transform:translateX(-50%) translateY(8px)}12%{opacity:1;transform:translateX(-50%)}82%{opacity:1}100%{opacity:0}}
|
||
/* ---- l'établi (moteur premier-ploxion + numéros de ligne) ---- */
|
||
.atl__ehd{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:8px}
|
||
.atl__ehd b{font-size:.95rem}
|
||
.atl__bar{display:flex;gap:6px;flex-wrap:wrap;align-items:center;margin:0 0 8px}
|
||
.atl__tool{display:inline-flex;align-items:center;justify-content:center;padding:8px 11px;min-width:44px;min-height:40px;border-radius:10px;border:1px solid var(--xr-border,#22324f);background:transparent;font-size:.82rem;cursor:pointer;transition:border-color .15s}
|
||
.atl__tool:hover{border-color:var(--xr-accent,#3fe0d0)}
|
||
.atl__tool:active{transform:scale(.96)}
|
||
.atl__status{font-size:.68rem;opacity:.65;flex:1 1 130px;min-width:130px;text-align:right}
|
||
.atl__ed{display:flex;border:1px solid var(--xr-border,#22324f);border-radius:11px;background:#060a12;overflow:auto;max-height:52vh;margin:0 0 8px}
|
||
.atl__gut{flex:0 0 auto;padding:10px 6px 10px 10px;font:12.5px/1.55 ui-monospace,monospace;color:#3f5570;text-align:right;user-select:none;white-space:pre;border-right:1px solid var(--xr-border,#22324f);position:sticky;left:0;background:#060a12}
|
||
.atl__code{position:relative;flex:1 1 auto;min-width:0}
|
||
.atl__hl,.atl__ta{margin:0;padding:10px 14px 10px 10px;font:12.5px/1.55 ui-monospace,monospace;white-space:pre;min-height:180px;min-width:100%;width:max-content;display:block}
|
||
.atl__hl{color:#dbe7f5;pointer-events:none}
|
||
.atl__ta{position:absolute;inset:0;width:100%;height:100%;background:transparent;color:transparent;caret-color:var(--xr-accent,#3fe0d0);border:0;outline:none;resize:none;overflow:hidden;white-space:pre;word-break:normal}
|
||
.atl__h-c{color:#6a7a95}.atl__h-s{color:#9df3c8}.atl__h-k{color:#c9aaff}.atl__h-n{color:#ffcf6a}.atl__h-j{color:#3fe0d0;font-weight:600}
|
||
@media (max-width:699px){ .atl__gut,.atl__hl,.atl__ta{font-size:16px;line-height:1.5} .atl__ed{max-height:44vh} }
|
||
.atl__find{display:none;gap:6px;margin:0 0 8px}
|
||
.atl__find.on{display:flex}
|
||
.atl__find input{flex:1}
|
||
.atl__log{font:11.5px/1.5 ui-monospace,monospace;max-height:120px;overflow-y:auto;margin:0 0 8px}
|
||
.atl__log div{padding:2px 0;border-bottom:1px dashed rgba(255,255,255,.06)}
|
||
.atl__log .err{color:#ff9d9d}.atl__log .bus{color:#9df3c8}.atl__log .inf{opacity:.6}
|
||
.atl__frame{width:100%;height:280px;border:1px solid var(--xr-border,#22324f);border-radius:11px;background:#0a0f18;display:none}
|
||
.atl__frame.on{display:block}
|
||
.atl__modebar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:0 0 8px}
|
||
.atl__mode{padding:7px 11px;border:1px solid var(--xr-border,#22324f);border-radius:9px;background:transparent;color:inherit;font-size:.72rem;font-weight:700;cursor:pointer}
|
||
.atl__mode.on{border-color:var(--xr-accent,#3fe0d0);color:var(--xr-accent,#3fe0d0);background:rgba(63,224,208,.08)}
|
||
.atl__device{margin-left:auto;padding:7px 9px;border:1px solid var(--xr-border,#22324f);border-radius:9px;background:var(--xr-bg,#070b12);color:inherit;font:inherit;font-size:.72rem}
|
||
.atl__workbench{display:grid;grid-template-columns:minmax(0,1fr) minmax(320px,1fr);gap:10px;align-items:start}
|
||
.atl__pane{min-width:0}
|
||
.atl__pane-title{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:0 0 6px;font-size:.68rem;text-transform:uppercase;letter-spacing:.07em;color:var(--xr-accent,#3fe0d0)}
|
||
.atl__viewport{display:flex;justify-content:center;align-items:flex-start;min-height:300px;padding:10px;background:rgba(255,255,255,.025);border:1px solid var(--xr-border,#22324f);border-radius:11px;overflow:auto}
|
||
.atl__viewport .atl__frame{flex:0 0 auto;min-width:0;margin:0}
|
||
.atl__viewport[data-device="phone"] .atl__frame{width:390px;height:690px}
|
||
.atl__viewport[data-device="tablet"] .atl__frame{width:768px;height:620px}
|
||
.atl__viewport[data-device="watch"] .atl__frame{width:240px;height:300px;border-radius:32px}
|
||
.atl__viewport[data-device="xer"] .atl__frame{width:520px;height:420px}
|
||
.atl__inspect{margin-top:7px;padding:9px;border:1px solid var(--xr-border,#22324f);border-radius:10px;background:rgba(255,255,255,.025);font:.7rem/1.45 var(--xr-font-mono,ui-monospace,monospace);min-height:48px}
|
||
.atl__inspect b{color:var(--xr-accent,#3fe0d0)}
|
||
.atl__inspect small{display:block;color:var(--xr-muted,#7f93c8);margin-top:3px}
|
||
.atl__inspecttools{display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:8px}
|
||
.atl__inspecttools input{width:76px;padding:5px 6px;border:1px solid var(--xr-border,#22324f);border-radius:7px;background:var(--xr-bg,#070b12);color:inherit;font:inherit}
|
||
.atl__inspecttools button{padding:5px 8px;border:1px solid var(--xr-accent,#3fe0d0);border-radius:7px;background:transparent;color:var(--xr-accent,#3fe0d0);font:inherit;cursor:pointer}
|
||
.atl__mode-test .atl__codepane{display:none}
|
||
.atl__mode-test .atl__previewpane{grid-column:1/-1}
|
||
.atl__mode-test .atl__viewport{min-height:520px}
|
||
.atl__mode-ui .atl__inspect{display:block}
|
||
.atl__mode-code .atl__inspect{opacity:.55}
|
||
@media (max-width:999px){.atl__workbench{grid-template-columns:1fr}.atl__mode-test .atl__previewpane{grid-column:auto}}
|
||
.atl__fw{position:relative}
|
||
.atl__fw.full{position:fixed;inset:0;z-index:9999;background:#0a0f18;padding:0;max-width:none}
|
||
.atl__fw.full .atl__frame{height:100%;border:0;border-radius:0}
|
||
.atl__fx{display:none;position:absolute;top:calc(8px + env(safe-area-inset-top));right:12px;z-index:3;padding:8px 13px;border-radius:99px;border:1px solid var(--xr-accent,#3fe0d0);background:rgba(7,11,18,.85);color:var(--xr-accent,#3fe0d0);font-weight:800;cursor:pointer}
|
||
.atl__fw.full .atl__fx{display:block}
|
||
.atl__ck{display:flex;gap:8px;align-items:flex-start;padding:7px 10px;border:1px solid var(--xr-border,#22324f);border-radius:10px;margin-bottom:4px;font-size:.76rem;line-height:1.4}
|
||
.atl__ck b{flex:0 0 auto}
|
||
.atl__ck.ok b{color:#7de6a0}.atl__ck.ko b{color:#ff9d9d}.atl__ck.warn b{color:#e8cf8a}
|
||
.atl__ck small{display:block;opacity:.6;font-size:.68rem}
|
||
.atl__send{border:1px dashed var(--xr-border,#22324f);border-radius:13px;padding:12px;margin:12px 0}
|
||
.atl__send.sent{border-color:rgba(120,230,160,.5);background:rgba(120,230,160,.06)}
|
||
.atl__sendrow{display:flex;gap:7px;margin-top:8px;flex-wrap:wrap}
|
||
.atl__sendrow .atl__in{flex:1 1 200px;width:auto}
|
||
.atl__party{color:#a9f0c2;font-size:.84rem;line-height:1.6}
|
||
/* ---- la barre pouce (sticky en bas de l'établi, mobile-first) ---- */
|
||
.atl__sticky{position:sticky;bottom:-12px;margin:10px -12px calc(-16px - env(safe-area-inset-bottom));padding:10px 12px calc(10px + env(safe-area-inset-bottom));background:linear-gradient(180deg,transparent,var(--xr-bg,#070b12) 26%);display:flex;gap:8px;max-width:none}
|
||
.atl__sticky .atl__btn{flex:1 1 auto;min-height:46px}
|
||
@media (min-width:700px){ .atl__sticky{position:static;margin:10px 0 0;padding:0;background:none;max-width:860px} .atl__sticky .atl__btn{flex:0 0 auto} }
|
||
/* ---- la file / le diff ---- */
|
||
.atl__diff{font:11.5px/1.5 ui-monospace,monospace;border:1px solid var(--xr-border,#22324f);border-radius:11px;background:#060a12;overflow-x:auto;padding:8px 0;margin:8px 0}
|
||
.atl__diff div{white-space:pre;padding:0 10px}
|
||
.atl__diff .add{background:rgba(120,230,160,.12);color:#9df3c8}
|
||
.atl__diff .del{background:rgba(255,120,120,.1);color:#ff9d9d}
|
||
.atl__diff .ctx{opacity:.5}
|
||
.atl__diff .hunk{opacity:.45;color:var(--xr-accent,#3fe0d0);padding-top:5px}
|
||
@media (max-width:699px){ .atl__diff{font-size:10.5px} }
|
||
</style>
|
||
<script>
|
||
(function () {
|
||
'use strict';
|
||
var ID = 'atelier';
|
||
window.jOSApps = window.jOSApps || {};
|
||
if (window.jOSApps[ID]) return; // idempotent
|
||
|
||
var MAX = 524288; // 512 Ko — la même borne que le serveur
|
||
var SCRIPT_END = '<' + '/script>'; // jamais en clair dans un blade
|
||
var SENT_LS = 'atelier:sent';
|
||
|
||
function esc(s) {
|
||
return window.jOSb && jOSb.esc ? jOSb.esc(s)
|
||
: String(s == null ? '' : s).replace(/[<>&"]/g, function (c) { return { '<': '<', '>': '>', '&': '&', '"': '"' }[c]; });
|
||
}
|
||
function CSRF() { var m = document.querySelector('meta[name="csrf-token"]'); return m ? m.getAttribute('content') : ''; }
|
||
function jget(url) {
|
||
return fetch(url, { credentials: 'same-origin', headers: { 'Accept': 'application/json' } })
|
||
.then(function (r) { if (!r.ok) { var e = new Error('http ' + r.status); e.status = r.status; throw e; } return r.json(); });
|
||
}
|
||
function jpost(url, body) {
|
||
return fetch(url, { method: 'POST', credentials: 'same-origin',
|
||
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': CSRF(), 'Accept': 'application/json' },
|
||
body: JSON.stringify(body || {}) })
|
||
.then(function (r) { return r.json().then(function (j) { j._status = r.status; return j; }); });
|
||
}
|
||
function sentCount() { try { return parseInt(localStorage.getItem(SENT_LS) || '0', 10) || 0; } catch (e) { return 0; } }
|
||
|
||
// ---- caches module (describe() s'en sert non monté) ----
|
||
var REG = null, REGAT = 0, QCACHE = null;
|
||
|
||
function loadReg() {
|
||
if (REG && (Date.now() - REGAT) < 300000) return Promise.resolve(REG);
|
||
return jget('/dev/ploxions.json').then(function (j) {
|
||
if (!j || !j.ploxions) throw new Error('format');
|
||
REG = j; REGAT = Date.now(); return j;
|
||
});
|
||
}
|
||
|
||
// échantillon stable-aléatoire par date — le même tirage que 🔧 dev-ploxions
|
||
function seededShuffle(arr, seedStr) {
|
||
var h = 1779033703 ^ seedStr.length;
|
||
for (var i = 0; i < seedStr.length; i++) { h = Math.imul(h ^ seedStr.charCodeAt(i), 3432918353); h = (h << 13) | (h >>> 19); }
|
||
function rnd() { h = Math.imul(h ^ (h >>> 16), 2246822507); h = Math.imul(h ^ (h >>> 13), 3266489909); h = (h ^= h >>> 16) >>> 0; return h / 4294967296; }
|
||
var a = arr.slice();
|
||
for (var j = a.length - 1; j > 0; j--) { var k = Math.floor(rnd() * (j + 1)); var t = a[j]; a[j] = a[k]; a[k] = t; }
|
||
return a;
|
||
}
|
||
function missionsDuJour(data, n) {
|
||
var pool = [];
|
||
(data.ploxions || []).forEach(function (p) {
|
||
if (p.admin || !p.enabled) return;
|
||
(p.missions || []).forEach(function (m) { pool.push({ p: p, m: m }); });
|
||
});
|
||
var faciles = pool.filter(function (x) { return x.m.diff === 'facile'; });
|
||
return seededShuffle(faciles.length >= n ? faciles : pool, new Date().toISOString().slice(0, 10)).slice(0, n);
|
||
}
|
||
|
||
// ---- ✨ le squelette d'un nouveau ploxion (l'exemple hello-toi du tuto premier-ploxion) ----
|
||
function squelette(id) {
|
||
function q(v) { return String(v).replace(/\\/g, '\\\\').replace(/'/g, "\\'"); }
|
||
var head = '{' + '{-- PL0XION ' + id + ' ✨ — né dans l\'atelier 🛠 (décris-le ici). ' +
|
||
"window.jOSApps['" + id + "'] = { manifest, mount -> { unmount }, describe }. --" + '}' + '}';
|
||
var L = [
|
||
head,
|
||
'<' + 'script>',
|
||
'(function () {',
|
||
" 'use strict';",
|
||
" var ID = '" + q(id) + "';",
|
||
' window.jOSApps = window.jOSApps || {};',
|
||
' if (window.jOSApps[ID]) return; // idempotent',
|
||
'',
|
||
' function mount(container, ctx) {',
|
||
' container.innerHTML =',
|
||
' \'<div style="padding:16px;font-family:system-ui;display:flex;flex-direction:column;gap:10px">\' +',
|
||
' \'<div style="font-weight:800;color:#3fe0d0">✨ ' + q(id) + '</div>\' +',
|
||
' \'<button data-go style="padding:9px;border-radius:8px;border:1px solid #3fe0d0;background:rgba(63,224,208,.12);color:#3fe0d0;font-weight:700;cursor:pointer">dire bonjour</button>\' +',
|
||
' \'<div data-msg style="font-family:monospace;color:#3fe0d0">salut, toi.</div>\' +',
|
||
' \'</div>\';',
|
||
'',
|
||
" var msg = container.querySelector('[data-msg]');",
|
||
" container.querySelector('[data-go]').addEventListener('click', function () {",
|
||
" msg.textContent = 'salut, xerboxion !';",
|
||
" if (window.jOSPorts) { jOSPorts.emit(ID, 'bonjour', {}); } // parle au bus",
|
||
' });',
|
||
'',
|
||
" return { unmount: function () { container.innerHTML = ''; } };",
|
||
' }',
|
||
'',
|
||
' window.jOSApps[ID] = {',
|
||
" manifest: { id: ID, name: '" + q(id) + "', icon: '✨' },",
|
||
' mount: mount,',
|
||
' describe: function () {',
|
||
" return { v: 1, id: ID, title: '" + q(id) + "', icon: '✨', items: [",
|
||
" { p: 1, kind: 'text', label: 'né dans l\\'atelier' }",
|
||
' ] };',
|
||
' }',
|
||
' };',
|
||
'})();',
|
||
SCRIPT_END,
|
||
''
|
||
];
|
||
return L.join('\n');
|
||
}
|
||
|
||
// ================= la preview : le runner de l'iframe sandbox (pattern premier-ploxion) =================
|
||
function runnerFn() {
|
||
'use strict';
|
||
function post(m) { try { parent.postMessage(m, '*'); } catch (e) {} }
|
||
var errors = [];
|
||
window.onerror = function (msg, src, line) {
|
||
errors.push(String(msg));
|
||
post({ xbAtl: 1, t: 'err', msg: String(msg) + (line ? ' (ligne ' + line + ')' : '') });
|
||
return true;
|
||
};
|
||
window.addEventListener('unhandledrejection', function (e) {
|
||
var m = (e.reason && e.reason.message) || String(e.reason || 'promesse rejetée');
|
||
errors.push(m); post({ xbAtl: 1, t: 'err', msg: 'promesse rejetée : ' + m });
|
||
});
|
||
// --- stubs de l'environnement jOS (le miroir de bin/verify-ploxion.mjs) ---
|
||
var noop = function () {};
|
||
window.jOSApps = {};
|
||
var subs = {};
|
||
window.jOSPorts = {
|
||
emit: function (id, port, payload) {
|
||
var topic = 'ploxion.' + id + (port ? '.' + port : '');
|
||
post({ xbAtl: 1, t: 'bus', topic: topic, payload: payload });
|
||
(subs[topic] || []).concat(subs['*'] || []).forEach(function (cb) { try { cb(payload, topic); } catch (e) {} });
|
||
return topic;
|
||
},
|
||
on: function (topic, cb) { (subs[topic] = subs[topic] || []).push(cb); return function () { subs[topic] = (subs[topic] || []).filter(function (x) { return x !== cb; }); }; },
|
||
io: function () { return { emit: noop, on: function () { return noop; } }; },
|
||
off: noop, list: function () { return []; }, topics: function () { return Object.keys(subs); }
|
||
};
|
||
var storeStub = function () { return { all: function () { return []; }, get: function (d) { return d === undefined ? null : d; }, upsert: noop, add: noop, put: noop, remove: noop, clear: noop, save: noop, load: function (d) { return d === undefined ? null : d; }, list: function () { return []; } }; };
|
||
window.jOSb = {
|
||
esc: function (s) { return String(s == null ? '' : s).replace(/[<>&"]/g, function (c) { return { '<': '<', '>': '>', '&': '&', '"': '"' }[c]; }); },
|
||
toast: function (m) { post({ xbAtl: 1, t: 'toast', msg: String(m) }); },
|
||
copy: noop, csrf: function () { return 'atelier'; }, confirm: function () { return Promise.resolve(true); },
|
||
fetchJSON: function () { return Promise.resolve({}); }, store: storeStub, cue: noop, mark: noop, on: function () { return noop; }
|
||
};
|
||
window.jOSStore = storeStub;
|
||
window.jOSBoxion = {
|
||
authed: function () { return false; },
|
||
save: function () { return Promise.resolve({ ok: false, offline: true }); }, saveSoon: noop,
|
||
load: function () { return Promise.resolve(null); }, list: function () { return Promise.resolve([]); },
|
||
del: function () { return Promise.resolve({ ok: false }); }, get: function () { return null; },
|
||
user: function () { return { name: 'atelier' }; }, store: storeStub
|
||
};
|
||
window.jOS = { openPloxion: noop, open: function () { return null; }, toggleWin: noop, closeWin: noop };
|
||
window.jOSGame = { event: noop, bion: noop, xp: noop, on: function () { return noop; }, progress: function () { return 0; }, level: function () { return 1; }, counts: function () { return {}; }, state: function () { return {}; } };
|
||
// bions courants : proxy permissif — l'aperçu dégrade doux, il ne plante pas
|
||
function perm() { return new Proxy(function () {}, { get: function (t, p) { if (p === 'then') return undefined; if (p === Symbol.toPrimitive) return function () { return ''; }; return perm(); }, apply: function () { return perm(); } }); }
|
||
['jOSChart', 'jOSSound', 'jOSPlayer', 'jOSKion', 'jOSMobile', 'jOSMap', 'jOSSwipe', 'jOSApi', 'jOSApiDriver',
|
||
'jOSRepoverse', 'jOSPlug', 'jOSForge', 'jOSTsoin', 'jOSQR', 'jOSui', 'jOSSensor', 'jOSCarte', 'jOSSDK'].forEach(function (n) { window[n] = perm(); });
|
||
window.fetch = function () { return Promise.resolve({ ok: true, status: 200, headers: { get: function () { return null; } }, json: function () { return Promise.resolve({}); }, text: function () { return Promise.resolve(''); }, blob: function () { return Promise.resolve(new Blob()); }, clone: function () { return this; } }); };
|
||
// (07.11) l'animation réelle : un ploxion qui dessine image par image (une fractale, un jeu) doit se voir tourner dans l'aperçu ;
|
||
// l'iframe est isolée (sandbox sans même-origine) et rendue invisible = le navigateur la ralentit lui-même
|
||
// --- exécute le code du brouillon (celui de l'utilisateur LUI-MÊME — self-XSS ok) ---
|
||
var okRun = true;
|
||
try { (0, eval)(window.__ATL_CODE__); }
|
||
catch (e) { okRun = false; post({ xbAtl: 1, t: 'err', msg: 'le script a levé : ' + e.message }); }
|
||
var expectId = window.__ATL_ID__ || null;
|
||
var ids = Object.keys(window.jOSApps);
|
||
var id = (expectId && window.jOSApps[expectId]) ? expectId : ids[0];
|
||
var app = id ? window.jOSApps[id] : null;
|
||
if (!app || typeof app.mount !== 'function') {
|
||
post({ xbAtl: 1, t: 'mounted', ok: false, msg: okRun ? 'rien d\'enregistré dans jOSApps' + (expectId ? ' sous « ' + expectId + ' »' : '') + ' (trouvé : ' + (ids.join(', ') || 'rien') + ')' : 'le script a levé' });
|
||
return;
|
||
}
|
||
var root = document.getElementById('root'); var handle = null; var threw = null;
|
||
try { handle = app.mount(root, { id: id }); } catch (e) { threw = e; }
|
||
function inspect(el, eventName) {
|
||
if (!el || el === root || !root.contains(el)) return;
|
||
var r = el.getBoundingClientRect(), attrs = {};
|
||
Array.prototype.forEach.call(el.attributes || [], function (a) { attrs[a.name] = a.value; });
|
||
post({ xbAtl: 1, t: 'inspect', event: eventName, tag: el.tagName.toLowerCase(), id: el.id || '',
|
||
classes: el.className && typeof el.className === 'string' ? el.className : '',
|
||
attrs: attrs, text: (el.textContent || '').trim().slice(0, 120),
|
||
rect: { x: Math.round(r.x), y: Math.round(r.y), width: Math.round(r.width), height: Math.round(r.height) } });
|
||
}
|
||
root.addEventListener('mouseover', function (e) {
|
||
if (e.target && e.target.closest) inspect(e.target.closest('*'), 'survol');
|
||
}, true);
|
||
root.addEventListener('click', function (e) {
|
||
if (e.target && e.target.closest) inspect(e.target.closest('*'), 'sélection');
|
||
}, true);
|
||
setTimeout(function () {
|
||
var rendered = (root.innerHTML || '').replace(/\s+/g, '').length;
|
||
post({ xbAtl: 1, t: 'mounted', ok: !threw && rendered > 0 && !errors.length, id: id, rendered: rendered,
|
||
unmount: !!(handle && typeof handle.unmount === 'function'),
|
||
msg: threw ? ('mount() a levé : ' + threw.message) : (rendered ? '' : 'rien n\'est rendu') });
|
||
// (07.11) la vue xerploxion : le describe() part au parent (puis toutes les 2 s : l'état vivant), dessiné sur tous les écrans des xers
|
||
var envoyerXui = function () { var x = null, er = ''; try { x = typeof app.describe === 'function' ? app.describe() : null; } catch (e) { er = e.message; } try { post({ xbAtl: 1, t: 'xui', xui: x ? JSON.parse(JSON.stringify(x)) : null, err: er }); } catch (e2) { post({ xbAtl: 1, t: 'xui', xui: null, err: 'describe() pas sérialisable : ' + e2.message }); } };
|
||
envoyerXui(); setInterval(envoyerXui, 2000);
|
||
}, 150);
|
||
}
|
||
|
||
function frameHtml(rawSource, opts) {
|
||
// le blade édité : on extrait <style> et <script> comme bin/verify-ploxion.mjs
|
||
var styles = [], scripts = [], m;
|
||
var reSty = new RegExp('<style[^>]*>([\\s\\S]*?)<\\/style>', 'g');
|
||
var reScr = new RegExp('<script[^>]*>([\\s\\S]*?)<\\/script>', 'g');
|
||
while ((m = reSty.exec(rawSource)) !== null) styles.push(m[1]);
|
||
while ((m = reScr.exec(rawSource)) !== null) { if (/function|=>/.test(m[1])) scripts.push(m[1]); }
|
||
var code = scripts.length ? scripts.join('\n;\n') : rawSource; // pas de balise = du JS nu
|
||
// ⚠️ sécurité : le code part en JSON avec TOUS les < échappés — une séquence de
|
||
// fermeture de script ne peut pas s'échapper de l'injection.
|
||
var inj = 'window.__ATL_CODE__=' + JSON.stringify(String(code)).replace(/</g, '\\u003c') + ';'
|
||
+ 'window.__ATL_ID__=' + JSON.stringify(String(opts.id || '')).replace(/</g, '\\u003c') + ';';
|
||
var S = '<' + 'script>';
|
||
return '<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">'
|
||
+ '<style>html,body{margin:0;min-height:100%;background:#0a0f18;color:#e7f0ff;font-family:ui-sans-serif,system-ui}#root{position:relative;min-height:96vh}</style>'
|
||
+ '<style>' + styles.join('\n').replace(new RegExp('<\\/style', 'gi'), '') + '</style>'
|
||
+ '</head><body><div id="root"></div>'
|
||
+ S + inj + SCRIPT_END
|
||
+ S + '(' + runnerFn.toString() + ')();' + SCRIPT_END
|
||
+ '</body></html>';
|
||
}
|
||
|
||
// ================= verify-lite : les heuristiques des missions, côté client =================
|
||
function liteChecks(src, id) {
|
||
var out = [];
|
||
function ck(level, ok, label, hint) { out.push({ level: level, ok: !!ok, label: label, hint: ok ? '' : (hint || '') }); }
|
||
// un blade légitime a autant de <script que de fermetures ; une fermeture DE PLUS =
|
||
// la séquence vit dans une string JS → elle TRONQUERA le fichier (piège n°1)
|
||
var opens = (src.match(/<script/gi) || []).length;
|
||
var closes = (src.match(new RegExp('<\\/script', 'gi')) || []).length;
|
||
ck('ko', closes <= opens, 'pas de séquence ' + SCRIPT_END + ' en clair dans le code', 'une fermeture de script de plus que d\'ouvertures : dans une string JS elle TRONQUE le blade — écris <\\/script>');
|
||
ck('ko', src.length <= MAX, 'taille ≤ 512 Ko', Math.round(src.length / 1024) + ' Ko — trop gros pour la file');
|
||
ck('ko', /jOSApps\s*\[/.test(src) || /jOSApps\./.test(src), 'enregistré dans window.jOSApps', 'le contrat : window.jOSApps[\'' + id + '\'] = { manifest, mount }');
|
||
ck('ko', /mount\s*[:=(]/.test(src), 'mount présent', 'mount(container) → { unmount } — sans lui, pas d\'écran');
|
||
ck('warn', /manifest\s*[:=]/.test(src), 'manifest présent (id, name, icon)', 'la carte d\'identité du ploxion');
|
||
ck('warn', /unmount\s*[:=]/.test(src), 'unmount présent (le droit au silence)', 'retourne { unmount } depuis mount()');
|
||
var inner = src.indexOf('innerHTML') >= 0;
|
||
ck('warn', !inner || /\besc\s*\(|jOSb\.esc|textContent/.test(src), 'esc() sur le HTML (la muraille XSS)', 'innerHTML sans esc() repéré — toute donnée passe par jOSb.esc()');
|
||
// (07.11) RS-7 : « la vue xerploxion, il faut l'implémenter tout le temps » : sans describe(), le ploxion n'existe sur aucun xer
|
||
ck('ko', /describe\s*[:=]/.test(src), 'describe() XUI (la vue xerploxion)', 'obligatoire : décrit en p1–p5, le ploxion s\'affiche sur tous les xers (32×32 d\'un cubion, montre, HUD, bureau)');
|
||
return out;
|
||
}
|
||
function checksLight(list) {
|
||
var red = list.some(function (c) { return c.level === 'ko' && !c.ok; });
|
||
var orange = list.some(function (c) { return c.level === 'warn' && !c.ok; });
|
||
return red ? 'red' : (orange ? 'orange' : 'green');
|
||
}
|
||
|
||
// ================= coloration légère (moteur premier-ploxion + jOS*) =================
|
||
function hl(code) {
|
||
var s = String(code).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||
return s.replace(/(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\\n])*'?)|("(?:\\.|[^"\\\n])*"?)|(\bjOS[A-Za-z0-9]+\b)|\b(function|return|var|let|const|if|else|for|while|new|typeof|try|catch|window|document|true|false|null|this)\b|(\b\d+(?:\.\d+)?\b)/g,
|
||
function (m0, c, s1, s2, j, k) {
|
||
var cls = c ? 'c' : (s1 || s2) ? 's' : j ? 'j' : k ? 'k' : 'n';
|
||
return '<span class="atl__h-' + cls + '">' + m0 + '</span>';
|
||
});
|
||
}
|
||
|
||
// ================= le diff simple (préfixe/suffixe communs — zéro lib) =================
|
||
function simpleDiff(oldS, newS) {
|
||
var a = String(oldS).split('\n'), b = String(newS).split('\n');
|
||
var i = 0, j = 0;
|
||
while (i < a.length && i < b.length && a[i] === b[i]) i++;
|
||
while (j < (a.length - i) && j < (b.length - i) && a[a.length - 1 - j] === b[b.length - 1 - j]) j++;
|
||
return { pre: b.slice(Math.max(0, i - 3), i), preAt: i, del: a.slice(i, a.length - j), add: b.slice(i, b.length - j), post: b.slice(b.length - j, Math.min(b.length, b.length - j + 3)) };
|
||
}
|
||
function renderDiff(oldS, newS) {
|
||
var d = simpleDiff(oldS, newS);
|
||
var h = '<div class="atl__diff">';
|
||
h += '<div class="hunk">@@ ligne ' + (d.preAt + 1) + ' · −' + d.del.length + ' +' + d.add.length + ' @@</div>';
|
||
d.pre.forEach(function (l) { h += '<div class="ctx"> ' + esc(l) + '</div>'; });
|
||
var cap = 400;
|
||
d.del.slice(0, cap).forEach(function (l) { h += '<div class="del">− ' + esc(l) + '</div>'; });
|
||
if (d.del.length > cap) h += '<div class="del">− … ' + (d.del.length - cap) + ' lignes de plus …</div>';
|
||
d.add.slice(0, cap).forEach(function (l) { h += '<div class="add">+ ' + esc(l) + '</div>'; });
|
||
if (d.add.length > cap) h += '<div class="add">+ … ' + (d.add.length - cap) + ' lignes de plus …</div>';
|
||
d.post.forEach(function (l) { h += '<div class="ctx"> ' + esc(l) + '</div>'; });
|
||
h += '</div>';
|
||
return h;
|
||
}
|
||
|
||
// ================= le ploxion =================
|
||
function mount(container, ctx) {
|
||
var st = { view: 'pick', id: null, meta: null, src: '', orig: '', note: '', dirty: false, savedAt: '',
|
||
hist: [], q: '', queue: null, admin: false, detail: null, sent: null, dead: false, full: false,
|
||
mode: 'code', device: 'desktop', inspect: null };
|
||
var busLog;
|
||
|
||
container.innerHTML =
|
||
'<div class="atl"><div class="atl__h">' +
|
||
'<div class="atl__ht"><b>🛠 Atelier</b><small data-sub>prends un ploxion · modifie · envoie le tsoin — c\'est ça, le commit</small></div>' +
|
||
'<div class="atl__tabs">' +
|
||
'<button class="atl__tab" data-tab="pick">🧩 prendre</button>' +
|
||
'<button class="atl__tab" data-tab="edit">✏️ l\'établi</button>' +
|
||
'<button class="atl__tab" data-tab="queue">⧗ la file</button>' +
|
||
'<button class="atl__tab" data-tab="recus">⇄ reçus</button>' +
|
||
'</div></div>' +
|
||
'<div class="atl__b" data-body></div></div>';
|
||
|
||
var body = container.querySelector('[data-body]');
|
||
function $(sel) { return container.querySelector(sel); }
|
||
|
||
// toast maison (le jOSb.toast réel a une autre signature host-based — on reste autonome)
|
||
function toast(msg) {
|
||
try {
|
||
var root = container.querySelector('.atl');
|
||
if (!root) return;
|
||
var t = document.createElement('div');
|
||
t.className = 'atl__toast'; t.textContent = msg;
|
||
root.appendChild(t);
|
||
setTimeout(function () { try { t.remove(); } catch (e) {} }, 2300);
|
||
} catch (e) {}
|
||
}
|
||
|
||
// ---------- navigation ----------
|
||
// ---- ⇄ LA BOÎTE : ce qu'on m'a partagé (07.11 ; RS-7 : « partager mon atelier sur epsylaeu » ; AtelierPartageController) ----
|
||
function renderRecus() {
|
||
if (!st.recus) { jget('/atelier/recus').then(function (j) { st.recus = j.recus || []; if (!st.dead && st.view === 'recus') render(); }).catch(function () { st.recus = []; if (!st.dead && st.view === 'recus') render(); }); return '<div class="atl__msg">chargement de ta boîte…</div>'; }
|
||
var h = '<div class="atl__sec">⇄ reçus <small>les brouillons qu\'on t\'a partagés : vois-les tourner, prends-les dans ton établi, renvoie ton tsoin</small></div>';
|
||
if (!st.recus.length) return h + '<div class="atl__msg">rien encore. Dans l\'établi, « ⇄ partager » envoie ton brouillon à un ami.</div>';
|
||
st.recus.forEach(function (x) {
|
||
h += '<div class="atl__row" style="display:block;cursor:default"><b>' + esc(x.ploxion) + '</b> <span class="atl__chip">' + esc(x.nom_de) + '</span> <span class="atl__chip">' + esc(String(x.lignes || '')) + ' lignes</span> <span class="atl__chip">' + esc((x.at || '').slice(0, 16).replace('T', ' ')) + '</span>' +
|
||
(x.note ? '<div class="atl__note">« ' + esc(x.note) + ' »</div>' : '') +
|
||
'<div style="display:flex;gap:7px;flex-wrap:wrap;margin:6px 0"><button class="atl__btn" data-rapercu="' + esc(x.uid) + '">▶ aperçu</button><button class="atl__btn atl__btn--go" data-rprendre="' + esc(x.uid) + '">⇩ prendre dans mon établi</button><button class="atl__btn" data-roublier="' + esc(x.uid) + '">✕</button></div>' +
|
||
'<iframe class="atl__frame" data-rframe="' + esc(x.uid) + '" sandbox="allow-scripts" title="le brouillon partagé (bac à sable)"></iframe></div>';
|
||
});
|
||
return h;
|
||
}
|
||
function wireRecus() {
|
||
container.querySelectorAll('[data-rapercu]').forEach(function (b) { b.addEventListener('click', function () {
|
||
var u = b.getAttribute('data-rapercu'), fr = container.querySelector('[data-rframe="' + u + '"]');
|
||
jget('/atelier/recus/' + encodeURIComponent(u)).then(function (x) { fr.classList.add('on'); fr.srcdoc = frameHtml(x.source || '', { id: x.ploxion }); });
|
||
}); });
|
||
container.querySelectorAll('[data-rprendre]').forEach(function (b) { b.addEventListener('click', function () {
|
||
var u = b.getAttribute('data-rprendre'); b.disabled = true; b.textContent = '…';
|
||
jget('/atelier/recus/' + encodeURIComponent(u)).then(function (x) {
|
||
return jpost('/atelier/draft/' + encodeURIComponent(x.ploxion), { source: x.source, note: 'partagé par ' + x.nom_de }).then(function () { take(x.ploxion); });
|
||
}).catch(function (e) { b.disabled = false; b.textContent = '✕ ' + (e.message || e); });
|
||
}); });
|
||
container.querySelectorAll('[data-roublier]').forEach(function (b) { b.addEventListener('click', function () {
|
||
jpost('/atelier/recus/' + encodeURIComponent(b.getAttribute('data-roublier')) + '/oublier', {}).then(function () { st.recus = null; render(); });
|
||
}); });
|
||
}
|
||
function setTab(v) {
|
||
st.view = v; st.detail = null;
|
||
if (v === 'recus') st.recus = null;
|
||
if (v === 'queue' && !st.queue) refreshQueue();
|
||
render();
|
||
}
|
||
container.querySelectorAll('.atl__tab').forEach(function (b) {
|
||
b.addEventListener('click', function () { setTab(b.getAttribute('data-tab')); });
|
||
});
|
||
|
||
// ---------- l'entrée : prendre un ploxion ----------
|
||
function renderPick() {
|
||
var h = '<input class="atl__in" data-q placeholder="chercher un ploxion : id, nom, description…" value="' + esc(st.q) + '">';
|
||
h += '<div class="atl__tiles">' +
|
||
'<button class="atl__tile" data-new><b>✨ crée un nouveau</b><small>pars du squelette hello-toi, baptise-le, il naît ici</small></button>' +
|
||
'<button class="atl__tile" data-goqueue><b>⧗ mes tsoins (' + sentCount() + ')</b><small>tes contributions envoyées, et leurs statuts</small></button>' +
|
||
'<button class="atl__tile" data-vscode><b>◇ depuis VS Code</b><small>Windows, Mac, Linux : tu codes dans ton VS Code, ça tourne ici</small></button></div>';
|
||
if (st.vsc) h += renderVscode();
|
||
if (!REG) { h += '<div class="atl__msg">chargement du registre…<br><small>si ça dure : il faut être <a href="/login">connecté</a> (compte normal).</small></div>'; return h; }
|
||
var q = st.q.toLowerCase();
|
||
if (q) {
|
||
var rows = (REG.ploxions || []).filter(function (p) {
|
||
return p.id.indexOf(q) !== -1 || (p.name || '').toLowerCase().indexOf(q) !== -1 || (p.description || '').toLowerCase().indexOf(q) !== -1;
|
||
}).slice(0, 40);
|
||
h += '<div class="atl__sec">résultats <small>' + rows.length + ' — toute la carte = prendre</small></div>';
|
||
if (!rows.length) h += '<div class="atl__note">rien — « ✨ crée un nouveau » pour le faire naître sous ce nom.</div>';
|
||
rows.forEach(function (p) {
|
||
h += '<button class="atl__row" data-take="' + esc(p.id) + '"><span class="ic">' + esc(p.icon) + '</span>' +
|
||
'<span class="mid"><b>' + esc(p.name) + ' · ' + esc(p.id) + '</b><small>' + esc(p.description || '—') + '</small></span>' +
|
||
(p.todo > 0 ? '<span class="atl__chip atl__chip--o">🎯 ' + p.todo + '</span>' : '<span class="atl__chip atl__chip--v">✓</span>') +
|
||
'</button>';
|
||
});
|
||
} else {
|
||
h += '<div class="atl__sec">🎯 les missions du jour <small>tirage du ' + esc(new Date().toISOString().slice(0, 10)) + ' — toute la carte = prendre</small></div>';
|
||
missionsDuJour(REG, 5).forEach(function (x) {
|
||
// carte-bouton UNIQUE : flux statique strict, rien qui flotte hors de sa carte
|
||
h += '<button class="atl__mi" data-take="' + esc(x.p.id) + '">' +
|
||
'<span class="atl__mit"><span class="ic">' + esc(x.m.icon) + '</span><b>' + esc(x.m.t) + '</b>' +
|
||
'<span class="atl__diffb atl__diffb--' + esc(x.m.diff || 'facile') + '">' + esc(x.m.diff || '') + '</span></span>' +
|
||
'<span class="atl__miw" style="display:block">' + esc(x.p.icon) + ' ' + esc(x.p.name) + ' — ' + esc(x.m.why) + '</span>' +
|
||
'<span class="atl__mia"><span class="atl__take">🛠 prendre ' + esc(x.p.id) + '</span></span>' +
|
||
'</button>';
|
||
});
|
||
h += '<div class="atl__note">…ou cherche n\'importe lequel des ' + (REG.count || '?') + ' ploxions du registre ci-dessus.</div>';
|
||
}
|
||
return h;
|
||
}
|
||
|
||
// ---------- ◇ VS Code (27.10, RS-7 : « contribuer au xerboxion sur Windows, avoir mon vscode, créer des ploxions, les envoyer
|
||
// au nexus ») : bin/xb.mjs pousse le fichier en brouillon à chaque sauvegarde ; l'établi lié le suit et relance l'aperçu. ----------
|
||
function renderVscode() {
|
||
var o = location.origin;
|
||
var h = '<div class="atl__send" data-vsc>' +
|
||
'<b style="font-size:.9rem">◇ contribuer depuis VS Code</b>' +
|
||
'<div class="atl__note">1 · sur Windows, dans PowerShell (il installe <code>xb</code> dans ton dossier xerboxion, et Node si besoin) :</div>' +
|
||
'<pre class="atl__vcmd">irm ' + esc(o) + '/downloads/xb/installer.ps1 | iex</pre>' +
|
||
'<div class="atl__note">WSL (conseillé sous Windows), Linux, Mac : <code>curl -fsSL ' + esc(o) + '/downloads/xb/installer.sh | sh</code> — puis <code>xb local demarrer</code> pour le xerboxion entier chez toi.</div>' +
|
||
'<div class="atl__note">2 · ton jeton (droit « atelier » seulement : lire un source, sauver ton brouillon, envoyer ton tsoin). Il n\'est montré qu\'une fois ; <code>xb init</code> te le demande.</div>';
|
||
h += st.vscJeton
|
||
? '<pre class="atl__vcmd" data-vjet>' + esc(st.vscJeton) + '</pre><button class="atl__btn" data-vcopy>⎘ copier</button>'
|
||
: '<button class="atl__btn atl__btn--go" data-vjeton>◇ créer mon jeton VS Code</button>';
|
||
h += '<div class="atl__note">3 · puis : <code>xb nouveau mon-ploxion</code> (ou <code>xb prendre carte</code>) → <code>xb dev mon-ploxion</code> : VS Code s\'ouvre, cette page aussi ; chaque Ctrl+S relance l\'aperçu ici. <code>xb envoyer mon-ploxion "pourquoi"</code> = le tsoin → la file → le nexus.</div>' +
|
||
'<div class="atl__note">révoquer : Réglages › Données › Jetons d\'accès.</div></div>';
|
||
return h;
|
||
}
|
||
function creerJetonVscode() {
|
||
var nom = 'VS Code';
|
||
try { if (window.jOSAppareil && jOSAppareil.nom) nom = 'VS Code · ' + jOSAppareil.nom(); } catch (e) {}
|
||
jpost('/px/jetons', { nom: nom, scopes: ['atelier'] }).then(function (j) {
|
||
if (st.dead) return;
|
||
if (j._status !== 201 || !j.jeton) { toast('✗ ' + (j.error || ('http ' + j._status))); return; }
|
||
st.vscJeton = j.jeton; render();
|
||
}).catch(function () { toast('✗ réseau'); });
|
||
}
|
||
// l'établi LIÉ : tant que la page est visible, on relit le brouillon (1,5 s) ; s'il a bougé (un Ctrl+S dans VS Code), on le reprend
|
||
var lieTimer = null, lieVu = '';
|
||
function lier(on) {
|
||
st.lie = !!on;
|
||
if (lieTimer) { clearInterval(lieTimer); lieTimer = null; }
|
||
if (!st.lie) return;
|
||
lieTimer = setInterval(function () {
|
||
if (st.dead || !st.id || st.view !== 'edit' || document.hidden || st.lieEnCours) return;
|
||
var id = st.id; st.lieEnCours = true;
|
||
jget('/atelier/source/' + encodeURIComponent(id)).then(function (j) {
|
||
st.lieEnCours = false;
|
||
var d = j && j.draft;
|
||
if (st.dead || st.id !== id || !d || !d.savedAt || d.savedAt === lieVu) return;
|
||
lieVu = d.savedAt;
|
||
if (d.source === st.src) return;
|
||
st.src = d.source; st.savedAt = d.savedAt; st.dirty = false; st.meta = st.meta || j;
|
||
if (st._recharger) st._recharger(); else render();
|
||
}).catch(function () { st.lieEnCours = false; });
|
||
}, 1500);
|
||
}
|
||
|
||
// ---------- charger un ploxion dans l'établi ----------
|
||
function take(id, fresh) {
|
||
st.id = id; st.view = 'edit'; st.meta = null; st.src = ''; st.orig = ''; st.dirty = false; st.hist = []; st.savedAt = ''; st.sent = null;
|
||
render();
|
||
jget('/atelier/source/' + encodeURIComponent(id)).then(function (j) {
|
||
if (st.dead || st.id !== id) return;
|
||
st.meta = j;
|
||
// le brouillon de L'UTILISATEUR d'abord (c'est le sien — jamais celui d'un autre), sinon le repo
|
||
st.src = (!fresh && j.draft && j.draft.source) ? j.draft.source : (j.source || '');
|
||
st.orig = j.source || ''; // le source original du repo : ⧗ reste gardé tant que rien ne change
|
||
st.savedAt = (j.draft && j.draft.savedAt) ? j.draft.savedAt : '';
|
||
render();
|
||
toast('🛠 ' + id + ' sur l\'établi' + ((j.draft && !fresh) ? ' — ton brouillon repris' : ''));
|
||
}).catch(function (e) {
|
||
if (st.dead) return;
|
||
if (e.status === 404) {
|
||
// pas au registre, pas de brouillon → une création : le squelette
|
||
st.meta = { id: id, in_registry: false, name: id, icon: '✨', rel: 'resources/views/ploxions/' + id + '/app.blade.php' };
|
||
st.src = squelette(id); st.orig = ''; st.dirty = true;
|
||
render();
|
||
toast('✨ ' + id + ' — un nouveau ploxion naît sur l\'établi');
|
||
} else {
|
||
st.meta = { error: e.message }; render();
|
||
}
|
||
});
|
||
}
|
||
|
||
// ---------- l'établi ----------
|
||
function renderEdit() {
|
||
if (!st.id) return '<div class="atl__msg">rien sur l\'établi — onglet 🧩 prendre.</div>';
|
||
if (!st.meta) return '<div class="atl__msg">… le source arrive …</div>';
|
||
if (st.meta.error) return '<div class="atl__msg">✗ ' + esc(st.meta.error) + '</div>';
|
||
var h = '<div class="atl__ehd">' +
|
||
'<b>' + esc(st.meta.icon || '▣') + ' ' + esc(st.id) + '</b>' +
|
||
(st.meta.in_registry ? '<span class="atl__chip">' + esc(st.meta.rel || '') + '</span>' : '<span class="atl__chip atl__chip--o">✨ création</span>') +
|
||
'<a class="atl__chip" href="/dev/ploxion/' + encodeURIComponent(st.id) + '" target="_blank" rel="noopener" style="text-decoration:none;color:inherit">📄 la fiche</a>' +
|
||
'<button class="atl__chip' + (st.lie ? ' atl__chip--v' : '') + '" data-lier title="suivre les Ctrl+S de VS Code (xb dev)" style="background:none;cursor:pointer">' + (st.lie ? '◆ lié à VS Code' : '◇ lier à VS Code') + '</button>' +
|
||
'</div>';
|
||
h += '<div class="atl__bar">' +
|
||
'<button class="atl__tool" data-undo title="annuler">↶</button>' +
|
||
'<button class="atl__tool" data-indent title="indenter">⇥</button>' +
|
||
'<button class="atl__tool" data-findtog title="chercher dans le code">🔍</button>' +
|
||
'<button class="atl__tool" data-reset title="recharger le source du repo">♻️</button>' +
|
||
'<button class="atl__btn atl__btn--go" data-run>▶ voir tourner</button>' +
|
||
'<button class="atl__btn" data-partager title="envoyer ce brouillon à un ami (sa boîte : atelier › ⇄ reçus)">⇄ partager</button>' +
|
||
'<button class="atl__tool" data-full title="plein écran">⛶</button>' +
|
||
'<span class="atl__status" data-status>' + (st.savedAt ? '💾 brouillon du ' + esc(st.savedAt.slice(0, 16).replace('T', ' ')) : 'pas encore de brouillon') + '</span>' +
|
||
'</div>';
|
||
h += '<div class="atl__find" data-find><input class="atl__in" data-findq placeholder="chercher… (entrée = suivant)"><button class="atl__btn" data-findgo>↓</button></div>';
|
||
h += '<div class="atl__modebar">' +
|
||
'<button class="atl__mode' + (st.mode === 'ui' ? ' on' : '') + '" data-mode="ui">◇ mode UI</button>' +
|
||
'<button class="atl__mode' + (st.mode === 'code' ? ' on' : '') + '" data-mode="code">⌘ mode code</button>' +
|
||
'<button class="atl__mode' + (st.mode === 'test' ? ' on' : '') + '" data-mode="test">▶ mode test</button>' +
|
||
'<select class="atl__device" data-device aria-label="vue de sortie"><option value="desktop">bureau · 100%</option><option value="phone">téléphone · 390px</option><option value="tablet">iPad · 768px</option><option value="watch">montre · 240px</option><option value="xer">xer · 520px</option></select>' +
|
||
'</div>';
|
||
h += '<div class="atl__workbench atl__mode-' + esc(st.mode || 'code') + '" data-workbench>' +
|
||
'<section class="atl__pane atl__codepane"><div class="atl__pane-title"><span>code source</span><span class="atl__muted">édition directe</span></div>' +
|
||
'<div class="atl__ed" data-edwrap><pre class="atl__gut" data-gut></pre>' +
|
||
'<div class="atl__code"><pre class="atl__hl" data-hl aria-hidden="true"></pre>' +
|
||
'<textarea class="atl__ta" data-ta spellcheck="false" wrap="off" autocapitalize="off" autocomplete="off" autocorrect="off"></textarea></div></div></section>' +
|
||
'<section class="atl__pane atl__previewpane"><div class="atl__pane-title"><span>aperçu vivant</span><span class="atl__muted" data-preview-status>en attente</span></div>' +
|
||
'<div class="atl__viewport" data-viewport data-device="desktop"><div class="atl__fw" data-fw><button class="atl__fx" data-unfull>✕ fermer</button><iframe class="atl__frame" data-frame sandbox="allow-scripts" title="ton ploxion qui tourne"></iframe></div></div>' +
|
||
'<div class="atl__inspect" data-inspect><b>Inspection</b><small>Survole ou clique un élément dans l’aperçu en mode UI pour retrouver son tag, ses attributs, sa taille et sa ligne probable.</small></div>' +
|
||
'<div class="atl__inspecttools" data-inspecttools style="display:none"><label>W <input data-ui-width type="number" min="1" max="2400"></label><label>H <input data-ui-height type="number" min="1" max="1600"></label><button data-apply-size>appliquer la taille</button></div></section></div>';
|
||
h += '<div class="atl__log" data-log></div>';
|
||
// (07.11) RS-7 : « il faut pouvoir voir toutes les vues dans l'atelier, et surtout sur les xers qu'on va mettre dans les cubions »
|
||
h += '<div class="atl__sec">◫ les vues <small>le describe() sur les écrans des xers (jOSXerVues) ; ▶ voir tourner pour les remplir</small></div><div data-vues class="atl__note">▶ voir tourner : chaque écran montre ce que ton ploxion y dit</div>';
|
||
h += '<div class="atl__sec">✅ les checks (verify-lite)</div><div data-checks></div>';
|
||
h += '<div class="atl__send" data-send>' +
|
||
'<b style="font-size:.9rem">⧗ envoyer le tsoin</b>' +
|
||
'<div class="atl__note" style="margin:4px 0 0">la contribution scellée : ton source complet + ta note partent dans la file — une session Claude l\'applique au repo. La note (1 ligne) : <b>pourquoi</b> ce tsoin.</div>' +
|
||
'<div class="atl__sendrow"><input class="atl__in" data-note maxlength="300" placeholder="pourquoi : ex. « ajoute le describe() XUI manquant »" value="' + esc(st.note) + '">' +
|
||
'<button class="atl__btn atl__btn--go" data-tsoin>⧗ ENVOYER LE TSOIN</button></div>' +
|
||
'<div data-sent></div></div>';
|
||
// la barre pouce : ▶ et ⧗ toujours sous le pouce en mobile (sticky bas)
|
||
h += '<div class="atl__sticky"><button class="atl__btn" data-run2>▶ voir tourner</button>' +
|
||
'<button class="atl__btn atl__btn--go" data-tsoin2>⧗ envoyer le tsoin</button></div>';
|
||
return h;
|
||
}
|
||
|
||
function wireEdit() {
|
||
var ta = $('[data-ta]'), pre = $('[data-hl]'), gut = $('[data-gut]'), frame = $('[data-frame]');
|
||
// ◫ les vues : le describe() que l'aperçu renvoie, dessiné sur chaque écran de xer
|
||
var vuesEl = $('[data-vues]'), vues = null;
|
||
if (st._onMsg) window.removeEventListener('message', st._onMsg);
|
||
st._onMsg = function (ev) {
|
||
if (!frame || ev.source !== frame.contentWindow) return;
|
||
var d = ev.data; if (!d || !d.xbAtl || d.t !== 'xui' || !vuesEl) return;
|
||
if (!d.xui) { vues = null; vuesEl.innerHTML = '<b style="color:#ff8a8a">✕ pas de vue xerploxion</b> : ' + esc(d.err || 'ce ploxion n\'a pas de describe()') + '. Sans lui, il n\'existe sur aucun xer (le 32×32 d\'un cubion, la montre, le HUD). Ajoute <code>describe: function () { return { v: 1, id, title, icon, items: [{ p: 1, kind: \'stat\', label, value }] }; }</code>'; return; }
|
||
if (!window.jOSXerVues) { vuesEl.textContent = 'le bion jOSXerVues manque ici'; return; }
|
||
st._xui = d.xui;
|
||
if (!vues) { vuesEl.innerHTML = '<div data-vg></div><div class="atl__sendrow" style="margin-top:8px"><button class="atl__btn" data-montre>⌚ sur ma montre</button><span class="atl__note" data-montre-etat style="margin:0"></span></div>'; vues = window.jOSXerVues.galerie(vuesEl.querySelector('[data-vg]'), d.xui); vuesEl.querySelector('[data-montre]').onclick = surMontre; }
|
||
else vues.maj(d.xui);
|
||
};
|
||
// ⌚ épingler ce ploxion sur la montre (XuiMontreController) : le XUI compact, que l'app Connect IQ lit avec la clé du compte
|
||
function compacter(x) {
|
||
try { if (window.jOSXui && window.jOSXui.compact) return window.jOSXui.compact(x); } catch (e) {}
|
||
return [x.id, x.title || x.id, (x.items || []).map(function (it) { return [it.p || 3, it.kind || 'stat', it.label || '', it.value == null ? '' : it.value, it.unit || '']; })];
|
||
}
|
||
function surMontre() {
|
||
var et = vuesEl.querySelector('[data-montre-etat]'); if (!st._xui) return;
|
||
var csrf = (document.querySelector('meta[name=csrf-token]') || {}).content || '';
|
||
fetch('/xui/montre', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': csrf }, body: JSON.stringify({ id: st.id, xuic: compacter(st._xui) }) })
|
||
.then(function (r) { return r.json().catch(function () { return { ok: false, erreur: 'HTTP ' + r.status }; }); })
|
||
.then(function (j) { if (et) et.innerHTML = j.ok ? '✓ sur ta montre (' + esc(j.epingles.join(', ')) + ') · clé de la montre : <b>' + esc(j.cle) + '</b> (à mettre dans Garmin Connect › l\'app xer › réglages)' : '✕ ' + esc(j.erreur || 'refusé'); })
|
||
.catch(function (e) { if (et) et.textContent = '✕ ' + e.message; });
|
||
}
|
||
window.addEventListener('message', st._onMsg);
|
||
var logEl = $('[data-log]'), statusEl = $('[data-status]');
|
||
if (!ta) return;
|
||
busLog = [];
|
||
ta.value = st.src;
|
||
var viewport = $('[data-viewport]'), device = $('[data-device]');
|
||
if (viewport) viewport.setAttribute('data-device', st.device || 'desktop');
|
||
if (device) {
|
||
device.value = st.device || 'desktop';
|
||
device.addEventListener('change', function () {
|
||
st.device = device.value;
|
||
if (viewport) viewport.setAttribute('data-device', st.device);
|
||
});
|
||
}
|
||
container.querySelectorAll('[data-mode]').forEach(function (b) {
|
||
b.addEventListener('click', function () {
|
||
st.mode = b.getAttribute('data-mode') || 'code';
|
||
render();
|
||
});
|
||
});
|
||
|
||
function paint() {
|
||
pre.innerHTML = hl(ta.value) + '\n';
|
||
var n = ta.value.split('\n').length, g = '';
|
||
for (var i = 1; i <= n; i++) g += i + '\n';
|
||
gut.textContent = g;
|
||
// le pre (statique) donne la taille, le textarea (absolu) la recouvre
|
||
ta.style.height = pre.offsetHeight + 'px';
|
||
ta.style.width = pre.offsetWidth + 'px';
|
||
}
|
||
function log(kind, msg) {
|
||
if (!logEl) return;
|
||
var d = document.createElement('div'); d.className = kind; d.textContent = msg;
|
||
logEl.appendChild(d);
|
||
while (logEl.children.length > 30) logEl.removeChild(logEl.firstChild);
|
||
logEl.scrollTop = logEl.scrollHeight;
|
||
}
|
||
st._log = log;
|
||
function sourceLine(info) {
|
||
var lines = st.src.split('\n'), needles = [];
|
||
if (info.id) needles.push('id="' + info.id + '"', "id='" + info.id + "'");
|
||
(info.classes || '').split(/\s+/).filter(Boolean).slice(0, 3).forEach(function (c) {
|
||
needles.push('.' + c, 'class="' + c, 'class=\'' + c);
|
||
});
|
||
Object.keys(info.attrs || {}).forEach(function (k) {
|
||
if (k.indexOf('data-') === 0) needles.push(k);
|
||
});
|
||
needles.push('<' + info.tag);
|
||
var best = { line: 0, score: -1 };
|
||
lines.forEach(function (line, i) {
|
||
var score = needles.reduce(function (n, needle) { return n + (line.indexOf(needle) >= 0 ? 1 : 0); }, 0);
|
||
if (score > best.score) best = { line: i + 1, score: score };
|
||
});
|
||
return best.score > 0 ? best.line : null;
|
||
}
|
||
function renderInspect(info) {
|
||
var box = $('[data-inspect]'), tools = $('[data-inspecttools]');
|
||
if (!box || !info) return;
|
||
var attrs = Object.keys(info.attrs || {}).map(function (k) { return k + (info.attrs[k] ? '="' + info.attrs[k] + '"' : ''); }).join(' ');
|
||
var line = sourceLine(info);
|
||
box.innerHTML = '<b>' + esc((info.event === 'survol' ? 'Survol' : 'Sélection') + ' · <' + info.tag + '>') + '</b>' +
|
||
'<small>' + esc((info.classes ? '.' + info.classes : '') + (info.id ? ' #' + info.id : '') + ' · ' + (info.rect ? info.rect.width + ' × ' + info.rect.height + ' px' : 'taille inconnue')) +
|
||
(line ? ' · ligne probable ' + line : ' · ligne non déterminée') + '<br>' + esc(attrs || 'aucun attribut') + '</small>';
|
||
if (tools) tools.style.display = 'flex';
|
||
var wi = $('[data-ui-width]'), hi = $('[data-ui-height]');
|
||
if (wi) wi.value = info.rect && info.rect.width || '';
|
||
if (hi) hi.value = info.rect && info.rect.height || '';
|
||
st.inspect = info;
|
||
}
|
||
if (st.messageHandler) window.removeEventListener('message', st.messageHandler);
|
||
st.messageHandler = function (e) {
|
||
if (st.dead || !e.data || e.data.xbAtl !== 1 || e.data.t !== 'inspect') return;
|
||
if (frame.contentWindow && e.source !== frame.contentWindow) return;
|
||
renderInspect(e.data);
|
||
};
|
||
window.addEventListener('message', st.messageHandler);
|
||
function selectorFor(info) {
|
||
if (info.id) return '#' + info.id;
|
||
var first = (info.classes || '').split(/\s+/).filter(Boolean)[0];
|
||
return first ? '.' + first : info.tag;
|
||
}
|
||
var applySize = $('[data-apply-size]');
|
||
if (applySize) applySize.addEventListener('click', function () {
|
||
if (!st.inspect) return;
|
||
var w = parseInt(($('[data-ui-width]') || {}).value, 10), h = parseInt(($('[data-ui-height]') || {}).value, 10);
|
||
if (!w || !h || w > 2400 || h > 1600) { log('err', 'taille invalide (1–2400 × 1–1600 px)'); return; }
|
||
var css = '<style data-atelier-ui>\n' + selectorFor(st.inspect) + ' { width: ' + w + 'px; min-height: ' + h + 'px; }\n</style>';
|
||
st.src = st.src.replace(/<style data-atelier-ui>[\s\S]*?<\/style>\s*/gi, '').replace(/\s*$/, '\n') + css + '\n';
|
||
st.dirty = true; ta.value = st.src; paint(); refreshChecks(); runPreview();
|
||
log('ok', 'taille appliquée à ' + selectorFor(st.inspect) + ' — tu peux encore l’ajuster dans le code');
|
||
});
|
||
// un Ctrl+S dans VS Code : le texte, la coloration, les checks, puis l'aperçu (sans reconstruire l'établi)
|
||
st._recharger = function () {
|
||
if (!ta.isConnected) { st._recharger = null; render(); return; }
|
||
ta.value = st.src; paint(); refreshChecks();
|
||
if (statusEl) statusEl.textContent = '◆ VS Code ' + (st.savedAt || '').slice(11, 19);
|
||
log('ok', '◆ repris de VS Code (' + st.src.length + ' o)');
|
||
runPreview();
|
||
};
|
||
var lb = $('[data-lier]');
|
||
if (lb) lb.addEventListener('click', function () { lier(!st.lie); render(); });
|
||
|
||
var histT = 0;
|
||
ta.addEventListener('input', function () {
|
||
var now = Date.now();
|
||
if (now - histT > 800) { st.hist.push(st.src); if (st.hist.length > 80) st.hist.shift(); histT = now; }
|
||
st.src = ta.value; st.dirty = true; paint(); refreshChecks();
|
||
if (statusEl) statusEl.textContent = '✏️ modifié — autosave dans 5 s';
|
||
});
|
||
ta.addEventListener('keydown', function (e) {
|
||
if (e.key === 'Tab') {
|
||
e.preventDefault();
|
||
var s = ta.selectionStart, v = ta.value;
|
||
ta.value = v.slice(0, s) + ' ' + v.slice(ta.selectionEnd);
|
||
ta.selectionStart = ta.selectionEnd = s + 2;
|
||
st.src = ta.value; st.dirty = true; paint();
|
||
}
|
||
});
|
||
|
||
$('[data-undo]').addEventListener('click', function () {
|
||
if (!st.hist.length) { log('inf', 'rien à annuler'); return; }
|
||
st.src = st.hist.pop(); ta.value = st.src; st.dirty = true; paint(); refreshChecks();
|
||
});
|
||
$('[data-indent]').addEventListener('click', function () {
|
||
var s = ta.selectionStart, v = ta.value;
|
||
ta.value = v.slice(0, s) + ' ' + v.slice(ta.selectionEnd);
|
||
ta.selectionStart = ta.selectionEnd = s + 2;
|
||
st.src = ta.value; st.dirty = true; paint(); ta.focus();
|
||
});
|
||
$('[data-findtog]').addEventListener('click', function () {
|
||
var f = $('[data-find]'); f.classList.toggle('on');
|
||
if (f.classList.contains('on')) { var q = $('[data-findq]'); if (q) q.focus(); }
|
||
});
|
||
function findNext() {
|
||
var q = ($('[data-findq]') || {}).value || '';
|
||
if (!q) return;
|
||
var from = ta.selectionEnd || 0;
|
||
var idx = ta.value.indexOf(q, from);
|
||
if (idx < 0) idx = ta.value.indexOf(q); // reboucle
|
||
if (idx < 0) { log('inf', '🔍 « ' + q + ' » introuvable'); return; }
|
||
ta.focus();
|
||
ta.selectionStart = idx; ta.selectionEnd = idx + q.length;
|
||
var line = ta.value.slice(0, idx).split('\n').length;
|
||
var lh = pre.offsetHeight / Math.max(1, ta.value.split('\n').length + 1);
|
||
$('[data-edwrap]').scrollTop = Math.max(0, (line - 4) * lh);
|
||
}
|
||
$('[data-findgo]').addEventListener('click', findNext);
|
||
$('[data-findq]').addEventListener('keydown', function (e) { if (e.key === 'Enter') { e.preventDefault(); findNext(); } });
|
||
$('[data-reset]').addEventListener('click', function () {
|
||
if (!window.confirm('Recharger le source du repo et perdre les modifs de l\'établi ? (le dernier brouillon sauvé reste sur le serveur jusqu\'au prochain autosave)')) return;
|
||
take(st.id, true);
|
||
});
|
||
|
||
// ---- la preview ----
|
||
function runPreview() {
|
||
var opens = (st.src.match(/<script/gi) || []).length;
|
||
var closes = (st.src.match(new RegExp('<\\/script', 'gi')) || []).length;
|
||
if (closes > opens) log('err', '⚠️ séquence ' + SCRIPT_END + ' en clair dans une string — elle tronquera le blade dans le repo. Écris <\\/script>.');
|
||
frame.classList.add('on');
|
||
if (statusEl) statusEl.textContent = '… ça monte …';
|
||
frame.srcdoc = frameHtml(st.src, { id: st.id });
|
||
}
|
||
$('[data-run]').addEventListener('click', runPreview);
|
||
// ⇄ partager ce brouillon : choisir un ami, il le reçoit dans sa boîte (atelier › ⇄ reçus)
|
||
var bPart = $('[data-partager]');
|
||
if (bPart) bPart.addEventListener('click', function () {
|
||
var zone = $('[data-partage]');
|
||
if (!zone) { bPart.insertAdjacentHTML('afterend', '<span data-partage style="display:inline-flex;gap:6px;align-items:center;flex-wrap:wrap"></span>'); zone = $('[data-partage]'); }
|
||
zone.innerHTML = '…';
|
||
jget('/px/friends').then(function (j) {
|
||
var l = (j.friends || []).filter(function (f) { return f.status === 'accepted'; });
|
||
if (!l.length) { zone.textContent = 'pas encore d\'amis (ploxion amis)'; return; }
|
||
zone.innerHTML = '<select class="atl__in" data-partage-a style="width:auto;padding:7px 10px">' + l.map(function (f) { return '<option value="' + f.id + '">' + esc(f.name) + '</option>'; }).join('') + '</select><button class="atl__btn atl__btn--go" data-partage-go>⇄ envoyer</button>';
|
||
zone.querySelector('[data-partage-go]').addEventListener('click', function () {
|
||
var a = +zone.querySelector('[data-partage-a]').value;
|
||
jpost('/atelier/partager/' + encodeURIComponent(st.id), { a: a, source: st.src, note: (st.note || '') }).then(function (r) { zone.textContent = r.ok ? '✓ envoyé à ' + r.a + ' (sa boîte : atelier › ⇄ reçus)' : '✕ ' + (r.erreur || r._status); });
|
||
});
|
||
}).catch(function (e) { zone.textContent = '✕ ' + (e.message || e); });
|
||
});
|
||
var run2 = $('[data-run2]');
|
||
if (run2) run2.addEventListener('click', function () {
|
||
runPreview();
|
||
try { frame.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } catch (e) {}
|
||
});
|
||
$('[data-full]').addEventListener('click', function () {
|
||
$('[data-fw]').classList.add('full');
|
||
frame.classList.add('on');
|
||
if (!frame.srcdoc) frame.srcdoc = frameHtml(st.src, { id: st.id });
|
||
});
|
||
$('[data-unfull]').addEventListener('click', function () { $('[data-fw]').classList.remove('full'); });
|
||
|
||
// ---- l'envoi ----
|
||
$('[data-note]').addEventListener('input', function (e) { st.note = e.target.value; refreshChecks(); });
|
||
$('[data-tsoin]').addEventListener('click', sendTsoin);
|
||
var ts2 = $('[data-tsoin2]');
|
||
if (ts2) ts2.addEventListener('click', function () {
|
||
if ((st.note || '').trim().length < 3) {
|
||
var n = $('[data-note]');
|
||
if (n) { try { n.scrollIntoView({ behavior: 'smooth', block: 'center' }); } catch (e) {} n.focus(); }
|
||
toast('⧗ dis d\'abord pourquoi — 1 ligne dans la note');
|
||
return;
|
||
}
|
||
sendTsoin();
|
||
});
|
||
|
||
paint(); refreshChecks();
|
||
runPreview();
|
||
if (st.sent) renderSent();
|
||
}
|
||
|
||
function refreshChecks() {
|
||
var box = $('[data-checks]');
|
||
if (!box || st.view !== 'edit') return;
|
||
var list = liteChecks(st.src, st.id || '');
|
||
var light = checksLight(list);
|
||
var lamp = light === 'green' ? '🟢 prêt à partir' : (light === 'orange' ? '🟠 ça peut partir — mais regarde les ⚠' : '🔴 à corriger avant l\'envoi');
|
||
var h = '<div class="atl__note" style="margin-top:0">' + lamp + '</div>';
|
||
list.forEach(function (c) {
|
||
var cls = c.ok ? 'ok' : (c.level === 'ko' ? 'ko' : 'warn');
|
||
h += '<div class="atl__ck ' + cls + '"><b>' + (c.ok ? '✓' : (c.level === 'ko' ? '✗' : '⚠')) + '</b><span>' + esc(c.label) +
|
||
(c.hint ? '<small>' + esc(c.hint) + '</small>' : '') + '</span></div>';
|
||
});
|
||
box.innerHTML = h;
|
||
// ⧗ gardé tant que : rouge, OU rien n'a changé vs le source original du repo
|
||
var unchanged = !!(st.meta && st.meta.in_registry) && st.src === st.orig;
|
||
var off = (light === 'red') || unchanged;
|
||
var hint = unchanged ? 'rien n\'a changé vs le source du repo — modifie d\'abord' : (light === 'red' ? 'corrige les ✗ d\'abord' : '');
|
||
[$('[data-tsoin]'), $('[data-tsoin2]')].forEach(function (btn) {
|
||
if (!btn) return;
|
||
btn.disabled = off;
|
||
btn.title = hint;
|
||
});
|
||
var sendNote = $('[data-send] .atl__note');
|
||
if (sendNote) {
|
||
// texte STATIQUE des deux côtés (zéro donnée utilisateur) — innerHTML sûr
|
||
sendNote.innerHTML = unchanged
|
||
? 'rien n\'a encore changé vs le source du repo — modifie, teste, puis le ⧗ s\'allume.'
|
||
: 'la contribution scellée : ton source complet + ta note partent dans la file — une session Claude l\'applique au repo. La note (1 ligne) : <b>pourquoi</b> ce tsoin.';
|
||
}
|
||
}
|
||
|
||
function saveDraft(quiet) {
|
||
if (!st.id || !st.dirty) return Promise.resolve(null);
|
||
var id = st.id, src = st.src;
|
||
if (src.length > MAX) { if (st._log) st._log('err', '✗ brouillon > 512 Ko — pas sauvable'); return Promise.resolve(null); }
|
||
return jpost('/atelier/draft/' + encodeURIComponent(id), { source: src, note: st.note })
|
||
.then(function (j) {
|
||
if (st.dead || st.id !== id) return j;
|
||
if (j.ok) {
|
||
st.dirty = (st.src !== src);
|
||
st.savedAt = j.savedAt || '';
|
||
var el = $('[data-status]');
|
||
if (el && !quiet) el.textContent = '💾 brouillon sauvé ' + (j.savedAt || '').slice(11, 19) + (j.versions ? ' (v−' + j.versions + ' gardées)' : '');
|
||
}
|
||
return j;
|
||
}).catch(function () { return null; });
|
||
}
|
||
|
||
function sendTsoin() {
|
||
var note = (st.note || '').trim();
|
||
if (note.length < 3) {
|
||
var n = $('[data-note]'); if (n) { n.focus(); n.style.borderColor = '#ff9d9d'; }
|
||
if (st._log) st._log('err', 'la note est obligatoire — 1 ligne : pourquoi ce tsoin.');
|
||
return;
|
||
}
|
||
var btn = $('[data-tsoin]'); if (btn) { btn.disabled = true; btn.textContent = '⧗ … le tsoin part …'; }
|
||
st.dirty = true; // force la sauvegarde du brouillon = ce qui part
|
||
saveDraft(true).then(function () {
|
||
return jpost('/atelier/tsoin/' + encodeURIComponent(st.id), { source: st.src, note: note });
|
||
}).then(function (j) {
|
||
if (st.dead) return;
|
||
if (!j || !j.ok) {
|
||
if (btn) { btn.disabled = false; btn.textContent = '⧗ ENVOYER LE TSOIN'; }
|
||
if (st._log) st._log('err', '✗ envoi refusé : ' + ((j && j.error) || 'erreur ' + (j && j._status)));
|
||
return;
|
||
}
|
||
st.sent = j;
|
||
try { localStorage.setItem(SENT_LS, String(sentCount() + 1)); } catch (e) {}
|
||
st.queue = null; // la file a changé
|
||
try { if (window.jOSPorts) jOSPorts.emit(ID, 'tsoin', { ploxion: st.id, id: j.id, diff: j.diff }); } catch (e) {}
|
||
renderSent();
|
||
});
|
||
}
|
||
function renderSent() {
|
||
var box = $('[data-sent]'), wrap = $('[data-send]');
|
||
if (!box || !st.sent) return;
|
||
if (wrap) wrap.classList.add('sent');
|
||
var d = st.sent.diff || {};
|
||
box.innerHTML = '<div class="atl__party" style="margin-top:8px">⧗ <b>ton tsoin est parti — c\'est ça, le commit.</b><br>' +
|
||
esc(st.id) + ' · +' + (d.plus || 0) + '/−' + (d.minus || 0) + ' lignes · statut : <b>envoyé</b>. ' +
|
||
'Il attend dans la file (onglet ⧗) — une session Claude le lit, l\'applique au repo, et ton nom voyage en Co-Authored-By.</div>';
|
||
var btn = $('[data-tsoin]');
|
||
if (btn) { btn.disabled = false; btn.textContent = '⧗ ENVOYER LE TSOIN'; }
|
||
}
|
||
|
||
// ---------- la file ----------
|
||
function refreshQueue() {
|
||
jget('/atelier/queue').then(function (j) {
|
||
if (st.dead) return;
|
||
st.queue = j.items || []; st.admin = !!j.admin;
|
||
QCACHE = { n: st.queue.length, enfile: st.queue.filter(function (x) { return x.status === 'envoye'; }).length };
|
||
if (st.view === 'queue') render();
|
||
}).catch(function () { if (!st.dead) { st.queue = []; if (st.view === 'queue') render(); } });
|
||
}
|
||
function stChip(s) {
|
||
if (s === 'applique') return '<span class="atl__chip atl__chip--v">✓ appliqué</span>';
|
||
if (s === 'refuse') return '<span class="atl__chip atl__chip--r">✗ refusé</span>';
|
||
return '<span class="atl__chip atl__chip--o">⧗ envoyé</span>';
|
||
}
|
||
function renderQueue() {
|
||
if (st.detail) return renderDetail();
|
||
if (!st.queue) return '<div class="atl__msg">… la file arrive …</div>';
|
||
var h = '<div class="atl__note" style="margin-top:0">' +
|
||
(st.admin ? 'toute la file (tu es admin) — ouvre un tsoin : ⇶ l\'applique dans le repo, ⇪ le met en ligne.' :
|
||
'tes tsoins de contribution — envoyé → une session Claude l\'applique → appliqué (ou refusé, avec amour).') + '</div>';
|
||
if (!st.queue.length) h += '<div class="atl__msg">la file est vide — prends un ploxion, modifie, envoie ton premier tsoin. 5 minutes.</div>';
|
||
st.queue.forEach(function (x) {
|
||
var d = x.diff || {};
|
||
h += '<button class="atl__row" data-qitem="' + esc(x.id) + '"><span class="ic">' + (x['new'] ? '✨' : '⧗') + '</span>' +
|
||
'<span class="mid"><b>' + esc(x.ploxion) + ' <span style="opacity:.6">+' + (d.plus || 0) + '/−' + (d.minus || 0) + '</span></b>' +
|
||
'<small>' + esc((x.date || '').slice(0, 16).replace('T', ' ')) + (st.admin ? ' · ' + esc(x.user.name) : '') + ' — ' + esc(x.note) + '</small></span>' +
|
||
stChip(x.status) + '</button>';
|
||
});
|
||
return h;
|
||
}
|
||
function renderDetail() {
|
||
var h = '<button class="atl__btn" data-qback>← la file</button><div data-qdetail class="atl__msg">… le tsoin arrive …</div>';
|
||
return h;
|
||
}
|
||
function wireQueue() {
|
||
container.querySelectorAll('[data-qitem]').forEach(function (b) {
|
||
b.addEventListener('click', function () { st.detail = b.getAttribute('data-qitem'); render(); loadDetail(); });
|
||
});
|
||
var back = $('[data-qback]');
|
||
if (back) back.addEventListener('click', function () { st.detail = null; render(); });
|
||
}
|
||
function loadDetail() {
|
||
var qid = st.detail;
|
||
jget('/atelier/queue/' + encodeURIComponent(qid)).then(function (j) {
|
||
if (st.dead || st.detail !== qid) return;
|
||
var box = $('[data-qdetail]');
|
||
if (!box) return;
|
||
var it = j.item, d = it.diff || {};
|
||
var h = '<div style="text-align:left;opacity:1;padding:0">' +
|
||
'<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:10px 0 4px">' +
|
||
'<b>' + esc(it.ploxion) + '</b> ' + stChip(it.status) +
|
||
'<span class="atl__chip">+' + (d.plus || 0) + '/−' + (d.minus || 0) + '</span>' +
|
||
'<span class="atl__chip">' + esc(it.user.name) + '</span>' +
|
||
'<span class="atl__chip">' + esc((it.date || '').slice(0, 16).replace('T', ' ')) + '</span></div>' +
|
||
'<div class="atl__note">« ' + esc(it.note) + ' » · cible : ' + esc(it.rel || '') + '</div>';
|
||
if (st.admin) {
|
||
// (03.11) ⇶ dans le repo : la commande ⌥ « tsoin-appliquer » (ops/tsoin-appliquer.sh sur l'hôte : écrit, vérifie, committe au nom
|
||
// du contributeur, marque appliqué), puis ⇪ déployer — les deux par le runner de l'hôte (jOSCommandes), deux temps chacun
|
||
var cmdOk = !!window.jOSCommandes;
|
||
h += '<div style="display:flex;gap:7px;flex-wrap:wrap;margin:8px 0">' +
|
||
// (07.11) ⇪ publier : appliquer + déployer d'un geste (RS-7 : « un bouton publier le ploxion »), même si le tsoin était marqué appliqué sans être dans le repo
|
||
(cmdOk && it.status !== 'refuse' ? '<button class="atl__btn atl__btn--go" data-publier>⇪ publier le ploxion</button>' : '') +
|
||
(cmdOk && it.status === 'envoye' ? '<button class="atl__btn atl__btn--go" data-repo>⇶ appliquer dans le repo</button>' : '') +
|
||
(cmdOk ? '<button class="atl__btn" data-deploy>⇪ déployer le labo</button>' : '') +
|
||
'<button class="atl__btn" data-st="applique">✓ marquer appliqué</button>' +
|
||
'<button class="atl__btn" data-st="refuse">✗ refuser</button>' +
|
||
'<button class="atl__btn" data-st="envoye">⧗ renvoyer en file</button></div>' +
|
||
'<pre class="atl__note" data-sortie style="white-space:pre-wrap;max-height:220px;overflow:auto;display:none"></pre>' +
|
||
'<div class="atl__note">⇪ publier = appliquer puis déployer, d\'un geste (le ploxion est en ligne à la fin). ⇶ écrit le ploxion dans le repo (et son entrée de registre s\'il est neuf), vérifie qu\'il se monte, committe au nom du contributeur ; ⇪ le met en ligne. « marquer appliqué » ne fait que tenir le statut.</div>';
|
||
}
|
||
// (07.11) ▶ L'APERÇU d'un tsoin (RS-7 : « dans l'atelier j'ai même pas l'aperçu, c'est important ») : le code d'un autre tourne dans le
|
||
// BAC À SABLE de l'établi (iframe sandbox="allow-scripts", sans allow-same-origin : origine opaque, ni cookies ni session, bions stubbés),
|
||
// jamais dans la page ; ses vues sur les écrans des xers (jOSXerVues) à côté. Le diff texte reste en dessous.
|
||
if (it.source) {
|
||
h += '<div style="display:flex;gap:7px;flex-wrap:wrap;margin:8px 0"><button class="atl__btn atl__btn--go" data-apercu>▶ aperçu (bac à sable)</button><button class="atl__tool" data-apercu-full title="plein écran">⛶</button></div>' +
|
||
'<div class="atl__fw" data-qfw><button class="atl__fx" data-qunfull>✕ fermer</button><iframe class="atl__frame" data-qframe sandbox="allow-scripts" title="le tsoin qui tourne (bac à sable)"></iframe></div>' +
|
||
'<div data-qvues class="atl__note"></div>';
|
||
}
|
||
// le diff TEXTE, en dessous
|
||
h += renderDiff(it.current || '', it.source || '') + '</div>';
|
||
box.className = ''; box.innerHTML = h;
|
||
var qf = box.querySelector('[data-qframe]'), qv = box.querySelector('[data-qvues]'), qg = null;
|
||
if (qf) {
|
||
if (st._onQMsg) window.removeEventListener('message', st._onQMsg);
|
||
st._onQMsg = function (ev) {
|
||
if (ev.source !== qf.contentWindow) return; var d = ev.data; if (!d || !d.xbAtl) return;
|
||
if (d.t === 'err') { qv.insertAdjacentHTML('beforeend', '<div style="color:#ff8a8a">✕ ' + esc(d.msg) + '</div>'); return; }
|
||
if (d.t !== 'xui') return;
|
||
if (!d.xui) { qv.innerHTML = '<b style="color:#ff8a8a">✕ pas de vue xerploxion</b> : ' + esc(d.err || 'pas de describe()'); return; }
|
||
if (window.jOSXerVues) { if (!qg) qg = window.jOSXerVues.galerie(qv, d.xui); else qg.maj(d.xui); }
|
||
};
|
||
window.addEventListener('message', st._onQMsg);
|
||
var lancerApercu = function () { qf.classList.add('on'); qv.textContent = '… ça monte (bac à sable)'; qg = null; qf.srcdoc = frameHtml(it.source, { id: it.ploxion }); };
|
||
box.querySelector('[data-apercu]').addEventListener('click', lancerApercu);
|
||
box.querySelector('[data-apercu-full]').addEventListener('click', function () { box.querySelector('[data-qfw]').classList.add('full'); if (!qf.srcdoc) lancerApercu(); });
|
||
box.querySelector('[data-qunfull]').addEventListener('click', function () { box.querySelector('[data-qfw]').classList.remove('full'); });
|
||
}
|
||
if (st.admin) {
|
||
var sortie = box.querySelector('[data-sortie]');
|
||
function lancerCmd(btn, id, args) {
|
||
if (btn.dataset.arme !== '1') { btn.dataset.arme = '1'; btn.dataset.t = btn.textContent; btn.textContent = '▶ sûr ?'; setTimeout(function () { if (btn.dataset.arme === '1') { btn.dataset.arme = ''; btn.textContent = btn.dataset.t; } }, 4000); return; }
|
||
btn.dataset.arme = ''; btn.disabled = true; btn.textContent = '…'; sortie.style.display = 'block'; sortie.textContent = '';
|
||
window.jOSCommandes.lancer(id, args).then(function (uid) {
|
||
window.jOSCommandes.suivre(uid, function (x) {
|
||
if (x.texte) { sortie.textContent += x.texte; sortie.scrollTop = sortie.scrollHeight; }
|
||
if (x.attend && !sortie.textContent) sortie.textContent = '… en attente du runner';
|
||
if (x.fini) { btn.disabled = false; btn.textContent = (x.etat && x.etat.etat === 'ok' ? '✓ ' : '✗ ') + btn.dataset.t; st.queue = null; refreshQueue(); }
|
||
});
|
||
}).catch(function (e) { btn.disabled = false; btn.textContent = btn.dataset.t; sortie.textContent = '✗ ' + (e.message || e); });
|
||
}
|
||
var bRepo = box.querySelector('[data-repo]'), bDep = box.querySelector('[data-deploy]');
|
||
if (bRepo) bRepo.addEventListener('click', function () { lancerCmd(bRepo, 'tsoin-appliquer', { id: it.id }); });
|
||
var bPub = box.querySelector('[data-publier]'); if (bPub) bPub.addEventListener('click', function () { lancerCmd(bPub, 'tsoin-publier', { id: it.id }); });
|
||
if (bDep) bDep.addEventListener('click', function () { lancerCmd(bDep, 'deploy', {}); });
|
||
box.querySelectorAll('[data-st]').forEach(function (b) {
|
||
b.addEventListener('click', function () {
|
||
jpost('/atelier/queue/' + encodeURIComponent(qid) + '/status', { status: b.getAttribute('data-st') })
|
||
.then(function () { st.queue = null; st.detail = null; refreshQueue(); render(); });
|
||
});
|
||
});
|
||
}
|
||
}).catch(function (e) {
|
||
var box = $('[data-qdetail]');
|
||
if (box) box.textContent = '✗ ' + (e.message || 'inaccessible');
|
||
});
|
||
}
|
||
|
||
// ---------- rendu ----------
|
||
function render() {
|
||
if (st.dead) return;
|
||
container.querySelectorAll('.atl__tab').forEach(function (b) {
|
||
b.classList.toggle('on', b.getAttribute('data-tab') === st.view);
|
||
});
|
||
if (st.view === 'pick') { body.innerHTML = renderPick(); wirePick(); }
|
||
else if (st.view === 'edit') { body.innerHTML = renderEdit(); wireEdit(); }
|
||
else if (st.view === 'recus') { body.innerHTML = renderRecus(); wireRecus(); }
|
||
else { body.innerHTML = renderQueue(); wireQueue(); if (st.detail) loadDetail(); }
|
||
}
|
||
function wirePick() {
|
||
var q = $('[data-q]');
|
||
if (q) q.addEventListener('input', function () {
|
||
st.q = q.value; render();
|
||
var q2 = $('[data-q]');
|
||
if (q2) { q2.focus(); try { q2.setSelectionRange(q2.value.length, q2.value.length); } catch (e) {} }
|
||
});
|
||
container.querySelectorAll('[data-take]').forEach(function (b) {
|
||
b.addEventListener('click', function () { take(b.getAttribute('data-take')); });
|
||
});
|
||
var nw = $('[data-new]');
|
||
if (nw) nw.addEventListener('click', function () {
|
||
var id = window.prompt('L\'id de ton nouveau ploxion (kebab-case : minuscules, chiffres, tirets — ex. hello-toi) :', '');
|
||
if (!id) return;
|
||
id = String(id).trim().toLowerCase();
|
||
if (!/^[a-z0-9][a-z0-9-]{1,39}$/.test(id)) { window.alert('kebab-case strict : [a-z0-9-], 2 à 40 caractères.'); return; }
|
||
if (REG && (REG.ploxions || []).some(function (p) { return p.id === id; })) {
|
||
if (!window.confirm('« ' + id + ' » existe déjà au registre — le prendre pour l\'améliorer plutôt ?')) return;
|
||
take(id); return;
|
||
}
|
||
take(id); // 404 → squelette
|
||
});
|
||
var vs = $('[data-vscode]');
|
||
if (vs) vs.addEventListener('click', function () { st.vsc = !st.vsc; render(); });
|
||
var vj = $('[data-vjeton]');
|
||
if (vj) vj.addEventListener('click', creerJetonVscode);
|
||
var vc = $('[data-vcopy]');
|
||
if (vc) vc.addEventListener('click', function () {
|
||
try { navigator.clipboard.writeText(st.vscJeton); toast('⎘ copié'); } catch (e) { toast('sélectionne et copie à la main'); }
|
||
});
|
||
var gq = $('[data-goqueue]');
|
||
if (gq) gq.addEventListener('click', function () { setTab('queue'); });
|
||
}
|
||
|
||
// ---------- bus (XUI pilote aussi) ----------
|
||
var offBus = null;
|
||
try {
|
||
if (window.jOSPorts && jOSPorts.on) offBus = jOSPorts.on('ploxion.' + ID + '.cmd', function (p) {
|
||
var c = p && p.cmd;
|
||
if (c === 'queue') setTab('queue');
|
||
else if (c === 'take' && p.ploxion) take(String(p.ploxion));
|
||
});
|
||
} catch (e) {}
|
||
|
||
// ---------- autosave 5 s ----------
|
||
var saveTimer = setInterval(function () { saveDraft(); }, 5000);
|
||
|
||
// ---------- deep-link : /px/atelier?ploxion=carte, hash, ctx, ou la passe de main du xer ----------
|
||
var deepId = null;
|
||
try {
|
||
deepId = (ctx && ctx.ploxion) || new URLSearchParams(location.search).get('ploxion') || null;
|
||
if (!deepId && location.hash) {
|
||
var hm = location.hash.match(/ploxion=([a-z0-9-]+)/);
|
||
if (hm) deepId = hm[1];
|
||
}
|
||
if (!deepId) {
|
||
deepId = localStorage.getItem('atelier:take');
|
||
if (deepId) localStorage.removeItem('atelier:take');
|
||
}
|
||
} catch (e) {}
|
||
render();
|
||
loadReg().then(function () { if (!st.dead && st.view === 'pick') render(); })
|
||
.catch(function () { if (!st.dead && st.view === 'pick') render(); });
|
||
refreshQueue();
|
||
try { if (/[?&]vscode=1\b/.test(location.search) || (ctx && ctx.vscode)) lier(true); } catch (e) {}
|
||
if (deepId && /^[a-z0-9][a-z0-9-]{1,39}$/.test(deepId)) take(deepId);
|
||
else if (st.lie) { st.vsc = true; render(); }
|
||
|
||
return {
|
||
unmount: function () {
|
||
st.dead = true;
|
||
if (st._onMsg) { window.removeEventListener('message', st._onMsg); st._onMsg = null; }
|
||
if (st._onQMsg) { window.removeEventListener('message', st._onQMsg); st._onQMsg = null; }
|
||
clearInterval(saveTimer);
|
||
if (lieTimer) clearInterval(lieTimer);
|
||
if (st.messageHandler) window.removeEventListener('message', st.messageHandler);
|
||
saveDraft(true); // best effort — le brouillon ne se perd pas
|
||
if (offBus) { try { offBus(); } catch (e) {} }
|
||
container.innerHTML = '';
|
||
}
|
||
};
|
||
}
|
||
|
||
// ---- XUI : describe() PUR (caches module + localStorage, jamais le DOM) ----
|
||
function describe() {
|
||
var items = [];
|
||
var sent = sentCount();
|
||
var enfile = QCACHE ? QCACHE.enfile : null;
|
||
items.push({ p: 1, kind: 'stat', label: '⧗ tsoins envoyés', value: String(sent) + (enfile !== null ? ' · ' + enfile + ' en file' : '') });
|
||
items.push({ p: 2, kind: 'action', label: 'voir la file', act: { port: 'ploxion.' + ID + '.cmd', payload: { cmd: 'queue', src: 'xui' } } });
|
||
if (REG) items.push({ p: 3, kind: 'stat', label: 'missions ouvertes', value: REG.missions_total });
|
||
items.push({ p: 4, kind: 'text', label: 'prends un ploxion, modifie, envoie le tsoin — c\'est ça, le commit' });
|
||
return { v: 1, id: ID, title: 'Atelier', icon: '🛠', items: items };
|
||
}
|
||
|
||
// ---- partage : /px/atelier?ploxion=<id> rouvre l'établi sur le même ploxion ----
|
||
function shareParams() {
|
||
try {
|
||
var el = document.querySelector('.atl [data-ta]');
|
||
var b = document.querySelector('.atl .atl__tab.on');
|
||
// approximation honnête : si l'établi est ouvert, l'id vit dans le header
|
||
var hd = document.querySelector('.atl [data-body] b');
|
||
if (el && hd) {
|
||
var m = hd.textContent.match(/([a-z0-9][a-z0-9-]{1,39})\s*$/);
|
||
if (m) return { ploxion: m[1] };
|
||
}
|
||
return null;
|
||
} catch (e) { return null; }
|
||
}
|
||
|
||
window.jOSApps[ID] = { manifest: { id: ID, name: 'Atelier', icon: '🛠' }, mount: mount, describe: describe, shareParams: shareParams };
|
||
})();
|
||
</script>
|