@prosekit/solid 0.7.0-beta.0 → 0.7.0-beta.2

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 (124) hide show
  1. package/dist/prosekit-solid-autocomplete.d.ts +225 -19
  2. package/dist/prosekit-solid-autocomplete.d.ts.map +1 -1
  3. package/dist/prosekit-solid-autocomplete.js +204 -9
  4. package/dist/prosekit-solid-autocomplete.js.map +1 -1
  5. package/dist/prosekit-solid-block-handle.d.ts +209 -15
  6. package/dist/prosekit-solid-block-handle.d.ts.map +1 -1
  7. package/dist/prosekit-solid-block-handle.js +160 -7
  8. package/dist/prosekit-solid-block-handle.js.map +1 -1
  9. package/dist/prosekit-solid-drop-indicator.d.ts +26 -7
  10. package/dist/prosekit-solid-drop-indicator.d.ts.map +1 -1
  11. package/dist/prosekit-solid-drop-indicator.js +29 -3
  12. package/dist/prosekit-solid-drop-indicator.js.map +1 -1
  13. package/dist/prosekit-solid-inline-popover.d.ts +203 -9
  14. package/dist/prosekit-solid-inline-popover.d.ts.map +1 -1
  15. package/dist/prosekit-solid-inline-popover.js +128 -5
  16. package/dist/prosekit-solid-inline-popover.js.map +1 -1
  17. package/dist/prosekit-solid-menu.d.ts +287 -0
  18. package/dist/prosekit-solid-menu.d.ts.map +1 -0
  19. package/dist/prosekit-solid-menu.js +241 -0
  20. package/dist/prosekit-solid-menu.js.map +1 -0
  21. package/dist/prosekit-solid-popover.d.ts +226 -15
  22. package/dist/prosekit-solid-popover.d.ts.map +1 -1
  23. package/dist/prosekit-solid-popover.js +165 -7
  24. package/dist/prosekit-solid-popover.js.map +1 -1
  25. package/dist/prosekit-solid-resizable.d.ts +55 -13
  26. package/dist/prosekit-solid-resizable.d.ts.map +1 -1
  27. package/dist/prosekit-solid-resizable.js +69 -7
  28. package/dist/prosekit-solid-resizable.js.map +1 -1
  29. package/dist/prosekit-solid-table-handle.d.ts +446 -39
  30. package/dist/prosekit-solid-table-handle.d.ts.map +1 -1
  31. package/dist/prosekit-solid-table-handle.js +334 -19
  32. package/dist/prosekit-solid-table-handle.js.map +1 -1
  33. package/dist/prosekit-solid-tooltip.d.ts +210 -15
  34. package/dist/prosekit-solid-tooltip.d.ts.map +1 -1
  35. package/dist/prosekit-solid-tooltip.js +149 -7
  36. package/dist/prosekit-solid-tooltip.js.map +1 -1
  37. package/dist/prosekit-solid.d.ts +23 -2
  38. package/dist/prosekit-solid.d.ts.map +1 -1
  39. package/dist/prosekit-solid.js +37 -6
  40. package/dist/prosekit-solid.js.map +1 -1
  41. package/package.json +28 -16
  42. package/src/components/autocomplete/autocomplete-empty.gen.ts +22 -24
  43. package/src/components/autocomplete/autocomplete-item.gen.ts +82 -26
  44. package/src/components/autocomplete/autocomplete-popup.gen.ts +78 -0
  45. package/src/components/autocomplete/autocomplete-positioner.gen.ts +167 -0
  46. package/src/components/autocomplete/autocomplete-root.gen.ts +110 -0
  47. package/src/components/autocomplete/index.gen.ts +12 -4
  48. package/src/components/autocomplete/index.ts +27 -0
  49. package/src/components/block-handle/block-handle-add.gen.ts +54 -26
  50. package/src/components/block-handle/block-handle-draggable.gen.ts +54 -26
  51. package/src/components/block-handle/block-handle-popup.gen.ts +27 -0
  52. package/src/components/block-handle/block-handle-positioner.gen.ts +185 -0
  53. package/src/components/block-handle/block-handle-root.gen.ts +82 -0
  54. package/src/components/block-handle/index.gen.ts +13 -3
  55. package/src/components/block-handle/index.ts +27 -0
  56. package/src/components/drop-indicator/drop-indicator.gen.ts +60 -26
  57. package/src/components/drop-indicator/index.gen.ts +5 -1
  58. package/src/components/drop-indicator/index.ts +14 -0
  59. package/src/components/inline-popover/index.gen.ts +11 -1
  60. package/src/components/inline-popover/index.ts +22 -0
  61. package/src/components/inline-popover/inline-popover-popup.gen.ts +27 -0
  62. package/src/components/inline-popover/inline-popover-positioner.gen.ts +191 -0
  63. package/src/components/inline-popover/inline-popover-root.gen.ts +106 -0
  64. package/src/components/menu/index.gen.ts +19 -0
  65. package/src/components/menu/index.ts +37 -0
  66. package/src/components/menu/menu-item.gen.ts +89 -0
  67. package/src/components/menu/menu-popup.gen.ts +53 -0
  68. package/src/components/menu/menu-positioner.gen.ts +192 -0
  69. package/src/components/menu/menu-root.gen.ts +86 -0
  70. package/src/components/menu/menu-submenu-root.gen.ts +27 -0
  71. package/src/components/menu/menu-submenu-trigger.gen.ts +27 -0
  72. package/src/components/menu/menu-trigger.gen.ts +77 -0
  73. package/src/components/popover/index.gen.ts +11 -3
  74. package/src/components/popover/index.ts +24 -0
  75. package/src/components/popover/popover-popup.gen.ts +27 -0
  76. package/src/components/popover/popover-positioner.gen.ts +192 -0
  77. package/src/components/popover/popover-root.gen.ts +90 -26
  78. package/src/components/popover/popover-trigger.gen.ts +90 -26
  79. package/src/components/resizable/index.gen.ts +8 -2
  80. package/src/components/resizable/index.ts +20 -0
  81. package/src/components/resizable/resizable-handle.gen.ts +49 -26
  82. package/src/components/resizable/resizable-root.gen.ts +89 -26
  83. package/src/components/table-handle/index.gen.ts +17 -9
  84. package/src/components/table-handle/index.ts +58 -0
  85. package/src/components/table-handle/table-handle-column-menu-root.gen.ts +61 -0
  86. package/src/components/table-handle/table-handle-column-menu-trigger.gen.ts +55 -0
  87. package/src/components/table-handle/table-handle-column-popup.gen.ts +27 -0
  88. package/src/components/table-handle/table-handle-column-positioner.gen.ts +196 -0
  89. package/src/components/table-handle/table-handle-drag-preview.gen.ts +52 -26
  90. package/src/components/table-handle/table-handle-drop-indicator.gen.ts +52 -26
  91. package/src/components/table-handle/table-handle-root.gen.ts +54 -26
  92. package/src/components/table-handle/table-handle-row-menu-root.gen.ts +61 -0
  93. package/src/components/table-handle/table-handle-row-menu-trigger.gen.ts +55 -0
  94. package/src/components/table-handle/table-handle-row-popup.gen.ts +27 -0
  95. package/src/components/table-handle/table-handle-row-positioner.gen.ts +196 -0
  96. package/src/components/tooltip/index.gen.ts +11 -3
  97. package/src/components/tooltip/index.ts +24 -0
  98. package/src/components/tooltip/tooltip-popup.gen.ts +27 -0
  99. package/src/components/tooltip/tooltip-positioner.gen.ts +192 -0
  100. package/src/components/tooltip/tooltip-root.gen.ts +83 -26
  101. package/src/components/tooltip/tooltip-trigger.gen.ts +58 -26
  102. package/src/extensions/solid-mark-view.ts +13 -5
  103. package/src/extensions/solid-node-view.spec.tsx +141 -0
  104. package/src/extensions/solid-node-view.ts +28 -5
  105. package/dist/create-component.js +0 -41
  106. package/dist/create-component.js.map +0 -1
  107. package/dist/create-props.d.ts +0 -6
  108. package/dist/create-props.d.ts.map +0 -1
  109. package/dist/types.d.ts +0 -26
  110. package/dist/types.d.ts.map +0 -1
  111. package/src/components/autocomplete/autocomplete-list.gen.ts +0 -29
  112. package/src/components/autocomplete/autocomplete-popover.gen.ts +0 -29
  113. package/src/components/block-handle/block-handle-popover.gen.ts +0 -29
  114. package/src/components/create-component.ts +0 -60
  115. package/src/components/create-props.ts +0 -13
  116. package/src/components/inline-popover/inline-popover.gen.ts +0 -29
  117. package/src/components/popover/popover-content.gen.ts +0 -29
  118. package/src/components/table-handle/table-handle-column-root.gen.ts +0 -29
  119. package/src/components/table-handle/table-handle-column-trigger.gen.ts +0 -29
  120. package/src/components/table-handle/table-handle-popover-content.gen.ts +0 -29
  121. package/src/components/table-handle/table-handle-popover-item.gen.ts +0 -29
  122. package/src/components/table-handle/table-handle-row-root.gen.ts +0 -29
  123. package/src/components/table-handle/table-handle-row-trigger.gen.ts +0 -29
  124. package/src/components/tooltip/tooltip-content.gen.ts +0 -29
