platejs 54.0.0-beta.2 → 54.0.0-beta.3

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 (237) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +56 -0
  3. package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DY104TqL.d.ts} +2 -2
  4. package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-Deo6n6Fs.d.ts} +7 -3
  5. package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-CJX5bKuv.d.ts} +7 -7
  6. package/dist/ai/index.d.ts +1 -1
  7. package/dist/ai/react/AIChatPlugin.js +113 -78
  8. package/dist/ai/react/CopilotPlugin.js +1 -1
  9. package/dist/ai/react/index.d.ts +23 -16
  10. package/dist/authored/index.d.ts +4 -4
  11. package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
  12. package/dist/code-block/codemirror/index.d.ts +1 -1
  13. package/dist/{combobox-DkBGgyd3.d.ts → combobox-DAOYWuvC.d.ts} +2 -2
  14. package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-Dt-unJZY-DCddmbSD.d.ts} +10 -2
  15. package/dist/compiler/index.d.ts +2 -2
  16. package/dist/{core-BJG8l_mk.d.ts → core-ClHasORr.d.ts} +433 -95
  17. package/dist/diff/index.d.ts +2 -2
  18. package/dist/docs/ai.md +4 -3
  19. package/dist/docs/api/core/plate-components.md +0 -19
  20. package/dist/docs/api/core/plate-controller.md +4 -2
  21. package/dist/docs/api/core/plate-plugin.md +3 -0
  22. package/dist/docs/api/core/plate-store.md +3 -3
  23. package/dist/docs/api/dom.md +14 -4
  24. package/dist/docs/api/editor-transforms.md +2 -1
  25. package/dist/docs/api/react-hooks.md +25 -11
  26. package/dist/docs/authored-changes.md +5 -2
  27. package/dist/docs/basic-blocks.md +42 -29
  28. package/dist/docs/blockquote.md +5 -3
  29. package/dist/docs/board.md +63 -8
  30. package/dist/docs/code-block.md +47 -0
  31. package/dist/docs/discussion.md +1 -1
  32. package/dist/docs/docx.md +1 -1
  33. package/dist/docs/dom-coverage.md +5 -0
  34. package/dist/docs/examples/editable-voids.md +2 -3
  35. package/dist/docs/external-text.md +2 -0
  36. package/dist/docs/field.md +370 -0
  37. package/dist/docs/find.md +9 -6
  38. package/dist/docs/form.md +2 -0
  39. package/dist/docs/heading.md +6 -0
  40. package/dist/docs/installation/manual.md +0 -4
  41. package/dist/docs/link.md +3 -3
  42. package/dist/docs/llms.txt +4 -2
  43. package/dist/docs/markdown.md +176 -8
  44. package/dist/docs/plugin-components.md +13 -10
  45. package/dist/docs/plugin-input-rules.md +4 -12
  46. package/dist/docs/prompt-editor.md +205 -0
  47. package/dist/docs/roots.md +8 -6
  48. package/dist/docs/rtl.md +6 -4
  49. package/dist/docs/selection.md +7 -4
  50. package/dist/docs/suggestion.md +1 -1
  51. package/dist/docs/toolbar.md +26 -30
  52. package/dist/docs/upload.md +106 -17
  53. package/dist/docx/export/index.d.ts +3 -3
  54. package/dist/docx/export/lib/docxStaticComponents.js +12 -2
  55. package/dist/docx/export/lib/exportDocx.js +29 -5
  56. package/dist/docx/export/lib/reviewPart.js +1 -1
  57. package/dist/docx/export/lib/reviewProjection.js +10 -8
  58. package/dist/docx/import/index.d.ts +4 -4
  59. package/dist/docx/paste/index.d.ts +4 -4
  60. package/dist/dom/index.d.ts +1 -6
  61. package/dist/dom/plite-dom.internal.js +2 -2
  62. package/dist/excalidraw/index.d.ts +3 -2
  63. package/dist/excalidraw/react/index.d.ts +3 -2
  64. package/dist/facade.js +2 -2
  65. package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
  66. package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
  67. package/dist/features/board/index.d.ts +2 -2
  68. package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
  69. package/dist/features/board/lib/boardStroke.internal.js +13 -1
  70. package/dist/features/board/lib/boardTypes.internal.js +16 -0
  71. package/dist/features/callout/index.d.ts +3 -2
  72. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
  73. package/dist/features/combobox/index.d.ts +2 -2
  74. package/dist/features/comments/index.d.ts +1 -1
  75. package/dist/features/date/index.d.ts +3 -2
  76. package/dist/features/details/index.d.ts +3 -2
  77. package/dist/features/details/lib/BaseDetailsPlugin.js +10 -10
  78. package/dist/features/field/index.d.ts +2 -0
  79. package/dist/features/field/index.js +2 -0
  80. package/dist/features/field/lib/BaseFieldPlugin.js +414 -0
  81. package/dist/features/field/lib/fieldRules.internal.js +42 -0
  82. package/dist/features/find/index.d.ts +3 -2
  83. package/dist/features/footnote/index.d.ts +1 -1
  84. package/dist/features/ink/index.d.ts +1 -1
  85. package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
  86. package/dist/features/ink/lib/inkCodec.internal.js +130 -0
  87. package/dist/features/ink/lib/inkGone.internal.js +229 -48
  88. package/dist/features/ink/lib/inkPlaces.internal.js +533 -62
  89. package/dist/features/layout/index.d.ts +1 -1
  90. package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
  91. package/dist/features/lint/index.d.ts +3 -2
  92. package/dist/features/media/index.d.ts +1 -1
  93. package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
  94. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +6 -2
  95. package/dist/features/mention/index.d.ts +5 -4
  96. package/dist/features/suggestion/index.d.ts +1 -1
  97. package/dist/features/table/index.d.ts +1 -1
  98. package/dist/features/table/lib/BaseTablePlugin.js +14 -8
  99. package/dist/features/table/lib/internal/selection.js +4 -2
  100. package/dist/features/toc/index.d.ts +1 -1
  101. package/dist/features/upload/index.d.ts +2 -2
  102. package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
  103. package/dist/history/index.d.ts +2 -2
  104. package/dist/html/index.d.ts +3 -3
  105. package/dist/html/server/index.d.ts +1 -1
  106. package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-cg_cWsaN.d.ts} +2 -31
  107. package/dist/hyperscript/index.d.ts +1 -1
  108. package/dist/{index-D1CFXA-i.d.ts → index-8WO2vI0U.d.ts} +475 -143
  109. package/dist/{index-DaM37gF6.d.ts → index-B5mYEawV.d.ts} +37 -21
  110. package/dist/{index-Bq3sdm3S.d.ts → index-BZWFoUXt.d.ts} +5 -4
  111. package/dist/{index-DdIRduDG.d.ts → index-C0POz7rg.d.ts} +3 -2
  112. package/dist/{index-Bxfvicyy.d.ts → index-C1_JIhL4.d.ts} +4 -3
  113. package/dist/{index-DC_MNGyu.d.ts → index-C35V_hj0.d.ts} +3 -3
  114. package/dist/{index-kLKMc-pI.d.ts → index-C6ql9pKw.d.ts} +2 -2
  115. package/dist/{index-hsC_sOn2.d.ts → index-C9DiGDVj.d.ts} +35 -5
  116. package/dist/{index-DTgaSxKr.d.ts → index-CLsEe3LY.d.ts} +40 -4
  117. package/dist/{index-CT7miqQN.d.ts → index-CdOLsPaW.d.ts} +29 -9
  118. package/dist/{index-DLA2DUR2.d.ts → index-CktYvOgk.d.ts} +4 -3
  119. package/dist/{index-BBKGrsG3.d.ts → index-Cmuluh6f.d.ts} +1 -1
  120. package/dist/{index-BiQerPJS.d.ts → index-CzLwBZpY.d.ts} +2 -2
  121. package/dist/{index-DzD6BIFJ.d.ts → index-D3-2iM1b.d.ts} +7 -5
  122. package/dist/{index-Cl77E9yr.d.ts → index-DKOFvteF.d.ts} +2 -2
  123. package/dist/{index-iaZOhA76.d.ts → index-DPWyk3lG-DOYwohXO.d.ts} +1 -1
  124. package/dist/index-DQnjqtQa.d.ts +678 -0
  125. package/dist/{index-CcZbqPqk.d.ts → index-Do9pj1GK.d.ts} +73 -39
  126. package/dist/{index-BU6k1Aev.d.ts → index-DpltOCot-A2b3p3Eb.d.ts} +4735 -4586
  127. package/dist/{index-Bc2Yg_2j.d.ts → index-HPYawTae-BCUQLEWF.d.ts} +2 -2
  128. package/dist/{index-BkR7-GLI.d.ts → index-baQOK89E.d.ts} +2 -2
  129. package/dist/{index-D5W-p9bS.d.ts → index-oIJAZxc2.d.ts} +49 -4
  130. package/dist/{index-xdmCBvlT.d.ts → index-r7yb77Wy.d.ts} +3 -2
  131. package/dist/index.d.ts +4 -4
  132. package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
  133. package/dist/internal/plugin/OverridePlugin.js +101 -119
  134. package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
  135. package/dist/internal/plugin/pastedUploadFiles.js +4 -0
  136. package/dist/internal/plugin/resolvePlugin.js +1 -1
  137. package/dist/internal/plugin/resolvePlugins.js +3 -0
  138. package/dist/internal/plugin/uploadDrafts.js +6 -0
  139. package/dist/internal/utils/mergePlugins.js +1 -0
  140. package/dist/lib/plugins/element-id/ElementIdPlugin.js +8 -2
  141. package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
  142. package/dist/lib/plugins/html/htmlSafety.js +1 -1
  143. package/dist/lib/plugins/input-rules/InputRulesPlugin.js +5 -15
  144. package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
  145. package/dist/markdown/index.d.ts +2 -2
  146. package/dist/markdown/index.js +2 -1
  147. package/dist/markdown/lib/MarkdownPlugin.js +16 -9
  148. package/dist/markdown/lib/RawHtmlPlugin.js +24 -0
  149. package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
  150. package/dist/markdown/lib/internal/markdownConversion.js +773 -74
  151. package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
  152. package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
  153. package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
  154. package/dist/markdown/lib/internal/markdownLine.js +5 -3
  155. package/dist/markdown/lib/internal/markdownMappings.js +19 -7
  156. package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
  157. package/dist/markdown/lib/internal/markdownRawHtml.js +314 -0
  158. package/dist/markdown/lib/internal/markdownSegments.js +57 -48
  159. package/dist/markdown/lib/internal/markdownTags.js +22 -8
  160. package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
  161. package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
  162. package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
  163. package/dist/math/index.d.ts +3 -2
  164. package/dist/math/react/index.d.ts +4 -3
  165. package/dist/migrations/index.d.ts +3 -3
  166. package/dist/pagination/index.d.ts +1 -1
  167. package/dist/pagination/react/index.d.ts +4 -4
  168. package/dist/react/components/EditorContentView.internal.js +17 -8
  169. package/dist/react/components/EditorProvider.js +5 -5
  170. package/dist/react/components/Plate.js +103 -122
  171. package/dist/react/components/PlateContainer.js +40 -32
  172. package/dist/react/components/PlateController.js +28 -16
  173. package/dist/react/components/PlateRoot.internal.js +3 -2
  174. package/dist/react/core.js +4 -4
  175. package/dist/react/features/board/BoardSurface.js +116 -87
  176. package/dist/react/features/board/boardClipboard.internal.js +15 -5
  177. package/dist/react/features/board/boardGesture.internal.js +6 -3
  178. package/dist/react/features/board/boardIndex.internal.js +7 -18
  179. package/dist/react/features/board/boardPictures.internal.js +19 -13
  180. package/dist/react/features/board/boardView.internal.js +184 -49
  181. package/dist/react/features/board/boardVoice.internal.js +10 -11
  182. package/dist/react/features/board/index.d.ts +64 -18
  183. package/dist/react/features/callout/index.d.ts +3 -2
  184. package/dist/react/features/combobox/index.d.ts +8 -8
  185. package/dist/react/features/comments/index.d.ts +6 -5
  186. package/dist/react/features/date/index.d.ts +4 -3
  187. package/dist/react/features/details/index.d.ts +4 -3
  188. package/dist/react/features/field/FieldPlugin.js +34 -0
  189. package/dist/react/features/field/index.d.ts +312 -0
  190. package/dist/react/features/field/index.js +2 -0
  191. package/dist/react/features/footnote/index.d.ts +7 -6
  192. package/dist/react/features/format-painter/index.d.ts +4 -3
  193. package/dist/react/features/ink/InkContent.js +313 -0
  194. package/dist/react/features/ink/index.d.ts +57 -29
  195. package/dist/react/features/ink/index.js +2 -2
  196. package/dist/react/features/ink/inkCapture.internal.js +39 -17
  197. package/dist/react/features/ink/inkInput.internal.js +1 -1
  198. package/dist/react/features/ink/inkLayout.internal.js +6 -3
  199. package/dist/react/features/ink/inkPaint.internal.js +78 -2
  200. package/dist/react/features/ink/inkPlacement.internal.js +331 -104
  201. package/dist/react/features/ink/inkWatch.internal.js +7 -5
  202. package/dist/react/features/layout/index.d.ts +5 -4
  203. package/dist/react/features/media/index.d.ts +5 -4
  204. package/dist/react/features/mention/index.d.ts +6 -5
  205. package/dist/react/features/resizable/Resizable.js +4 -6
  206. package/dist/react/features/resizable/index.d.ts +5 -5
  207. package/dist/react/features/suggestion/index.d.ts +6 -5
  208. package/dist/react/features/table/TablePlugin.js +4 -11
  209. package/dist/react/features/table/index.d.ts +8 -7
  210. package/dist/react/features/toc/index.d.ts +2 -2
  211. package/dist/react/features/upload/index.d.ts +11 -6
  212. package/dist/react/index.d.ts +6 -6
  213. package/dist/react/index.js +4 -4
  214. package/dist/react/internal/plate-context.js +425 -188
  215. package/dist/react/plite-react.js +2 -2
  216. package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
  217. package/dist/react/stores/plate/useEditor.js +32 -14
  218. package/dist/react/stores/plate/useEditorHistory.js +55 -0
  219. package/dist/react/stores/plate/useEditorSelector.js +66 -21
  220. package/dist/react/utils/pipeRenderElement.internal.js +1 -1
  221. package/dist/react/utils/pluginRenderElement.internal.js +1 -1
  222. package/dist/react/virtualized.d.ts +4 -4
  223. package/dist/{source-CNKy99Th.d.ts → source-aUwpNnAw.d.ts} +4 -4
  224. package/dist/static/index.d.ts +18 -18
  225. package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
  226. package/dist/static/internal/staticPresentation.js +4 -4
  227. package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
  228. package/dist/tabbable/index.d.ts +1 -1
  229. package/dist/tabbable/react/index.d.ts +3 -3
  230. package/dist/testing/index.d.ts +3 -3
  231. package/dist/yjs/index.d.ts +1 -1
  232. package/dist/yjs/react/index.d.ts +6 -6
  233. package/package.json +20 -2
  234. package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
  235. package/dist/react/components/EditorSelectionView.js +0 -40
  236. package/dist/react/features/ink/InkLayer.js +0 -218
  237. package/dist/react/internal/createPlateTargetScope.js +0 -62
