@fluidframework/react 2.90.0-378676 → 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,68 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { TextAsTree } from "@fluidframework/tree/internal";
7
+
8
+ /**
9
+ * Sync `newText` into the provided `root` tree.
10
+ */
11
+ export function syncTextToTree(root: TextAsTree.Tree, newText: string): void {
12
+ const sync = computeSync(root.charactersCopy(), [...newText]);
13
+
14
+ if (sync.remove) {
15
+ root.removeRange(sync.remove.start, sync.remove.end);
16
+ }
17
+ if (sync.insert) {
18
+ root.insertAt(sync.insert.location, sync.insert.slice.join(""));
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Sync `newText` into the provided `root` tree.
24
+ */
25
+ export function computeSync<T>(
26
+ existing: readonly T[],
27
+ final: readonly T[],
28
+ ): { remove?: { start: number; end: number }; insert?: { location: number; slice: T[] } } {
29
+ // Find common prefix and suffix to minimize changes
30
+
31
+ let prefixLength = 0;
32
+ while (
33
+ prefixLength < existing.length &&
34
+ prefixLength < final.length &&
35
+ existing[prefixLength] === final[prefixLength]
36
+ ) {
37
+ prefixLength++;
38
+ }
39
+
40
+ let suffixLength = 0;
41
+ while (
42
+ suffixLength + prefixLength < existing.length &&
43
+ suffixLength + prefixLength < final.length &&
44
+ existing[existing.length - 1 - suffixLength] === final[final.length - 1 - suffixLength]
45
+ ) {
46
+ suffixLength++;
47
+ }
48
+
49
+ // Locate middle replaced range in existing and final
50
+ const existingMiddleStart = prefixLength;
51
+ const existingMiddleEnd = existing.length - suffixLength;
52
+ const newMiddleStart = prefixLength;
53
+ const newMiddleEnd = final.length - suffixLength;
54
+
55
+ return {
56
+ remove:
57
+ existingMiddleStart < existingMiddleEnd
58
+ ? { start: existingMiddleStart, end: existingMiddleEnd }
59
+ : undefined,
60
+ insert:
61
+ newMiddleStart < newMiddleEnd
62
+ ? {
63
+ location: existingMiddleStart,
64
+ slice: final.slice(newMiddleStart, newMiddleEnd),
65
+ }
66
+ : undefined,
67
+ };
68
+ }
@@ -0,0 +1,149 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { TextAsTree } from "@fluidframework/tree/internal";
7
+ import Quill from "quill";
8
+ import * as React from "react";
9
+
10
+ import type { PropTreeNode } from "../../propNode.js";
11
+ import { withMemoizedTreeObservations } from "../../useTree.js";
12
+
13
+ import { syncTextToTree } from "./plainUtils.js";
14
+
15
+ /**
16
+ * Props for the MainView component.
17
+ * @input @internal
18
+ */
19
+ export interface MainViewProps {
20
+ root: PropTreeNode<TextAsTree.Tree>;
21
+ }
22
+
23
+ /**
24
+ * A React component for plain text editing.
25
+ * @remarks
26
+ * Uses {@link @fluidframework/tree#TextAsTree.Tree} for the data-model and Quill for the UI.
27
+ * @internal
28
+ */
29
+ export const MainView: React.FC<MainViewProps> = ({ root }) => {
30
+ return <TextEditorView root={root} />;
31
+ };
32
+
33
+ /**
34
+ * The text editor view component with Quill integration.
35
+ * Uses TextAsTree for collaborative plain text storage.
36
+ *
37
+ * @remarks
38
+ * This uses withMemoizedTreeObservations to automatically re-render
39
+ * when the tree changes.
40
+ */
41
+ const TextEditorView = withMemoizedTreeObservations(({ root }: { root: TextAsTree.Tree }) => {
42
+ // DOM element where Quill will mount its editor
43
+ const editorRef = React.useRef<HTMLDivElement>(null);
44
+ // Quill instance, persisted across renders to avoid re-initialization
45
+ const quillRef = React.useRef<Quill | null>(null);
46
+ // Guards against update loops between Quill and the tree
47
+ const isUpdatingRef = React.useRef<boolean>(false);
48
+
49
+ // Access tree content during render to establish observation.
50
+ // The HOC will automatically re-render when this content changes.
51
+ const currentText = root.fullString();
52
+
53
+ // Initialize Quill editor
54
+ React.useEffect(() => {
55
+ if (editorRef.current && !quillRef.current) {
56
+ const quill = new Quill(editorRef.current, {
57
+ placeholder: "Start typing...",
58
+ });
59
+
60
+ // Set initial content from tree (add trailing newline to match Quill's convention)
61
+ const initialText = root.fullString();
62
+ if (initialText.length > 0) {
63
+ const textWithNewline = initialText.endsWith("\n") ? initialText : `${initialText}\n`;
64
+ quill.setText(textWithNewline);
65
+ }
66
+
67
+ // Listen to local Quill changes
68
+ quill.on("text-change", (_delta, _oldDelta, source) => {
69
+ if (source === "user" && !isUpdatingRef.current) {
70
+ isUpdatingRef.current = true;
71
+
72
+ // Get plain text from Quill and preserve trailing newline
73
+ const newText = quill.getText();
74
+ // TODO: Consider using delta from Quill to compute a more minimal update,
75
+ // and maybe add a debugAssert that the delta actually gets the strings synchronized.
76
+ syncTextToTree(root, newText);
77
+
78
+ isUpdatingRef.current = false;
79
+ }
80
+ });
81
+
82
+ quillRef.current = quill;
83
+ }
84
+ // In React strict mode, effects run twice. The `!quillRef.current` check above
85
+ // makes the second call a no-op, preventing double-initialization of Quill.
86
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
+ }, []);
88
+
89
+ // Sync Quill when tree changes externally.
90
+ // We skip this if isUpdatingRef is true, meaning we caused the tree change ourselves
91
+ // via the text-change handler above - in that case Quill already has the correct content.
92
+ // No update is lost because isUpdatingRef is only true synchronously during our own
93
+ // handler execution, so Quill already reflects the change.
94
+ if (quillRef.current && !isUpdatingRef.current) {
95
+ const quillText = quillRef.current.getText();
96
+ // Normalize tree text to match Quill's trailing newline convention
97
+ const treeTextWithNewline = currentText.endsWith("\n") ? currentText : `${currentText}\n`;
98
+
99
+ // Only update if content actually differs (avoids cursor jump on local edits)
100
+ if (quillText !== treeTextWithNewline) {
101
+ isUpdatingRef.current = true;
102
+
103
+ const selection = quillRef.current.getSelection();
104
+ quillRef.current.setText(treeTextWithNewline);
105
+ if (selection) {
106
+ const length = quillRef.current.getLength();
107
+ const newPosition = Math.min(selection.index, length - 1);
108
+ quillRef.current.setSelection(newPosition, 0);
109
+ }
110
+
111
+ isUpdatingRef.current = false;
112
+ }
113
+ }
114
+
115
+ return (
116
+ <div
117
+ className="text-editor-container"
118
+ style={{ height: "100%", display: "flex", flexDirection: "column" }}
119
+ >
120
+ <style>
121
+ {`
122
+ .ql-container {
123
+ height: 100%;
124
+ font-size: 14px;
125
+ }
126
+ .ql-editor {
127
+ height: 100%;
128
+ outline: none;
129
+ }
130
+ .ql-editor.ql-blank::before {
131
+ color: #999;
132
+ font-style: italic;
133
+ }
134
+ `}
135
+ </style>
136
+ <h2 style={{ margin: "10px 0" }}>Collaborative Text Editor</h2>
137
+ <div
138
+ ref={editorRef}
139
+ style={{
140
+ flex: 1,
141
+ minHeight: "300px",
142
+ border: "1px solid #ccc",
143
+ borderRadius: "4px",
144
+ padding: "8px",
145
+ }}
146
+ />
147
+ </div>
148
+ );
149
+ });
@@ -0,0 +1,117 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { Listenable } from "@fluidframework/core-interfaces";
7
+ import {
8
+ CommitKind,
9
+ type CommitMetadata,
10
+ type Revertible,
11
+ type RevertibleFactory,
12
+ type TreeViewEvents,
13
+ } from "@fluidframework/tree";
14
+
15
+ /**
16
+ * Interface for undo/redo stack operations.
17
+ * @internal
18
+ */
19
+ export interface UndoRedo {
20
+ /**
21
+ * Reverts the most recent change. Only valid to call when {@link UndoRedo.canUndo} returns true.
22
+ * @throws Error if there is nothing to undo.
23
+ */
24
+ undo(): void;
25
+ /**
26
+ * Reapplies the most recently undone change. Only valid to call when {@link UndoRedo.canRedo} returns true.
27
+ * @throws Error if there is nothing to redo.
28
+ */
29
+ redo(): void;
30
+ dispose(): void;
31
+ canUndo(): boolean;
32
+ canRedo(): boolean;
33
+ /**
34
+ * Subscribe to state changes (when canUndo/canRedo may have changed).
35
+ * @param callback - Called when the undo/redo stack state changes
36
+ * @returns Unsubscribe function
37
+ */
38
+ onStateChange(callback: () => void): () => void;
39
+ }
40
+
41
+ /**
42
+ * Manages undo and redo stacks for a TreeView.
43
+ * Listens to commitApplied events and manages Revertible objects.
44
+ * @sealed @internal
45
+ */
46
+ export class UndoRedoStacks implements UndoRedo {
47
+ private readonly undoStack: Revertible[] = [];
48
+ private readonly redoStack: Revertible[] = [];
49
+ private readonly listeners = new Set<() => void>();
50
+ private readonly unsubscribe: () => void;
51
+
52
+ public constructor(events: Listenable<TreeViewEvents>) {
53
+ this.unsubscribe = events.on(
54
+ "commitApplied",
55
+ (commit: CommitMetadata, getRevertible?: RevertibleFactory) => {
56
+ if (getRevertible === undefined) return;
57
+ const revertible = getRevertible();
58
+ if (commit.kind === CommitKind.Undo) {
59
+ this.redoStack.push(revertible);
60
+ } else {
61
+ if (commit.kind === CommitKind.Default) {
62
+ for (const r of this.redoStack) r.dispose();
63
+ this.redoStack.length = 0;
64
+ }
65
+ this.undoStack.push(revertible);
66
+ }
67
+ this.notifyListeners();
68
+ },
69
+ );
70
+ }
71
+
72
+ public undo(): void {
73
+ const revertible = this.undoStack.pop();
74
+ if (revertible === undefined) {
75
+ throw new Error("Cannot undo: undo stack is empty.");
76
+ }
77
+ revertible.revert();
78
+ this.notifyListeners();
79
+ }
80
+
81
+ public redo(): void {
82
+ const revertible = this.redoStack.pop();
83
+ if (revertible === undefined) {
84
+ throw new Error("Cannot redo: redo stack is empty.");
85
+ }
86
+ revertible.revert();
87
+ this.notifyListeners();
88
+ }
89
+
90
+ public dispose(): void {
91
+ this.unsubscribe();
92
+ this.listeners.clear();
93
+ for (const r of this.undoStack) r.dispose();
94
+ for (const r of this.redoStack) r.dispose();
95
+ this.undoStack.length = 0;
96
+ this.redoStack.length = 0;
97
+ }
98
+
99
+ public canUndo(): boolean {
100
+ return this.undoStack.length > 0;
101
+ }
102
+
103
+ public canRedo(): boolean {
104
+ return this.redoStack.length > 0;
105
+ }
106
+
107
+ public onStateChange(callback: () => void): () => void {
108
+ this.listeners.add(callback);
109
+ return () => this.listeners.delete(callback);
110
+ }
111
+
112
+ private notifyListeners(): void {
113
+ for (const listener of this.listeners) {
114
+ listener();
115
+ }
116
+ }
117
+ }
package/tsconfig.json CHANGED
@@ -9,5 +9,11 @@
9
9
  "noUnusedLocals": false,
10
10
  // ES2021 needed for FinalizationRegistry
11
11
  "lib": ["ES2021", "DOM", "DOM.Iterable"],
12
+ // Suppress type errors in Quill's use of quill-delta.
13
+ // Without this, the quill code gives a lot of errors like:
14
+ // node_modules/.pnpm/quill@2.0.3/node_modules/quill/blots/block.d.ts:6:17 - error TS2709: Cannot use namespace 'Delta' as a type.
15
+ // These issues (and others, see imports of quill-delta) are likely related to quill-delta's export style not working well with node16 module resolution.
16
+ // Quill internally uses `"moduleResolution": "bundler"` which seems to work properly with quill-delta's exports, but would be inconsistent with the rest of this repo.
17
+ "skipLibCheck": true,
12
18
  },
13
19
  }
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
- "mainEntryPointFilePath": "<projectFolder>/dist/alpha.d.ts"
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
- "mainEntryPointFilePath": "<projectFolder>/dist/beta.d.ts"
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
- "mainEntryPointFilePath": "<projectFolder>/dist/public.d.ts"
5
- }
package/dist/alpha.d.ts DELETED
@@ -1,45 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- /*
7
- * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
8
- * Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
9
- */
10
-
11
- /**
12
- * Utilities for using SharedTree with React.
13
- * @packageDocumentation
14
- */
15
-
16
- export {
17
- // #region @alpha APIs
18
- IReactTreeDataObject,
19
- IsMappableObjectType,
20
- NodeRecord,
21
- ObservationOptions,
22
- PropTreeNode,
23
- PropTreeNodeRecord,
24
- PropTreeValue,
25
- SchemaIncompatibleProps,
26
- TreeViewComponent,
27
- TreeViewProps,
28
- UnwrapPropTreeNode,
29
- UnwrapPropTreeNodeRecord,
30
- WrapNodes,
31
- WrapPropTreeNodeRecord,
32
- objectIdNumber,
33
- toPropTreeNode,
34
- toPropTreeRecord,
35
- treeDataObject,
36
- unwrapPropTreeNode,
37
- unwrapPropTreeRecord,
38
- usePropTreeNode,
39
- usePropTreeRecord,
40
- useTree,
41
- useTreeObservations,
42
- withMemoizedTreeObservations,
43
- withTreeObservations
44
- // #endregion
45
- } from "./index.js";
package/dist/beta.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- /*
7
- * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
8
- * Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
9
- */
10
-
11
- /**
12
- * Utilities for using SharedTree with React.
13
- * @packageDocumentation
14
- */export {}
15
-
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- /**
6
- * Utilities for using SharedTree with React.
7
- * @packageDocumentation
8
- */
9
- export type { IReactTreeDataObject, TreeViewProps, SchemaIncompatibleProps, } from "./reactSharedTreeView.js";
10
- export { treeDataObject, treeDataObjectInternal, TreeViewComponent, } from "./reactSharedTreeView.js";
11
- export type { ObservationOptions } from "./useObservation.js";
12
- export type { NodeRecord, PropTreeNode, PropTreeNodeRecord, PropTreeValue, UnwrapPropTreeNode, UnwrapPropTreeNodeRecord, WrapPropTreeNodeRecord, WrapNodes, IsMappableObjectType, } from "./propNode.js";
13
- export { toPropTreeNode, toPropTreeRecord, unwrapPropTreeNode, unwrapPropTreeRecord, } from "./propNode.js";
14
- export { useTree, usePropTreeNode, usePropTreeRecord, useTreeObservations, withTreeObservations, withMemoizedTreeObservations, } from "./useTree.js";
15
- export { objectIdNumber } from "./simpleIdentifier.js";
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AAEH,YAAY,EACX,oBAAoB,EACpB,aAAa,EACb,uBAAuB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,YAAY,EACX,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,SAAS,EACT,oBAAoB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.objectIdNumber = exports.withMemoizedTreeObservations = exports.withTreeObservations = exports.useTreeObservations = exports.usePropTreeRecord = exports.usePropTreeNode = exports.useTree = exports.unwrapPropTreeRecord = exports.unwrapPropTreeNode = exports.toPropTreeRecord = exports.toPropTreeNode = exports.TreeViewComponent = exports.treeDataObjectInternal = exports.treeDataObject = void 0;
8
- var reactSharedTreeView_js_1 = require("./reactSharedTreeView.js");
9
- Object.defineProperty(exports, "treeDataObject", { enumerable: true, get: function () { return reactSharedTreeView_js_1.treeDataObject; } });
10
- Object.defineProperty(exports, "treeDataObjectInternal", { enumerable: true, get: function () { return reactSharedTreeView_js_1.treeDataObjectInternal; } });
11
- Object.defineProperty(exports, "TreeViewComponent", { enumerable: true, get: function () { return reactSharedTreeView_js_1.TreeViewComponent; } });
12
- var propNode_js_1 = require("./propNode.js");
13
- Object.defineProperty(exports, "toPropTreeNode", { enumerable: true, get: function () { return propNode_js_1.toPropTreeNode; } });
14
- Object.defineProperty(exports, "toPropTreeRecord", { enumerable: true, get: function () { return propNode_js_1.toPropTreeRecord; } });
15
- Object.defineProperty(exports, "unwrapPropTreeNode", { enumerable: true, get: function () { return propNode_js_1.unwrapPropTreeNode; } });
16
- Object.defineProperty(exports, "unwrapPropTreeRecord", { enumerable: true, get: function () { return propNode_js_1.unwrapPropTreeRecord; } });
17
- var useTree_js_1 = require("./useTree.js");
18
- Object.defineProperty(exports, "useTree", { enumerable: true, get: function () { return useTree_js_1.useTree; } });
19
- Object.defineProperty(exports, "usePropTreeNode", { enumerable: true, get: function () { return useTree_js_1.usePropTreeNode; } });
20
- Object.defineProperty(exports, "usePropTreeRecord", { enumerable: true, get: function () { return useTree_js_1.usePropTreeRecord; } });
21
- Object.defineProperty(exports, "useTreeObservations", { enumerable: true, get: function () { return useTree_js_1.useTreeObservations; } });
22
- Object.defineProperty(exports, "withTreeObservations", { enumerable: true, get: function () { return useTree_js_1.withTreeObservations; } });
23
- Object.defineProperty(exports, "withMemoizedTreeObservations", { enumerable: true, get: function () { return useTree_js_1.withMemoizedTreeObservations; } });
24
- var simpleIdentifier_js_1 = require("./simpleIdentifier.js");
25
- Object.defineProperty(exports, "objectIdNumber", { enumerable: true, get: function () { return simpleIdentifier_js_1.objectIdNumber; } });
26
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,mEAIkC;AAHjC,wHAAA,cAAc,OAAA;AACd,gIAAA,sBAAsB,OAAA;AACtB,2HAAA,iBAAiB,OAAA;AAclB,6CAKuB;AAJtB,6GAAA,cAAc,OAAA;AACd,+GAAA,gBAAgB,OAAA;AAChB,iHAAA,kBAAkB,OAAA;AAClB,mHAAA,oBAAoB,OAAA;AAErB,2CAOsB;AANrB,qGAAA,OAAO,OAAA;AACP,6GAAA,eAAe,OAAA;AACf,+GAAA,iBAAiB,OAAA;AACjB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,0HAAA,4BAA4B,OAAA;AAE7B,6DAAuD;AAA9C,qHAAA,cAAc,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Utilities for using SharedTree with React.\n * @packageDocumentation\n */\n\nexport type {\n\tIReactTreeDataObject,\n\tTreeViewProps,\n\tSchemaIncompatibleProps,\n} from \"./reactSharedTreeView.js\";\nexport {\n\ttreeDataObject,\n\ttreeDataObjectInternal,\n\tTreeViewComponent,\n} from \"./reactSharedTreeView.js\";\nexport type { ObservationOptions } from \"./useObservation.js\";\nexport type {\n\tNodeRecord,\n\tPropTreeNode,\n\tPropTreeNodeRecord,\n\tPropTreeValue,\n\tUnwrapPropTreeNode,\n\tUnwrapPropTreeNodeRecord,\n\tWrapPropTreeNodeRecord,\n\tWrapNodes,\n\tIsMappableObjectType,\n} from \"./propNode.js\";\nexport {\n\ttoPropTreeNode,\n\ttoPropTreeRecord,\n\tunwrapPropTreeNode,\n\tunwrapPropTreeRecord,\n} from \"./propNode.js\";\nexport {\n\tuseTree,\n\tusePropTreeNode,\n\tusePropTreeRecord,\n\tuseTreeObservations,\n\twithTreeObservations,\n\twithMemoizedTreeObservations,\n} from \"./useTree.js\";\nexport { objectIdNumber } from \"./simpleIdentifier.js\";\n"]}
package/dist/package.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "sideEffects": false
4
- }
@@ -1,114 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import type { ErasedType } from "@fluidframework/core-interfaces";
6
- import type { TreeNode, TreeLeafValue } from "@fluidframework/tree";
7
- /**
8
- * A type erased TreeNode for use in react props.
9
- * @remarks
10
- * Read content from the node using {@link usePropTreeNode} or {@link usePropTreeRecord}.
11
- *
12
- * In events where tracking dependencies is not required, the node can be unwrapped using {@link unwrapPropTreeNode}.
13
- *
14
- * To convert a TreeNode to this type use {@link toPropTreeNode} or {@link toPropTreeRecord}.
15
- * @alpha
16
- */
17
- export interface PropTreeNode<T extends TreeNode> extends ErasedType<[T, "PropTreeNode"]> {
18
- }
19
- /**
20
- * Type TreeNodes in T as {@link PropTreeNode}s.
21
- * @remarks
22
- * This only handles a few cases (TreeNode, structurally typed objects fields and arrays) and leaves other types as is.
23
- * Users which provide other types (e.g. maps) which contain TreeNodes will need to handle wrapping those themselves if the wrapping is desired.
24
- *
25
- * Users of this should not rely on a given use of TreeNode not being wrapped:
26
- * future changes to this API may add more cases which are wrapped, and this will be considered a non-breaking change.
27
- * @privateRemarks
28
- * Covering all cases is impossible, and trying to cover more with recursive mapped types can break some of the types by losing methods, private members, etc.
29
- * To mitigate this IsMappableObjectType is used for objects, and only mappable types, where the mapping actually impacted the type are modified.
30
- *
31
- * This is intended to cover the common cases, and users can handle other cases manually.
32
- * See the tests for this for more details.
33
- * @alpha
34
- */
35
- export type WrapNodes<T> = T extends TreeNode ? PropTreeNode<T> : T extends readonly (infer U)[] ? readonly WrapNodes<U>[] : T extends infer U ? IsMappableObjectType<U, {
36
- [P in keyof U]: WrapNodes<U[P]>;
37
- } extends U ? U : {
38
- [P in keyof U]: WrapNodes<U[P]>;
39
- }, T> : T;
40
- /**
41
- * Detect if a type is a simple structural object.
42
- * @remarks
43
- * This returns the true case if the type is entirely defined by its set of public properties.
44
- * More concretely, this indicates if creating a mapped type based on `T`
45
- * will be lossy due to details mapped types cannot access.
46
- *
47
- * This is shallow, and distributes over unions.
48
- *
49
- * This also returns the true case for primitive types since mapping over them leaves them unchanged if doing so in a generic context:
50
- * Mapping over a primitive does not leave them unchanged if done directly (not to a generic type parameter), but this can not detect that behavior.
51
- * This is fine as the use for this is to detect when making a mapped type from a generic type parameter would be lossy.
52
- * @system @alpha
53
- */
54
- export type IsMappableObjectType<T, True = true, False = false, Mapped = {
55
- [P in keyof T]: T[P];
56
- }> = [Mapped] extends [T] ? ([T] extends [Mapped] ? True : False) : False;
57
- /**
58
- * Casts a node from a {@link PropTreeNode} back to a TreeNode.
59
- * @remarks
60
- * This should only be done in scenarios where tracking observations is not required (such as event handlers),
61
- * or when taking care to handle invalidation manually.
62
- * @alpha
63
- */
64
- export declare function unwrapPropTreeNode<T extends TreeNode | TreeLeafValue>(propNode: PropTreeValue<T> | T): T;
65
- /**
66
- * {@link unwrapPropTreeNode} but for a {@link PropTreeNodeRecord}.
67
- * @alpha
68
- */
69
- export declare function unwrapPropTreeRecord<T extends PropTreeNodeRecord>(props: T): UnwrapPropTreeNodeRecord<T>;
70
- /**
71
- * {@inheritdoc unwrapPropTreeNode}
72
- * @alpha
73
- */
74
- export type UnwrapPropTreeNode<T extends TreeLeafValue | PropTreeNode<TreeNode> | undefined> = T extends PropTreeNode<infer Node> ? Node : T;
75
- /**
76
- * Record that can contain TreeNodes.
77
- * @alpha
78
- */
79
- export type NodeRecord = Record<string, TreeNode | TreeLeafValue>;
80
- /**
81
- * Type erase `TreeNode`s from a {@link NodeRecord} as a {@link PropTreeNode}.
82
- * @alpha
83
- */
84
- export type WrapPropTreeNodeRecord<T extends NodeRecord> = {
85
- readonly [P in keyof T]: PropTreeValue<T[P]>;
86
- };
87
- /**
88
- * Type erase `TreeNode`s from a {@link NodeRecord} as a {@link PropTreeNode}.
89
- * @alpha
90
- */
91
- export type UnwrapPropTreeNodeRecord<T extends PropTreeNodeRecord> = {
92
- readonly [P in keyof T]: UnwrapPropTreeNode<T[P]>;
93
- };
94
- /**
95
- * Type erase `TreeNode`s from a {@link NodeRecord} as a {@link PropTreeNode}.
96
- * @alpha
97
- */
98
- export type PropTreeNodeRecord = Record<string, TreeLeafValue | PropTreeNode<TreeNode> | undefined>;
99
- /**
100
- * Type erase a `TreeNode` from a `TreeNode | TreeLeafValue` as a {@link PropTreeNode}.
101
- * @alpha
102
- */
103
- export type PropTreeValue<T extends TreeNode | TreeLeafValue | undefined> = T extends TreeNode ? PropTreeNode<T> : T;
104
- /**
105
- * Type erase a TreeNode as a {@link PropTreeNode}.
106
- * @alpha
107
- */
108
- export declare function toPropTreeNode<T extends TreeNode | TreeLeafValue>(node: T): PropTreeValue<T>;
109
- /**
110
- * Type erase a {@link NodeRecord} as a {@link PropTreeNodeRecord}.
111
- * @alpha
112
- */
113
- export declare function toPropTreeRecord<T extends NodeRecord>(node: T): WrapPropTreeNodeRecord<T>;
114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H,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,GAAG,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAE5F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAEzF"}
package/dist/propNode.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.toPropTreeRecord = exports.toPropTreeNode = exports.unwrapPropTreeRecord = exports.unwrapPropTreeNode = void 0;
8
- /**
9
- * Casts a node from a {@link PropTreeNode} back to a TreeNode.
10
- * @remarks
11
- * This should only be done in scenarios where tracking observations is not required (such as event handlers),
12
- * or when taking care to handle invalidation manually.
13
- * @alpha
14
- */
15
- function unwrapPropTreeNode(propNode) {
16
- return propNode;
17
- }
18
- exports.unwrapPropTreeNode = unwrapPropTreeNode;
19
- /**
20
- * {@link unwrapPropTreeNode} but for a {@link PropTreeNodeRecord}.
21
- * @alpha
22
- */
23
- function unwrapPropTreeRecord(props) {
24
- return props;
25
- }
26
- exports.unwrapPropTreeRecord = unwrapPropTreeRecord;
27
- /**
28
- * Type erase a TreeNode as a {@link PropTreeNode}.
29
- * @alpha
30
- */
31
- function toPropTreeNode(node) {
32
- return node;
33
- }
34
- exports.toPropTreeNode = toPropTreeNode;
35
- /**
36
- * Type erase a {@link NodeRecord} as a {@link PropTreeNodeRecord}.
37
- * @alpha
38
- */
39
- function toPropTreeRecord(node) {
40
- return node;
41
- }
42
- exports.toPropTreeRecord = toPropTreeRecord;
43
- //# sourceMappingURL=propNode.js.map