@@ -0,0 +1,141 @@
1
+ import { createEditor, union, type NodeJSON } from '@prosekit/core'
2
+ import { defineTestExtension, type ImageAttrs } from '@prosekit/testing'
3
+ import { onCleanup, onMount, type Component } from 'solid-js'
4
+ import { beforeEach, describe, expect, it } from 'vitest'
5
+ import { render } from 'vitest-browser-solid'
6
+ import { page } from 'vitest/browser'
7
+
8
+ import { ProseKit } from '../components/prosekit.ts'
9
+
10
+ import { defineSolidNodeView, type SolidNodeViewComponent, type SolidNodeViewProps } from './solid-node-view.ts'
11
+
12
+ describe('SolidNodeView', () => {
13
+ const initialState = {
14
+ imageRefresh: {
15
+ mounted: 0,
16
+ unmounted: 0,
17
+ setAttrs: 0,
18
+ },
19
+ }
20
+
21
+ let state = structuredClone(initialState)
22
+
23
+ beforeEach(() => {
24
+ state = structuredClone(initialState)
25
+ })
26
+
27
+ function defineExtension() {
28
+ return union(
29
+ defineTestExtension(),
30
+ defineSolidNodeView({
31
+ name: 'image',
32
+ component: ImageRefreshView satisfies SolidNodeViewComponent,
33
+ }),
34
+ )
35
+ }
36
+
37
+ const ImageRefreshView: Component<SolidNodeViewProps> = (props) => {
38
+ const url = () => (props.node.attrs as ImageAttrs).src
39
+
40
+ onMount(() => {
41
+ state.imageRefresh.mounted++
42
+ const id = setInterval(() => {
43
+ state.imageRefresh.setAttrs++
44
+ props.setAttrs({ src: String(Math.random()) })
45
+ }, 50)
46
+ onCleanup(() => {
47
+ state.imageRefresh.unmounted++
48
+ clearInterval(id)
49
+ })
50
+ })
51
+
52
+ return <div data-testid="image-refresh-view" data-url={url()}></div>
53
+ }
54
+
55
+ const TestEditor: Component<{ initialContent?: NodeJSON }> = (props) => {
56
+ const editor = createEditor({
57
+ extension: defineExtension(),
58
+ defaultContent: props.initialContent,
59
+ })
60
+
61
+ onCleanup(() => editor.mount(null))
62
+
63
+ return (
64
+ <ProseKit editor={editor}>
65
+ <div data-testid="editor" ref={editor.mount}></div>
66
+ </ProseKit>
67
+ )
68
+ }
69
+
70
+ const paragraphJSON: NodeJSON = {
71
+ type: 'paragraph',
72
+ content: [{ type: 'text', text: 'Hello' }],
73
+ }
74
+ const imageRefreshJSON: NodeJSON = {
75
+ type: 'image',
76
+ }
77
+
78
+ const editor = page.getByTestId('editor')
79
+ const imageRefresh = page.getByTestId('image-refresh-view')
80
+
81
+ it('can render a single self-update image node', async () => {
82
+ const initialContent: NodeJSON = {
83
+ type: 'doc',
84
+ content: [imageRefreshJSON, paragraphJSON],
85
+ }
86
+ const screen = render(() => <TestEditor initialContent={initialContent} />)
87
+ await expect.element(editor).toBeVisible()
88
+ await expect.element(imageRefresh).toBeInTheDocument()
89
+
90
+ const urls = new Set<string>()
91
+ const check = () => {
92
+ imageRefresh.elements().forEach((element) => {
93
+ const url = element.getAttribute('data-url')
94
+ if (url) {
95
+ urls.add(url)
96
+ }
97
+ })
98
+ return urls.size >= 5
99
+ }
100
+
101
+ await expect.poll(check, { interval: 50, timeout: 30_000 }).toBe(true)
102
+
103
+ screen.unmount()
104
+
105
+ expect(state.imageRefresh.setAttrs).toBeGreaterThanOrEqual(5)
106
+ expect(state.imageRefresh.mounted).toBe(1)
107
+ expect(state.imageRefresh.unmounted).toBe(1)
108
+ })
109
+
110
+ it('can render multiple self-update image nodes', async () => {
111
+ const initialContent: NodeJSON = {
112
+ type: 'doc',
113
+ content: [imageRefreshJSON, paragraphJSON, imageRefreshJSON, imageRefreshJSON],
114
+ }
115
+ const screen = render(() => <TestEditor initialContent={initialContent} />)
116
+ await expect.element(editor).toBeVisible()
117
+ await expect.element(imageRefresh.nth(0)).toBeInTheDocument()
118
+ await expect.element(imageRefresh.nth(1)).toBeInTheDocument()
119
+ await expect.element(imageRefresh.nth(2)).toBeInTheDocument()
120
+ await expect.element(imageRefresh.nth(3)).not.toBeInTheDocument()
121
+
122
+ const urls = new Set<string>()
123
+ const check = () => {
124
+ imageRefresh.elements().forEach((element) => {
125
+ const url = element.getAttribute('data-url')
126
+ if (url) {
127
+ urls.add(url)
128
+ }
129
+ })
130
+ return urls.size >= 15
131
+ }
132
+
133
+ await expect.poll(check, { interval: 50, timeout: 30_000 }).toBe(true)
134
+
135
+ screen.unmount()
136
+
137
+ expect(state.imageRefresh.setAttrs).toBeGreaterThanOrEqual(15)
138
+ expect(state.imageRefresh.mounted).toBe(3)
139
+ expect(state.imageRefresh.unmounted).toBe(3)
140
+ })
141
+ })
@@ -36,13 +36,36 @@ export interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeV
36
36
  class ProseKitSolidNodeView extends AbstractSolidNodeView<SolidNodeViewComponent> {
37
37
  render = (): JSX.Element => {
38
38
  const UserComponent = this.component
39
- const getProps = this.context
39
+ const getProps: () => SolidNodeViewProps = this.context
40
+ const props: SolidNodeViewProps = {
41
+ get contentRef() {
42
+ return getProps().contentRef
43
+ },
44
+ get view() {
45
+ return getProps().view
46
+ },
47
+ get getPos() {
48
+ return getProps().getPos
49
+ },
50
+ get setAttrs() {
51
+ return getProps().setAttrs
52
+ },
53
+ get node() {
54
+ return getProps().node
55
+ },
56
+ get selected() {
57
+ return getProps().selected
58
+ },
59
+ get decorations() {
60
+ return getProps().decorations
61
+ },
62
+ get innerDecorations() {
63
+ return getProps().innerDecorations
64
+ },
65
+ }
40
66
  return createComponent(Portal, {
41
67
  mount: this.dom,
42
- get children() {
43
- const props: SolidNodeViewProps = getProps()
44
- return createComponent(UserComponent, props)
45
- },
68
+ children: createComponent(UserComponent, props),
46
69
  ref: hidePortalDiv,
47
70
  })
48
71
  }
@@ -1,41 +0,0 @@
1
- import { n as useEditorContext } from "./editor-context.js";
2
- import h from "solid-js/h";
3
- //#region src/components/create-component.ts
4
- function createComponent(tagName, propNames, eventNames) {
5
- const hasEditor = propNames.includes("editor");
6
- const lowerCaseEventNameMap = new Map(eventNames.map((name) => [name.toLowerCase(), name]));
7
- const Component = (props) => {
8
- const properties = {};
9
- const eventHandlers = {};
10
- for (const name of Object.keys(props)) {
11
- if (propNames.includes(name)) {
12
- properties["prop:" + name] = () => props[name];
13
- continue;
14
- }
15
- if (name.startsWith("on")) {
16
- const lowerCaseEventName = name.slice(2).toLowerCase();
17
- const eventName = lowerCaseEventNameMap.get(lowerCaseEventName);
18
- if (eventName) {
19
- const extractDetail = eventName.endsWith("Change");
20
- eventHandlers["on:" + eventName] = (event) => {
21
- const handler = props[name];
22
- if (typeof handler === "function") handler(extractDetail ? event.detail : event);
23
- };
24
- continue;
25
- }
26
- }
27
- properties[name] = () => props[name];
28
- }
29
- const editor = useEditorContext();
30
- if (hasEditor && editor) properties["prop:editor"] = () => props["editor"] || editor;
31
- return () => h(tagName, {
32
- ...properties,
33
- ...eventHandlers
34
- });
35
- };
36
- return Component;
37
- }
38
- //#endregion
39
- export { createComponent as t };
40
-
41
- //# sourceMappingURL=create-component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-component.js","names":[],"sources":["../src/components/create-component.ts"],"sourcesContent":["import type { AnyFunction } from '@prosekit/core'\nimport type { Component } from 'solid-js'\nimport h from 'solid-js/h'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { PropsWithElement } from '../types.ts'\n\nexport function createComponent<\n Props extends object,\n CustomElement extends HTMLElement,\n>(\n tagName: string,\n propNames: string[],\n eventNames: string[],\n): Component<PropsWithElement<Props, CustomElement>> {\n const hasEditor = propNames.includes('editor')\n const lowerCaseEventNameMap = new Map(\n eventNames.map((name) => [name.toLowerCase(), name]),\n )\n\n const Component = (props: Record<string, unknown>) => {\n const properties: Record<string, () => unknown> = {}\n const eventHandlers: Record<string, AnyFunction> = {}\n\n for (const name of Object.keys(props)) {\n if (propNames.includes(name)) {\n properties['prop:' + name] = () => props[name]\n continue\n }\n\n if (name.startsWith('on')) {\n const lowerCaseEventName = name.slice(2).toLowerCase()\n const eventName = lowerCaseEventNameMap.get(lowerCaseEventName)\n if (eventName) {\n const extractDetail = eventName.endsWith('Change')\n eventHandlers['on:' + eventName] = (event: Event) => {\n const handler = props[name] as AnyFunction | null\n if (typeof handler === 'function') {\n handler(extractDetail ? (event as CustomEvent).detail : event)\n }\n }\n continue\n }\n }\n\n properties[name] = () => props[name]\n }\n\n const editor = useEditorContext()\n\n if (hasEditor && editor) {\n properties['prop:editor'] = () => props['editor'] || editor\n }\n\n return () => h(tagName, { ...properties, ...eventHandlers })\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return Component as any\n}\n"],"mappings":";;;AAOA,SAAgB,gBAId,SACA,WACA,YACmD;CACnD,MAAM,YAAY,UAAU,SAAS,SAAS;CAC9C,MAAM,wBAAwB,IAAI,IAChC,WAAW,KAAK,SAAS,CAAC,KAAK,aAAa,EAAE,KAAK,CAAC,CACrD;CAED,MAAM,aAAa,UAAmC;EACpD,MAAM,aAA4C,EAAE;EACpD,MAAM,gBAA6C,EAAE;AAErD,OAAK,MAAM,QAAQ,OAAO,KAAK,MAAM,EAAE;AACrC,OAAI,UAAU,SAAS,KAAK,EAAE;AAC5B,eAAW,UAAU,cAAc,MAAM;AACzC;;AAGF,OAAI,KAAK,WAAW,KAAK,EAAE;IACzB,MAAM,qBAAqB,KAAK,MAAM,EAAE,CAAC,aAAa;IACtD,MAAM,YAAY,sBAAsB,IAAI,mBAAmB;AAC/D,QAAI,WAAW;KACb,MAAM,gBAAgB,UAAU,SAAS,SAAS;AAClD,mBAAc,QAAQ,cAAc,UAAiB;MACnD,MAAM,UAAU,MAAM;AACtB,UAAI,OAAO,YAAY,WACrB,SAAQ,gBAAiB,MAAsB,SAAS,MAAM;;AAGlE;;;AAIJ,cAAW,cAAc,MAAM;;EAGjC,MAAM,SAAS,kBAAkB;AAEjC,MAAI,aAAa,OACf,YAAW,uBAAuB,MAAM,aAAa;AAGvD,eAAa,EAAE,SAAS;GAAE,GAAG;GAAY,GAAG;GAAe,CAAC;;AAI9D,QAAO"}
@@ -1,6 +0,0 @@
1
- //#region src/components/create-props.d.ts
2
- type CreateProps<Props extends { [PropName in keyof Props]: unknown }, Events extends { [EventName in keyof Events]: CustomEvent }> = Props & CreateEventProps<Events>;
3
- type CreateEventProps<Events extends { [EventName in keyof Events]: CustomEvent }> = { [EventName in keyof Events as `on${Capitalize<string & EventName>}`]: (event: EventName extends `${string}Change` ? Events[EventName]['detail'] : Events[EventName]) => void };
4
- //#endregion
5
- export { CreateProps as t };
6
- //# sourceMappingURL=create-props.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-props.d.ts","names":[],"sources":["../src/components/create-props.ts"],"mappings":";KAAY,WAAA,oCACyB,KAAA,mDACE,MAAA,GAAS,WAAA,MAC5C,KAAA,GAAQ,gBAAA,CAAiB,MAAA;AAAA,KAExB,gBAAA,sCACkC,MAAA,GAAS,WAAA,4BAE1B,MAAA,SAAe,UAAA,UAAoB,SAAA,OACrD,KAAA,EAAO,SAAA,6BAAsC,MAAA,CAAO,SAAA,cAChD,MAAA,CAAO,SAAA"}
package/dist/types.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { Accessor, JSX, JSXElement } from "solid-js";
2
-
3
- //#region src/types.d.ts
4
- /**
5
- * @internal
6
- */
7
- type PropsWithClass<P = unknown> = P & {
8
- class?: string | undefined;
9
- };
10
- /**
11
- * @internal
12
- */
13
- type PropsWithChildren<P = unknown> = P & {
14
- children?: JSXElement | undefined;
15
- };
16
- /**
17
- * @internal
18
- */
19
- type PropsWithElement<Props extends object, CustomElement extends HTMLElement> = Props & JSX.HTMLAttributes<CustomElement>;
20
- /**
21
- * T or a reactive/non-reactive function returning T
22
- */
23
- type MaybeAccessor<T> = T | Accessor<T>;
24
- //#endregion
25
- export { PropsWithElement as i, PropsWithChildren as n, PropsWithClass as r, MaybeAccessor as t };
26
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;AAKA;KAAY,cAAA,gBAA8B,CAAA;EACxC,KAAA;AAAA;;;;KAMU,iBAAA,gBAAiC,CAAA;EAC3C,QAAA,GAAW,UAAA;AAAA;;;;KAMD,gBAAA,6CAA6D,WAAA,IAAe,KAAA,GAAQ,GAAA,CAAI,cAAA,CAAe,aAAA;;;;KAKvG,aAAA,MAAmB,CAAA,GAAI,QAAA,CAAS,CAAA"}
@@ -1,29 +0,0 @@
1
- import {
2
- type AutocompleteListElement,
3
- type AutocompleteListProps as Props,
4
- type AutocompleteListEvents as Events,
5
- autocompleteListProps,
6
- autocompleteListEvents,
7
- } from '@prosekit/web/autocomplete'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link AutocompleteList} component.
16
- */
17
- export interface AutocompleteListProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const AutocompleteList: Component<PropsWithElement<
20
- AutocompleteListProps,
21
- AutocompleteListElement
22
- >> = createComponent<
23
- AutocompleteListProps,
24
- AutocompleteListElement
25
- >(
26
- 'prosekit-autocomplete-list',
27
- Object.keys(autocompleteListProps),
28
- Object.keys(autocompleteListEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type AutocompletePopoverElement,
3
- type AutocompletePopoverProps as Props,
4
- type AutocompletePopoverEvents as Events,
5
- autocompletePopoverProps,
6
- autocompletePopoverEvents,
7
- } from '@prosekit/web/autocomplete'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link AutocompletePopover} component.
16
- */
17
- export interface AutocompletePopoverProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const AutocompletePopover: Component<PropsWithElement<
20
- AutocompletePopoverProps,
21
- AutocompletePopoverElement
22
- >> = createComponent<
23
- AutocompletePopoverProps,
24
- AutocompletePopoverElement
25
- >(
26
- 'prosekit-autocomplete-popover',
27
- Object.keys(autocompletePopoverProps),
28
- Object.keys(autocompletePopoverEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type BlockHandlePopoverElement,
3
- type BlockHandlePopoverProps as Props,
4
- type BlockHandlePopoverEvents as Events,
5
- blockHandlePopoverProps,
6
- blockHandlePopoverEvents,
7
- } from '@prosekit/web/block-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link BlockHandlePopover} component.
16
- */
17
- export interface BlockHandlePopoverProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const BlockHandlePopover: Component<PropsWithElement<
20
- BlockHandlePopoverProps,
21
- BlockHandlePopoverElement
22
- >> = createComponent<
23
- BlockHandlePopoverProps,
24
- BlockHandlePopoverElement
25
- >(
26
- 'prosekit-block-handle-popover',
27
- Object.keys(blockHandlePopoverProps),
28
- Object.keys(blockHandlePopoverEvents),
29
- )
@@ -1,60 +0,0 @@
1
- import type { AnyFunction } from '@prosekit/core'
2
- import type { Component } from 'solid-js'
3
- import h from 'solid-js/h'
4
-
5
- import { useEditorContext } from '../contexts/editor-context.ts'
6
- import type { PropsWithElement } from '../types.ts'
7
-
8
- export function createComponent<
9
- Props extends object,
10
- CustomElement extends HTMLElement,
11
- >(
12
- tagName: string,
13
- propNames: string[],
14
- eventNames: string[],
15
- ): Component<PropsWithElement<Props, CustomElement>> {
16
- const hasEditor = propNames.includes('editor')
17
- const lowerCaseEventNameMap = new Map(
18
- eventNames.map((name) => [name.toLowerCase(), name]),
19
- )
20
-
21
- const Component = (props: Record<string, unknown>) => {
22
- const properties: Record<string, () => unknown> = {}
23
- const eventHandlers: Record<string, AnyFunction> = {}
24
-
25
- for (const name of Object.keys(props)) {
26
- if (propNames.includes(name)) {
27
- properties['prop:' + name] = () => props[name]
28
- continue
29
- }
30
-
31
- if (name.startsWith('on')) {
32
- const lowerCaseEventName = name.slice(2).toLowerCase()
33
- const eventName = lowerCaseEventNameMap.get(lowerCaseEventName)
34
- if (eventName) {
35
- const extractDetail = eventName.endsWith('Change')
36
- eventHandlers['on:' + eventName] = (event: Event) => {
37
- const handler = props[name] as AnyFunction | null
38
- if (typeof handler === 'function') {
39
- handler(extractDetail ? (event as CustomEvent).detail : event)
40
- }
41
- }
42
- continue
43
- }
44
- }
45
-
46
- properties[name] = () => props[name]
47
- }
48
-
49
- const editor = useEditorContext()
50
-
51
- if (hasEditor && editor) {
52
- properties['prop:editor'] = () => props['editor'] || editor
53
- }
54
-
55
- return () => h(tagName, { ...properties, ...eventHandlers })
56
- }
57
-
58
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
59
- return Component as any
60
- }
@@ -1,13 +0,0 @@
1
- export type CreateProps<
2
- Props extends { [PropName in keyof Props]: unknown },
3
- Events extends { [EventName in keyof Events]: CustomEvent },
4
- > = Props & CreateEventProps<Events>
5
-
6
- type CreateEventProps<
7
- Events extends { [EventName in keyof Events]: CustomEvent },
8
- > = {
9
- [EventName in keyof Events as `on${Capitalize<string & EventName>}`]: (
10
- event: EventName extends `${string}Change` ? Events[EventName]['detail']
11
- : Events[EventName],
12
- ) => void
13
- }
@@ -1,29 +0,0 @@
1
- import {
2
- type InlinePopoverElement,
3
- type InlinePopoverProps as Props,
4
- type InlinePopoverEvents as Events,
5
- inlinePopoverProps,
6
- inlinePopoverEvents,
7
- } from '@prosekit/web/inline-popover'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link InlinePopover} component.
16
- */
17
- export interface InlinePopoverProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const InlinePopover: Component<PropsWithElement<
20
- InlinePopoverProps,
21
- InlinePopoverElement
22
- >> = createComponent<
23
- InlinePopoverProps,
24
- InlinePopoverElement
25
- >(
26
- 'prosekit-inline-popover',
27
- Object.keys(inlinePopoverProps),
28
- Object.keys(inlinePopoverEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type PopoverContentElement,
3
- type PopoverContentProps as Props,
4
- type PopoverContentEvents as Events,
5
- popoverContentProps,
6
- popoverContentEvents,
7
- } from '@prosekit/web/popover'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link PopoverContent} component.
16
- */
17
- export interface PopoverContentProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const PopoverContent: Component<PropsWithElement<
20
- PopoverContentProps,
21
- PopoverContentElement
22
- >> = createComponent<
23
- PopoverContentProps,
24
- PopoverContentElement
25
- >(
26
- 'prosekit-popover-content',
27
- Object.keys(popoverContentProps),
28
- Object.keys(popoverContentEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type TableHandleColumnRootElement,
3
- type TableHandleColumnRootProps as Props,
4
- type TableHandleColumnRootEvents as Events,
5
- tableHandleColumnRootProps,
6
- tableHandleColumnRootEvents,
7
- } from '@prosekit/web/table-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link TableHandleColumnRoot} component.
16
- */
17
- export interface TableHandleColumnRootProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const TableHandleColumnRoot: Component<PropsWithElement<
20
- TableHandleColumnRootProps,
21
- TableHandleColumnRootElement
22
- >> = createComponent<
23
- TableHandleColumnRootProps,
24
- TableHandleColumnRootElement
25
- >(
26
- 'prosekit-table-handle-column-root',
27
- Object.keys(tableHandleColumnRootProps),
28
- Object.keys(tableHandleColumnRootEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type TableHandleColumnTriggerElement,
3
- type TableHandleColumnTriggerProps as Props,
4
- type TableHandleColumnTriggerEvents as Events,
5
- tableHandleColumnTriggerProps,
6
- tableHandleColumnTriggerEvents,
7
- } from '@prosekit/web/table-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link TableHandleColumnTrigger} component.
16
- */
17
- export interface TableHandleColumnTriggerProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const TableHandleColumnTrigger: Component<PropsWithElement<
20
- TableHandleColumnTriggerProps,
21
- TableHandleColumnTriggerElement
22
- >> = createComponent<
23
- TableHandleColumnTriggerProps,
24
- TableHandleColumnTriggerElement
25
- >(
26
- 'prosekit-table-handle-column-trigger',
27
- Object.keys(tableHandleColumnTriggerProps),
28
- Object.keys(tableHandleColumnTriggerEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type TableHandlePopoverContentElement,
3
- type TableHandlePopoverContentProps as Props,
4
- type TableHandlePopoverContentEvents as Events,
5
- tableHandlePopoverContentProps,
6
- tableHandlePopoverContentEvents,
7
- } from '@prosekit/web/table-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link TableHandlePopoverContent} component.
16
- */
17
- export interface TableHandlePopoverContentProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const TableHandlePopoverContent: Component<PropsWithElement<
20
- TableHandlePopoverContentProps,
21
- TableHandlePopoverContentElement
22
- >> = createComponent<
23
- TableHandlePopoverContentProps,
24
- TableHandlePopoverContentElement
25
- >(
26
- 'prosekit-table-handle-popover-content',
27
- Object.keys(tableHandlePopoverContentProps),
28
- Object.keys(tableHandlePopoverContentEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type TableHandlePopoverItemElement,
3
- type TableHandlePopoverItemProps as Props,
4
- type TableHandlePopoverItemEvents as Events,
5
- tableHandlePopoverItemProps,
6
- tableHandlePopoverItemEvents,
7
- } from '@prosekit/web/table-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link TableHandlePopoverItem} component.
16
- */
17
- export interface TableHandlePopoverItemProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const TableHandlePopoverItem: Component<PropsWithElement<
20
- TableHandlePopoverItemProps,
21
- TableHandlePopoverItemElement
22
- >> = createComponent<
23
- TableHandlePopoverItemProps,
24
- TableHandlePopoverItemElement
25
- >(
26
- 'prosekit-table-handle-popover-item',
27
- Object.keys(tableHandlePopoverItemProps),
28
- Object.keys(tableHandlePopoverItemEvents),
29
- )
@@ -1,29 +0,0 @@
1
- import {
2
- type TableHandleRowRootElement,
3
- type TableHandleRowRootProps as Props,
4
- type TableHandleRowRootEvents as Events,
5
- tableHandleRowRootProps,
6
- tableHandleRowRootEvents,
7
- } from '@prosekit/web/table-handle'
8
- import type { Component } from 'solid-js'
9
-
10
- import type { PropsWithElement } from '../../types.ts'
11
- import { createComponent } from '../create-component.ts'
12
- import type { CreateProps } from '../create-props.ts'
13
-
14
- /**
15
- * Props for the {@link TableHandleRowRoot} component.
16
- */
17
- export interface TableHandleRowRootProps extends Partial<CreateProps<Props, Events>> {}
18
-
19
- export const TableHandleRowRoot: Component<PropsWithElement<
20
- TableHandleRowRootProps,
21
- TableHandleRowRootElement
22
- >> = createComponent<
23
- TableHandleRowRootProps,
24
- TableHandleRowRootElement
25
- >(
26
- 'prosekit-table-handle-row-root',
27
- Object.keys(tableHandleRowRootProps),
28
- Object.keys(tableHandleRowRootEvents),
29
- )