test class replacement
This commit is contained in:
@@ -6,6 +6,8 @@ import Demo from '~/components/Demo'
|
|||||||
import Tab from '~/components/Tab'
|
import Tab from '~/components/Tab'
|
||||||
import ReactRenderer from '~/components/ReactRenderer'
|
import ReactRenderer from '~/components/ReactRenderer'
|
||||||
|
|
||||||
|
import '@tiptap/core/../src/test.ts'
|
||||||
|
|
||||||
export default function (Vue, { router, head, isClient }) {
|
export default function (Vue, { router, head, isClient }) {
|
||||||
Vue.component('Layout', App)
|
Vue.component('Layout', App)
|
||||||
Vue.component('Demo', Demo)
|
Vue.component('Demo', Demo)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
"@types/prosemirror-dropcursor": "^1.0.0",
|
"@types/prosemirror-dropcursor": "^1.0.0",
|
||||||
"@types/prosemirror-gapcursor": "^1.0.1",
|
"@types/prosemirror-gapcursor": "^1.0.1",
|
||||||
"collect.js": "^4.28.2",
|
"collect.js": "^4.28.2",
|
||||||
|
"deepmerge": "^4.2.2",
|
||||||
"prosemirror-commands": "^1.1.3",
|
"prosemirror-commands": "^1.1.3",
|
||||||
"prosemirror-dropcursor": "^1.3.2",
|
"prosemirror-dropcursor": "^1.3.2",
|
||||||
"prosemirror-gapcursor": "^1.1.5",
|
"prosemirror-gapcursor": "^1.1.5",
|
||||||
|
|||||||
169
packages/core/src/test.ts
Normal file
169
packages/core/src/test.ts
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
import { NodeSpec } from "prosemirror-model";
|
||||||
|
import deepmerge from 'deepmerge'
|
||||||
|
|
||||||
|
type RecursivePartial<T> = {
|
||||||
|
[P in keyof T]?:
|
||||||
|
T[P] extends (infer U)[] ? RecursivePartial<U>[] :
|
||||||
|
T[P] extends object ? RecursivePartial<T[P]> :
|
||||||
|
T[P];
|
||||||
|
}
|
||||||
|
|
||||||
|
type Extension<Options = any> = {
|
||||||
|
name: string
|
||||||
|
defaultOptions?: Options | (() => Options)
|
||||||
|
bla?: number[] | ((this: ExtensionOptions<Options>) => number[])
|
||||||
|
blub?: number[] | (() => number[])
|
||||||
|
schema?: () => NodeSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExtensionOptions<T> = {
|
||||||
|
options: T
|
||||||
|
}
|
||||||
|
|
||||||
|
function Extension<Options>(config: Extension<Options>) {
|
||||||
|
const instance = (options: Options) => {
|
||||||
|
const extensionInstance = {
|
||||||
|
...config,
|
||||||
|
options,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof extensionInstance.name === 'function') {
|
||||||
|
// @ts-ignore
|
||||||
|
extensionInstance.name()
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensionInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.extend = (extendConfig: RecursivePartial<Extension>) => {
|
||||||
|
return Extension<Options>(deepmerge({...config}, {...extendConfig}) as Extension)
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
type HeadingOptions = {
|
||||||
|
levels?: number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const Heading = Extension<HeadingOptions>({
|
||||||
|
name: 'heading',
|
||||||
|
defaultOptions: {
|
||||||
|
levels: [1, 2, 3, 4, 5, 6],
|
||||||
|
},
|
||||||
|
schema() {
|
||||||
|
return {
|
||||||
|
defining: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Heading
|
||||||
|
const h = Heading.extend({
|
||||||
|
name: '123',
|
||||||
|
})({
|
||||||
|
levels: [1, 2]
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log({h})
|
||||||
|
|
||||||
|
// const bla = Extension(options => {
|
||||||
|
// name: 'heading',
|
||||||
|
// bla: () => {
|
||||||
|
// return [1, 2]
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
|
||||||
|
// const Heading1 = Heading.extend({
|
||||||
|
// name: 'heading 1'
|
||||||
|
// })
|
||||||
|
|
||||||
|
// console.log(Heading(1), Heading1(2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// interface ExtenstionClass<T> {
|
||||||
|
// new (options?: T): ExtenstionClass<T>
|
||||||
|
// name?: string
|
||||||
|
// bla?: number[] | (() => number[])
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // class ExtenstionClass implements ExtenstionClass {
|
||||||
|
// class ExtenstionClass<T> {
|
||||||
|
// // name: '124'
|
||||||
|
|
||||||
|
// // bla() {
|
||||||
|
// // return [1, 2]
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// class Whatever extends ExtenstionClass<HeadingOptions> {
|
||||||
|
// name: '1243'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// new Whatever({
|
||||||
|
// bla: 124,
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// interface ExxxtensionConstructor<T> {
|
||||||
|
// new (options: Partial<T>): any
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface Exxxtension {
|
||||||
|
// name: string
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const Exxxtension: ExxxtensionConstructor<HeadingOptions> = class Exxxtension implements Exxxtension {
|
||||||
|
// name = '1'
|
||||||
|
// };
|
||||||
|
|
||||||
|
// new Exxxtension({
|
||||||
|
// levels: [1, 2],
|
||||||
|
// // test: 'bla',
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// interface ExxxtensionConstructor<T> {
|
||||||
|
// new (options: Partial<T>): any
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface Exxxtension {
|
||||||
|
// name: string
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface NodeExtension extends Exxxtension {
|
||||||
|
// schema(): NodeSpec
|
||||||
|
// what: number
|
||||||
|
// }
|
||||||
|
|
||||||
|
// class Exxxtension implements Exxxtension {
|
||||||
|
// // public topNode = false
|
||||||
|
// }
|
||||||
|
|
||||||
|
// class NodeExtension implements NodeExtension {
|
||||||
|
// // public topNode = false
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const HeadingNode: ExxxtensionConstructor<HeadingOptions> = class HeadingNode extends NodeExtension implements NodeExtension {
|
||||||
|
// name = 'heading'
|
||||||
|
|
||||||
|
// // what = 's'
|
||||||
|
|
||||||
|
// schema() {
|
||||||
|
// return {
|
||||||
|
// defining: true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// new HeadingNode({
|
||||||
|
// levels: [1, 2],
|
||||||
|
// // test: 'bla',
|
||||||
|
// })
|
||||||
Reference in New Issue
Block a user