@@ -1,54 +1,427 @@
1
- import { markRootViewUsed, readRootViewUse, subscribeRootViewUse } from "../../facade.js";
1
+ import { getCarriedCaretEditor, getEditorRuntimeOwner, getViewPresentation, markRootViewUsed, readCaretViewIn, readRootViewUse, readShownViewUse, subscribeCaretTarget, subscribeEditorViewState, subscribeShownViewUse } from "../../facade.js";
2
+ import { failInvariant } from "../../internal/failInvariant.js";
2
3
  import { getEditorDOMRoot } from "../../dom/plite-dom.internal.js";
3
- import { useEditorRootElement, useEditorViewState } from "../plite-react.js";
4
+ import { useEditorRootElement } from "../plite-react.js";
4
5
  import { trackEditableFocus } from "../stores/plate-controller/document-focus.internal.js";
5
- import { createPlateTargetScope } from "./createPlateTargetScope.js";
6
6
  import { useEditorContext, useOptionalEditorContext } from "./plite-components.js";
7
7
  import React from "react";
8
8
  import { c } from "react/compiler-runtime";
9
9
  //#region src/react/internal/plate-context.tsx
10
- const createPlateScope = () => createPlateTargetScope((target) => readRootViewUse(target.editor));
10
+ const stopNothing = () => {};
11
+ const subscribeNothing = () => stopNothing;
12
+ const readNothing = () => null;
13
+ const readTrue = () => true;
14
+ const readFalse = () => false;
15
+ const readBoolean = (value) => value ? readTrue : readFalse;
16
+ const readViewFact = {
17
+ composing: (editor) => editor.read.view.isComposing(),
18
+ focused: (editor) => editor.read.view.isFocused(),
19
+ readOnly: (editor) => editor.read.view.isReadOnly()
20
+ };
21
+ const readServerFacts = ({ editor }) => ({
22
+ composing: readViewFact.composing(editor),
23
+ focused: readViewFact.focused(editor),
24
+ mounted: editor.api.dom.root() != null,
25
+ readOnly: readViewFact.readOnly(editor)
26
+ });
27
+ const noTarget = {
28
+ fixed: null,
29
+ getServerSnapshot: readNothing,
30
+ getSnapshot: readNothing,
31
+ server: null,
32
+ subscribe: subscribeNothing
33
+ };
34
+ const useFixedScope = (target) => {
35
+ const $ = c(8);
36
+ let t0;
37
+ if ($[0] !== target) {
38
+ t0 = () => target && readServerFacts(target);
39
+ $[0] = target;
40
+ $[1] = t0;
41
+ } else t0 = $[1];
42
+ const [server] = React.useState(t0);
43
+ let t1;
44
+ bb0: {
45
+ if (!target) {
46
+ t1 = noTarget;
47
+ break bb0;
48
+ }
49
+ let t2;
50
+ if ($[2] !== target) {
51
+ t2 = () => target;
52
+ $[2] = target;
53
+ $[3] = t2;
54
+ } else t2 = $[3];
55
+ const read = t2;
56
+ let t3;
57
+ if ($[4] !== read || $[5] !== server || $[6] !== target) {
58
+ t3 = {
59
+ fixed: target,
60
+ getServerSnapshot: read,
61
+ getSnapshot: read,
62
+ server,
63
+ subscribe: subscribeNothing
64
+ };
65
+ $[4] = read;
66
+ $[5] = server;
67
+ $[6] = target;
68
+ $[7] = t3;
69
+ } else t3 = $[7];
70
+ t1 = t3;
71
+ }
72
+ return t1;
73
+ };
74
+ const createAreaViews = () => {
75
+ const views = /* @__PURE__ */ new Set();
76
+ const listeners = /* @__PURE__ */ new Set();
77
+ const changed = () => listeners.forEach((listener) => listener());
78
+ return {
79
+ hold(view) {
80
+ views.add(view);
81
+ changed();
82
+ return () => {
83
+ views.delete(view);
84
+ changed();
85
+ };
86
+ },
87
+ subscribe(listener) {
88
+ listeners.add(listener);
89
+ return () => {
90
+ listeners.delete(listener);
91
+ };
92
+ },
93
+ usedLast() {
94
+ let latest = null;
95
+ for (const view of views) if (!latest || readRootViewUse(view.editor) > readRootViewUse(latest.editor)) latest = view;
96
+ return latest;
97
+ }
98
+ };
99
+ };
100
+ const useAreaScope = (around) => {
101
+ const $ = c(13);
102
+ const [views] = React.useState(createAreaViews);
103
+ const model = React.use(PlateModelContext);
104
+ let t0;
105
+ if ($[0] !== around || $[1] !== views) {
106
+ t0 = () => views.usedLast() ?? around.getSnapshot();
107
+ $[0] = around;
108
+ $[1] = views;
109
+ $[2] = t0;
110
+ } else t0 = $[2];
111
+ let t1;
112
+ if ($[3] !== around || $[4] !== model || $[5] !== views) {
113
+ t1 = (listener) => {
114
+ const stops = [
115
+ views.subscribe(listener),
116
+ around.subscribe(listener),
117
+ model ? subscribeShownViewUse(getEditorRuntimeOwner(model.editor), listener) : stopNothing
118
+ ];
119
+ return () => stops.forEach(_temp);
120
+ };
121
+ $[3] = around;
122
+ $[4] = model;
123
+ $[5] = views;
124
+ $[6] = t1;
125
+ } else t1 = $[6];
126
+ let t2;
127
+ if ($[7] !== around.getServerSnapshot || $[8] !== around.server || $[9] !== t0 || $[10] !== t1 || $[11] !== views) {
128
+ t2 = {
129
+ getServerSnapshot: around.getServerSnapshot,
130
+ getSnapshot: t0,
131
+ server: around.server,
132
+ subscribe: t1,
133
+ views
134
+ };
135
+ $[7] = around.getServerSnapshot;
136
+ $[8] = around.server;
137
+ $[9] = t0;
138
+ $[10] = t1;
139
+ $[11] = views;
140
+ $[12] = t2;
141
+ } else t2 = $[12];
142
+ return t2;
143
+ };
144
+ const outsideEveryProvider = {
145
+ fixed: null,
146
+ getServerSnapshot: readNothing,
147
+ getSnapshot: readNothing,
148
+ server: null,
149
+ subscribe: subscribeNothing
150
+ };
11
151
  const targets = /* @__PURE__ */ new WeakMap();
