@prosekit/solid 0.6.8 → 0.7.0-beta.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-solid.d.ts","names":[],"sources":["../src/components/prosekit.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-editor.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"mappings":";;;;;;;;;KAOY,aAAA,GAAgB,WAAA;EAC1B,MAAA,EAAQ,MAAA;AAAA;;;;;AADV;cASa,QAAA,EAAU,SAAA,CAAU,aAAA;;;;;;UCAhB,kBAAA,SAA2B,oBAAA;ADT5C;;;AAAA,KCcY,sBAAA,GAAyB,SAAA,CAAU,kBAAA;;;;;;UAO9B,oBAAA,SAA6B,uBAAA,CAAwB,sBAAA;EDIrE;;;ECAC,IAAA;AAAA;;;;AAXF;;iBAgDgB,mBAAA,CAAoB,OAAA,EAAS,oBAAA,GAAuB,SAAA;;;;;;UCrDnD,kBAAA,SAA2B,oBAAA;AFT5C;;;AAAA,KEcY,sBAAA,GAAyB,SAAA,CAAU,kBAAA;;;;;;UAO9B,oBAAA,SAA6B,uBAAA,CAAwB,sBAAA;EFIrE;;;EEAC,IAAA;AAAA;;;;ADXF;;iBCgDgB,mBAAA,CAAoB,OAAA,EAAS,oBAAA,GAAuB,SAAA;;;UC7DnD,mBAAA;;;;;EAKf,MAAA,GAAS,aAAA,CAAc,MAAA;EHNb;;;EGWV,QAAA,GAAW,QAAA;AAAA;;;;iBAMG,YAAA;AHRhB;;;;;AGaE,SAAA,EAAW,QAAA,CAAS,SAAA,UACpB,OAAA,GAAU,mBAAA;;;;;;;;iBCpBI,YAAA,CACd,OAAA,GAAU,GAAA,EAAK,eAAA,WACf,OAAA,GAAU,mBAAA;;;UCJK,uBAAA,WAAkC,SAAA;;;;;EAKjD,MAAA,GAAS,aAAA,CAAc,MAAA,CAAO,CAAA;AAAA;;;;;;;;;ALGhC;;;;iBKYgB,qBAAA,WAAgC,SAAA,UAAA;;;;AJZhD;;;;AImBE,MAAA,GAAS,MAAA,EAAQ,MAAA,CAAO,CAAA,MAAO,OAAA,EAC/B,OAAA,GAAU,uBAAA,CAAwB,CAAA,IACjC,QAAA,CAAS,OAAA;;;;;;;;iBC3BI,SAAA,WAAoB,SAAA,OAAA,CAAiB,OAAA;;;ANHrD;;;;EMUE,MAAA;AAAA,UACQ,MAAA,CAAO,CAAA;;;iBCdD,SAAA,CAAU,MAAA,QAAc,MAAA,EAAQ,OAAA,GAAU,mBAAA;;;;;;;;iBCM1C,cAAA,CACd,OAAA,GAAU,KAAA,EAAO,WAAA,WACjB,OAAA,GAAU,mBAAA"}
1
+ {"version":3,"file":"prosekit-solid.d.ts","names":[],"sources":["../src/components/prosekit.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-editor.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"mappings":";;;;;;;;;KAOY,aAAA,GAAgB,WAAA;EAC1B,MAAA,EAAQ,MAAA;AAAA;;;;;AADV;cASa,QAAA,EAAU,SAAA,CAAU,aAAA;;;;;;UCAhB,kBAAA,SAA2B,oBAAA;ADT5C;;;AAAA,KCcY,sBAAA,GAAyB,SAAA,CAAU,kBAAA;;;;;;UAO9B,oBAAA,SAA6B,uBAAA,CAAwB,sBAAA;EDIrE;;;ECAC,IAAA;AAAA;;;;AAXF;;iBAwDgB,mBAAA,CAAoB,OAAA,EAAS,oBAAA,GAAuB,SAAA;;;;;;UC7DnD,kBAAA,SAA2B,oBAAA;AFT5C;;;AAAA,KEcY,sBAAA,GAAyB,SAAA,CAAU,kBAAA;;;;;;UAO9B,oBAAA,SAA6B,uBAAA,CAAwB,sBAAA;EFIrE;;;EEAC,IAAA;AAAA;;;;ADXF;;iBCuEgB,mBAAA,CAAoB,OAAA,EAAS,oBAAA,GAAuB,SAAA;;;UCpFnD,mBAAA;;;;;EAKf,MAAA,GAAS,aAAA,CAAc,MAAA;EHNb;;;EGWV,QAAA,GAAW,QAAA;AAAA;;;;iBAMG,YAAA;AHRhB;;;;;AGaE,SAAA,EAAW,QAAA,CAAS,SAAA,UACpB,OAAA,GAAU,mBAAA;;;;;;;;iBCpBI,YAAA,CACd,OAAA,GAAU,GAAA,EAAK,eAAA,WACf,OAAA,GAAU,mBAAA;;;UCJK,uBAAA,WAAkC,SAAA;;;;;EAKjD,MAAA,GAAS,aAAA,CAAc,MAAA,CAAO,CAAA;AAAA;;;;;;;;;ALGhC;;;;iBKYgB,qBAAA,WAAgC,SAAA,UAAA;;;;AJZhD;;;;AImBE,MAAA,GAAS,MAAA,EAAQ,MAAA,CAAO,CAAA,MAAO,OAAA,EAC/B,OAAA,GAAU,uBAAA,CAAwB,CAAA,IACjC,QAAA,CAAS,OAAA;;;;;;;;iBC3BI,SAAA,WAAoB,SAAA,OAAA,CAAiB,OAAA;;;ANHrD;;;;EMUE,MAAA;AAAA,UACQ,MAAA,CAAO,CAAA;;;iBCdD,SAAA,CAAU,MAAA,QAAc,MAAA,EAAQ,OAAA,GAAU,mBAAA;;;;;;;;iBCM1C,cAAA,CACd,OAAA,GAAU,KAAA,EAAO,WAAA,WACjB,OAAA,GAAU,mBAAA"}
@@ -18,9 +18,17 @@ var ProseKitSolidMarkView = class extends AbstractSolidMarkView {
18
18
  const getProps = this.context;
19
19
  return createComponent(Portal, {
20
20
  mount: this.dom,
21
- get children() {
22
- return createComponent(UserComponent, getProps());
23
- },
21
+ children: createComponent(UserComponent, {
22
+ get contentRef() {
23
+ return getProps().contentRef;
24
+ },
25
+ get view() {
26
+ return getProps().view;
27
+ },
28
+ get mark() {
29
+ return getProps().mark;
30
+ }
31
+ }),
24
32
  ref: hidePortalDiv
25
33
  });
26
34
  };
@@ -57,9 +65,32 @@ var ProseKitSolidNodeView = class extends AbstractSolidNodeView {
57
65
  const getProps = this.context;
58
66
  return createComponent(Portal, {
59
67
  mount: this.dom,
60
- get children() {
61
- return createComponent(UserComponent, getProps());
62
- },
68
+ children: createComponent(UserComponent, {
69
+ get contentRef() {
70
+ return getProps().contentRef;
71
+ },
72
+ get view() {
73
+ return getProps().view;
74
+ },
75
+ get getPos() {
76
+ return getProps().getPos;
77
+ },
78
+ get setAttrs() {
79
+ return getProps().setAttrs;
80
+ },
81
+ get node() {
82
+ return getProps().node;
83
+ },
84
+ get selected() {
85
+ return getProps().selected;
86
+ },
87
+ get decorations() {
88
+ return getProps().decorations;
89
+ },
90
+ get innerDecorations() {
91
+ return getProps().innerDecorations;
92
+ }
93
+ }),
63
94
  ref: hidePortalDiv
64
95
  });
65
96
  };
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-solid.js","names":[],"sources":["../src/extensions/helpers.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/utils/to-value.ts","../src/hooks/use-editor-extension.ts","../src/components/view-renderer.ts","../src/components/prosekit.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["export function hidePortalDiv(el: HTMLElement): void {\n el.style.display = 'contents'\n el.dataset.solidPortal = 'true'\n}\n","import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidMarkView,\n buildSolidMarkViewCreator,\n type MarkViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidMarkViewProps extends MarkViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidMarkViewComponent = Component<SolidMarkViewProps>\n\n/**\n * Options for {@link defineSolidMarkView}.\n *\n * @public\n */\nexport interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitSolidMarkView extends AbstractSolidMarkView<SolidMarkViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps = this.context\n return createComponent(Portal, {\n mount: this.dom,\n get children() {\n const props: MarkViewContextProps = getProps()\n return createComponent(UserComponent, props)\n },\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidMarkViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidMarkViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidMarkView)\n return defineMarkViewFactory<SolidMarkViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a Solid component.\n *\n * @public\n */\nexport function defineSolidMarkView(options: SolidMarkViewOptions): Extension {\n return defineMarkViewComponent<SolidMarkViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidNodeView,\n buildSolidNodeViewCreator,\n type NodeViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidNodeViewProps extends NodeViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidNodeViewComponent = Component<SolidNodeViewProps>\n\n/**\n * Options for {@link defineSolidNodeView}.\n *\n * @public\n */\nexport interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitSolidNodeView extends AbstractSolidNodeView<SolidNodeViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps = this.context\n return createComponent(Portal, {\n mount: this.dom,\n get children() {\n const props: SolidNodeViewProps = getProps()\n return createComponent(UserComponent, props)\n },\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidNodeViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidNodeViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidNodeView)\n return defineNodeViewFactory<SolidNodeViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a node view using a Solid component.\n *\n * @public\n */\nexport function defineSolidNodeView(options: SolidNodeViewOptions): Extension {\n return defineNodeViewComponent<SolidNodeViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","/**\n * Accesses the value of a MaybeAccessor\n *\n * @example\n * ```ts\n * access(\"foo\") // => \"foo\"\n * access(() => \"foo\") // => \"foo\"\n * ```\n */\nexport function toValue<T>(\n v: (() => T) | T,\n): T {\n return (typeof v === 'function') ? (v as () => T)() : v\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, onCleanup, type Accessor } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorAccessor: MaybeAccessor<Editor> | undefined | null,\n extensionAccessor: Accessor<Extension | null>,\n): void {\n const editorContext = useEditorContext()\n\n createEffect(() => {\n const editor = toValue(editorAccessor) || toValue(editorContext)\n const extension = extensionAccessor()\n\n if (!editor) {\n throw new EditorNotFoundError()\n }\n if (extension) {\n onCleanup(editor.use(extension))\n }\n })\n}\n","import { union, type Editor } from '@prosekit/core'\nimport { useSolidRenderer } from '@prosemirror-adapter/solid'\nimport type { Component, JSX, ParentProps } from 'solid-js'\n\nimport { defineSolidMarkViewFactory } from '../extensions/solid-mark-view.ts'\nimport { defineSolidNodeViewFactory } from '../extensions/solid-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\ntype ViewRendererProps = ParentProps<{\n editor: Editor\n}>\n\nexport const ViewRenderer: Component<ViewRendererProps> = (props): JSX.Element => {\n const { renderSolidRenderer, removeSolidRenderer, render } = useSolidRenderer()\n\n const extension = union([\n defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer),\n defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer),\n ])\n\n useEditorExtension(() => props.editor, () => extension)\n\n return [props.children, render] as unknown as JSX.Element\n}\n","import type { Editor } from '@prosekit/core'\nimport { createComponent, type Component, type ParentProps } from 'solid-js'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport type ProseKitProps = ParentProps<{\n editor: Editor\n}>\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: Component<ProseKitProps> = (props) => {\n return createComponent(EditorContextProvider, {\n get value() {\n return props.editor\n },\n get children() {\n return createComponent(ViewRenderer, {\n get editor() {\n return props.editor\n },\n get children() {\n return props.children\n },\n })\n },\n })\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: () => T | null,\n priority?: Priority | null,\n): () => T | null {\n return () => {\n const ext = extension()\n return ext && priority ? withPriority(ext, priority) : ext\n }\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\n\nimport { useEditorExtension } from './use-editor-extension.ts'\nimport { usePriorityExtension } from './use-priority-extension.ts'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor>\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The accessor to an extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Accessor<Extension | null>,\n options?: UseExtensionOptions,\n): void {\n useEditorExtension(\n options?.editor,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineDocChangeHandler((view) => handler(view.state.doc))\n useExtension(() => extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, createSignal } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): () => Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const [depend, forceUpdate] = useForceUpdate()\n\n createEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return () => {\n depend()\n return editor\n }\n}\n\nfunction useForceUpdate() {\n return createSignal(undefined, { equals: false })\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { createMemo, type Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\nimport { useEditor } from './use-editor.ts'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor<E>>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns an accessor of the derived value that updates whenever the editor\n * state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Accessor<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Accessor<Editor<E>> = initialEditor\n ? () => toValue(initialEditor)\n : useEditor<E>({ update: true })\n\n return createMemo(() => derive(editorAccessor()))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(keymap: () => Keymap, options?: UseExtensionOptions): void {\n const extension = () => defineKeymap(keymap())\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineUpdateHandler((view) => handler(view.state))\n useExtension(() => extension, options)\n}\n"],"mappings":";;;;;;AAAA,SAAgB,cAAc,IAAuB;AACnD,IAAG,MAAM,UAAU;AACnB,IAAG,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AQ;EAAY,CAAC;AAEjC,cAAa;AACX,UAAQ;AACR,SAAO;;;AAIX,SAAS,iBAAiB;AACxB,QAAO,aAAa,KAAA,GAAW,EAAE,QAAQ,OAAO,CAAC;;;;;;;;;;;;;;;;ACnBnD,SAAgB,sBAOd,QACA,SACmB;CACnB,MAAM,gBAAgB,SAAS;CAC/B,MAAM,iBAAsC,sBAClC,QAAQ,cAAc,GAC5B,UAAa,EAAE,QAAQ,MAAM,CAAC;AAElC,QAAO,iBAAiB,OAAO,gBAAgB,CAAC,CAAC;;;;ACvCnD,SAAgB,UAAU,QAAsB,SAAqC;CACnF,MAAM,kBAAkB,aAAa,QAAQ,CAAC;AAC9C,cAAa,WAAW,QAAQ;;;;;;;;;ACIlC,SAAgB,eACd,SACA,SACM;CACN,MAAM,YAAY,qBAAqB,SAAS,QAAQ,KAAK,MAAM,CAAC;AACpE,oBAAmB,WAAW,QAAQ"}
1
+ {"version":3,"file":"prosekit-solid.js","names":[],"sources":["../src/extensions/helpers.ts","../src/extensions/solid-mark-view.ts","../src/extensions/solid-node-view.ts","../src/utils/to-value.ts","../src/hooks/use-editor-extension.ts","../src/components/view-renderer.ts","../src/components/prosekit.ts","../src/hooks/use-priority-extension.ts","../src/hooks/use-extension.ts","../src/hooks/use-doc-change.ts","../src/hooks/use-editor.ts","../src/hooks/use-editor-derived-value.ts","../src/hooks/use-keymap.ts","../src/hooks/use-state-update.ts"],"sourcesContent":["export function hidePortalDiv(el: HTMLElement): void {\n el.style.display = 'contents'\n el.dataset.solidPortal = 'true'\n}\n","import { defineMarkViewComponent, defineMarkViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidMarkView,\n buildSolidMarkViewCreator,\n type MarkViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidMarkViewProps extends MarkViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidMarkViewComponent = Component<SolidMarkViewProps>\n\n/**\n * Options for {@link defineSolidMarkView}.\n *\n * @public\n */\nexport interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkViewComponent> {\n /**\n * The name of the mark type.\n */\n name: string\n}\n\nclass ProseKitSolidMarkView extends AbstractSolidMarkView<SolidMarkViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps: () => SolidMarkViewProps = this.context\n const props: SolidMarkViewProps = {\n get contentRef() {\n return getProps().contentRef\n },\n get view() {\n return getProps().view\n },\n get mark() {\n return getProps().mark\n },\n }\n return createComponent(Portal, {\n mount: this.dom,\n children: createComponent(UserComponent, props),\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidMarkViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidMarkViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidMarkView)\n return defineMarkViewFactory<SolidMarkViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a mark view using a Solid component.\n *\n * @public\n */\nexport function defineSolidMarkView(options: SolidMarkViewOptions): Extension {\n return defineMarkViewComponent<SolidMarkViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'\nimport type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'\nimport {\n AbstractSolidNodeView,\n buildSolidNodeViewCreator,\n type NodeViewContextProps,\n type SolidRendererResult,\n} from '@prosemirror-adapter/solid'\nimport { createComponent, type Component, type JSX } from 'solid-js'\nimport { Portal } from 'solid-js/web'\n\nimport { hidePortalDiv } from './helpers.ts'\n\n/**\n * @public\n */\nexport interface SolidNodeViewProps extends NodeViewContextProps {}\n\n/**\n * @public\n */\nexport type SolidNodeViewComponent = Component<SolidNodeViewProps>\n\n/**\n * Options for {@link defineSolidNodeView}.\n *\n * @public\n */\nexport interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeViewComponent> {\n /**\n * The name of the node type.\n */\n name: string\n}\n\nclass ProseKitSolidNodeView extends AbstractSolidNodeView<SolidNodeViewComponent> {\n render = (): JSX.Element => {\n const UserComponent = this.component\n const getProps: () => SolidNodeViewProps = this.context\n const props: SolidNodeViewProps = {\n get contentRef() {\n return getProps().contentRef\n },\n get view() {\n return getProps().view\n },\n get getPos() {\n return getProps().getPos\n },\n get setAttrs() {\n return getProps().setAttrs\n },\n get node() {\n return getProps().node\n },\n get selected() {\n return getProps().selected\n },\n get decorations() {\n return getProps().decorations\n },\n get innerDecorations() {\n return getProps().innerDecorations\n },\n }\n return createComponent(Portal, {\n mount: this.dom,\n children: createComponent(UserComponent, props),\n ref: hidePortalDiv,\n })\n }\n}\n\n/**\n * @internal\n */\nexport function defineSolidNodeViewFactory(\n renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],\n removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],\n): Extension {\n const factory = buildSolidNodeViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidNodeView)\n return defineNodeViewFactory<SolidNodeViewOptions>({\n group: 'solid',\n factory,\n })\n}\n\n/**\n * Defines a node view using a Solid component.\n *\n * @public\n */\nexport function defineSolidNodeView(options: SolidNodeViewOptions): Extension {\n return defineNodeViewComponent<SolidNodeViewOptions>({\n group: 'solid',\n name: options.name,\n args: options,\n })\n}\n","/**\n * Accesses the value of a MaybeAccessor\n *\n * @example\n * ```ts\n * access(\"foo\") // => \"foo\"\n * access(() => \"foo\") // => \"foo\"\n * ```\n */\nexport function toValue<T>(\n v: (() => T) | T,\n): T {\n return (typeof v === 'function') ? (v as () => T)() : v\n}\n","import { EditorNotFoundError, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, onCleanup, type Accessor } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\n/**\n * @internal\n */\nexport function useEditorExtension(\n editorAccessor: MaybeAccessor<Editor> | undefined | null,\n extensionAccessor: Accessor<Extension | null>,\n): void {\n const editorContext = useEditorContext()\n\n createEffect(() => {\n const editor = toValue(editorAccessor) || toValue(editorContext)\n const extension = extensionAccessor()\n\n if (!editor) {\n throw new EditorNotFoundError()\n }\n if (extension) {\n onCleanup(editor.use(extension))\n }\n })\n}\n","import { union, type Editor } from '@prosekit/core'\nimport { useSolidRenderer } from '@prosemirror-adapter/solid'\nimport type { Component, JSX, ParentProps } from 'solid-js'\n\nimport { defineSolidMarkViewFactory } from '../extensions/solid-mark-view.ts'\nimport { defineSolidNodeViewFactory } from '../extensions/solid-node-view.ts'\nimport { useEditorExtension } from '../hooks/use-editor-extension.ts'\n\ntype ViewRendererProps = ParentProps<{\n editor: Editor\n}>\n\nexport const ViewRenderer: Component<ViewRendererProps> = (props): JSX.Element => {\n const { renderSolidRenderer, removeSolidRenderer, render } = useSolidRenderer()\n\n const extension = union([\n defineSolidMarkViewFactory(renderSolidRenderer, removeSolidRenderer),\n defineSolidNodeViewFactory(renderSolidRenderer, removeSolidRenderer),\n ])\n\n useEditorExtension(() => props.editor, () => extension)\n\n return [props.children, render] as unknown as JSX.Element\n}\n","import type { Editor } from '@prosekit/core'\nimport { createComponent, type Component, type ParentProps } from 'solid-js'\n\nimport { EditorContextProvider } from '../contexts/editor-context.ts'\n\nimport { ViewRenderer } from './view-renderer.ts'\n\nexport type ProseKitProps = ParentProps<{\n editor: Editor\n}>\n\n/**\n * The root component for a ProseKit editor.\n *\n * @public\n */\nexport const ProseKit: Component<ProseKitProps> = (props) => {\n return createComponent(EditorContextProvider, {\n get value() {\n return props.editor\n },\n get children() {\n return createComponent(ViewRenderer, {\n get editor() {\n return props.editor\n },\n get children() {\n return props.children\n },\n })\n },\n })\n}\n","import { withPriority, type Extension, type Priority } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function usePriorityExtension<T extends Extension = Extension>(\n extension: () => T | null,\n priority?: Priority | null,\n): () => T | null {\n return () => {\n const ext = extension()\n return ext && priority ? withPriority(ext, priority) : ext\n }\n}\n","import type { Editor, Extension, Priority } from '@prosekit/core'\nimport type { Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\n\nimport { useEditorExtension } from './use-editor-extension.ts'\nimport { usePriorityExtension } from './use-priority-extension.ts'\n\nexport interface UseExtensionOptions {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor>\n\n /**\n * Optional priority to add the extension with.\n */\n priority?: Priority\n}\n\n/**\n * Add an extension to the editor.\n */\nexport function useExtension(\n /**\n * The accessor to an extension to add to the editor. If it changes, the previous\n * extension will be removed and the new one (if not null) will be added.\n */\n extension: Accessor<Extension | null>,\n options?: UseExtensionOptions,\n): void {\n useEditorExtension(\n options?.editor,\n usePriorityExtension(extension, options?.priority),\n )\n}\n","import { defineDocChangeHandler } from '@prosekit/core'\nimport type { ProseMirrorNode } from '@prosekit/pm/model'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor document changes.\n *\n * @public\n */\nexport function useDocChange(\n handler: (doc: ProseMirrorNode) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineDocChangeHandler((view) => handler(view.state.doc))\n useExtension(() => extension, options)\n}\n","import { defineMountHandler, defineUpdateHandler, ProseKitError, union, type Editor, type Extension } from '@prosekit/core'\nimport { createEffect, createSignal } from 'solid-js'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\n\n/**\n * Retrieves the editor instance from the nearest ProseKit component.\n *\n * @public\n */\nexport function useEditor<E extends Extension = any>(options?: {\n /**\n * Whether to update the component when the editor is mounted or editor state\n * is updated.\n *\n * @default false\n */\n update?: boolean\n}): () => Editor<E> {\n const update = options?.update ?? false\n\n const editor = useEditorContext<E>()\n if (!editor) {\n throw new ProseKitError(\n 'useEditor must be used within the ProseKit component',\n )\n }\n\n const [depend, forceUpdate] = useForceUpdate()\n\n createEffect(() => {\n if (update) {\n const extension = union(\n defineMountHandler(forceUpdate),\n defineUpdateHandler(forceUpdate),\n )\n return editor.use(extension)\n }\n }, [editor, update, forceUpdate])\n\n return () => {\n depend()\n return editor\n }\n}\n\nfunction useForceUpdate() {\n return createSignal(undefined, { equals: false })\n}\n","import type { Editor, Extension } from '@prosekit/core'\nimport { createMemo, type Accessor } from 'solid-js'\n\nimport type { MaybeAccessor } from '../types.ts'\nimport { toValue } from '../utils/to-value.ts'\n\nimport { useEditor } from './use-editor.ts'\n\nexport interface UseEditorDerivedOptions<E extends Extension = any> {\n /**\n * The editor to add the extension to. If not provided, it will use the\n * editor from the nearest `<ProseKit>` component.\n */\n editor?: MaybeAccessor<Editor<E>>\n}\n\n/**\n * Runs a function to derive a value from the editor instance after editor state\n * changes.\n *\n * This is useful when you need to render something based on the editor state,\n * for example, whether the selected text is wrapped in an italic mark.\n *\n * It returns an accessor of the derived value that updates whenever the editor\n * state changes.\n *\n * @public\n */\nexport function useEditorDerivedValue<E extends Extension, Derived>(\n /**\n * A function that receives the editor instance and returns a derived value.\n *\n * It will be called whenever the editor's document state changes, or when it\n * mounts.\n */\n derive: (editor: Editor<E>) => Derived,\n options?: UseEditorDerivedOptions<E>,\n): Accessor<Derived> {\n const initialEditor = options?.editor\n const editorAccessor: Accessor<Editor<E>> = initialEditor\n ? () => toValue(initialEditor)\n : useEditor<E>({ update: true })\n\n return createMemo(() => derive(editorAccessor()))\n}\n","import { defineKeymap, type Keymap } from '@prosekit/core'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\nexport function useKeymap(keymap: () => Keymap, options?: UseExtensionOptions): void {\n const extension = () => defineKeymap(keymap())\n useExtension(extension, options)\n}\n","import { defineUpdateHandler } from '@prosekit/core'\nimport type { EditorState } from '@prosekit/pm/state'\n\nimport { useExtension, type UseExtensionOptions } from './use-extension.ts'\n\n/**\n * Calls the given handler whenever the editor state changes.\n *\n * @public\n */\nexport function useStateUpdate(\n handler: (state: EditorState) => void,\n options?: UseExtensionOptions,\n): void {\n const extension = defineUpdateHandler((view) => handler(view.state))\n useExtension(() => extension, options)\n}\n"],"mappings":";;;;;;AAAA,SAAgB,cAAc,IAAuB;AACnD,IAAG,MAAM,UAAU;AACnB,IAAG,QAAQ,cAAc;;;;ACiC3B,IAAM,wBAAN,cAAoC,sBAA8C;;;sBACpD;GAC1B,MAAM,gBAAgB,KAAK;GAC3B,MAAM,WAAqC,KAAK;AAYhD,UAAO,gBAAgB,QAAQ;IAC7B,OAAO,KAAK;IACZ,UAAU,gBAAgB,eAbM;KAChC,IAAI,aAAa;AACf,aAAO,UAAU,CAAC;;KAEpB,IAAI,OAAO;AACT,aAAO,UAAU,CAAC;;KAEpB,IAAI,OAAO;AACT,aAAO,UAAU,CAAC;;KAErB,CAGgD;IAC/C,KAAK;IACN,CAAC;;;;;;;AAON,SAAgB,2BACd,qBACA,qBACW;AAEX,QAAO,sBAA4C;EACjD,OAAO;EACP,SAHc,0BAA0B,qBAAqB,qBAAqB,sBAAsB;EAIzG,CAAC;;;;;;;AAQJ,SAAgB,oBAAoB,SAA0C;AAC5E,QAAO,wBAA8C;EACnD,OAAO;EACP,MAAM,QAAQ;EACd,MAAM;EACP,CAAC;;;;AC/CJ,IAAM,wBAAN,cAAoC,sBAA8C;;;sBACpD;GAC1B,MAAM,gBAAgB,KAAK;GAC3B,MAAM,WAAqC,KAAK;AA2BhD,UAAO,gBAAgB,QAAQ;IAC7B,OAAO,KAAK;IACZ,UAAU,gBAAgB,eA5BM;KAChC,IAAI,aAAa;AACf,aAAO,UAAU,CAAC;;KAEpB,IAAI,OAAO;AACT,aAAO,UAAU,CAAC;;KAEpB,IAAI,SAAS;AACX,aAAO,UAAU,CAAC;;KAEpB,IAAI,W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eACd,SACA,SACM;CACN,MAAM,YAAY,qBAAqB,SAAS,QAAQ,KAAK,MAAM,CAAC;AACpE,oBAAmB,WAAW,QAAQ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/solid",
3
3
  "type": "module",
4
- "version": "0.6.8",
4
+ "version": "0.7.0-beta.1",
5
5
  "private": false,
6
6
  "description": "Solid components and utilities for ProseKit",
7
7
  "author": {
@@ -68,11 +68,11 @@
68
68
  "src"
69
69
  ],
70
70
  "dependencies": {
71
- "@prosemirror-adapter/core": "^0.5.2",
72
- "@prosemirror-adapter/solid": "^0.5.2",
73
- "@prosekit/core": "^0.11.0",
71
+ "@prosemirror-adapter/core": "^0.5.3",
72
+ "@prosemirror-adapter/solid": "^0.5.3",
74
73
  "@prosekit/pm": "^0.1.15",
75
- "@prosekit/web": "^0.7.13"
74
+ "@prosekit/web": "^0.8.0-beta.0",
75
+ "@prosekit/core": "^0.12.0-beta.0"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "solid-js": ">= 1.7.0"
@@ -86,9 +86,13 @@
86
86
  "solid-js": "^1.9.11",
87
87
  "tsdown": "^0.21.4",
88
88
  "typescript": "~5.9.3",
89
+ "vite-plugin-solid": "^2.11.11",
90
+ "vitest": "^4.1.1",
91
+ "vitest-browser-solid": "^1.0.1",
92
+ "@prosekit/config-tsdown": "0.0.0",
89
93
  "@prosekit/config-ts": "0.0.0",
90
94
  "@prosekit/config-vitest": "0.0.0",
91
- "@prosekit/config-tsdown": "0.0.0"
95
+ "@prosekit/testing": "0.0.0"
92
96
  },
93
97
  "publishConfig": {
94
98
  "dev": {}
@@ -36,13 +36,21 @@ export interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkV
36
36
  class ProseKitSolidMarkView extends AbstractSolidMarkView<SolidMarkViewComponent> {
37
37
  render = (): JSX.Element => {
38
38
  const UserComponent = this.component
39
- const getProps = this.context
39
+ const getProps: () => SolidMarkViewProps = this.context
40
+ const props: SolidMarkViewProps = {
41
+ get contentRef() {
42
+ return getProps().contentRef
43
+ },
44
+ get view() {
45
+ return getProps().view
46
+ },
47
+ get mark() {
48
+ return getProps().mark
49
+ },
50
+ }
40
51
  return createComponent(Portal, {
41
52
  mount: this.dom,
42
- get children() {
43
- const props: MarkViewContextProps = getProps()
44
- return createComponent(UserComponent, props)
45
- },
53
+ children: createComponent(UserComponent, props),
46
54
  ref: hidePortalDiv,
47
55
  })
48
56
  }
@@ -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
  }