@lofcz/platejs-utils 52.3.4
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.
- package/LICENSE +24 -0
- package/README.md +9 -0
- package/dist/index.d.ts +528 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/plate-keys-C2YNmTqZ.js +127 -0
- package/dist/plate-keys-C2YNmTqZ.js.map +1 -0
- package/dist/react/index.d.ts +107 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +300 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { t as KEYS } from "../plate-keys-C2YNmTqZ.js";
|
|
2
|
+
import { getContainerTypes } from "@platejs/core";
|
|
3
|
+
import { c } from "react-compiler-runtime";
|
|
4
|
+
import { createTPlatePlugin, useEditorComposing, useEditorReadOnly, useEditorRef, useEditorSelector, useFocused, usePluginOption } from "@platejs/core/react";
|
|
5
|
+
import React from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/react/hooks/useEditorString.ts
|
|
8
|
+
const useEditorString = () => {
|
|
9
|
+
const $ = c(1);
|
|
10
|
+
let t0;
|
|
11
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
12
|
+
t0 = [];
|
|
13
|
+
$[0] = t0;
|
|
14
|
+
} else t0 = $[0];
|
|
15
|
+
return useEditorSelector(_temp$4, t0);
|
|
16
|
+
};
|
|
17
|
+
function _temp$4(editor) {
|
|
18
|
+
return editor.api.string([]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/react/hooks/useFormInputProps.ts
|
|
23
|
+
/**
|
|
24
|
+
* Hook to allow the user to spread a set of predefined props to the Div wrapper
|
|
25
|
+
* of an Input element
|
|
26
|
+
*
|
|
27
|
+
* @param param0 An options object which can be expanded to add further
|
|
28
|
+
* functionality
|
|
29
|
+
* @returns A props object which can be spread onto the element
|
|
30
|
+
*/
|
|
31
|
+
const useFormInputProps = (options) => {
|
|
32
|
+
if (!options) return { props: {} };
|
|
33
|
+
const { preventDefaultOnEnterKeydown } = options;
|
|
34
|
+
/**
|
|
35
|
+
* Handle the keydown capture event and prevent the default behaviour when the
|
|
36
|
+
* user presses enter.
|
|
37
|
+
*
|
|
38
|
+
* In the event the user presses enter on a field such as a link, prior to
|
|
39
|
+
* filling in both label and url, the default behaviour is to submit the form.
|
|
40
|
+
* This, ultimately, results in no link being added as you need to fill both
|
|
41
|
+
* fields to pass validation.
|
|
42
|
+
*
|
|
43
|
+
* By calling preventDefault we short circuit the form's submission thus
|
|
44
|
+
* allowing the user to continue filling in the other fields
|
|
45
|
+
*
|
|
46
|
+
* @param e The original event which was provided by the VDOM implement their
|
|
47
|
+
* own behaviour on this event
|
|
48
|
+
*/
|
|
49
|
+
const handleEnterKeydownCapture = (e) => {
|
|
50
|
+
if (e.key === "Enter" || e.keyCode === 13) e.preventDefault();
|
|
51
|
+
};
|
|
52
|
+
return { props: { onKeyDownCapture: preventDefaultOnEnterKeydown ? (e) => handleEnterKeydownCapture(e) : void 0 } };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/react/hooks/useMarkToolbarButton.ts
|
|
57
|
+
const useMarkToolbarButtonState = (t0) => {
|
|
58
|
+
const $ = c(7);
|
|
59
|
+
const { clear, nodeType } = t0;
|
|
60
|
+
let t1;
|
|
61
|
+
let t2;
|
|
62
|
+
if ($[0] !== nodeType) {
|
|
63
|
+
t1 = (editor) => editor.api.hasMark(nodeType);
|
|
64
|
+
t2 = [nodeType];
|
|
65
|
+
$[0] = nodeType;
|
|
66
|
+
$[1] = t1;
|
|
67
|
+
$[2] = t2;
|
|
68
|
+
} else {
|
|
69
|
+
t1 = $[1];
|
|
70
|
+
t2 = $[2];
|
|
71
|
+
}
|
|
72
|
+
const pressed = useEditorSelector(t1, t2);
|
|
73
|
+
let t3;
|
|
74
|
+
if ($[3] !== clear || $[4] !== nodeType || $[5] !== pressed) {
|
|
75
|
+
t3 = {
|
|
76
|
+
clear,
|
|
77
|
+
nodeType,
|
|
78
|
+
pressed
|
|
79
|
+
};
|
|
80
|
+
$[3] = clear;
|
|
81
|
+
$[4] = nodeType;
|
|
82
|
+
$[5] = pressed;
|
|
83
|
+
$[6] = t3;
|
|
84
|
+
} else t3 = $[6];
|
|
85
|
+
return t3;
|
|
86
|
+
};
|
|
87
|
+
const useMarkToolbarButton = (state) => {
|
|
88
|
+
const $ = c(7);
|
|
89
|
+
const editor = useEditorRef();
|
|
90
|
+
let t0;
|
|
91
|
+
if ($[0] !== editor || $[1] !== state.clear || $[2] !== state.nodeType) {
|
|
92
|
+
t0 = () => {
|
|
93
|
+
editor.tf.toggleMark(state.nodeType, { remove: state.clear });
|
|
94
|
+
editor.tf.focus();
|
|
95
|
+
};
|
|
96
|
+
$[0] = editor;
|
|
97
|
+
$[1] = state.clear;
|
|
98
|
+
$[2] = state.nodeType;
|
|
99
|
+
$[3] = t0;
|
|
100
|
+
} else t0 = $[3];
|
|
101
|
+
let t1;
|
|
102
|
+
if ($[4] !== state.pressed || $[5] !== t0) {
|
|
103
|
+
t1 = { props: {
|
|
104
|
+
pressed: state.pressed,
|
|
105
|
+
onClick: t0,
|
|
106
|
+
onMouseDown: _temp$3
|
|
107
|
+
} };
|
|
108
|
+
$[4] = state.pressed;
|
|
109
|
+
$[5] = t0;
|
|
110
|
+
$[6] = t1;
|
|
111
|
+
} else t1 = $[6];
|
|
112
|
+
return t1;
|
|
113
|
+
};
|
|
114
|
+
function _temp$3(e) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/react/hooks/useRemoveNodeButton.ts
|
|
120
|
+
const useRemoveNodeButton = (t0) => {
|
|
121
|
+
const $ = c(3);
|
|
122
|
+
const { element } = t0;
|
|
123
|
+
const editor = useEditorRef();
|
|
124
|
+
let t1;
|
|
125
|
+
if ($[0] !== editor || $[1] !== element) {
|
|
126
|
+
t1 = { props: {
|
|
127
|
+
onClick: () => {
|
|
128
|
+
const path = editor.api.findPath(element);
|
|
129
|
+
editor.tf.removeNodes({ at: path });
|
|
130
|
+
},
|
|
131
|
+
onMouseDown: _temp$2
|
|
132
|
+
} };
|
|
133
|
+
$[0] = editor;
|
|
134
|
+
$[1] = element;
|
|
135
|
+
$[2] = t1;
|
|
136
|
+
} else t1 = $[2];
|
|
137
|
+
return t1;
|
|
138
|
+
};
|
|
139
|
+
function _temp$2(e) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/react/hooks/useSelection.ts
|
|
145
|
+
function useSelectionCollapsed() {
|
|
146
|
+
const $ = c(1);
|
|
147
|
+
let t0;
|
|
148
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
149
|
+
t0 = [];
|
|
150
|
+
$[0] = t0;
|
|
151
|
+
} else t0 = $[0];
|
|
152
|
+
return useEditorSelector(_temp$1, t0);
|
|
153
|
+
}
|
|
154
|
+
function _temp$1(editor) {
|
|
155
|
+
return !editor.api.isExpanded();
|
|
156
|
+
}
|
|
157
|
+
function useSelectionExpanded() {
|
|
158
|
+
const $ = c(1);
|
|
159
|
+
let t0;
|
|
160
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
161
|
+
t0 = [];
|
|
162
|
+
$[0] = t0;
|
|
163
|
+
} else t0 = $[0];
|
|
164
|
+
return useEditorSelector(_temp2, t0);
|
|
165
|
+
}
|
|
166
|
+
function _temp2(editor) {
|
|
167
|
+
return editor.api.isExpanded();
|
|
168
|
+
}
|
|
169
|
+
function useSelectionWithinBlock() {
|
|
170
|
+
const $ = c(1);
|
|
171
|
+
let t0;
|
|
172
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
173
|
+
t0 = [];
|
|
174
|
+
$[0] = t0;
|
|
175
|
+
} else t0 = $[0];
|
|
176
|
+
return useEditorSelector(_temp3, t0);
|
|
177
|
+
}
|
|
178
|
+
function _temp3(editor) {
|
|
179
|
+
return editor.api.isAt({ block: true });
|
|
180
|
+
}
|
|
181
|
+
function useSelectionAcrossBlocks() {
|
|
182
|
+
const $ = c(1);
|
|
183
|
+
let t0;
|
|
184
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
185
|
+
t0 = [];
|
|
186
|
+
$[0] = t0;
|
|
187
|
+
} else t0 = $[0];
|
|
188
|
+
return useEditorSelector(_temp4, t0);
|
|
189
|
+
}
|
|
190
|
+
function _temp4(editor) {
|
|
191
|
+
return editor.api.isAt({ blocks: true });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/react/hooks/useSelectionFragment.ts
|
|
196
|
+
const useSelectionFragment = () => {
|
|
197
|
+
const $ = c(1);
|
|
198
|
+
let t0;
|
|
199
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
200
|
+
t0 = [];
|
|
201
|
+
$[0] = t0;
|
|
202
|
+
} else t0 = $[0];
|
|
203
|
+
return useEditorSelector(_temp, t0);
|
|
204
|
+
};
|
|
205
|
+
const useSelectionFragmentProp = (t0) => {
|
|
206
|
+
const $ = c(5);
|
|
207
|
+
let t1;
|
|
208
|
+
if ($[0] !== t0) {
|
|
209
|
+
t1 = t0 === void 0 ? {} : t0;
|
|
210
|
+
$[0] = t0;
|
|
211
|
+
$[1] = t1;
|
|
212
|
+
} else t1 = $[1];
|
|
213
|
+
const options = t1;
|
|
214
|
+
let t2;
|
|
215
|
+
if ($[2] !== options) {
|
|
216
|
+
t2 = (editor) => {
|
|
217
|
+
const fragment = editor.api.fragment(editor.selection, { unwrap: getContainerTypes(editor) });
|
|
218
|
+
return editor.api.prop({
|
|
219
|
+
nodes: fragment,
|
|
220
|
+
...options
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
$[2] = options;
|
|
224
|
+
$[3] = t2;
|
|
225
|
+
} else t2 = $[3];
|
|
226
|
+
let t3;
|
|
227
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
228
|
+
t3 = [];
|
|
229
|
+
$[4] = t3;
|
|
230
|
+
} else t3 = $[4];
|
|
231
|
+
return useEditorSelector(t2, t3);
|
|
232
|
+
};
|
|
233
|
+
function _temp(editor) {
|
|
234
|
+
return editor.api.fragment(editor.selection, { unwrap: getContainerTypes(editor) });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/react/plugins/BlockPlaceholderPlugin.tsx
|
|
239
|
+
const BlockPlaceholderPlugin = createTPlatePlugin({
|
|
240
|
+
key: KEYS.blockPlaceholder,
|
|
241
|
+
editOnly: true,
|
|
242
|
+
options: {
|
|
243
|
+
_target: null,
|
|
244
|
+
placeholders: { [KEYS.p]: "Type something..." },
|
|
245
|
+
query: ({ path }) => path.length === 1
|
|
246
|
+
},
|
|
247
|
+
useHooks: (ctx) => {
|
|
248
|
+
const { editor, getOptions, setOption } = ctx;
|
|
249
|
+
const focused = useFocused();
|
|
250
|
+
const readOnly = useEditorReadOnly();
|
|
251
|
+
const composing = useEditorComposing();
|
|
252
|
+
const entry = useEditorSelector(() => {
|
|
253
|
+
if (readOnly || composing || !focused || !editor.selection || editor.api.isExpanded()) return null;
|
|
254
|
+
return editor.api.block();
|
|
255
|
+
}, [
|
|
256
|
+
readOnly,
|
|
257
|
+
composing,
|
|
258
|
+
focused
|
|
259
|
+
]);
|
|
260
|
+
React.useEffect(() => {
|
|
261
|
+
if (!entry) {
|
|
262
|
+
setOption("_target", null);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const { placeholders, query } = getOptions();
|
|
266
|
+
const [element, path] = entry;
|
|
267
|
+
const placeholder = Object.keys(placeholders).find((key) => editor.getType(key) === element.type);
|
|
268
|
+
if (query({
|
|
269
|
+
...ctx,
|
|
270
|
+
node: element,
|
|
271
|
+
path
|
|
272
|
+
}) && placeholder && editor.api.isEmpty(element) && !editor.api.isEmpty()) setOption("_target", {
|
|
273
|
+
node: element,
|
|
274
|
+
placeholder: placeholders[placeholder]
|
|
275
|
+
});
|
|
276
|
+
else setOption("_target", null);
|
|
277
|
+
}, [
|
|
278
|
+
editor,
|
|
279
|
+
entry,
|
|
280
|
+
setOption,
|
|
281
|
+
getOptions
|
|
282
|
+
]);
|
|
283
|
+
}
|
|
284
|
+
}).extendSelectors(({ getOption }) => ({ placeholder: (node) => {
|
|
285
|
+
const target = getOption("_target");
|
|
286
|
+
if (target?.node === node) return target.placeholder;
|
|
287
|
+
} })).extend({ inject: {
|
|
288
|
+
isBlock: true,
|
|
289
|
+
nodeProps: { transformProps: (props) => {
|
|
290
|
+
const placeholder = usePluginOption(props.plugin, "placeholder", props.element);
|
|
291
|
+
if (placeholder) return {
|
|
292
|
+
className: props.getOption("className"),
|
|
293
|
+
placeholder
|
|
294
|
+
};
|
|
295
|
+
} }
|
|
296
|
+
} });
|
|
297
|
+
|
|
298
|
+
//#endregion
|
|
299
|
+
export { BlockPlaceholderPlugin, useEditorString, useFormInputProps, useMarkToolbarButton, useMarkToolbarButtonState, useRemoveNodeButton, useSelectionAcrossBlocks, useSelectionCollapsed, useSelectionExpanded, useSelectionFragment, useSelectionFragmentProp, useSelectionWithinBlock };
|
|
300
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["useEditorSelector","useEditorString","$","_c","t0","Symbol","for","_temp","editor","api","string","InputProps","preventDefaultOnEnterKeydown","useFormInputProps","options","props","handleEnterKeydownCapture","e","React","KeyboardEvent","HTMLDivElement","key","keyCode","preventDefault","onKeyDownCapture","undefined","useEditorRef","useEditorSelector","useMarkToolbarButtonState","t0","$","_c","clear","nodeType","t1","t2","editor","api","hasMark","pressed","t3","useMarkToolbarButton","state","tf","toggleMark","remove","focus","props","onClick","onMouseDown","_temp","e","preventDefault","useEditorRef","TElement","useRemoveNodeButton","t0","$","_c","element","editor","t1","props","onClick","path","api","findPath","tf","removeNodes","at","onMouseDown","_temp","e","preventDefault","useEditorSelector","useSelectionCollapsed","$","_c","t0","Symbol","for","_temp","editor","api","isExpanded","useSelectionExpanded","_temp2","useSelectionWithinBlock","_temp3","isAt","block","useSelectionAcrossBlocks","_temp4","blocks","getContainerTypes","useEditorSelector","EditorPropOptions","TElement","useSelectionFragment","$","_c","t0","Symbol","for","_temp","useSelectionFragmentProp","t1","undefined","options","t2","editor","fragment","api","selection","unwrap","prop","nodes","t3","PluginConfig","createTPlatePlugin","PlatePluginContext","useEditorComposing","useEditorReadOnly","useEditorSelector","useFocused","usePluginOption","Path","TElement","React","KEYS","BlockPlaceholderConfig","_target","node","placeholder","placeholders","Record","query","context","path","className","BlockPlaceholderPlugin","key","blockPlaceholder","editOnly","options","p","length","useHooks","ctx","editor","getOptions","setOption","focused","readOnly","composing","entry","selection","api","isExpanded","block","useEffect","element","Object","keys","find","getType","type","isEmpty","extendSelectors","getOption","target","extend","inject","isBlock","nodeProps","transformProps","props","plugin"],"sources":["../../src/react/hooks/useEditorString.ts","../../src/react/hooks/useFormInputProps.ts","../../src/react/hooks/useMarkToolbarButton.ts","../../src/react/hooks/useRemoveNodeButton.ts","../../src/react/hooks/useSelection.ts","../../src/react/hooks/useSelectionFragment.ts","../../src/react/plugins/BlockPlaceholderPlugin.tsx"],"sourcesContent":["import { useEditorSelector } from '@platejs/core/react';\n\nexport const useEditorString = () =>\n useEditorSelector((editor) => editor.api.string([]), []);\n","type InputProps = {\n /**\n * Should we activate the onKeyDownCapture handler to preventDefault when the\n * user presses enter?\n */\n preventDefaultOnEnterKeydown?: boolean;\n};\n\n/**\n * Hook to allow the user to spread a set of predefined props to the Div wrapper\n * of an Input element\n *\n * @param param0 An options object which can be expanded to add further\n * functionality\n * @returns A props object which can be spread onto the element\n */\nexport const useFormInputProps = (options?: InputProps) => {\n // Nothing provided to just return an empty object which can still be spread.\n // If we need to add more functionality later we will still be able to do so\n if (!options) return { props: {} };\n\n // Destructure our options so we can use them\n const { preventDefaultOnEnterKeydown } = options;\n\n /**\n * Handle the keydown capture event and prevent the default behaviour when the\n * user presses enter.\n *\n * In the event the user presses enter on a field such as a link, prior to\n * filling in both label and url, the default behaviour is to submit the form.\n * This, ultimately, results in no link being added as you need to fill both\n * fields to pass validation.\n *\n * By calling preventDefault we short circuit the form's submission thus\n * allowing the user to continue filling in the other fields\n *\n * @param e The original event which was provided by the VDOM implement their\n * own behaviour on this event\n */\n const handleEnterKeydownCapture = (\n e: React.KeyboardEvent<HTMLDivElement>\n ) => {\n // Prevent the form from submitting\n if (e.key === 'Enter' || e.keyCode === 13) {\n e.preventDefault();\n }\n };\n\n return {\n props: {\n onKeyDownCapture: preventDefaultOnEnterKeydown\n ? (e: React.KeyboardEvent<HTMLDivElement>) =>\n handleEnterKeydownCapture(e)\n : undefined,\n },\n };\n};\n","import { useEditorRef, useEditorSelector } from '@platejs/core/react';\n\nexport const useMarkToolbarButtonState = ({\n clear,\n nodeType,\n}: {\n nodeType: string;\n clear?: string[] | string;\n}) => {\n const pressed = useEditorSelector(\n (editor) => editor.api.hasMark(nodeType),\n [nodeType]\n );\n\n return {\n clear,\n nodeType,\n pressed,\n };\n};\n\nexport const useMarkToolbarButton = (\n state: ReturnType<typeof useMarkToolbarButtonState>\n) => {\n const editor = useEditorRef();\n\n return {\n props: {\n pressed: state.pressed,\n onClick: () => {\n editor.tf.toggleMark(state.nodeType, { remove: state.clear });\n editor.tf.focus();\n },\n onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => {\n e.preventDefault();\n },\n },\n };\n};\n","import { useEditorRef } from '@platejs/core/react';\nimport type { TElement } from '@platejs/slate';\n\nexport const useRemoveNodeButton = ({ element }: { element: TElement }) => {\n const editor = useEditorRef();\n\n return {\n props: {\n onClick: () => {\n const path = editor.api.findPath(element);\n\n editor.tf.removeNodes({ at: path });\n },\n onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) => {\n e.preventDefault();\n },\n },\n };\n};\n","import { useEditorSelector } from '@platejs/core/react';\n\nexport function useSelectionCollapsed() {\n return useEditorSelector((editor) => !editor.api.isExpanded(), []);\n}\n\nexport function useSelectionExpanded() {\n return useEditorSelector((editor) => editor.api.isExpanded(), []);\n}\n\nexport function useSelectionWithinBlock() {\n return useEditorSelector((editor) => editor.api.isAt({ block: true }), []);\n}\n\nexport function useSelectionAcrossBlocks() {\n return useEditorSelector((editor) => editor.api.isAt({ blocks: true }), []);\n}\n","import { getContainerTypes } from '@platejs/core';\nimport { useEditorSelector } from '@platejs/core/react';\nimport type { EditorPropOptions, TElement } from '@platejs/slate';\n\nexport const useSelectionFragment = () =>\n useEditorSelector(\n (editor) =>\n editor.api.fragment(editor.selection, {\n unwrap: getContainerTypes(editor),\n }),\n []\n );\n\nexport const useSelectionFragmentProp = (\n options: Omit<EditorPropOptions, 'nodes'> = {}\n) =>\n useEditorSelector((editor) => {\n const fragment = editor.api.fragment<TElement>(editor.selection, {\n unwrap: getContainerTypes(editor),\n });\n\n return editor.api.prop({ nodes: fragment, ...options });\n }, []);\n","import type { PluginConfig } from '@platejs/core';\nimport {\n createTPlatePlugin,\n type PlatePluginContext,\n useEditorComposing,\n useEditorReadOnly,\n useEditorSelector,\n useFocused,\n usePluginOption,\n} from '@platejs/core/react';\nimport type { Path, TElement } from '@platejs/slate';\nimport React from 'react';\n\nimport { KEYS } from '../../lib';\n\nexport type BlockPlaceholderConfig = PluginConfig<\n 'blockPlaceholder',\n {\n _target: { node: TElement; placeholder: string } | null;\n placeholders: Record<string, string>;\n query: (\n context: PlatePluginContext<BlockPlaceholderConfig> & {\n node: TElement;\n path: Path;\n }\n ) => boolean;\n className?: string;\n }\n>;\n\nexport const BlockPlaceholderPlugin =\n createTPlatePlugin<BlockPlaceholderConfig>({\n key: KEYS.blockPlaceholder,\n editOnly: true,\n options: {\n _target: null,\n placeholders: {\n [KEYS.p]: 'Type something...',\n },\n query: ({ path }) => path.length === 1,\n },\n useHooks: (ctx) => {\n const { editor, getOptions, setOption } = ctx;\n const focused = useFocused();\n\n const readOnly = useEditorReadOnly();\n const composing = useEditorComposing();\n const entry = useEditorSelector(() => {\n if (\n readOnly ||\n composing ||\n !focused ||\n !editor.selection ||\n editor.api.isExpanded()\n )\n return null;\n\n return editor.api.block();\n }, [readOnly, composing, focused]);\n\n React.useEffect(() => {\n if (!entry) {\n setOption('_target', null);\n return;\n }\n\n const { placeholders, query } = getOptions();\n\n const [element, path] = entry;\n\n // const getPlaceholder = (node: TElement) => {\n // if (node?.listStyleType) {\n // switch (node.listStyleType) {\n // case 'disc':\n // return 'List';\n // break;\n // case 'decimal':\n // return 'List';\n // break;\n // case 'todo':\n // return 'To-do';\n // break;\n // }\n // }\n\n // const key = getPluginKey(editor, node.type);\n // if (!key) return;\n\n // return placeholders?.[key];\n // }\n\n const placeholder = Object.keys(placeholders).find(\n (key) => editor.getType(key) === element.type\n );\n\n if (\n query({ ...ctx, node: element, path }) &&\n placeholder &&\n editor.api.isEmpty(element) &&\n !editor.api.isEmpty()\n ) {\n setOption('_target', {\n node: element,\n placeholder: placeholders[placeholder],\n });\n } else {\n setOption('_target', null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editor, entry, setOption, getOptions]);\n },\n })\n .extendSelectors(({ getOption }) => ({\n placeholder: (node: TElement) => {\n const target = getOption('_target');\n\n if (target?.node === node) {\n return target.placeholder;\n }\n },\n }))\n .extend({\n inject: {\n isBlock: true,\n nodeProps: {\n transformProps: (props) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const placeholder = usePluginOption(\n props.plugin,\n 'placeholder',\n props.element!\n );\n\n if (placeholder) {\n return {\n className: props.getOption('className'),\n placeholder,\n };\n }\n },\n },\n },\n });\n"],"mappings":";;;;;;;AAEA,MAAaC,wBAAkB;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;AAAA,KAAAF,EA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AGP;CACF,EACD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lofcz/platejs-utils",
|
|
3
|
+
"version": "52.3.4",
|
|
4
|
+
"description": "Plate utils",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"plate",
|
|
7
|
+
"plugin",
|
|
8
|
+
"slate"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://platejs.org",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/udecode/plate/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/lofcz/plate.git",
|
|
17
|
+
"directory": "packages/utils"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js",
|
|
23
|
+
"./react": "./dist/react/index.js",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/**/*"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"clsx": "^2.1.1",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"react-compiler-runtime": "^1.0.0",
|
|
35
|
+
"@platejs/core": "npm:@lofcz/platejs-core@52.3.4",
|
|
36
|
+
"@platejs/slate": "npm:@lofcz/platejs-slate@52.3.4",
|
|
37
|
+
"@udecode/utils": "npm:@lofcz/udecode-utils@52.3.4",
|
|
38
|
+
"@udecode/react-utils": "npm:@lofcz/udecode-react-utils@52.3.4"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=18.0.0",
|
|
42
|
+
"react-dom": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"type": "module",
|
|
48
|
+
"module": "./dist/index.js",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@plate/scripts": "1.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"brl": "plate-pkg p:brl",
|
|
54
|
+
"build": "plate-pkg p:build",
|
|
55
|
+
"build:watch": "plate-pkg p:build:watch",
|
|
56
|
+
"clean": "plate-pkg p:clean",
|
|
57
|
+
"lint": "plate-pkg p:lint",
|
|
58
|
+
"lint:fix": "plate-pkg p:lint:fix",
|
|
59
|
+
"test": "plate-pkg p:test",
|
|
60
|
+
"test:watch": "plate-pkg p:test:watch",
|
|
61
|
+
"typecheck": "plate-pkg p:typecheck"
|
|
62
|
+
}
|
|
63
|
+
}
|