Skip to content

Commit d95816a

Browse files
committed
DOC-3246: Final improvements
1 parent d4856c7 commit d95816a

File tree

5 files changed

+75
-92
lines changed

5 files changed

+75
-92
lines changed

modules/ROOT/examples/live-demos/comments-embedded-with-mentions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
1919
description: 'Marketing Director',
2020
}
2121
}
22-
}
22+
};
2323

2424
const adminUser = userDb['johnsmith'];
2525
const currentUser = userDb['jennynichols'];

modules/ROOT/pages/userlookup.adoc

Lines changed: 71 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,37 @@
22
:navtitle: User Lookup
33
:description: TinyMCE User Lookup provides an API to identify the current user and retrieve user details via integration-defined methods.
44
:keywords: userLookup, fetchUsers, user_id, user management, collaborative editing
5+
:apiname: User Lookup
56

6-
The {productname} User Lookup API enables integrations to retrieve and cache user details (such as names and avatars) and identify the current user within the editor.
7+
The {productname} {apiname} API allows you to retrieve and cache user details, such as names and avatars, and identify the current user within the editor.
78

8-
This is useful when building features that rely on user context, such as commenting, collaborative editing, or displaying user-specific information. The API provides built-in caching for efficient user data management.
9+
This is useful when building features that rely on user context, such as commenting, collaborative editing, or displaying user-specific information. The API provides built-in caching for efficient user data management, as well as fallback user data when none is provided.
910

10-
== How it works
11+
== Properties and Methods
1112

12-
The User Lookup API provides two main functions:
13+
The {apiname} API serves two purposes, to identify the current user and to fetch user details for other users. These can be configured to suit your application through the xref:#user_id[`user_id`] and xref:#fetch_users[`fetch_users`] options respectively.
1314

14-
[cols="2,4",options="header"]
15-
|===
16-
|Method|Description
15+
The {apiname} API provides properties and methods through the `editor.userLookup` object, which is available after the editor is initialized.
1716

18-
|`editor.userLookup.userId`|Returns the current user's ID, set via the `user_id` configuration option.
19-
|`editor.userLookup.fetchUsers(userIds)`|Fetches and caches user information. Returns a Promise-based lookup object.
17+
[cols="2,1,2",options="header"]
2018
|===
19+
|API|Type|Return Type
2120

22-
== Basic setup
23-
24-
For a basic setup, you only need to configure the `user_id` option:
25-
26-
[source,js]
27-
----
28-
tinymce.init({
29-
selector: '#editor',
30-
user_id: 'current-user-id'
31-
});
32-
----
33-
34-
For more advanced user data fetching, see the <<options,Options>> section below.
21+
|xref:#userlookup-userid[`editor.userLookup.userId`]|Property|`string`
22+
|xref:#userlookup-fetchusers[`editor.userLookup.fetchUsers(userIds)`]|Method|`Object<string, Promise<UserObject>>`
23+
|===
3524

36-
== Understanding user lookup
25+
[[userlookup-userid]]
26+
=== `editor.userLookup.userId`
3727

38-
The User Lookup API handles three main scenarios:
28+
Returns the current user's ID, set via the `user_id` configuration option. This is a string that uniquely identifies the user in the context of the editor, such as a username or an email address. If the `user_id` option is not set, it defaults to `'Anonymous'`.
3929

40-
1. **Basic identification**: Setting a current user ID for editor context
41-
2. **Dynamic fetching**: Retrieving user details from backend systems
42-
3. **Fallback behavior**: Auto-generating user data when no fetch function is provided
30+
[[userlookup-fetchusers]]
31+
=== `editor.userLookup.fetchUsers`
4332

44-
== Data structure
33+
Fetches and caches user information for the specified user IDs. This method accepts an array of user IDs and returns an object where each key is a user ID and each value is a Promise that resolves to the user object. If a user ID is not found, the Promise will reject with an error message.
4534

46-
=== User
35+
=== The `user` object
4736

4837
The user is an `Object` that contains the following fields:
4938

@@ -53,7 +42,7 @@ The user is an `Object` that contains the following fields:
5342
| `id` | `string` | required | The unique string ID of the user.
5443
| `name` | `string` | optional | The display name of the user. If not provided, defaults to the `id`.
5544
| `avatar` | `string` | optional | The URL of the user's avatar image or data URI. If not provided, an auto-generated SVG using the user's initials will be used.
56-
| `custom` | `Object` | optional | Additional metadata for the user.
45+
| `custom` | `Object` | optional | Additional metadata for the user. This can include any custom fields relevant to your application, such as roles or permissions.
5746
|===
5847

