pwix:editor
This is an encapsulation of 'trumbowyg' Javascript editor for Meteor, so a client-only package.
A bit of taxonomy
Documents
pwix:editor talks a lot of documents though, actually, pwix:editor doesn't know anything about them.
But it expects that these unknown and unmanaged documents have two main properties:
- a HTML content, said document's content here
- an optional name which identifies the document, said document's name here.
Edition mode
pwix:editor is able to manage four edition modes:
- 
Editor.C.Mode.HIDDENBuild the component, but do not display in the DOM. 
- 
Editor.C.Mode.STANDARDThe document's content is displayed as standard HTML: this is the default startup mode. In this mode, all the document's content is just displayed as if they were no editor at all. This way, you can safely directly integrates teScribercomponent in your pages without your standard user being conscious of anything.
- 
Editor.C.Mode.PREVIEWThe document's content is displayed inside of a thin panel. The header of this panel displays the document's name, along with two PreviewandEditbuttons. The document's content is displayed as standard HTML.
- 
Editor.C.Mode.EDITIONThis mode is an extension of the Editor.C.Mode.PREVIEW, where the user is able to actually edit the document's content. A buttons panel with different edition options (font size, color, etc.) along with a WYSIWYG HTML editor is available.
Configuration
The package's behavior can be configured through a call to the Editor.configure() method, with just a single javascript object argument, which itself should only contains the options you want override.
Known configuration options are:
- 
fontfamilyAddsA list of font families to be added to the default teEditorones.This is supposed to be an array of objects with following keys: - name: the displayed name
- family: the font face family.
 
- 
storeSwitchStateWhether the application plans to use the teSwitchcomponent and wishes to record its last state.When enabled, this option will create a cookie. This cookie is published to CookieManager as a functional one, and the user may refuse it. Default to false.
- 
uploadUrlThe URL to which the images should be uploaded. No default. 
- 
verbosityDefine the expected verbosity level. The accepted value can be any or-ed combination of following: - 
Editor.C.Verbose.NONEDo not display any trace log to the console 
- 
Editor.C.Verbose.COLLECTIONSTrace collections events. This includes on each and every collection: - declarations and definitions
- methods calls and results
 
- 
Editor.C.Verbose.COMPONENTSTrace Blaze components life: - creation
- rendering
- destruction
 
- 
Editor.C.Verbose.CONFIGURETrace Editor.configure()calls and their result
- 
Editor.C.Verbose.MODETrace edition mode changes 
- 
Editor.C.Verbose.SWITCHTrace the internal behavior of the teSwitchcomponent
- 
Editor.C.Verbose.TEMSGTrace te-xxxmessages
- 
Editor.C.Verbose.TRUMBOWYGTrace the 'trumbowyg' editor life: - instanciation and deletion
- internal messaging events
 
- 
Editor.C.Verbose.UPLOADTrace upload configuration and operations 
 
