Document editor reads like the document page: New Document and the edit page show what it says with the page's typography in the editor and in Markdown Preview, a document toolbar matching the Markdown one with headings, strikethrough, quote, code block, table and line, a taller New Document editor, and Ctrl+S to save on the edit page; other editors unchanged; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-29 14:27:23 -05:00
parent 85c151eec8
commit 626f472990
5 changed files with 106 additions and 20 deletions

View File

@@ -21,6 +21,7 @@ Update from Maintenance > Update as usual - this release has three database chan
- Markdown pasted into a document's rich text editor - copied from GitHub, VS Code, Obsidian or an AI chat - goes in as formatting. Ctrl+Shift+V pastes it as it is.
- A document's page is easier to read: headings in proportion to the text with room between sections, and tables, code and quotes that look part of it. Under its name are its folder, its template, Markdown when it's written in it, and its review - due, or when it's next due - whose menu has Mark Reviewed and how often. The buttons are Edit, Share and Export (PDF, Markdown or Print), with the rest in the ⋮ menu, now including Template. Beside it, Contents marks the section you're reading, and Linked, Versions and History are tabs of one card: Linked shows each kind of record with its count, opening to the list.
- Lists on a phone: Tickets, Credentials, Assets and Contacts (and Contacts' portal invites) show each row as a card instead of a table cut off at the edge of the screen - its name with the tick box and ⋮ menu across the top, then every other column with its label: a ticket's client, status, priority, agent, due date and last activity, a credential's login and what it's for, an asset's type, model, IP, location and status, a contact's phone and email. Status, priority, agent and location still change with a tap, and the column names above the cards sort the list.
- Writing a document - New Document and the edit page - shows it as it will read on its page: headings in proportion to the text, tables with their lines, and code and quotes as they look there, in the editor and in Markdown's Preview. The editor's toolbar has what a document is made of, as the Markdown toolbar has: headings, bold, italic, strikethrough, color, link, lists, quote, code block, table and line, then align and indent. New Document's editor starts taller, and Ctrl+S saves on the edit page.
- A document's quick view (Quick view in Files, and the view button on an asset or contact) reads like its page: headings in proportion to the text with tables, code and quotes that look part of it, its folder, template, Markdown and review above it, and what it's linked to as a count of each kind that opens to the list, instead of every linked record listed under it. Along the bottom are Open Document, Edit (now the edit page, as from the document), Share and Export (PDF or Markdown).
- Documents and articles read outside ITFlow look like a document's page: in the client portal (a document, and a Help article), on a shared link and on the public help center, headings are in proportion to the text, tables, code and quotes look part of it, and a picture shown smaller than it is opens full size when clicked. A long one - three headings or more - has its Contents beside it, in view as you scroll and marking the section being read, or above it on a phone. Picking a heading in Contents marks that one, not the one just under it - on a document's page in ITFlow too.
- A document's PDF, and a Knowledge Base article's, look like your invoices and the documentation PDF: your logo and company details at the top, then its name with the client, its folder (an article's category) and when it was last updated and by whom, and its summary. Each later page has the client and the name at the top, and every page your company, Confidential (Knowledge Base for an article) and the date at the foot, with the page number. Tables have lines, code is shaded, a checklist shows its boxes, symbols such as ✓ and → show, and a document with headings has them as bookmarks beside the PDF.
@@ -57,6 +58,7 @@ Update from Maintenance > Update as usual - this release has three database chan
- documentReadHtml() (functions/files.php) lays out a document or article outside the agent app - client/document.php, client/kb_article.php, guest/kb.php and guest/share.php - with .itflow-prose, and the Contents beside it in an .itflow-document-read grid (css/itflow_custom.css). js/document_contents.js reads [data-document-body] as well as .itflow-document-body, runs again from window.itflowDocumentContents() (js/guest_share.js, once a shared document is in), leaves the address alone with data-document-contents-keep-address (a shared link's secret is after its #), and keeps a section picked from the list marked while the page scrolls to it. The portal footer loads it when a page sets $portal_document_contents.
- A list table with .itflow-list-stack (css/itflow_custom.css) stacks below 768px: each row a grid card with the tick box, first cell and last (the menu) across the top and every other cell under them labelled from its data-label, and the head a wrapping row of its sort links. Used on agent/ticket_list.php, agent/credentials.php, agent/assets.php and agent/contacts.php (contacts and invites); the ticket row's phone-only line of status, priority and client is gone, as the card shows them.
- agent/modals/document/document_view.php uses .itflow-prose and linkGroupsHtml()'s compact mode, which takes $open_up_to (5 by default, 0 for the quick view: always closed). Its Edit goes to agent/document_edit.php, so agent/modals/document/document_edit.php, which only it opened, is gone.
- A document's editor is .tinymce-document (agent/modals/document/document_form.php; .tinymce-page on agent/document_edit.php): js/app.js itflowDocumentWriter, the document editor with its own toolbar and itflowProseContentStyle() - .itflow-prose as literal CSS, as the editor is an iframe. The page's editor saves on Ctrl+S (addShortcut), the fields and Markdown box through a keydown on the page; the Markdown Preview has .itflow-prose; Markdown pasted into the editor (js/document_markdown.js) takes .tinymce-document too. Other editors (.tinymce) are as they were.
## [26.12.2]

View File

@@ -6,7 +6,8 @@
* edit_document; saving keeps what it said before as a version and goes back to the document.
*
* The editor is .tinymce-page (js/app.js): as tall as the window, with its toolbar always in
* view. Leaving with changes unsaved asks first - js/app.js does that for any editor on a page.
* view, and what it says as it will read on the document's page. Ctrl+S saves. Leaving with
* changes unsaved asks first - js/app.js does that for any editor on a page.
*/
require_once "includes/inc_all_client.php";
@@ -57,7 +58,7 @@ $page_title = 'Editing ' . $row['document_name'];
<div class="card mb-3">
<div class="card-header d-flex flex-wrap align-items-center gap-2">
<h3 class="card-title mb-0 me-auto text-truncate"><i class="fas fa-fw fa-edit me-2"></i>Editing <strong><?= $document_name ?></strong></h3>
<button type="submit" name="edit_document" class="btn btn-primary fw-bold"><i class="fas fa-check me-2"></i>Save</button>
<button type="submit" name="edit_document" class="btn btn-primary fw-bold" title="Save (Ctrl+S)"><i class="fas fa-check me-2"></i>Save</button>
<a class="btn btn-light border" href="document.php?client_id=<?= $client_id ?>&document_id=<?= $document_id ?>"><i class="fas fa-times me-2"></i>Cancel</a>
</div>
<div class="card-body itflow-document-page-form">
@@ -65,22 +66,32 @@ $page_title = 'Editing ' . $row['document_name'];
// The page's own editor, not the window's
ob_start();
require 'modals/document/document_form.php';
echo str_replace('class="form-control tinymce"', 'class="form-control tinymce-page"', ob_get_clean());
echo str_replace('class="form-control tinymce-document"', 'class="form-control tinymce-page"', ob_get_clean());
?>
</div>
</div>
</form>
<script>
// Saving is not leaving with changes unsaved - the editor is marked clean as the form goes
document.querySelector('form[data-document-page-form]').addEventListener('submit', function () {
if (window.tinymce) {
tinymce.get().forEach(function (editor) {
editor.save();
editor.setDirty(false);
});
}
});
(function () {
var form = document.querySelector('form[data-document-page-form]');
// Saving is not leaving with changes unsaved - the editor is marked clean as the form goes
form.addEventListener('submit', function () {
if (window.tinymce) {
tinymce.get().forEach(function (editor) {
editor.save();
editor.setDirty(false);
});
}
});
// Ctrl+S saves from the fields and the Markdown box - the rich text editor has its own (js/app.js)
document.addEventListener('keydown', function (e) {
if ((e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === 's') {
e.preventDefault();
form.requestSubmit(form.querySelector('button[name="edit_document"]'));
}
});
})();
</script>
<?php

View File

@@ -15,7 +15,9 @@
*
* It is written in the rich text editor or in Markdown, picked above the editor
* and switched either way as it is written (js/document_markdown.js); the form
* posts format, with content or markdown.
* posts format, with content or markdown. Both show it as it will read on its
* page (.itflow-prose): the rich text editor as it is written, Markdown in its
* Preview.
*/
$document_markdown_ready = documentMarkdownReady();
@@ -82,7 +84,8 @@ $document_format_uid = bin2hex(random_bytes(4));
<?php } ?>
<div data-editor-rich<?= $document_is_markdown ? ' hidden' : '' ?>>
<textarea class="form-control tinymce" name="content" aria-label="Content"><?= $document_content ?></textarea>
<!-- Written as it will read on its page (.tinymce-document, js/app.js) -->
<textarea class="form-control tinymce-document" name="content" aria-label="Content"><?= $document_content ?></textarea>
</div>
<?php if ($document_markdown_ready) { ?>
@@ -136,7 +139,7 @@ $document_format_uid = bin2hex(random_bytes(4));
</div>
</div>
<textarea class="form-control font-monospace itflow-markdown-input" name="markdown" rows="18" aria-label="Content, in Markdown" data-markdown-input placeholder="# A heading&#10;&#10;Write here in Markdown - paste or drop a picture to add it."><?= isset($document_markdown) && $document_markdown !== null ? escapeHtml($document_markdown) : '' ?></textarea>
<div class="itflow-markdown-preview itflow-document-body border border-top-0 rounded-bottom" data-markdown-preview hidden></div>
<div class="itflow-markdown-preview itflow-document-body itflow-prose border border-top-0 rounded-bottom" data-markdown-preview hidden></div>
</div>
<?php } ?>
</div>

View File

@@ -428,6 +428,46 @@ function itflowTinyMceSkin() {
};
}
/**
* A document as it reads on its page (.itflow-prose, css/itflow_custom.css), for the editing
* surface - which is an iframe, so the page's stylesheet and custom properties don't reach it
* and the values are passed in as literal text, as itflowTinyMceSkin() does.
*/
function itflowProseContentStyle() {
var root = getComputedStyle(document.documentElement);
function v(name, fallback) {
var value = root.getPropertyValue(name).trim();
return value || fallback;
}
var border = v('--bs-border-color', '#dee2e6');
var tint = v('--bs-tertiary-bg', '#f8f9fa');
var muted = v('--bs-secondary-color', '#6c757d');
var strong = v('--bs-emphasis-color', '#000');
return 'body{line-height:1.65;margin:1.25rem 1.5rem;}' +
'body>:first-child{margin-top:0;}' +
'h1,h2,h3,h4,h5,h6{margin:1.75rem 0 .6rem;font-weight:600;line-height:1.3;color:' + strong + ';}' +
'h1{font-size:1.6rem;}' +
'h2{font-size:1.3rem;padding-bottom:.35rem;border-bottom:1px solid ' + border + ';}' +
'h3{font-size:1.12rem;}' +
'h4{font-size:1rem;}' +
'h5,h6{font-size:.9rem;text-transform:uppercase;letter-spacing:.03em;color:' + muted + ';}' +
'p,ul,ol,table,pre,blockquote,figure{margin:0 0 1rem;}' +
'ul,ol{padding-left:1.5rem;}' +
'li+li{margin-top:.25rem;}' +
'hr{margin:2rem 0;border:0;border-top:1px solid ' + border + ';}' +
'img{max-width:100%;height:auto;border-radius:.375rem;}' +
'table{border-collapse:collapse;font-size:.925rem;}' +
// Every table with its lines, as on the page - not TinyMCE's dashed outline for one without a border
'table td,table th{padding:.4rem .65rem;border:1px solid ' + border + ' !important;}' +
'table th,table thead td{background-color:' + tint + ';font-weight:600;}' +
'pre{padding:.75rem 1rem;border:1px solid ' + border + ';border-radius:.375rem;background-color:' + tint + ';white-space:pre;overflow-x:auto;}' +
':not(pre)>code{padding:.1rem .3rem;border-radius:.25rem;background-color:' + tint + ';color:' + strong + ';}' +
'blockquote{margin-left:0;padding:.25rem 0 .25rem 1rem;border-left:.25rem solid ' + border + ';color:' + muted + ';}';
}
/**
* Chart.js defaults for the current colour mode.
*
@@ -633,10 +673,33 @@ function itflowInit() {
};
itflowTinyMce.init({ ...itflowDocumentEditor, selector: '.tinymce' });
// A document edited on its own page (agent/document_edit.php): the editor fills the window
// below the fields and scrolls inside itself, so the toolbar never scrolls away
itflowTinyMce.init({
// A document itself (agent/modals/document/document_form.php) - written as it will read on its
// page, and with what a document is made of on the toolbar, as the Markdown box has
const itflowDocumentWriter = {
...itflowDocumentEditor,
content_style: itflowDocumentEditor.content_style + itflowProseContentStyle(),
block_formats: 'Normal text=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4',
toolbar: [
...(itflowAiOn(false) ? [{ name: 'ai', items: ['reword'] }] : []),
{ name: 'styles', items: ['blocks'] },
{ name: 'formatting', items: ['bold', 'italic', 'strikethrough', 'forecolor'] },
{ name: 'link', items: ['link'] },
{ name: 'lists', items: ['bullist', 'numlist'] },
{ name: 'blocks', items: ['blockquote', 'codesample', 'table', 'hr'] },
{ name: 'alignment', items: ['alignleft', 'aligncenter', 'alignright'] },
{ name: 'indentation', items: ['outdent', 'indent'] },
{ name: 'extra', items: ['code', 'fullscreen'] },
{ name: 'history', items: ['undo', 'redo'] }
]
};
// ...in a window (New Document): room to write in, growing with what it says
itflowTinyMce.init({ ...itflowDocumentWriter, selector: '.tinymce-document', min_height: 420, max_height: Math.max(480, Math.round(window.innerHeight * 0.6)) });
// ...and on a page of its own (agent/document_edit.php): the editor fills the window below
// the fields and scrolls inside itself, so the toolbar never scrolls away. Ctrl+S saves.
itflowTinyMce.init({
...itflowDocumentWriter,
selector: '.tinymce-page',
plugins: 'link image lists table code codesample fullscreen',
min_height: 420,
@@ -652,6 +715,13 @@ function itflowInit() {
}
editor.on('init', fit);
window.addEventListener('resize', fit);
editor.addShortcut('meta+s', 'Save', function () {
const form = editor.getElement().closest('form');
const save = form ? form.querySelector('button[type="submit"][name]') : null;
if (save) {
form.requestSubmit(save);
}
});
}
});

View File

@@ -618,7 +618,7 @@
/*
* Markdown pasted into the rich text editor of a document, an article or a template (.tinymce,
* .tinymce-page). Only what is plainly Markdown is turned into formatting: a fenced code block,
* .tinymce-document, .tinymce-page). Only what is plainly Markdown is turned into formatting: a fenced code block,
* a table, a checklist, a link written as Markdown, or a heading with more Markdown after it.
* A script with # comments, or a few lines starting with a dash, goes in as it was.
*/
@@ -665,7 +665,7 @@
tinymce.on('AddEditor', function (added) {
var editor = added.editor;
var element = editor.getElement ? editor.getElement() : null;
if (!element || !element.classList || !(element.classList.contains('tinymce') || element.classList.contains('tinymce-page'))) {
if (!element || !element.classList || !['tinymce', 'tinymce-document', 'tinymce-page'].some(function (name) { return element.classList.contains(name); })) {
return;
}
var plainNext = false;