@fluidframework/react 2.83.0 → 2.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -0
  3. package/lib/index.d.ts +2 -0
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +2 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/propNode.js.map +1 -1
  8. package/lib/test/mochaHooks.js +13 -0
  9. package/lib/test/mochaHooks.js.map +1 -0
  10. package/lib/test/text/plainUtils.test.js +75 -0
  11. package/lib/test/text/plainUtils.test.js.map +1 -0
  12. package/lib/test/text/textEditor.test.js +704 -0
  13. package/lib/test/text/textEditor.test.js.map +1 -0
  14. package/lib/test/undoRedo.test.js +62 -0
  15. package/lib/test/undoRedo.test.js.map +1 -0
  16. package/lib/test/useObservation.spec.js +0 -1
  17. package/lib/test/useObservation.spec.js.map +1 -1
  18. package/lib/test/useTree.spec.js +0 -1
  19. package/lib/test/useTree.spec.js.map +1 -1
  20. package/lib/text/formatted/index.d.ts +6 -0
  21. package/lib/text/formatted/index.d.ts.map +1 -0
  22. package/lib/text/formatted/index.js +6 -0
  23. package/lib/text/formatted/index.js.map +1 -0
  24. package/lib/text/formatted/quillFormattedView.d.ts +54 -0
  25. package/lib/text/formatted/quillFormattedView.d.ts.map +1 -0
  26. package/lib/text/formatted/quillFormattedView.js +426 -0
  27. package/lib/text/formatted/quillFormattedView.js.map +1 -0
  28. package/lib/text/index.d.ts +7 -0
  29. package/lib/text/index.d.ts.map +1 -0
  30. package/lib/text/index.js +7 -0
  31. package/lib/text/index.js.map +1 -0
  32. package/lib/text/plain/index.d.ts +7 -0
  33. package/lib/text/plain/index.d.ts.map +1 -0
  34. package/lib/text/plain/index.js +7 -0
  35. package/lib/text/plain/index.js.map +1 -0
  36. package/lib/text/plain/plainTextView.d.ts +14 -0
  37. package/lib/text/plain/plainTextView.d.ts.map +1 -0
  38. package/lib/text/plain/plainTextView.js +75 -0
  39. package/lib/text/plain/plainTextView.js.map +1 -0
  40. package/lib/text/plain/plainUtils.d.ts +23 -0
  41. package/lib/text/plain/plainUtils.d.ts.map +1 -0
  42. package/lib/text/plain/plainUtils.js +51 -0
  43. package/lib/text/plain/plainUtils.js.map +1 -0
  44. package/lib/text/plain/quillView.d.ts +22 -0
  45. package/lib/text/plain/quillView.d.ts.map +1 -0
  46. package/lib/text/plain/quillView.js +112 -0
  47. package/lib/text/plain/quillView.js.map +1 -0
  48. package/lib/undoRedo.d.ts +51 -0
  49. package/lib/undoRedo.d.ts.map +1 -0
  50. package/lib/undoRedo.js +76 -0
  51. package/lib/undoRedo.js.map +1 -0
  52. package/package.json +26 -45
  53. package/react.test-files.tar +0 -0
  54. package/src/index.ts +10 -0
  55. package/src/propNode.ts +1 -1
  56. package/src/text/formatted/index.ts +11 -0
  57. package/src/text/formatted/quillFormattedView.tsx +509 -0
  58. package/src/text/index.ts +15 -0
  59. package/src/text/plain/index.ts +7 -0
  60. package/src/text/plain/plainTextView.tsx +110 -0
  61. package/src/text/plain/plainUtils.ts +68 -0
  62. package/src/text/plain/quillView.tsx +149 -0
  63. package/src/undoRedo.ts +117 -0
  64. package/tsconfig.json +6 -0
  65. package/api-extractor/api-extractor-lint-alpha.cjs.json +0 -5
  66. package/api-extractor/api-extractor-lint-beta.cjs.json +0 -5
  67. package/api-extractor/api-extractor-lint-public.cjs.json +0 -5
  68. package/dist/alpha.d.ts +0 -45
  69. package/dist/beta.d.ts +0 -15
  70. package/dist/index.d.ts +0 -16
  71. package/dist/index.d.ts.map +0 -1
  72. package/dist/index.js +0 -26
  73. package/dist/index.js.map +0 -1
  74. package/dist/package.json +0 -4
  75. package/dist/propNode.d.ts +0 -114
  76. package/dist/propNode.d.ts.map +0 -1
  77. package/dist/propNode.js +0 -43
  78. package/dist/propNode.js.map +0 -1
  79. package/dist/public.d.ts +0 -15
  80. package/dist/reactSharedTreeView.d.ts +0 -119
  81. package/dist/reactSharedTreeView.d.ts.map +0 -1
  82. package/dist/reactSharedTreeView.js +0 -206
  83. package/dist/reactSharedTreeView.js.map +0 -1
  84. package/dist/simpleIdentifier.d.ts +0 -19
  85. package/dist/simpleIdentifier.d.ts.map +0 -1
  86. package/dist/simpleIdentifier.js +0 -33
  87. package/dist/simpleIdentifier.js.map +0 -1
  88. package/dist/useObservation.d.ts +0 -83
  89. package/dist/useObservation.d.ts.map +0 -1
  90. package/dist/useObservation.js +0 -295
  91. package/dist/useObservation.js.map +0 -1
  92. package/dist/useTree.d.ts +0 -80
  93. package/dist/useTree.d.ts.map +0 -1
  94. package/dist/useTree.js +0 -137
  95. package/dist/useTree.js.map +0 -1
  96. package/tsconfig.cjs.json +0 -7