- 
Please note that Editor.configure() methmethod should be called in the same terms both in client and server sides.
Also note, as an explicit reminder for the fools, that, because the Meteor packages are instanciated at application level, they can be configured once at most, and only once at most. Each addtionnal call to Editor.configure() will just override the previous one. You have been warned: only the application should configure a package.
Provides
A global object
Editor
This object is allocated at package level: there is only one instance in your application. It gathers the avilable methods (see below).
This global object contains:
- 
Editor.ModesAn array of allowed edition modes. 
Methods
Constants
Edition modes
- Editor.C.Mode.HIDDEN
- Editor.C.Mode.STANDARD
- Editor.C.Mode.PREVIEW
- Editor.C.Mode.EDITION
Verbosity levels
- Editor.C.Verbose.NONE
- Editor.C.Verbose.COLLECTIONS
- Editor.C.Verbose.COMPONENTS
- Editor.C.Verbose.CONFIGURE
- Editor.C.Verbose.MODE
- Editor.C.Verbose.SWITCH
- Editor.C.Verbose.TEMSG
- Editor.C.Verbose.TRUMBOWYG
- Editor.C.Verbose.UPLOAD
Blaze components
teManager
A panel which let the application manage its documents.
The component is configurable with an object passed as an argument, which may contain:
- 
collectionThe collection name, defaulting to te_contents.
- 
plusButtonWhether the manager should exhibit a 'plus' button, defaulting to true.
teScriber
The editor component itself.
The component is configurable with an object passed as an argument, which may contain:
- 
contentAn optional input/output ReactiveVar which is expected to contain the ... document's content (by the way), interpreted as a HTML string. It not provided, the component just displays an empty editing area, and advertises of its updates through the te-content-changedevent.
- 
modeThe edition mode as a string, defaulting to Editor.C.Mode.STANDARD.
- 
documentThe document's name as a string, defaulting to the empty string. 
- 
displayNameWhether to display the name in the topmost panel, defaulting to true.
- 
withNamePanelWhether to display the topmost panel, which would include the document's name and the preview/edit buttons, defaulting to true.
- 
withHTMLBtnWhether to authorize the HTML button, which should be reserved to advanced users, defaulting to true.
- 
withFullScreenBtnWhether to authorize the FullScreen button, which should be reserved to edit full articles, defaulting to true.
- 
fontfamilyAddsAn array of font families to be added to those already managed by the editor. Example: [ { name: 'Arial', family: 'Arial, Helvetica, sans-serif' } ]
The teScriber component doesn't provide any save way. Instead, it provides two ways for the caller be informed of the changes:
- 
the contentReactiveVar, if provided, is continuously updated,
- 
a te-content-changedmessage is sent on the component on each change.
teSerializer
This is an encapsulation of the Editor component, which manages the serialization/deserialization of the documents.
The component is configurable with an object passed as an argument, which may contain:
- 
collectionThe collection name, defaulting to te_contents.teSerializerexpects that the collection supportsname,content,createdAt,createdBy,updatedAtandupdatedBystandard fields.The Editor.collections.Contents.schemaschema can be used as a to-be-extended base schema by the application.
- 
documentThe document name in the database. Mandatory. 
- 
modeThe desired edition mode, defaulting to Editor.C.Mode.STANDARD
Because teSerializer is an encapsulation of teScriber, then teScriber needed arguments can also be passed through the argument object.
teSwitch
A switch which let the user toggle the edition mode.
Use case: particularly in development mode, it happens that the Editor.C.Mode.PREVIEW may slightly disturb the display. This switch, when toggled to off, let the editor run in Editor.C.Mode.STANDARD even when the user is allowed to edit.
The component is configurable with an object passed as an argument, which may contain:
- 
labelTopA (HTML) string to be displayed above the switch, defaulting to none 
- 
labelRightA (HTML) string to be displayed on the right of the switch, defaulting to none 
- 
labelBottomA (HTML) string to be displayed below the switch, defaulting to none 
- 
labelLeftA (HTML) string to be displayed on the left of the switch, defaulting to none 
- 
titleA string label as the button title, defaulting to none 
- 
stateWhether the switch is initially onoroff, defaulting tooff
- 
enabledWhether the switch is initially enabled, defaulting to true
The teSwitch component maintains its state through two Editor reaactive variables:
- 
Editor.switch.usedWhether the application makes use of the teSwitchcomponent. The variable is set totruewhen the component is created, set tofalseon destruction.
- 
Editor.switch.stateWhen used, the state of the teSwitchcomponent, astrueforon,falseforoff.
Events
Informational messages
Informational messages are sent by the component on itself. The caller can take advantage of them to be kept informed about the various changes.
- 
te-mode-changedTriggered on the teScriberelement when the edition mode changes.Provides an object { prev: <previous_mode>, new: <new_mode> }
- 
te-content-changedTriggered on the teScriberelement when the content has been changed (inEditor.C.Mode.EDITIONmode only).Provides an object { html: <html> }or{ html: <html>, name: <name> }, depending whether anamehas been provided or not.
- 
te-initializedTriggered on the teScriberelement when the editor has been initialized (inEditor.C.Mode.PREVIEWorEditor.C.Mode.EDITIONmodes).
- 
te-serializedTriggered on the teSerializerelement when the content has been serialized.Provides an object { result: <result> }.
- 
te-switch-on
- 
te-switch-offTriggered on the teSwitchcomponent when the switch state changes. The message advertises of the new state of the switch.
Action messages
Action messages are the way the caller can interact with the component during its lifetime. They must be sent to the teScriber component.
- 
te-content-resetForce the editor to take into account the current content of the provided ReactiveVar. May be useful when the caller has to cancel a done edition, and restore a previous value. The te-content-changedmessage is not sent when this action is requested.
- 
te-mode-setChange the mode to the specified one. Expects an object { mode: <mode> }.
Fonts
pwix:editor provides following fonts:
- Arial
- Arial Black
- Comic Sans
- Courier
- Cousine
- Josefin Sans
- Orbitron
- Serpentine
- Ubuntu Mono.
NPM peer dependencies
Starting with v 1.0.0, and in accordance with advices from the Meteor Guide, we no more hardcode NPM dependencies in the Npm.depends clause of the package.js.
Instead we check npm versions of installed packages at runtime, on server startup, in development environment.
Dependencies as of v 1.4.0:
'jquery-resizable-dom': '^0.35.0', 'lodash': '^4.17.0', 'uuid': '^9.0.0 || ^10.0.0'
Each of these dependencies should be installed at application level:
meteor npm install <package> --save
Translations
New and updated translations are willingly accepted, and more than welcome. Just be kind enough to submit a PR on the Github repository.
Cookies and comparable technologies
pwix:editor may use localStorage to record some valuable data.
pwix:editor/switch_state
The last teSwitch state.
Allowed/disallowed through the storeSwitchState configuration parameter.
This is considered a disableable functional cookie, and is advertised as such to the CookieManager if it is present.
P. Wieser
- Last updated on 2024, Sep. 20th