5948
.Example user object:
@@ -72,46 +61,29 @@ The user is an `Object` that contains the following fields:
7261

7362
== Options
7463

75-
The following configuration options affect the behavior of the User Lookup API.
64+
The following configuration options affect the behavior of the {apiname} API.
7665

7766
include::partial$configuration/user_id.adoc[leveloffset=+1]
7867

7968
include::partial$configuration/fetch_users.adoc[leveloffset=+1]
8069

8170
== Usage Examples
8271

83-
=== Basic Usage
72+
=== Basic setup
8473

85-
Once the editor is initialized, you can access the current user ID and fetch user information:
74+
For a basic setup, configuring the `user_id` option allows you to identify the current user. The `fetch_users` option can be omitted, and {productname} will provide fallback user data.
8675

8776
[source,js]
8877
----
89-
editor.on('init', () => {
90-
// Get the current user ID
91-
console.log('Current user:', editor.userLookup.userId);
92-
93-
// Fetch user information
94-
const users = editor.userLookup.fetchUsers(['user-1', 'user-2']);
95-
96-
users['user-1'].then((user) => {
97-
console.log('User 1 name:', user.name);
98-
});
99-
100-
// Handle multiple users
101-
Promise.all(Object.values(users)).then((allUsers) => {
102-
allUsers.forEach((user) => {
103-
console.log(`Fetched: ${user.name} (${user.id})`);
104-
});
105-
});
78+
tinymce.init({
79+
selector: '#editor',
80+
user_id: 'alextaylor'
10681
});
10782
----
10883

109-
NOTE: All lookups are cached. If a user has already been fetched, the same promise will be returned without calling `fetch_users` again.
84+
=== Complete setup with `fetch_users`
11085

111-
[[complete-example]]
112-
=== Complete Example with User Database
113-
114-
This example shows how to set up a complete user lookup system with a simulated backend:
86+
This example demonstrates how to simulate user lookup in-browser. In a production environment, the `fetch_users` function would typically make network requests to your backend API.
11587

11688
.Example
11789
[source,js]
@@ -140,58 +112,58 @@ tinymce.init({
140112
return Promise.all(
141113
userIds.map(
142114
(userId) => new Promise(
143-
(resolve) => resolve(userDb[userId] || { id: userId })
115+
(resolve) => resolve(userDb[userId] || { id: userId }) // Return user data or a fallback object if not found
144116
)
145117
)
146118
)
147119
},
148120
});
149121
----
150122

151-
This example demonstrates how to simulate user lookup in-browser. In a production environment, the `fetch_users` function would typically make network requests to your backend API.
123+
NOTE: It is recommended to handle (or catch) promise rejections in the `fetch_users` function by providing fallback data. This will ensure that your application can gracefully handle cases where user data is not found or the network request fails.
152124

153-
[[fallback-behavior]]
154-
=== Fallback Behavior
125+
=== Basic usage
155126

156-
If no `fetch_users` function is configured, {productname} will return fallback users with auto-generated data:
157-
158-
* `name` defaults to the user ID
159-
* `avatar` is an auto-generated SVG using the first letter of the name
160-
161-
This is useful for simpler setups or prototyping:
127+
Once the editor is initialized, you can access the current user ID and fetch user information:
162128

163129
[source,js]
164130
----
165-
tinymce.init({
166-
selector: '#editor',
167-
user_id: 'anonymous-guest'
168-
});
169-
170131
editor.on('init', () => {
171-
const users = editor.userLookup.fetchUsers(['anonymous-guest']);
172-
users['anonymous-guest'].then((user) => {
173-
console.log('Generated fallback user:', user);
132+
// Get the current user ID
133+
const currentUserId = editor.userLookup.userId;
134+
console.log('Current user:', currentUserId);
135+
136+
// Fetch user information
137+
const users = editor.userLookup.fetchUsers([ currentUserId ]);
138+
139+
users[currentUserId].then((user) => {
140+
console.log('Current user name:', user.name);
141+
});
142+
143+
// Handle multiple users
144+
Promise.all(Object.values(users)).then((allUsers) => {
145+
allUsers.forEach((user) => {
146+
console.log(`Fetched: ${user.name} (${user.id})`);
147+
});
174148
});
175149
});
176150
----
177151

178-
== Advanced Usage
179-
180-
[[ui-integration]]
181-
=== UI Integration Example
152+
=== Advanced usage with UI example
182153

183154
This example shows how to create a toolbar button that displays the current user's information:
155+
184156
[source,js]
185157
----
186158
tinymce.init({
187159
selector: '#editor',
188-
user_id: 'current-user',
160+
user_id: 'alextaylor',
189161
setup: (editor) => {
190162
editor.ui.registry.addButton('show-user', {
191163
text: 'Show User',
192164
onAction: () => {
193165
const currentUser = editor.userLookup.userId;
194-
const users = editor.userLookup.fetchUsers([currentUser]);
166+
const users = editor.userLookup.fetchUsers([ currentUser ]);
195167
196168
users[currentUser].then((user) => {
197169
editor.notificationManager.open({
@@ -206,15 +178,26 @@ tinymce.init({
206178
});
207179
----
208180

209-
[[apis]]
210-
== APIs
181+
=== Fallback Behavior
211182

212-
The User Lookup API provides the following methods:
183+
If no `fetch_users` function is configured, {productname} will return fallback users with auto-generated data:
213184

214-
[cols="3,4,2",options="header"]
215-
|===
216-
|Method|Description|Return Type
185+
* `name` defaults to the user ID
186+
* `avatar` is an auto-generated SVG using the first letter of the name
217187

218-
|`editor.userLookup.userId`|Gets the current user's ID, set via the `user_id` configuration option.|`string`
219-
|`editor.userLookup.fetchUsers(userIds)`|Fetches and caches user information for the specified user IDs. Returns an object where each key is a user ID and each value is a Promise that resolves to the user object.|`Object<string, Promise<UserObject>>`
220-
|===
188+
This is useful for simpler setups or prototyping:
189+
190+
[source,js]
191+
----
192+
tinymce.init({
193+
selector: '#editor',
194+
user_id: 'alextaylor'
195+
});
196+
197+
editor.on('init', () => {
198+
const users = editor.userLookup.fetchUsers(['alextaylor']);
199+
users['alextaylor'].then((user) => {
200+
console.log('Generated fallback user:', user);
201+
});
202+
});
203+
----

modules/ROOT/partials/configuration/suggestededits_access.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[suggestededits_access]]
22
== `suggestededits_access`
33

4-
The `suggestededits_access` option determines the level of access a user has to the {pluginname} view. This setting is crucial for controlling who can accept or reject suggestions, add feedback, or view the document in read-only mode. When used in conjunction with the `readonly` option, it allows for fine-grained control over user permissions.
4+
The `suggestededits_access` option determines the level of access a user has to the {pluginname} view. This setting is crucial for controlling who can accept or reject suggestions, add feedback, or view suggestions in read-only mode. The `suggestededits_access` option does not control access to the editor content, however when used in conjunction with the xref:editor-important-options#readonly[`readonly`] option it allows for fine-grained control over user permissions.
55

66
When set to:
77

modules/ROOT/partials/configuration/suggestededits_content.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When set to:
88
* `'html'`: the editor loads content normally, and the plugin synchronises the model with the content. This simplifies the configuration of {pluginname} in an existing integration, by attaching the {pluginname} model as an additional field alongside the editor content.
99
* `'model'`: the editor uses the `suggestededits_model` option to generate the initial content, ignoring any pre-existing content in the editor. With this configuration, you only need to store and provide the model, simplifying the integration of the {pluginname} plugin.
1010

11-
NOTE: The integrator is responsible for saving the model and providing it on the next load using the `suggestededits_model` option.
11+
NOTE: You are responsible for saving the model and providing it on the next load using the `suggestededits_model` option.
1212

1313
*Type:* `+String+`
1414

modules/ROOT/partials/events/suggestededits-events.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The following events are provided by the xref:{plugincode}.adoc[{pluginname} plugin].
22

3-
[cols="1,1,2",options="header"]
3+
[cols="2,1,3",options="header"]
44
|===
55
|Name |Data |Description
66
|SuggestedEditsBeginReview |N/A |The Suggested Edits view has opened.

0 commit comments

Comments
 (0)