@milkdown/plugin-tooltip 5.5.0 → 6.0.0
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 -13
- package/lib/{src/button-manager → button-manager}/calc-button-pos.d.ts +1 -1
- package/lib/button-manager/calc-button-pos.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/create-tooltip.d.ts +1 -1
- package/lib/button-manager/create-tooltip.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/filter-button.d.ts +0 -0
- package/lib/button-manager/filter-button.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/index.d.ts +1 -1
- package/lib/button-manager/index.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/no-active.d.ts +0 -0
- package/lib/button-manager/no-active.d.ts.map +1 -0
- package/lib/button-manager/style.d.ts +3 -0
- package/lib/button-manager/style.d.ts.map +1 -0
- package/lib/index.d.ts +21 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +64 -387
- package/lib/index.es.js.map +1 -1
- package/lib/item.d.ts +34 -0
- package/lib/item.d.ts.map +1 -0
- package/lib/{src/selection-marks-tooltip.d.ts → selection-marks-tooltip.d.ts} +3 -2
- package/lib/selection-marks-tooltip.d.ts.map +1 -0
- package/lib/{src/utility → utility}/element.d.ts +0 -0
- package/lib/utility/element.d.ts.map +1 -0
- package/lib/{src/utility → utility}/index.d.ts +0 -1
- package/lib/utility/index.d.ts.map +1 -0
- package/lib/{src/utility → utility}/prosemirror.d.ts +0 -0
- package/lib/utility/prosemirror.d.ts.map +1 -0
- package/lib/{src/utility → utility}/toggle.d.ts +0 -0
- package/lib/utility/toggle.d.ts.map +1 -0
- package/package.json +34 -10
- package/src/button-manager/calc-button-pos.ts +2 -3
- package/src/button-manager/create-tooltip.ts +9 -7
- package/src/button-manager/filter-button.ts +1 -1
- package/src/button-manager/index.ts +8 -3
- package/src/button-manager/no-active.ts +1 -1
- package/src/button-manager/style.ts +11 -10
- package/src/index.ts +6 -20
- package/src/item.ts +34 -75
- package/src/selection-marks-tooltip.ts +8 -9
- package/src/utility/index.ts +0 -1
- package/src/utility/toggle.ts +3 -3
- package/lib/src/button-manager/calc-button-pos.d.ts.map +0 -1
- package/lib/src/button-manager/create-tooltip.d.ts.map +0 -1
- package/lib/src/button-manager/filter-button.d.ts.map +0 -1
- package/lib/src/button-manager/index.d.ts.map +0 -1
- package/lib/src/button-manager/no-active.d.ts.map +0 -1
- package/lib/src/button-manager/style.d.ts +0 -3
- package/lib/src/button-manager/style.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -21
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/input-manager/calc-input-pos.d.ts +0 -3
- package/lib/src/input-manager/calc-input-pos.d.ts.map +0 -1
- package/lib/src/input-manager/create-input.d.ts +0 -7
- package/lib/src/input-manager/create-input.d.ts.map +0 -1
- package/lib/src/input-manager/filter-input.d.ts +0 -19
- package/lib/src/input-manager/filter-input.d.ts.map +0 -1
- package/lib/src/input-manager/index.d.ts +0 -10
- package/lib/src/input-manager/index.d.ts.map +0 -1
- package/lib/src/input-manager/style.d.ts +0 -3
- package/lib/src/input-manager/style.d.ts.map +0 -1
- package/lib/src/item.d.ts +0 -53
- package/lib/src/item.d.ts.map +0 -1
- package/lib/src/selection-marks-tooltip.d.ts.map +0 -1
- package/lib/src/utility/element.d.ts.map +0 -1
- package/lib/src/utility/index.d.ts.map +0 -1
- package/lib/src/utility/input.d.ts +0 -9
- package/lib/src/utility/input.d.ts.map +0 -1
- package/lib/src/utility/prosemirror.d.ts.map +0 -1
- package/lib/src/utility/toggle.d.ts.map +0 -1
- package/src/input-manager/calc-input-pos.ts +0 -19
- package/src/input-manager/create-input.ts +0 -39
- package/src/input-manager/filter-input.ts +0 -33
- package/src/input-manager/index.ts +0 -64
- package/src/input-manager/style.ts +0 -66
- package/src/utility/input.ts +0 -137
|
@@ -3,17 +3,14 @@ import type { EditorState, EditorView } from '@milkdown/prose';
|
|
|
3
3
|
import { Utils } from '@milkdown/utils';
|
|
4
4
|
|
|
5
5
|
import { createButtonManager } from './button-manager';
|
|
6
|
-
import {
|
|
7
|
-
import type { ButtonMap, InputMap } from './item';
|
|
6
|
+
import type { ButtonMap } from './item';
|
|
8
7
|
|
|
9
|
-
export const createPlugin = (buttonMap: ButtonMap,
|
|
10
|
-
|
|
11
|
-
const inputManager = createInputManager(inputMap, utils);
|
|
8
|
+
export const createPlugin = (buttonMap: ButtonMap, utils: Utils, bottom: boolean, containerClassName: string) => {
|
|
9
|
+
let buttonManager = createButtonManager(buttonMap, utils, bottom, containerClassName);
|
|
12
10
|
let shouldHide = false;
|
|
13
11
|
|
|
14
12
|
const hide = () => {
|
|
15
13
|
buttonManager.hide();
|
|
16
|
-
inputManager.hide();
|
|
17
14
|
};
|
|
18
15
|
|
|
19
16
|
const update = (view: EditorView, prevState?: EditorState) => {
|
|
@@ -28,18 +25,20 @@ export const createPlugin = (buttonMap: ButtonMap, inputMap: InputMap, utils: Ut
|
|
|
28
25
|
if (isEqualSelection) return;
|
|
29
26
|
|
|
30
27
|
buttonManager.update(view);
|
|
31
|
-
inputManager.update(view);
|
|
32
28
|
};
|
|
33
29
|
|
|
34
30
|
return {
|
|
31
|
+
recreate: (editorView: EditorView) => {
|
|
32
|
+
buttonManager = createButtonManager(buttonMap, utils, bottom, containerClassName);
|
|
33
|
+
buttonManager.render(editorView);
|
|
34
|
+
update(editorView);
|
|
35
|
+
},
|
|
35
36
|
update,
|
|
36
37
|
destroy: () => {
|
|
37
38
|
buttonManager.destroy();
|
|
38
|
-
inputManager.destroy();
|
|
39
39
|
},
|
|
40
40
|
render: (editorView: EditorView) => {
|
|
41
41
|
buttonManager.render(editorView);
|
|
42
|
-
inputManager.render(editorView);
|
|
43
42
|
update(editorView);
|
|
44
43
|
},
|
|
45
44
|
setHide: (isTyping: boolean) => {
|
package/src/utility/index.ts
CHANGED
package/src/utility/toggle.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { commandsCtx, Ctx,
|
|
2
|
+
import { commandsCtx, Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
3
3
|
import type { Icon } from '@milkdown/design-system';
|
|
4
4
|
import type { MarkType } from '@milkdown/prose';
|
|
5
5
|
|
|
@@ -13,8 +13,8 @@ export const createToggleIcon = (
|
|
|
13
13
|
mark: MarkType | undefined,
|
|
14
14
|
disableForMark: MarkType | undefined,
|
|
15
15
|
): ButtonItem => ({
|
|
16
|
-
$: ctx.get(
|
|
17
|
-
command: () => ctx.get(commandsCtx).
|
|
16
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, iconName)?.dom as HTMLElement,
|
|
17
|
+
command: () => ctx.get(commandsCtx).call(key),
|
|
18
18
|
active: (view) => hasMark(view.state, mark),
|
|
19
19
|
disable: (view) => isTextAndNotHasMark(view.state, disableForMark),
|
|
20
20
|
enable: (view) => !!mark && !!view.state.schema.marks[mark.name],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calc-button-pos.d.ts","sourceRoot":"","sources":["calc-button-pos.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,WAAW,QAAQ,UAAU,SAmBnE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-tooltip.d.ts","sourceRoot":"","sources":["create-tooltip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,aAAK,OAAO,GAAG;IACX,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF,eAAO,MAAM,aAAa,cAAe,SAAS,SAAS,KAAK,KAAG,OAmBlE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-button.d.ts","sourceRoot":"","sources":["filter-button.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,eAAO,MAAM,YAAY,cAAe,SAAS,QAAQ,UAAU,YAqBlE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,mBAAmB,cAAe,SAAS,SAAS,KAAK;;;yBAwBzC,UAAU;;CAUtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-active.d.ts","sourceRoot":"","sources":["no-active.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,eAAO,MAAM,QAAQ,cAAe,SAAS,QAAQ,UAAU,YAI9D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,WAAW,cAAe,SAAS,WAAW,OAAO,WA6CjE,CAAC"}
|
package/lib/src/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PluginKey } from '@milkdown/prose';
|
|
2
|
-
import { AtomList } from '@milkdown/utils';
|
|
3
|
-
import { InputOptions } from './item';
|
|
4
|
-
export declare const key: PluginKey<any, any>;
|
|
5
|
-
export declare const tooltipPlugin: import("@milkdown/utils/lib/src/types").WithExtend<string, InputOptions, {
|
|
6
|
-
[x: string]: import("prosemirror-model").NodeType<any>;
|
|
7
|
-
} & {
|
|
8
|
-
[x: string]: import("prosemirror-model").MarkType<any>;
|
|
9
|
-
}, {
|
|
10
|
-
schema?: ((ctx: import("@milkdown/core").Ctx) => {
|
|
11
|
-
node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
|
|
12
|
-
mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
|
|
13
|
-
}) | undefined;
|
|
14
|
-
view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
|
|
15
|
-
[x: string]: import("@milkdown/prose").NodeViewFactory;
|
|
16
|
-
} & {
|
|
17
|
-
[x: string]: import("@milkdown/prose").MarkViewFactory;
|
|
18
|
-
}>) | undefined;
|
|
19
|
-
}>;
|
|
20
|
-
export declare const tooltip: AtomList<import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, InputOptions>> & import("@milkdown/core").MilkdownPlugin>;
|
|
21
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAA0B,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAuB,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG3D,eAAO,MAAM,GAAG,qBAA2C,CAAC;AAE5D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;EAuDxB,CAAC;AAEH,eAAO,MAAM,OAAO,+KAAqC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calc-input-pos.d.ts","sourceRoot":"","sources":["calc-input-pos.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,eAAO,MAAM,YAAY,SAAU,UAAU,SAAS,cAAc,SAenE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-input.d.ts","sourceRoot":"","sources":["create-input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C,eAAO,MAAM,WAAW,UAAW,KAAK;;;;CAiCvC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@milkdown/prose';
|
|
2
|
-
import type { InputMap } from '../item';
|
|
3
|
-
export declare const filterInput: (currentView: EditorView, inputMap: InputMap, div: HTMLDivElement, input: HTMLInputElement, button: HTMLButtonElement) => ({
|
|
4
|
-
command: import("../item").Event2Command;
|
|
5
|
-
display: import("../item").Pred;
|
|
6
|
-
update: import("../item").Updater;
|
|
7
|
-
placeholder: string;
|
|
8
|
-
} & {
|
|
9
|
-
bind: true;
|
|
10
|
-
}) | ({
|
|
11
|
-
command: import("../item").Event2Command;
|
|
12
|
-
display: import("../item").Pred;
|
|
13
|
-
update: import("../item").Updater;
|
|
14
|
-
placeholder: string;
|
|
15
|
-
} & {
|
|
16
|
-
bind?: false | undefined;
|
|
17
|
-
buttonText: string;
|
|
18
|
-
}) | undefined;
|
|
19
|
-
//# sourceMappingURL=filter-input.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-input.d.ts","sourceRoot":"","sources":["filter-input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,gBACP,UAAU,YACb,QAAQ,OACb,cAAc,SACZ,gBAAgB,UACf,iBAAiB;;;;;;;;;;;;;;;cAsB5B,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@milkdown/prose';
|
|
2
|
-
import { Utils } from '@milkdown/utils';
|
|
3
|
-
import type { InputMap } from '../item';
|
|
4
|
-
export declare const createInputManager: (inputMap: InputMap, utils: Utils) => {
|
|
5
|
-
destroy: () => void;
|
|
6
|
-
hide: () => void;
|
|
7
|
-
update: (editorView: EditorView) => void;
|
|
8
|
-
render: (editorView: EditorView) => void;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKvD,eAAO,MAAM,kBAAkB,aAAc,QAAQ,SAAS,KAAK;;;yBAyCtC,UAAU;yBAOV,UAAU;CAMtC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,WAAW,cAAe,SAAS,WAAW,OAAO,WA8DjE,CAAC"}
|
package/lib/src/item.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Ctx } from '@milkdown/core';
|
|
2
|
-
import { EditorView, Schema } from '@milkdown/prose';
|
|
3
|
-
export declare type Pred = (view: EditorView) => boolean;
|
|
4
|
-
export declare type Updater = (view: EditorView, $: HTMLElement) => void;
|
|
5
|
-
export declare type Event2Command = (e: Event) => void;
|
|
6
|
-
export declare type ButtonItem = {
|
|
7
|
-
$: HTMLElement;
|
|
8
|
-
command: () => void;
|
|
9
|
-
active: Pred;
|
|
10
|
-
disable?: Pred;
|
|
11
|
-
enable: Pred;
|
|
12
|
-
};
|
|
13
|
-
export declare type InputItem = {
|
|
14
|
-
command: Event2Command;
|
|
15
|
-
display: Pred;
|
|
16
|
-
update: Updater;
|
|
17
|
-
placeholder: string;
|
|
18
|
-
} & ({
|
|
19
|
-
bind: true;
|
|
20
|
-
} | {
|
|
21
|
-
bind?: false;
|
|
22
|
-
buttonText: string;
|
|
23
|
-
});
|
|
24
|
-
export declare enum ButtonAction {
|
|
25
|
-
ToggleBold = 0,
|
|
26
|
-
ToggleItalic = 1,
|
|
27
|
-
ToggleStrike = 2,
|
|
28
|
-
ToggleCode = 3,
|
|
29
|
-
ToggleLink = 4
|
|
30
|
-
}
|
|
31
|
-
export declare enum InputAction {
|
|
32
|
-
ModifyLink = 0,
|
|
33
|
-
ModifyImage = 1,
|
|
34
|
-
ModifyInlineMath = 2
|
|
35
|
-
}
|
|
36
|
-
export declare type ButtonMap = Record<ButtonAction, ButtonItem>;
|
|
37
|
-
export declare type InputMap = Record<InputAction, InputItem>;
|
|
38
|
-
export declare type InputOptions = {
|
|
39
|
-
link: {
|
|
40
|
-
placeholder: string;
|
|
41
|
-
buttonText: string;
|
|
42
|
-
};
|
|
43
|
-
image: {
|
|
44
|
-
placeholder: string;
|
|
45
|
-
buttonText: string;
|
|
46
|
-
};
|
|
47
|
-
inlineMath: {
|
|
48
|
-
placeholder: string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
export declare const inputMap: (schema: Schema, ctx: Ctx, inputOptions: InputOptions) => InputMap;
|
|
52
|
-
export declare const buttonMap: (schema: Schema, ctx: Ctx) => ButtonMap;
|
|
53
|
-
//# sourceMappingURL=item.d.ts.map
|
package/lib/src/item.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,UAAU,EAA0B,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAa5F,oBAAY,IAAI,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;AACjD,oBAAY,OAAO,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,KAAK,IAAI,CAAC;AACjE,oBAAY,aAAa,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;AAE/C,oBAAY,UAAU,GAAG;IACrB,CAAC,EAAE,WAAW,CAAC;IACf,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACvB,GAAG,CACE;IACI,IAAI,EAAE,IAAI,CAAC;CACd,GACD;IACI,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACtB,CACN,CAAC;AAEF,oBAAY,YAAY;IACpB,UAAU,IAAA;IACV,YAAY,IAAA;IACZ,YAAY,IAAA;IACZ,UAAU,IAAA;IACV,UAAU,IAAA;CACb;AAED,oBAAY,WAAW;IACnB,UAAU,IAAA;IACV,WAAW,IAAA;IACX,gBAAgB,IAAA;CACnB;AAED,oBAAY,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACzD,oBAAY,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAEtD,oBAAY,YAAY,GAAG;IACvB,IAAI,EAAE;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACR,WAAW,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AAEF,eAAO,MAAM,QAAQ,WAAY,MAAM,OAAO,GAAG,gBAAgB,YAAY,KAAG,QA2B/E,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,OAAO,GAAG,KAAG,SAqBpD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selection-marks-tooltip.d.ts","sourceRoot":"","sources":["selection-marks-tooltip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElD,eAAO,MAAM,YAAY,cAAe,SAAS,YAAY,QAAQ,SAAS,KAAK;mBAUzD,UAAU;;yBAqBP,UAAU;wBAKX,OAAO;CAIlC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,YAAa,WAAW,WAAW,MAAM,KAAG,OACxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Ctx } from '@milkdown/core';
|
|
2
|
-
import { Event2Command, Updater } from '../item';
|
|
3
|
-
export declare const modifyLink: (ctx: Ctx) => Event2Command;
|
|
4
|
-
export declare const modifyInlineMath: (ctx: Ctx) => Event2Command;
|
|
5
|
-
export declare const modifyImage: (ctx: Ctx) => Event2Command;
|
|
6
|
-
export declare const updateLinkView: Updater;
|
|
7
|
-
export declare const updateInlineMathView: Updater;
|
|
8
|
-
export declare const updateImageView: Updater;
|
|
9
|
-
//# sourceMappingURL=input.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["input.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGjD,eAAO,MAAM,UAAU,QACb,GAAG,KAAG,aAmBX,CAAC;AAEN,eAAO,MAAM,gBAAgB,QACnB,GAAG,KAAG,aAaX,CAAC;AAEN,eAAO,MAAM,WAAW,QACd,GAAG,KAAG,aAmBX,CAAC;AAEN,eAAO,MAAM,cAAc,EAAE,OA6B5B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,OAkBlC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,OAkB7B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prosemirror.d.ts","sourceRoot":"","sources":["prosemirror.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAkB,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAiB,MAAM,iBAAiB,CAAC;AAEvG,oBAAY,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,OAAO,gBAAiB,WAAW,uCAAoB,OAOnE,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,uCAAoB,OACa,CAAC;AAE9F,eAAO,MAAM,aAAa,aAAc,QAAQ,QAAQ,IAAI,YAE3D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["toggle.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAAgB,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,eAAO,MAAM,gBAAgB,QACpB,GAAG,YACE,IAAI,OACT,MAAM,QACL,QAAQ,GAAG,SAAS,kBACV,QAAQ,GAAG,SAAS,KACrC,UAMD,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { calculateTextPosition, EditorView } from '@milkdown/prose';
|
|
3
|
-
|
|
4
|
-
export const calcInputPos = (view: EditorView, input: HTMLDivElement) => {
|
|
5
|
-
calculateTextPosition(view, input, (start, end, target, parent) => {
|
|
6
|
-
const $editor = input.parentElement;
|
|
7
|
-
if (!$editor) {
|
|
8
|
-
throw new Error();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const selectionWidth = end.left - start.left;
|
|
12
|
-
let left = start.left - parent.left - (target.width - selectionWidth) / 2;
|
|
13
|
-
const top = start.bottom - parent.top + 14 + $editor.scrollTop;
|
|
14
|
-
|
|
15
|
-
if (left < 0) left = 0;
|
|
16
|
-
|
|
17
|
-
return [top, left];
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { EditorView } from '@milkdown/prose';
|
|
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
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import type { EditorView } from '@milkdown/prose';
|
|
3
|
-
import { Utils } from '@milkdown/utils';
|
|
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
|
-
const onKeydown = (e: KeyboardEvent) => {
|
|
29
|
-
if (!inputCommand) return;
|
|
30
|
-
if ('key' in e && e.key === 'Enter') {
|
|
31
|
-
inputCommand(e);
|
|
32
|
-
div.classList.add('hide');
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
input.addEventListener('input', onInput);
|
|
37
|
-
input.addEventListener('keydown', onKeydown);
|
|
38
|
-
button.addEventListener('mousedown', onClick);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
destroy: () => {
|
|
42
|
-
input.removeEventListener('input', onInput);
|
|
43
|
-
input.removeEventListener('keydown', onKeydown);
|
|
44
|
-
div.removeEventListener('mousedown', onClick);
|
|
45
|
-
div.remove();
|
|
46
|
-
},
|
|
47
|
-
hide: () => {
|
|
48
|
-
div.classList.add('hide');
|
|
49
|
-
setCommand();
|
|
50
|
-
},
|
|
51
|
-
update: (editorView: EditorView) => {
|
|
52
|
-
const result = filterInput(editorView, inputMap, div, input, button);
|
|
53
|
-
if (!result) return;
|
|
54
|
-
binding = !!result.bind;
|
|
55
|
-
setCommand(result.command);
|
|
56
|
-
calcInputPos(editorView, div);
|
|
57
|
-
},
|
|
58
|
-
render: (editorView: EditorView) => {
|
|
59
|
-
const wrapper = editorView.dom.parentNode;
|
|
60
|
-
if (!wrapper) throw new Error();
|
|
61
|
-
wrapper.appendChild(div);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Emotion, ThemeTool } from '@milkdown/core';
|
|
3
|
-
|
|
4
|
-
export const injectStyle = (themeTool: ThemeTool, { css }: Emotion) => {
|
|
5
|
-
const { palette, mixin, size } = themeTool;
|
|
6
|
-
|
|
7
|
-
return css`
|
|
8
|
-
${mixin.border?.()};
|
|
9
|
-
${mixin.shadow?.()};
|
|
10
|
-
|
|
11
|
-
display: inline-flex;
|
|
12
|
-
justify-content: space-between;
|
|
13
|
-
align-items: center;
|
|
14
|
-
position: absolute;
|
|
15
|
-
background: ${palette('surface')};
|
|
16
|
-
border-radius: ${size.radius};
|
|
17
|
-
font-size: 1rem;
|
|
18
|
-
|
|
19
|
-
height: 3.5rem;
|
|
20
|
-
box-sizing: border-box;
|
|
21
|
-
width: 25.5rem;
|
|
22
|
-
padding: 0 1rem;
|
|
23
|
-
gap: 1rem;
|
|
24
|
-
z-index: 2;
|
|
25
|
-
|
|
26
|
-
input,
|
|
27
|
-
button {
|
|
28
|
-
all: unset;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
input {
|
|
32
|
-
flex-grow: 1;
|
|
33
|
-
caret-color: ${palette('primary')};
|
|
34
|
-
&::placeholder {
|
|
35
|
-
color: ${palette('neutral', 0.6)};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
button {
|
|
40
|
-
cursor: pointer;
|
|
41
|
-
height: 2.25rem;
|
|
42
|
-
color: ${palette('primary')};
|
|
43
|
-
font-size: 0.875rem;
|
|
44
|
-
padding: 0 0.5rem;
|
|
45
|
-
font-weight: 500;
|
|
46
|
-
letter-spacing: 1.25px;
|
|
47
|
-
&:hover {
|
|
48
|
-
background-color: ${palette('secondary', 0.12)};
|
|
49
|
-
}
|
|
50
|
-
&.disable {
|
|
51
|
-
color: ${palette('neutral', 0.38)};
|
|
52
|
-
cursor: not-allowed;
|
|
53
|
-
&:hover {
|
|
54
|
-
background: transparent;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
&.hide {
|
|
58
|
-
display: none;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
&.hide {
|
|
63
|
-
display: none;
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
};
|
package/src/utility/input.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { commandsCtx, Ctx } from '@milkdown/core';
|
|
3
|
-
import { findSelectedNodeOfType, Node as ProseNode } from '@milkdown/prose';
|
|
4
|
-
|
|
5
|
-
import { Event2Command, Updater } from '../item';
|
|
6
|
-
import { elementIsTag } from './element';
|
|
7
|
-
|
|
8
|
-
export const modifyLink =
|
|
9
|
-
(ctx: Ctx): Event2Command =>
|
|
10
|
-
(e: Event | KeyboardEvent) => {
|
|
11
|
-
const { target } = e;
|
|
12
|
-
if (!(target instanceof HTMLElement)) {
|
|
13
|
-
return () => true;
|
|
14
|
-
}
|
|
15
|
-
if (elementIsTag(target, 'input')) {
|
|
16
|
-
if (!('key' in e) || e.key !== 'Enter') {
|
|
17
|
-
target.focus();
|
|
18
|
-
return () => false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const parent = target.parentNode;
|
|
22
|
-
if (!parent) return () => false;
|
|
23
|
-
|
|
24
|
-
const inputEl = Array.from(parent.children).find((el) => el.tagName === 'INPUT');
|
|
25
|
-
if (!(inputEl instanceof HTMLInputElement)) return () => false;
|
|
26
|
-
|
|
27
|
-
return ctx.get(commandsCtx).callByName('ModifyLink', inputEl.value);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const modifyInlineMath =
|
|
31
|
-
(ctx: Ctx): Event2Command =>
|
|
32
|
-
(e) => {
|
|
33
|
-
const { target } = e;
|
|
34
|
-
if (!(target instanceof HTMLElement)) {
|
|
35
|
-
return () => true;
|
|
36
|
-
}
|
|
37
|
-
const parent = target.parentNode;
|
|
38
|
-
if (!parent) return () => false;
|
|
39
|
-
|
|
40
|
-
const inputEl = Array.from(parent.children).find((el) => el.tagName === 'INPUT');
|
|
41
|
-
if (!(inputEl instanceof HTMLInputElement)) return () => false;
|
|
42
|
-
|
|
43
|
-
return ctx.get(commandsCtx).callByName('ModifyInlineMath', inputEl.value);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const modifyImage =
|
|
47
|
-
(ctx: Ctx): Event2Command =>
|
|
48
|
-
(e: Event | KeyboardEvent) => {
|
|
49
|
-
const { target } = e;
|
|
50
|
-
if (!(target instanceof HTMLElement)) {
|
|
51
|
-
return () => true;
|
|
52
|
-
}
|
|
53
|
-
if (elementIsTag(target, 'input')) {
|
|
54
|
-
if (!('key' in e) || e.key !== 'Enter') {
|
|
55
|
-
target.focus();
|
|
56
|
-
return () => false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const parent = target.parentNode;
|
|
60
|
-
if (!parent) return () => false;
|
|
61
|
-
|
|
62
|
-
const inputEl = Array.from(parent.children).find((el) => el.tagName === 'INPUT');
|
|
63
|
-
if (!(inputEl instanceof HTMLInputElement)) return () => false;
|
|
64
|
-
|
|
65
|
-
return ctx.get(commandsCtx).callByName('ModifyImage', inputEl.value);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const updateLinkView: Updater = (view, $) => {
|
|
69
|
-
const { marks } = view.state.schema;
|
|
70
|
-
const { firstChild, lastElementChild } = $;
|
|
71
|
-
if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement)) return;
|
|
72
|
-
|
|
73
|
-
const { selection } = view.state;
|
|
74
|
-
let node: ProseNode | undefined;
|
|
75
|
-
const { from, to } = selection;
|
|
76
|
-
view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
|
|
77
|
-
if (marks.link.isInSet(n.marks)) {
|
|
78
|
-
node = n;
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return;
|
|
82
|
-
});
|
|
83
|
-
if (!node) return;
|
|
84
|
-
|
|
85
|
-
const mark = node.marks.find((m) => m.type === marks.link);
|
|
86
|
-
if (!mark) return;
|
|
87
|
-
|
|
88
|
-
const value = mark.attrs['href'];
|
|
89
|
-
firstChild.value = value;
|
|
90
|
-
if (!value) {
|
|
91
|
-
lastElementChild.classList.add('disable');
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (lastElementChild.classList.contains('disable')) {
|
|
95
|
-
lastElementChild.classList.remove('disable');
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export const updateInlineMathView: Updater = (view, $) => {
|
|
100
|
-
const { nodes } = view.state.schema;
|
|
101
|
-
const { firstChild, lastElementChild } = $;
|
|
102
|
-
if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement)) return;
|
|
103
|
-
|
|
104
|
-
const result = findSelectedNodeOfType(view.state.selection, nodes.math_inline);
|
|
105
|
-
if (!result) return;
|
|
106
|
-
const { node } = result;
|
|
107
|
-
|
|
108
|
-
const value = node.attrs['value'];
|
|
109
|
-
firstChild.value = value;
|
|
110
|
-
if (!value) {
|
|
111
|
-
lastElementChild.classList.add('disable');
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (lastElementChild.classList.contains('disable')) {
|
|
115
|
-
lastElementChild.classList.remove('disable');
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const updateImageView: Updater = (view, $) => {
|
|
120
|
-
const { nodes } = view.state.schema;
|
|
121
|
-
const { firstChild, lastElementChild } = $;
|
|
122
|
-
if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement)) return;
|
|
123
|
-
|
|
124
|
-
const result = findSelectedNodeOfType(view.state.selection, nodes.image);
|
|
125
|
-
if (!result) return;
|
|
126
|
-
const { node } = result;
|
|
127
|
-
|
|
128
|
-
const value = node.attrs['src'];
|
|
129
|
-
firstChild.value = value.length > 50 ? 'Url is too long to display.' : value;
|
|
130
|
-
if (!value) {
|
|
131
|
-
lastElementChild.classList.add('disable');
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (lastElementChild.classList.contains('disable')) {
|
|
135
|
-
lastElementChild.classList.remove('disable');
|
|
136
|
-
}
|
|
137
|
-
};
|