Skip to content

Commit 7a3e46a

Browse files
committed
Rich Text: add custom fonts and image from entity selection
1 parent 7ff1746 commit 7a3e46a

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

content/en/docs/marketplace/platform-supported-content/widgets/richtext/_index.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ To configure this widget, follow these steps:
9393
* **Syntax** - items: blockquote, codesample, codeblock, (view/edit)code
9494
* **Font colors** - items: fontfamily, fontsize, forecolor, backcolor
9595
* **Content type** - items: header
96+
* **View** - items: fullscreen
9697
* **Removal** - items: clear
98+
* **Table** - items: table
9799
* **Advanced** – if selected, you can configure buttons for different toolbar groups
98100

99101
{{% alert color="info" %}}All the toolbar groups that you configure will be available in the toolbar. With vertical bars or separator options ("|"), you can separate different toolbar groups.{{% /alert %}}
@@ -128,8 +130,141 @@ To configure this widget, follow these steps:
128130

129131
### Advanced Tab
130132

131-
* **Enable spell checking** – configures to use the browser’s native spell checker
133+
* **Enable spell checking** – configures to use the browser’s native spell checker.
134+
* **Custom fonts** – configures extra fonts selection for the font family.
135+
* **Selectable images** – configures image entity source to allow rich text to use images from entity instead of base64 string.
136+
* **Enable default upload** – if enabled, it will keep the current image upload method using base64 string, otherwise it is hidden (default value: true).
132137

133138
### Common Tab
134139