12
152
  const getPlateTarget = (editor) => targets.get(editor);
13
- const PlateEditorContext = React.createContext(null);
14
- const PlateControllerContext = React.createContext(null);
153
+ const targetOf = (editor, containerRef) => {
154
+ let target = targets.get(editor);
155
+ if (!target) {
156
+ target = {
157
+ editor,
158
+ containerRef,
159
+ editableRef: { get current() {
160
+ return editor.api.dom.editable();
161
+ } }
162
+ };
163
+ targets.set(editor, target);
164
+ }
165
+ return target;
166
+ };
167
+ const createCaretScope = (view, containerRef) => {
168
+ const getSnapshot = () => targetOf(getCarriedCaretEditor(view) ?? failInvariant("Expected a mounted editor root"), containerRef);
169
+ const first = getSnapshot();
170
+ return {
171
+ getServerSnapshot: () => first,
172
+ getSnapshot,
173
+ server: readServerFacts(first),
174
+ subscribe: (listener) => subscribeCaretTarget(getEditorRuntimeOwner(view), listener)
175
+ };
176
+ };
177
+ const createCaretSlotScope = (own) => {
178
+ const owner = getEditorRuntimeOwner(own.editor);
179
+ return {
180
+ getServerSnapshot: () => own,
181
+ getSnapshot: () => {
182
+ const view = readCaretViewIn(own.editor);
183
+ return view && view !== own.editor ? targetOf(view, own.containerRef) : own;
184
+ },
185
+ server: readServerFacts(own),
186
+ subscribe: (listener) => {
187
+ const stops = [subscribeCaretTarget(owner, listener), subscribeShownViewUse(owner, listener)];
188
+ return () => stops.forEach((stop) => stop());
189
+ }
190
+ };
191
+ };
192
+ const PlateScopeContext = React.createContext(outsideEveryProvider);
15
193
  const PlateModelContext = React.createContext(null);
