@prosekit/core 0.0.15 → 0.0.17

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.
@@ -56,6 +56,8 @@ export declare function applyAction(operator: Action): Command;
56
56
  */
57
57
  export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
58
58
 
59
+ export declare function attrsMatch(nodeOrMark: ProseMirrorNode | Mark, attrs: Attrs): boolean;
60
+
59
61
  export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
60
62
 
61
63
  export declare interface CommandApplier<Args extends any[] = any[]> {
@@ -63,7 +65,9 @@ export declare interface CommandApplier<Args extends any[] = any[]> {
63
65
  canApply(...args: Args): boolean;
64
66
  }
65
67
 
66
- /** @internal */
68
+ /**
69
+ * @internal
70
+ */
67
71
  declare interface CommandArgs {
68
72
  [name: string]: any[];
69
73
  }
@@ -84,7 +88,9 @@ export declare type Converters = ConverterTuple[];
84
88
 
85
89
  declare type ConverterTuple = Tuple5<FacetConverter | undefined>;
86
90
 
87
- /** @public */
91
+ /**
92
+ * @public
93
+ */
88
94
  declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;
89
95
  export { createEditor }
90
96
  export { createEditor as createEditor_alias_1 }
@@ -142,7 +148,9 @@ declare function defineBaseCommands(): Extension<{
142
148
  export { defineBaseCommands }
143
149
  export { defineBaseCommands as defineBaseCommands_alias_1 }
144
150
 
145
- /** @public */
151
+ /**
152
+ * @public
153
+ */
146
154
  declare function defineBaseKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
147
155
  export { defineBaseKeymap }
148
156
  export { defineBaseKeymap as defineBaseKeymap_alias_1 }
@@ -159,7 +167,9 @@ declare function defineDefaultState(options: DefaultStateOptions): Extension;
159
167
  export { defineDefaultState }
160
168
  export { defineDefaultState as defineDefaultState_alias_1 }
161
169
 
162
- /** @public */
170
+ /**
171
+ * @public
172
+ */
163
173
  declare function defineDoc(): Extension< {
164
174
  NODES: "doc";
165
175
  }>;
@@ -196,7 +206,9 @@ declare function defineInputRule(rules: (context: {
196
206
  export { defineInputRule }
197
207
  export { defineInputRule as defineInputRule_alias_1 }
198
208
 
199
- /** @public */
209
+ /**
210
+ * @public
211
+ */
200
212
  declare function defineKeymap(keymap: Keymap): Extension;
201
213
  export { defineKeymap }
202
214
  export { defineKeymap as defineKeymap_alias_1 }
@@ -227,13 +239,26 @@ declare function defineNodeViewEffect(options: NodeViewEffectOptions): Extension
227
239
  export { defineNodeViewEffect }
228
240
  export { defineNodeViewEffect as defineNodeViewEffect_alias_1 }
229
241
 
230
- /** @public */
242
+ /**
243
+ * @public
244
+ *
245
+ * Defines a paragraph node spec as the highest priority, because it should be the default block node for most cases.
246
+ */
231
247
  declare function defineParagraph(): Extension< {
232
248
  NODES: "paragraph";
233
249
  }>;
234
250
  export { defineParagraph }
235
251
  export { defineParagraph as defineParagraph_alias_1 }
236
252
 
253
+ /**
254
+ * @public
255
+ *
256
+ * Defines a paragraph node spec.
257
+ */
258
+ export declare function defineParagraphSpec(): Extension< {
259
+ NODES: "paragraph";
260
+ }>;
261
+
237
262
  /**
238
263
  * Adds a ProseMirror plugin to the editor.
239
264
  *
@@ -248,19 +273,25 @@ declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
248
273
  export { definePlugin }
249
274
  export { definePlugin as definePlugin_alias_1 }
250
275
 
251
- /** @public */
276
+ /**
277
+ * @public
278
+ */
252
279
  declare function defineText(): Extension< {
253
280
  NODES: "text";
254
281
  }>;
255
282
  export { defineText }
256
283
  export { defineText as defineText_alias_1 }
257
284
 
258
- /** @public */
285
+ /**
286
+ * @public
287
+ */
259
288
  declare class Editor<E extends Extension = any> {
260
289
  private instance;
261
290
  private constructor();
262
291
  private afterMounted;
263
- /** @internal */
292
+ /**
293
+ * @internal
294
+ */
264
295
  static create(instance: any): Editor<any>;
265
296
  get mounted(): boolean;
266
297
  get view(): EditorView;
@@ -283,7 +314,9 @@ declare class Editor<E extends Extension = any> {
283
314
  export { Editor }
284
315
  export { Editor as Editor_alias_1 }
285
316
 
286
- /** @public */
317
+ /**
318
+ * @public
319
+ */
287
320
  declare interface EditorOptions<E extends Extension> {
288
321
  /**
289
322
  * The extension to use when creating the editor.
@@ -378,32 +411,48 @@ export declare type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractK
378
411
  */
379
412
  export declare type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
380
413
 
381
- /** @public */
414
+ /**
415
+ * @public
416
+ */
382
417
  declare class Facet<Input, Output> {
383
- /** @internal */
418
+ /**
419
+ * @internal
420
+ */
384
421
  readonly index: number;
385
- /** @internal */
422
+ /**
423
+ * @internal
424
+ */
386
425
  readonly converter: () => FacetConverter<Input, Output>;
387
- /** @internal */
426
+ /**
427
+ * @internal
428
+ */
388
429
  readonly next: Facet<Output, any> | null;
389
- /** @internal */
430
+ /**
431
+ * @internal
432
+ */
390
433
  readonly singleton: boolean;
391
434
  private constructor();
392
435
  static define<Input, Output>({ converter: converter, convert: convert, next, singleton, }: FacetOptions<Input, Output>): Facet<Input, Output>;
393
- /** @internal */
436
+ /**
437
+ * @internal
438
+ */
394
439
  static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
395
440
  extension(payloads: Input[]): FacetExtension<Input, Output>;
396
441
  }
397
442
  export { Facet }
398
443
  export { Facet as Facet_alias_1 }
399
444
 
400
- /** @public */
445
+ /**
446
+ * @public
447
+ */
401
448
  export declare interface FacetConverter<Input = any, Output = any> {
402
449
  create: (inputs: Input[]) => Output;
403
450
  update: (inputs: Input[]) => Output | null;
404
451
  }
405
452
 
406
- /** @public */
453
+ /**
454
+ * @public
455
+ */
407
456
  declare class FacetExtension<Input, Output> {
408
457
  readonly facet: Facet<Input, Output>;
409
458
  readonly payloads: Input[];
@@ -413,7 +462,9 @@ declare class FacetExtension<Input, Output> {
413
462
  export { FacetExtension }
414
463
  export { FacetExtension as FacetExtension_alias_1 }
415
464
 
416
- /** @public */
465
+ /**
466
+ * @public
467
+ */
417
468
  declare interface FacetOptions<Input, Output> {
418
469
  convert?: (payloads: Input[]) => Output;
419
470
  converter?: () => FacetConverter<Input, Output>;
@@ -427,12 +478,16 @@ export declare function getCustomSelection(state: EditorState, from?: number | n
427
478
 
428
479
  export declare function getFacetCount(): number;
429
480
 
430
- /** @internal */
481
+ /**
482
+ * @internal
483
+ */
431
484
  declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
432
485
  export { getMarkType }
433
486
  export { getMarkType as getMarkType_alias_1 }
434
487
 
435
- /** @internal */
488
+ /**
489
+ * @internal
490
+ */
436
491
  declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
437
492
  export { getNodeType }
438
493
  export { getNodeType as getNodeType_alias_1 }
@@ -471,7 +526,9 @@ export declare function isNodeActive(state: EditorState, type: string | NodeType
471
526
 
472
527
  export declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
473
528
 
474
- /** @public */
529
+ /**
530
+ * @public
531
+ */
475
532
  declare interface Keymap {
476
533
  [key: string]: Command;
477
534
  }
@@ -555,12 +612,16 @@ export declare type Payloads = PayloadTuple[];
555
612
 
556
613
  declare type PayloadTuple = Tuple5<Payload[]>;
557
614
 
558
- /** @internal */
615
+ /**
616
+ * @internal
617
+ */
559
618
  declare const pluginFacet: Facet<PluginPayload, StatePayload>;
560
619
  export { pluginFacet }
561
620
  export { pluginFacet as pluginFacet_alias_1 }
562
621
 
563
- /** @internal */
622
+ /**
623
+ * @internal
624
+ */
564
625
  declare type PluginPayload = (context: {
565
626
  schema: Schema;
566
627
  }) => Plugin_2[];
@@ -711,7 +772,9 @@ export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
711
772
 
712
773
  export declare function voidFunction(): void;
713
774
 
714
- /** @public */
775
+ /**
776
+ * @public
777
+ */
715
778
  declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
716
779
  export { withPriority }
717
780
  export { withPriority as withPriority_alias_1 }
@@ -154,30 +154,11 @@ import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
154
154
  import "@prosekit/pm/model";
155
155
  import "@prosekit/pm/state";
156
156
 
157
- // src/utils/object-euqal.ts
158
- function objectEqual(a, b) {
159
- if (a === b) {
160
- return true;
161
- }
162
- if (typeof a !== "object" || typeof b !== "object") {
163
- return false;
164
- }
165
- if (a === null || b === null) {
166
- return false;
167
- }
168
- if (Array.isArray(a) || Array.isArray(b)) {
169
- return false;
170
- }
171
- const aKeys = Object.keys(a);
172
- const bKeys = Object.keys(b);
173
- if (aKeys.length !== bKeys.length) {
174
- return false;
175
- }
176
- for (const key of aKeys) {
177
- if (!bKeys.includes(key)) {
178
- return false;
179
- }
180
- if (!objectEqual(a[key], b[key])) {
157
+ // src/utils/attrs-match.ts
158
+ function attrsMatch(nodeOrMark, attrs) {
159
+ const currentAttrs = nodeOrMark.attrs;
160
+ for (const [key, value] of Object.entries(attrs)) {
161
+ if (currentAttrs[key] !== value) {
181
162
  return false;
182
163
  }
183
164
  }
@@ -190,7 +171,7 @@ function isNodeActive(state, type, attrs) {
190
171
  const nodeType = getNodeType(state.schema, type);
191
172
  for (let depth = $pos.depth; depth >= 0; depth--) {
192
173
  const node = $pos.node(depth);
193
- if (node.type === nodeType && (!attrs || objectEqual(attrs, node.attrs))) {
174
+ if (node.type === nodeType && (!attrs || attrsMatch(node, attrs))) {
194
175
  return true;
195
176
  }
196
177
  }
@@ -252,7 +233,9 @@ function getFacetCount() {
252
233
  }
253
234
  var Facet = class _Facet {
254
235
  constructor(converter, next, singleton) {
255
- /** @internal */
236
+ /**
237
+ * @internal
238
+ */
256
239
  this.index = facetCount++;
257
240
  this.converter = converter;
258
241
  this.next = next;
@@ -273,7 +256,9 @@ var Facet = class _Facet {
273
256
  }
274
257
  return new _Facet(converterFunction, next, singleton != null ? singleton : false);
275
258
  }
276
- /** @internal */
259
+ /**
260
+ * @internal
261
+ */
277
262
  static defineRootFacet(options) {
278
263
  return _Facet.define(options);
279
264
  }
@@ -805,7 +790,9 @@ var Editor = class _Editor {
805
790
  this.unmount = this.unmount.bind(this);
806
791
  this.use = this.use.bind(this);
807
792
  }
808
- /** @internal */
793
+ /**
794
+ * @internal
795
+ */
809
796
  static create(instance) {
810
797
  if (!(instance instanceof EditorInstance)) {
811
798
  throw new TypeError("Invalid EditorInstance");
@@ -979,7 +966,8 @@ var nodeSpecFacet = Facet.define({
979
966
  function defineDoc() {
980
967
  return defineNodeSpec({
981
968
  name: "doc",
982
- content: "block+"
969
+ content: "block+",
970
+ topNode: true
983
971
  });
984
972
  }
985
973
 
@@ -1220,7 +1208,7 @@ var nodeViewEffectFacet = Facet.define({
1220
1208
  });
1221
1209
 
1222
1210
  // src/extensions/paragraph.ts
1223
- function defineParagraph() {
1211
+ function defineParagraphSpec() {
1224
1212
  return defineNodeSpec({
1225
1213
  name: "paragraph",
1226
1214
  content: "inline*",
@@ -1231,6 +1219,9 @@ function defineParagraph() {
1231
1219
  }
1232
1220
  });
1233
1221
  }
1222
+ function defineParagraph() {
1223
+ return withPriority(defineParagraphSpec(), 0 /* highest */);
1224
+ }
1234
1225
 
1235
1226
  // src/extensions/text.ts
1236
1227
  function defineText() {
package/dist/style.css CHANGED
@@ -1,4 +1,4 @@
1
- /* ../../node_modules/.pnpm/prosemirror-view@1.32.1/node_modules/prosemirror-view/style/prosemirror.css */
1
+ /* ../../node_modules/.pnpm/prosemirror-view@1.32.3/node_modules/prosemirror-view/style/prosemirror.css */
2
2
  .ProseMirror {
3
3
  position: relative;
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.17",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -38,9 +38,9 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@prosekit/pm": "^0.0.6",
41
+ "@prosekit/pm": "^0.0.7",
42
42
  "orderedmap": "^2.1.1",
43
- "type-fest": "^4.5.0"
43
+ "type-fest": "^4.6.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@prosekit/dev": "*",
package/src/index.ts DELETED
@@ -1,53 +0,0 @@
1
- export { addMark } from './commands/add-mark'
2
- export { insertNode } from './commands/insert-node'
3
- export { setBlockType } from './commands/set-block-type'
4
- export { toggleMark } from './commands/toggle-mark'
5
- export { toggleNode } from './commands/toggle-node'
6
- export { Editor, createEditor, type EditorOptions } from './editor/editor'
7
- export { union } from './editor/type-utils'
8
- export { withPriority } from './editor/with-priority'
9
- export { ProseKitError } from './error'
10
- export { defineBaseCommands, defineCommands } from './extensions/command'
11
- export {
12
- defineDefaultState,
13
- type DefaultStateOptions,
14
- } from './extensions/default-state'
15
- export { defineDoc } from './extensions/doc'
16
- export { defineEventHandler } from './extensions/event-handler'
17
- export { defineHistory } from './extensions/history'
18
- export { defineInputRule } from './extensions/input-rules'
19
- export {
20
- defineBaseKeymap,
21
- defineKeymap,
22
- type Keymap,
23
- } from './extensions/keymap'
24
- export { defineMarkSpec, type MarkSpecOptions } from './extensions/mark-spec'
25
- export { defineNodeSpec, type NodeSpecOptions } from './extensions/node-spec'
26
- export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
27
- export {
28
- defineNodeViewEffect,
29
- type NodeViewEffectOptions,
30
- } from './extensions/node-view-effect'
31
- export { defineParagraph } from './extensions/paragraph'
32
- export {
33
- definePlugin,
34
- pluginFacet,
35
- type PluginPayload,
36
- } from './extensions/plugin'
37
- export { defineText } from './extensions/text'
38
- export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
39
- export { type CommandArgs as CommandArgs } from './types/command'
40
- export {
41
- type Extension,
42
- type ExtractCommandAppliers,
43
- type ExtractCommandCreators,
44
- type ExtractMarks,
45
- type ExtractNodes,
46
- type SimplifyExtension,
47
- } from './types/extension'
48
- export { type ExtensionTyping } from './types/extension-typing'
49
- export type { NodeJson, SelectionJson, StateJson } from './types/model'
50
- export { Priority } from './types/priority'
51
- export { type SimplifyUnion } from './types/simplify-union'
52
- export { getMarkType } from './utils/get-mark-type'
53
- export { getNodeType } from './utils/get-node-type'