@tiptap/core 3.0.0-beta.15 → 3.0.0-beta.16

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "3.0.0-beta.15",
4
+ "version": "3.0.0-beta.16",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -52,10 +52,10 @@
52
52
  "jsx-dev-runtime"
53
53
  ],
54
54
  "devDependencies": {
55
- "@tiptap/pm": "3.0.0-beta.15"
55
+ "@tiptap/pm": "3.0.0-beta.16"
56
56
  },
57
57
  "peerDependencies": {
58
- "@tiptap/pm": "3.0.0-beta.15"
58
+ "@tiptap/pm": "3.0.0-beta.16"
59
59
  },
60
60
  "repository": {
61
61
  "type": "git",
package/src/Extension.ts CHANGED
@@ -15,8 +15,16 @@ export class Extension<Options = any, Storage = any> extends Extendable<
15
15
  > {
16
16
  type = 'extension'
17
17
 
18
- static create<O = any, S = any>(config: Partial<ExtensionConfig<O, S>> = {}) {
19
- return new Extension<O, S>(config)
18
+ /**
19
+ * Create a new Extension instance
20
+ * @param config - Extension configuration object or a function that returns a configuration object
21
+ */
22
+ static create<O = any, S = any>(
23
+ config: Partial<ExtensionConfig<O, S>> | (() => Partial<ExtensionConfig<O, S>>) = {},
24
+ ) {
25
+ // If the config is a function, execute it to get the configuration object
26
+ const resolvedConfig = typeof config === 'function' ? config() : config
27
+ return new Extension<O, S>(resolvedConfig)
20
28
  }
21
29
 
22
30
  configure(options?: Partial<Options>) {
@@ -27,7 +35,9 @@ export class Extension<Options = any, Storage = any> extends Extendable<
27
35
  ExtendedOptions = Options,
28
36
  ExtendedStorage = Storage,
29
37
  ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>,
30
- >(extendedConfig?: Partial<ExtendedConfig>) {
31
- return super.extend(extendedConfig) as Extension<ExtendedOptions, ExtendedStorage>
38
+ >(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)) {
39
+ // If the extended config is a function, execute it to get the configuration object
40
+ const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig
41
+ return super.extend(resolvedConfig) as Extension<ExtendedOptions, ExtendedStorage>
32
42
  }
33
43
  }
package/src/Mark.ts CHANGED
@@ -146,8 +146,14 @@ export interface MarkConfig<Options = any, Storage = any>
146
146
  export class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {
147
147
  type = 'mark'
148
148
 
149
- static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> = {}) {
150
- return new Mark<O, S>(config)
149
+ /**
150
+ * Create a new Mark instance
151
+ * @param config - Mark configuration object or a function that returns a configuration object
152
+ */
153
+ static create<O = any, S = any>(config: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>) = {}) {
154
+ // If the config is a function, execute it to get the configuration object
155
+ const resolvedConfig = typeof config === 'function' ? config() : config
156
+ return new Mark<O, S>(resolvedConfig)
151
157
  }
152
158
 
153
159
  static handleExit({ editor, mark }: { editor: Editor; mark: Mark }) {
@@ -186,7 +192,9 @@ export class Mark<Options = any, Storage = any> extends Extendable<Options, Stor
186
192
  ExtendedOptions = Options,
187
193
  ExtendedStorage = Storage,
188
194
  ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>,
189
- >(extendedConfig?: Partial<ExtendedConfig>) {
190
- return super.extend(extendedConfig) as Mark<ExtendedOptions, ExtendedStorage>
195
+ >(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)) {
196
+ // If the extended config is a function, execute it to get the configuration object
197
+ const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig
198
+ return super.extend(resolvedConfig) as Mark<ExtendedOptions, ExtendedStorage>
191
199
  }
192
200
  }
package/src/Node.ts CHANGED
@@ -340,8 +340,14 @@ export interface NodeConfig<Options = any, Storage = any>
340
340
  export class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
341
341
  type = 'node'
342
342
 
343
- static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> = {}) {
344
- return new Node<O, S>(config)
343
+ /**
344
+ * Create a new Node instance
345
+ * @param config - Node configuration object or a function that returns a configuration object
346
+ */
347
+ static create<O = any, S = any>(config: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>) = {}) {
348
+ // If the config is a function, execute it to get the configuration object
349
+ const resolvedConfig = typeof config === 'function' ? config() : config
350
+ return new Node<O, S>(resolvedConfig)
345
351
  }
346
352
 
347
353
  configure(options?: Partial<Options>) {
@@ -352,7 +358,9 @@ export class Node<Options = any, Storage = any> extends Extendable<Options, Stor
352
358
  ExtendedOptions = Options,
353
359
  ExtendedStorage = Storage,
354
360
  ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>,
355
- >(extendedConfig?: Partial<ExtendedConfig>) {
356
- return super.extend(extendedConfig) as Node<ExtendedOptions, ExtendedStorage>
361
+ >(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)) {
362
+ // If the extended config is a function, execute it to get the configuration object
363
+ const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig
364
+ return super.extend(resolvedConfig) as Node<ExtendedOptions, ExtendedStorage>
357
365
  }
358
366
  }
@@ -182,8 +182,9 @@ export const insertContentAt: RawCommands['insertContentAt'] =
182
182
 
183
183
  const fromSelectionAtStart = selection.$from.parentOffset === 0
184
184
  const isTextSelection = selection.$from.node().isText || selection.$from.node().isTextblock
185
+ const hasContent = selection.$from.node().content.size > 0
185
186
 
186
- if (fromSelectionAtStart && isTextSelection) {
187
+ if (fromSelectionAtStart && isTextSelection && hasContent) {
187
188
  from = Math.max(0, from - 1)
188
189
  }
189
190