@fluidframework/react 2.90.0-378676 → 2.91.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 (112) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -0
  3. package/api-report/react.alpha.api.md +8 -8
  4. package/lib/index.d.ts +2 -0
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +2 -0
  7. package/lib/index.js.map +1 -1
  8. package/lib/propNode.js.map +1 -1
  9. package/lib/reactSharedTreeView.d.ts +6 -6
  10. package/lib/reactSharedTreeView.d.ts.map +1 -1
  11. package/lib/reactSharedTreeView.js +16 -18
  12. package/lib/reactSharedTreeView.js.map +1 -1
  13. package/lib/test/mochaHooks.js +13 -0
  14. package/lib/test/mochaHooks.js.map +1 -0
  15. package/lib/test/reactSharedTreeView.spec.js +3 -3
  16. package/lib/test/reactSharedTreeView.spec.js.map +1 -1
  17. package/lib/test/text/plainUtils.test.js +75 -0
  18. package/lib/test/text/plainUtils.test.js.map +1 -0
  19. package/lib/test/text/textEditor.test.js +760 -0
  20. package/lib/test/text/textEditor.test.js.map +1 -0
  21. package/lib/test/undoRedo.test.js +62 -0
  22. package/lib/test/undoRedo.test.js.map +1 -0
  23. package/lib/test/useObservation.spec.js +8 -9
  24. package/lib/test/useObservation.spec.js.map +1 -1
  25. package/lib/test/useTree.spec.js +15 -16
  26. package/lib/test/useTree.spec.js.map +1 -1
  27. package/lib/text/formatted/index.d.ts +6 -0
  28. package/lib/text/formatted/index.d.ts.map +1 -0
  29. package/lib/text/formatted/index.js +6 -0
  30. package/lib/text/formatted/index.js.map +1 -0
  31. package/lib/text/formatted/quillFormattedView.d.ts +66 -0
  32. package/lib/text/formatted/quillFormattedView.d.ts.map +1 -0
  33. package/lib/text/formatted/quillFormattedView.js +520 -0
  34. package/lib/text/formatted/quillFormattedView.js.map +1 -0
  35. package/lib/text/index.d.ts +7 -0
  36. package/lib/text/index.d.ts.map +1 -0
  37. package/lib/text/index.js +7 -0
  38. package/lib/text/index.js.map +1 -0
  39. package/lib/text/plain/index.d.ts +7 -0
  40. package/lib/text/plain/index.d.ts.map +1 -0
  41. package/lib/text/plain/index.js +7 -0
  42. package/lib/text/plain/index.js.map +1 -0
  43. package/lib/text/plain/plainTextView.d.ts +14 -0
  44. package/lib/text/plain/plainTextView.d.ts.map +1 -0
  45. package/lib/text/plain/plainTextView.js +70 -0
  46. package/lib/text/plain/plainTextView.js.map +1 -0
  47. package/lib/text/plain/plainUtils.d.ts +23 -0
  48. package/lib/text/plain/plainUtils.d.ts.map +1 -0
  49. package/lib/text/plain/plainUtils.js +51 -0
  50. package/lib/text/plain/plainUtils.js.map +1 -0
  51. package/lib/text/plain/quillView.d.ts +22 -0
  52. package/lib/text/plain/quillView.d.ts.map +1 -0
  53. package/lib/text/plain/quillView.js +106 -0
  54. package/lib/text/plain/quillView.js.map +1 -0
  55. package/lib/undoRedo.d.ts +51 -0
  56. package/lib/undoRedo.d.ts.map +1 -0
  57. package/lib/undoRedo.js +76 -0
  58. package/lib/undoRedo.js.map +1 -0
  59. package/lib/useObservation.js +6 -6
  60. package/lib/useObservation.js.map +1 -1
  61. package/lib/useTree.d.ts +7 -7
  62. package/lib/useTree.d.ts.map +1 -1
  63. package/lib/useTree.js +6 -6
  64. package/lib/useTree.js.map +1 -1
  65. package/package.json +28 -46
  66. package/react.test-files.tar +0 -0
  67. package/src/index.ts +10 -0
  68. package/src/propNode.ts +1 -1
  69. package/src/reactSharedTreeView.tsx +11 -13
  70. package/src/text/formatted/index.ts +11 -0
  71. package/src/text/formatted/quillFormattedView.tsx +627 -0
  72. package/src/text/index.ts +15 -0
  73. package/src/text/plain/index.ts +7 -0
  74. package/src/text/plain/plainTextView.tsx +110 -0
  75. package/src/text/plain/plainUtils.ts +68 -0
  76. package/src/text/plain/quillView.tsx +149 -0
  77. package/src/undoRedo.ts +117 -0
  78. package/src/useObservation.ts +6 -6
  79. package/src/useTree.ts +19 -12
  80. package/tsconfig.json +6 -0
  81. package/api-extractor/api-extractor-lint-alpha.cjs.json +0 -5
  82. package/api-extractor/api-extractor-lint-beta.cjs.json +0 -5
  83. package/api-extractor/api-extractor-lint-public.cjs.json +0 -5
  84. package/dist/alpha.d.ts +0 -45
  85. package/dist/beta.d.ts +0 -15
  86. package/dist/index.d.ts +0 -16
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/index.js +0 -26
  89. package/dist/index.js.map +0 -1
  90. package/dist/package.json +0 -4
  91. package/dist/propNode.d.ts +0 -114
  92. package/dist/propNode.d.ts.map +0 -1
  93. package/dist/propNode.js +0 -43
  94. package/dist/propNode.js.map +0 -1
  95. package/dist/public.d.ts +0 -15
  96. package/dist/reactSharedTreeView.d.ts +0 -119
  97. package/dist/reactSharedTreeView.d.ts.map +0 -1
  98. package/dist/reactSharedTreeView.js +0 -206
  99. package/dist/reactSharedTreeView.js.map +0 -1
  100. package/dist/simpleIdentifier.d.ts +0 -19
  101. package/dist/simpleIdentifier.d.ts.map +0 -1
  102. package/dist/simpleIdentifier.js +0 -33
  103. package/dist/simpleIdentifier.js.map +0 -1
  104. package/dist/useObservation.d.ts +0 -83
  105. package/dist/useObservation.d.ts.map +0 -1
  106. package/dist/useObservation.js +0 -295
  107. package/dist/useObservation.js.map +0 -1
  108. package/dist/useTree.d.ts +0 -80
  109. package/dist/useTree.d.ts.map +0 -1
  110. package/dist/useTree.js +0 -137
  111. package/dist/useTree.js.map +0 -1
  112. package/tsconfig.cjs.json +0 -7
