Repository navigation
v3.0.0
I'm happy to release and announce a new major version of this library, a full refresh of the was made, by rewriting it with TypeScript and using Tailwind for the styling.
New helpful features have been added and some unused features (unsaved changes) were replaced by listeners for better customization.
What's Changed
- Library code reimplemented with TypeScript to improve on type error checking
- UI redesigned with Tailwind instead of plain CSS code
- FontAwesome icons now included with the library
- Moved from using NPM to Yarn
- Migrated to Vite instead of Webpack (dropped support for old browsers)
New features
- TypeScript
index.d.tsfile exported with the bundled package for easier library usage - Elements now use
keyproperty instead of arrayindex(now you can move elements from one position to another) - Portrait and landscape page mode
- Added top banner at the page with page size, orientation and zoom level
- Move elements using
arrow keys - Move elements "faster" pressing
shiftandarrow keys - UI themes created by defining a Tailwind primary color (4 themes included)
- Localization files for English, Spanish, French, Italian, German, and Simplified Chinese
- Removed abbreviator
$.jEditorto use JavaScript ES modulesimport jEditor from "@medic-plus/js-document-editor - Elements can be selected from the side panel, with details section showing when selected
jEditorobject now is not global and all references are inside the editor inside a single variableconst myEditor = new jEditor(options, data)- Property
dataextracted fromoptionsand sent as a second parameter - Reworked position buttons to use one of this two
center(horizontal and vertical) andcardinal(NW, N, NE, E, C, W, SW, S and SE) - Background functionality has been extended so you can pass the
size,repeat, andpositionalong theurlparameter - Now paper sizes have a
orientationproperty allowing to set a default orientation when changed (ifforceOrientationis enabled) - Added a PDF generation example with the help of
html2canvasandjsPDFlibraries
New editor options:
fontSize: Default font size value for elements that doesn't have a value definedarrowStep: Amount of pixels to move element by an arrow key pressarrowShiftStep: Amount of pixels to move element by pressingshiftand an arrow keydragStep: Amount of pixels to move element when dragging with the mouse (grid snap)zoomThreshold: Value for the default zoom reset button (show more or less page)detailProperties,alignButtonsandpositionButtons: Changed detail view to use a customized panel for each elementpositionButtonsClassName: CSS class for position buttons (usegrid-col-2for center buttons andgrid-col-3for cardinal buttons)toastDuration: Default toast duration in milisecondsorientation: Page orientation defined asportraitorlandscapeforceOrientation: Sets the paper size orientation instead of the previous one- Listener functions:
onChange,onEditorChange,onSidebarChangeandonElementChange
New editor functions:
setLocale(locale): Now you can change the locale (string for included locales or Locale object for custom one) and re-render the page with a single function (you can also change the option and re-render manually)getDefaultLocales(): Returns the list of supported localessetTheme(theme): Sets the jEditor[data-theme="my-theme"]getDefaultThemes(): Returns the list of supported style themeshasData(key): Validates if an element has values on editor datagetElementData(key): Get element valuespushData(data): Add an element to the current valuespullData(key): Get and remove a single element values from the editor
Breaking Changes
Options
The following options have been renamed or changed:
container: It's required with no default valuedata: Moved as a second parameter for jEditor class defined asEditorData[]elements: Type defined asEditorElement[]zoomandzoomIncrement: Base changed from 0-1 to 0-100 (default zoom 100, default increment 10)sizeUnit: Renamed tounitssizeDecimals: Renamed todecimalsrendered: Renamed toeditorModepaperSizes: Type defined asPaperSize[], default value increased to 7 sizes (letter, half-letter, legal, tabloid, A3, A4 and A5)paperSize: Changed from string type toPaperSizesettings: Renamed totoolbarActionsas typeToolbarAction[]extraFunctions: Renamed tocustomToolbarActionsas typeCustomToolbarAction[]locale: Typed asLocalewith 18 properties (by default includedlocale/enandlocale/es)helper: Replaced bydetailPropertiesas typeUIElement[](set array as [] to disable functionality)
These options have been removed:
elementFunctions: Replaced byalignButtons,positionButtonsanddetailPropertiessaveButton: Replaced bycustomToolbarActionsand event listenerselementAction: Removed element propertyevents: Removed to use jEditor object functions
Functions
The following functions have been renamed, changed or removed:
setOptions(options): Now it replaces the whole options value, for old behavior usemergeOptions(options)setData(options): Now it replaces the whole data array, for old behavior usemergeData(data)renderObjects(): Renamed torenderElements(), for whole editor userender()setPaper(paperSize): Renamed tosetPaperSize(papserSize, orientation)setBackround(url): Removed, now changebackgroundproperty and run arender()orgetEditor().render()clearBackround(): Removed, now changebackgroundtoundefinedand render the editorunsaved(): Removed, now you can use event listeners to achieve the same (check live demo)- getObject(element): Changed to
getElementData(key)to get data
Events
This functions have been removed to use internal functions inside sidebar and editor components, some of them were moved to another location:
addElement(event): Now usegetSidebar().showElementListItem(key)removeElement(event): Now usegetSidebar().hideElementListItem(key)modifyElement(event): Now usegetSidebar().showDetails(key)orgetSidebar().clickElementListItem(key)cancelModifyElement(event): Not implemented but same behavior fromgetSidebar().showDetails("")zoomIn(): Now usegetEditor().zoomIn()zoomOut(): Now usegetEditor().zoomOut()zoomReset(): Now usegetEditor().resetZoom()changePaper():UsegetNextPageSize(options)from utils and thensetPaperSize(papserSize, orientation)setPaper(event, paperSize): Now usesetPaperSize(papserSize, orientation)renderObjects(): Now userenderElements()toast(text, css, timer): Now useshowToast(message, className, timeout)unsaved(): RemovedsaveData(): RemovedsetPageBackround(url): Now usebackgroundoption
- v3.0.0 by @IvanVasquez in #3
Full Changelog: v2.2.5...v3.0.0