@@ -0,0 +1,426 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { assert } from "@fluidframework/core-utils/internal";
6
+ import { Tree, TreeAlpha, FormattedTextAsTree } from "@fluidframework/tree/internal";
7
+ export { FormattedTextAsTree } from "@fluidframework/tree/internal";
8
+ import Quill from "quill";
9
+ import DeltaPackage from "quill-delta";
10
+ import * as React from "react";
11
+ import * as ReactDOM from "react-dom";
12
+ import { unwrapPropTreeNode } from "../../propNode.js";
13
+ const Delta = DeltaPackage.default;
14
+ /**
15
+ * A React component for formatted text editing.
16
+ * @remarks
17
+ * Uses {@link @fluidframework/tree#FormattedTextAsTree.Tree} for the data-model and Quill for the rich text editor UI.
18
+ * @internal
19
+ */
20
+ export const FormattedMainView = React.forwardRef(({ root, undoRedo }, ref) => {
21
+ return React.createElement(FormattedTextEditorView, { root: root, undoRedo: undoRedo, ref: ref });
22
+ });
23
+ FormattedMainView.displayName = "FormattedMainView";
24
+ /** Quill size names mapped to pixel values for tree storage. */
25
+ const sizeMap = { small: 10, large: 18, huge: 24 };
26
+ /** Reverse mapping: pixel values back to Quill size names for display. */
27
+ const sizeReverse = { 10: "small", 18: "large", 24: "huge" };
28
+ /** Set of recognized font families for Quill. */
29
+ const fontSet = new Set(["monospace", "serif", "sans-serif", "Arial"]);
30
+ /** Default formatting values when no explicit format is specified. */
31
+ const defaultSize = 12;
32
+ /** Default font when no explicit font is specified. */
33
+ const defaultFont = "Arial";
34
+ /**
35
+ * Parse CSS font-size from a pasted HTML element's inline style.
36
+ * Returns a Quill size name if the pixel value matches a supported size, undefined otherwise.
37
+ * 12px is the default size and returns undefined (no Quill attribute needed).
38
+ */
39
+ export function parseCssFontSize(node) {
40
+ const style = node.style.fontSize;
41
+ if (!style)
42
+ return undefined;
43
+ // check if pixel value is in <size>px format
44
+ if (style.endsWith("px")) {
45
+ // Parse pixel value (e.g., "18px" -> 18)
46
+ const parsed = Number.parseFloat(style);
47
+ if (Number.isNaN(parsed))
48
+ return undefined;
49
+ // Round to nearest integer and look up Quill size name
50
+ const rounded = Math.round(parsed);
51
+ if (rounded in sizeReverse) {
52
+ return sizeReverse[rounded];
53
+ }
54
+ }
55
+ return undefined;
56
+ }
57
+ /**
58
+ * Parse CSS font-family from a pasted HTML element's inline style.
59
+ * Tries fonts in priority order (first to last per CSS spec) and returns
60
+ * the first recognized Quill font value.
61
+ */
62
+ export function parseCssFontFamily(node) {
63
+ const style = node.style.fontFamily;
64
+ if (style === "")
65
+ return undefined;
66
+ // Splitting on "," does not handle commas inside quoted font names, and escape
67
+ // sequences within font names are not supported. This is fine since none of the
68
+ // font names we match against contain commas or escapes.
69
+ const fonts = style.split(",");
70
+ for (const raw of fonts) {
71
+ // Trim whitespace and leading and trailing quotes
72
+ const font = raw.trim().replace(/^["']/, "").replace(/["']$/, "");
73
+ // check if font is in our supported font set
74
+ if (fontSet.has(font)) {
75
+ return font;
76
+ }
77
+ }
78
+ // No recognized font family found; fall back to default (Arial)
79
+ return undefined;
80
+ }
81
+ /**
82
+ * Clipboard matcher that preserves recognized font-size and font-family
83
+ * from pasted HTML elements. Applies each format independently via
84
+ * compose/retain so new attributes can be added without risk of an
85
+ * early return skipping them.
86
+ * @see https://quilljs.com/docs/modules/clipboard#addmatcher
87
+ */
88
+ export function clipboardFormatMatcher(node, delta) {
89
+ if (!(node instanceof HTMLElement))
90
+ return delta;
91
+ const size = parseCssFontSize(node);
92
+ const font = parseCssFontFamily(node);
93
+ let result = delta;
94
+ if (size !== undefined) {
95
+ result = result.compose(new Delta().retain(result.length(), { size }));
96
+ }
97
+ if (font !== undefined) {
98
+ result = result.compose(new Delta().retain(result.length(), { font }));
99
+ }
100
+ return result;
101
+ }
102
+ /**
103
+ * Parse a size value from Quill into a numeric pixel value.
104
+ * Handles Quill's named sizes (small, large, huge), numeric values, and pixel strings.
105
+ */
106
+ function parseSize(size) {
107
+ if (typeof size === "number")
108
+ return size;
109
+ if (size === "small" || size === "large" || size === "huge") {
110
+ return sizeMap[size];
111
+ }
112
+ if (typeof size === "string") {
113
+ const parsed = Number.parseInt(size, 10);
114
+ if (!Number.isNaN(parsed)) {
115
+ return parsed;
116
+ }
117
+ }
118
+ return defaultSize;
119
+ }
120
+ /**
121
+ * Convert Quill attributes to a complete CharacterFormat object.
122
+ * Used when inserting new characters - all format properties must have values.
123
+ * Missing attributes default to false/default values.
124
+ */
125
+ function quillAttrsToFormat(attrs) {
126
+ return {
127
+ bold: attrs?.bold === true,
128
+ italic: attrs?.italic === true,
129
+ underline: attrs?.underline === true,
130
+ size: parseSize(attrs?.size),
131
+ font: typeof attrs?.font === "string" ? attrs.font : defaultFont,
132
+ };
133
+ }
134
+ /**
135
+ * Convert Quill attributes to a partial CharacterFormat object.
136
+ * Used when applying formatting to existing text via retain operations.
137
+ * Only includes properties that were explicitly set in the Quill attributes,
138
+ * allowing selective format updates without overwriting unrelated properties.
139
+ */
140
+ function quillAttrsToPartial(attrs) {
141
+ if (!attrs)
142
+ return {};
143
+ const format = {};
144
+ // Only include attributes that are explicitly present in the Quill delta
145
+ if ("bold" in attrs)
146
+ format.bold = attrs.bold === true;
147
+ if ("italic" in attrs)
148
+ format.italic = attrs.italic === true;
149
+ if ("underline" in attrs)
150
+ format.underline = attrs.underline === true;
151
+ if ("size" in attrs)
152
+ format.size = parseSize(attrs.size);
153
+ if ("font" in attrs)
154
+ format.font = typeof attrs.font === "string" ? attrs.font : defaultFont;
155
+ return format;
156
+ }
157
+ /**
158
+ * Convert a CharacterFormat from the tree to Quill attributes.
159
+ * Used when building Quill deltas from tree content to sync external changes.
160
+ * Only includes non-default values to keep deltas minimal.
161
+ */
162
+ function formatToQuillAttrs(format) {
163
+ const attrs = {};
164
+ // Only include non-default formatting to keep Quill deltas minimal
165
+ if (format.bold)
166
+ attrs.bold = true;
167
+ if (format.italic)
168
+ attrs.italic = true;
169
+ if (format.underline)
170
+ attrs.underline = true;
171
+ if (format.size !== defaultSize) {
172
+ // Convert pixel value back to Quill size name if possible
173
+ attrs.size =
174
+ format.size in sizeReverse
175
+ ? sizeReverse[format.size]
176
+ : `${format.size}px`;
177
+ }
178
+ if (format.font !== defaultFont)
179
+ attrs.font = format.font;
180
+ return attrs;
181
+ }
182
+ /**
183
+ * Build a Quill Delta representing the full tree content.
184
+ * Iterates through formatted characters and groups consecutive characters
185
+ * with identical formatting into single insert operations for efficiency.
186
+ *
187
+ * @remarks
188
+ * This is used to sync Quill's display when the tree changes externally
189
+ * (e.g., from a remote collaborator's edit).
190
+ */
191
+ function buildDeltaFromTree(root) {
192
+ const ops = [];
193
+ // Accumulator for current run of identically-formatted text
194
+ let text = "";
195
+ let attrs = {};
196
+ // JSON key for current attributes, used for equality comparison
197
+ // TODO:Performance: implement faster equality check.
198
+ let key = "";
199
+ // Helper to push accumulated text as an insert operation
200
+ const pushRun = () => {
201
+ if (!text)
202
+ return;
203
+ const op = { insert: text };
204
+ if (Object.keys(attrs).length > 0)
205
+ op.attributes = attrs;
206
+ ops.push(op);
207
+ };
208
+ // Iterate through each formatted character in the tree
209
+ // TODO:Performance: Optimize this loop by adding an API to get runs to FormattedTextAsTree.Tree, and implementing that using cursors.
210
+ // Something like `getUniformRun(startIndex, maxLength): number` and `substring(startIndex, length): string`.
211
+ for (const atom of root.charactersWithFormatting()) {
212
+ const a = formatToQuillAttrs(atom.format);
213
+ const k = JSON.stringify(a);
214
+ if (k === key) {
215
+ // Same formatting as previous character - extend current run
216
+ text += atom.content.content;
217
+ }
218
+ else {
219
+ // Different formatting - push current run and start new one
220
+ pushRun();
221
+ text = atom.content.content;
222
+ attrs = a;
223
+ key = k;
224
+ }
225
+ }
226
+ // Push any remaining accumulated text
227
+ pushRun();
228
+ // Quill expects documents to end with a newline
229
+ // eslint-disable-next-line unicorn/prefer-at -- .at() not available in target
230
+ const last = ops[ops.length - 1];
231
+ if (typeof last?.insert !== "string" || !last.insert.endsWith("\n")) {
232
+ ops.push({ insert: "\n" });
233
+ }
234
+ return ops;
235
+ }
236
+ /**
237
+ * The formatted text editor view component with Quill integration.
238
+ * Uses FormattedTextAsTree for collaborative rich text storage with formatting.
239
+ *
240
+ * @remarks
241
+ * This component uses event-based synchronization via Tree.on("treeChanged")
242
+ * to efficiently handle external changes without expensive render-time operations.
243
+ * Unlike the plain text version, this component uses Quill's delta operations
244
+ * to make targeted edits (insert at index, delete range, format range) rather
245
+ * than replacing all content on each change.
246
+ */
247
+ const FormattedTextEditorView = React.forwardRef(({ root: propRoot, undoRedo }, ref) => {
248
+ // Unwrap the PropTreeNode to get the actual tree node
249
+ const root = unwrapPropTreeNode(propRoot);
250
+ // DOM element where Quill will mount its editor
251
+ const editorRef = React.useRef(null);
252
+ // Quill instance, persisted across renders to avoid re-initialization
253
+ const quillRef = React.useRef(null);
254
+ // Guards against update loops between Quill and the tree
255
+ const isUpdating = React.useRef(false);
256
+ // Container element for undo/redo button portal
257
+ const [undoRedoContainer, setUndoRedoContainer] = React.useState(undefined);
258
+ // Force re-render when undo/redo state changes
259
+ const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
260
+ // Expose undo/redo methods via ref
261
+ React.useImperativeHandle(ref, () => ({
262
+ undo: () => undoRedo?.undo(),
263
+ redo: () => undoRedo?.redo(),
264
+ }));
265
+ // Initialize Quill editor with formatting toolbar using Quill provided CSS
266
+ React.useEffect(() => {
267
+ if (!editorRef.current || quillRef.current)
268
+ return;
269
+ const quill = new Quill(editorRef.current, {
270
+ theme: "snow",
271
+ placeholder: "Start typing with formatting...",
272
+ modules: {
273
+ history: false, // Disable Quill's built-in undo/redo
274
+ toolbar: [
275
+ ["bold", "italic", "underline"],
276
+ [{ size: ["small", false, "large", "huge"] }],
277
+ [{ font: [] }],
278
+ ["clean"],
279
+ ],
280
+ clipboard: [Node.ELEMENT_NODE, clipboardFormatMatcher],
281
+ },
282
+ });
283
+ // Set initial content from tree
284
+ quill.setContents(buildDeltaFromTree(root));
285
+ // Listen to local Quill changes and apply them to the tree.
286
+ // We process delta operations to make targeted edits, preserving collaboration integrity.
287
+ // Note: Quill uses UTF-16 code units for positions, but the tree uses Unicode codepoints.
288
+ // We must convert between them to handle emoji and other non-BMP characters correctly.
289
+ //
290
+ // The typing here is very fragile: if no parameter types are given,
291
+ // the inference for this event is strongly typed, but the types are wrong (The wrong "Delta" type is provided).
292
+ // This is likely related to the node16 module resolution issues with quill-delta.
293
+ // If we break that inference by adding types, `any` is inferred for all of them, so incorrect types here would still compile.
294
+ quill.on("text-change", (delta, _oldDelta, source) => {
295
+ if (source !== "user" || isUpdating.current)
296
+ return;
297
+ isUpdating.current = true;
298
+ // Wrap all tree mutations in a transaction so they undo/redo as one atomic unit.
299
+ // If the node is not part of a branch (e.g. unhydrated), apply edits directly.
300
+ const branch = TreeAlpha.branch(root);
301
+ const applyDelta = () => {
302
+ // Helper to count Unicode codepoints in a string
303
+ const codepointCount = (s) => [...s].length;
304
+ // Get current content for UTF-16 to codepoint position mapping
305
+ // We update this as we process operations to keep positions accurate
306
+ let content = root.fullString();
307
+ let utf16Pos = 0; // Position in UTF-16 code units (Quill's view)
308
+ let cpPos = 0; // Position in codepoints (tree's view)
309
+ for (const op of delta.ops) {
310
+ if (op.retain !== undefined) {
311
+ // The docs for retain imply this is always a number, but the type definitions allow a record here.
312
+ // It is unknown why the type definitions allow a record as they have no doc comments.
313
+ // For now this assert seems to be passing, so we just assume its always a number.
314
+ assert(typeof op.retain === "number", 0xcdf /* Expected retain count to be a number */);
315
+ // Convert UTF-16 retain count to codepoint count
316
+ const retainedStr = content.slice(utf16Pos, utf16Pos + op.retain);
317
+ const cpCount = codepointCount(retainedStr);
318
+ if (op.attributes) {
319
+ root.formatRange(cpPos, cpPos + cpCount, quillAttrsToPartial(op.attributes));
320
+ }
321
+ utf16Pos += op.retain;
322
+ cpPos += cpCount;
323
+ }
324
+ else if (op.delete !== undefined) {
325
+ // Convert UTF-16 delete count to codepoint count
326
+ const deletedStr = content.slice(utf16Pos, utf16Pos + op.delete);
327
+ const cpCount = codepointCount(deletedStr);
328
+ root.removeRange(cpPos, cpPos + cpCount);
329
+ // Update content to reflect deletion for future position calculations
330
+ content = content.slice(0, utf16Pos) + content.slice(utf16Pos + op.delete);
331
+ // Don't advance positions - next op starts at same position
332
+ }
333
+ else if (typeof op.insert === "string") {
334
+ // Insert: add new text with formatting at current position
335
+ root.defaultFormat = new FormattedTextAsTree.CharacterFormat(quillAttrsToFormat(op.attributes));
336
+ root.insertAt(cpPos, op.insert);
337
+ // Update content to reflect insertion
338
+ content = content.slice(0, utf16Pos) + op.insert + content.slice(utf16Pos);
339
+ // Advance by inserted content length
340
+ utf16Pos += op.insert.length;
341
+ cpPos += codepointCount(op.insert);
342
+ }
343
+ }
344
+ };
345
+ if (branch === undefined) {
346
+ applyDelta();
347
+ }
348
+ else {
349
+ branch.runTransaction(applyDelta);
350
+ }
351
+ isUpdating.current = false;
352
+ });
353
+ quillRef.current = quill;
354
+ // Create container for React-controlled undo/redo buttons and prepend to toolbar
355
+ const toolbar = editorRef.current.previousElementSibling;
356
+ const container = document.createElement("span");
357
+ container.className = "ql-formats";
358
+ toolbar.prepend(container);
359
+ setUndoRedoContainer(container);
360
+ // In React strict mode, effects run twice. The `!quillRef.current` check above
361
+ // makes the second call a no-op, preventing double-initialization of Quill.
362
+ // eslint-disable-next-line react-hooks/exhaustive-deps
363
+ }, []);
364
+ // Sync Quill when tree changes externally (e.g., from remote collaborators).
365
+ // Uses event subscription instead of render-time observation for efficiency.
366
+ React.useEffect(() => {
367
+ return Tree.on(root, "treeChanged", () => {
368
+ // Skip if we caused the tree change ourselves via the text-change handler
369
+ if (!quillRef.current || isUpdating.current)
370
+ return;
371
+ // TODO:Performance: Once SharedTree has better ArrayNode change events,
372
+ // use those events to construct a delta, instead of rebuilding a new delta then diffing every edit.
373
+ // After doing the optimization, keep this diffing logic as a way to test for de-sync between the tree and Quill:
374
+ // Use it in tests and possibly occasionally in debug builds.
375
+ const treeDelta = buildDeltaFromTree(root);
376
+ // eslint doesn't seem to be resolving the types correctly here.
377
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
378
+ const quillDelta = quillRef.current.getContents();
379
+ // Compute diff between current Quill state and tree state
380
+ const diff = new Delta(quillDelta).diff(new Delta(treeDelta));
381
+ // Only update if there are actual differences
382
+ if (diff.ops.length > 0) {
383
+ isUpdating.current = true;
384
+ // Apply only the diff for surgical updates (better cursor preservation)
385
+ quillRef.current.updateContents(diff.ops);
386
+ isUpdating.current = false;
387
+ }
388
+ });
389
+ }, [root]);
390
+ // Subscribe to undo/redo state changes to update button disabled state
391
+ React.useEffect(() => {
392
+ if (!undoRedo)
393
+ return;
394
+ return undoRedo.onStateChange(() => {
395
+ forceUpdate();
396
+ });
397
+ }, [undoRedo]);
398
+ // Render undo/redo buttons via portal into Quill toolbar
399
+ const undoRedoButtons = undoRedoContainer
400
+ ? ReactDOM.createPortal(React.createElement(React.Fragment, null,
401
+ React.createElement("button", { type: "button", className: "ql-undo", disabled: undoRedo?.canUndo() !== true, onClick: () => undoRedo?.undo() }),
402
+ React.createElement("button", { type: "button", className: "ql-redo", disabled: undoRedo?.canRedo() !== true, onClick: () => undoRedo?.redo() })), undoRedoContainer)
403
+ : undefined;
404
+ return (React.createElement("div", { style: { height: "100%", display: "flex", flexDirection: "column" } },
405
+ React.createElement("style", null, `
406
+ .ql-container { height: 100%; font-size: 14px; }
407
+ .ql-editor { height: 100%; outline: none; }
408
+ .ql-editor.ql-blank::before { color: #999; font-style: italic; }
409
+ .ql-toolbar { border-radius: 4px 4px 0 0; background: #f8f9fa; }
410
+ .ql-container.ql-snow { border-radius: 0 0 4px 4px; }
411
+ .ql-undo, .ql-redo { width: 28px !important; }
412
+ .ql-undo::after { content: "↶"; font-size: 18px; }
413
+ .ql-redo::after { content: "↷"; font-size: 18px; }
414
+ .ql-undo:disabled, .ql-redo:disabled { opacity: 0.3; cursor: not-allowed; }
415
+ `),
416
+ React.createElement("h2", { style: { margin: "10px 0" } }, "Collaborative Formatted Text Editor"),
417
+ React.createElement("div", { ref: editorRef, style: {
418
+ flex: 1,
419
+ minHeight: "300px",
420
+ border: "1px solid #ccc",
421
+ borderRadius: "4px",
422
+ } }),
423
+ undoRedoButtons));
424
+ });
425
+ FormattedTextEditorView.displayName = "FormattedTextEditorView";
426
+ //# sourceMappingURL=quillFormattedView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quillFormattedView.js","sourceRoot":"","sources":["../../../src/text/formatted/quillFormattedView.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAA6B,MAAM,OAAO,CAAC;AAClD,OAAO,YAAY,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAqB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAM1E,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC;AAkBnC;;;;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AM,EAAE,gBAAgB;gBACxB,YAAY,EAAE,KAAK;aACnB,GACA;QACD,eAAe,CACX,CACN,CAAC;AACH,CAAC,CAAC,CAAC;AACH,uBAAuB,CAAC,WAAW,GAAG,yBAAyB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { Tree, TreeAlpha, FormattedTextAsTree } from \"@fluidframework/tree/internal\";\nexport { FormattedTextAsTree } from \"@fluidframework/tree/internal\";\nimport Quill, { type EmitterSource } from \"quill\";\nimport DeltaPackage from \"quill-delta\";\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\n\nimport { type PropTreeNode, unwrapPropTreeNode } from \"../../propNode.js\";\nimport type { UndoRedo } from \"../../undoRedo.js\";\n\n// Workaround for quill-delta's export style not working well with node16 module resolution.\ntype Delta = DeltaPackage.default;\ntype QuillDeltaOp = DeltaPackage.Op;\nconst Delta = DeltaPackage.default;\n\n/**\n * Props for the FormattedMainView component.\n * @input @internal\n */\nexport interface FormattedMainViewProps {\n\treadonly root: PropTreeNode<FormattedTextAsTree.Tree>;\n\t/** Optional undo/redo stack for the editor. */\n\treadonly undoRedo?: UndoRedo;\n}\n\n/**\n * Ref handle exposing undo/redo methods for the formatted editor.\n * @input @internal\n */\nexport type FormattedEditorHandle = Pick<UndoRedo, \"undo\" | \"redo\">;\n\n/**\n * A React component for formatted text editing.\n * @remarks\n * Uses {@link @fluidframework/tree#FormattedTextAsTree.Tree} for the data-model and Quill for the rich text editor UI.\n * @internal\n */\nexport const FormattedMainView = React.forwardRef<\n\tFormattedEditorHandle,\n\tFormattedMainViewProps\n>(({ root, undoRedo }, ref) => {\n\treturn <FormattedTextEditorView root={root} undoRedo={undoRedo} ref={ref} />;\n});\nFormattedMainView.displayName = \"FormattedMainView\";\n\n/** Quill size names mapped to pixel values for tree storage. */\nconst sizeMap = { small: 10, large: 18, huge: 24 } as const;\n/** Reverse mapping: pixel values back to Quill size names for display. */\nconst sizeReverse = { 10: \"small\", 18: \"large\", 24: \"huge\" } as const;\n/** Set of recognized font families for Quill. */\nconst fontSet = new Set<string>([\"monospace\", \"serif\", \"sans-serif\", \"Arial\"]);\n/** Default formatting values when no explicit format is specified. */\nconst defaultSize = 12;\n/** Default font when no explicit font is specified. */\nconst defaultFont = \"Arial\";\n/**\n * Parse CSS font-size from a pasted HTML element's inline style.\n * Returns a Quill size name if the pixel value matches a supported size, undefined otherwise.\n * 12px is the default size and returns undefined (no Quill attribute needed).\n */\nexport function parseCssFontSize(node: HTMLElement): string | undefined {\n\tconst style = node.style.fontSize;\n\tif (!style) return undefined;\n\n\t// check if pixel value is in <size>px format\n\tif (style.endsWith(\"px\")) {\n\t\t// Parse pixel value (e.g., \"18px\" -> 18)\n\t\tconst parsed = Number.parseFloat(style);\n\t\tif (Number.isNaN(parsed)) return undefined;\n\n\t\t// Round to nearest integer and look up Quill size name\n\t\tconst rounded = Math.round(parsed);\n\t\tif (rounded in sizeReverse) {\n\t\t\treturn sizeReverse[rounded as keyof typeof sizeReverse];\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Parse CSS font-family from a pasted HTML element's inline style.\n * Tries fonts in priority order (first to last per CSS spec) and returns\n * the first recognized Quill font value.\n */\nexport function parseCssFontFamily(node: HTMLElement): string | undefined {\n\tconst style = node.style.fontFamily;\n\tif (style === \"\") return undefined;\n\n\t// Splitting on \",\" does not handle commas inside quoted font names, and escape\n\t// sequences within font names are not supported. This is fine since none of the\n\t// font names we match against contain commas or escapes.\n\tconst fonts = style.split(\",\");\n\tfor (const raw of fonts) {\n\t\t// Trim whitespace and leading and trailing quotes\n\t\tconst font = raw.trim().replace(/^[\"']/, \"\").replace(/[\"']$/, \"\");\n\t\t// check if font is in our supported font set\n\t\tif (fontSet.has(font)) {\n\t\t\treturn font;\n\t\t}\n\t}\n\t// No recognized font family found; fall back to default (Arial)\n\treturn undefined;\n}\n\n/**\n * Clipboard matcher that preserves recognized font-size and font-family\n * from pasted HTML elements. Applies each format independently via\n * compose/retain so new attributes can be added without risk of an\n * early return skipping them.\n * @see https://quilljs.com/docs/modules/clipboard#addmatcher\n */\nexport function clipboardFormatMatcher(node: Node, delta: Delta): Delta {\n\tif (!(node instanceof HTMLElement)) return delta;\n\n\tconst size = parseCssFontSize(node);\n\tconst font = parseCssFontFamily(node);\n\n\tlet result = delta;\n\tif (size !== undefined) {\n\t\tresult = result.compose(new Delta().retain(result.length(), { size }));\n\t}\n\tif (font !== undefined) {\n\t\tresult = result.compose(new Delta().retain(result.length(), { font }));\n\t}\n\treturn result;\n}\n\n/**\n * Parse a size value from Quill into a numeric pixel value.\n * Handles Quill's named sizes (small, large, huge), numeric values, and pixel strings.\n */\nfunction parseSize(size: unknown): number {\n\tif (typeof size === \"number\") return size;\n\tif (size === \"small\" || size === \"large\" || size === \"huge\") {\n\t\treturn sizeMap[size];\n\t}\n\tif (typeof size === \"string\") {\n\t\tconst parsed = Number.parseInt(size, 10);\n\t\tif (!Number.isNaN(parsed)) {\n\t\t\treturn parsed;\n\t\t}\n\t}\n\treturn defaultSize;\n}\n\n/**\n * Convert Quill attributes to a complete CharacterFormat object.\n * Used when inserting new characters - all format properties must have values.\n * Missing attributes default to false/default values.\n */\nfunction quillAttrsToFormat(attrs?: Record<string, unknown>): {\n\tbold: boolean;\n\titalic: boolean;\n\tunderline: boolean;\n\tsize: number;\n\tfont: string;\n} {\n\treturn {\n\t\tbold: attrs?.bold === true,\n\t\titalic: attrs?.italic === true,\n\t\tunderline: attrs?.underline === true,\n\t\tsize: parseSize(attrs?.size),\n\t\tfont: typeof attrs?.font === \"string\" ? attrs.font : defaultFont,\n\t};\n}\n\n/**\n * Convert Quill attributes to a partial CharacterFormat object.\n * Used when applying formatting to existing text via retain operations.\n * Only includes properties that were explicitly set in the Quill attributes,\n * allowing selective format updates without overwriting unrelated properties.\n */\nfunction quillAttrsToPartial(\n\tattrs?: Record<string, unknown>,\n): Partial<FormattedTextAsTree.CharacterFormat> {\n\tif (!attrs) return {};\n\tconst format: Partial<FormattedTextAsTree.CharacterFormat> = {};\n\t// Only include attributes that are explicitly present in the Quill delta\n\tif (\"bold\" in attrs) format.bold = attrs.bold === true;\n\tif (\"italic\" in attrs) format.italic = attrs.italic === true;\n\tif (\"underline\" in attrs) format.underline = attrs.underline === true;\n\tif (\"size\" in attrs) format.size = parseSize(attrs.size);\n\tif (\"font\" in attrs) format.font = typeof attrs.font === \"string\" ? attrs.font : defaultFont;\n\treturn format;\n}\n\n/**\n * Convert a CharacterFormat from the tree to Quill attributes.\n * Used when building Quill deltas from tree content to sync external changes.\n * Only includes non-default values to keep deltas minimal.\n */\nfunction formatToQuillAttrs(\n\tformat: FormattedTextAsTree.CharacterFormat,\n): Record<string, unknown> {\n\tconst attrs: Record<string, unknown> = {};\n\t// Only include non-default formatting to keep Quill deltas minimal\n\tif (format.bold) attrs.bold = true;\n\tif (format.italic) attrs.italic = true;\n\tif (format.underline) attrs.underline = true;\n\tif (format.size !== defaultSize) {\n\t\t// Convert pixel value back to Quill size name if possible\n\t\tattrs.size =\n\t\t\tformat.size in sizeReverse\n\t\t\t\t? sizeReverse[format.size as keyof typeof sizeReverse]\n\t\t\t\t: `${format.size}px`;\n\t}\n\tif (format.font !== defaultFont) attrs.font = format.font;\n\treturn attrs;\n}\n\n/**\n * Build a Quill Delta representing the full tree content.\n * Iterates through formatted characters and groups consecutive characters\n * with identical formatting into single insert operations for efficiency.\n *\n * @remarks\n * This is used to sync Quill's display when the tree changes externally\n * (e.g., from a remote collaborator's edit).\n */\nfunction buildDeltaFromTree(root: FormattedTextAsTree.Tree): QuillDeltaOp[] {\n\tconst ops: QuillDeltaOp[] = [];\n\t// Accumulator for current run of identically-formatted text\n\tlet text = \"\";\n\tlet attrs: Record<string, unknown> = {};\n\t// JSON key for current attributes, used for equality comparison\n\t// TODO:Performance: implement faster equality check.\n\tlet key = \"\";\n\n\t// Helper to push accumulated text as an insert operation\n\tconst pushRun = (): void => {\n\t\tif (!text) return;\n\t\tconst op: QuillDeltaOp = { insert: text };\n\t\tif (Object.keys(attrs).length > 0) op.attributes = attrs;\n\t\tops.push(op);\n\t};\n\n\t// Iterate through each formatted character in the tree\n\t// TODO:Performance: Optimize this loop by adding an API to get runs to FormattedTextAsTree.Tree, and implementing that using cursors.\n\t// Something like `getUniformRun(startIndex, maxLength): number` and `substring(startIndex, length): string`.\n\tfor (const atom of root.charactersWithFormatting()) {\n\t\tconst a = formatToQuillAttrs(atom.format);\n\t\tconst k = JSON.stringify(a);\n\t\tif (k === key) {\n\t\t\t// Same formatting as previous character - extend current run\n\t\t\ttext += atom.content.content;\n\t\t} else {\n\t\t\t// Different formatting - push current run and start new one\n\t\t\tpushRun();\n\t\t\ttext = atom.content.content;\n\t\t\tattrs = a;\n\t\t\tkey = k;\n\t\t}\n\t}\n\t// Push any remaining accumulated text\n\tpushRun();\n\n\t// Quill expects documents to end with a newline\n\t// eslint-disable-next-line unicorn/prefer-at -- .at() not available in target\n\tconst last = ops[ops.length - 1];\n\tif (typeof last?.insert !== \"string\" || !last.insert.endsWith(\"\\n\")) {\n\t\tops.push({ insert: \"\\n\" });\n\t}\n\treturn ops;\n}\n\n/**\n * The formatted text editor view component with Quill integration.\n * Uses FormattedTextAsTree for collaborative rich text storage with formatting.\n *\n * @remarks\n * This component uses event-based synchronization via Tree.on(\"treeChanged\")\n * to efficiently handle external changes without expensive render-time operations.\n * Unlike the plain text version, this component uses Quill's delta operations\n * to make targeted edits (insert at index, delete range, format range) rather\n * than replacing all content on each change.\n */\nconst FormattedTextEditorView = React.forwardRef<\n\tFormattedEditorHandle,\n\t{\n\t\troot: PropTreeNode<FormattedTextAsTree.Tree>;\n\t\tundoRedo?: UndoRedo;\n\t}\n>(({ root: propRoot, undoRedo }, ref) => {\n\t// Unwrap the PropTreeNode to get the actual tree node\n\tconst root = unwrapPropTreeNode(propRoot);\n\t// DOM element where Quill will mount its editor\n\tconst editorRef = React.useRef<HTMLDivElement>(null);\n\t// Quill instance, persisted across renders to avoid re-initialization\n\tconst quillRef = React.useRef<Quill | null>(null);\n\t// Guards against update loops between Quill and the tree\n\tconst isUpdating = React.useRef(false);\n\t// Container element for undo/redo button portal\n\tconst [undoRedoContainer, setUndoRedoContainer] = React.useState<HTMLElement | undefined>(\n\t\tundefined,\n\t);\n\t// Force re-render when undo/redo state changes\n\tconst [, forceUpdate] = React.useReducer((x: number) => x + 1, 0);\n\n\t// Expose undo/redo methods via ref\n\tReact.useImperativeHandle(ref, () => ({\n\t\tundo: () => undoRedo?.undo(),\n\t\tredo: () => undoRedo?.redo(),\n\t}));\n\n\t// Initialize Quill editor with formatting toolbar using Quill provided CSS\n\tReact.useEffect(() => {\n\t\tif (!editorRef.current || quillRef.current) return;\n\t\tconst quill = new Quill(editorRef.current, {\n\t\t\ttheme: \"snow\",\n\t\t\tplaceholder: \"Start typing with formatting...\",\n\t\t\tmodules: {\n\t\t\t\thistory: false, // Disable Quill's built-in undo/redo\n\t\t\t\ttoolbar: [\n\t\t\t\t\t[\"bold\", \"italic\", \"underline\"],\n\t\t\t\t\t[{ size: [\"small\", false, \"large\", \"huge\"] }],\n\t\t\t\t\t[{ font: [] }],\n\t\t\t\t\t[\"clean\"],\n\t\t\t\t],\n\t\t\t\tclipboard: [Node.ELEMENT_NODE, clipboardFormatMatcher],\n\t\t\t},\n\t\t});\n\n\t\t// Set initial content from tree\n\t\tquill.setContents(buildDeltaFromTree(root));\n\n\t\t// Listen to local Quill changes and apply them to the tree.\n\t\t// We process delta operations to make targeted edits, preserving collaboration integrity.\n\t\t// Note: Quill uses UTF-16 code units for positions, but the tree uses Unicode codepoints.\n\t\t// We must convert between them to handle emoji and other non-BMP characters correctly.\n\t\t//\n\t\t// The typing here is very fragile: if no parameter types are given,\n\t\t// the inference for this event is strongly typed, but the types are wrong (The wrong \"Delta\" type is provided).\n\t\t// This is likely related to the node16 module resolution issues with quill-delta.\n\t\t// If we break that inference by adding types, `any` is inferred for all of them, so incorrect types here would still compile.\n\t\tquill.on(\"text-change\", (delta: Delta, _oldDelta: Delta, source: EmitterSource) => {\n\t\t\tif (source !== \"user\" || isUpdating.current) return;\n\t\t\tisUpdating.current = true;\n\n\t\t\t// Wrap all tree mutations in a transaction so they undo/redo as one atomic unit.\n\t\t\t// If the node is not part of a branch (e.g. unhydrated), apply edits directly.\n\t\t\tconst branch = TreeAlpha.branch(root);\n\t\t\tconst applyDelta = (): void => {\n\t\t\t\t// Helper to count Unicode codepoints in a string\n\t\t\t\tconst codepointCount = (s: string): number => [...s].length;\n\n\t\t\t\t// Get current content for UTF-16 to codepoint position mapping\n\t\t\t\t// We update this as we process operations to keep positions accurate\n\t\t\t\tlet content = root.fullString();\n\t\t\t\tlet utf16Pos = 0; // Position in UTF-16 code units (Quill's view)\n\t\t\t\tlet cpPos = 0; // Position in codepoints (tree's view)\n\n\t\t\t\tfor (const op of delta.ops) {\n\t\t\t\t\tif (op.retain !== undefined) {\n\t\t\t\t\t\t// The docs for retain imply this is always a number, but the type definitions allow a record here.\n\t\t\t\t\t\t// It is unknown why the type definitions allow a record as they have no doc comments.\n\t\t\t\t\t\t// For now this assert seems to be passing, so we just assume its always a number.\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\ttypeof op.retain === \"number\",\n\t\t\t\t\t\t\t0xcdf /* Expected retain count to be a number */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\t// Convert UTF-16 retain count to codepoint count\n\t\t\t\t\t\tconst retainedStr = content.slice(utf16Pos, utf16Pos + op.retain);\n\t\t\t\t\t\tconst cpCount = codepointCount(retainedStr);\n\n\t\t\t\t\t\tif (op.attributes) {\n\t\t\t\t\t\t\troot.formatRange(cpPos, cpPos + cpCount, quillAttrsToPartial(op.attributes));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tutf16Pos += op.retain;\n\t\t\t\t\t\tcpPos += cpCount;\n\t\t\t\t\t} else if (op.delete !== undefined) {\n\t\t\t\t\t\t// Convert UTF-16 delete count to codepoint count\n\t\t\t\t\t\tconst deletedStr = content.slice(utf16Pos, utf16Pos + op.delete);\n\t\t\t\t\t\tconst cpCount = codepointCount(deletedStr);\n\n\t\t\t\t\t\troot.removeRange(cpPos, cpPos + cpCount);\n\t\t\t\t\t\t// Update content to reflect deletion for future position calculations\n\t\t\t\t\t\tcontent = content.slice(0, utf16Pos) + content.slice(utf16Pos + op.delete);\n\t\t\t\t\t\t// Don't advance positions - next op starts at same position\n\t\t\t\t\t} else if (typeof op.insert === \"string\") {\n\t\t\t\t\t\t// Insert: add new text with formatting at current position\n\t\t\t\t\t\troot.defaultFormat = new FormattedTextAsTree.CharacterFormat(\n\t\t\t\t\t\t\tquillAttrsToFormat(op.attributes),\n\t\t\t\t\t\t);\n\t\t\t\t\t\troot.insertAt(cpPos, op.insert);\n\t\t\t\t\t\t// Update content to reflect insertion\n\t\t\t\t\t\tcontent = content.slice(0, utf16Pos) + op.insert + content.slice(utf16Pos);\n\t\t\t\t\t\t// Advance by inserted content length\n\t\t\t\t\t\tutf16Pos += op.insert.length;\n\t\t\t\t\t\tcpPos += codepointCount(op.insert);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (branch === undefined) {\n\t\t\t\tapplyDelta();\n\t\t\t} else {\n\t\t\t\tbranch.runTransaction(applyDelta);\n\t\t\t}\n\n\t\t\tisUpdating.current = false;\n\t\t});\n\n\t\tquillRef.current = quill;\n\n\t\t// Create container for React-controlled undo/redo buttons and prepend to toolbar\n\t\tconst toolbar = editorRef.current.previousElementSibling as HTMLElement;\n\t\tconst container = document.createElement(\"span\");\n\t\tcontainer.className = \"ql-formats\";\n\t\ttoolbar.prepend(container);\n\t\tsetUndoRedoContainer(container);\n\t\t// In React strict mode, effects run twice. The `!quillRef.current` check above\n\t\t// makes the second call a no-op, preventing double-initialization of Quill.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, []);\n\n\t// Sync Quill when tree changes externally (e.g., from remote collaborators).\n\t// Uses event subscription instead of render-time observation for efficiency.\n\tReact.useEffect(() => {\n\t\treturn Tree.on(root, \"treeChanged\", () => {\n\t\t\t// Skip if we caused the tree change ourselves via the text-change handler\n\t\t\tif (!quillRef.current || isUpdating.current) return;\n\n\t\t\t// TODO:Performance: Once SharedTree has better ArrayNode change events,\n\t\t\t// use those events to construct a delta, instead of rebuilding a new delta then diffing every edit.\n\t\t\t// After doing the optimization, keep this diffing logic as a way to test for de-sync between the tree and Quill:\n\t\t\t// Use it in tests and possibly occasionally in debug builds.\n\t\t\tconst treeDelta = buildDeltaFromTree(root);\n\n\t\t\t// eslint doesn't seem to be resolving the types correctly here.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst quillDelta: Delta = quillRef.current.getContents();\n\n\t\t\t// Compute diff between current Quill state and tree state\n\t\t\tconst diff = new Delta(quillDelta).diff(new Delta(treeDelta));\n\n\t\t\t// Only update if there are actual differences\n\t\t\tif (diff.ops.length > 0) {\n\t\t\t\tisUpdating.current = true;\n\n\t\t\t\t// Apply only the diff for surgical updates (better cursor preservation)\n\t\t\t\tquillRef.current.updateContents(diff.ops);\n\n\t\t\t\tisUpdating.current = false;\n\t\t\t}\n\t\t});\n\t}, [root]);\n\n\t// Subscribe to undo/redo state changes to update button disabled state\n\tReact.useEffect(() => {\n\t\tif (!undoRedo) return;\n\t\treturn undoRedo.onStateChange(() => {\n\t\t\tforceUpdate();\n\t\t});\n\t}, [undoRedo]);\n\n\t// Render undo/redo buttons via portal into Quill toolbar\n\tconst undoRedoButtons = undoRedoContainer\n\t\t? ReactDOM.createPortal(\n\t\t\t\t<>\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName=\"ql-undo\"\n\t\t\t\t\t\tdisabled={undoRedo?.canUndo() !== true}\n\t\t\t\t\t\tonClick={() => undoRedo?.undo()}\n\t\t\t\t\t/>\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName=\"ql-redo\"\n\t\t\t\t\t\tdisabled={undoRedo?.canRedo() !== true}\n\t\t\t\t\t\tonClick={() => undoRedo?.redo()}\n\t\t\t\t\t/>\n\t\t\t\t</>,\n\t\t\t\tundoRedoContainer,\n\t\t\t)\n\t\t: undefined;\n\n\treturn (\n\t\t<div style={{ height: \"100%\", display: \"flex\", flexDirection: \"column\" }}>\n\t\t\t<style>{`\n\t\t\t\t.ql-container { height: 100%; font-size: 14px; }\n\t\t\t\t.ql-editor { height: 100%; outline: none; }\n\t\t\t\t.ql-editor.ql-blank::before { color: #999; font-style: italic; }\n\t\t\t\t.ql-toolbar { border-radius: 4px 4px 0 0; background: #f8f9fa; }\n\t\t\t\t.ql-container.ql-snow { border-radius: 0 0 4px 4px; }\n\t\t\t\t.ql-undo, .ql-redo { width: 28px !important; }\n\t\t\t\t.ql-undo::after { content: \"↶\"; font-size: 18px; }\n\t\t\t\t.ql-redo::after { content: \"↷\"; font-size: 18px; }\n\t\t\t\t.ql-undo:disabled, .ql-redo:disabled { opacity: 0.3; cursor: not-allowed; }\n\t\t\t`}</style>\n\t\t\t<h2 style={{ margin: \"10px 0\" }}>Collaborative Formatted Text Editor</h2>\n\t\t\t<div\n\t\t\t\tref={editorRef}\n\t\t\t\tstyle={{\n\t\t\t\t\tflex: 1,\n\t\t\t\t\tminHeight: \"300px\",\n\t\t\t\t\tborder: \"1px solid #ccc\",\n\t\t\t\t\tborderRadius: \"4px\",\n\t\t\t\t}}\n\t\t\t/>\n\t\t\t{undoRedoButtons}\n\t\t</div>\n\t);\n});\nFormattedTextEditorView.displayName = \"FormattedTextEditorView\";\n"]}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { FormattedMainView, type FormattedMainViewProps, type FormattedEditorHandle, } from "./formatted/index.js";
6
+ export { PlainTextMainView, QuillMainView as PlainQuillView, type MainViewProps as PlainMainViewProps, } from "./plain/index.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/text/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,iBAAiB,EACjB,aAAa,IAAI,cAAc,EAC/B,KAAK,aAAa,IAAI,kBAAkB,GACxC,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { FormattedMainView, } from "./formatted/index.js";
6
+ export { PlainTextMainView, QuillMainView as PlainQuillView, } from "./plain/index.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/text/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,iBAAiB,GAGjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,iBAAiB,EACjB,aAAa,IAAI,cAAc,GAE/B,MAAM,kBAAkB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tFormattedMainView,\n\ttype FormattedMainViewProps,\n\ttype FormattedEditorHandle,\n} from \"./formatted/index.js\";\nexport {\n\tPlainTextMainView,\n\tQuillMainView as PlainQuillView,\n\ttype MainViewProps as PlainMainViewProps,\n} from \"./plain/index.js\";\n"]}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { MainView as PlainTextMainView } from "./plainTextView.js";
6
+ export { MainView as QuillMainView, type MainViewProps } from "./quillView.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/text/plain/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { MainView as PlainTextMainView } from "./plainTextView.js";
6
+ export { MainView as QuillMainView } from "./quillView.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/text/plain/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAsB,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { MainView as PlainTextMainView } from \"./plainTextView.js\";\nexport { MainView as QuillMainView, type MainViewProps } from \"./quillView.js\";\n"]}
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as React from "react";
6
+ import type { MainViewProps } from "./quillView.js";
7
+ /**
8
+ * A React component for plain text editing.
9
+ * @remarks
10
+ * Uses {@link @fluidframework/tree#TextAsTree.Tree} for the data-model and an HTML textarea for the UI.
11
+ * @internal
12
+ */
13
+ export declare const MainView: React.FC<MainViewProps>;
14
+ //# sourceMappingURL=plainTextView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plainTextView.d.ts","sourceRoot":"","sources":["../../../src/text/plain/plainTextView.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAE5C,CAAC"}
@@ -0,0 +1,75 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as React from "react";
6
+ import { withMemoizedTreeObservations } from "../../useTree.js";
7
+ import { syncTextToTree } from "./plainUtils.js";
8
+ /**
9
+ * A React component for plain text editing.
10
+ * @remarks
11
+ * Uses {@link @fluidframework/tree#TextAsTree.Tree} for the data-model and an HTML textarea for the UI.
12
+ * @internal
13
+ */
14
+ export const MainView = ({ root }) => {
15
+ return React.createElement(PlainTextEditorView, { root: root });
16
+ };
17
+ /**
18
+ * A plain text editor view component using a native HTML textarea.
19
+ * Uses TextAsTree for collaborative plain text storage.
20
+ *
21
+ * @remarks
22
+ * This uses withMemoizedTreeObservations to automatically re-render
23
+ * when the tree changes.
24
+ */
25
+ const PlainTextEditorView = withMemoizedTreeObservations(({ root }) => {
26
+ // Reference to the textarea element
27
+ const textareaRef = React.useRef(null);
28
+ // Guards against update loops between textarea and the tree
29
+ const isUpdatingRef = React.useRef(false);
30
+ // Access tree content during render to establish observation.
31
+ // The HOC will automatically re-render when this content changes.
32
+ const currentText = root.fullString();
33
+ // Handle textarea changes - sync textarea → tree
34
+ const handleChange = React.useCallback((event) => {
35
+ if (isUpdatingRef.current) {
36
+ return;
37
+ }
38
+ isUpdatingRef.current = true;
39
+ const newText = event.target.value;
40
+ syncTextToTree(root, newText);
41
+ isUpdatingRef.current = false;
42
+ }, [root]);
43
+ // Sync textarea when tree changes externally.
44
+ // We skip this if isUpdatingRef is true, meaning we caused the tree change ourselves
45
+ // via the handleChange above - in that case textarea already has the correct content.
46
+ if (textareaRef.current && !isUpdatingRef.current) {
47
+ const textareaValue = textareaRef.current.value;
48
+ // Only update if content actually differs (avoids cursor jump on local edits)
49
+ if (textareaValue !== currentText) {
50
+ isUpdatingRef.current = true;
51
+ // Preserve cursor position
52
+ const selectionStart = textareaRef.current.selectionStart;
53
+ const selectionEnd = textareaRef.current.selectionEnd;
54
+ textareaRef.current.value = currentText;
55
+ // Restore cursor position, clamped to new text length
56
+ const newPosition = Math.min(selectionStart, currentText.length);
57
+ const newEnd = Math.min(selectionEnd, currentText.length);
58
+ textareaRef.current.setSelectionRange(newPosition, newEnd);
59
+ isUpdatingRef.current = false;
60
+ }
61
+ }
62
+ return (React.createElement("div", { className: "text-editor-container", style: { height: "100%", display: "flex", flexDirection: "column" } },
63
+ React.createElement("h2", { style: { margin: "10px 0" } }, "Collaborative Text Editor"),
64
+ React.createElement("textarea", { ref: textareaRef, defaultValue: currentText, onChange: handleChange, placeholder: "Start typing...", style: {
65
+ flex: 1,
66
+ minHeight: "300px",
67
+ border: "1px solid #ccc",
68
+ borderRadius: "4px",
69
+ padding: "8px",
70
+ fontSize: "14px",
71
+ fontFamily: "inherit",
72
+ resize: "vertical",
73
+ } })));
74
+ });
75
+ //# sourceMappingURL=plainTextView.js.map