16
- const PlateViewFactsContext = React.createContext({
17
- composing: false,
18
- focused: false,
19
- mounted: false,
20
- readOnly: false
21
- });
194
+ const PlateReadOnlyContext = React.createContext(false);
195
+ const createPlateController = () => {
196
+ const primaryOf = /* @__PURE__ */ new Map();
197
+ const listeners = /* @__PURE__ */ new Set();
198
+ const notify = () => listeners.forEach((listener) => listener());
199
+ const pickLastUsedRoot = () => {
200
+ let picked = null;
201
+ let pickedAt = 0;
202
+ for (const [entry, isPrimary] of primaryOf) {
203
+ const usedAt = readShownViewUse(getEditorRuntimeOwner(entry.rootView), getViewPresentation(entry.rootView));
204
+ if (usedAt === null) continue;
205
+ if (usedAt > pickedAt) {
206
+ picked = entry;
207
+ pickedAt = usedAt;
208
+ } else if (!picked && isPrimary) picked = entry;
209
+ }
210
+ return picked;
211
+ };
212
+ return {
213
+ getSnapshot: pickLastUsedRoot,
214
+ join(entry, isPrimary) {
215
+ primaryOf.set(entry, isPrimary);
216
+ const stop = subscribeShownViewUse(getEditorRuntimeOwner(entry.rootView), notify);
217
+ notify();
218
+ return () => {
219
+ stop();
220
+ primaryOf.delete(entry);
221
+ notify();
222
+ };
223
+ },
224
+ subscribe: (listener) => {
225
+ listeners.add(listener);
226
+ return () => {
227
+ listeners.delete(listener);
228
+ };
229
+ }
230
+ };
231
+ };
232
+ const PlateControllerContext = React.createContext(null);
233
+ const PlatePickedContext = React.createContext(null);
234
+ const underController = { ...noTarget };
235
+ const usePickedRoot = () => React.use(PlateScopeContext) === underController ? React.use(PlatePickedContext) : null;
236
+ const usePlateScope = () => {
237
+ return usePickedRoot()?.scope ?? React.use(PlateScopeContext);
238
+ };
22
239
  function usePlateModel() {
23
240
  const model = React.useContext(PlateModelContext);
24
241
  if (!model) throw new Error("EditorContent requires an EditorRoot.");
25
242
  return model;
26
243
  }
