Skip to content

Commit 05c8c98

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

File tree

5 files changed

+139
-1
lines changed

5 files changed

+139
-1
lines changed

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

Lines changed: 139 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,144 @@ 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+
{{% alert color="info" %}}This feature is available from Rich Text version 4.7.0 and above.{{% /alert %}}
168+
To add a new custom font, simply go to advance tab and click new on custom font.
169+
170+
* **Font name** – this is the font name that will be use to display the font on font-family selection in Rich Text toolbar.
171+
* **Font style** – this is the font-family declaration that you have set previously in font-face styling.
172+
173+
#### Display custom font with correct styling in the toolbar
174+
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.
175+
176+
* **Font name variable**
177+
The new font name will be display in the toolbar with data-value attribute as `data-value="your-font-name"`.
178+
The name will be derrived from **Font name** configuration by set it to lower case, and replace all space(" ") with dash("-").
179+
You can use this following custom styling to display it correctly in the toolbar:
180+
181+
```css
182+
.widget-rich-text .ql-toolbar [data-value=your-font-name]:before {
183+
font-family: 'Your-font-family-name';
184+
}
185+
```
186+
187+
188+
### Image from entity
189+
{{% alert color="info" %}}This feature is available from Rich Text version 4.8.0 and above.{{% /alert %}}
190+
The default image upload and selection method of Rich Text is to use base64 string as the image source.\
191+
This has found to be troublesome if the image size is too large that causes the string value attribute to be big.
192+
By using image source from entity, Rich Text will use the image url instead of base64.
193+
194+
195+
#### Using file uploader widget
196+
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.
197+
198+
##### Prerequisite
199+
Entity that being used for Rich Text data source value attribute have to use FileUploadContext entity generalization.
200+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/entity-with-file-upload-context.png" alt="Rich text entity with FileUploadContext generalization" >}}
201+
202+
##### Configuration
203+
* **Selectable images**\
204+
Rich text needs to know the source of image entity to be display.\
205+
On the **advance tab > selectable images**, choose association to **UploadedImage_FileUploadContext/UploadedImage** entity.\
206+
By selecting this, Rich Text will display a dropzone for image upload widget.
207+
208+
* **Configuring the image upload widget**
209+
- Drag and drop File Uploader widget to the available image upload dropzone underneath Rich Text widget.
210+
- Open File Uploader widget configuration and select Images as **Upload mode**
211+
- On the advace tab of File Uploader widget, set **Enable custom buttons** "Yes" and add a custom buttons.
212+
- Set **Default file action** to "Yes" on the custom button and call the [nanoflow to select images](#configuring-image-selection-nanoflow) as the action.
213+
214+
#### Using other widget as image selector
215+
User can also configure to use another widget as the image selector for Rich Text.\
216+
This widget have to has access to the System.Image object.
217+
218+
##### Prerequisite
219+
220+
* Entity that being used for Rich Text data source value attribute have to use has association to System.Image entity.
221+
222+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/entity-with-system-image.png" alt="Rich text entity with FileUploadContext generalization" >}}
223+
224+
* The custom widget needs to have access to the System.Image object and able to call nanoflow action when image being selected.
225+
* 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.
226+
227+
##### Configuration
228+
* **Selectable images**
229+
Rich text needs to know the source of image entity to be display.\
230+
On the **advance tab > selectable images**, choose association to the **System.Image** entity.\
231+
By selecting this, Rich Text will display a dropzone for image upload widget.
232+
233+
* **Configuring the image upload widget**
234+
- Drag and drop the custom widget to the available image upload dropzone underneath Rich Text widget.
235+
- Use the same **System.Image** association as the datasource.
236+
- Set the action to call the [nanoflow to select images](#configuring-image-selection-nanoflow) as necessary.
237+
238+
#### Configuring image selection nanoflow
239+
The nanoflow is needed to trigger image object selection and returning the flow back to Rich Text widget.
240+
241+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/image-selection-nanoflow.png" alt="Image selection nanoflow" >}}
242+
243+
* **Nanoflow parameter**
244+
The nanoflow needs to have access to the **System.Image** entity. Set this as the parameter.
245+
In case of using File Uploader, this should be automatically set up when creating the nanoflow from custom action button.
246+
247+
* **Getting the object GUID**
248+
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.
249+
250+
* **Trigger image selection javascript**
251+
This step is required to pass the GUID of the image object back to Rich Text.
252+
Create a new javascript action and add a string parameter.
253+
In this example, we will name the parameter *fileGuid* and *selectImage* as the Javascript action.
254+
255+
{{< figure src="/attachments/appstore/platform-supported-content/widgets/rich-text/js-action-setup.png" alt="Javascript action configuration" >}}
256+
257+
Use the following code in the javascript action:
258+
259+
```Javascript
260+
export async function selectImage(fileGuid) {
261+
// BEGIN USER CODE
262+
const img = {
263+
id: fileGuid,
264+
url: mx.data.getDocumentUrl(fileGuid, Date.now(), false)
265+
}
266+
const customEvent = new CustomEvent("imageSelected", { bubbles: true, detail: img });
267+
window.getSelection().anchorNode.dispatchEvent(customEvent);
268+
// END USER CODE
269+
}
270+
```
271+
272+
This code will trigger a new Event called "imageSelected" and bubble up the event back to Rich Text widget to continue the flow.
273+
User then can use the image id instead of base64 string as the image source.

0 commit comments

Comments
 (0)