@milkdown/crepe 7.19.2 → 7.20.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 (100) hide show
  1. package/lib/cjs/builder.js +43 -1
  2. package/lib/cjs/builder.js.map +1 -1
  3. package/lib/cjs/feature/block-edit/index.js +8 -2
  4. package/lib/cjs/feature/block-edit/index.js.map +1 -1
  5. package/lib/cjs/feature/code-mirror/index.js +1 -0
  6. package/lib/cjs/feature/code-mirror/index.js.map +1 -1
  7. package/lib/cjs/feature/cursor/index.js +1 -0
  8. package/lib/cjs/feature/cursor/index.js.map +1 -1
  9. package/lib/cjs/feature/image-block/index.js +4 -1
  10. package/lib/cjs/feature/image-block/index.js.map +1 -1
  11. package/lib/cjs/feature/latex/index.js +5 -0
  12. package/lib/cjs/feature/latex/index.js.map +1 -1
  13. package/lib/cjs/feature/link-tooltip/index.js +1 -0
  14. package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
  15. package/lib/cjs/feature/list-item/index.js +1 -0
  16. package/lib/cjs/feature/list-item/index.js.map +1 -1
  17. package/lib/cjs/feature/placeholder/index.js +1 -0
  18. package/lib/cjs/feature/placeholder/index.js.map +1 -1
  19. package/lib/cjs/feature/table/index.js +1 -0
  20. package/lib/cjs/feature/table/index.js.map +1 -1
  21. package/lib/cjs/feature/toolbar/index.js +9 -2
  22. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  23. package/lib/cjs/feature/top-bar/index.js +790 -0
  24. package/lib/cjs/feature/top-bar/index.js.map +1 -0
  25. package/lib/cjs/index.js +630 -142
  26. package/lib/cjs/index.js.map +1 -1
  27. package/lib/esm/builder.js +43 -1
  28. package/lib/esm/builder.js.map +1 -1
  29. package/lib/esm/feature/block-edit/index.js +8 -2
  30. package/lib/esm/feature/block-edit/index.js.map +1 -1
  31. package/lib/esm/feature/code-mirror/index.js +1 -0
  32. package/lib/esm/feature/code-mirror/index.js.map +1 -1
  33. package/lib/esm/feature/cursor/index.js +1 -0
  34. package/lib/esm/feature/cursor/index.js.map +1 -1
  35. package/lib/esm/feature/image-block/index.js +4 -1
  36. package/lib/esm/feature/image-block/index.js.map +1 -1
  37. package/lib/esm/feature/latex/index.js +5 -0
  38. package/lib/esm/feature/latex/index.js.map +1 -1
  39. package/lib/esm/feature/link-tooltip/index.js +1 -0
  40. package/lib/esm/feature/link-tooltip/index.js.map +1 -1
  41. package/lib/esm/feature/list-item/index.js +1 -0
  42. package/lib/esm/feature/list-item/index.js.map +1 -1
  43. package/lib/esm/feature/placeholder/index.js +1 -0
  44. package/lib/esm/feature/placeholder/index.js.map +1 -1
  45. package/lib/esm/feature/table/index.js +1 -0
  46. package/lib/esm/feature/table/index.js.map +1 -1
  47. package/lib/esm/feature/toolbar/index.js +9 -2
  48. package/lib/esm/feature/toolbar/index.js.map +1 -1
  49. package/lib/esm/feature/top-bar/index.js +788 -0
  50. package/lib/esm/feature/top-bar/index.js.map +1 -0
  51. package/lib/esm/index.js +631 -143
  52. package/lib/esm/index.js.map +1 -1
  53. package/lib/theme/common/style.css +1 -0
  54. package/lib/theme/common/top-bar.css +152 -0
  55. package/lib/tsconfig.tsbuildinfo +1 -1
  56. package/lib/types/core/builder.d.ts +2 -1
  57. package/lib/types/core/builder.d.ts.map +1 -1
  58. package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
  59. package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
  60. package/lib/types/feature/image-block/index.d.ts +2 -0
  61. package/lib/types/feature/image-block/index.d.ts.map +1 -1
  62. package/lib/types/feature/index.d.ts +4 -1
  63. package/lib/types/feature/index.d.ts.map +1 -1
  64. package/lib/types/feature/latex/inline-tooltip/component.d.ts.map +1 -1
  65. package/lib/types/feature/loader.d.ts.map +1 -1
  66. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  67. package/lib/types/feature/toolbar/config.d.ts +1 -1
  68. package/lib/types/feature/top-bar/component.d.ts +11 -0
  69. package/lib/types/feature/top-bar/component.d.ts.map +1 -0
  70. package/lib/types/feature/top-bar/config.d.ts +34 -0
  71. package/lib/types/feature/top-bar/config.d.ts.map +1 -0
  72. package/lib/types/feature/top-bar/index.d.ts +26 -0
  73. package/lib/types/feature/top-bar/index.d.ts.map +1 -0
  74. package/lib/types/icons/code-block.d.ts +2 -0
  75. package/lib/types/icons/code-block.d.ts.map +1 -0
  76. package/lib/types/icons/index.d.ts +1 -0
  77. package/lib/types/icons/index.d.ts.map +1 -1
  78. package/lib/types/utils/group-builder.d.ts +1 -1
  79. package/lib/types/utils/group-builder.d.ts.map +1 -1
  80. package/lib/types/utils/keep-alive.d.ts +2 -0
  81. package/lib/types/utils/keep-alive.d.ts.map +1 -0
  82. package/package.json +18 -13
  83. package/src/core/builder.ts +39 -2
  84. package/src/feature/block-edit/handle/component.tsx +3 -2
  85. package/src/feature/block-edit/menu/component.tsx +3 -2
  86. package/src/feature/block-edit/menu/config.ts +1 -1
  87. package/src/feature/image-block/index.ts +4 -0
  88. package/src/feature/index.ts +6 -0
  89. package/src/feature/latex/inline-tooltip/component.tsx +4 -2
  90. package/src/feature/loader.ts +4 -0
  91. package/src/feature/toolbar/component.tsx +7 -5
  92. package/src/feature/top-bar/component.tsx +198 -0
  93. package/src/feature/top-bar/config.ts +367 -0
  94. package/src/feature/top-bar/index.ts +113 -0
  95. package/src/icons/code-block.ts +12 -0
  96. package/src/icons/index.ts +1 -0
  97. package/src/theme/common/style.css +1 -0
  98. package/src/theme/common/top-bar.css +156 -0
  99. package/src/utils/group-builder.ts +1 -1
  100. package/src/utils/keep-alive.ts +3 -0