244
+ const useScopeTarget = (scope) => {
245
+ return React.useSyncExternalStore(scope.subscribe, scope.getSnapshot, scope.getServerSnapshot);
246
+ };
247
+ const usePlateTarget = () => {
248
+ return useScopeTarget(usePlateScope());
249
+ };
250
+ /**
251
+ * Give an `EditorRoot`'s children outside every editing area the editor of the
252
+ * caret's root, and join the controller around the `EditorRoot` with it.
253
+ */
254
+ function PlateCaretScope(t0) {
255
+ const $ = c(15);
256
+ const { children, primary } = t0;
257
+ const model = usePlateModel();
258
+ const view = useEditorContext();
259
+ let t1;
260
+ if ($[0] !== model.containerRef || $[1] !== view) {
261
+ t1 = createCaretScope(view, model.containerRef);
262
+ $[0] = model.containerRef;
263
+ $[1] = view;
264
+ $[2] = t1;
265
+ } else t1 = $[2];
266
+ let t2;
267
+ if ($[3] !== model || $[4] !== t1 || $[5] !== view) {
268
+ t2 = {
269
+ model,
270
+ scope: t1,
271
+ rootView: view
272
+ };
273
+ $[3] = model;
274
+ $[4] = t1;
275
+ $[5] = view;
276
+ $[6] = t2;
277
+ } else t2 = $[6];
278
+ const outside = t2;
279
+ const controller = React.use(PlateControllerContext);
280
+ let t3;
281
+ let t4;
282
+ if ($[7] !== controller || $[8] !== outside || $[9] !== primary) {
283
+ t3 = () => controller?.join(outside, primary);
284
+ t4 = [
285
+ controller,
286
+ outside,
287
+ primary
288
+ ];
289
+ $[7] = controller;
290
+ $[8] = outside;
291
+ $[9] = primary;
292
+ $[10] = t3;
293
+ $[11] = t4;
294
+ } else {
295
+ t3 = $[10];
296
+ t4 = $[11];
297
+ }
298
+ React.useLayoutEffect(t3, t4);
299
+ let t5;
300
+ if ($[12] !== children || $[13] !== outside.scope) {
301
+ t5 = /* @__PURE__ */ React.createElement(PlateScopeContext, { value: outside.scope }, children);
302
+ $[12] = children;
303
+ $[13] = outside.scope;
304
+ $[14] = t5;
305
+ } else t5 = $[14];
306
+ return t5;
307
+ }
308
+ function PlateCaretSlots(t0) {
309
+ const $ = c(10);
310
+ const { slots } = t0;
311
+ const own = React.use(PlateScopeContext).fixed ?? failInvariant("Expected a mounted editing area");
312
+ let t1;
313
+ if ($[0] !== own) {
314
+ t1 = createCaretSlotScope(own);
315
+ $[0] = own;
316
+ $[1] = t1;
317
+ } else t1 = $[1];
318
+ const scope = t1;
319
+ const target = React.useSyncExternalStore(scope.subscribe, scope.getSnapshot, scope.getServerSnapshot);
320
+ let t2;
321
+ if ($[2] !== slots || $[3] !== target) {
322
+ let t3;
323
+ if ($[5] !== target) {
324
+ t3 = (t4) => {
325
+ const { Caret, name } = t4;
326
+ return /* @__PURE__ */ React.createElement(Caret, {
327
+ editableRef: target.editableRef,
328
+ key: name
329
+ });
330
+ };
331
+ $[5] = target;
332
+ $[6] = t3;
333
+ } else t3 = $[6];
334
+ t2 = slots.map(t3);
335
+ $[2] = slots;
336
+ $[3] = target;
337
+ $[4] = t2;
338
+ } else t2 = $[4];
339
+ let t3;
340
+ if ($[7] !== scope || $[8] !== t2) {
341
+ t3 = /* @__PURE__ */ React.createElement(PlateScopeContext, { value: scope }, t2);
342
+ $[7] = scope;
343
+ $[8] = t2;
344
+ $[9] = t3;
345
+ } else t3 = $[9];
346
+ return t3;
347
+ }
348
+ const viewStateReaders = /* @__PURE__ */ new WeakMap();
349
+ const subscribeSharedViewState = (editor, listener) => {
350
+ let readers = viewStateReaders.get(editor);
351
+ if (!readers) {
352
+ const listeners = /* @__PURE__ */ new Set();
353
+ readers = {
354
+ listeners,
355
+ stop: subscribeEditorViewState(editor, () => {
356
+ for (const notify of listeners) notify();
357
+ })
358
+ };
359
+ viewStateReaders.set(editor, readers);
360
+ }
361
+ const shared = readers;
362
+ shared.listeners.add(listener);
363
+ return () => {
364
+ shared.listeners.delete(listener);
365
+ if (shared.listeners.size > 0) return;
366
+ shared.stop();
367
+ viewStateReaders.delete(editor);
368
+ };
369
+ };
370
+ const useTargetViewState = (target, fact, withoutEditor) => {
371
+ const $ = c(8);
372
+ const { server } = usePlateScope();
373
+ const editor = target?.editor;
374
+ let t0;
375
+ if ($[0] !== editor || $[1] !== fact || $[2] !== withoutEditor) {
376
+ t0 = () => editor ? readViewFact[fact](editor) : withoutEditor;
377
+ $[0] = editor;
378
+ $[1] = fact;
379
+ $[2] = withoutEditor;
380
+ $[3] = t0;
381
+ } else t0 = $[3];
382
+ const readFact = t0;
383
+ let t1;
384
+ if ($[4] !== editor) {
385
+ t1 = (listener) => editor ? subscribeSharedViewState(editor, listener) : stopNothing;
386
+ $[4] = editor;
387
+ $[5] = t1;
388
+ } else t1 = $[5];
389
+ const t2 = t1;
390
+ const t3 = server?.[fact] ?? withoutEditor;
391
+ let t4;
392
+ if ($[6] !== t3) {
393
+ t4 = readBoolean(t3);
394
+ $[6] = t3;
395
+ $[7] = t4;
396
+ } else t4 = $[7];
397
+ return React.useSyncExternalStore(t2, readFact, t4);
398
+ };
27
399
  /** Bind node renderers to the native view that owns their snapshot. */
