@examind/block-types 0.1.18

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 (59) hide show
  1. package/README.md +40 -0
  2. package/package.json +21 -0
  3. package/types/examind/index.d.ts +12 -0
  4. package/types/examind/nodes/EssayQuestionNode.ts +16 -0
  5. package/types/examind/nodes/FillInTheBlankQuestionNode.ts +14 -0
  6. package/types/examind/nodes/FillInTheBlankSpaceNode.ts +21 -0
  7. package/types/examind/nodes/FinancialStatementQuestionNode.ts +46 -0
  8. package/types/examind/nodes/HorizontalRuleNode.ts +3 -0
  9. package/types/examind/nodes/ImageNode.ts +18 -0
  10. package/types/examind/nodes/JournalEntryQuestionNode.ts +32 -0
  11. package/types/examind/nodes/MatchingQuestionNode.ts +21 -0
  12. package/types/examind/nodes/MultipleOptionQuestionNode.ts +29 -0
  13. package/types/examind/nodes/ShortAnswerQuestionNode.ts +15 -0
  14. package/types/examind/nodes/SimulationQuestionNode.ts +15 -0
  15. package/types/examind/nodes/VariableNode.ts +24 -0
  16. package/types/index.ts +2 -0
  17. package/types/lexical/LexicalCommands.ts +159 -0
  18. package/types/lexical/LexicalConstants.ts +51 -0
  19. package/types/lexical/LexicalEditor.ts +597 -0
  20. package/types/lexical/LexicalEditorState.ts +30 -0
  21. package/types/lexical/LexicalEvents.ts +13 -0
  22. package/types/lexical/LexicalGC.ts +13 -0
  23. package/types/lexical/LexicalMutations.ts +10 -0
  24. package/types/lexical/LexicalNode.ts +460 -0
  25. package/types/lexical/LexicalNodeState.ts +379 -0
  26. package/types/lexical/LexicalNormalization.ts +9 -0
  27. package/types/lexical/LexicalReconciler.ts +13 -0
  28. package/types/lexical/LexicalSelection.ts +295 -0
  29. package/types/lexical/LexicalUpdateTags.ts +51 -0
  30. package/types/lexical/LexicalUpdates.ts +31 -0
  31. package/types/lexical/LexicalUtils.ts +304 -0
  32. package/types/lexical/index.ts +35 -0
  33. package/types/lexical/link/index.ts +125 -0
  34. package/types/lexical/list/LexicalListItemNode.ts +65 -0
  35. package/types/lexical/list/LexicalListNode.ts +56 -0
  36. package/types/lexical/list/checkList.ts +9 -0
  37. package/types/lexical/list/formatList.ts +69 -0
  38. package/types/lexical/list/index.ts +11 -0
  39. package/types/lexical/list/utils.ts +64 -0
  40. package/types/lexical/nodes/ArtificialNode.ts +12 -0
  41. package/types/lexical/nodes/LexicalDecoratorNode.ts +26 -0
  42. package/types/lexical/nodes/LexicalElementNode.ts +207 -0
  43. package/types/lexical/nodes/LexicalLineBreakNode.ts +25 -0
  44. package/types/lexical/nodes/LexicalParagraphNode.ts +31 -0
  45. package/types/lexical/nodes/LexicalRootNode.ts +30 -0
  46. package/types/lexical/nodes/LexicalTabNode.ts +28 -0
  47. package/types/lexical/nodes/LexicalTextNode.ts +288 -0
  48. package/types/lexical/rich-text/index.ts +53 -0
  49. package/types/lexical/table/LexicalTableCellNode.ts +72 -0
  50. package/types/lexical/table/LexicalTableCommands.ts +17 -0
  51. package/types/lexical/table/LexicalTableNode.ts +65 -0
  52. package/types/lexical/table/LexicalTableObserver.ts +108 -0
  53. package/types/lexical/table/LexicalTablePluginHelpers.ts +25 -0
  54. package/types/lexical/table/LexicalTableRowNode.ts +34 -0
  55. package/types/lexical/table/LexicalTableSelection.ts +74 -0
  56. package/types/lexical/table/LexicalTableSelectionHelpers.ts +40 -0
  57. package/types/lexical/table/LexicalTableUtils.ts +112 -0
  58. package/types/lexical/table/constants.ts +8 -0
  59. package/types/lexical/table/index.ts +16 -0
