@milkdown/plugin-tooltip 4.11.2 → 4.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/button-manager/create-tooltip.d.ts +6 -1
- package/lib/button-manager/create-tooltip.d.ts.map +1 -1
- package/lib/button-manager/create-tooltip.js +11 -7
- package/lib/button-manager/create-tooltip.js.map +1 -1
- package/lib/button-manager/index.d.ts +2 -1
- package/lib/button-manager/index.d.ts.map +1 -1
- package/lib/button-manager/index.js +3 -2
- package/lib/button-manager/index.js.map +1 -1
- package/lib/button-manager/style.d.ts.map +1 -1
- package/lib/button-manager/style.js +1 -0
- package/lib/button-manager/style.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +32 -11
- package/lib/index.js.map +1 -1
- package/lib/input-manager/filter-input.d.ts +16 -1
- package/lib/input-manager/filter-input.d.ts.map +1 -1
- package/lib/input-manager/filter-input.js +8 -2
- package/lib/input-manager/filter-input.js.map +1 -1
- package/lib/input-manager/index.d.ts +2 -1
- package/lib/input-manager/index.d.ts.map +1 -1
- package/lib/input-manager/index.js +19 -7
- package/lib/input-manager/index.js.map +1 -1
- package/lib/input-manager/style.d.ts.map +1 -1
- package/lib/input-manager/style.js +5 -1
- package/lib/input-manager/style.js.map +1 -1
- package/lib/item.d.ts +10 -2
- package/lib/item.d.ts.map +1 -1
- package/lib/item.js +4 -2
- package/lib/item.js.map +1 -1
- package/lib/selection-marks-tooltip.d.ts +3 -1
- package/lib/selection-marks-tooltip.d.ts.map +1 -1
- package/lib/selection-marks-tooltip.js +13 -5
- package/lib/selection-marks-tooltip.js.map +1 -1
- package/lib/utility/input.d.ts +2 -0
- package/lib/utility/input.d.ts.map +1 -1
- package/lib/utility/input.js +33 -0
- package/lib/utility/input.js.map +1 -1
- package/lib/utility/prosemirror.d.ts.map +1 -1
- package/lib/utility/prosemirror.js +2 -2
- package/lib/utility/prosemirror.js.map +1 -1
- package/package.json +5 -3
- package/src/button-manager/calc-button-pos.ts +16 -0
- package/src/button-manager/create-tooltip.ts +32 -0
- package/src/button-manager/filter-button.ts +28 -0
- package/src/button-manager/index.ts +44 -0
- package/src/button-manager/no-active.ts +10 -0
- package/src/button-manager/style.ts +50 -0
- package/src/index.ts +56 -0
- package/src/input-manager/calc-input-pos.ts +15 -0
- package/src/input-manager/create-input.ts +39 -0
- package/src/input-manager/filter-input.ts +33 -0
- package/src/input-manager/index.ts +55 -0
- package/src/input-manager/style.ts +67 -0
- package/src/item.ts +117 -0
- package/src/selection-marks-tooltip.ts +50 -0
- package/src/utility/element.ts +3 -0
- package/src/utility/index.ts +5 -0
- package/src/utility/input.ts +133 -0
- package/src/utility/prosemirror.ts +37 -0
- package/src/utility/toggle.ts +21 -0
package/lib/utility/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/utility/input.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,WAAW,EAAO,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,CAAC,MAAM,UAAU,GACnB,CAAC,GAAQ,EAAiB,EAAE,CAC5B,CAAC,CAAC,EAAE,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACrB,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE;QAClC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC;KACrB;IACD,IAAI,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAC/B,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;KACtB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,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAE/D,oBAAY,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,OAAO,gBAAiB,WAAW,QAAQ,QAAQ,KAAG,OAIlE,CAAC;AAEF,eAAO,MAAM,eAAe,gBAAiB,WAAW,KAAG,OAU1D,CAAC;AAEF,eAAO,MAAM,aAAa,gBAAiB,WAAW,KAAG,
|
|
1
|
+
{"version":3,"file":"prosemirror.d.ts","sourceRoot":"","sources":["../../src/utility/prosemirror.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAE/D,oBAAY,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,OAAO,gBAAiB,WAAW,QAAQ,QAAQ,KAAG,OAIlE,CAAC;AAEF,eAAO,MAAM,eAAe,gBAAiB,WAAW,KAAG,OAU1D,CAAC;AAEF,eAAO,MAAM,aAAa,gBAAiB,WAAW,KAAG,OAC0B,CAAC;AAEpF,eAAO,MAAM,mBAAmB,gBAAiB,WAAW,QAAQ,QAAQ,KAAG,OACc,CAAC;AAE9F,eAAO,MAAM,aAAa,aAAc,QAAQ,QAAQ,IAAI,YAE3D,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { findParentNode } from '@milkdown/utils';
|
|
|
3
3
|
import { TextSelection } from 'prosemirror-state';
|
|
4
4
|
export const hasMark = (editorState, type) => {
|
|
5
5
|
const { from, to } = editorState.selection;
|
|
6
|
-
return editorState.doc.rangeHasMark(from, to, type);
|
|
6
|
+
return editorState.doc.rangeHasMark(from, from === to ? to + 1 : to, type);
|
|
7
7
|
};
|
|
8
8
|
export const isTextSelection = (editorState) => {
|
|
9
9
|
const { selection } = editorState;
|
|
@@ -15,7 +15,7 @@ export const isTextSelection = (editorState) => {
|
|
|
15
15
|
}
|
|
16
16
|
return false;
|
|
17
17
|
};
|
|
18
|
-
export const isInCodeFence = (editorState) => Boolean(findParentNode((node) => node.type.
|
|
18
|
+
export const isInCodeFence = (editorState) => Boolean(findParentNode((node) => !!node.type.spec.code)(editorState.selection));
|
|
19
19
|
export const isTextAndNotHasMark = (editorState, mark) => !isTextSelection(editorState) || isInCodeFence(editorState) || hasMark(editorState, mark);
|
|
20
20
|
export const equalNodeType = (nodeType, node) => {
|
|
21
21
|
return (Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1) || node.type === nodeType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosemirror.js","sourceRoot":"","sources":["../../src/utility/prosemirror.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAO/D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,WAAwB,EAAE,IAAc,EAAW,EAAE;IACzE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,WAAW,CAAC,SAAS,CAAC;IAE3C,OAAO,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"prosemirror.js","sourceRoot":"","sources":["../../src/utility/prosemirror.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAO/D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,WAAwB,EAAE,IAAc,EAAW,EAAE;IACzE,MAAM,EAAE,IA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C,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;AACnG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/plugin-tooltip",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"files": [
|
|
10
|
-
"lib"
|
|
10
|
+
"lib",
|
|
11
|
+
"src"
|
|
11
12
|
],
|
|
12
13
|
"keywords": [
|
|
13
14
|
"milkdown",
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
],
|
|
16
17
|
"peerDependencies": {
|
|
17
18
|
"@milkdown/core": "*",
|
|
18
|
-
"@milkdown/preset-gfm": "*"
|
|
19
|
+
"@milkdown/preset-gfm": "*",
|
|
20
|
+
"@milkdown/plugin-math": "*"
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"@emotion/css": "^11.1.3",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { calculateTextPosition } from '@milkdown/utils';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
|
|
5
|
+
export const calcButtonPos = (buttons: HTMLElement, view: EditorView) => {
|
|
6
|
+
buttons.classList.remove('hide');
|
|
7
|
+
calculateTextPosition(view, buttons, (start, end, target, parent) => {
|
|
8
|
+
const selectionWidth = end.left - start.left;
|
|
9
|
+
let left = start.left - parent.left - (target.width - selectionWidth) / 2;
|
|
10
|
+
const top = start.top - parent.top - target.height - 14;
|
|
11
|
+
|
|
12
|
+
if (left < 0) left = 0;
|
|
13
|
+
|
|
14
|
+
return [top, left];
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Utils } from '@milkdown/utils';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
|
|
5
|
+
import type { ButtonMap } from '../item';
|
|
6
|
+
import { injectStyle } from './style';
|
|
7
|
+
|
|
8
|
+
type Tooltip = {
|
|
9
|
+
dom: HTMLDivElement;
|
|
10
|
+
render: (editorView: EditorView) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createTooltip = (buttonMap: ButtonMap, utils: Utils): Tooltip => {
|
|
14
|
+
const div = document.createElement('div');
|
|
15
|
+
const style = utils.getStyle(injectStyle) || '';
|
|
16
|
+
if (style) {
|
|
17
|
+
div.classList.add(style);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
div.classList.add('tooltip');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
dom: div,
|
|
24
|
+
render: (editorView: EditorView) => {
|
|
25
|
+
Object.values(buttonMap)
|
|
26
|
+
.filter((item) => item.enable(editorView))
|
|
27
|
+
.forEach(({ $ }) => div.appendChild($));
|
|
28
|
+
|
|
29
|
+
editorView.dom.parentNode?.appendChild(div);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
|
|
4
|
+
import { ButtonMap } from '../item';
|
|
5
|
+
import { noActive } from './no-active';
|
|
6
|
+
|
|
7
|
+
export const filterButton = (buttonMap: ButtonMap, view: EditorView) => {
|
|
8
|
+
Object.values(buttonMap)
|
|
9
|
+
.filter((item) => item.enable(view))
|
|
10
|
+
.forEach((item) => {
|
|
11
|
+
const disable = item.disable?.(view);
|
|
12
|
+
if (disable) {
|
|
13
|
+
item.$.classList.add('hide');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
item.$.classList.remove('hide');
|
|
18
|
+
|
|
19
|
+
const active = item.active(view);
|
|
20
|
+
if (active) {
|
|
21
|
+
item.$.classList.add('active');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
item.$.classList.remove('active');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return noActive(buttonMap, view);
|
|
28
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Utils } from '@milkdown/utils';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
|
|
5
|
+
import type { ButtonMap } from '../item';
|
|
6
|
+
import { calcButtonPos } from './calc-button-pos';
|
|
7
|
+
import { createTooltip } from './create-tooltip';
|
|
8
|
+
import { filterButton } from './filter-button';
|
|
9
|
+
|
|
10
|
+
export const createButtonManager = (buttonMap: ButtonMap, utils: Utils) => {
|
|
11
|
+
const { dom: buttons, render } = createTooltip(buttonMap, utils);
|
|
12
|
+
|
|
13
|
+
const onClick = (e: Event) => {
|
|
14
|
+
const target = Object.values(buttonMap).find(({ $ }) => e.target instanceof Element && $.contains(e.target));
|
|
15
|
+
if (!target) return;
|
|
16
|
+
|
|
17
|
+
e.stopPropagation();
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
target.command();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const hide = () => {
|
|
23
|
+
buttons.classList.add('hide');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
buttons.addEventListener('mousedown', onClick);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
destroy: () => {
|
|
30
|
+
buttons.removeEventListener('mousedown', onClick);
|
|
31
|
+
buttons.remove();
|
|
32
|
+
},
|
|
33
|
+
hide,
|
|
34
|
+
update: (editorView: EditorView) => {
|
|
35
|
+
const noActive = filterButton(buttonMap, editorView);
|
|
36
|
+
if (noActive) {
|
|
37
|
+
hide();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
calcButtonPos(buttons, editorView);
|
|
41
|
+
},
|
|
42
|
+
render,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { EditorView } from 'prosemirror-view';
|
|
3
|
+
|
|
4
|
+
import { ButtonMap } from '../item';
|
|
5
|
+
|
|
6
|
+
export const noActive = (buttonMap: ButtonMap, view: EditorView) => {
|
|
7
|
+
return Object.values(buttonMap)
|
|
8
|
+
.filter((item) => item.enable(view))
|
|
9
|
+
.every(({ $ }) => $.classList.contains('hide'));
|
|
10
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import { ThemeTool } from '@milkdown/core';
|
|
4
|
+
|
|
5
|
+
export const injectStyle = (themeTool: ThemeTool) => {
|
|
6
|
+
const { palette, mixin, size } = themeTool;
|
|
7
|
+
return css`
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
justify-content: space-evenly;
|
|
11
|
+
position: absolute;
|
|
12
|
+
border-radius: ${size.radius};
|
|
13
|
+
z-index: 2;
|
|
14
|
+
|
|
15
|
+
${mixin.border?.()};
|
|
16
|
+
${mixin.shadow?.()};
|
|
17
|
+
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
background: ${palette('surface')};
|
|
20
|
+
|
|
21
|
+
.icon {
|
|
22
|
+
position: relative;
|
|
23
|
+
color: ${palette('solid', 0.87)};
|
|
24
|
+
|
|
25
|
+
width: 3rem;
|
|
26
|
+
line-height: 3rem;
|
|
27
|
+
text-align: center;
|
|
28
|
+
transition: all 0.4s ease-in-out;
|
|
29
|
+
&:hover {
|
|
30
|
+
background-color: ${palette('secondary', 0.12)};
|
|
31
|
+
}
|
|
32
|
+
&.active {
|
|
33
|
+
color: ${palette('primary')};
|
|
34
|
+
}
|
|
35
|
+
&:not(:last-child)::after {
|
|
36
|
+
content: '';
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 0;
|
|
39
|
+
right: calc(-0.5 * ${size.lineWidth});
|
|
40
|
+
width: ${size.lineWidth};
|
|
41
|
+
bottom: 0;
|
|
42
|
+
background: ${palette('line')};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
&.hide,
|
|
46
|
+
.hide {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { schemaCtx } from '@milkdown/core';
|
|
3
|
+
import { AtomList, createProsePlugin } from '@milkdown/utils';
|
|
4
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
5
|
+
|
|
6
|
+
import { buttonMap, inputMap, InputOptions } from './item';
|
|
7
|
+
import { createPlugin } from './selection-marks-tooltip';
|
|
8
|
+
|
|
9
|
+
export const key = new PluginKey('MILKDOWN_PLUGIN_TOOLTIP');
|
|
10
|
+
|
|
11
|
+
export const tooltipPlugin = createProsePlugin<InputOptions>((options, utils) => {
|
|
12
|
+
const schema = utils.ctx.get(schemaCtx);
|
|
13
|
+
const plugin = createPlugin(
|
|
14
|
+
buttonMap(schema, utils.ctx),
|
|
15
|
+
inputMap(schema, utils.ctx, {
|
|
16
|
+
link: {
|
|
17
|
+
placeholder: 'Input Web Link',
|
|
18
|
+
buttonText: 'APPLY',
|
|
19
|
+
...(options?.link ?? {}),
|
|
20
|
+
},
|
|
21
|
+
image: {
|
|
22
|
+
placeholder: 'Input Image Link',
|
|
23
|
+
buttonText: 'APPLY',
|
|
24
|
+
...(options?.image ?? {}),
|
|
25
|
+
},
|
|
26
|
+
inlineMath: {
|
|
27
|
+
placeholder: 'Input Math',
|
|
28
|
+
...(options?.inlineMath ?? {}),
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
utils,
|
|
32
|
+
);
|
|
33
|
+
return new Plugin({
|
|
34
|
+
key,
|
|
35
|
+
props: {
|
|
36
|
+
handleKeyDown: () => {
|
|
37
|
+
plugin.setHide(true);
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
handleClick: (view) => {
|
|
41
|
+
plugin.setHide(false);
|
|
42
|
+
plugin.update(view);
|
|
43
|
+
return false;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
view: (editorView) => {
|
|
47
|
+
plugin.render(editorView);
|
|
48
|
+
return {
|
|
49
|
+
update: plugin.update,
|
|
50
|
+
destroy: plugin.destroy,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const tooltip = AtomList.create([tooltipPlugin()]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { calculateTextPosition } from '@milkdown/utils';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
|
|
5
|
+
export const calcInputPos = (view: EditorView, input: HTMLDivElement) => {
|
|
6
|
+
calculateTextPosition(view, input, (start, end, target, parent) => {
|
|
7
|
+
const selectionWidth = end.left - start.left;
|
|
8
|
+
let left = start.left - parent.left - (target.width - selectionWidth) / 2;
|
|
9
|
+
const top = start.bottom - parent.top + 14;
|
|
10
|
+
|
|
11
|
+
if (left < 0) left = 0;
|
|
12
|
+
|
|
13
|
+
return [top, left];
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { Utils } from '@milkdown/utils';
|
|
3
|
+
|
|
4
|
+
import { injectStyle } from './style';
|
|
5
|
+
|
|
6
|
+
export const createInput = (utils: Utils) => {
|
|
7
|
+
const div = document.createElement('div');
|
|
8
|
+
const style = utils.getStyle(injectStyle);
|
|
9
|
+
if (style) {
|
|
10
|
+
div.classList.add(style);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.classList.add('tooltip-input');
|
|
14
|
+
|
|
15
|
+
const input = document.createElement('input');
|
|
16
|
+
div.appendChild(input);
|
|
17
|
+
const button = document.createElement('button');
|
|
18
|
+
div.appendChild(button);
|
|
19
|
+
|
|
20
|
+
input.addEventListener('input', (e) => {
|
|
21
|
+
const { target } = e;
|
|
22
|
+
if (!(target instanceof HTMLInputElement)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!target.value) {
|
|
27
|
+
button.classList.add('disable');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
button.classList.remove('disable');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
div,
|
|
36
|
+
input,
|
|
37
|
+
button,
|
|
38
|
+
} as const;
|
|
39
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { EditorView } from 'prosemirror-view';
|
|
3
|
+
|
|
4
|
+
import type { InputMap } from '../item';
|
|
5
|
+
|
|
6
|
+
export const filterInput = (
|
|
7
|
+
currentView: EditorView,
|
|
8
|
+
inputMap: InputMap,
|
|
9
|
+
div: HTMLDivElement,
|
|
10
|
+
input: HTMLInputElement,
|
|
11
|
+
button: HTMLButtonElement,
|
|
12
|
+
) => {
|
|
13
|
+
const target = Object.values(inputMap).find((input) => input.display(currentView));
|
|
14
|
+
|
|
15
|
+
if (!target) {
|
|
16
|
+
div.classList.add('hide');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
div.classList.remove('hide');
|
|
21
|
+
|
|
22
|
+
if (target.bind) {
|
|
23
|
+
button.classList.add('hide');
|
|
24
|
+
} else {
|
|
25
|
+
button.classList.remove('hide');
|
|
26
|
+
button.textContent = target.buttonText;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
input.placeholder = target.placeholder;
|
|
30
|
+
target.update(currentView, div);
|
|
31
|
+
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Utils } from '@milkdown/utils';
|
|
3
|
+
import type { EditorView } from 'prosemirror-view';
|
|
4
|
+
|
|
5
|
+
import type { Event2Command, InputMap } from '../item';
|
|
6
|
+
import { calcInputPos } from './calc-input-pos';
|
|
7
|
+
import { createInput } from './create-input';
|
|
8
|
+
import { filterInput } from './filter-input';
|
|
9
|
+
|
|
10
|
+
export const createInputManager = (inputMap: InputMap, utils: Utils) => {
|
|
11
|
+
let inputCommand: Event2Command | undefined;
|
|
12
|
+
let binding = false;
|
|
13
|
+
const setCommand = (x?: Event2Command) => (inputCommand = x);
|
|
14
|
+
|
|
15
|
+
const { div, button, input } = createInput(utils);
|
|
16
|
+
|
|
17
|
+
const onClick = (e: Event) => {
|
|
18
|
+
if (!inputCommand || button.classList.contains('disable')) return;
|
|
19
|
+
|
|
20
|
+
e.stopPropagation();
|
|
21
|
+
inputCommand(e);
|
|
22
|
+
div.classList.add('hide');
|
|
23
|
+
};
|
|
24
|
+
const onInput = (e: Event) => {
|
|
25
|
+
if (!binding || !inputCommand) return;
|
|
26
|
+
inputCommand(e);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
input.addEventListener('input', onInput);
|
|
30
|
+
button.addEventListener('mousedown', onClick);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
destroy: () => {
|
|
34
|
+
input.removeEventListener('input', onInput);
|
|
35
|
+
div.removeEventListener('mousedown', onClick);
|
|
36
|
+
div.remove();
|
|
37
|
+
},
|
|
38
|
+
hide: () => {
|
|
39
|
+
div.classList.add('hide');
|
|
40
|
+
setCommand();
|
|
41
|
+
},
|
|
42
|
+
update: (editorView: EditorView) => {
|
|
43
|
+
const result = filterInput(editorView, inputMap, div, input, button);
|
|
44
|
+
if (!result) return;
|
|
45
|
+
binding = !!result.bind;
|
|
46
|
+
setCommand(result.command);
|
|
47
|
+
calcInputPos(editorView, div);
|
|
48
|
+
},
|
|
49
|
+
render: (editorView: EditorView) => {
|
|
50
|
+
const wrapper = editorView.dom.parentNode;
|
|
51
|
+
if (!wrapper) throw new Error();
|
|
52
|
+
wrapper.appendChild(div);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import { ThemeTool } from '@milkdown/core';
|
|
4
|
+
|
|
5
|
+
export const injectStyle = (themeTool: ThemeTool) => {
|
|
6
|
+
const { palette, mixin, size } = themeTool;
|
|
7
|
+
|
|
8
|
+
return css`
|
|
9
|
+
${mixin.border?.()};
|
|
10
|
+
${mixin.shadow?.()};
|
|
11
|
+
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
align-items: center;
|
|
15
|
+
position: absolute;
|
|
16
|
+
background: ${palette('surface')};
|
|
17
|
+
border-radius: ${size.radius};
|
|
18
|
+
font-size: 1rem;
|
|
19
|
+
|
|
20
|
+
height: 3.5rem;
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
width: 25.5rem;
|
|
23
|
+
padding: 0 1rem;
|
|
24
|
+
gap: 1rem;
|
|
25
|
+
z-index: 2;
|
|
26
|
+
|
|
27
|
+
input,
|
|
28
|
+
button {
|
|
29
|
+
all: unset;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
input {
|
|
33
|
+
flex-grow: 1;
|
|
34
|
+
caret-color: ${palette('primary')};
|
|
35
|
+
&::placeholder {
|
|
36
|
+
color: ${palette('neutral', 0.6)};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
button {
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
height: 2.25rem;
|
|
43
|
+
color: ${palette('primary')};
|
|
44
|
+
font-size: 0.875rem;
|
|
45
|
+
padding: 0 0.5rem;
|
|
46
|
+
font-weight: 500;
|
|
47
|
+
letter-spacing: 1.25px;
|
|
48
|
+
&:hover {
|
|
49
|
+
background-color: ${palette('secondary', 0.12)};
|
|
50
|
+
}
|
|
51
|
+
&.disable {
|
|
52
|
+
color: ${palette('neutral', 0.38)};
|
|
53
|
+
cursor: not-allowed;
|
|
54
|
+
&:hover {
|
|
55
|
+
background: transparent;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
&.hide {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&.hide {
|
|
64
|
+
display: none;
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
};
|
package/src/item.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Ctx } from '@milkdown/core';
|
|
3
|
+
import { ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, ToggleStrikeThrough } from '@milkdown/preset-gfm';
|
|
4
|
+
import { findSelectedNodeOfType } from '@milkdown/utils';
|
|
5
|
+
import type { Schema } from 'prosemirror-model';
|
|
6
|
+
import { EditorView } from 'prosemirror-view';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
createToggleIcon,
|
|
10
|
+
hasMark,
|
|
11
|
+
modifyImage,
|
|
12
|
+
modifyInlineMath,
|
|
13
|
+
modifyLink,
|
|
14
|
+
updateImageView,
|
|
15
|
+
updateInlineMathView,
|
|
16
|
+
updateLinkView,
|
|
17
|
+
} from './utility';
|
|
18
|
+
|
|
19
|
+
export type Pred = (view: EditorView) => boolean;
|
|
20
|
+
export type Updater = (view: EditorView, $: HTMLElement) => void;
|
|
21
|
+
export type Event2Command = (e: Event) => void;
|
|
22
|
+
|
|
23
|
+
export type ButtonItem = {
|
|
24
|
+
$: HTMLElement;
|
|
25
|
+
command: () => void;
|
|
26
|
+
active: Pred;
|
|
27
|
+
disable?: Pred;
|
|
28
|
+
enable: Pred;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type InputItem = {
|
|
32
|
+
command: Event2Command;
|
|
33
|
+
display: Pred;
|
|
34
|
+
update: Updater;
|
|
35
|
+
placeholder: string;
|
|
36
|
+
} & (
|
|
37
|
+
| {
|
|
38
|
+
bind: true;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
bind?: false;
|
|
42
|
+
buttonText: string;
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export enum ButtonAction {
|
|
47
|
+
ToggleBold,
|
|
48
|
+
ToggleItalic,
|
|
49
|
+
ToggleStrike,
|
|
50
|
+
ToggleCode,
|
|
51
|
+
ToggleLink,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export enum InputAction {
|
|
55
|
+
ModifyLink,
|
|
56
|
+
ModifyImage,
|
|
57
|
+
ModifyInlineMath,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type ButtonMap = Record<ButtonAction, ButtonItem>;
|
|
61
|
+
export type InputMap = Record<InputAction, InputItem>;
|
|
62
|
+
|
|
63
|
+
export type InputOptions = {
|
|
64
|
+
link: {
|
|
65
|
+
placeholder: string;
|
|
66
|
+
buttonText: string;
|
|
67
|
+
};
|
|
68
|
+
image: {
|
|
69
|
+
placeholder: string;
|
|
70
|
+
buttonText: string;
|
|
71
|
+
};
|
|
72
|
+
inlineMath: {
|
|
73
|
+
placeholder: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const inputMap = (schema: Schema, ctx: Ctx, inputOptions: InputOptions): InputMap => {
|
|
78
|
+
const { marks, nodes } = schema;
|
|
79
|
+
return {
|
|
80
|
+
[InputAction.ModifyLink]: {
|
|
81
|
+
display: (view) => view.state.selection.empty && hasMark(view.state, marks.link),
|
|
82
|
+
command: modifyLink(ctx),
|
|
83
|
+
update: updateLinkView,
|
|
84
|
+
...inputOptions.link,
|
|
85
|
+
},
|
|
86
|
+
[InputAction.ModifyInlineMath]: {
|
|
87
|
+
display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.math_inline)),
|
|
88
|
+
command: modifyInlineMath(ctx),
|
|
89
|
+
update: updateInlineMathView,
|
|
90
|
+
bind: true,
|
|
91
|
+
...inputOptions.inlineMath,
|
|
92
|
+
},
|
|
93
|
+
[InputAction.ModifyImage]: {
|
|
94
|
+
display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.image)),
|
|
95
|
+
command: modifyImage(ctx),
|
|
96
|
+
update: updateImageView,
|
|
97
|
+
...inputOptions.image,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const buttonMap = (schema: Schema, ctx: Ctx): ButtonMap => {
|
|
103
|
+
const { marks } = schema;
|
|
104
|
+
return {
|
|
105
|
+
[ButtonAction.ToggleBold]: createToggleIcon(ctx, 'bold', ToggleBold, marks.strong, marks.code_inline),
|
|
106
|
+
[ButtonAction.ToggleItalic]: createToggleIcon(ctx, 'italic', ToggleItalic, marks.em, marks.code_inline),
|
|
107
|
+
[ButtonAction.ToggleStrike]: createToggleIcon(
|
|
108
|
+
ctx,
|
|
109
|
+
'strikeThrough',
|
|
110
|
+
ToggleStrikeThrough,
|
|
111
|
+
marks.strike_through,
|
|
112
|
+
marks.code_inline,
|
|
113
|
+
),
|
|
114
|
+
[ButtonAction.ToggleCode]: createToggleIcon(ctx, 'code', ToggleInlineCode, marks.code_inline, marks.link),
|
|
115
|
+
[ButtonAction.ToggleLink]: createToggleIcon(ctx, 'link', ToggleLink, marks.link, marks.code_inline),
|
|
116
|
+
};
|
|
117
|
+
};
|