Documentations › mmo.editor › js › éditeur SectionEditor MMO.editor · 1 symbole · générée le 27 Oct 2026
The section-type editor: the types of section of the site -- their fields (the schema), their template (PHP), their styles -- made and changed from the browser, with a live preview. Everything goes through the api (admin/section-types…, `MMO.editor.config.sectionTypes). <mmo-section-editor>` is its element.
class MMO.editor.SectionEditor Espace de noms MMO.editor- The site's types are written (the folder `Pages::$typesFolder`); the others -- mmo.editor's, another folder's --
are shown read only, and « Copy to my site » makes a copy that replaces them.
- « Fields » edits the schema as a form: each field has a kind (text, rich text, link, image, choice, list…), a
label, an example. « Schema » is the same json, by hand. « Template » is the PHP drawing the section: « Generate
from the fields » writes one to start from. « Styles » is the type's css.
- A template is PHP that the server runs: the right to write one (`editor.sections#edit`) is a developer's.
Events: `api` (each call), `saved` (`detail`: the type). new MMO.editor.SectionEditor(document.getElementById('types'), {type: 'faq'});
Index KINDS static the kinds of field, and the schema each one is constructor(node, options) destroy() h(tag, attrs, children) $(name) t(text, context) notify(text) ask(title, text) confirm(title, text) code(name, oninput) [internal] A code area: monospace, Tab indents build() [internal] The editor's own nodes: a bar, the tabs, the preview showTab(id) call(method, path, body, {raw = false, retry = true}) async start() async loadTypes() async The types, in the picker: the site's first, then the others (read only) open(name, force) async setType(type) renderStatus() changed() create() async Make a new type of the site: a name, then a title field to start from (saved with « Save ») save() async copy() async remove() async generate() async showErrors(errors) Show what the api says is wrong: in a list, and on the tab of each parse(json) setSchemaText(text) The json was typed by hand: the fields follow it when it is valid schemaChanged() The fields changed: the json follows kindOf(field) convert(field, kind) renderFields() [internal] The type's settings, and its fields as cards fieldsEditor(properties, ro, nested) [internal] @return {HTMLElement} the cards of the fields of $properties (an object's, or a list's items') fieldCard(key, field, {rename, move, remove, index, first, last, ro, nested}) [internal] @return {HTMLElement} the card of one field: its name, its kind, its label… its own fields for a list input(label, value, onchange, {help = null, wide = false, area = false, type = 'text', change = false, disabled = false}) [internal] @return {HTMLElement} a labelled input; onchange gets the value (false keeps the input as it was) select(label, value, options, onchange, disabled) check(label, checked, onchange, disabled) preview() Render a page holding one section of the type as the editor has it, a moment after the last change
Constantes1 the kinds of field, and the schema each one is
static KINDS = {
text: {label: 'Text', schema: () => ({type: 'string', default: ''})},
inline: {label: 'Rich text, one line', schema: () => ({type: 'string', format: 'html', editor: 'inline', default: ''})},
rich: {label: 'Rich text', schema: () => ({type: 'string', format: 'html', tools: 'bold,italic,link|ul,ol', default: '<p></p>'})},
link: {label: 'Link (text and address)', schema: () => ({type: 'object', properties: {label: {type: 'string', label: 'Text', default: 'Read more'}, url: {type: 'string', format: 'url', label: 'Link', default: '#'}}})},
url: {label: 'Address', schema: () => ({type: 'string', format: 'url', default: ''})},
image: {label: 'Image', schema: () => ({type: 'object', format: 'image', properties: {src: {type: 'string', label: 'Address', default: ''}, alt: {type: 'string', label: 'Description', level: 'standard', default: ''}}})},
choice: {label: 'Choice', schema: () => ({type: 'string', enum: ['one', 'two'], default: 'one'})},
boolean: {label: 'Yes / no', schema: () => ({type: 'boolean', default: false})},
number: {label: 'Number', schema: () => ({type: 'integer', default: 0})},
list: {label: 'List of items', schema: () => ({type: 'array', items: {type: 'object', properties: {title: {type: 'string', label: 'Title', minLength: 1, default: 'An item'}}}, default: [{title: 'An item'}]})},
object: {label: 'Group of fields (edit it in « Schema »)', schema: () => ({type: 'object', properties: {}})},
}; Méthodes36 constructor(node, options = {}) node HTMLElement- where it is built options = {}
destroy() h(tag, attrs = {}, ...children) $(name) t(text, context = null) notify(text) ask(title, text) title text retourne Promise<string | false>what the user typed, false when cancelled
confirm(title, text) [internal] A code area: monospace, Tab indents
code(name, oninput) [internal] The editor's own nodes: a bar, the tabs, the preview
build() showTab(id) async call(method, path, body = undefined, {raw = false, retry = true} = {}) method path body = undefined {raw = false, retry = true} = {}
async start() The types, in the picker: the site's first, then the others (read only)
async loadTypes() async open(name, force = false) setType(type) renderStatus() changed() Make a new type of the site: a name, then a title field to start from (saved with « Save »)
async create() async save() async copy() async remove() async generate() Show what the api says is wrong: in a list, and on the tab of each
showErrors(errors) parse(json) json retourne ?Object$json parsed, null when it is not a json object
The json was typed by hand: the fields follow it when it is valid
setSchemaText(text) The fields changed: the json follows
schemaChanged() kindOf(field) field retourne stringthe kind of a field (KINDS)
convert(field, kind) field kind retourne Object$field as a $kind: its label, help and level kept
[internal] The type's settings, and its fields as cards
renderFields() [internal] @return {HTMLElement} the cards of the fields of $properties (an object's, or a list's items')
fieldsEditor(properties, ro, nested = false) properties ro nested = false
[internal] @return {HTMLElement} the card of one field: its name, its kind, its label… its own fields for a list
fieldCard(key, field, {rename, move, remove, index, first, last, ro, nested}) key field {rename, move, remove, index, first, last, ro, nested}
input(label, value, onchange, {help = null, wide = false, area = false, type = 'text', change = false, disabled = false}) SectionEditor.js:521 [internal] @return {HTMLElement} a labelled input; onchange gets the value (false keeps the input as it was)
input(label, value, onchange, {help = null, wide = false, area = false, type = 'text', change = false, disabled = false} = {}) label value onchange {help = null, wide = false, area = false, type = 'text', change = false, disabled = false} = {}
select(label, value, options, onchange, disabled = false) label value options onchange disabled = false
check(label, checked, onchange, disabled = false) label checked onchange disabled = false
Render a page holding one section of the type as the editor has it, a moment after the last change
preview()