package/dist/useTree.js DELETED
@@ -1,137 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.usePropTreeRecord = exports.usePropTreeNode = exports.useTreeObservations = exports.withMemoizedTreeObservations = exports.withTreeObservations = exports.useTree = void 0;
31
- const tree_1 = require("@fluidframework/tree");
32
- const internal_1 = require("@fluidframework/tree/internal");
33
- const React = __importStar(require("react"));
34
- const propNode_js_1 = require("./propNode.js");
35
- const useObservation_js_1 = require("./useObservation.js");
36
- /**
37
- * Custom hook which invalidates a React Component when there is a change in the subtree defined by `subtreeRoot`.
38
- * This includes changes to the tree's content, but not changes to its parentage.
39
- * See {@link @fluidframework/tree#TreeChangeEvents.treeChanged} for details.
40
- * @remarks
41
- * Consider using {@link useTreeObservations} instead which tracks what was observed and only invalidates if it changes.
42
- * @alpha
43
- */
44
- function useTree(subtreeRoot) {
45
- // Use a React effect hook to invalidate this component when the subtreeRoot changes.
46
- // We do this by incrementing a counter, which is passed as a dependency to the effect hook.
47
- const [invalidations, setInvalidations] = React.useState(0);
48
- // React effect hook that increments the 'invalidation' counter whenever subtreeRoot or any of its children change.
49
- React.useEffect(() => {
50
- // Returns the cleanup function to be invoked when the component unmounts.
51
- return tree_1.Tree.on(subtreeRoot, "treeChanged", () => {
52
- setInvalidations((i) => i + 1);
53
- });
54
- }, [invalidations, subtreeRoot]);
55
- return invalidations;
56
- }
57
- exports.useTree = useTree;
58
- /**
59
- * Higher order component which wraps a component to use {@link useTreeObservations}.
60
- *
61
- * @remarks
62
- * When passing TreeNodes in props, care must be taken to not observe their content outside of a context which does observation tracking (or manual invalidation).
63
- * This wraps a component in such tracking.
64
- *
65
- * It is recommended that sub-components which take in TreeNodes, if not defined using this higher order components, take the nodes in as {@link PropTreeNode}s.
66
- * Components defined using this higher order component can take in either raw TreeNodes or {@link PropTreeNode}s: the latter will be automatically unwrapped.
67
- * @privateRemarks
68
- * `React.FC` does not seem to be covariant over its input type, so to make use of this more ergonomic,
69
- * the return type intersects the various ways this could be used (with or without PropTreeNode wrapping).
70
- * @alpha
71
- */
72
- function withTreeObservations(component, options) {
73
- return (props) => useTreeObservations(() => component(props), options);
74
- }
75
- exports.withTreeObservations = withTreeObservations;
76
- /**
77
- * {@link withTreeObservations} wrapped with React.memo.
78
- * @remarks
79
- * There is no special logic here, just a convenience wrapper.
80
- * @alpha
81
- */
82
- function withMemoizedTreeObservations(component, options) {
83
- return React.memo(withTreeObservations(component, options), options?.propsAreEqual);
84
- }
85
- exports.withMemoizedTreeObservations = withMemoizedTreeObservations;
86
- /**
87
- * Custom hook which invalidates a React Component when there is a change in tree content observed during `trackDuring`.
88
- *
89
- * @param trackDuring - Called synchronously, and will have its tree observations tracked.
90
- *
91
- * @remarks
92
- * This includes changes to the tree's content.
93
- * Currently this will throw if observing a node's parentage to be undefined,
94
- * and node status changes will not cause invalidation.
95
- *
96
- * For additional type safety to help avoid observing TreeNode content outside of this hook, see {@link PropTreeNode}.
97
- * @alpha
98
- */
99
- function useTreeObservations(trackDuring, options) {
100
- return (0, useObservation_js_1.useObservation)((invalidate) => internal_1.TreeAlpha.trackObservationsOnce(invalidate, trackDuring), options);
101
- }
102
- exports.useTreeObservations = useTreeObservations;
103
- /**
104
- * Custom hook for using a prop tree node.
105
- *
106
- * @param propNode - Input, automatically unwrapped TreeNode from a {@link PropTreeNode} if needed.
107
- * @param trackDuring - Callback which reads from the node and returns a result.
108
- * If the result is a TreeNode or {@link NodeRecord} it will be wrapped as a {@link PropTreeNode} or {@link PropTreeNodeRecord}, see {@link WrapNodes}.
109
- *
110
- * It is recommended that when returning data containing TreeNodes,
111
- * use a format supported by {@link WrapNodes} or wrap the nodes manually using {@link toPropTreeNode}.
112
- * This improves the type safety, reducing the risk of invalidation bugs due to untracked access of tree content contained in the return value.
113
- *
114
- * Note that is is fine to observe any node inside the callback, not just the provided node: all accesses will be tracked.
115
- * The input node is just provided as a way to automatically unwrap the {@link PropTreeNode}
116
- *
117
- * @remarks
118
- * Reads content using {@link useTreeObservations} to track dependencies.
119
- * @alpha
120
- */
121
- function usePropTreeNode(propNode, trackDuring) {
122
- const node = (0, propNode_js_1.unwrapPropTreeNode)(propNode);
123
- const result = useTreeObservations(() => trackDuring(node));
124
- return result;
125
- }
126
- exports.usePropTreeNode = usePropTreeNode;
127
- /**
128
- * {@link usePropTreeNode} but takes in a {@link PropTreeNodeRecord}.
129
- * @alpha
130
- */
131
- function usePropTreeRecord(props, f) {
132
- const record = (0, propNode_js_1.unwrapPropTreeRecord)(props);
133
- const result = useTreeObservations(() => f(record));
134
- return result;
135
- }
136
- exports.usePropTreeRecord = usePropTreeRecord;
137
- //# sourceMappingURL=useTree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTree.js","sourceRoot":"","sources":["../src/useTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,+CAA4C;AAC5C,4DAA0D;AAC1D,6CAA+B;AAE/B,+CAOuB;AACvB,2DAA8E;AAE9E;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,WAAqB;IAC5C,qFAAqF;IACrF,4FAA4F;IAC5F,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5D,mHAAmH;IACnH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;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;AATD,0CASC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAChC,KAAQ,EACR,CAAiD;IAEjD,MAAM,MAAM,GAAG,IAAA,kCAAoB,EAAC,KAAK,CAAC,CAAC;IAE3C,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpD,OAAO,MAA4B,CAAC;AACrC,CAAC;AATD,8CASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeLeafValue, TreeNode } from \"@fluidframework/tree\";\nimport { Tree } from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/internal\";\nimport * as React from \"react\";\n\nimport {\n\tunwrapPropTreeNode,\n\tunwrapPropTreeRecord,\n\ttype PropTreeNodeRecord,\n\ttype PropTreeValue,\n\ttype UnwrapPropTreeNodeRecord,\n\ttype WrapNodes,\n} from \"./propNode.js\";\nimport { useObservation, type ObservationOptions } from \"./useObservation.js\";\n\n/**\n * Custom hook which invalidates a React Component when there is a change in the subtree defined by `subtreeRoot`.\n * This includes changes to the tree's content, but not changes to its parentage.\n * See {@link @fluidframework/tree#TreeChangeEvents.treeChanged} for details.\n * @remarks\n * Consider using {@link useTreeObservations} instead which tracks what was observed and only invalidates if it changes.\n * @alpha\n */\nexport function useTree(subtreeRoot: TreeNode): number {\n\t// Use a React effect hook to invalidate this component when the subtreeRoot changes.\n\t// We do this by incrementing a counter, which is passed as a dependency to the effect hook.\n\tconst [invalidations, setInvalidations] = React.useState(0);\n\n\t// React effect hook that increments the 'invalidation' counter whenever subtreeRoot or any of its children change.\n\tReact.useEffect(() => {\n\t\t// Returns the cleanup function to be invoked when the component unmounts.\n\t\treturn Tree.on(subtreeRoot, \"treeChanged\", () => {\n\t\t\tsetInvalidations((i) => i + 1);\n\t\t});\n\t}, [invalidations, subtreeRoot]);\n\n\treturn invalidations;\n}\n\n/**\n * Higher order component which wraps a component to use {@link useTreeObservations}.\n *\n * @remarks\n * When passing TreeNodes in props, care must be taken to not observe their content outside of a context which does observation tracking (or manual invalidation).\n * This wraps a component in such tracking.\n *\n * It is recommended that sub-components which take in TreeNodes, if not defined using this higher order components, take the nodes in as {@link PropTreeNode}s.\n * Components defined using this higher order component can take in either raw TreeNodes or {@link PropTreeNode}s: the latter will be automatically unwrapped.\n * @privateRemarks\n * `React.FC` does not seem to be covariant over its input type, so to make use of this more ergonomic,\n * the return type intersects the various ways this could be used (with or without PropTreeNode wrapping).\n * @alpha\n */\nexport function withTreeObservations<TIn>(\n\tcomponent: React.FC<TIn>,\n\toptions?: ObservationOptions,\n): React.FC<TIn> & React.FC<WrapNodes<TIn>> & React.FC<TIn | WrapNodes<TIn>> {\n\treturn (props: TIn | WrapNodes<TIn>): React.ReactNode =>\n\t\tuseTreeObservations(() => component(props as TIn), options);\n}\n\n/**\n * {@link withTreeObservations} wrapped with React.memo.\n * @remarks\n * There is no special logic here, just a convenience wrapper.\n * @alpha\n */\nexport function withMemoizedTreeObservations<TIn>(\n\tcomponent: React.FC<TIn>,\n\toptions?: ObservationOptions & {\n\t\treadonly propsAreEqual?: Parameters<typeof React.memo>[1];\n\t},\n): React.MemoExoticComponent<ReturnType<typeof withTreeObservations<TIn>>> {\n\treturn React.memo(withTreeObservations(component, options), options?.propsAreEqual);\n}\n\n/**\n * Custom hook which invalidates a React Component when there is a change in tree content observed during `trackDuring`.\n *\n * @param trackDuring - Called synchronously, and will have its tree observations tracked.\n *\n * @remarks\n * This includes changes to the tree's content.\n * Currently this will throw if observing a node's parentage to be undefined,\n * and node status changes will not cause invalidation.\n *\n * For additional type safety to help avoid observing TreeNode content outside of this hook, see {@link PropTreeNode}.\n * @alpha\n */\nexport function useTreeObservations<TResult>(\n\ttrackDuring: () => TResult,\n\toptions?: ObservationOptions,\n): TResult {\n\treturn useObservation(\n\t\t(invalidate) => TreeAlpha.trackObservationsOnce(invalidate, trackDuring),\n\t\toptions,\n\t);\n}\n\n/**\n * Custom hook for using a prop tree node.\n *\n * @param propNode - Input, automatically unwrapped TreeNode from a {@link PropTreeNode} if needed.\n * @param trackDuring - Callback which reads from the node and returns a result.\n * If the result is a TreeNode or {@link NodeRecord} it will be wrapped as a {@link PropTreeNode} or {@link PropTreeNodeRecord}, see {@link WrapNodes}.\n *\n * It is recommended that when returning data containing TreeNodes,\n * use a format supported by {@link WrapNodes} or wrap the nodes manually using {@link toPropTreeNode}.\n * This improves the type safety, reducing the risk of invalidation bugs due to untracked access of tree content contained in the return value.\n *\n * Note that is is fine to observe any node inside the callback, not just the provided node: all accesses will be tracked.\n * The input node is just provided as a way to automatically unwrap the {@link PropTreeNode}\n *\n * @remarks\n * Reads content using {@link useTreeObservations} to track dependencies.\n * @alpha\n */\nexport function usePropTreeNode<T extends TreeNode | TreeLeafValue, TResult>(\n\tpropNode: PropTreeValue<T> | T,\n\ttrackDuring: (node: T) => TResult,\n): WrapNodes<TResult> {\n\tconst node: T = unwrapPropTreeNode(propNode);\n\n\tconst result = useTreeObservations(() => trackDuring(node));\n\n\treturn result as WrapNodes<TResult>;\n}\n\n/**\n * {@link usePropTreeNode} but takes in a {@link PropTreeNodeRecord}.\n * @alpha\n */\nexport function usePropTreeRecord<const T extends PropTreeNodeRecord, TResult>(\n\tprops: T,\n\tf: (node: UnwrapPropTreeNodeRecord<T>) => TResult,\n): WrapNodes<TResult> {\n\tconst record = unwrapPropTreeRecord(props);\n\n\tconst result = useTreeObservations(() => f(record));\n\n\treturn result as WrapNodes<TResult>;\n}\n"]}
package/tsconfig.cjs.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- // This config must be used in a "type": "commonjs" environment. (Use `fluid-tsc commonjs`.)
3
- "extends": "./tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "./dist",
6
- },
7
- }