@@ -0,0 +1,379 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalNode } from './LexicalNode';
8
+ import { NODE_STATE_KEY } from './LexicalConstants';
9
+ /**
10
+ * The return value of {@link createState}, for use with
11
+ * {@link $getState} and {@link $setState}.
12
+ */
13
+ export declare class StateConfig<K extends string, V> {
14
+ /** The string key used when serializing this state to JSON */
15
+ readonly key: K;
16
+ /** The parse function from the StateValueConfig passed to createState */
17
+ readonly parse: (value?: unknown) => V;
18
+ /**
19
+ * The unparse function from the StateValueConfig passed to createState,
20
+ * with a default that is simply a pass-through that assumes the value is
21
+ * JSON serializable.
22
+ */
23
+ readonly unparse: (value: V) => unknown;
24
+ /**
25
+ * An equality function from the StateValueConfig, with a default of
26
+ * Object.is.
27
+ */
28
+ readonly isEqual: (a: V, b: V) => boolean;
29
+ /**
30
+ * The result of `stateValueConfig.parse(undefined)`, which is computed only
31
+ * once and used as the default value. When the current value `isEqual` to
32
+ * the `defaultValue`, it will not be serialized to JSON.
33
+ */
34
+ readonly defaultValue: V;
35
+ constructor(key: K, stateValueConfig: StateValueConfig<V>);
36
+ }
37
+ /**
38
+ * For advanced use cases, using this type is not recommended unless
39
+ * it is required (due to TypeScript's lack of features like
40
+ * higher-kinded types).
41
+ *
42
+ * A {@link StateConfig} type with any key and any value that can be
43
+ * used in situations where the key and value type can not be known,
44
+ * such as in a generic constraint when working with a collection of
45
+ * StateConfig.
46
+ *
47
+ * {@link StateConfigKey} and {@link StateConfigValue} will be
48
+ * useful when this is used as a generic constraint.
49
+ */
50
+ export type AnyStateConfig = StateConfig<any, any>;
51
+ /**
52
+ * Get the value type (V) from a StateConfig
53
+ */
54
+ export type StateConfigValue<S extends AnyStateConfig> = S extends StateConfig<infer _K, infer V> ? V : never;
55
+ /**
56
+ * Get the key type (K) from a StateConfig
57
+ */
58
+ export type StateConfigKey<S extends AnyStateConfig> = S extends StateConfig<infer K, infer _V> ? K : never;
59
+ /**
60
+ * A value type, or an updater for that value type. For use with
61
+ * {@link $setState} or any user-defined wrappers around it.
62
+ */
63
+ export type ValueOrUpdater<V> = V | ((prevValue: V) => V);
64
+ /**
65
+ * Configure a value to be used with StateConfig.
66
+ *
67
+ * The value type should be inferred from the definition of parse.
68
+ *
69
+ * If the value type is not JSON serializable, then unparse must also be provided.
70
+ *
71
+ * Values should be treated as immutable, much like React.useState. Mutating
72
+ * stored values directly will cause unpredictable behavior, is not supported,
73
+ * and may trigger errors in the future.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const numberOrNullState = createState('numberOrNull', {parse: (v) => typeof v === 'number' ? v : null});
78
+ * // ^? State<'numberOrNull', StateValueConfig<number | null>>
79
+ * const numberState = createState('number', {parse: (v) => typeof v === 'number' ? v : 0});
80
+ * // ^? State<'number', StateValueConfig<number>>
81
+ * ```
82
+ *
83
+ * Only the parse option is required, it is generally not useful to
84
+ * override `unparse` or `isEqual`. However, if you are using
85
+ * non-primitive types such as Array, Object, Date, or something
86
+ * more exotic then you would want to override this. In these
87
+ * cases you might want to reach for third party libraries.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const isoDateState = createState('isoDate', {
92
+ * parse: (v): null | Date => {
93
+ * const date = typeof v === 'string' ? new Date(v) : null;
94
+ * return date && !isNaN(date.valueOf()) ? date : null;
95
+ * }
96
+ * isEqual: (a, b) => a === b || (a && b && a.valueOf() === b.valueOf()),
97
+ * unparse: (v) => v && v.toString()
98
+ * });
99
+ * ```
100
+ *
101
+ * You may find it easier to write a parse function using libraries like
102
+ * zod, valibot, ajv, Effect, TypeBox, etc. perhaps with a wrapper function.
103
+ */
104
+ export interface StateValueConfig<V> {
105
+ /**
106
+ * This function must return a default value when called with undefined,
107
+ * otherwise it should parse the given JSON value to your type V. Note
108
+ * that it is not required to copy or clone the given value, you can
109
+ * pass it directly through if it matches the expected type.
110
+ *
111
+ * When you encounter an invalid value, it's up to you to decide
112
+ * as to whether to ignore it and return the default value,
113
+ * return some non-default error value, or throw an error.
114
+ *
115
+ * It is possible for V to include undefined, but if it does, then
116
+ * it should also be considered the default value since undefined
117
+ * can not be serialized to JSON so it is indistinguishable from the
118
+ * default.
119
+ *
120
+ * Similarly, if your V is a function, then usage of {@link $setState}
121
+ * must use an updater function because your type will be indistinguishable
122
+ * from an updater function.
123
+ */
124
+ parse: (jsonValue: unknown) => V;
125
+ /**
126
+ * This is optional and for advanced use cases only.
127
+ *
128
+ * You may specify a function that converts V back to JSON.
129
+ * This is mandatory when V is not a JSON serializable type.
130
+ */
131
+ unparse?: (parsed: V) => unknown;
132
+ /**
133
+ * This is optional and for advanced use cases only.
134
+ *
135
+ * Used to define the equality function so you can use an Array or Object
136
+ * as V and still omit default values from the exported JSON.
137
+ *
138
+ * The default is `Object.is`, but something like `fast-deep-equal` might be
139
+ * more appropriate for your use case.
140
+ */
141
+ isEqual?: (a: V, b: V) => boolean;
142
+ }
143
+ /**
144
+ * Create a StateConfig for the given string key and StateValueConfig.
145
+ *
146
+ * The key must be locally unique. In dev you will get a key collision error
147
+ * when you use two separate StateConfig on the same node with the same key.
148
+ *
149
+ * The returned StateConfig value should be used with {@link $getState} and
150
+ * {@link $setState}.
151
+ *
152
+ * @param key The key to use
153
+ * @param valueConfig Configuration for the value type
154
+ * @returns a StateConfig
155
+ */
156
+ export declare function createState<K extends string, V>(key: K, valueConfig: StateValueConfig<V>): StateConfig<K, V>;
157
+ /**
158
+ * Given two versions of a node and a stateConfig, compare their state values
159
+ * using `$getState(nodeVersion, stateConfig, 'direct')`.
160
+ * If the values are equal according to `stateConfig.isEqual`, return `null`,
161
+ * otherwise return `[value, prevValue]`.
162
+ *
163
+ * This is useful for implementing updateDOM. Note that the `'direct'`
164
+ * version argument is used for both nodes.
165
+ *
166
+ * @param node Any LexicalNode
167
+ * @param prevNode A previous version of node
168
+ * @param stateConfig The configuration of the state to read
169
+ * @returns `[value, prevValue]` if changed, otherwise `null`
170
+ */
171
+ export declare function $getStateChange<T extends LexicalNode, K extends string, V>(node: T, prevNode: T, stateConfig: StateConfig<K, V>): null | [value: V, prevValue: V];
172
+ /**
173
+ * The accessor for working with node state. This will read the value for the
174
+ * state on the given node, and will return `stateConfig.defaultValue` if the
175
+ * state has never been set on this node.
176
+ *
177
+ * The `version` parameter is optional and should generally be `'latest'`,
178
+ * consistent with the behavior of other node methods and functions,
179
+ * but for certain use cases such as `updateDOM` you may have a need to
180
+ * use `'direct'` to read the state from a previous version of the node.
181
+ *
182
+ * For very advanced use cases, you can expect that 'direct' does not
183
+ * require an editor state, just like directly accessing other properties
184
+ * of a node without an accessor (e.g. `textNode.__text`).
185
+ *
186
+ * @param node Any LexicalNode
187
+ * @param stateConfig The configuration of the state to read
188
+ * @param version The default value 'latest' will read the latest version of the node state, 'direct' will read the version that is stored on this LexicalNode which not reflect the version used in the current editor state
189
+ * @returns The current value from the state, or the default value provided by the configuration.
190
+ */
191
+ export declare function $getState<K extends string, V>(node: LexicalNode, stateConfig: StateConfig<K, V>, version?: 'latest' | 'direct'): V;
192
+ /**
193
+ * Set the state defined by stateConfig on node. Like with `React.useState`
194
+ * you may directly specify the value or use an updater function that will
195
+ * be called with the previous value of the state on that node (which will
196
+ * be the `stateConfig.defaultValue` if not set).
197
+ *
198
+ * When an updater function is used, the node will only be marked dirty if
199
+ * `stateConfig.isEqual(prevValue, value)` is false.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const toggle = createState('toggle', {parse: Boolean});
204
+ * // set it direction
205
+ * $setState(node, counterState, true);
206
+ * // use an updater
207
+ * $setState(node, counterState, (prev) => !prev);
208
+ * ```
209
+ *
210
+ * @param node The LexicalNode to set the state on
211
+ * @param stateConfig The configuration for this state
212
+ * @param valueOrUpdater The value or updater function
213
+ * @returns node
214
+ */
215
+ export declare function $setState<Node extends LexicalNode, K extends string, V>(node: Node, stateConfig: StateConfig<K, V>, valueOrUpdater: ValueOrUpdater<V>): Node;
216
+ type KnownStateMap = Map<AnyStateConfig, unknown>;
217
+ type UnknownStateRecord = Record<string, unknown>;
218
+ type SharedConfigMap = Map<string, AnyStateConfig>;
219
+ /**
220
+ * @internal
221
+ */
222
+ export declare class NodeState<T extends LexicalNode> {
223
+ /**
224
+ * @internal
225
+ *
226
+ * Track the (versioned) node that this NodeState was created for, to
227
+ * facilitate copy-on-write for NodeState. When a LexicalNode is cloned,
228
+ * it will *reference* the NodeState from its prevNode. From the nextNode
229
+ * you can continue to read state without copying, but the first $setState
230
+ * will trigger a copy of the prevNode's NodeState with the node property
231
+ * updated.
232
+ */
233
+ readonly node: LexicalNode;
234
+ /**
235
+ * @internal
236
+ *
237
+ * State that has already been parsed in a get state, so it is safe. (can be returned with
238
+ * just a cast since the proof was given before).
239
+ *
240
+ * Note that it uses StateConfig, so in addition to (1) the CURRENT VALUE, it has access to
241
+ * (2) the State key (3) the DEFAULT VALUE and (4) the PARSE FUNCTION
242
+ */
243
+ readonly knownState: KnownStateMap;
244
+ /**
245
+ * @internal
246
+ *
247
+ * A copy of serializedNode[NODE_STATE_KEY] that is made when JSON is
248
+ * imported but has not been parsed yet.
249
+ *
250
+ * It stays here until a get state requires us to parse it, and since we
251
+ * then know the value is safe we move it to knownState and garbage collect
252
+ * it at the next version.
253
+ *
254
+ * Note that since only string keys are used here, we can only allow this
255
+ * state to pass-through on export or on the next version since there is
256
+ * no known value configuration. This pass-through is to support scenarios
257
+ * where multiple versions of the editor code are working in parallel so
258
+ * an old version of your code doesnt erase metadata that was
259
+ * set by a newer version of your code.
260
+ */
261
+ unknownState: undefined | UnknownStateRecord;
262
+ /**
263
+ * @internal
264
+ *
265
+ * This sharedConfigMap is preserved across all versions of a given node and
266
+ * remains writable. It is how keys are resolved to configuration.
267
+ */
268
+ readonly sharedConfigMap: SharedConfigMap;
269
+ /**
270
+ * @internal
271
+ *
272
+ * The count of known or unknown keys in this state, ignoring the
273
+ * intersection between the two sets.
274
+ */
275
+ size: number;
276
+ /**
277
+ * @internal
278
+ */
279
+ constructor(node: T, sharedConfigMap?: SharedConfigMap, unknownState?: undefined | UnknownStateRecord, knownState?: KnownStateMap, size?: number | undefined);
280
+ /** @internal */
281
+ getValue<K extends string, V>(stateConfig: StateConfig<K, V>): V;
282
+ /**
283
+ * @internal
284
+ *
285
+ * Used only for advanced use cases, such as collab. The intent here is to
286
+ * allow you to diff states with a more stable interface than the properties
287
+ * of this class.
288
+ */
289
+ getInternalState(): [
290
+ {
291
+ readonly [k in string]: unknown;
292
+ } | undefined,
293
+ ReadonlyMap<AnyStateConfig, unknown>
294
+ ];
295
+ /**
296
+ * Encode this NodeState to JSON in the format that its node expects.
297
+ * This returns `{[NODE_STATE_KEY]?: UnknownStateRecord}` rather than
298
+ * `UnknownStateRecord | undefined` so that we can support flattening
299
+ * specific entries in the future when nodes can declare what
300
+ * their required StateConfigs are.
301
+ */
302
+ toJSON(): {
303
+ [NODE_STATE_KEY]?: UnknownStateRecord;
304
+ };
305
+ /**
306
+ * @internal
307
+ *
308
+ * A NodeState is writable when the node to update matches
309
+ * the node associated with the NodeState. This basically
310
+ * mirrors how the EditorState NodeMap works, but in a
311
+ * bottom-up organization rather than a top-down organization.
312
+ *
313
+ * This allows us to implement the same "copy on write"
314
+ * pattern for state, without having the state version
315
+ * update every time the node version changes (e.g. when
316
+ * its parent or siblings change).
317
+ *
318
+ * @param node The node to associate with the state
319
+ * @returns The next writable state
320
+ */
321
+ getWritable(node: T): NodeState<T>;
322
+ /** @internal */
323
+ updateFromKnown<K extends string, V>(stateConfig: StateConfig<K, V>, value: V): void;
324
+ /**
325
+ * @internal
326
+ *
327
+ * This is intended for advanced use cases only, such
328
+ * as collab or dev tools.
329
+ *
330
+ * Update a single key value pair from unknown state,
331
+ * parsing it if the key is known to this node. This is
332
+ * basically like updateFromJSON, but the effect is
333
+ * isolated to a single entry.
334
+ *
335
+ * @param k The string key from an UnknownStateRecord
336
+ * @param v The unknown value from an UnknownStateRecord
337
+ */
338
+ updateFromUnknown(k: string, v: unknown): void;
339
+ /**
340
+ * @internal
341
+ *
342
+ * Reset all existing state to default or empty values,
343
+ * and perform any updates from the given unknownState.
344
+ *
345
+ * This is used when initializing a node's state from JSON,
346
+ * or when resetting a node's state from JSON.
347
+ *
348
+ * @param unknownState The new state in serialized form
349
+ */
350
+ updateFromJSON(unknownState: undefined | UnknownStateRecord): void;
351
+ }
352
+ /**
353
+ * @internal
354
+ *
355
+ * Only for direct use in very advanced integrations, such as lexical-yjs.
356
+ * Typically you would only use {@link createState}, {@link $getState}, and
357
+ * {@link $setState}. This is effectively the preamble for {@link $setState}.
358
+ */
359
+ export declare function $getWritableNodeState<T extends LexicalNode>(node: T): NodeState<T>;
360
+ /**
361
+ * @internal
362
+ *
363
+ * This is used to implement LexicalNode.updateFromJSON and is
364
+ * not intended to be exported from the package.
365
+ *
366
+ * @param node any LexicalNode
367
+ * @param unknownState undefined or a serialized State
368
+ * @returns A writable version of node, with the state set.
369
+ */
370
+ export declare function $updateStateFromJSON<T extends LexicalNode>(node: T, unknownState: undefined | UnknownStateRecord): T;
371
+ /**
372
+ * @internal
373
+ *
374
+ * Return true if the two nodes have equivalent NodeState, to be used
375
+ * to determine when TextNode are being merged, not a lot of use cases
376
+ * otherwise.
377
+ */
378
+ export declare function $nodeStatesAreEquivalent<T extends LexicalNode>(a: undefined | NodeState<T>, b: undefined | NodeState<T>): boolean;
379
+ export {};
@@ -0,0 +1,9 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { RangeSelection, TextNode } from '.';
8
+ export declare function $normalizeTextNode(textNode: TextNode): void;
9
+ export declare function $normalizeSelection(selection: RangeSelection): RangeSelection;
@@ -0,0 +1,13 @@
1
+ // THIS FILE IS AUTO-GENERATED
2
+ // To regenerate, run: pnpm build (from the root of the project)
3
+
4
+ // Type definitions based on Lexical
5
+ // Original copyright: Meta Platforms, Inc. and affiliates.
6
+
7
+ import type { LexicalEditor, MutatedNodes } from './LexicalEditor';
8
+ import type { NodeKey } from './LexicalNode';
9
+ import { EditorState } from './LexicalEditorState';
10
+ type IntentionallyMarkedAsDirtyElement = boolean;
11
+ export declare function $reconcileRoot(prevEditorState: EditorState, nextEditorState: EditorState, editor: LexicalEditor, dirtyType: 0 | 1 | 2, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>): MutatedNodes;
12
+ export declare function storeDOMWithKey(key: NodeKey, dom: HTMLElement, editor: LexicalEditor): void;
13
+ export {};