mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-text.git
synced 2026-11-29 07:15:10 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
commit
a420792db3
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# 📝 Texte
|
||||||
|
|
||||||
|
Éditeur de texte multi-documents — onglets, sauvegarde auto, export .txt.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| id | `text` |
|
||||||
|
| fournit | `text-editor` `documents` |
|
||||||
|
| bions qu'il nomme | `jOSApps` `jOSFiles` `jOSPorts` |
|
||||||
|
| fichiers | `app.blade.php` |
|
||||||
|
| dans le labo | `resources/views/ploxions/text/` (dépôt `my_website2`) |
|
||||||
|
|
||||||
|
## Contribuer
|
||||||
|
|
||||||
|
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=text — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||||
|
- **Dans VS Code** : `xb prendre text` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||||
|
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||||
|
|
||||||
|
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||||
|
|
||||||
|
© 2026 chill-tekk · ne pas nuire
|
||||||
179
app.blade.php
Normal file
179
app.blade.php
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
{{-- PL0XI0N text — éditeur de texte multi-documents. Onglets, sauvegarde auto
|
||||||
|
(localStorage), compteur mots/caractères, export .txt. 100% client-side,
|
||||||
|
aucune route serveur. window.jOSApps['text']. mount(c, ctx) -> { unmount }.
|
||||||
|
(25.09, docs/dev/33 § Créer des fichiers) LE CONTRAT « OUVRIR CE FICHIER » (jOSFiles.fichier) : ouvert avec un fichier du xerboxion
|
||||||
|
(au montage, ou déjà ouvert par le bus ploxion.text.cmd {cmd:'fichier', fichier:<jeton>}), il devient un onglet ⌗ qui s'enregistre
|
||||||
|
DANS CE FICHIER (le texte tel quel, 0,6 s après la dernière frappe) ; un onglet-fichier ne va jamais dans xb:text (il vit dans son fichier). --}}
|
||||||
|
<style>
|
||||||
|
.txt { display:flex; flex-direction:column; height:100%; background:#06090d;
|
||||||
|
color:rgba(220,232,240,.92); font-family:ui-sans-serif,system-ui,sans-serif; }
|
||||||
|
.txt__tabs { flex:0 0 auto; display:flex; align-items:center; gap:4px; padding:6px 8px;
|
||||||
|
border-bottom:1px solid rgba(120,160,230,.18); overflow-x:auto; }
|
||||||
|
.txt__tab { display:flex; align-items:center; gap:6px; padding:4px 9px; border-radius:7px; cursor:pointer;
|
||||||
|
border:1px solid rgba(120,160,230,.2); background:rgba(18,26,42,.4); font-size:.74rem; color:rgba(190,212,228,.8); white-space:nowrap; }
|
||||||
|
.txt__tab.on { background:rgba(120,160,230,.16); color:#fff; border-color:rgba(120,160,230,.45); }
|
||||||
|
.txt__tab b { font-weight:600; }
|
||||||
|
.txt__tx { cursor:pointer; border:0; background:none; color:rgba(190,212,228,.5); font-size:.78rem; line-height:1; }
|
||||||
|
.txt__tx:hover { color:rgba(255,140,140,.95); }
|
||||||
|
.txt__add { cursor:pointer; padding:4px 9px; border-radius:7px; border:1px dashed rgba(120,160,230,.35);
|
||||||
|
background:none; color:rgba(160,195,255,.85); font-size:.78rem; flex:0 0 auto; }
|
||||||
|
.txt__add:hover { background:rgba(120,160,230,.12); color:#fff; }
|
||||||
|
.txt__area { flex:1; min-height:0; width:100%; border:0; outline:none; resize:none; box-sizing:border-box;
|
||||||
|
padding:14px 18px; background:none; color:rgba(228,238,246,.96); font-family:ui-monospace,'Share Tech Mono',monospace;
|
||||||
|
font-size:.9rem; line-height:1.55; }
|
||||||
|
.txt__foot { flex:0 0 auto; display:flex; align-items:center; gap:10px; padding:5px 12px;
|
||||||
|
border-top:1px solid rgba(120,160,230,.18); font-size:.68rem; color:rgba(150,180,220,.6); font-family:ui-monospace,monospace; }
|
||||||
|
.txt__sp { flex:1; }
|
||||||
|
.txt__btn { cursor:pointer; padding:2px 9px; border-radius:6px; border:1px solid rgba(120,160,230,.3);
|
||||||
|
background:none; color:rgba(160,195,255,.85); font-size:.68rem; }
|
||||||
|
.txt__btn:hover { background:rgba(120,160,230,.12); color:#fff; }
|
||||||
|
.txt__name { background:none; border:0; color:inherit; font:inherit; width:auto; max-width:120px; outline:none; }
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
var KEY = 'xb:text';
|
||||||
|
function load() {
|
||||||
|
try { var d = JSON.parse(localStorage.getItem(KEY)); if (d && d.docs && d.docs.length) return d; } catch (e) {}
|
||||||
|
return { active: 0, docs: [{ id: 'd0', name: 'doc-1', body: '' }] };
|
||||||
|
}
|
||||||
|
// (25.09) un onglet-fichier (d.fichier : la poignée jOSFiles.fichier) vit dans son fichier : jamais dans xb:text
|
||||||
|
function save(s) {
|
||||||
|
var docs = s.docs.filter(function (d) { return !d.fichier; }), c = s.docs[s.active], a = docs.indexOf(c);
|
||||||
|
if (!docs.length) docs = [{ id: 'd0', name: 'doc-1', body: '' }];
|
||||||
|
try { localStorage.setItem(KEY, JSON.stringify({ active: a >= 0 ? a : 0, docs: docs })); } catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function describe() {
|
||||||
|
var s = null; try { s = JSON.parse(localStorage.getItem('xb:text')); } catch (e) {}
|
||||||
|
var docs = (s && s.docs) ? s.docs.length : 0;
|
||||||
|
return { v: 1, id: 'text', title: 'Texte', icon: '📝', items: [
|
||||||
|
{ p: 1, kind: 'stat', label: 'documents', value: docs }
|
||||||
|
] };
|
||||||
|
}
|
||||||
|
function mount(container, ctx) {
|
||||||
|
var st = load();
|
||||||
|
container.innerHTML =
|
||||||
|
'<div class="txt">'
|
||||||
|
+ ' <div class="txt__tabs"></div>'
|
||||||
|
+ ' <textarea class="txt__area" placeholder="écris…" spellcheck="false"></textarea>'
|
||||||
|
+ ' <div class="txt__foot"><span class="txt__name-wrap">📝 <input class="txt__name" /></span>'
|
||||||
|
+ ' <span class="txt__sp"></span><span class="txt__stat"></span>'
|
||||||
|
+ ' <button class="txt__btn" data-export>export .txt</button></div>'
|
||||||
|
+ '</div>';
|
||||||
|
var tabs = container.querySelector('.txt__tabs');
|
||||||
|
var area = container.querySelector('.txt__area');
|
||||||
|
var nameI = container.querySelector('.txt__name');
|
||||||
|
var stat = container.querySelector('.txt__stat');
|
||||||
|
|
||||||
|
function cur() { return st.docs[st.active]; }
|
||||||
|
function persist() { save(st); }
|
||||||
|
function updStat() {
|
||||||
|
var b = area.value; var w = b.trim() ? b.trim().split(/\s+/).length : 0;
|
||||||
|
stat.textContent = w + ' mots · ' + b.length + ' car.';
|
||||||
|
}
|
||||||
|
function renderTabs() {
|
||||||
|
tabs.innerHTML = '';
|
||||||
|
st.docs.forEach(function (d, i) {
|
||||||
|
var t = document.createElement('div'); t.className = 'txt__tab' + (i === st.active ? ' on' : '');
|
||||||
|
t.innerHTML = '<b></b>'; t.querySelector('b').textContent = (d.fichier ? '⌗ ' : '') + d.name; if (d.fichier) t.title = d.fichier.chemin;
|
||||||
|
t.addEventListener('click', function () { st.active = i; persist(); paint(); });
|
||||||
|
if (st.docs.length > 1) {
|
||||||
|
var x = document.createElement('button'); x.className = 'txt__tx'; x.textContent = '✕';
|
||||||
|
x.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (d.fichier && d.sale) { clearTimeout(fxT); ecrireFichiers(); } // (relecture adverse 25.09) un onglet ⌗ fermé : sa dernière frappe part d'abord dans son fichier
|
||||||
|
st.docs.splice(i, 1); if (st.active >= st.docs.length) st.active = st.docs.length - 1;
|
||||||
|
persist(); paint();
|
||||||
|
});
|
||||||
|
t.appendChild(x);
|
||||||
|
}
|
||||||
|
tabs.appendChild(t);
|
||||||
|
});
|
||||||
|
var add = document.createElement('button'); add.className = 'txt__add'; add.textContent = '+';
|
||||||
|
add.title = 'nouveau document';
|
||||||
|
add.addEventListener('click', function () {
|
||||||
|
st.docs.push({ id: 'd' + Date.now().toString(36), name: 'doc-' + (st.docs.length + 1), body: '' });
|
||||||
|
st.active = st.docs.length - 1; persist(); paint(); area.focus();
|
||||||
|
});
|
||||||
|
tabs.appendChild(add);
|
||||||
|
}
|
||||||
|
function paint() {
|
||||||
|
renderTabs(); area.value = cur().body; nameI.value = cur().name; updStat();
|
||||||
|
}
|
||||||
|
|
||||||
|
// bus jOSPorts — out text.buffer (→ code.save / script.in), best-effort
|
||||||
|
var offs = [], bufT = null;
|
||||||
|
function emitBuffer() {
|
||||||
|
try {
|
||||||
|
if (!window.jOSPorts || !window.jOSPorts.emit) return;
|
||||||
|
var d = cur(); if (!d) return;
|
||||||
|
window.jOSPorts.emit('text', 'buffer', { id: d.id, name: d.name, path: d.path || '', body: d.body });
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
area.addEventListener('input', function () {
|
||||||
|
cur().body = area.value; persist(); updStat();
|
||||||
|
if (cur().fichier) { cur().sale = true; clearTimeout(fxT); fxT = setTimeout(ecrireFichiers, 600); }
|
||||||
|
else { clearTimeout(bufT); bufT = setTimeout(emitBuffer, 500); } // un onglet-fichier ne diffuse pas son contenu sur le bus
|
||||||
|
});
|
||||||
|
// ── le contrat « ouvrir ce fichier » (jOSFiles.fichier) ──
|
||||||
|
var FX = window.jOSFiles && window.jOSFiles.fichier, fxT = null, offFx = null;
|
||||||
|
function ecrireFichiers() { fxT = null; st.docs.forEach(function (d) { if (!d.fichier || !d.sale) return; d.sale = false; var h = d.fichier; h.ecrire(d.body).then(function (ok) { if (!ok) d.sale = true; if (cur() === d) stat.textContent = ok ? '💾 ' + h.nom : '⚠ ' + h.nom + ' pas enregistré'; }); }); }
|
||||||
|
// (relecture adverse 25.09) DÉJÀ OUVERT avec des changements en route (pas encore partis, ou un envoi en vol) : l'onglet est montré tel
|
||||||
|
// quel — relu à ce moment, le fichier dit encore l'avant (l'écran reculait, la frappe suivante effaçait la dernière du fichier)
|
||||||
|
function ongletDe(h) { for (var k = 0; k < st.docs.length; k++) { if (st.docs[k].fichier && st.docs[k].fichier.chemin === h.chemin) return k; } return -1; }
|
||||||
|
function enRoute(i) { var d = i >= 0 ? st.docs[i] : null; return !!(d && (d.sale || (typeof d.fichier.occupe === 'function' && d.fichier.occupe()))); }
|
||||||
|
function prendreFichier(h) {
|
||||||
|
if (!h) return;
|
||||||
|
var i0 = ongletDe(h); if (enRoute(i0)) { st.active = i0; persist(); paint(); return; }
|
||||||
|
h.texte().then(function (txt) {
|
||||||
|
if (txt == null) { stat.textContent = '⚠ fichier introuvable : ' + h.nom; return; }
|
||||||
|
var i = ongletDe(h); if (enRoute(i)) { st.active = i; persist(); paint(); return; }
|
||||||
|
if (i >= 0) { st.docs[i].body = txt; st.docs[i].fichier = h; st.docs[i].sale = false; st.active = i; }
|
||||||
|
else { st.docs.push({ id: 'f' + Date.now().toString(36), name: h.nom, body: txt, path: h.chemin, fichier: h }); st.active = st.docs.length - 1; }
|
||||||
|
persist(); paint(); try { area.focus(); } catch (e) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
nameI.addEventListener('input', function () { if (cur().fichier) { nameI.value = cur().name; return; } cur().name = nameI.value || 'sans-nom'; persist(); renderTabs(); }); // un fichier se renomme au bureau
|
||||||
|
container.querySelector('[data-export]').addEventListener('click', function () {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = URL.createObjectURL(new Blob([cur().body], { type: 'text/plain' }));
|
||||||
|
a.download = (cur().name || 'doc') + '.txt'; a.click(); URL.revokeObjectURL(a.href);
|
||||||
|
});
|
||||||
|
|
||||||
|
paint();
|
||||||
|
if (FX && FX.de) { var fx0 = FX.de('text', ctx); if (fx0) prendreFichier(fx0); }
|
||||||
|
if (FX && FX.ecouter) offFx = FX.ecouter('text', prendreFichier, ctx);
|
||||||
|
|
||||||
|
// bus jOSPorts — in text.doc (← code.open) : charge un fichier dans un onglet
|
||||||
|
try {
|
||||||
|
if (window.jOSPorts && window.jOSPorts.on) {
|
||||||
|
offs.push(window.jOSPorts.on('ploxion.text.doc', function (p) {
|
||||||
|
if (!p || typeof p !== 'object') return;
|
||||||
|
var body = typeof p.body === 'string' ? p.body
|
||||||
|
: typeof p.content === 'string' ? p.content
|
||||||
|
: typeof p.text === 'string' ? p.text : null;
|
||||||
|
if (body === null) return;
|
||||||
|
var path = typeof p.path === 'string' ? p.path : '';
|
||||||
|
var name = (typeof p.name === 'string' && p.name) ? p.name
|
||||||
|
: (path ? path.split('/').pop() : 'doc-' + (st.docs.length + 1));
|
||||||
|
var i = -1;
|
||||||
|
if (path) { for (var k = 0; k < st.docs.length; k++) { if (st.docs[k].path === path) { i = k; break; } } }
|
||||||
|
if (i >= 0) { st.docs[i].body = body; st.docs[i].name = name; st.active = i; }
|
||||||
|
else { st.docs.push({ id: 'd' + Date.now().toString(36), name: name, body: body, path: path }); st.active = st.docs.length - 1; }
|
||||||
|
persist(); paint();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return { unmount: function () {
|
||||||
|
clearTimeout(bufT); if (fxT) { clearTimeout(fxT); ecrireFichiers(); } if (offFx) offFx();
|
||||||
|
offs.forEach(function (off) { try { if (off) off(); } catch (e) {} });
|
||||||
|
container.innerHTML = '';
|
||||||
|
} };
|
||||||
|
}
|
||||||
|
|
||||||
|
window.jOSApps = window.jOSApps || {};
|
||||||
|
window.jOSApps['text'] = { manifest: { id: 'text', name: 'Texte', icon: '📝' }, mount: mount, describe: describe };
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user