@@ -0,0 +1,788 @@
1
+ import { TextSelection, PluginKey, Plugin } from '@milkdown/kit/prose/state';
2
+ import { $ctx, $prose } from '@milkdown/kit/utils';
3
+ import { defineComponent, ref, onMounted, onUnmounted, computed, h, Fragment, createApp } from 'vue';
4
+ import { createSlice } from '@milkdown/kit/ctx';
5
+ import { Icon } from '@milkdown/kit/component';
6
+ import { commandsCtx, editorViewCtx, editorCtx, EditorStatus } from '@milkdown/kit/core';
7
+ import clsx from 'clsx';
8
+ import { imageBlockSchema } from '@milkdown/kit/component/image-block';
9
+ import { toggleLinkCommand } from '@milkdown/kit/component/link-tooltip';
10
+ import { toggleStrongCommand, strongSchema, toggleEmphasisCommand, emphasisSchema, inlineCodeSchema, toggleInlineCodeCommand, bulletListSchema, wrapInBlockTypeCommand, orderedListSchema, listItemSchema, linkSchema, addBlockTypeCommand, selectTextNearPosCommand, codeBlockSchema, setBlockTypeCommand, blockquoteSchema, hrSchema, isMarkSelectedCommand, paragraphSchema, headingSchema } from '@milkdown/kit/preset/commonmark';
11
+ import { toggleStrikethroughCommand, strikethroughSchema, createTable } from '@milkdown/kit/preset/gfm';
12
+
13
+ createSlice([], "FeaturesCtx");
14
+ createSlice({}, "CrepeCtx");
15
+ function useCrepeFeatures(ctx) {
16
+ return ctx.use("FeaturesCtx");
17
+ }
18
+ function crepeFeatureConfig(feature) {
19
+ return (ctx) => {
20
+ useCrepeFeatures(ctx).update((features) => {
21
+ if (features.includes(feature)) {
22
+ return features;
23
+ }
24
+ return [...features, feature];
25
+ });
26
+ };
27
+ }
28
+
29
+ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
30
+ CrepeFeature2["CodeMirror"] = "code-mirror";
31
+ CrepeFeature2["ListItem"] = "list-item";
32
+ CrepeFeature2["LinkTooltip"] = "link-tooltip";
33
+ CrepeFeature2["Cursor"] = "cursor";
34
+ CrepeFeature2["ImageBlock"] = "image-block";
35
+ CrepeFeature2["BlockEdit"] = "block-edit";
36
+ CrepeFeature2["Toolbar"] = "toolbar";
37
+ CrepeFeature2["Placeholder"] = "placeholder";
38
+ CrepeFeature2["Table"] = "table";
39
+ CrepeFeature2["Latex"] = "latex";
40
+ CrepeFeature2["TopBar"] = "top-bar";
41
+ return CrepeFeature2;
42
+ })(CrepeFeature || {});
43
+
44
+ function keepAlive(..._args) {
45
+ }
46
+
47
+ const boldIcon = `
48
+ <svg
49
+ xmlns="http://www.w3.org/2000/svg"
50
+ width="24"
51
+ height="24"
52
+ viewBox="0 0 24 24"
53
+ >
54
+ <path
55
+ d="M8.85758 18.625C8.4358 18.625 8.07715 18.4772 7.78163 18.1817C7.48613 17.8862 7.33838 17.5275 7.33838 17.1058V6.8942C7.33838 6.47242 7.48613 6.11377 7.78163 5.81825C8.07715 5.52275 8.4358 5.375 8.85758 5.375H12.1999C13.2191 5.375 14.1406 5.69231 14.9643 6.32693C15.788 6.96154 16.1999 7.81603 16.1999 8.89038C16.1999 9.63779 16.0194 10.2471 15.6585 10.7183C15.2976 11.1894 14.9088 11.5314 14.4922 11.7442C15.005 11.9211 15.4947 12.2708 15.9614 12.7933C16.428 13.3157 16.6614 14.0192 16.6614 14.9038C16.6614 16.182 16.1902 17.1217 15.2479 17.723C14.3056 18.3243 13.3563 18.625 12.3999 18.625H8.85758ZM9.4883 16.6327H12.3191C13.1063 16.6327 13.6627 16.4141 13.9884 15.9769C14.314 15.5397 14.4768 15.1205 14.4768 14.7192C14.4768 14.3179 14.314 13.8987 13.9884 13.4615C13.6627 13.0243 13.0909 12.8057 12.273 12.8057H9.4883V16.6327ZM9.4883 10.875H12.0826C12.6903 10.875 13.172 10.7013 13.5278 10.3539C13.8836 10.0064 14.0615 9.59037 14.0615 9.10575C14.0615 8.59035 13.8733 8.16918 13.497 7.84225C13.1207 7.51533 12.6595 7.35188 12.1133 7.35188H9.4883V10.875Z"
56
+ />
57
+ </svg>
58
+ `;
59
+
60
+ const bulletListIcon = `
61
+ <svg
62
+ xmlns="http://www.w3.org/2000/svg"
63
+ width="24"
64
+ height="24"
65
+ viewBox="0 0 24 24"
66
+ >
67
+ <g clip-path="url(#clip0_977_8070)">
68
+ <path
69
+ d="M4 10.5C3.17 10.5 2.5 11.17 2.5 12C2.5 12.83 3.17 13.5 4 13.5C4.83 13.5 5.5 12.83 5.5 12C5.5 11.17 4.83 10.5 4 10.5ZM4 4.5C3.17 4.5 2.5 5.17 2.5 6C2.5 6.83 3.17 7.5 4 7.5C4.83 7.5 5.5 6.83 5.5 6C5.5 5.17 4.83 4.5 4 4.5ZM4 16.5C3.17 16.5 2.5 17.18 2.5 18C2.5 18.82 3.18 19.5 4 19.5C4.82 19.5 5.5 18.82 5.5 18C5.5 17.18 4.83 16.5 4 16.5ZM8 19H20C20.55 19 21 18.55 21 18C21 17.45 20.55 17 20 17H8C7.45 17 7 17.45 7 18C7 18.55 7.45 19 8 19ZM8 13H20C20.55 13 21 12.55 21 12C21 11.45 20.55 11 20 11H8C7.45 11 7 11.45 7 12C7 12.55 7.45 13 8 13ZM7 6C7 6.55 7.45 7 8 7H20C20.55 7 21 6.55 21 6C21 5.45 20.55 5 20 5H8C7.45 5 7 5.45 7 6Z"
70
+ />
71
+ </g>
72
+ <defs>
73
+ <clipPath id="clip0_977_8070">
74
+ <rect width="24" height="24" />
75
+ </clipPath>
76
+ </defs>
77
+ </svg>
78
+ `;
79
+
80
+ const chevronDownIcon = `
81
+ <svg
82
+ xmlns="http://www.w3.org/2000/svg"
83
+ fill="none"
84
+ viewBox="0 0 24 24"
85
+ stroke-width="1.5"
86
+ stroke="currentColor"
87
+ class="w-6 h-6"
88
+ >
89
+ <path
90
+ stroke-linecap="round"
91
+ stroke-linejoin="round"
92
+ d="M19.5 8.25l-7.5 7.5-7.5-7.5"
93
+ />
94
+ </svg>
95
+ `;
96
+
97
+ const codeIcon = `
98
+ <svg
99
+ xmlns="http://www.w3.org/2000/svg"
100
+ width="24"
101
+ height="24"
102
+ viewBox="0 0 24 24"
103
+ >
104
+ <g clip-path="url(#clip0_977_8081)">
105
+ <path
106
+ d="M9.4 16.6L4.8 12L9.4 7.4L8 6L2 12L8 18L9.4 16.6ZM14.6 16.6L19.2 12L14.6 7.4L16 6L22 12L16 18L14.6 16.6Z"
107
+ />
108
+ </g>
109
+ <defs>
110
+ <clipPath id="clip0_977_8081">
111
+ <rect width="24" height="24" />
112
+ </clipPath>
113
+ </defs>
114
+ </svg>
115
+ `;
116
+
117
+ const codeBlockIcon = `
118
+ <svg
119
+ xmlns="http://www.w3.org/2000/svg"
120
+ width="24"
121
+ height="24"
122
+ viewBox="0 0 24 24"
123
+ >
124
+ <path
125
+ d="M3 3h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zm1 2v14h16V5H4zm8 10h6v2h-6v-2zm-3.333-3L5.838 9.172l1.415-1.415L11.495 12l-4.242 4.243-1.415-1.415L8.667 12z"
126
+ />
127
+ </svg>
128
+ `;
129
+
130
+ const dividerIcon = `
131
+ <svg
132
+ xmlns="http://www.w3.org/2000/svg"
133
+ width="24"
134
+ height="24"
135
+ viewBox="0 0 24 24"
136
+ >
137
+ <g clip-path="url(#clip0_977_7900)">
138
+ <path
139
+ fill-rule="evenodd"
140
+ clip-rule="evenodd"
141
+ d="M19 13H5C4.45 13 4 12.55 4 12C4 11.45 4.45 11 5 11H19C19.55 11 20 11.45 20 12C20 12.55 19.55 13 19 13Z"
142
+ />
143
+ </g>
144
+ <defs>
145
+ <clipPath id="clip0_977_7900">
146
+ <rect width="24" height="24" />
147
+ </clipPath>
148
+ </defs>
149
+ </svg>
150
+ `;
151
+
152
+ const imageIcon = `
153
+ <svg
154
+ xmlns="http://www.w3.org/2000/svg"
155
+ width="24"
156
+ height="24"
157
+ viewBox="0 0 24 24"
158
+ >
159
+ <g clip-path="url(#clip0_977_8075)">
160
+ <path
161
+ d="M19 5V19H5V5H19ZM19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM14.14 11.86L11.14 15.73L9 13.14L6 17H18L14.14 11.86Z"
162
+ />
163
+ </g>
164
+ <defs>
165
+ <clipPath id="clip0_977_8075">
166
+ <rect width="24" height="24" />
167
+ </clipPath>
168
+ </defs>
169
+ </svg>
170
+ `;
171
+
172
+ const italicIcon = `
173
+ <svg
174
+ xmlns="http://www.w3.org/2000/svg"
175
+ width="24"
176
+ height="24"
177
+ viewBox="0 0 24 24"
178
+ >
179
+ <path
180
+ d="M6.29811 18.625C6.04505 18.625 5.83115 18.5375 5.65641 18.3626C5.48166 18.1877 5.39429 17.9736 5.39429 17.7203C5.39429 17.467 5.48166 17.2532 5.65641 17.0788C5.83115 16.9045 6.04505 16.8173 6.29811 16.8173H9.21159L12.452 7.18265H9.53851C9.28545 7.18265 9.07155 7.0952 8.89681 6.9203C8.72206 6.7454 8.63469 6.5313 8.63469 6.278C8.63469 6.02472 8.72206 5.81089 8.89681 5.63652C9.07155 5.46217 9.28545 5.375 9.53851 5.375H16.8847C17.1377 5.375 17.3516 5.46245 17.5264 5.63735C17.7011 5.81225 17.7885 6.02634 17.7885 6.27962C17.7885 6.53293 17.7011 6.74676 17.5264 6.92113C17.3516 7.09548 17.1377 7.18265 16.8847 7.18265H14.2789L11.0385 16.8173H13.6443C13.8973 16.8173 14.1112 16.9048 14.286 17.0797C14.4607 17.2546 14.5481 17.4687 14.5481 17.722C14.5481 17.9752 14.4607 18.1891 14.286 18.3634C14.1112 18.5378 13.8973 18.625 13.6443 18.625H6.29811Z"
181
+ />
182
+ </svg>
183
+ `;
184
+
185
+ const linkIcon = `
186
+ <svg
187
+ xmlns="http://www.w3.org/2000/svg"
188
+ width="24"
189
+ height="24"
190
+ viewBox="0 0 24 24"
191
+ >
192
+ <path
193
+ d="M17.0385 19.5003V16.5388H14.0769V15.0388H17.0385V12.0773H18.5384V15.0388H21.5V16.5388H18.5384V19.5003H17.0385ZM10.8077 16.5388H7.03845C5.78282 16.5388 4.7125 16.0963 3.8275 15.2114C2.9425 14.3266 2.5 13.2564 2.5 12.0009C2.5 10.7454 2.9425 9.67504 3.8275 8.78979C4.7125 7.90454 5.78282 7.46191 7.03845 7.46191H10.8077V8.96186H7.03845C6.1987 8.96186 5.48235 9.25834 4.8894 9.85129C4.29645 10.4442 3.99998 11.1606 3.99998 12.0003C3.99998 12.8401 4.29645 13.5564 4.8894 14.1494C5.48235 14.7423 6.1987 15.0388 7.03845 15.0388H10.8077V16.5388ZM8.25 12.7503V11.2504H15.75V12.7503H8.25ZM21.5 12.0003H20C20 11.1606 19.7035 10.4442 19.1106 9.85129C18.5176 9.25834 17.8013 8.96186 16.9615 8.96186H13.1923V7.46191H16.9615C18.2171 7.46191 19.2875 7.90441 20.1725 8.78939C21.0575 9.67439 21.5 10.7447 21.5 12.0003Z"
194
+ />
195
+ </svg>
196
+ `;
197
+
198
+ const orderedListIcon = `
199
+ <svg
200
+ xmlns="http://www.w3.org/2000/svg"
201
+ width="24"
202
+ height="24"
203
+ viewBox="0 0 24 24"
204
+ >
205
+ <g clip-path="url(#clip0_977_8067)">
206
+ <path
207
+ d="M8 7H20C20.55 7 21 6.55 21 6C21 5.45 20.55 5 20 5H8C7.45 5 7 5.45 7 6C7 6.55 7.45 7 8 7ZM20 17H8C7.45 17 7 17.45 7 18C7 18.55 7.45 19 8 19H20C20.55 19 21 18.55 21 18C21 17.45 20.55 17 20 17ZM20 11H8C7.45 11 7 11.45 7 12C7 12.55 7.45 13 8 13H20C20.55 13 21 12.55 21 12C21 11.45 20.55 11 20 11ZM4.5 16H2.5C2.22 16 2 16.22 2 16.5C2 16.78 2.22 17 2.5 17H4V17.5H3.5C3.22 17.5 3 17.72 3 18C3 18.28 3.22 18.5 3.5 18.5H4V19H2.5C2.22 19 2 19.22 2 19.5C2 19.78 2.22 20 2.5 20H4.5C4.78 20 5 19.78 5 19.5V16.5C5 16.22 4.78 16 4.5 16ZM2.5 5H3V7.5C3 7.78 3.22 8 3.5 8C3.78 8 4 7.78 4 7.5V4.5C4 4.22 3.78 4 3.5 4H2.5C2.22 4 2 4.22 2 4.5C2 4.78 2.22 5 2.5 5ZM4.5 10H2.5C2.22 10 2 10.22 2 10.5C2 10.78 2.22 11 2.5 11H3.8L2.12 12.96C2.04 13.05 2 13.17 2 13.28V13.5C2 13.78 2.22 14 2.5 14H4.5C4.78 14 5 13.78 5 13.5C5 13.22 4.78 13 4.5 13H3.2L4.88 11.04C4.96 10.95 5 10.83 5 10.72V10.5C5 10.22 4.78 10 4.5 10Z"
208
+ />
209
+ </g>
210
+ <defs>
211
+ <clipPath id="clip0_977_8067">
212
+ <rect width="24" height="24" />
213
+ </clipPath>
214
+ </defs>
215
+ </svg>
216
+ `;
217
+
218
+ const quoteIcon = `
219
+ <svg
220
+ xmlns="http://www.w3.org/2000/svg"
221
+ width="24"
222
+ height="24"
223
+ viewBox="0 0 24 24"
224
+ >
225
+ <g clip-path="url(#clip0_977_7897)">
226
+ <path
227
+ d="M7.17 17C7.68 17 8.15 16.71 8.37 16.26L9.79 13.42C9.93 13.14 10 12.84 10 12.53V8C10 7.45 9.55 7 9 7H5C4.45 7 4 7.45 4 8V12C4 12.55 4.45 13 5 13H7L5.97 15.06C5.52 15.95 6.17 17 7.17 17ZM17.17 17C17.68 17 18.15 16.71 18.37 16.26L19.79 13.42C19.93 13.14 20 12.84 20 12.53V8C20 7.45 19.55 7 19 7H15C14.45 7 14 7.45 14 8V12C14 12.55 14.45 13 15 13H17L15.97 15.06C15.52 15.95 16.17 17 17.17 17Z"
228
+ />
229
+ </g>
230
+ <defs>
231
+ <clipPath id="clip0_977_7897">
232
+ <rect width="24" height="24" />
233
+ </clipPath>
234
+ </defs>
235
+ </svg>
236
+ `;
237
+
238
+ const strikethroughIcon = `
239
+ <svg
240
+ xmlns="http://www.w3.org/2000/svg"
241
+ width="24"
242
+ height="24"
243
+ viewBox="0 0 24 24"
244
+ >
245
+ <path
246
+ d="M3.25 13.7404C3.0375 13.7404 2.85938 13.6684 2.71563 13.5246C2.57188 13.3808 2.5 13.2026 2.5 12.99C2.5 12.7774 2.57188 12.5993 2.71563 12.4558C2.85938 12.3122 3.0375 12.2404 3.25 12.2404H20.75C20.9625 12.2404 21.1406 12.3123 21.2843 12.4561C21.4281 12.5999 21.5 12.7781 21.5 12.9907C21.5 13.2033 21.4281 13.3814 21.2843 13.525C21.1406 13.6686 20.9625 13.7404 20.75 13.7404H3.25ZM10.9423 10.2596V6.62495H6.5673C6.2735 6.62495 6.02377 6.52201 5.8181 6.31613C5.61245 6.11026 5.50963 5.86027 5.50963 5.56615C5.50963 5.27205 5.61245 5.02083 5.8181 4.8125C6.02377 4.60417 6.2735 4.5 6.5673 4.5H17.4423C17.7361 4.5 17.9858 4.60294 18.1915 4.80883C18.3971 5.01471 18.5 5.2647 18.5 5.5588C18.5 5.85292 18.3971 6.10413 18.1915 6.31245C17.9858 6.52078 17.7361 6.62495 17.4423 6.62495H13.0673V10.2596H10.9423ZM10.9423 15.7211H13.0673V18.4423C13.0673 18.7361 12.9643 18.9858 12.7584 19.1915C12.5526 19.3971 12.3026 19.5 12.0085 19.5C11.7144 19.5 11.4631 19.3962 11.2548 19.1887C11.0465 18.9811 10.9423 18.7291 10.9423 18.4327V15.7211Z"
247
+ />
248
+ </svg>
249
+ `;
250
+
251
+ const tableIcon = `
252
+ <svg
253
+ xmlns="http://www.w3.org/2000/svg"
254
+ width="24"
255
+ height="24"
256
+ viewBox="0 0 24 24"
257
+ >
258
+ <g clip-path="url(#clip0_977_8078)">
259
+ <path
260
+ d="M20 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H20C21.1 21 22 20.1 22 19V5C22 3.9 21.1 3 20 3ZM20 5V8H5V5H20ZM15 19H10V10H15V19ZM5 10H8V19H5V10ZM17 19V10H20V19H17Z"
261
+ />
262
+ </g>
263
+ <defs>
264
+ <clipPath id="clip0_977_8078">
265
+ <rect width="24" height="24" />
266
+ </clipPath>
267
+ </defs>
268
+ </svg>
269
+ `;
270
+
271
+ const todoListIcon = `
272
+ <svg
273
+ xmlns="http://www.w3.org/2000/svg"
274
+ width="24"
275
+ height="24"
276
+ viewBox="0 0 24 24"
277
+ >
278
+ <path
279
+ d="M5.66936 16.3389L9.39244 12.6158C9.54115 12.4671 9.71679 12.3937 9.91936 12.3957C10.1219 12.3976 10.2975 12.4761 10.4463 12.6312C10.5847 12.7823 10.654 12.9585 10.654 13.1599C10.654 13.3613 10.5847 13.5363 10.4463 13.6851L6.32704 17.8197C6.14627 18.0004 5.93538 18.0908 5.69436 18.0908C5.45333 18.0908 5.24243 18.0004 5.06166 17.8197L3.01744 15.7754C2.87899 15.637 2.81136 15.4629 2.81456 15.2533C2.81776 15.0437 2.88859 14.8697 3.02706 14.7312C3.16551 14.5928 3.34008 14.5235 3.55076 14.5235C3.76144 14.5235 3.93494 14.5928 4.07126 14.7312L5.66936 16.3389ZM5.66936 8.72359L9.39244 5.00049C9.54115 4.85177 9.71679 4.77838 9.91936 4.78031C10.1219 4.78223 10.2975 4.86075 10.4463 5.01586C10.5847 5.16691 10.654 5.34314 10.654 5.54454C10.654 5.74592 10.5847 5.92097 10.4463 6.06969L6.32704 10.2043C6.14627 10.3851 5.93538 10.4755 5.69436 10.4755C5.45333 10.4755 5.24243 10.3851 5.06166 10.2043L3.01744 8.16009C2.87899 8.02162 2.81136 7.84759 2.81456 7.63799C2.81776 7.42837 2.88859 7.25433 3.02706 7.11586C3.16551 6.97741 3.34008 6.90819 3.55076 6.90819C3.76144 6.90819 3.93494 6.97741 4.07126 7.11586L5.66936 8.72359ZM13.7597 16.5581C13.5472 16.5581 13.3691 16.4862 13.2253 16.3424C13.0816 16.1986 13.0097 16.0204 13.0097 15.8078C13.0097 15.5952 13.0816 15.4171 13.2253 15.2735C13.3691 15.13 13.5472 15.0582 13.7597 15.0582H20.7597C20.9722 15.0582 21.1503 15.1301 21.2941 15.2739C21.4378 15.4177 21.5097 15.5959 21.5097 15.8085C21.5097 16.0211 21.4378 16.1992 21.2941 16.3427C21.1503 16.4863 20.9722 16.5581 20.7597 16.5581H13.7597ZM13.7597 8.94276C13.5472 8.94276 13.3691 8.87085 13.2253 8.72704C13.0816 8.58324 13.0097 8.40504 13.0097 8.19244C13.0097 7.97985 13.0816 7.80177 13.2253 7.65819C13.3691 7.5146 13.5472 7.44281 13.7597 7.44281H20.7597C20.9722 7.44281 21.1503 7.51471 21.2941 7.65851C21.4378 7.80233 21.5097 7.98053 21.5097 8.19311C21.5097 8.40571 21.4378 8.5838 21.2941 8.72739C21.1503 8.87097 20.9722 8.94276 20.7597 8.94276H13.7597Z"
280
+ />
281
+ </svg>
282
+ `;
283
+
284
+ const functionsIcon = `
285
+ <svg
286
+ xmlns="http://www.w3.org/2000/svg"
287
+ width="32"
288
+ height="32"
289
+ viewBox="0 0 24 24"
290
+ >
291
+ <path
292
+ fill="currentColor"
293
+ d="M7 19v-.808L13.096 12L7 5.808V5h10v1.25H9.102L14.727 12l-5.625 5.77H17V19z"
294
+ />
295
+ </svg>
296
+ `;
297
+
298
+ var __typeError$1 = (msg) => {
299
+ throw TypeError(msg);
300
+ };
301
+ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
302
+ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
303
+ var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
304
+ var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
305
+ var _groups, _getGroupInstance;
306
+ class GroupBuilder {
307
+ constructor() {
308
+ __privateAdd$1(this, _groups, []);
309
+ this.clear = () => {
310
+ __privateSet$1(this, _groups, []);
311
+ return this;
312
+ };
313
+ __privateAdd$1(this, _getGroupInstance, (group) => {
314
+ const groupInstance = {
315
+ group,
316
+ addItem: (key, item) => {
317
+ const data = { ...item, key };
318
+ group.items.push(data);
319
+ return groupInstance;
320
+ },
321
+ clear: () => {
322
+ group.items = [];
323
+ return groupInstance;
324
+ }
325
+ };
326
+ return groupInstance;
327
+ });
328
+ this.addGroup = (key, label) => {
329
+ const items = [];
330
+ const group = {
331
+ key,
332
+ label,
333
+ items
334
+ };
335
+ __privateGet$1(this, _groups).push(group);
336
+ return __privateGet$1(this, _getGroupInstance).call(this, group);
337
+ };
338
+ this.getGroup = (key) => {
339
+ const group = __privateGet$1(this, _groups).find((group2) => group2.key === key);
340
+ if (!group) throw new Error(`Group with key ${key} not found`);
341
+ return __privateGet$1(this, _getGroupInstance).call(this, group);
342
+ };
343
+ this.build = () => {
344
+ return __privateGet$1(this, _groups);
345
+ };
346
+ }
347
+ }
348
+ _groups = new WeakMap();
349
+ _getGroupInstance = new WeakMap();
350
+
351
+ const defaultHeadingOptions = [
352
+ { label: "Paragraph", level: null },
353
+ { label: "Heading 1", level: 1 },
354
+ { label: "Heading 2", level: 2 },
355
+ { label: "Heading 3", level: 3 },
356
+ { label: "Heading 4", level: 4 },
357
+ { label: "Heading 5", level: 5 },
358
+ { label: "Heading 6", level: 6 }
359
+ ];
360
+ function getCurrentHeading(ctx, options) {
361
+ var _a, _b;
362
+ const headingOptions = options != null ? options : defaultHeadingOptions;
363
+ const view = ctx.get(editorViewCtx);
364
+ const { $from } = view.state.selection;
365
+ const node = $from.parent;
366
+ const paragraphOption = (_a = headingOptions.find((o) => o.level === null)) != null ? _a : headingOptions[0];
367
+ if (node.type === headingSchema.type(ctx)) {
368
+ const level = node.attrs.level;
369
+ return (_b = headingOptions.find((o) => o.level === level)) != null ? _b : paragraphOption;
370
+ }
371
+ return paragraphOption;
372
+ }
373
+ function setHeading(ctx, level) {
374
+ const commands = ctx.get(commandsCtx);
375
+ if (level === null || level === void 0) {
376
+ const paragraph = paragraphSchema.type(ctx);
377
+ commands.call(setBlockTypeCommand.key, { nodeType: paragraph });
378
+ } else {
379
+ const heading = headingSchema.type(ctx);
380
+ commands.call(setBlockTypeCommand.key, {
381
+ nodeType: heading,
382
+ attrs: { level }
383
+ });
384
+ }
385
+ }
386
+ function isMarkActive(ctx, markType) {
387
+ const commands = ctx.get(commandsCtx);
388
+ const selected = commands.call(isMarkSelectedCommand.key, markType);
389
+ if (selected) return true;
390
+ const view = ctx.get(editorViewCtx);
391
+ const { state } = view;
392
+ if (state.storedMarks) {
393
+ return state.storedMarks.some((m) => m.type === markType);
394
+ }
395
+ if (state.selection instanceof TextSelection) {
396
+ const { $cursor } = state.selection;
397
+ if ($cursor) {
398
+ return $cursor.marks().some((m) => m.type === markType);
399
+ }
400
+ }
401
+ return false;
402
+ }
403
+ function buildHeadingSelector(headingOptions, chevronIcon) {
404
+ const options = headingOptions != null ? headingOptions : defaultHeadingOptions;
405
+ return {
406
+ icon: "",
407
+ active: () => false,
408
+ selector: {
409
+ chevronIcon: chevronIcon != null ? chevronIcon : chevronDownIcon,
410
+ activeLabel: (ctx) => getCurrentHeading(ctx, options).label,
411
+ options: options.map((opt) => ({
412
+ label: opt.label,
413
+ onSelect: (ctx) => setHeading(ctx, opt.level)
414
+ }))
415
+ }
416
+ };
417
+ }
418
+ function getGroups(config, ctx) {
419
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
420
+ const flags = ctx && useCrepeFeatures(ctx).get();
421
+ const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
422
+ const isImageBlockEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.ImageBlock);
423
+ const isTableEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Table);
424
+ const groupBuilder = new GroupBuilder();
425
+ groupBuilder.addGroup("heading", "Heading").addItem("heading-selector", {
426
+ ...buildHeadingSelector(config == null ? void 0 : config.headingOptions, config == null ? void 0 : config.chevronDownIcon)
427
+ });
428
+ groupBuilder.addGroup("formatting", "Formatting").addItem("bold", {
429
+ icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon,
430
+ active: (ctx2) => isMarkActive(ctx2, strongSchema.type(ctx2)),
431
+ onRun: (ctx2) => {
432
+ const commands = ctx2.get(commandsCtx);
433
+ commands.call(toggleStrongCommand.key);
434
+ }
435
+ }).addItem("italic", {
436
+ icon: (_b = config == null ? void 0 : config.italicIcon) != null ? _b : italicIcon,
437
+ active: (ctx2) => isMarkActive(ctx2, emphasisSchema.type(ctx2)),
438
+ onRun: (ctx2) => {
439
+ const commands = ctx2.get(commandsCtx);
440
+ commands.call(toggleEmphasisCommand.key);
441
+ }
442
+ }).addItem("strikethrough", {
443
+ icon: (_c = config == null ? void 0 : config.strikethroughIcon) != null ? _c : strikethroughIcon,
444
+ active: (ctx2) => isMarkActive(ctx2, strikethroughSchema.type(ctx2)),
445
+ onRun: (ctx2) => {
446
+ const commands = ctx2.get(commandsCtx);
447
+ commands.call(toggleStrikethroughCommand.key);
448
+ }
449
+ }).addItem("code", {
450
+ icon: (_d = config == null ? void 0 : config.codeIcon) != null ? _d : codeIcon,
451
+ active: (ctx2) => isMarkActive(ctx2, inlineCodeSchema.type(ctx2)),
452
+ onRun: (ctx2) => {
453
+ const view = ctx2.get(editorViewCtx);
454
+ const { state } = view;
455
+ if (state.selection.empty) {
456
+ const markType = inlineCodeSchema.type(ctx2);
457
+ const has = isMarkActive(ctx2, markType);
458
+ if (has) {
459
+ view.dispatch(state.tr.removeStoredMark(markType));
460
+ } else {
461
+ view.dispatch(state.tr.addStoredMark(markType.create()));
462
+ }
463
+ } else {
464
+ const commands = ctx2.get(commandsCtx);
465
+ commands.call(toggleInlineCodeCommand.key);
466
+ }
467
+ }
468
+ });
469
+ groupBuilder.addGroup("list", "List").addItem("bullet-list", {
470
+ icon: (_e = config == null ? void 0 : config.bulletListIcon) != null ? _e : bulletListIcon,
471
+ active: () => false,
472
+ onRun: (ctx2) => {
473
+ const commands = ctx2.get(commandsCtx);
474
+ const bulletList = bulletListSchema.type(ctx2);
475
+ commands.call(wrapInBlockTypeCommand.key, { nodeType: bulletList });
476
+ }
477
+ }).addItem("ordered-list", {
478
+ icon: (_f = config == null ? void 0 : config.orderedListIcon) != null ? _f : orderedListIcon,
479
+ active: () => false,
480
+ onRun: (ctx2) => {
481
+ const commands = ctx2.get(commandsCtx);
482
+ const orderedList = orderedListSchema.type(ctx2);
483
+ commands.call(wrapInBlockTypeCommand.key, { nodeType: orderedList });
484
+ }
485
+ }).addItem("task-list", {
486
+ icon: (_g = config == null ? void 0 : config.taskListIcon) != null ? _g : todoListIcon,
487
+ active: () => false,
488
+ onRun: (ctx2) => {
489
+ const commands = ctx2.get(commandsCtx);
490
+ const listItem = listItemSchema.type(ctx2);
491
+ commands.call(wrapInBlockTypeCommand.key, {
492
+ nodeType: listItem,
493
+ attrs: { checked: false }
494
+ });
495
+ }
496
+ });
497
+ const insertGroup = groupBuilder.addGroup("insert", "Insert");
498
+ insertGroup.addItem("link", {
499
+ icon: (_h = config == null ? void 0 : config.linkIcon) != null ? _h : linkIcon,
500
+ active: (ctx2) => isMarkActive(ctx2, linkSchema.type(ctx2)),
501
+ onRun: (ctx2) => {
502
+ const view = ctx2.get(editorViewCtx);
503
+ const { state } = view;
504
+ const markType = linkSchema.type(ctx2);
505
+ if (state.selection.empty && isMarkActive(ctx2, markType)) {
506
+ view.dispatch(state.tr.removeStoredMark(markType));
507
+ return;
508
+ }
509
+ const commands = ctx2.get(commandsCtx);
510
+ commands.call(toggleLinkCommand.key);
511
+ }
512
+ });
513
+ if (isImageBlockEnabled) {
514
+ insertGroup.addItem("image", {
515
+ icon: (_i = config == null ? void 0 : config.imageIcon) != null ? _i : imageIcon,
516
+ active: () => false,
517
+ onRun: (ctx2) => {
518
+ const commands = ctx2.get(commandsCtx);
519
+ const imageBlock = imageBlockSchema.type(ctx2);
520
+ commands.call(addBlockTypeCommand.key, { nodeType: imageBlock });
521
+ }
522
+ });
523
+ }
524
+ if (isTableEnabled) {
525
+ insertGroup.addItem("table", {
526
+ icon: (_j = config == null ? void 0 : config.tableIcon) != null ? _j : tableIcon,
527
+ active: () => false,
528
+ onRun: (ctx2) => {
529
+ const commands = ctx2.get(commandsCtx);
530
+ const view = ctx2.get(editorViewCtx);
531
+ const { from } = view.state.selection;
532
+ commands.call(addBlockTypeCommand.key, {
533
+ nodeType: createTable(ctx2, 3, 3)
534
+ });
535
+ commands.call(selectTextNearPosCommand.key, { pos: from });
536
+ }
537
+ });
538
+ }
539
+ const blockGroup = groupBuilder.addGroup("block", "Block");
540
+ blockGroup.addItem("code-block", {
541
+ icon: (_k = config == null ? void 0 : config.codeBlockIcon) != null ? _k : codeBlockIcon,
542
+ active: () => false,
543
+ onRun: (ctx2) => {
544
+ const commands = ctx2.get(commandsCtx);
545
+ const codeBlock = codeBlockSchema.type(ctx2);
546
+ commands.call(setBlockTypeCommand.key, { nodeType: codeBlock });
547
+ }
548
+ });
549
+ if (isLatexEnabled) {
550
+ blockGroup.addItem("math", {
551
+ icon: (_l = config == null ? void 0 : config.mathIcon) != null ? _l : functionsIcon,
552
+ active: () => false,
553
+ onRun: (ctx2) => {
554
+ const commands = ctx2.get(commandsCtx);
555
+ const codeBlock = codeBlockSchema.type(ctx2);
556
+ commands.call(addBlockTypeCommand.key, {
557
+ nodeType: codeBlock,
558
+ attrs: { language: "LaTeX" }
559
+ });
560
+ }
561
+ });
562
+ }
563
+ groupBuilder.addGroup("more", "More").addItem("quote", {
564
+ icon: (_m = config == null ? void 0 : config.quoteIcon) != null ? _m : quoteIcon,
565
+ active: () => false,
566
+ onRun: (ctx2) => {
567
+ const commands = ctx2.get(commandsCtx);
568
+ const blockquote = blockquoteSchema.type(ctx2);
569
+ commands.call(wrapInBlockTypeCommand.key, { nodeType: blockquote });
570
+ }
571
+ }).addItem("hr", {
572
+ icon: (_n = config == null ? void 0 : config.hrIcon) != null ? _n : dividerIcon,
573
+ active: () => false,
574
+ onRun: (ctx2) => {
575
+ const commands = ctx2.get(commandsCtx);
576
+ const hr = hrSchema.type(ctx2);
577
+ commands.call(addBlockTypeCommand.key, { nodeType: hr });
578
+ }
579
+ });
580
+ (_o = config == null ? void 0 : config.buildTopBar) == null ? void 0 : _o.call(config, groupBuilder);
581
+ return groupBuilder.build();
582
+ }
583
+
584
+ keepAlive(h, Fragment);
585
+ const TopBar = defineComponent({
586
+ props: {
587
+ ctx: {
588
+ type: Object,
589
+ required: true
590
+ },
591
+ version: {
592
+ type: Object,
593
+ required: true
594
+ },
595
+ config: {
596
+ type: Object,
597
+ required: false
598
+ }
599
+ },
600
+ setup(props) {
601
+ const { ctx, config } = props;
602
+ const openSelectorKey = ref(null);
603
+ const onClick = (fn) => (e) => {
604
+ e.preventDefault();
605
+ if (ctx) {
606
+ fn(ctx);
607
+ }
608
+ };
609
+ function isReady() {
610
+ const status = ctx.get(editorCtx).status;
611
+ return status === EditorStatus.Created;
612
+ }
613
+ function subscribeState() {
614
+ keepAlive(props.version.value);
615
+ }
616
+ function checkActive(checker) {
617
+ subscribeState();
618
+ if (!isReady()) return false;
619
+ return checker(ctx);
620
+ }
621
+ function getSelectorLabel(selector) {
622
+ var _a, _b;
623
+ subscribeState();
624
+ if (!isReady()) return (_b = (_a = selector.options[0]) == null ? void 0 : _a.label) != null ? _b : "";
625
+ return selector.activeLabel(ctx);
626
+ }
627
+ function onToggleSelector(key, e) {
628
+ e.preventDefault();
629
+ e.stopPropagation();
630
+ openSelectorKey.value = openSelectorKey.value === key ? null : key;
631
+ }
632
+ const clickOutsideHandler = (e) => {
633
+ const target = e.target;
634
+ if (target.closest(".top-bar-heading-selector")) return;
635
+ openSelectorKey.value = null;
636
+ };
637
+ onMounted(() => {
638
+ window.addEventListener("pointerdown", clickOutsideHandler);
639
+ });
640
+ onUnmounted(() => {
641
+ window.removeEventListener("pointerdown", clickOutsideHandler);
642
+ });
643
+ const groupInfo = computed(() => getGroups(config, ctx));
644
+ function renderSelector(itemKey, selector) {
645
+ const isOpen = openSelectorKey.value === itemKey;
646
+ const activeLabel = getSelectorLabel(selector);
647
+ return /* @__PURE__ */ h("div", { key: itemKey, class: "top-bar-heading-selector" }, /* @__PURE__ */ h(
648
+ "button",
649
+ {
650
+ type: "button",
651
+ class: "top-bar-heading-button",
652
+ onPointerdown: (e) => onToggleSelector(itemKey, e)
653
+ },
654
+ /* @__PURE__ */ h("span", { class: "top-bar-heading-label" }, activeLabel),
655
+ selector.chevronIcon && /* @__PURE__ */ h("span", { class: "top-bar-chevron" }, /* @__PURE__ */ h(Icon, { icon: selector.chevronIcon }))
656
+ ), isOpen && /* @__PURE__ */ h("div", { class: "top-bar-heading-dropdown" }, selector.options.map((option, index) => /* @__PURE__ */ h(
657
+ "button",
658
+ {
659
+ key: `${itemKey}-${index}`,
660
+ type: "button",
661
+ class: clsx(
662
+ "top-bar-heading-option",
663
+ activeLabel === option.label && "active"
664
+ ),
665
+ onPointerdown: (e) => {
666
+ e.preventDefault();
667
+ e.stopPropagation();
668
+ openSelectorKey.value = null;
669
+ option.onSelect(ctx);
670
+ }
671
+ },
672
+ option.label
673
+ ))));
674
+ }
675
+ function renderButton(item) {
676
+ return /* @__PURE__ */ h(
677
+ "button",
678
+ {
679
+ key: item.key,
680
+ type: "button",
681
+ class: clsx("top-bar-item", checkActive(item.active) && "active"),
682
+ onPointerdown: onClick(item.onRun)
683
+ },
684
+ /* @__PURE__ */ h(Icon, { icon: item.icon })
685
+ );
686
+ }
687
+ return () => {
688
+ const view = isReady() ? ctx.get(editorViewCtx) : null;
689
+ const isReadonly = view ? !view.editable : false;
690
+ if (isReadonly) return null;
691
+ return /* @__PURE__ */ h("div", { class: "top-bar-inner" }, groupInfo.value.map((group) => {
692
+ return group.items.map((item) => {
693
+ if (item.selector) {
694
+ return renderSelector(item.key, item.selector);
695
+ }
696
+ if (!item.onRun) return null;
697
+ return renderButton(
698
+ item
699
+ );
700
+ });
701
+ }).reduce((acc, curr, index) => {
702
+ var _a, _b;
703
+ if (index === 0) {
704
+ acc.push(...curr);
705
+ } else {
706
+ const groupKey = (_b = (_a = groupInfo.value[index]) == null ? void 0 : _a.key) != null ? _b : index;
707
+ acc.push(
708
+ /* @__PURE__ */ h("div", { key: `divider-${groupKey}`, class: "top-bar-divider" }),
709
+ ...curr
710
+ );
711
+ }
712
+ return acc;
713
+ }, []));
714
+ };
715
+ }
716
+ });
717
+
718
+ var __typeError = (msg) => {
719
+ throw TypeError(msg);
720
+ };
721
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
722
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
723
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
724
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
725
+ var _container, _app, _version;
726
+ const topBarPluginKey = new PluginKey("CREPE_TOP_BAR");
727
+ class TopBarView {
728
+ constructor(ctx, view, config) {
729
+ __privateAdd(this, _container);
730
+ __privateAdd(this, _app);
731
+ __privateAdd(this, _version);
732
+ this.update = (view, _prevState) => {
733
+ __privateGet(this, _container).style.display = view.editable ? "" : "none";
734
+ __privateGet(this, _version).value++;
735
+ };
736
+ this.destroy = () => {
737
+ __privateGet(this, _app).unmount();
738
+ __privateGet(this, _container).remove();
739
+ };
740
+ __privateSet(this, _version, ref(0));
741
+ const container = document.createElement("div");
742
+ container.className = "milkdown-top-bar";
743
+ const app = createApp(TopBar, {
744
+ ctx,
745
+ config,
746
+ version: __privateGet(this, _version)
747
+ });
748
+ app.mount(container);
749
+ __privateSet(this, _container, container);
750
+ __privateSet(this, _app, app);
751
+ const editorRoot = view.dom.parentElement;
752
+ if (editorRoot) {
753
+ editorRoot.insertBefore(container, editorRoot.firstChild);
754
+ }
755
+ this.update(view);
756
+ }
757
+ }
758
+ _container = new WeakMap();
759
+ _app = new WeakMap();
760
+ _version = new WeakMap();
761
+ const topBarSlice = $ctx(
762
+ {
763
+ view: () => ({
764
+ update: () => {
765
+ },
766
+ destroy: () => {
767
+ }
768
+ })
769
+ },
770
+ "topBarConfig"
771
+ );
772
+ const topBarPlugin = $prose((ctx) => {
773
+ const config = ctx.get(topBarSlice.key);
774
+ return new Plugin({
775
+ key: topBarPluginKey,
776
+ view: config.view
777
+ });
778
+ });
779
+ const topBar = (editor, config) => {
780
+ editor.config(crepeFeatureConfig(CrepeFeature.TopBar)).config((ctx) => {
781
+ ctx.set(topBarSlice.key, {
782
+ view: (view) => new TopBarView(ctx, view, config)
783
+ });
784
+ }).use(topBarSlice).use(topBarPlugin);
785
+ };
786
+
787
+ export { topBar };
788
+ //# sourceMappingURL=index.js.map