@prosekit/core 0.0.16 → 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 }
@@ -261,19 +273,25 @@ declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
261
273
  export { definePlugin }
262
274
  export { definePlugin as definePlugin_alias_1 }
263
275
 
264
- /** @public */
276
+ /**
277
+ * @public
278
+ */
265
279
  declare function defineText(): Extension< {
266
280
  NODES: "text";
267
281
  }>;
268
282
  export { defineText }
269
283
  export { defineText as defineText_alias_1 }
270
284
 
271
- /** @public */
285
+ /**
286
+ * @public
287
+ */
272
288
  declare class Editor<E extends Extension = any> {
273
289
  private instance;
274
290
  private constructor();
275
291
  private afterMounted;
276
- /** @internal */
292
+ /**
293
+ * @internal
294
+ */
277
295
  static create(instance: any): Editor<any>;
278
296
  get mounted(): boolean;
279
297
  get view(): EditorView;
@@ -296,7 +314,9 @@ declare class Editor<E extends Extension = any> {
296
314
  export { Editor }
297
315
  export { Editor as Editor_alias_1 }
298
316
 
299
- /** @public */
317
+ /**
318
+ * @public
319
+ */
300
320
  declare interface EditorOptions<E extends Extension> {
301
321
  /**
302
322
  * The extension to use when creating the editor.
@@ -391,32 +411,48 @@ export declare type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractK
391
411
  */
392
412
  export declare type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
393
413
 
394
- /** @public */
414
+ /**
415
+ * @public
416
+ */
395
417
  declare class Facet<Input, Output> {
396
- /** @internal */
418
+ /**
419
+ * @internal
420
+ */
397
421
  readonly index: number;
398
- /** @internal */
422
+ /**
423
+ * @internal
424
+ */
399
425
  readonly converter: () => FacetConverter<Input, Output>;
400
- /** @internal */
426
+ /**
427
+ * @internal
428
+ */
401
429
  readonly next: Facet<Output, any> | null;
402
- /** @internal */
430
+ /**
431
+ * @internal
432
+ */
403
433
  readonly singleton: boolean;
404
434
  private constructor();
405
435
  static define<Input, Output>({ converter: converter, convert: convert, next, singleton, }: FacetOptions<Input, Output>): Facet<Input, Output>;
406
- /** @internal */
436
+ /**
437
+ * @internal
438
+ */
407
439
  static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
408
440
  extension(payloads: Input[]): FacetExtension<Input, Output>;
409
441
  }
410
442
  export { Facet }
411
443
  export { Facet as Facet_alias_1 }
412
444
 
413
- /** @public */
445
+ /**
446
+ * @public
447
+ */
414
448
  export declare interface FacetConverter<Input = any, Output = any> {
415
449
  create: (inputs: Input[]) => Output;
416
450
  update: (inputs: Input[]) => Output | null;
417
451
  }
418
452
 
419
- /** @public */
453
+ /**
454
+ * @public
455
+ */
420
456
  declare class FacetExtension<Input, Output> {
421
457
  readonly facet: Facet<Input, Output>;
422
458
  readonly payloads: Input[];
@@ -426,7 +462,9 @@ declare class FacetExtension<Input, Output> {
426
462
  export { FacetExtension }
427
463
  export { FacetExtension as FacetExtension_alias_1 }
428
464
 
429
- /** @public */
465
+ /**
466
+ * @public
467
+ */
430
468
  declare interface FacetOptions<Input, Output> {
431
469
  convert?: (payloads: Input[]) => Output;
432
470
  converter?: () => FacetConverter<Input, Output>;
@@ -440,12 +478,16 @@ export declare function getCustomSelection(state: EditorState, from?: number | n
440
478
 
441
479
  export declare function getFacetCount(): number;
442
480
 
443
- /** @internal */
481
+ /**
482
+ * @internal
483
+ */
444
484
  declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
445
485
  export { getMarkType }
446
486
  export { getMarkType as getMarkType_alias_1 }
447
487
 
448
- /** @internal */
488
+ /**
489
+ * @internal
490
+ */
449
491
  declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
450
492
  export { getNodeType }
451
493
  export { getNodeType as getNodeType_alias_1 }
@@ -484,7 +526,9 @@ export declare function isNodeActive(state: EditorState, type: string | NodeType
484
526
 
485
527
  export declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
486
528
 
487
- /** @public */
529
+ /**
530
+ * @public
531
+ */
488
532
  declare interface Keymap {
489
533
  [key: string]: Command;
490
534
  }
@@ -568,12 +612,16 @@ export declare type Payloads = PayloadTuple[];
568
612
 
569
613
  declare type PayloadTuple = Tuple5<Payload[]>;
570
614
 
571
- /** @internal */
615
+ /**
616
+ * @internal
617
+ */
572
618
  declare const pluginFacet: Facet<PluginPayload, StatePayload>;
573
619
  export { pluginFacet }
574
620
  export { pluginFacet as pluginFacet_alias_1 }
575
621
 
576
- /** @internal */
622
+ /**
623
+ * @internal
624
+ */
577
625
  declare type PluginPayload = (context: {
578
626
  schema: Schema;
579
627
  }) => Plugin_2[];
@@ -724,7 +772,9 @@ export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
724
772
 
725
773
  export declare function voidFunction(): void;
726
774
 
727
- /** @public */
775
+ /**
776
+ * @public
777
+ */
728
778
  declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
729
779
  export { withPriority }
730
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");
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.16",
4
+ "version": "0.0.17",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -38,7 +38,7 @@
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
43
  "type-fest": "^4.6.0"
44
44
  },
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'