<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[TheBrand.app - Medium]]></title>
        <description><![CDATA[All things about iOs, Android, Web and Games development. - Medium]]></description>
        <link>https://medium.com/thebrand?source=rss----c5ebdf2c8903---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>TheBrand.app - Medium</title>
            <link>https://medium.com/thebrand?source=rss----c5ebdf2c8903---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 04:23:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/thebrand" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ISO-3166 Country and Province Codes]]></title>
            <link>https://medium.com/thebrand/iso-3166-country-and-province-codes-b11352313be?source=rss----c5ebdf2c8903---4</link>
            <guid isPermaLink="false">https://medium.com/p/b11352313be</guid>
            <category><![CDATA[country-code]]></category>
            <category><![CDATA[subdivision]]></category>
            <category><![CDATA[iso3166]]></category>
            <dc:creator><![CDATA[Kamalesh Basu]]></dc:creator>
            <pubDate>Mon, 18 Apr 2022 07:45:54 GMT</pubDate>
            <atom:updated>2022-04-18T07:45:54.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8ujlST3GF3F4V8p29yoBQ.jpeg" /><figcaption>Photo Credit: <a href="https://unsplash.com/@farzadme">https://unsplash.com/@farzadme</a></figcaption></figure><h3>What it is?</h3><p>ISO 3166 defines and standardises</p><blockquote>internationally recognized codes of letters and/or numbers that we can use when we refer to countries and their subdivisions.</blockquote><p>ISO 3166 defines 3 unique codes for each internationally recognised country:</p><ul><li><strong>alpha-2: </strong>Two Character Alpha code consisting of two letters of the English alphabet</li><li><strong>alpha-3:</strong> Three Character Alpha code consisting of three letters of the English alphabet</li><li><strong>numeric-3:</strong> A three digit numeric code</li></ul><p>Additionally, ISO 3166–1 and ISO 3166–2 define Alphanumeric Codes for subdivisions, provinces, parishes, etc. for each of these countries.</p><p>You can grab this information from this link: <a href="https://www.iso.org/iso-3166-country-codes.html">https://www.iso.org/iso-3166-country-codes.html</a></p><h3>Needed a JSON Format</h3><p>Recently, while working on an App, I needed the list of all countries, country codes and province codes in a <strong>.json</strong>, <strong>.xml</strong> or <strong>.csv</strong> format.</p><p>I was unable to find a free and easily available source without having to scrape/parse a site. So I decided to put one together.</p><p>Here it is if you need a similar data source for your work:</p><p><a href="https://github.com/kamaleshbasu/ISO-3166">GitHub - kamaleshbasu/ISO-3166: International Standard for country codes and codes for their subdivisions</a></p><p>The JSON index is the <strong>alpha-2</strong> code of the country.</p><h3>Plans ahead</h3><p><strong>Province Types</strong>: Planning to add Subdivision Types and Subdivision hierarchy.</p><p><strong>Language Codes</strong>: Will add all language codes for the countries and the subdivisions.</p><p><strong>RESTful Service</strong>: Once the above is complete, might create a RESTful service for querying the dataset. This might be a long term goal based on my time and requirements.</p><p>Let me know if there is anything else you would like to see for this dataset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b11352313be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebrand/iso-3166-country-and-province-codes-b11352313be">ISO-3166 Country and Province Codes</a> was originally published in <a href="https://medium.com/thebrand">TheBrand.app</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bezier Animations — UI elements to Flutter Widgets (Part 2)]]></title>
            <link>https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-2-25829255768e?source=rss----c5ebdf2c8903---4</link>
            <guid isPermaLink="false">https://medium.com/p/25829255768e</guid>
            <category><![CDATA[ui-ux-design]]></category>
            <category><![CDATA[bezier]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Kamalesh Basu]]></dc:creator>
            <pubDate>Sat, 01 Feb 2020 11:17:37 GMT</pubDate>
            <atom:updated>2020-02-01T11:46:06.461Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bezier Animations — UI elements to Flutter Widgets (Part 2)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5IwI3UFT8BmTwyY9k_vcbg.jpeg" /></figure><p>In <a href="https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-1-95c04b6ba1c4"><strong>Part 1</strong></a> of this Article, we took a look at how we can export paths/shapes from UX design software into our Flutter App while maintaining the design integrity and ensuring we get an accurate representation of the paths created by the designer. I suggest you give it a quick read, before going ahead with this.</p><p>The <a href="https://github.com/kamaleshbasu/bezier_animation">repository</a> for the tutorial and the <a href="https://github.com/kamaleshbasu/bezier_animation/blob/master/adobe_xd/login-ui.xd">design file </a>we are working with is the same as Part 1.</p><p>In Part 1, we ended up with this main.dart file. We will continue from here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3eb7879d15db8b43b54448c9a0f150e3/href">https://medium.com/media/3eb7879d15db8b43b54448c9a0f150e3/href</a></iframe><h3>8. Making the Vector Path Parametric</h3><p>In order to obtain the two paths in our design file (Adobe XD), we wrote two methods — one for the first path and one for the second (_getInitialPath and _getFinalPathrespectively). This is not very useful as we have no way of obtaining intermediate steps when going from one path to another. And hence we can’t animate our path this way.</p><p>So we need to rewrite our clipping method in such a way that it can generate the two paths and any intermediate paths that we will need to animate. We need to first convert our method into a <a href="https://en.wikipedia.org/wiki/Parametric_equation"><strong>parametric function</strong></a>. A parametric function is a method whose workings (in our case rendering the path) depends on 1 or more variables — it could be class variables or method variables or both.</p><p>We are going to use a <strong>point-wise linear extrapolation</strong> to write our parametric function. Let’s break that down.</p><p><strong>A. Point-Wise</strong>: If we look at our functions _getInitialPath and _getFinalPath , we will see that the first Bezier segment (a vertical line) that we draw for both paths are:</p><pre><strong>For first curve:</strong><br>path.lineTo(-0.003999999999997783 * _xScaling,341.78499999999997 * _yScaling);</pre><pre><strong>For final curve:<br></strong>path.lineTo(-0.003999999999997783 * _xScaling,217.841 * _yScaling);</pre><p>There is one point involved in each of these Bezier instructions with an x -coordinate and any -coordinates.</p><p>Point-wise extrapolation means, for each and every Bezier segment, we will look at individual points involved in the segment — the initial point, the final point, and the control points. And then we are going to write a parametric function to define these points — so that the parametric function generates the initial and final coordinates of this point and intermediate coordinates of the point. As a matter of fact, for each point, we will write 4 parametric functions for:</p><ol><li>x -coordinate</li><li>y -coordinate</li><li>_xScaling</li><li>_yScaling</li></ol><p>Each of these is a number of type double .</p><p>The scaling factors ensure that the path stretches and fits for all device sizes. Also, the scaling factors are the same for all the points involved in the path. So we only need to write them once and reuse them for all the points.</p><blockquote>In Part 1 of this Article, I assumed that both paths have the same number of points. I recommended adding points along the path, if a path has fewer points than the other. As you can see, we need to insist that both paths have the same number of points otherwise we can’t use <strong>point-wise</strong> parametric functions.</blockquote><blockquote>There are techniques that can deal with such sets of paths without adding extra points but I will leave that out for another discussion. In my opinion, point-wise strategy works very well and is very efficient. Hence, you can almost always stick to it.</blockquote><p><strong>B. </strong><a href="https://en.wikipedia.org/wiki/Extrapolation"><strong>Linear Extrapolation</strong></a><strong>:</strong> We have boiled down our problem to writing parametric functions for the 4 above numeric values. So let’s focus on one of them.</p><p>Let’s say hypothetically, the y -coordinate of the point in the initial path is 10 and that in the final path is 20 . Line extrapolation means when we are half-way through our animation, the y -coordinate should have reached the value of 15 . If we are 30% -of the way in our animation, the y -coordinate should have reached the value of 13 and so on.</p><p>Let’s formalize this idea. Let’s call the initial value of y -coordinate as y1 and the final value as y2 . Then the difference between these two values, deltaY = y2-y1 . Instead of using percentages, we are going to use decimals to denote our animation progress. 0will mean the initial state and 1will mean the final state.</p><p>So if my animation (while going from initial to final state) has progressed by an amountprogress , my y -coordinate should be:</p><pre>y = y1 + deltaY * progress</pre><p>This is our <strong>parametric function </strong>for the y-coordinate of the point. And we will do this to each of the 4 numbers associated with the point ( x , y , _xScaling and _yScaling ). And then we will do it for all the points associated with the Bezier segment and then we will do that for all the Bezier segments. And that will be our new getClip method. This process is sometimes called <strong>Bezier Tweening</strong>.</p><blockquote>A quick note. We are using a Linear Extrapolation, which is most often the case. But if you follow this <a href="https://en.wikipedia.org/wiki/Extrapolation">Wikipedia link</a>, you will see other types of extrapolation and you might want to use those for your project. In general, my advice is to use Linear extrapolation for your <strong>parametric function</strong> and then implement non-linear behavior through your <a href="https://api.flutter.dev/flutter/animation/AnimationController-class.html"><strong>AnimationController</strong></a>. More on it in a bit.</blockquote><h4>8.1 This is too daunting!</h4><p>At this point, you might be thinking this is too scary and tedious. For a lot of languages and frameworks, Bezier Tweening libraries already exist. <a href="https://greensock.com/">GreenSock</a> is one such library that handles all of this for you if you are dealing with web animations. Currently, at the time of writing, there is no library that I have found that neatly does this for Dart/Flutter. If you know of any, please let me know in the comments.</p><p>So I wrote a <a href="https://itchylabs.com/tools/path-to-bezier-tweener/"><strong>simple tool</strong></a>, which generates the Dart/Flutter code for doing exactly that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqsj4f1aTRP2OySf-YWCTw.png" /><figcaption>Dart/Flutter Code Generator for Simple Bezier Tweening</figcaption></figure><p>You can set up each path, just as we did in Part 1 of the article. Here is the video on how to set up each path:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBKAGrdIYnfI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBKAGrdIYnfI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBKAGrdIYnfI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd6614fee526bcc4a8e9af8e5a9fb7fa/href">https://medium.com/media/fd6614fee526bcc4a8e9af8e5a9fb7fa/href</a></iframe><p>Once you hit the <strong>Generate ClipPath Tween</strong> button, it will generate the parametric function for your paths:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*12Y2-rNXXZxup3kxDmsJEw.png" /><figcaption>Generated Dart/Flutter code for our Clipper Class</figcaption></figure><p>As you can see, this parametric function is making use of the progress parameter which will represent our animation progress. We will define it as a class variable.</p><h3>9. Toggling with Parametric Function</h3><p>Before we get to animating, let’s see if we can reproduce the toggling behavior we achieved by using the two clipping methods at the end of <strong>Part 1</strong>.</p><ol><li>Delete the _getInitialPath and _getFinalPath methods.</li><li>Replace the getClip method with the method generated by the Bezier Tweening tool.</li><li>Delete the class variable state from <strong>BezierClipper</strong> and define a doubleclass variable progress. Update our constructor and it should be something like:</li></ol><pre>final <em>double</em> progress;<br><em>BezierClipper</em>(this.progress);</pre><pre>@overide<br>Path getClip(Size size){<br>   //Code generated by Bezier Tweener tool<br>}</pre><pre>@override<br><em>bool</em> shouldReclip(<em>CustomClipper</em>&lt;<em>Path</em>&gt; oldClipper) =&gt; true;</pre><p>4. Next, we focus on the <strong>_AnimationPageState</strong> class. Replace state variable with double progress and update the _toggle() method accordingly:</p><pre>double progress = 0;</pre><pre>_toggle(){<br>  setState((){<br>    progress = progress == 0 ? 1 : 0;<br>  });<br>}</pre><p>In the build method of the class replace the state variable with progress . If you reload the App, you will see we manage to get back our toggle function, but this time with the <strong>Parametric </strong><strong>getClip</strong>function.</p><h3>10. Parametric function for the Container</h3><p>We just need to fix one more thing before we can animate. If you look at our design file, the two paths are of different heights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TmqBEe7PBa_ec9P9pttKyg.png" /><figcaption>Heights of Paths are different.</figcaption></figure><p>But in our app, the height of the container doesn’t change. We will fix that. In the initial state, the path occupies about 0.405 of the Artboard height and in the second path it is about 0.337 of the Artboard height. We define a new parametric equation for the <strong>Container</strong> height.</p><pre>final <strong>heightScaling</strong> = 0.405 + (0.337 - 0.405) * progress;<br>final <strong>height</strong> = <em>MediaQuery</em>.of(context).size.height * heightScaling;</pre><p>And now when we toggle, the height of the Container also adjusts itself.</p><h3>11. Animating the Bezier Paths</h3><ol><li>Add an <a href="https://api.flutter.dev/flutter/animation/AnimationController-class.html"><strong>AnimationController</strong></a><strong>, </strong>an <a href="https://api.flutter.dev/flutter/animation/Animation-class.html"><strong>Animation</strong></a> variable and boolean to the <strong>_AnimationPageState</strong> class. We also remove the progress variable.</li></ol><pre><em>bool</em> isFinalState = false;<br><em>AnimationController</em> _controller;<br><em>Animation</em>&lt;<em>double</em>&gt; _animation;</pre><p>2. Next, we initiate the variables and also setup the disposemethod:</p><pre><em>@override<br>void</em> initState()<br>{<br>  super.initState();</pre><pre>  _controller =  <em>AnimationController</em>(<br>    vsync: this, <br>    duration: <em>Duration</em>(milliseconds: 1000)<br>  );</pre><pre>  _animation = <em>CurvedAnimation</em>(<br>    parent: _controller,<br>    curve: <em>Curves</em>.easeOut, <br>    reverseCurve: <em>Curves</em>.easeIn,<br>   );<br>}</pre><pre><em>@override</em><br><em>void</em> dispose() {<br>  _controller.dispose();<br>  super.dispose();<br>}</pre><p>Note that we use easeOut and easeIn as our animation curves. This is obtained from the Adobe XD design file and going to the <strong>Prototype</strong> tab. If you inspect the Animation, it is of type easeOut and so we used easeIn as the reverseCurve. This is how we add <strong>non-linearity</strong> in our animations and can keep our Path parametric function linear.</p><p>3. Next, we need to wrap our <strong>ClipPath</strong> with an <strong>AnimationBuilder</strong> widget:</p><pre><strong><em>AnimatedBuilder</em>(<br>  animation: _controller,<br>  builder: (context, anim){</strong><br>    <strong>final <em>double</em> progress = _animation.value;</strong><br>    final <em>double</em> heightScaling = 0.405 + (0.337 - 0.405) * progress;<br>    final <em>double </em>height = <em>MediaQuery</em>.of(context).size.height * heightScaling;</pre><pre>    return <em>ClipPath</em>(<br>      clipper: <em>BezierClipper</em>(progress),<br>      child: <em>Container</em>(<br>        color : <em>Color</em>.fromRGBO(255, 91, 53, 1),<br>        height: height,<br>      ),<br>    );<br>  }<br><strong>),</strong></pre><p>4. Remove the padding property from the <strong>Toggle </strong>button Container. We don’t need it anymore.</p><p>And our animation is done!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fc7cOs7aj4_A%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dc7cOs7aj4_A&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fc7cOs7aj4_A%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/019551221ae418fbecf31766cb120148/href">https://medium.com/media/019551221ae418fbecf31766cb120148/href</a></iframe><p>And here is our final main.dart file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d0a9c61344a5a650f0fc4326465a91b/href">https://medium.com/media/6d0a9c61344a5a650f0fc4326465a91b/href</a></iframe><h3>12. Final Thoughts and Improvements</h3><ol><li><strong>Animation Cancelling: </strong>We still need to do a few improvements before this animation is production-ready. We need to address how we cancel an animation-in-progress when some event happens that requires the animation to be interrupted. For example, if we quickly press the <strong>Toggle </strong>button twice, how do we want to handle that. And there could be other considerations.</li><li><strong>Multi-Path Animations</strong>: The ideas can be easily extended to animations where the path might have more than two states. For example, in a carousel, the background of each slide might be a different path. And you can easily create a smooth transition for the background as the user browses the slides.</li><li><strong>Animation Chaining:</strong> In most cases, animations are chained. One animation happens after when one animation is partially or fully completed. It will be quite easy to do that too using a single <strong>AnimationController</strong>.</li><li><strong>Tools:</strong> The two simple tools I created are by no means exhaustive. For example, your source SVG files might have other in-built transformations such as rotation and scaling. I haven’t built the tool to handle those cases. And it will be nice if you could just drag-and-drop your SVG files. I do plan to build that at some point but I just wanted to show how anyone can go ahead and build these tools for their own project. Also, I would like to provide a better code formatter for both the tools.</li><li><strong>Library:</strong> And hopefully, someone comes up with a library that deals with a lot of these stuff out of the box. If nothing comes up, I might take a stab at it. Adobe XD has an <strong>XD to Flutter </strong>plugin project page. But not much info is available on the page.</li></ol><p>I hope some of the concepts discussed helped you better understand the fundamentals of Bezier curves, point-wise linear extrapolation, parametric functions, and Bezier animations. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25829255768e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-2-25829255768e">Bezier Animations — UI elements to Flutter Widgets (Part 2)</a> was originally published in <a href="https://medium.com/thebrand">TheBrand.app</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bezier Animations — UI elements to Flutter Widgets (Part 1)]]></title>
            <link>https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-1-95c04b6ba1c4?source=rss----c5ebdf2c8903---4</link>
            <guid isPermaLink="false">https://medium.com/p/95c04b6ba1c4</guid>
            <category><![CDATA[bezier]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[ui-ux-design]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Kamalesh Basu]]></dc:creator>
            <pubDate>Wed, 29 Jan 2020 11:08:02 GMT</pubDate>
            <atom:updated>2020-02-01T11:42:19.528Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bezier Animations — UI elements to Flutter Widgets (Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yKpI-DmLmNlSi2SdAZGww.jpeg" /></figure><p>UX Softwares such as <a href="https://www.sketch.com/">Sketch</a>, <a href="https://www.adobe.com/products/xd.html">Adobe Xd</a> and <a href="https://www.figma.com/">Figma</a> have empowered designers to imagine, experiment and provide great finesse to User Interfaces and experiences. Just take a look at design websites such as <a href="https://dribbble.com/">Dribbble</a> or <a href="https://www.behance.net/">Behance</a>, and you will be awestruck at the quality of designs being published.</p><p>One common feature of UI/UX elements today are animations — not flashing neon light animations — but subtle, tasteful, more organic animations. <a href="https://en.wikipedia.org/wiki/B%C3%A9zier_curve"><strong>Bezier curves</strong></a><strong> </strong>are a great way of creating smooth curves and provide a simple, elegant yet powerful way of animating UI elements in an App. This two-part article will be an attempt to simplify the process of converting a designer’s UI elements into Flutter Widgets for drawing Bezier Curves and animating them.</p><h3>1. The Design Process</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*czQT-zQdIsxR9MFb8zcF-A.gif" /><figcaption>A simple Bezier curved based animation in the orange page header</figcaption></figure><p>Almost all UI/UX software has a <strong>Path</strong> or <strong>Pen </strong>tool for creating smooth <strong>shapes</strong> or <strong>paths</strong>. Paths are composed of anchors or points which are joined by segments or arcs. In most cases, these arcs are defined by a quadratic or cubic equation. These arcs are collectively called Bezier curves.</p><p>To create an animation of such paths or shapes, a designer needs to define a new path/shape (usually containing the same number of points and segments) in a new Artboard or View, and make use of the auto-animate feature of the UX software to create the animation.</p><p>In this article, we will focus on the Bezier curve animation (the orange page header) shown in the image above and take a look at how to export the designer’s path animation into a Flutter widget. The above UI was created using Adobe XD and the file is available in the <a href="https://github.com/kamaleshbasu/bezier_animation">repository</a> for this article.</p><p>For the article, we will assume the number of anchors/points and segments for the two paths we are animating between is the same. If the two paths have a different number of points, you can simply add additional points along the path with fewer points and it will work just the same.</p><h3>2. Path to Bezier curve</h3><p>Before we can programmatically draw the shape or path created by the designer, we need to translate the Path into Points and Segments (Bezier curve). Each segment in a Bezier curve is defined by the <strong>starting point</strong>, the <strong>endpoint,</strong> and zero or more <strong>control points</strong>. The <strong>control points</strong> are responsible for the curvature of the curve.</p><p>If there are no control points, it is a straight line. If there is only one control point, then it is a quadratic Bezier curve and if it has two control points, it is a cubic Bezier curve. We seldom need to consider segments that require more than two control points.</p><p>Whenever we are trying to export a path or a shape from a Design software and draw it using Bezier curve functions in our app, our strategy will be:</p><ol><li><strong>Export the path/shape from UX software as an SVG</strong></li><li><strong>Convert the </strong><a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths"><strong>SVG path (“d” string)</strong></a><strong> to Bezier curves</strong></li><li><strong>Programatically draw the Bezier curves (in Flutter for our case)</strong></li></ol><h3>3. Export Path to SVG</h3><p>Some plugins exist which allows Paths to be exported directly into Bezier curves but in case you don’t have access to such a plugin, our strategy will always work.</p><p>We start by exporting our path in the UX Software to an SVG. Any scalable vector graphic (SVG), can be represented by a <strong>String</strong> (often called a <strong>“d”</strong> String) which is a series of instructions on how to draw the path that represents the SVG. For example, a simple SVG string can be:</p><pre>M0,0L0,100Q100,120,100,100L100,0L0,0</pre><p>This reads (For all possible instructions you can find in an SVG path string, check out this <a href="https://www.w3schools.com/graphics/svg_path.asp">link</a>.):</p><pre>1. <strong>M</strong>ove to point (0,0)<br>2. Draw straight <strong>L</strong>ine to (0,100)<br>3. Draw <strong>Q</strong>uadratic Curve to (100,100) with control point (100,120)<br>4. Draw straight <strong>L</strong>ine to (100,0)<br>5. Draw straight <strong>L</strong>ine to (0,0)</pre><p>For the article, I will use Adobe XD (it’s free to use) but similar export capabilities exist for all UX software.</p><p>If you open the <a href="https://github.com/kamaleshbasu/bezier_animation/blob/master/adobe_xd/login-ui.xd">Adobe XD file</a> provided in the <a href="https://github.com/kamaleshbasu/bezier_animation">repository</a> for this article, you will see two Artboards with each Artboard containing the two states of the Path we are going to animate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrZ54EA5mBD-M_jCTYqXOQ.png" /><figcaption>The two states of the same path in the Artboard</figcaption></figure><p>Select the path in <strong>Artboard 1</strong>, and then select the following options from the toolbar:</p><pre>File &gt; Export &gt; Selected</pre><p>Save the file as an svg and give it a name such as, curve.svg . Follow the same steps with the path in <strong>Artboard 2</strong>, and save the path as curve_final.svg . You can watch the steps in the following video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fko360KOjq5c%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dko360KOjq5c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fko360KOjq5c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6942e75f599dfddf1fc8d9d54b605930/href">https://medium.com/media/6942e75f599dfddf1fc8d9d54b605930/href</a></iframe><h3>4. SVG path to Bezier instructions</h3><p>Once you have created the SVG files, open up the first file curve.svg in your browser, right-click on the image and select <strong>Inspect Element </strong>(for non-Chrome browsers the option might be different). You will see something as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lb3DCyl7_J3iiquJX7EkjA.png" /><figcaption>Screenshot of the SVG image in Chrome Element inspector</figcaption></figure><p>You can immediately get hold of the path string from pathattribute:</p><pre>M-27.4,335.344S-3.935,356.71,44.157,356.71s70.664-62.965,131.742-55.941,79.371,26.263,135.113,26.263S386.6,247.758,386.6,247.758V-6.441h-414Z</pre><p>There is one other important information we need to take note of and that is the transformattribute:</p><pre>translate(27.396 6.441)</pre><p>I personally prefer to convert the SVG path to cubic-bezier segments and there are plenty of ways you can do that. Some of the libraries that can help are <a href="http://raphaeljs.com/">Raphael</a> or <a href="http://snapsvg.io/">SnapSVG</a>. Both libraries have functions that will allow you to convert an SVG path String into an array of Bezier instructions. If you are unfamiliar with either of those, you can make use of the tool I have put together <a href="https://itchylabs.com/tools/path-to-bezier/">here</a> using SnapSVG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*unfe7qgTQJ9BGm_3wJDU0Q.png" /><figcaption>A tool to convert SVG Path string into Cubic Bezier Segments</figcaption></figure><p>Enter the path String and the translation coordinates in the appropriate fields. To get the Path dimensions, go back to the Adobe XD file and select the path. And you will be able to get the Width and Height of the Path. Once all the values are in, hit <strong>Convert! </strong>You can follow all the steps in this video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBKAGrdIYnfI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBKAGrdIYnfI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBKAGrdIYnfI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd6614fee526bcc4a8e9af8e5a9fb7fa/href">https://medium.com/media/fd6614fee526bcc4a8e9af8e5a9fb7fa/href</a></iframe><p>It generates the Cubic Bezier instructions:</p><pre>M, -0.003999999999997783, 341.78499999999997</pre><pre>C, -0.003999999999997783, 341.78499999999997, 23.461000000000002, 363.15099999999995, 71.553, 363.15099999999995</pre><pre>C, 119.645, 363.15099999999995, 142.21699999999998, 300.186, 203.29500000000002, 307.21</pre><pre>C, 264.373, 314.234, 282.666, 333.47299999999996, 338.408, 333.47299999999996</pre><pre>C, 394.15000000000003, 333.47299999999996, 413.99600000000004, 254.199, 413.99600000000004, 254.199</pre><pre>C, 413.99600000000004, 254.199, 413.99600000000004, 0, 413.99600000000004, 0</pre><pre>C, 413.99600000000004, 0, -0.003999999999976467, 0, -0.003999999999976467, 0</pre><pre>C, -0.003999999999976467, 0, -0.003999999999997783, 341.78499999999997, -0.003999999999997783, 341.78499999999997</pre><p>It also generates the necessary Dart code for our Flutter App but we will come back to it later. (I could have done a better job at formatting the Dart code, but I was trying to get it out ASAP and I may go back and improve on it.)</p><h3>5. Setting up the Flutter App</h3><p>Start a new Flutter app:</p><pre>flutter create --org com.itchylabs --description &quot;Bezier Curve Animations&quot; bezier_animation</pre><p>(<strong>Tip</strong>: You can run the entire code without creating a Flutter app by going to <a href="https://dartpad.dartlang.org/flutter">https://dartpad.dartlang.org/flutter</a> and by running the code there.)</p><p>Change the main.dart file as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/add2e70113d837d529e83b8ee7e7e31d/href">https://medium.com/media/add2e70113d837d529e83b8ee7e7e31d/href</a></iframe><p>If you run the app on an emulator, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5BUoX7UmsnhTpxVOMvjcw.png" /></figure><p>We have created an orange container and now we are going to <strong>Clip</strong> this container to get our desired path.</p><h3>6. Clipping the Container</h3><p>You can clip any widget in Flutter, by wrapping it with a <a href="https://api.flutter.dev/flutter/widgets/ClipPath-class.html"><strong>ClipPath</strong></a> widget and then by defining the clipper property. The clipper property is an object extended from the <a href="https://api.flutter.dev/flutter/rendering/CustomClipper-class.html"><strong>CustomClipper</strong></a><strong> </strong>and will define the Path. In our case, we will Clip the container we created but you can use this technique to clip images, text fields or any other widget in Flutter.</p><p>We modify our code by wrapping our container as follows:</p><pre><strong><em>ClipPath</em>(<br>  clipper: <em>BezierClipper</em>(),<br>  child:</strong> <em>Container</em>(<br>    color : <em>Color</em>.fromRGBO(255, 91, 53, 1),<br>    height: height,<br>  ),<br><strong>),</strong></pre><p>We will now define our <strong>BezierClipper </strong>class by extending a CustomClipper as follows:</p><pre><strong>class <em>BezierClipper</em> extends <em>CustomClipper</em>&lt;<em>Path</em>&gt;{<br>  <em>@override<br>  Path</em> getClip(<em>Size</em> size) =&gt; null;</strong></pre><pre><strong><em>@override<br>  bool</em> shouldReclip(<em>CustomClipper</em>&lt;<em>Path</em>&gt; oldClipper) =&gt; true;<br>}</strong></pre><h4>6.1 A Test Clipper — A quadratic clip</h4><p>We are exclusively going to work with getClip method and whatever path we return from that method will be used to clip the container. Change the getClip method as follows:</p><pre><em>@override<br>Path</em> getClip(<em>Size</em> size){<br>  <em>Path</em> path = new <em>Path</em>();<br>  path.lineTo(0, size.height*0.85); <strong>//vertical line</strong><br>  path.quadraticBezierTo(size.width/2, size.height, size.width, size.height*0.85); <strong>//quadratic curve</strong><br>  path.lineTo(size.width, 0); <strong>//vertical line</strong><br>  return path;<br>}</pre><p>This will give us the following rounded path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UlZNT8U5H3733_LCO5h4LA.png" /></figure><p>This is what we are doing:</p><ol><li>Draw a vertical line from the top-left corner of the Container to 85% way down the height of the container.</li><li>Draw a quadratic curve to the right edge of the container with a control point which is in the “center bottom” of the container.</li><li>Draw a vertical line to the top-right corner of the Container.</li></ol><p>Since all our measures are based on thesize variable of the getClipmethod, all the dimensions of the path are relative to the container (or widget) it is clipping.</p><h4>6.2 A Test Clipper — A cubic clip</h4><p>Update the getClip method as follows:</p><pre><em>@override<br>Path</em> getClip(<em>Size</em> size){<br>  <em>Path</em> path = new <em>Path</em>();<br>  path.lineTo(0, size.height*0.85); <strong>//vertical line</strong><br>  path.cubicTo(size.width/3, size.height, 2*size.width/3, size.height*0.7, size.width, size.height*0.85); <strong>//cubic curve</strong><br>  path.lineTo(size.width, 0); <strong>//vertical line</strong><br>  return path;<br>}</pre><p>You have created a nice wavy bottom border for the container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8vlSH7DsjKGniDebdsKJw.png" /></figure><h4>6.3 Our Path Clipper</h4><p>Head over to the <a href="https://itchylabs.com/tools/path-to-bezier/">online tool</a> and copy the Flutter Clipper the tool generates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08jg2AALjF3gG4j8WANozw.png" /><figcaption>Auto-generated Flutter Clipper</figcaption></figure><p>Use that as the getClip method and you will get our path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4XTjewp2Z4KgJ-3_lKj9A.png" /></figure><h4>6.4 Our 2nd Path Clipper and Toggling Between the two paths</h4><ol><li>Now follow the same steps for the 2nd path with the file curve_final.svg and grab the getClip method but save it in your <strong>BezierClipper</strong> class as _getFinalClip method.</li><li>Rename the getClip method as _getInitialClip .</li><li>Define a new intclass variable and a constructor for our <strong>BezierClipper</strong> class as follows:</li></ol><pre>final <em>int</em> state;<br><em>BezierClipper</em>(this.state);</pre><p>4. Define a new getClip method as follows:</p><pre><em>@override<br>Path</em> getClip(<em>Size</em> size) =&gt; state == 1 ? _getInitialClip(size) : _getFinalClip(size);</pre><p>5. In the <strong>_AnimationPageState</strong> class add a new variable and method:</p><pre><em>int</em> state = 1;</pre><pre>_toggle(){<br>  setState(() {<br>    state = state == 1? 2 : 1;<br>  });<br>}</pre><p>6. In the <strong>Stack</strong> widget of the buildmethod of <strong>_AnimationPageState </strong>class add a new child Container with a button which will call the _toggle method:</p><pre><em>Container</em>(<br>  padding: <em>EdgeInsets</em>.only(top: height * 1.2),<br>  child : <em>Center</em>(<br>    child: <em>RaisedButton</em>(<br>     child: <em>Text</em>(&quot;Toggle&quot;),<br>     onPressed: _toggle,<br>    ),<br>  )<br>),</pre><p>7. Update our clipper property from BezierClipper() to BezierClipper(state) .</p><p>Now if you press the button, the path will toggle (not animate) between the two states.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKM4EEZ8nnBU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKM4EEZ8nnBU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKM4EEZ8nnBU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5b67bb30c00dbdbc96da66d3ce9524f/href">https://medium.com/media/c5b67bb30c00dbdbc96da66d3ce9524f/href</a></iframe><p>And here is the final main.dart file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3eb7879d15db8b43b54448c9a0f150e3/href">https://medium.com/media/3eb7879d15db8b43b54448c9a0f150e3/href</a></iframe><h3>7. Wrapping Up</h3><p>In this article, we explored how we can export paths/shapes from UX design software into our Flutter App while maintaining the design integrity and ensuring we get an accurate representation of the paths created by the designer. <a href="https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-2-25829255768e">In Part 2</a>, we will explore how we can animate these paths smoothly. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95c04b6ba1c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebrand/bezier-animations-ui-elements-to-flutter-widgets-part-1-95c04b6ba1c4">Bezier Animations — UI elements to Flutter Widgets (Part 1)</a> was originally published in <a href="https://medium.com/thebrand">TheBrand.app</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Editing document templates using TinyMCE and Angular]]></title>
            <link>https://medium.com/thebrand/editing-document-templates-using-tinymce-and-angular-2602394f2e?source=rss----c5ebdf2c8903---4</link>
            <guid isPermaLink="false">https://medium.com/p/2602394f2e</guid>
            <category><![CDATA[tinymce]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[document-editor]]></category>
            <dc:creator><![CDATA[Kamalesh Basu]]></dc:creator>
            <pubDate>Thu, 12 Dec 2019 13:44:22 GMT</pubDate>
            <atom:updated>2019-12-12T15:32:40.137Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nVL48S-LEID86b_w" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In sizeable applications, we often need to manage document templates — contracts, emails, social media posts, and others. Document templates often tend to contain <strong><em>Placeholder Fragments</em></strong> which need to be replaced with targeted content before the document is dispatched.</p><p>You can imagine a marketplace that has to send contracts to Service providers and customers and have to insert <em>Company name</em>, <em>Company ID</em> and <em>Contact information</em> from their database into the contracts before sending them to relevant parties. The same thing goes for the invoicing module as well.</p><p>Another use case will be for a website to send a Drip campaign to their new sign-ups and insert the <em>User’s name</em> and <em>Other targeted info</em> into the email templates for the Drip campaign.</p><p>While editing these templates, identifiers such as <strong>&lt;Company-Name&gt;</strong> or <strong>#company-name</strong> are inserted in their WYSIWYG editors (or in Text Boxes). The script that parses this template is usually designed to detect these identifiers and replaces them with values from their database before dispatching the document.</p><h3>Issues with this method</h3><p>Common errors/annoyances that can happen when typing in these identifiers in a WYSIWYG editor:</p><ol><li>Misspelling and typos</li><li>Deleting with Backspace leads to artifacts such as <strong>#company-n </strong>or <strong>&lt;Compan</strong>. The Backspace doesn’t fully delete the fragment.</li></ol><h3>Custom TinyMCE Plugin to edit document fragment</h3><p>While in the example I will cover TinyMCE, similar plugins can be built for any of the extensible editors. I will use an Angular project for the demo but you can build it for any frontend project.</p><h4><strong>Step 1. Start a new Angular project and install TinyMCE</strong></h4><p>Run the following line of codes in your terminal to create a new Angular project and install TinyMCE angular component.</p><pre>$ ng n document-fragment-example</pre><pre>$ cd document-fragment-example<br>$ npm install @tinymce/tinymce-angular</pre><h4>Step 2. (Optional) Loading TinyMCE in your project locally</h4><p>If you are not loading TinyMCE from the cloud (<a href="https://github.com/tinymce/tinymce-angular">more here</a>), run the following line of code to install the TinyMCE code in your project:</p><pre>$ npm install --save tinymce</pre><p>Open your @project-root/<strong>angular.json</strong> file in your code editor and find the script section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icNryUMfz9rofmTQk9hKRQ.png" /><figcaption>Assets, styles and script imports in <strong>angular.json</strong></figcaption></figure><p>and import the TinyMCE javascript:</p><pre>&quot;scripts&quot; : [<br>   &quot;node_modules/tinymce/tinymce.min.js&quot;<br>],</pre><p>and import all the necessary TinyMCE assets:</p><pre>&quot;assets&quot; : [<br>   { <em>&quot;glob&quot;</em>: &quot;**/*&quot;, <em>&quot;input&quot;</em>: &quot;node_modules/tinymce/skins&quot;, <em>&quot;output&quot;</em>: &quot;/tinymce/skins/&quot; },<br>   { <em>&quot;glob&quot;</em>: &quot;**/*&quot;, <em>&quot;input&quot;</em>: &quot;node_modules/tinymce/themes&quot;, <em>&quot;output&quot;</em>: &quot;/tinymce/themes/&quot; },<br>   { <em>&quot;glob&quot;</em>: &quot;**/*&quot;, <em>&quot;input&quot;</em>: &quot;node_modules/tinymce/plugins&quot;, <em>&quot;output&quot;</em>: &quot;/tinymce/plugins/&quot; }<br>]</pre><h4>Step 3. Testing TinyMCE Editor in Angular App</h4><p>Open the @project-root/src/<strong>app.module.ts </strong>file and import the TinyMCE Editor module:</p><pre>import { EditorModule } from &#39;@tinymce/tinymce-angular&#39;;</pre><p>and add it to the import list in the @NgModule :</p><pre>@NgModule({<br>declarations: [<br>   AppComponent<br>],<br>imports: [<br>   BrowserModule,<br>   AppRoutingModule,<br>   EditorModule<br>],<br>...</pre><p>Open the @project-root/src/<strong>app.component.html </strong>and delete all contents of the file and update it as follows:</p><pre>&lt;<strong>router-outlet</strong>&gt;&lt;/<strong>router-outlet</strong>&gt;<br>&lt;<strong>editor</strong> [init]=&quot;{<br>   base_url: &#39;/tinymce&#39;,<br>   suffix: &#39;.min&#39;,<br>   plugins: &#39;link&#39;,<br>   statusbar : false<br>}&quot;&gt;&lt;/<strong>editor</strong>&gt;</pre><p>If you skipped Step 2 and chose to load TinyMCE from the cloud, you should update the content of <strong>app.component.html</strong> as follows:</p><pre>&lt;<strong>router-outlet</strong>&gt;&lt;/<strong>router-outlet</strong>&gt;<br>&lt;<strong>editor</strong> apiKey=&quot;tinymce-cloud-api-key&quot; [init]=&quot;{<br>   plugins: &#39;link&#39;, <br>   statusbar : false<br>}&quot;&gt;&lt;/<strong>editor</strong>&gt;</pre><p>If you now run your angular app using $ ng serve and browse your project using <a href="http://localhost:4200/">http://localhost:4200</a> (if you set a different port use that instead of 4200), you will see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a0NUaPCrpbR5rGnyFspqeg.png" /><figcaption>TinyMCE editor in Angular Component</figcaption></figure><h4>Step 4. Setting up the TinyMCE Plugin</h4><p>Create a js directory in your @project-root/src/assets and create a file mce.contract.plugin.js . This file will register our plugin with TinyMCE. The Plugin’s purpose will be to do the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUd4VPk1hDU4xgIAeWMY2g.png" /><figcaption>Preview of TinyMCE Plugin we are going to build</figcaption></figure><ol><li>The plugin will register a new TinyMCE plugin called contractPlugin .</li><li>The plugin will add a new TinyMCE menuButton which will have 5 options to insert 5 different template fragments into the Editor content.</li><li>Ensure that upon using Backspace in the TinyMCE editor, the whole template fragment is deleted.</li></ol><p>Once we have created the Plugin file we will import it in our @project-root/<strong>angular.json</strong> file by adding to our script section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yeq1SUurv6cseBkig5TcBQ.png" /><figcaption>Import newly create TinyMCE Plugin to <strong>angular.json</strong></figcaption></figure><h4>Step 5. Registering the Plugin and creating the menuButton</h4><p>Edit the contents of mce.contract.plugin.js to register the contractPlugin with TinyMCE:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab04153d3de760a37a4018c8d40e0f66/href">https://medium.com/media/ab04153d3de760a37a4018c8d40e0f66/href</a></iframe><p>and add the menuButton:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e1d1c24977c672454549c5e364f27e1/href">https://medium.com/media/1e1d1c24977c672454549c5e364f27e1/href</a></iframe><p>Update your @project-root/src/<strong>app.component.html </strong>as follows (make similar changes for the cloud loaded TinyMCE version):</p><pre>&lt;<strong>editor</strong> [init]=&quot;{<br>   base_url: &#39;/tinymce&#39;,<br>   suffix: &#39;.min&#39;,<br>   plugins: &#39;link contractPlugin&#39;,<br>   toolbar1 : &#39;undo redo | styleselect | bold italic | link                                   contractPlugin&#39;,<br>   statusbar : false<br>}&quot;&gt;&lt;/<strong>editor</strong>&gt;</pre><p>and you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpy80qyvO1JHZZtxrDNGRw.png" /><figcaption>Custom MenuButton “<strong>Contract Templates</strong>” added to TinyMCE editor</figcaption></figure><p><strong>Tip:</strong> If you are new to TinyMCE plugin creation, you will find their starter tutorials on <a href="https://www.tiny.cloud/docs/advanced/creating-a-plugin/">Plugin Creation</a> and <a href="https://www.tiny.cloud/docs/ui-components/typesoftoolbarbuttons/">Toolbar Buttons</a> useful.</p><h4>Step 6. Creating MenuItems and callback function</h4><p>Edit the contents of mce.contract.plugin.js to add the list of MenuItems:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d15764db4dba0b860bcca3407813b5d/href">https://medium.com/media/3d15764db4dba0b860bcca3407813b5d/href</a></iframe><p>We create a callback function which formats the editor content to be inserted and then call the function to insert the content into the editor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fe82a623b6634360464d98c5fcfdda1/href">https://medium.com/media/3fe82a623b6634360464d98c5fcfdda1/href</a></iframe><p>Your TinyMCE editor should now update to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oPW8E_Grk1U3a3xNJQ25gw.png" /><figcaption>Template Fragments inserted into the Editor by the Plugin</figcaption></figure><h4>Step 7. Fix keyboard Backspace issue</h4><p>If you use the backspace in your editor to delete any of the fragments, you will notice the following artifacts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_d1eEKJK9Ix4jYWWc1vbVQ.png" /><figcaption>Using Backspace in the Editor doesn’t delete the template fragment but produces an unintended artifact</figcaption></figure><p>We can make use of the noneditable plugin from TinyMCE to fix this. Import the plugin in your @project-root/src/<strong>app.component.html</strong> (make a similar adjustment for the cloud loaded TinyMCE version):</p><pre>&lt;<strong>editor</strong> [init]=&quot;{<br>   base_url: &#39;/tinymce&#39;,<br>   suffix: &#39;.min&#39;,<br>   plugins: &#39;link contractPlugin <strong>noneditable</strong>&#39;,<br>   toolbar1 : &#39;undo redo | styleselect | bold italic | link                                   contractPlugin&#39;,<br>   statusbar : false<br>}&quot;&gt;&lt;/<strong>editor</strong>&gt;</pre><p>Update the MenuItem callback action to add the <strong>mceNonEditable</strong> class to the inserted content as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/882aae957619e82de5a14f0f1292630b/href">https://medium.com/media/882aae957619e82de5a14f0f1292630b/href</a></iframe><p>Our plugin is good to go!</p><h3>Parting thoughts</h3><p>This is a simple yet effective way to build extensions to WYSIWYG editors. Such plugins can be used to insert Tweets or Instagram posts or YouTube videos in a blog or a Stock Chart in a financial report. You can think of many such use cases.</p><p>The official <a href="https://github.com/tinymce/tinymce-angular">TinyMCE component for Angular GitHub page</a> provides tips on how to get the content from the WYSIWYG editor into your Component using FormsModule and ReactiveFormsModule in Angular. You can use this to save the templates on your server or in your Firebase.</p><p>Thanks for reading! You can get the complete source code from:<br><a href="https://github.com/kamaleshbasu/document-fragment-example">https://github.com/kamaleshbasu/document-fragment-example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2602394f2e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thebrand/editing-document-templates-using-tinymce-and-angular-2602394f2e">Editing document templates using TinyMCE and Angular</a> was originally published in <a href="https://medium.com/thebrand">TheBrand.app</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>