Browse Source

Update canvas docs

pull/3725/head
Artur Arseniev 5 years ago
parent
commit
1c7d52b95d
  1. 105
      src/canvas/index.js

105
src/canvas/index.js

@ -26,6 +26,8 @@
* * [setZoom](#setzoom) * * [setZoom](#setzoom)
* * [getZoom](#getzoom) * * [getZoom](#getzoom)
* *
* [Component]: component.html
*
* @module Canvas * @module Canvas
*/ */
@ -48,11 +50,6 @@ export default () => {
return CanvasView; return CanvasView;
}, },
/**
* Name of the module
* @type {String}
* @private
*/
name: 'Canvas', name: 'Canvas',
/** /**
@ -88,7 +85,9 @@ export default () => {
/** /**
* Get the configuration object * Get the configuration object
* @return {Object} * @returns {Object} Configuration object
* @example
* console.log(canvas.getConfig())
*/ */
getConfig() { getConfig() {
return c; return c;
@ -96,7 +95,7 @@ export default () => {
/** /**
* Get the canvas element * Get the canvas element
* @return {HTMLElement} * @returns {HTMLElement}
*/ */
getElement() { getElement() {
return CanvasView.el; return CanvasView.el;
@ -107,8 +106,8 @@ export default () => {
}, },
/** /**
* Get the iframe element of the canvas * Get the main frame element of the canvas
* @return {HTMLIFrameElement} * @returns {HTMLIFrameElement}
*/ */
getFrameEl() { getFrameEl() {
const { frame } = CanvasView || {}; const { frame } = CanvasView || {};
@ -120,16 +119,16 @@ export default () => {
}, },
/** /**
* Get the window instance of the iframe element * Get the main frame window instance
* @return {Window} * @returns {Window}
*/ */
getWindow() { getWindow() {
return this.getFrameEl().contentWindow; return this.getFrameEl().contentWindow;
}, },
/** /**
* Get the document of the iframe element * Get the main frame document element
* @return {HTMLDocument} * @returns {HTMLDocument}
*/ */
getDocument() { getDocument() {
const frame = this.getFrameEl(); const frame = this.getFrameEl();
@ -137,7 +136,7 @@ export default () => {
}, },
/** /**
* Get the body of the iframe element * Get the main frame body element
* @return {HTMLBodyElement} * @return {HTMLBodyElement}
*/ */
getBody() { getBody() {
@ -159,7 +158,7 @@ export default () => {
/** /**
* Returns element containing all global canvas tools * Returns element containing all global canvas tools
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getGlobalToolsEl() { getGlobalToolsEl() {
@ -168,7 +167,7 @@ export default () => {
/** /**
* Returns element containing all canvas tools * Returns element containing all canvas tools
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getToolsEl(compView) { getToolsEl(compView) {
@ -177,7 +176,7 @@ export default () => {
/** /**
* Returns highlighter element * Returns highlighter element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getHighlighter(compView) { getHighlighter(compView) {
@ -186,7 +185,7 @@ export default () => {
/** /**
* Returns badge element * Returns badge element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getBadgeEl(compView) { getBadgeEl(compView) {
@ -195,7 +194,7 @@ export default () => {
/** /**
* Returns placer element * Returns placer element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getPlacerEl() { getPlacerEl() {
@ -204,7 +203,7 @@ export default () => {
/** /**
* Returns ghost element * Returns ghost element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getGhostEl() { getGhostEl() {
@ -213,7 +212,7 @@ export default () => {
/** /**
* Returns toolbar element * Returns toolbar element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getToolbarEl() { getToolbarEl() {
@ -222,7 +221,7 @@ export default () => {
/** /**
* Returns resizer element * Returns resizer element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getResizerEl() { getResizerEl() {
@ -231,7 +230,7 @@ export default () => {
/** /**
* Returns offset viewer element * Returns offset viewer element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getOffsetViewerEl(compView) { getOffsetViewerEl(compView) {
@ -244,17 +243,13 @@ export default () => {
/** /**
* Returns fixed offset viewer element * Returns fixed offset viewer element
* @return {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getFixedOffsetViewerEl() { getFixedOffsetViewerEl() {
return CanvasView.fixedOffsetEl; return CanvasView.fixedOffsetEl;
}, },
/**
* Render canvas
* @private
* */
render() { render() {
CanvasView && CanvasView.remove(); CanvasView && CanvasView.remove();
CanvasView = new canvasView({ CanvasView = new canvasView({
@ -266,7 +261,7 @@ export default () => {
/** /**
* Get frame position * Get frame position
* @return {Object} * @returns {Object}
* @private * @private
*/ */
getOffset() { getOffset() {
@ -281,7 +276,7 @@ export default () => {
/** /**
* Get the offset of the passed component element * Get the offset of the passed component element
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @returns {Object}
* @private * @private
*/ */
offset(el) { offset(el) {
@ -303,7 +298,7 @@ export default () => {
/** /**
* Get element position relative to the canvas * Get element position relative to the canvas
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @returns {Object}
* @private * @private
*/ */
getElementPos(el, opts) { getElementPos(el, opts) {
@ -313,7 +308,7 @@ export default () => {
/** /**
* Returns element's offsets like margins and paddings * Returns element's offsets like margins and paddings
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @returns {Object}
* @private * @private
*/ */
getElementOffsets(el) { getElementOffsets(el) {
@ -513,7 +508,7 @@ export default () => {
/** /**
* Check if the canvas is focused * Check if the canvas is focused
* @return {Boolean} * @returns {Boolean}
*/ */
hasFocus() { hasFocus() {
return this.getDocument().hasFocus(); return this.getDocument().hasFocus();
@ -541,7 +536,7 @@ export default () => {
* executed via `scrollIntoView` API and options of this method are * executed via `scrollIntoView` API and options of this method are
* passed to it. For instance, you can scroll smoothly by using * passed to it. For instance, you can scroll smoothly by using
* `{ behavior: 'smooth' }`. * `{ behavior: 'smooth' }`.
* @param {HTMLElement|Component} el * @param {HTMLElement|[Component]} el
* @param {Object} [opts={}] Options, same as options for `scrollIntoView` * @param {Object} [opts={}] Options, same as options for `scrollIntoView`
* @param {Boolean} [opts.force=false] Force the scroll, even if the element is already visible * @param {Boolean} [opts.force=false] Force the scroll, even if the element is already visible
* @example * @example
@ -576,9 +571,11 @@ export default () => {
}, },
/** /**
* Set zoom value * Set canvas zoom value
* @param {Number} value The zoom value, from 0 to 100 * @param {Number} value The zoom value, from 0 to 100
* @returns {this} * @returns {this}
* @example
* canvas.setZoom(50) // set zoom to 50%
*/ */
setZoom(value) { setZoom(value) {
canvas.set('zoom', parseFloat(value)); canvas.set('zoom', parseFloat(value));
@ -586,8 +583,11 @@ export default () => {
}, },
/** /**
* Get zoom value * Get canvas zoom value
* @returns {Number} * @returns {Number}
* @example
* canvas.setZoom(50) // set zoom to 50%
* const zoom = canvas.getZoom() // 50
*/ */
getZoom() { getZoom() {
return parseFloat(canvas.get('zoom')); return parseFloat(canvas.get('zoom'));
@ -616,23 +616,22 @@ export default () => {
* @param {Object} props Frame properties * @param {Object} props Frame properties
* @returns {Frame} * @returns {Frame}
* @example * @example
* * canvas.addFrame({
editor.Canvas.addFrame({ * name: 'Mobile home page',
name: 'Mobile home page', * x: 100, // Position in canvas
x: 100, // Position in canvas * y: 100,
y: 100, * width: 500, // Frame dimensions
width: 500, // Frame dimensions * height: 600,
height: 600, * // device: 'DEVICE-ID',
// device: 'DEVICE-ID', * components: [
components: [ * '<h1 class="testh">Title frame</h1>',
'<h1 class="testh">Title frame</h1>', * '<p class="testp">Paragraph frame</p>',
'<p class="testp">Paragraph frame</p>', * ],
], * styles: `
styles: ` * .testh { color: red; }
.testh { color: red; } * .testp { color: blue; }
.testp { color: blue; } * `,
`, * });
});
*/ */
addFrame(props = {}, opts = {}) { addFrame(props = {}, opts = {}) {
return canvas.get('frames').add( return canvas.get('frames').add(

Loading…
Cancel
Save