135140
For more information, see [Common Section](/refguide/common-widget-properties/#common-properties) in *Properties Common in the Page Editor*.
141+
142+
143+
# Advance configuration
144+
145+
### Custom fonts
146+
147+
This advance configuration allows you to add extra font list to the font family selection in Rich Text widget.
148+
149+
#### Prerequisite
150+
Prior to adding new font, font files and font family have to be already included in your project.
151+
152+
* **Adding font files**
153+
To add font files into the project, you can put the font files inside your styles/web directory.
154+
155+
* **Define font family in styling**
156+
You will need to define the new font by adding the font face custom styling.
157+
```css
158+
@font-face {
159+
font-family: 'Your-font-family-name';
160+
src: url('YourFontFile.ttf') format('truetype');
161+
font-weight: 100;
162+
font-style: normal;
163+
}
164+
```
165+
166+
#### Adding a custom font into rich text
167+
To add a new custom font, simply go to advance tab and click new on custom font.
168+
169+
* **Font name** – this is the font name that will be use to display the font on font-family selection in Rich Text toolbar.
170+
* **Font style** – this is the font-family declaration that you have set previously in font-face styling.
171+
172+
#### Display custom font with correct styling in the toolbar
173+
This is an optional configuration that user can do to display the custom fonts in it's own styling on the font-family toolbar selection.
174+
175+
* **Font name variable**
176+
The new font name will be display in the toolbar with data-value attribute as `data-value="your-font-name"`.
177+
The name will be derrived from **Font name** configuration by set it to lower case, and replace all space(" ") with dash("-").
178+
You can use this following custom styling to display it correctly in the toolbar:
179+
180+
```css
181+
.widget-rich-text .ql-toolbar [data-value=your-font-name]:before {
182+
font-family: 'Your-font-family-name';
183+
}
184+
```
185+
186+
187+
### Image from entity
188+
189+
Starting from Rich Text version 4.8.0, user can now configure image upload from entity instead of using the default base64 string.
190+
191+
192+
#### Using file uploader widget
193+
The default and recommended way of uploading and selecting images from entity in Rich Text widget is to use [File Uploader](/appstore/modules/file-uploader/) module.
194+
195+
##### Prerequisite
196+
Entity that being used for Rich Text data source value attribute have to use FileUploadContext entity generalization.
197+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/entity-with-file-upload-context.png" alt="Rich text entity with FileUploadContext generalization" >}}
198+
199+
##### Configuration
200+
* **Selectable images**\
201+
Rich text needs to know the source of image entity to be display.\
202+
On the **advance tab > selectable images**, choose association to **UploadedImage_FileUploadContext/UploadedImage** entity.\
203+
By selecting this, Rich Text will display a dropzone for image upload widget.
204+
205+
* **Configuring the image upload widget**
206+
- Drag and drop File Uploader widget to the available image upload dropzone underneath Rich Text widget.
207+
- Open File Uploader widget configuration and select Images as **Upload mode**
208+
- On the advace tab of File Uploader widget, set **Enable custom buttons** "Yes" and add a custom buttons.
209+
- Set **Default file action** to "Yes" on the custom button and call the [nanoflow to select images](#configuring-image-selection-nanoflow) as the action.
210+
211+
#### Using other widget as image selector
212+
User can also configure to use another widget as the image selector for Rich Text.\
213+
This widget have to has access to the System.Image object.
214+
215+
##### Prerequisite
216+
217+
* Entity that being used for Rich Text data source value attribute have to use has association to System.Image entity.
218+
219+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/entity-with-system-image.png" alt="Rich text entity with FileUploadContext generalization" >}}
220+
221+
* The custom widget needs to have access to the System.Image object and able to call nanoflow action when image being selected.
222+
* It is not mandatory that the custom widget have upload image function (e.g, using gallery and [Image](/appstore/widgets/image/) widget with onClick is also possible), because Rich Text widget only need the selection action call.
223+
224+
##### Configuration
225+
* **Selectable images**
226+
Rich text needs to know the source of image entity to be display.\
227+
On the **advance tab > selectable images**, choose association to the **System.Image** entity.\
228+
By selecting this, Rich Text will display a dropzone for image upload widget.
229+
230+
* **Configuring the image upload widget**
231+
- Drag and drop the custom widget to the available image upload dropzone underneath Rich Text widget.
232+
- Use the same **System.Image** association as the datasource.
233+
- Set the action to call the [nanoflow to select images](#configuring-image-selection-nanoflow) as necessary.
234+
235+
#### Configuring image selection nanoflow
236+
The nanoflow is needed to trigger image object selection and returning the flow back to Rich Text widget.
237+
238+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/image-selection-nanoflow.png" alt="Image selection nanoflow" >}}
239+
240+
* **Nanoflow parameter**
241+
The nanoflow needs to have access to the **System.Image** entity. Set this as the parameter.
242+
In case of using File Uploader, this should be automatically set up when creating the nanoflow from custom action button.
243+
244+
* **Getting the object GUID**
245+
The first step of the nanoflow is to get the GUID from the image object. Set call to javascript action GetGuid provided by [Nanoflow Commons](/appstore/modules/nanoflow-commons/) module.
246+
247+
* **Trigger image selection javascript**
248+
This step is required to pass the GUID of the image object back to Rich Text.
249+
Create a new javascript action and add a string parameter.
250+
In this example, we will name the parameter *fileGuid* and *selectImage* as the Javascript action.
251+
252+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/js-action-setup.png" alt="Javascript action configuration" >}}
253+
254+
Use the following code in the javascript action:
255+
256+
```Javascript
257+
export async function selectImage(fileGuid) {
258+
// BEGIN USER CODE
259+
const img = {
260+
id: fileGuid,
261+
url: mx.data.getDocumentUrl(fileGuid, Date.now(), false)
262+
}
263+
const customEvent = new CustomEvent("imageSelected", { bubbles: true, detail: img });
264+
window.getSelection().anchorNode.dispatchEvent(customEvent);
265+
// END USER CODE
266+
}
267+
```
268+
269+
This code will trigger a new Event called "imageSelected" and bubble up the event back to Rich Text widget to continue the flow.
270+
User then can use the image id instead of base64 string as the image source.

0 commit comments

Comments
 (0)