@milkdown/plugin-slash 5.4.0 → 5.4.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.
- package/lib/index.es.js +12 -14
- package/lib/index.es.js.map +1 -1
- package/lib/src/config.d.ts.map +1 -1
- package/lib/src/prose-plugin/props.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/config.ts +11 -22
- package/src/prose-plugin/props.ts +3 -2
package/lib/index.es.js
CHANGED
|
@@ -15,9 +15,7 @@ var __objRest = (source, exclude) => {
|
|
|
15
15
|
};
|
|
16
16
|
import { createPlugin, AtomList } from "@milkdown/utils";
|
|
17
17
|
import { schemaCtx, themeToolCtx, commandsCtx } from "@milkdown/core";
|
|
18
|
-
import { TurnIntoHeading, WrapInBulletList, WrapInOrderedList, TurnIntoTaskList, InsertImage, WrapInBlockquote, InsertTable, TurnIntoCodeFence, InsertHr } from "@milkdown/preset-gfm";
|
|
19
18
|
import { findParentNode, DecorationSet, Decoration, calculateNodePosition, Plugin, PluginKey } from "@milkdown/prose";
|
|
20
|
-
import { key as key$1 } from "@milkdown/plugin-upload";
|
|
21
19
|
import scrollIntoView from "smooth-scroll-into-view-if-needed";
|
|
22
20
|
const itemStyle = ({ font, palette }, { css }) => {
|
|
23
21
|
return css`
|
|
@@ -123,77 +121,77 @@ const defaultActions = (ctx, input = "/") => {
|
|
|
123
121
|
{
|
|
124
122
|
id: "h1",
|
|
125
123
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Large Heading", "h1"),
|
|
126
|
-
command: () => ctx.get(commandsCtx).
|
|
124
|
+
command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 1),
|
|
127
125
|
keyword: ["h1", "large heading"],
|
|
128
126
|
typeName: "heading"
|
|
129
127
|
},
|
|
130
128
|
{
|
|
131
129
|
id: "h2",
|
|
132
130
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Medium Heading", "h2"),
|
|
133
|
-
command: () => ctx.get(commandsCtx).
|
|
131
|
+
command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 2),
|
|
134
132
|
keyword: ["h2", "medium heading"],
|
|
135
133
|
typeName: "heading"
|
|
136
134
|
},
|
|
137
135
|
{
|
|
138
136
|
id: "h3",
|
|
139
137
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Small Heading", "h3"),
|
|
140
|
-
command: () => ctx.get(commandsCtx).
|
|
138
|
+
command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 3),
|
|
141
139
|
keyword: ["h3", "small heading"],
|
|
142
140
|
typeName: "heading"
|
|
143
141
|
},
|
|
144
142
|
{
|
|
145
143
|
id: "bulletList",
|
|
146
144
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Bullet List", "bulletList"),
|
|
147
|
-
command: () => ctx.get(commandsCtx).
|
|
145
|
+
command: () => ctx.get(commandsCtx).callByName("WrapInBulletList"),
|
|
148
146
|
keyword: ["bullet list", "ul"],
|
|
149
147
|
typeName: "bullet_list"
|
|
150
148
|
},
|
|
151
149
|
{
|
|
152
150
|
id: "orderedList",
|
|
153
151
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Ordered List", "orderedList"),
|
|
154
|
-
command: () => ctx.get(commandsCtx).
|
|
152
|
+
command: () => ctx.get(commandsCtx).callByName("WrapInOrderedList"),
|
|
155
153
|
keyword: ["ordered list", "ol"],
|
|
156
154
|
typeName: "ordered_list"
|
|
157
155
|
},
|
|
158
156
|
{
|
|
159
157
|
id: "taskList",
|
|
160
158
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Task List", "taskList"),
|
|
161
|
-
command: () => ctx.get(commandsCtx).
|
|
159
|
+
command: () => ctx.get(commandsCtx).callByName("TurnIntoTaskList"),
|
|
162
160
|
keyword: ["task list", "task"],
|
|
163
161
|
typeName: "task_list_item"
|
|
164
162
|
},
|
|
165
163
|
{
|
|
166
164
|
id: "image",
|
|
167
165
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Image", "image"),
|
|
168
|
-
command: () => ctx.get(commandsCtx).
|
|
166
|
+
command: () => ctx.get(commandsCtx).callByName("InsertImage"),
|
|
169
167
|
keyword: ["image"],
|
|
170
168
|
typeName: "image"
|
|
171
169
|
},
|
|
172
170
|
{
|
|
173
171
|
id: "blockquote",
|
|
174
172
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Quote", "quote"),
|
|
175
|
-
command: () => ctx.get(commandsCtx).
|
|
173
|
+
command: () => ctx.get(commandsCtx).callByName("WrapInBlockquote"),
|
|
176
174
|
keyword: ["quote", "blockquote"],
|
|
177
175
|
typeName: "blockquote"
|
|
178
176
|
},
|
|
179
177
|
{
|
|
180
178
|
id: "table",
|
|
181
179
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Table", "table"),
|
|
182
|
-
command: () => ctx.get(commandsCtx).
|
|
180
|
+
command: () => ctx.get(commandsCtx).callByName("InsertTable"),
|
|
183
181
|
keyword: ["table"],
|
|
184
182
|
typeName: "table"
|
|
185
183
|
},
|
|
186
184
|
{
|
|
187
185
|
id: "code",
|
|
188
186
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Code Fence", "code"),
|
|
189
|
-
command: () => ctx.get(commandsCtx).
|
|
187
|
+
command: () => ctx.get(commandsCtx).callByName("TurnIntoCodeFence"),
|
|
190
188
|
keyword: ["code"],
|
|
191
189
|
typeName: "fence"
|
|
192
190
|
},
|
|
193
191
|
{
|
|
194
192
|
id: "divider",
|
|
195
193
|
dom: createDropdownItem(ctx.get(themeToolCtx), "Divide Line", "divider"),
|
|
196
|
-
command: () => ctx.get(commandsCtx).
|
|
194
|
+
command: () => ctx.get(commandsCtx).callByName("InsertHr"),
|
|
197
195
|
keyword: ["divider", "hr"],
|
|
198
196
|
typeName: "hr"
|
|
199
197
|
}
|
|
@@ -259,7 +257,7 @@ const createProps = (status, utils) => {
|
|
|
259
257
|
},
|
|
260
258
|
decorations: (state) => {
|
|
261
259
|
const paragraph = findParentNode(({ type }) => type.name === "paragraph")(state.selection);
|
|
262
|
-
const uploadPlugin = state.plugins.find((x) => x.
|
|
260
|
+
const uploadPlugin = state.plugins.find((x) => x.key === "MILKDOWN_PLUGIN_UPLOAD$");
|
|
263
261
|
const decorations = uploadPlugin == null ? void 0 : uploadPlugin.getState(state);
|
|
264
262
|
if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {
|
|
265
263
|
status.clear();
|
package/lib/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/style.ts","../src/utility.ts","../src/config.ts","../src/prose-plugin/props.ts","../src/item.ts","../src/prose-plugin/status.ts","../src/prose-plugin/dropdown.ts","../src/prose-plugin/input.ts","../src/prose-plugin/view.ts","../src/prose-plugin/index.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\n\nconst itemStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => {\n return css`\n .slash-dropdown-item {\n display: flex;\n gap: 2rem;\n height: 3rem;\n padding: 0 1rem;\n align-items: center;\n justify-content: flex-start;\n cursor: pointer;\n line-height: 2;\n font-family: ${font.typography};\n font-size: 0.875rem;\n\n transition: all 0.2s ease-in-out;\n\n &,\n .icon {\n color: ${palette('neutral', 0.87)};\n transition: all 0.2s ease-in-out;\n }\n\n &.hide {\n display: none;\n }\n\n &.active {\n background: ${palette('secondary', 0.12)};\n &,\n .icon {\n color: ${palette('primary')};\n }\n }\n `;\n};\n\nexport const injectStyle = (themeTool: ThemeTool, emotion: Emotion) => {\n const { mixin, size, palette } = themeTool;\n const style = emotion.css`\n width: 20.5rem;\n max-height: 20.5rem;\n overflow-y: auto;\n ${mixin.border?.()};\n border-radius: ${size.radius};\n position: absolute;\n background: ${palette('surface')};\n\n ${mixin.shadow?.()};\n\n &.hide {\n display: none;\n }\n\n ${mixin.scrollbar?.()};\n\n ${itemStyle(themeTool, emotion)}\n `;\n return style;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { ThemeTool } from '@milkdown/core';\nimport type { Icon } from '@milkdown/design-system';\nimport type { Command, Node } from '@milkdown/prose';\nimport type { Utils } from '@milkdown/utils';\n\nimport { injectStyle } from './style';\n\nexport const createDropdown = (utils: Utils) => {\n const div = document.createElement('div');\n div.setAttribute('role', 'listbox');\n div.setAttribute('tabindex', '-1');\n const style = utils.getStyle(injectStyle);\n\n if (style) {\n div.classList.add(style);\n }\n\n div.classList.add('slash-dropdown', 'hide');\n\n return div;\n};\n\ntype ItemOptions = {\n textClassName: string;\n};\nexport const createDropdownItem = (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions>) => {\n const textClassName = options?.textClassName ?? 'text';\n\n const div = document.createElement('div');\n div.setAttribute('role', 'option');\n div.classList.add('slash-dropdown-item');\n\n const iconSpan = themeTool.slots.icon(icon);\n\n const textSpan = document.createElement('span');\n textSpan.textContent = text;\n textSpan.className = textClassName;\n\n div.appendChild(iconSpan);\n div.appendChild(textSpan);\n\n return div;\n};\n\nexport const getDepth = (node: Node) => {\n let cur = node;\n let depth = 0;\n while (cur.childCount) {\n cur = cur.child(0);\n depth += 1;\n }\n\n return depth;\n};\n\nconst cleanUp: Command = (state, dispatch) => {\n const { selection } = state;\n const { $from } = selection;\n const tr = state.tr.deleteRange($from.start(), $from.pos);\n dispatch?.(tr);\n return false;\n};\n\nexport const cleanUpAndCreateNode =\n (createCommand: () => void): Command =>\n (state, dispatch, view) => {\n if (view) {\n cleanUp(state, dispatch, view);\n createCommand();\n }\n return true;\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { commandsCtx, Ctx, schemaCtx, themeToolCtx } from '@milkdown/core';\nimport {\n InsertHr,\n InsertImage,\n InsertTable,\n TurnIntoCodeFence,\n TurnIntoHeading,\n TurnIntoTaskList,\n WrapInBlockquote,\n WrapInBulletList,\n WrapInOrderedList,\n} from '@milkdown/preset-gfm';\nimport { EditorState, Node } from '@milkdown/prose';\n\nimport { WrappedAction } from './item';\nimport { createDropdownItem } from './utility';\n\ntype Nullable<T> = T | null | undefined;\n\nexport type StatusConfig = {\n placeholder?: Nullable<string>;\n actions?: Nullable<WrappedAction[]>;\n};\n\nexport type StatusConfigBuilderParams = {\n content: string;\n isTopLevel: boolean;\n parentNode: Node;\n state: EditorState;\n};\n\nexport type StatusConfigBuilder = (params: StatusConfigBuilderParams) => Nullable<StatusConfig>;\n\nexport type Config = (ctx: Ctx) => StatusConfigBuilder;\n\nexport const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {\n const { nodes } = ctx.get(schemaCtx);\n const actions: Array<WrappedAction & { keyword: string[]; typeName: string }> = [\n {\n id: 'h1',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),\n command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 1),\n keyword: ['h1', 'large heading'],\n typeName: 'heading',\n },\n {\n id: 'h2',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),\n command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 2),\n keyword: ['h2', 'medium heading'],\n typeName: 'heading',\n },\n {\n id: 'h3',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),\n command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 3),\n keyword: ['h3', 'small heading'],\n typeName: 'heading',\n },\n {\n id: 'bulletList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),\n command: () => ctx.get(commandsCtx).call(WrapInBulletList),\n keyword: ['bullet list', 'ul'],\n typeName: 'bullet_list',\n },\n {\n id: 'orderedList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),\n command: () => ctx.get(commandsCtx).call(WrapInOrderedList),\n keyword: ['ordered list', 'ol'],\n typeName: 'ordered_list',\n },\n {\n id: 'taskList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),\n command: () => ctx.get(commandsCtx).call(TurnIntoTaskList),\n keyword: ['task list', 'task'],\n typeName: 'task_list_item',\n },\n {\n id: 'image',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),\n command: () => ctx.get(commandsCtx).call(InsertImage),\n keyword: ['image'],\n typeName: 'image',\n },\n {\n id: 'blockquote',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),\n command: () => ctx.get(commandsCtx).call(WrapInBlockquote),\n keyword: ['quote', 'blockquote'],\n typeName: 'blockquote',\n },\n {\n id: 'table',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),\n command: () => ctx.get(commandsCtx).call(InsertTable),\n keyword: ['table'],\n typeName: 'table',\n },\n {\n id: 'code',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),\n command: () => ctx.get(commandsCtx).call(TurnIntoCodeFence),\n keyword: ['code'],\n typeName: 'fence',\n },\n {\n id: 'divider',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),\n command: () => ctx.get(commandsCtx).call(InsertHr),\n keyword: ['divider', 'hr'],\n typeName: 'hr',\n },\n ];\n\n const userInput = input.slice(1).toLocaleLowerCase();\n\n return actions\n .filter((action) => !!nodes[action.typeName] && action.keyword.some((keyword) => keyword.includes(userInput)))\n .map(({ keyword, typeName, ...action }) => action);\n};\n\nexport const defaultConfig: Config = (ctx) => {\n return ({ content, isTopLevel }) => {\n if (!isTopLevel) return null;\n\n if (!content) {\n return { placeholder: 'Type / to use the slash commands...' };\n }\n\n if (content.startsWith('/')) {\n return content === '/'\n ? {\n placeholder: 'Type to filter...',\n actions: defaultActions(ctx),\n }\n : {\n actions: defaultActions(ctx, content),\n };\n }\n\n return null;\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\nimport { key as uploadKey } from '@milkdown/plugin-upload';\nimport { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { Status } from './status';\n\nexport type Props = ReturnType<typeof createProps>;\n\nconst createEmptyStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => css`\n position: relative;\n &::before {\n position: absolute;\n cursor: text;\n font-family: ${font.typography};\n font-size: 0.875rem;\n color: ${palette('neutral', 0.6)};\n content: attr(data-text);\n height: 100%;\n display: flex;\n align-items: center;\n }\n`;\n\nconst createSlashStyle = (_: ThemeTool, { css }: Emotion) => css`\n &::before {\n left: 0.5rem;\n }\n`;\n\nexport const createProps = (status: Status, utils: Utils) => {\n const emptyStyle = utils.getStyle(createEmptyStyle);\n const slashStyle = utils.getStyle(createSlashStyle);\n\n return {\n handleKeyDown: (_: EditorView, event: Event) => {\n if (status.isEmpty()) {\n return false;\n }\n if (!(event instanceof KeyboardEvent)) {\n return false;\n }\n\n if (!['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {\n return false;\n }\n\n return true;\n },\n decorations: (state: EditorState) => {\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);\n const uploadPlugin = state.plugins.find((x) => x.spec.key === uploadKey);\n const decorations: DecorationSet = uploadPlugin?.getState(state);\n if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {\n status.clear();\n return;\n }\n\n if (\n !paragraph ||\n paragraph.node.childCount > 1 ||\n state.selection.$from.parentOffset !== paragraph.node.textContent.length ||\n (paragraph.node.firstChild && paragraph.node.firstChild.type.name !== 'text')\n ) {\n status.clear();\n return;\n }\n\n const { placeholder, actions } = status.update({\n parentNode: state.selection.$from.node(state.selection.$from.depth - 1),\n isTopLevel: state.selection.$from.depth === 1,\n content: paragraph.node.textContent,\n state,\n });\n\n if (!placeholder) {\n return null;\n }\n\n const createDecoration = (text: string, className: (string | undefined)[]) => {\n const pos = paragraph.pos;\n return DecorationSet.create(state.doc, [\n Decoration.node(pos, pos + paragraph.node.nodeSize, {\n class: className.filter((x) => x).join(' '),\n 'data-text': text,\n }),\n ]);\n };\n\n if (actions.length) {\n return createDecoration(placeholder, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);\n }\n\n return createDecoration(placeholder, [emptyStyle, 'empty-node']);\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Command } from '@milkdown/prose';\n\nimport { cleanUpAndCreateNode } from './utility';\n\nexport type Action = {\n id: string;\n $: HTMLElement;\n command: Command;\n};\n\nexport type WrappedAction = Pick<Action, 'id'> & {\n command: () => void;\n dom: HTMLElement;\n};\n\nexport const transformAction = (action: WrappedAction): Action => ({\n id: action.id,\n $: action.dom,\n command: cleanUpAndCreateNode(action.command),\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { StatusConfigBuilder, StatusConfigBuilderParams } from '..';\nimport { Action, transformAction } from '../item';\n\nexport type StatusCtx = {\n placeholder: string | null;\n actions: Action[];\n};\n\nconst createStatusCtx = (): StatusCtx => {\n return {\n placeholder: null,\n actions: [],\n };\n};\n\nexport type Status = ReturnType<typeof createStatus>;\n\nexport const createStatus = (builder: StatusConfigBuilder) => {\n const statusCtx = createStatusCtx();\n\n return {\n get: () => statusCtx,\n clear: () => {\n statusCtx.placeholder = null;\n statusCtx.actions = [];\n },\n update: (builderParams: StatusConfigBuilderParams) => {\n const config = builder(builderParams);\n statusCtx.placeholder = config?.placeholder ?? null;\n statusCtx.actions = (config?.actions ?? []).map(transformAction);\n return statusCtx;\n },\n isEmpty: () => statusCtx.actions.length === 0,\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\ntype Listeners = {\n mouseEnter: EventListener;\n mouseLeave: EventListener;\n};\n\nexport const renderDropdown = (status: Status, dropdownElement: HTMLElement, listeners: Listeners): boolean => {\n const { actions } = status.get();\n\n if (!actions.length) {\n dropdownElement.classList.add('hide');\n return false;\n }\n\n dropdownElement.childNodes.forEach((child) => {\n child.removeEventListener('mouseenter', listeners.mouseEnter);\n child.removeEventListener('mouseleave', listeners.mouseLeave);\n });\n\n // Reset dropdownElement children\n dropdownElement.textContent = '';\n\n actions.forEach(({ $ }) => {\n $.classList.remove('active');\n $.addEventListener('mouseenter', listeners.mouseEnter);\n $.addEventListener('mouseleave', listeners.mouseLeave);\n dropdownElement.appendChild($);\n });\n\n dropdownElement.classList.remove('hide');\n\n actions[0].$.classList.add('active');\n requestAnimationFrame(() => {\n scrollIntoView(actions[0].$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n });\n\n return true;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { EditorView } from '@milkdown/prose';\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\nexport const createMouseManager = () => {\n let mouseLock = false;\n\n return {\n isLock: () => mouseLock,\n lock: () => {\n mouseLock = true;\n },\n unlock: () => {\n mouseLock = false;\n },\n };\n};\nexport type MouseManager = ReturnType<typeof createMouseManager>;\n\nexport const handleMouseMove = (mouseManager: MouseManager) => () => {\n mouseManager.unlock();\n};\n\nexport const handleMouseEnter = (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => {\n if (mouseManager.isLock()) return;\n const { actions } = status.get();\n const active = actions.findIndex((x) => x.$.classList.contains('active'));\n if (active >= 0) {\n actions[active].$.classList.remove('active');\n }\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.add('active');\n};\n\nexport const handleMouseLeave = () => (e: MouseEvent) => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.remove('active');\n};\n\nexport const handleClick =\n (status: Status, view: EditorView, dropdownElement: HTMLElement) =>\n (e: Event): void => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n if (!view) return;\n\n const stop = () => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const { actions } = status.get();\n\n const el = Object.values(actions).find(({ $ }) => $.contains(target));\n if (!el) {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n stop();\n\n return;\n }\n\n stop();\n el.command(view.state, view.dispatch, view);\n };\n\nexport const handleKeydown =\n (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => {\n if (!(e instanceof KeyboardEvent)) return;\n if (!mouseManager.isLock()) mouseManager.lock();\n\n const { key } = e;\n if (status.isEmpty()) return;\n if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key)) return;\n\n const { actions } = status.get();\n\n let active = actions.findIndex(({ $ }) => $.classList.contains('active'));\n if (active < 0) active = 0;\n\n const moveActive = (next: number) => {\n actions[active].$.classList.remove('active');\n actions[next].$.classList.add('active');\n scrollIntoView(actions[next].$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n };\n\n if (key === 'ArrowDown') {\n const next = active === actions.length - 1 ? 0 : active + 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'ArrowUp') {\n const next = active === 0 ? actions.length - 1 : active - 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'Escape') {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n return;\n }\n\n actions[active].command(view.state, view.dispatch, view);\n actions[active].$.classList.remove('active');\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { calculateNodePosition, EditorView } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport { createDropdown } from '../utility';\nimport { renderDropdown } from './dropdown';\nimport {\n createMouseManager,\n handleClick,\n handleKeydown,\n handleMouseEnter,\n handleMouseLeave,\n handleMouseMove,\n} from './input';\nimport { Status } from './status';\n\nconst calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {\n calculateNodePosition(view, dropdownElement, (selected, target, parent) => {\n const $editor = dropdownElement.parentElement;\n if (!$editor) {\n throw new Error();\n }\n\n let left = selected.left - parent.left;\n let top = selected.bottom - parent.top + 14 + $editor.scrollTop;\n\n if (left < 0) {\n left = 0;\n }\n\n if (window.innerHeight - selected.bottom < target.height) {\n top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;\n }\n return [top, left];\n });\n};\n\nexport const createView = (status: Status, view: EditorView, utils: Utils) => {\n const wrapper = view.dom.parentNode;\n if (!wrapper) return {};\n\n const dropdownElement = createDropdown(utils);\n const mouseManager = createMouseManager();\n wrapper.appendChild(dropdownElement);\n\n const _mouseMove = handleMouseMove(mouseManager);\n const _mouseDown = handleClick(status, view, dropdownElement);\n const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);\n const _mouseEnter = handleMouseEnter(status, mouseManager);\n const _mouseLeave = handleMouseLeave();\n\n wrapper.addEventListener('mousemove', _mouseMove);\n wrapper.addEventListener('mousedown', _mouseDown);\n wrapper.addEventListener('keydown', _keydown);\n\n return {\n update: (view: EditorView) => {\n const show = renderDropdown(status, dropdownElement, {\n mouseEnter: _mouseEnter as EventListener,\n mouseLeave: _mouseLeave as EventListener,\n });\n\n if (!show) return;\n\n calculatePosition(view, dropdownElement);\n },\n\n destroy: () => {\n wrapper.removeEventListener('mousemove', _mouseMove);\n wrapper.removeEventListener('mousedown', _mouseDown);\n wrapper.removeEventListener('keydown', _keydown);\n dropdownElement.remove();\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Plugin, PluginKey } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { StatusConfigBuilder } from '..';\nimport { createProps } from './props';\nimport { createStatus } from './status';\nimport { createView } from './view';\n\nexport const key = 'MILKDOWN_PLUGIN_SLASH';\n\nexport const createSlashPlugin = (utils: Utils, builder: StatusConfigBuilder) => {\n const status = createStatus(builder);\n\n return new Plugin({\n key: new PluginKey(key),\n props: createProps(status, utils),\n view: (view) => createView(status, view, utils),\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { AtomList, createPlugin } from '@milkdown/utils';\n\nimport type { Config } from './config';\nimport { defaultConfig } from './config';\nimport { createSlashPlugin } from './prose-plugin';\n\nexport type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';\nexport { defaultActions, defaultConfig } from './config';\nexport { createDropdownItem } from './utility';\n\nexport type Options = {\n config: Config;\n};\n\nexport const slashPlugin = createPlugin<string, Options>((utils, options) => {\n const slashConfig = options?.config ?? defaultConfig;\n\n return {\n prosePlugins: (_, ctx) => {\n const config = slashConfig(ctx);\n\n const plugin = createSlashPlugin(utils, config);\n\n return [plugin];\n },\n };\n});\n\nexport const slash = AtomList.create([slashPlugin()]);\n"],"names":["uploadKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,YAAY,CAAC,EAAE,MAAM,WAAsB,EAAE,UAAmB;SAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAUgB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAOP,QAAQ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BASd,QAAQ,aAAa;AAAA;AAAA;AAAA,6BAGtB,QAAQ;AAAA;AAAA;AAAA;AAAA;MAMxB,cAAc,CAAC,WAAsB,YAAqB;;QAC7D,EAAE,OAAO,MAAM,YAAY;QAC3B,QAAQ,QAAQ;AAAA;AAAA;AAAA;AAAA,UAIhB,YAAM,WAAN;AAAA,yBACe,KAAK;AAAA;AAAA,sBAER,QAAQ;AAAA;AAAA,UAEpB,YAAM,WAAN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAMA,YAAM,cAAN;AAAA;AAAA,UAEA,UAAU,WAAW;AAAA;SAEpB;AAAA;MCpDE,iBAAiB,CAAC,UAAiB;QACtC,MAAM,SAAS,cAAc;MAC/B,aAAa,QAAQ;MACrB,aAAa,YAAY;QACvB,QAAQ,MAAM,SAAS;MAEzB,OAAO;QACH,UAAU,IAAI;AAAA;MAGlB,UAAU,IAAI,kBAAkB;SAE7B;AAAA;MAME,qBAAqB,CAAC,WAAsB,MAAc,MAAY,YAAmC;;QAC5G,gBAAgB,yCAAS,kBAAT,YAA0B;QAE1C,MAAM,S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1
|
+
{"version":3,"file":"index.es.js","sources":["../src/style.ts","../src/utility.ts","../src/config.ts","../src/prose-plugin/props.ts","../src/item.ts","../src/prose-plugin/status.ts","../src/prose-plugin/dropdown.ts","../src/prose-plugin/input.ts","../src/prose-plugin/view.ts","../src/prose-plugin/index.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\n\nconst itemStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => {\n return css`\n .slash-dropdown-item {\n display: flex;\n gap: 2rem;\n height: 3rem;\n padding: 0 1rem;\n align-items: center;\n justify-content: flex-start;\n cursor: pointer;\n line-height: 2;\n font-family: ${font.typography};\n font-size: 0.875rem;\n\n transition: all 0.2s ease-in-out;\n\n &,\n .icon {\n color: ${palette('neutral', 0.87)};\n transition: all 0.2s ease-in-out;\n }\n\n &.hide {\n display: none;\n }\n\n &.active {\n background: ${palette('secondary', 0.12)};\n &,\n .icon {\n color: ${palette('primary')};\n }\n }\n `;\n};\n\nexport const injectStyle = (themeTool: ThemeTool, emotion: Emotion) => {\n const { mixin, size, palette } = themeTool;\n const style = emotion.css`\n width: 20.5rem;\n max-height: 20.5rem;\n overflow-y: auto;\n ${mixin.border?.()};\n border-radius: ${size.radius};\n position: absolute;\n background: ${palette('surface')};\n\n ${mixin.shadow?.()};\n\n &.hide {\n display: none;\n }\n\n ${mixin.scrollbar?.()};\n\n ${itemStyle(themeTool, emotion)}\n `;\n return style;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { ThemeTool } from '@milkdown/core';\nimport type { Icon } from '@milkdown/design-system';\nimport type { Command, Node } from '@milkdown/prose';\nimport type { Utils } from '@milkdown/utils';\n\nimport { injectStyle } from './style';\n\nexport const createDropdown = (utils: Utils) => {\n const div = document.createElement('div');\n div.setAttribute('role', 'listbox');\n div.setAttribute('tabindex', '-1');\n const style = utils.getStyle(injectStyle);\n\n if (style) {\n div.classList.add(style);\n }\n\n div.classList.add('slash-dropdown', 'hide');\n\n return div;\n};\n\ntype ItemOptions = {\n textClassName: string;\n};\nexport const createDropdownItem = (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions>) => {\n const textClassName = options?.textClassName ?? 'text';\n\n const div = document.createElement('div');\n div.setAttribute('role', 'option');\n div.classList.add('slash-dropdown-item');\n\n const iconSpan = themeTool.slots.icon(icon);\n\n const textSpan = document.createElement('span');\n textSpan.textContent = text;\n textSpan.className = textClassName;\n\n div.appendChild(iconSpan);\n div.appendChild(textSpan);\n\n return div;\n};\n\nexport const getDepth = (node: Node) => {\n let cur = node;\n let depth = 0;\n while (cur.childCount) {\n cur = cur.child(0);\n depth += 1;\n }\n\n return depth;\n};\n\nconst cleanUp: Command = (state, dispatch) => {\n const { selection } = state;\n const { $from } = selection;\n const tr = state.tr.deleteRange($from.start(), $from.pos);\n dispatch?.(tr);\n return false;\n};\n\nexport const cleanUpAndCreateNode =\n (createCommand: () => void): Command =>\n (state, dispatch, view) => {\n if (view) {\n cleanUp(state, dispatch, view);\n createCommand();\n }\n return true;\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { commandsCtx, Ctx, schemaCtx, themeToolCtx } from '@milkdown/core';\nimport { EditorState, Node } from '@milkdown/prose';\n\nimport { WrappedAction } from './item';\nimport { createDropdownItem } from './utility';\n\ntype Nullable<T> = T | null | undefined;\n\nexport type StatusConfig = {\n placeholder?: Nullable<string>;\n actions?: Nullable<WrappedAction[]>;\n};\n\nexport type StatusConfigBuilderParams = {\n content: string;\n isTopLevel: boolean;\n parentNode: Node;\n state: EditorState;\n};\n\nexport type StatusConfigBuilder = (params: StatusConfigBuilderParams) => Nullable<StatusConfig>;\n\nexport type Config = (ctx: Ctx) => StatusConfigBuilder;\n\nexport const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {\n const { nodes } = ctx.get(schemaCtx);\n const actions: Array<WrappedAction & { keyword: string[]; typeName: string }> = [\n {\n id: 'h1',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 1),\n keyword: ['h1', 'large heading'],\n typeName: 'heading',\n },\n {\n id: 'h2',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 2),\n keyword: ['h2', 'medium heading'],\n typeName: 'heading',\n },\n {\n id: 'h3',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 3),\n keyword: ['h3', 'small heading'],\n typeName: 'heading',\n },\n {\n id: 'bulletList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBulletList'),\n keyword: ['bullet list', 'ul'],\n typeName: 'bullet_list',\n },\n {\n id: 'orderedList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInOrderedList'),\n keyword: ['ordered list', 'ol'],\n typeName: 'ordered_list',\n },\n {\n id: 'taskList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoTaskList'),\n keyword: ['task list', 'task'],\n typeName: 'task_list_item',\n },\n {\n id: 'image',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),\n command: () => ctx.get(commandsCtx).callByName('InsertImage'),\n keyword: ['image'],\n typeName: 'image',\n },\n {\n id: 'blockquote',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBlockquote'),\n keyword: ['quote', 'blockquote'],\n typeName: 'blockquote',\n },\n {\n id: 'table',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),\n command: () => ctx.get(commandsCtx).callByName('InsertTable'),\n keyword: ['table'],\n typeName: 'table',\n },\n {\n id: 'code',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoCodeFence'),\n keyword: ['code'],\n typeName: 'fence',\n },\n {\n id: 'divider',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),\n command: () => ctx.get(commandsCtx).callByName('InsertHr'),\n keyword: ['divider', 'hr'],\n typeName: 'hr',\n },\n ];\n\n const userInput = input.slice(1).toLocaleLowerCase();\n\n return actions\n .filter((action) => !!nodes[action.typeName] && action.keyword.some((keyword) => keyword.includes(userInput)))\n .map(({ keyword, typeName, ...action }) => action);\n};\n\nexport const defaultConfig: Config = (ctx) => {\n return ({ content, isTopLevel }) => {\n if (!isTopLevel) return null;\n\n if (!content) {\n return { placeholder: 'Type / to use the slash commands...' };\n }\n\n if (content.startsWith('/')) {\n return content === '/'\n ? {\n placeholder: 'Type to filter...',\n actions: defaultActions(ctx),\n }\n : {\n actions: defaultActions(ctx, content),\n };\n }\n\n return null;\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\nimport { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { Status } from './status';\n\nexport type Props = ReturnType<typeof createProps>;\n\nconst createEmptyStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => css`\n position: relative;\n &::before {\n position: absolute;\n cursor: text;\n font-family: ${font.typography};\n font-size: 0.875rem;\n color: ${palette('neutral', 0.6)};\n content: attr(data-text);\n height: 100%;\n display: flex;\n align-items: center;\n }\n`;\n\nconst createSlashStyle = (_: ThemeTool, { css }: Emotion) => css`\n &::before {\n left: 0.5rem;\n }\n`;\n\nexport const createProps = (status: Status, utils: Utils) => {\n const emptyStyle = utils.getStyle(createEmptyStyle);\n const slashStyle = utils.getStyle(createSlashStyle);\n\n return {\n handleKeyDown: (_: EditorView, event: Event) => {\n if (status.isEmpty()) {\n return false;\n }\n if (!(event instanceof KeyboardEvent)) {\n return false;\n }\n\n if (!['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {\n return false;\n }\n\n return true;\n },\n decorations: (state: EditorState) => {\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);\n const uploadPlugin = state.plugins.find(\n (x) => (x as unknown as { key: string }).key === 'MILKDOWN_PLUGIN_UPLOAD$',\n );\n const decorations: DecorationSet = uploadPlugin?.getState(state);\n if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {\n status.clear();\n return;\n }\n\n if (\n !paragraph ||\n paragraph.node.childCount > 1 ||\n state.selection.$from.parentOffset !== paragraph.node.textContent.length ||\n (paragraph.node.firstChild && paragraph.node.firstChild.type.name !== 'text')\n ) {\n status.clear();\n return;\n }\n\n const { placeholder, actions } = status.update({\n parentNode: state.selection.$from.node(state.selection.$from.depth - 1),\n isTopLevel: state.selection.$from.depth === 1,\n content: paragraph.node.textContent,\n state,\n });\n\n if (!placeholder) {\n return null;\n }\n\n const createDecoration = (text: string, className: (string | undefined)[]) => {\n const pos = paragraph.pos;\n return DecorationSet.create(state.doc, [\n Decoration.node(pos, pos + paragraph.node.nodeSize, {\n class: className.filter((x) => x).join(' '),\n 'data-text': text,\n }),\n ]);\n };\n\n if (actions.length) {\n return createDecoration(placeholder, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);\n }\n\n return createDecoration(placeholder, [emptyStyle, 'empty-node']);\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Command } from '@milkdown/prose';\n\nimport { cleanUpAndCreateNode } from './utility';\n\nexport type Action = {\n id: string;\n $: HTMLElement;\n command: Command;\n};\n\nexport type WrappedAction = Pick<Action, 'id'> & {\n command: () => void;\n dom: HTMLElement;\n};\n\nexport const transformAction = (action: WrappedAction): Action => ({\n id: action.id,\n $: action.dom,\n command: cleanUpAndCreateNode(action.command),\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { StatusConfigBuilder, StatusConfigBuilderParams } from '..';\nimport { Action, transformAction } from '../item';\n\nexport type StatusCtx = {\n placeholder: string | null;\n actions: Action[];\n};\n\nconst createStatusCtx = (): StatusCtx => {\n return {\n placeholder: null,\n actions: [],\n };\n};\n\nexport type Status = ReturnType<typeof createStatus>;\n\nexport const createStatus = (builder: StatusConfigBuilder) => {\n const statusCtx = createStatusCtx();\n\n return {\n get: () => statusCtx,\n clear: () => {\n statusCtx.placeholder = null;\n statusCtx.actions = [];\n },\n update: (builderParams: StatusConfigBuilderParams) => {\n const config = builder(builderParams);\n statusCtx.placeholder = config?.placeholder ?? null;\n statusCtx.actions = (config?.actions ?? []).map(transformAction);\n return statusCtx;\n },\n isEmpty: () => statusCtx.actions.length === 0,\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\ntype Listeners = {\n mouseEnter: EventListener;\n mouseLeave: EventListener;\n};\n\nexport const renderDropdown = (status: Status, dropdownElement: HTMLElement, listeners: Listeners): boolean => {\n const { actions } = status.get();\n\n if (!actions.length) {\n dropdownElement.classList.add('hide');\n return false;\n }\n\n dropdownElement.childNodes.forEach((child) => {\n child.removeEventListener('mouseenter', listeners.mouseEnter);\n child.removeEventListener('mouseleave', listeners.mouseLeave);\n });\n\n // Reset dropdownElement children\n dropdownElement.textContent = '';\n\n actions.forEach(({ $ }) => {\n $.classList.remove('active');\n $.addEventListener('mouseenter', listeners.mouseEnter);\n $.addEventListener('mouseleave', listeners.mouseLeave);\n dropdownElement.appendChild($);\n });\n\n dropdownElement.classList.remove('hide');\n\n actions[0].$.classList.add('active');\n requestAnimationFrame(() => {\n scrollIntoView(actions[0].$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n });\n\n return true;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { EditorView } from '@milkdown/prose';\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\nexport const createMouseManager = () => {\n let mouseLock = false;\n\n return {\n isLock: () => mouseLock,\n lock: () => {\n mouseLock = true;\n },\n unlock: () => {\n mouseLock = false;\n },\n };\n};\nexport type MouseManager = ReturnType<typeof createMouseManager>;\n\nexport const handleMouseMove = (mouseManager: MouseManager) => () => {\n mouseManager.unlock();\n};\n\nexport const handleMouseEnter = (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => {\n if (mouseManager.isLock()) return;\n const { actions } = status.get();\n const active = actions.findIndex((x) => x.$.classList.contains('active'));\n if (active >= 0) {\n actions[active].$.classList.remove('active');\n }\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.add('active');\n};\n\nexport const handleMouseLeave = () => (e: MouseEvent) => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.remove('active');\n};\n\nexport const handleClick =\n (status: Status, view: EditorView, dropdownElement: HTMLElement) =>\n (e: Event): void => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n if (!view) return;\n\n const stop = () => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const { actions } = status.get();\n\n const el = Object.values(actions).find(({ $ }) => $.contains(target));\n if (!el) {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n stop();\n\n return;\n }\n\n stop();\n el.command(view.state, view.dispatch, view);\n };\n\nexport const handleKeydown =\n (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => {\n if (!(e instanceof KeyboardEvent)) return;\n if (!mouseManager.isLock()) mouseManager.lock();\n\n const { key } = e;\n if (status.isEmpty()) return;\n if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key)) return;\n\n const { actions } = status.get();\n\n let active = actions.findIndex(({ $ }) => $.classList.contains('active'));\n if (active < 0) active = 0;\n\n const moveActive = (next: number) => {\n actions[active].$.classList.remove('active');\n actions[next].$.classList.add('active');\n scrollIntoView(actions[next].$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n };\n\n if (key === 'ArrowDown') {\n const next = active === actions.length - 1 ? 0 : active + 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'ArrowUp') {\n const next = active === 0 ? actions.length - 1 : active - 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'Escape') {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n return;\n }\n\n actions[active].command(view.state, view.dispatch, view);\n actions[active].$.classList.remove('active');\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { calculateNodePosition, EditorView } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport { createDropdown } from '../utility';\nimport { renderDropdown } from './dropdown';\nimport {\n createMouseManager,\n handleClick,\n handleKeydown,\n handleMouseEnter,\n handleMouseLeave,\n handleMouseMove,\n} from './input';\nimport { Status } from './status';\n\nconst calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {\n calculateNodePosition(view, dropdownElement, (selected, target, parent) => {\n const $editor = dropdownElement.parentElement;\n if (!$editor) {\n throw new Error();\n }\n\n let left = selected.left - parent.left;\n let top = selected.bottom - parent.top + 14 + $editor.scrollTop;\n\n if (left < 0) {\n left = 0;\n }\n\n if (window.innerHeight - selected.bottom < target.height) {\n top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;\n }\n return [top, left];\n });\n};\n\nexport const createView = (status: Status, view: EditorView, utils: Utils) => {\n const wrapper = view.dom.parentNode;\n if (!wrapper) return {};\n\n const dropdownElement = createDropdown(utils);\n const mouseManager = createMouseManager();\n wrapper.appendChild(dropdownElement);\n\n const _mouseMove = handleMouseMove(mouseManager);\n const _mouseDown = handleClick(status, view, dropdownElement);\n const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);\n const _mouseEnter = handleMouseEnter(status, mouseManager);\n const _mouseLeave = handleMouseLeave();\n\n wrapper.addEventListener('mousemove', _mouseMove);\n wrapper.addEventListener('mousedown', _mouseDown);\n wrapper.addEventListener('keydown', _keydown);\n\n return {\n update: (view: EditorView) => {\n const show = renderDropdown(status, dropdownElement, {\n mouseEnter: _mouseEnter as EventListener,\n mouseLeave: _mouseLeave as EventListener,\n });\n\n if (!show) return;\n\n calculatePosition(view, dropdownElement);\n },\n\n destroy: () => {\n wrapper.removeEventListener('mousemove', _mouseMove);\n wrapper.removeEventListener('mousedown', _mouseDown);\n wrapper.removeEventListener('keydown', _keydown);\n dropdownElement.remove();\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Plugin, PluginKey } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { StatusConfigBuilder } from '..';\nimport { createProps } from './props';\nimport { createStatus } from './status';\nimport { createView } from './view';\n\nexport const key = 'MILKDOWN_PLUGIN_SLASH';\n\nexport const createSlashPlugin = (utils: Utils, builder: StatusConfigBuilder) => {\n const status = createStatus(builder);\n\n return new Plugin({\n key: new PluginKey(key),\n props: createProps(status, utils),\n view: (view) => createView(status, view, utils),\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { AtomList, createPlugin } from '@milkdown/utils';\n\nimport type { Config } from './config';\nimport { defaultConfig } from './config';\nimport { createSlashPlugin } from './prose-plugin';\n\nexport type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';\nexport { defaultActions, defaultConfig } from './config';\nexport { createDropdownItem } from './utility';\n\nexport type Options = {\n config: Config;\n};\n\nexport const slashPlugin = createPlugin<string, Options>((utils, options) => {\n const slashConfig = options?.config ?? defaultConfig;\n\n return {\n prosePlugins: (_, ctx) => {\n const config = slashConfig(ctx);\n\n const plugin = createSlashPlugin(utils, config);\n\n return [plugin];\n },\n };\n});\n\nexport const slash = AtomList.create([slashPlugin()]);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,MAAM,YAAY,CAAC,EAAE,MAAM,WAAsB,EAAE,UAAmB;SAC3D;AAAA;AAAA;AAAA;AAAA;AA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,MAAM;QACvC,WAAW,cAAc,QAAQ,MAAM,iBAAiB;QACxD,cAAc,iBAAiB,QAAQ;QACvC,cAAc;UAEZ,iBAAiB,aAAa;UAC9B,iBAAiB,aAAa;UAC9B,iBAAiB,WAAW;SAE7B;AAAA,IACH,QAAQ,CAAC,UAAqB;YACpB,OAAO,eAAe,QAAQ,iBAAiB;AAAA,QACjD,YAAY;AAAA,QACZ,YAAY;AAAA;UAGZ,CAAC;;wBAEa,OAAM;AAAA;AAAA,IAG5B,SAAS,MAAM;cACH,oBAAoB,aAAa;cACjC,oBAAoB,aAAa;cACjC,oBAAoB,WAAW;sBACvB;AAAA;AAAA;AAAA;MC9Df,MAAM;MAEN,oBAAoB,CAAC,OAAc,YAAiC;QACvE,SAAS,aAAa;SAErB,IAAI,OAAO;AAAA,IACd,KAAK,IAAI,UAAU;AAAA,IACnB,OAAO,YAAY,QAAQ;AAAA,IAC3B,MAAM,CAAC,SAAS,WAAW,QAAQ,MAAM;AAAA;AAAA;MCFpC,cAAc,aAA8B,CAAC,OAAO,YAAY;;QACnE,cAAc,yCAAS,WAAT,YAAmB;SAEhC;AAAA,IACH,cAAc,CAAC,GAAG,QAAQ;YAChB,SAAS,YAAY;YAErB,SAAS,kBAAkB,OAAO;aAEjC,CAAC;AAAA;AAAA;AAAA;MAKP,QAAQ,SAAS,OAAO,CAAC;;"}
|
package/lib/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAA2B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAA2B,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC,oBAAY,YAAY,GAAG;IACvB,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,oBAAY,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEhG,oBAAY,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,CAAC;AAEvD,eAAO,MAAM,cAAc,QAAS,GAAG,qBAAgB,aAAa,EAuFnE,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAqB3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["props.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["props.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,aAAa,EAAE,WAAW,EAAE,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,oBAAY,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAuBnD,eAAO,MAAM,WAAW,WAAY,MAAM,SAAS,KAAK;uBAK7B,UAAU,SAAS,KAAK;yBActB,WAAW;CAiDvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/plugin-slash",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.es.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -15,18 +15,16 @@
|
|
|
15
15
|
"milkdown plugin"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@milkdown/core": "5.4.
|
|
19
|
-
"@milkdown/prose": "5.4.
|
|
20
|
-
"@milkdown/design-system": "5.4.
|
|
21
|
-
"@milkdown/preset-gfm": "5.4.0",
|
|
22
|
-
"@milkdown/plugin-upload": "5.4.0"
|
|
18
|
+
"@milkdown/core": "5.4.1",
|
|
19
|
+
"@milkdown/prose": "5.4.1",
|
|
20
|
+
"@milkdown/design-system": "5.4.1"
|
|
23
21
|
},
|
|
24
22
|
"peerDependencies": {
|
|
25
23
|
"@milkdown/core": "^5.4.0",
|
|
26
24
|
"@milkdown/prose": "^5.4.0"
|
|
27
25
|
},
|
|
28
26
|
"dependencies": {
|
|
29
|
-
"@milkdown/utils": "5.4.
|
|
27
|
+
"@milkdown/utils": "5.4.1",
|
|
30
28
|
"smooth-scroll-into-view-if-needed": "^1.1.32",
|
|
31
29
|
"tslib": "^2.3.1"
|
|
32
30
|
},
|
package/src/config.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx, Ctx, schemaCtx, themeToolCtx } from '@milkdown/core';
|
|
3
|
-
import {
|
|
4
|
-
InsertHr,
|
|
5
|
-
InsertImage,
|
|
6
|
-
InsertTable,
|
|
7
|
-
TurnIntoCodeFence,
|
|
8
|
-
TurnIntoHeading,
|
|
9
|
-
TurnIntoTaskList,
|
|
10
|
-
WrapInBlockquote,
|
|
11
|
-
WrapInBulletList,
|
|
12
|
-
WrapInOrderedList,
|
|
13
|
-
} from '@milkdown/preset-gfm';
|
|
14
3
|
import { EditorState, Node } from '@milkdown/prose';
|
|
15
4
|
|
|
16
5
|
import { WrappedAction } from './item';
|
|
@@ -40,77 +29,77 @@ export const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {
|
|
|
40
29
|
{
|
|
41
30
|
id: 'h1',
|
|
42
31
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
|
|
43
|
-
command: () => ctx.get(commandsCtx).
|
|
32
|
+
command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 1),
|
|
44
33
|
keyword: ['h1', 'large heading'],
|
|
45
34
|
typeName: 'heading',
|
|
46
35
|
},
|
|
47
36
|
{
|
|
48
37
|
id: 'h2',
|
|
49
38
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
|
|
50
|
-
command: () => ctx.get(commandsCtx).
|
|
39
|
+
command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 2),
|
|
51
40
|
keyword: ['h2', 'medium heading'],
|
|
52
41
|
typeName: 'heading',
|
|
53
42
|
},
|
|
54
43
|
{
|
|
55
44
|
id: 'h3',
|
|
56
45
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
|
|
57
|
-
command: () => ctx.get(commandsCtx).
|
|
46
|
+
command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 3),
|
|
58
47
|
keyword: ['h3', 'small heading'],
|
|
59
48
|
typeName: 'heading',
|
|
60
49
|
},
|
|
61
50
|
{
|
|
62
51
|
id: 'bulletList',
|
|
63
52
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
|
|
64
|
-
command: () => ctx.get(commandsCtx).
|
|
53
|
+
command: () => ctx.get(commandsCtx).callByName('WrapInBulletList'),
|
|
65
54
|
keyword: ['bullet list', 'ul'],
|
|
66
55
|
typeName: 'bullet_list',
|
|
67
56
|
},
|
|
68
57
|
{
|
|
69
58
|
id: 'orderedList',
|
|
70
59
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
|
|
71
|
-
command: () => ctx.get(commandsCtx).
|
|
60
|
+
command: () => ctx.get(commandsCtx).callByName('WrapInOrderedList'),
|
|
72
61
|
keyword: ['ordered list', 'ol'],
|
|
73
62
|
typeName: 'ordered_list',
|
|
74
63
|
},
|
|
75
64
|
{
|
|
76
65
|
id: 'taskList',
|
|
77
66
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
|
|
78
|
-
command: () => ctx.get(commandsCtx).
|
|
67
|
+
command: () => ctx.get(commandsCtx).callByName('TurnIntoTaskList'),
|
|
79
68
|
keyword: ['task list', 'task'],
|
|
80
69
|
typeName: 'task_list_item',
|
|
81
70
|
},
|
|
82
71
|
{
|
|
83
72
|
id: 'image',
|
|
84
73
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
|
|
85
|
-
command: () => ctx.get(commandsCtx).
|
|
74
|
+
command: () => ctx.get(commandsCtx).callByName('InsertImage'),
|
|
86
75
|
keyword: ['image'],
|
|
87
76
|
typeName: 'image',
|
|
88
77
|
},
|
|
89
78
|
{
|
|
90
79
|
id: 'blockquote',
|
|
91
80
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
|
|
92
|
-
command: () => ctx.get(commandsCtx).
|
|
81
|
+
command: () => ctx.get(commandsCtx).callByName('WrapInBlockquote'),
|
|
93
82
|
keyword: ['quote', 'blockquote'],
|
|
94
83
|
typeName: 'blockquote',
|
|
95
84
|
},
|
|
96
85
|
{
|
|
97
86
|
id: 'table',
|
|
98
87
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
|
|
99
|
-
command: () => ctx.get(commandsCtx).
|
|
88
|
+
command: () => ctx.get(commandsCtx).callByName('InsertTable'),
|
|
100
89
|
keyword: ['table'],
|
|
101
90
|
typeName: 'table',
|
|
102
91
|
},
|
|
103
92
|
{
|
|
104
93
|
id: 'code',
|
|
105
94
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
|
|
106
|
-
command: () => ctx.get(commandsCtx).
|
|
95
|
+
command: () => ctx.get(commandsCtx).callByName('TurnIntoCodeFence'),
|
|
107
96
|
keyword: ['code'],
|
|
108
97
|
typeName: 'fence',
|
|
109
98
|
},
|
|
110
99
|
{
|
|
111
100
|
id: 'divider',
|
|
112
101
|
dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
|
|
113
|
-
command: () => ctx.get(commandsCtx).
|
|
102
|
+
command: () => ctx.get(commandsCtx).callByName('InsertHr'),
|
|
114
103
|
keyword: ['divider', 'hr'],
|
|
115
104
|
typeName: 'hr',
|
|
116
105
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { Emotion, ThemeTool } from '@milkdown/core';
|
|
3
|
-
import { key as uploadKey } from '@milkdown/plugin-upload';
|
|
4
3
|
import { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';
|
|
5
4
|
import { Utils } from '@milkdown/utils';
|
|
6
5
|
|
|
@@ -50,7 +49,9 @@ export const createProps = (status: Status, utils: Utils) => {
|
|
|
50
49
|
},
|
|
51
50
|
decorations: (state: EditorState) => {
|
|
52
51
|
const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);
|
|
53
|
-
const uploadPlugin = state.plugins.find(
|
|
52
|
+
const uploadPlugin = state.plugins.find(
|
|
53
|
+
(x) => (x as unknown as { key: string }).key === 'MILKDOWN_PLUGIN_UPLOAD$',
|
|
54
|
+
);
|
|
54
55
|
const decorations: DecorationSet = uploadPlugin?.getState(state);
|
|
55
56
|
if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {
|
|
56
57
|
status.clear();
|