28
400
  function usePlateRenderContext(fallbackEditor) {
29
401
  const $ = c(11);
30
402
  const nativeEditor = useOptionalEditorContext();
31
403
  const editor = nativeEditor ?? fallbackEditor;
32
- const inherited = React.useContext(PlateEditorContext);
404
+ const inherited = React.useContext(PlateScopeContext).fixed ?? null;
33
405
  const emptyRef = React.useRef(null);
34
406
  let t0;
35
- if ($[0] !== editor || $[1] !== inherited) {
36
- t0 = inherited?.editor === editor ? inherited : {
407
+ if ($[0] !== editor || $[1] !== inherited?.containerRef || $[2] !== inherited?.editor) {
408
+ t0 = inherited?.editor === editor ? null : {
37
409
  editor,
38
410
  containerRef: inherited?.containerRef ?? emptyRef,
39
411
  editableRef: emptyRef
40
412
  };
41
413
  $[0] = editor;
42
- $[1] = inherited;
43
- $[2] = t0;
44
- } else t0 = $[2];
414
+ $[1] = inherited?.containerRef;
415
+ $[2] = inherited?.editor;
416
+ $[3] = t0;
417
+ } else t0 = $[3];
45
418
  const target = t0;
419
+ const scope = useFixedScope(target);
46
420
  let t1;
47
- if ($[3] !== editor || $[4] !== inherited?.editor || $[5] !== nativeEditor || $[6] !== target) {
48
- t1 = (children) => !nativeEditor || inherited?.editor === editor ? children : /* @__PURE__ */ React.createElement(PlateTargetProvider, { target }, children);
49
- $[3] = editor;
50
- $[4] = inherited?.editor;
51
- $[5] = nativeEditor;
421
+ if ($[4] !== nativeEditor || $[5] !== scope || $[6] !== target) {
422
+ t1 = (children) => !nativeEditor || !target ? children : /* @__PURE__ */ React.createElement(PlateScopeContext, { value: scope }, children);
423
+ $[4] = nativeEditor;
424
+ $[5] = scope;
52
425
  $[6] = target;
53
426
  $[7] = t1;
54
427
  } else t1 = $[7];
@@ -64,117 +437,13 @@ function usePlateRenderContext(fallbackEditor) {
64
437
  } else t2 = $[10];
65
438
  return t2;
66
439
  }
67
- function PlateTargetProvider(t0) {
68
- const $ = c(15);
69
- const { children, readOnly, target } = t0;
70
- const [snapshot, setSnapshot] = React.useState(null);
71
- let t1;
72
- if ($[0] !== snapshot || $[1] !== target) {
73
- t1 = snapshot?.target === target ? snapshot.facts : {
74
- composing: target?.editor.read.view.isComposing() ?? false,
75
- focused: target?.editor.read.view.isFocused() ?? false,
76
- mounted: target?.editor.api.dom.root() != null,
77
- readOnly: target?.editor.read.view.isReadOnly() ?? true
78
- };
79
- $[0] = snapshot;
80
- $[1] = target;
81
- $[2] = t1;
82
- } else t1 = $[2];
83
- const observedFacts = t1;
84
- let t2;
85
- if ($[3] !== observedFacts || $[4] !== readOnly) {
86
- t2 = readOnly === void 0 ? observedFacts : {
87
- ...observedFacts,
88
- readOnly
89
- };
90
- $[3] = observedFacts;
91
- $[4] = readOnly;
92
- $[5] = t2;
93
- } else t2 = $[5];
94
- const facts = t2;
95
- let t3;
96
- if ($[6] !== target) {
97
- t3 = target && /* @__PURE__ */ React.createElement(PlateTargetFacts, {
98
- target,
99
- onChange: setSnapshot
100
- });
101
- $[6] = target;
102
- $[7] = t3;
103
- } else t3 = $[7];
104
- let t4;
105
- if ($[8] !== children || $[9] !== facts || $[10] !== t3) {
106
- t4 = /* @__PURE__ */ React.createElement(PlateViewFactsContext, { value: facts }, t3, children);
107
- $[8] = children;
108
- $[9] = facts;
109
- $[10] = t3;
110
- $[11] = t4;
111
- } else t4 = $[11];
112
- let t5;
113
- if ($[12] !== t4 || $[13] !== target) {
114
- t5 = /* @__PURE__ */ React.createElement(PlateEditorContext, { value: target }, t4);
115
- $[12] = t4;
116
- $[13] = target;
117
- $[14] = t5;
118
- } else t5 = $[14];
119
- return t5;
120
- }
121
- function PlateTargetFacts(t0) {
122
- const $ = c(6);
123
- const { onChange, target } = t0;
124
- const facts = useEditorViewState(target.editor, _temp);
125
- const element = useEditorRootElement(target.editor);
126
- let t1;
127
- let t2;
128
- if ($[0] !== element || $[1] !== facts || $[2] !== onChange || $[3] !== target) {
129
- t1 = () => {
130
- onChange({
131
- target,
132
- facts: {
133
- ...facts,
134
- mounted: element !== null
135
- }
136
- });
137
- };
138
- t2 = [
139
- element,
140
- facts,
141
- onChange,
142
- target
143
- ];
144
- $[0] = element;
145
- $[1] = facts;
146
- $[2] = onChange;
147
- $[3] = target;
148
- $[4] = t1;
149
- $[5] = t2;
150
- } else {
151
- t1 = $[4];
152
- t2 = $[5];
153
- }
154
- React.useLayoutEffect(t1, t2);
155
- return null;
156
- }
157
- function _temp(view) {
158
- return {
159
- composing: view.isComposing(),
160
- focused: view.isFocused(),
161
- readOnly: view.isReadOnly()
162
- };
163
- }
164
- function PlateScopeProvider({ children, fallback = null, fallbackReadOnly, scope }) {
165
- const target = React.useSyncExternalStore(scope.subscribe, scope.getSnapshot, () => null);
166
- return /* @__PURE__ */ React.createElement(PlateTargetProvider, {
167
- target: target ?? fallback,
168
- readOnly: target ? void 0 : fallbackReadOnly
169
- }, children);
170
- }
171
440
  function PlateMountedView(t0) {
172
- const $ = c(27);
441
+ const $ = c(16);
173
442
  const { children, editableRef } = t0;
174
443
  const model = usePlateModel();
175
444
  const editor = useEditorContext();
176
445
  const element = useEditorRootElement(editor);
177
- const controller = React.useContext(PlateControllerContext);
446
+ const area = React.useContext(PlateScopeContext).views;
178
447
  let value;
179
448
  if ($[0] !== editableRef || $[1] !== editor || $[2] !== model.containerRef) {
180
449
  value = {
@@ -189,82 +458,50 @@ function PlateMountedView(t0) {
189
458
  $[3] = value;
190
459
  } else value = $[3];
191
460
  const target = value;
192
- const { primary } = model;
461
+ const scope = useFixedScope(target);
193
462
  let t1;
194
- if ($[4] !== controller || $[5] !== editor || $[6] !== model.scope || $[7] !== target) {
463
+ if ($[4] !== area || $[5] !== editor || $[6] !== target) {
195
464
  t1 = () => {
196
465
  const root = getEditorDOMRoot(editor);
197
466
  if (!root) return;
198
- const removeLocal = model.scope.register(target, true);
199
- const removeController = controller?.register(target, false);
200
- const removeUse = subscribeRootViewUse(editor, () => {
201
- model.scope.used(target);
202
- controller?.used(target);
203
- });
467
+ const release = area?.hold(target);
204
468
  const removeFocus = trackEditableFocus(root, () => markRootViewUsed(editor));
205
469
  return () => {
206
470
  removeFocus();
207
- removeUse();
208
- removeController?.();
209
- removeLocal();
471
+ release?.();
210
472
  };
211
473
  };
212
- $[4] = controller;
474
+ $[4] = area;
213
475
  $[5] = editor;
214
- $[6] = model.scope;
215
- $[7] = target;
216
- $[8] = t1;
217
- } else t1 = $[8];
476
+ $[6] = target;
477
+ $[7] = t1;
478
+ } else t1 = $[7];
218
479
  let t2;
219
- if ($[9] !== controller || $[10] !== editor || $[11] !== element || $[12] !== model.scope || $[13] !== target) {
480
+ if ($[8] !== area || $[9] !== editor || $[10] !== element || $[11] !== target) {
220
481
  t2 = [
221
- controller,
482
+ area,
222
483
  editor,
223
484
  element,
224
- model.scope,
225
485
  target
226
486
  ];
227
- $[9] = controller;
228
- $[10] = editor;
229
- $[11] = element;
230
- $[12] = model.scope;
231
- $[13] = target;
232
- $[14] = t2;
233
- } else t2 = $[14];
487
+ $[8] = area;
488
+ $[9] = editor;
489
+ $[10] = element;
490
+ $[11] = target;
491
+ $[12] = t2;
492
+ } else t2 = $[12];
234
493
  React.useLayoutEffect(t1, t2);
235
494
  let t3;
236
- if ($[15] !== controller || $[16] !== primary || $[17] !== target) {
237
- t3 = () => {
238
- controller?.setPrimary(target, primary);
239
- };
240
- $[15] = controller;
241
- $[16] = primary;
242
- $[17] = target;
243
- $[18] = t3;
244
- } else t3 = $[18];
245
- let t4;
246
- if ($[19] !== controller || $[20] !== element || $[21] !== primary || $[22] !== target) {
247
- t4 = [
248
- controller,
249
- element,
250
- primary,
251
- target
252
- ];
253
- $[19] = controller;
254
- $[20] = element;
255
- $[21] = primary;
256
- $[22] = target;
257
- $[23] = t4;
258
- } else t4 = $[23];
259
- React.useLayoutEffect(t3, t4);
260
- let t5;
261
- if ($[24] !== children || $[25] !== target) {
262
- t5 = /* @__PURE__ */ React.createElement(PlateTargetProvider, { target }, children);
263
- $[24] = children;
264
- $[25] = target;
265
- $[26] = t5;
266
- } else t5 = $[26];
267
- return t5;
495
+ if ($[13] !== children || $[14] !== scope) {
496
+ t3 = /* @__PURE__ */ React.createElement(PlateScopeContext, { value: scope }, children);
497
+ $[13] = children;
498
+ $[14] = scope;
499
+ $[15] = t3;
500
+ } else t3 = $[15];
501
+ return t3;
502
+ }
503
+ function _temp(stop) {
504
+ return stop();
268
505
  }
269
506
  //#endregion
270
- export { PlateControllerContext, PlateEditorContext, PlateModelContext, PlateMountedView, PlateScopeProvider, PlateTargetProvider, PlateViewFactsContext, createPlateScope, getPlateTarget, usePlateModel, usePlateRenderContext };
507
+ export { PlateCaretScope, PlateCaretSlots, PlateControllerContext, PlateModelContext, PlateMountedView, PlatePickedContext, PlateReadOnlyContext, PlateScopeContext, createPlateController, getPlateTarget, outsideEveryProvider, readBoolean, subscribeNothing, underController, useAreaScope, useFixedScope, usePickedRoot, usePlateModel, usePlateRenderContext, usePlateScope, usePlateTarget, useScopeTarget, useTargetViewState };
@@ -1,2 +1,2 @@
1
- import { EditorReadOnlyProvider, ReactUpdatePolicy, installBrowserHandle, react, setDOMTextSyncRendererCapability, setRetainedTextFlowRendererCapability, useAnnotation, useAnnotationStore, useAnnotations, useChildRoot, useClaimEditableDOMCommit, useContentRoot, useDropIndicator, useEditableClip, useEditorEditableElement, useEditorFocused, useEditorHistory, useEditorReadOnly, useEditorRootElement, useEditorRuntimeState, useEditorScrollElement, useEditorScrollElementRef, useEditorViewState, useElementPath, useElementSelected, useNodeSelector, useOptionalEditorReadOnly, useRootChrome, useRootEditor, useRootState, useRuntimeState, useSelectionGeometry, useSelectionView, useSetStateField, useStateFieldValue } from "plitejs/react";
2
- export { EditorReadOnlyProvider, ReactUpdatePolicy, installBrowserHandle, react, setDOMTextSyncRendererCapability, setRetainedTextFlowRendererCapability, useAnnotation, useAnnotationStore, useAnnotations, useChildRoot, useClaimEditableDOMCommit, useContentRoot, useDropIndicator, useEditableClip, useEditorEditableElement, useEditorFocused, useEditorHistory, useEditorReadOnly, useEditorRootElement, useEditorRuntimeState, useEditorScrollElement, useEditorScrollElementRef, useEditorViewState, useElementPath, useElementSelected, useNodeSelector, useOptionalEditorReadOnly, useRootChrome, useRootEditor, useRootState, useRuntimeState, useSelectionGeometry, useSelectionView, useSetStateField, useStateFieldValue };
1
+ import { EditorReadOnlyProvider, ReactUpdatePolicy, installBrowserHandle, react, setDOMTextSyncRendererCapability, setRetainedTextFlowRendererCapability, useAnnotation, useAnnotationStore, useAnnotations, useChildRoot, useClaimEditableDOMCommit, useContentRoot, useDropIndicator, useEditableClip, useEditorEditableElement, useEditorFocused, useEditorHistory, useEditorReadOnly, useEditorRootElement, useEditorRuntimeState, useEditorScrollElement, useEditorScrollElementRef, useEditorViewState, useElementPath, useElementSelected, useNodeSelector, useOptionalEditorReadOnly, useRootChrome, useRootEditor, useRootState, useRuntimeState, useSelectionGeometry, useSetStateField, useStateFieldValue } from "plitejs/react";
2
+ export { EditorReadOnlyProvider, ReactUpdatePolicy, installBrowserHandle, react, setDOMTextSyncRendererCapability, setRetainedTextFlowRendererCapability, useAnnotation, useAnnotationStore, useAnnotations, useChildRoot, useClaimEditableDOMCommit, useContentRoot, useDropIndicator, useEditableClip, useEditorEditableElement, useEditorFocused, useEditorHistory, useEditorReadOnly, useEditorRootElement, useEditorRuntimeState, useEditorScrollElement, useEditorScrollElementRef, useEditorViewState, useElementPath, useElementSelected, useNodeSelector, useOptionalEditorReadOnly, useRootChrome, useRootEditor, useRootState, useRuntimeState, useSelectionGeometry, useSetStateField, useStateFieldValue };