@limetech/lime-elements 37.39.1 → 37.40.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/CHANGELOG.md +30 -0
- package/dist/cjs/limel-dock-button.cjs.entry.js +17 -3
- package/dist/cjs/limel-dock-button.cjs.entry.js.map +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +127 -81
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
- package/dist/collection/components/dock/dock-button/dock-button.js +17 -3
- package/dist/collection/components/dock/dock-button/dock-button.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-commands.js +70 -65
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-commands.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-items.js +9 -8
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-items.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js +32 -0
- package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js.map +1 -0
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +19 -8
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js.map +1 -1
- package/dist/esm/limel-dock-button.entry.js +17 -3
- package/dist/esm/limel-dock-button.entry.js.map +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +127 -81
- package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-5983b027.entry.js → p-1367c295.entry.js} +2 -2
- package/dist/lime-elements/p-1367c295.entry.js.map +1 -0
- package/dist/lime-elements/{p-fecf1bf1.entry.js → p-e9f943ac.entry.js} +2 -2
- package/dist/lime-elements/p-e9f943ac.entry.js.map +1 -0
- package/dist/types/components/dock/dock-button/dock-button.d.ts +2 -0
- package/dist/types/components/text-editor/prosemirror-adapter/menu/menu-commands.d.ts +10 -6
- package/dist/types/components/text-editor/prosemirror-adapter/menu/menu-items.d.ts +2 -1
- package/dist/types/components/text-editor/prosemirror-adapter/prosemirror-adapter.d.ts +2 -0
- package/package.json +1 -1
- package/dist/lime-elements/p-5983b027.entry.js.map +0 -1
- package/dist/lime-elements/p-fecf1bf1.entry.js.map +0 -1
|
@@ -26,8 +26,15 @@ export class DockButton {
|
|
|
26
26
|
event.stopPropagation();
|
|
27
27
|
this.itemSelected.emit(this.item);
|
|
28
28
|
};
|
|
29
|
-
this.focusCustomComponentElement = () => {
|
|
29
|
+
this.focusCustomComponentElement = (entries) => {
|
|
30
30
|
var _a, _b, _c;
|
|
31
|
+
const entry = entries.find((e) => e.target === this.customComponentElement);
|
|
32
|
+
if (!entry) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!entry.isIntersecting) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
31
38
|
if ((_b = (_a = this.customComponentElement) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.delegatesFocus) {
|
|
32
39
|
(_c = this.customComponentElement) === null || _c === void 0 ? void 0 : _c.focus();
|
|
33
40
|
}
|
|
@@ -55,8 +62,15 @@ export class DockButton {
|
|
|
55
62
|
if (!this.isOpen) {
|
|
56
63
|
return;
|
|
57
64
|
}
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
if (!this.intersectionObserver) {
|
|
66
|
+
this.intersectionObserver = new IntersectionObserver(this.focusCustomComponentElement);
|
|
67
|
+
this.intersectionObserver.observe(this.customComponentElement);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
73
|
+
this.intersectionObserver = undefined;
|
|
60
74
|
}
|
|
61
75
|
renderPopover() {
|
|
62
76
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;MACxC,OAAO,CACH,qBACI,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAC5B,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,GACxC,CACL,CAAC;KACL;EACL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAeJ","sourcesContent":["import {\n Component,\n Event,\n EventEmitter,\n h,\n Prop,\n State,\n Watch,\n} from '@stencil/core';\nimport { DockItem } from '../dock.types';\nimport { createRandomString } from '../../../util/random-string';\n\n/**\n * @private\n */\n@Component({\n tag: 'limel-dock-button',\n shadow: false,\n styleUrl: 'dock-button.scss',\n})\nexport class DockButton {\n /**\n * Item that is placed in the dock.\n */\n @Prop()\n public item!: DockItem;\n\n /**\n * When the dock is expanded or collapsed, dock items\n * show labels and tooltips as suitable for the layout.\n */\n @Prop({ reflect: true })\n public expanded? = false;\n\n /**\n * When dock is using mobile layout, dock items\n * show labels and tooltips as suitable for the layout.\n */\n @Prop({ reflect: true })\n public useMobileLayout? = false;\n\n /**\n * Fired when a dock item has been selected from the dock.\n */\n @Event()\n public itemSelected: EventEmitter<DockItem>;\n\n /**\n * Fired when a dock menu is opened.\n */\n @Event()\n public menuOpen: EventEmitter<DockItem>;\n\n /**\n * Indicated whether the popover that renders a component is open.\n */\n @State()\n private isOpen = false;\n\n /**\n * Fired when the popover is closed.\n */\n @Event()\n public close: EventEmitter<void>;\n\n private tooltipId: string;\n private customComponentElement: HTMLElement;\n\n constructor() {\n this.tooltipId = createRandomString();\n }\n\n public render() {\n if (this.item?.dockMenu?.componentName) {\n return this.renderPopover();\n }\n\n return this.renderButton(this.handleClick);\n }\n\n @Watch('isOpen')\n protected openWatcher() {\n if (!this.isOpen) {\n return;\n }\n\n const observer = new IntersectionObserver(\n this.focusCustomComponentElement,\n );\n observer.observe(this.customComponentElement);\n }\n\n private renderPopover() {\n const CustomComponent = this.item?.dockMenu.componentName;\n\n return (\n <limel-popover\n openDirection={this.useMobileLayout ? 'top' : 'right-start'}\n open={this.isOpen || this.item.dockMenu.menuOpen}\n onClose={this.onPopoverClose}\n >\n {this.renderButton(this.openPopover, 'trigger')}\n <CustomComponent\n ref={this.setCustomComponentElement}\n {...(this.item.dockMenu.props || {})}\n onClose={this.onPopoverClose}\n />\n </limel-popover>\n );\n }\n\n private renderButton(\n handleClick: (event: MouseEvent) => void,\n slot?: string,\n ) {\n return (\n <button\n slot={slot}\n tabindex=\"0\"\n id={this.tooltipId}\n type=\"button\"\n class={{\n button: true,\n selected: this.item?.selected,\n }}\n onClick={handleClick}\n aria-live=\"polite\"\n >\n {this.renderIcon()}\n {this.renderLabel()}\n {this.renderTooltip()}\n {this.renderNotification()}\n </button>\n );\n }\n\n private renderNotification = () => {\n if (this.item.badge !== undefined) {\n return <limel-badge label={this.item.badge} />;\n }\n };\n\n private openPopover = (event: MouseEvent) => {\n event.stopPropagation();\n this.isOpen = true;\n this.menuOpen.emit(this.item);\n };\n\n private setCustomComponentElement = (element: HTMLElement) => {\n this.customComponentElement = element;\n };\n\n private onPopoverClose = () => {\n this.isOpen = false;\n this.close.emit();\n };\n\n private handleClick = (event: MouseEvent) => {\n event.stopPropagation();\n this.itemSelected.emit(this.item);\n };\n\n private renderIcon() {\n if (!this.item.icon) {\n return;\n }\n\n return <limel-icon name={this.item.icon} class=\"icon\" />;\n }\n\n private renderLabel() {\n if (this.expanded) {\n return <span class=\"text\">{this.item.label}</span>;\n }\n }\n\n private renderTooltip() {\n if (!this.expanded && this.item.label) {\n return (\n <limel-tooltip\n elementId={this.tooltipId}\n label={this.item.label}\n helperLabel={this.item.helperLabel}\n openDirection={this.getOpenDirection()}\n />\n );\n }\n\n if (this.expanded && this.item.helperLabel) {\n return (\n <limel-tooltip\n elementId={this.tooltipId}\n label={this.item.helperLabel}\n openDirection={this.getOpenDirection()}\n />\n );\n }\n }\n\n private focusCustomComponentElement = () => {\n if (this.customComponentElement?.shadowRoot?.delegatesFocus) {\n this.customComponentElement?.focus();\n }\n };\n\n private getOpenDirection = () => {\n if (this.useMobileLayout) {\n return 'top';\n }\n\n return 'right';\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dock-button.js","sourceRoot":"","sources":["../../../../src/components/dock/dock-button/dock-button.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,KAAK,EACL,KAAK,GACR,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE;;GAEG;AAMH,MAAM,OAAO,UAAU;EAiDnB;IA2EQ,uBAAkB,GAAG,GAAG,EAAE;MAC9B,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;QAC/B,OAAO,mBAAa,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAI,CAAC;OAClD;IACL,CAAC,CAAC;IAEM,gBAAW,GAAG,CAAC,KAAiB,EAAE,EAAE;MACxC,KAAK,CAAC,eAAe,EAAE,CAAC;MACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;MACnB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;IAEM,8BAAyB,GAAG,CAAC,OAAoB,EAAE,EAAE;MACzD,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC;IAC1C,CAAC,CAAC;IAEM,mBAAc,GAAG,GAAG,EAAE;MAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;MACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC;IAEM,gBAAW,GAAG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,IAAI,CAAC,kBAAkB,EAAE,CACrB,CACZ,CAAC;EACN,CAAC;EA4BO,UAAU;IACd,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;MACjB,OAAO;KACV;IAED,OAAO,kBAAY,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAC,MAAM,GAAG,CAAC;EAC7D,CAAC;EAEO,WAAW;IACf,IAAI,IAAI,CAAC,QAAQ,EAAE;MACf,OAAO,YAAM,KAAK,EAAC,MAAM,IAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAQ,CAAC;KACtD;EACL,CAAC;EAEO,aAAa;IACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;MACnC,OAAO,CACH,qBACI,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EACtB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAClC,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,GACxC,CACL,CAAC;KACL;IAED,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;MACxC,OAAO,CACH,qBACI,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAC5B,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,GACxC,CACL,CAAC;KACL;EACL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BJ","sourcesContent":["import {\n Component,\n Event,\n EventEmitter,\n h,\n Prop,\n State,\n Watch,\n} from '@stencil/core';\nimport { DockItem } from '../dock.types';\nimport { createRandomString } from '../../../util/random-string';\n\n/**\n * @private\n */\n@Component({\n tag: 'limel-dock-button',\n shadow: false,\n styleUrl: 'dock-button.scss',\n})\nexport class DockButton {\n /**\n * Item that is placed in the dock.\n */\n @Prop()\n public item!: DockItem;\n\n /**\n * When the dock is expanded or collapsed, dock items\n * show labels and tooltips as suitable for the layout.\n */\n @Prop({ reflect: true })\n public expanded? = false;\n\n /**\n * When dock is using mobile layout, dock items\n * show labels and tooltips as suitable for the layout.\n */\n @Prop({ reflect: true })\n public useMobileLayout? = false;\n\n /**\n * Fired when a dock item has been selected from the dock.\n */\n @Event()\n public itemSelected: EventEmitter<DockItem>;\n\n /**\n * Fired when a dock menu is opened.\n */\n @Event()\n public menuOpen: EventEmitter<DockItem>;\n\n /**\n * Indicated whether the popover that renders a component is open.\n */\n @State()\n private isOpen = false;\n\n /**\n * Fired when the popover is closed.\n */\n @Event()\n public close: EventEmitter<void>;\n\n private tooltipId: string;\n private customComponentElement: HTMLElement;\n private intersectionObserver?: IntersectionObserver;\n\n constructor() {\n this.tooltipId = createRandomString();\n }\n\n public render() {\n if (this.item?.dockMenu?.componentName) {\n return this.renderPopover();\n }\n\n return this.renderButton(this.handleClick);\n }\n\n @Watch('isOpen')\n protected openWatcher() {\n if (!this.isOpen) {\n return;\n }\n\n if (!this.intersectionObserver) {\n this.intersectionObserver = new IntersectionObserver(\n this.focusCustomComponentElement,\n );\n this.intersectionObserver.observe(this.customComponentElement);\n }\n }\n\n public disconnectedCallback() {\n this.intersectionObserver?.disconnect();\n this.intersectionObserver = undefined;\n }\n\n private renderPopover() {\n const CustomComponent = this.item?.dockMenu.componentName;\n\n return (\n <limel-popover\n openDirection={this.useMobileLayout ? 'top' : 'right-start'}\n open={this.isOpen || this.item.dockMenu.menuOpen}\n onClose={this.onPopoverClose}\n >\n {this.renderButton(this.openPopover, 'trigger')}\n <CustomComponent\n ref={this.setCustomComponentElement}\n {...(this.item.dockMenu.props || {})}\n onClose={this.onPopoverClose}\n />\n </limel-popover>\n );\n }\n\n private renderButton(\n handleClick: (event: MouseEvent) => void,\n slot?: string,\n ) {\n return (\n <button\n slot={slot}\n tabindex=\"0\"\n id={this.tooltipId}\n type=\"button\"\n class={{\n button: true,\n selected: this.item?.selected,\n }}\n onClick={handleClick}\n aria-live=\"polite\"\n >\n {this.renderIcon()}\n {this.renderLabel()}\n {this.renderTooltip()}\n {this.renderNotification()}\n </button>\n );\n }\n\n private renderNotification = () => {\n if (this.item.badge !== undefined) {\n return <limel-badge label={this.item.badge} />;\n }\n };\n\n private openPopover = (event: MouseEvent) => {\n event.stopPropagation();\n this.isOpen = true;\n this.menuOpen.emit(this.item);\n };\n\n private setCustomComponentElement = (element: HTMLElement) => {\n this.customComponentElement = element;\n };\n\n private onPopoverClose = () => {\n this.isOpen = false;\n this.close.emit();\n };\n\n private handleClick = (event: MouseEvent) => {\n event.stopPropagation();\n this.itemSelected.emit(this.item);\n };\n\n private renderIcon() {\n if (!this.item.icon) {\n return;\n }\n\n return <limel-icon name={this.item.icon} class=\"icon\" />;\n }\n\n private renderLabel() {\n if (this.expanded) {\n return <span class=\"text\">{this.item.label}</span>;\n }\n }\n\n private renderTooltip() {\n if (!this.expanded && this.item.label) {\n return (\n <limel-tooltip\n elementId={this.tooltipId}\n label={this.item.label}\n helperLabel={this.item.helperLabel}\n openDirection={this.getOpenDirection()}\n />\n );\n }\n\n if (this.expanded && this.item.helperLabel) {\n return (\n <limel-tooltip\n elementId={this.tooltipId}\n label={this.item.helperLabel}\n openDirection={this.getOpenDirection()}\n />\n );\n }\n }\n\n private focusCustomComponentElement = (\n entries: IntersectionObserverEntry[],\n ) => {\n const entry = entries.find(\n (e) => e.target === this.customComponentElement,\n );\n if (!entry) {\n return;\n }\n\n if (!entry.isIntersecting) {\n return;\n }\n\n if (this.customComponentElement?.shadowRoot?.delegatesFocus) {\n this.customComponentElement?.focus();\n }\n };\n\n private getOpenDirection = () => {\n if (this.useMobileLayout) {\n return 'top';\n }\n\n return 'right';\n };\n}\n"]}
|
|
@@ -1,77 +1,82 @@
|
|
|
1
1
|
import { toggleMark, setBlockType, wrapIn } from 'prosemirror-commands';
|
|
2
2
|
import { wrapInList } from 'prosemirror-schema-list';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
addorremovelink: 'link',
|
|
14
|
-
numberedlist: 'ordered_list',
|
|
15
|
-
list: 'bullet_list',
|
|
3
|
+
import { EditorMenuTypes, LevelMapping } from './types';
|
|
4
|
+
const createToggleMarkCommand = (schema, markName, url) => {
|
|
5
|
+
const markType = schema.marks[markName];
|
|
6
|
+
if (!markType) {
|
|
7
|
+
throw new Error(`Mark "${markName}" not found in schema`);
|
|
8
|
+
}
|
|
9
|
+
if (markName === EditorMenuTypes.Link && url) {
|
|
10
|
+
const attrs = {
|
|
11
|
+
href: url,
|
|
12
|
+
target: isExternalLink(url) ? '_blank' : null,
|
|
16
13
|
};
|
|
17
|
-
|
|
14
|
+
return toggleMark(markType, attrs);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
case 'paragraph':
|
|
29
|
-
return this.createSetNodeTypeCommand(mark);
|
|
30
|
-
case 'headerlevel1':
|
|
31
|
-
case 'headerlevel2':
|
|
32
|
-
case 'headerlevel3':
|
|
33
|
-
return this.createSetNodeTypeCommand('heading', parseInt(mark[mark.length - 1], 10));
|
|
34
|
-
case 'blockquote':
|
|
35
|
-
return this.createWrapInCommand(mark);
|
|
36
|
-
case 'ordered_list':
|
|
37
|
-
case 'bullet_list':
|
|
38
|
-
return this.createListCommand(mark);
|
|
39
|
-
default:
|
|
40
|
-
throw new Error(`The Mark "${mark}" is not supported`);
|
|
41
|
-
}
|
|
16
|
+
return toggleMark(markType);
|
|
17
|
+
};
|
|
18
|
+
const isExternalLink = (url) => {
|
|
19
|
+
return !url.startsWith(window.location.origin);
|
|
20
|
+
};
|
|
21
|
+
const createSetNodeTypeCommand = (schema, nodeType, level) => {
|
|
22
|
+
const type = schema.nodes[nodeType];
|
|
23
|
+
if (!type) {
|
|
24
|
+
throw new Error(`Node type "${nodeType}" not found in schema`);
|
|
42
25
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!markType) {
|
|
46
|
-
throw new Error(`Mark "${markName}" not found in schema`);
|
|
47
|
-
}
|
|
48
|
-
return toggleMark(markType);
|
|
26
|
+
if (nodeType === 'heading' && level) {
|
|
27
|
+
return setBlockType(type, { level: level });
|
|
49
28
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!type) {
|
|
53
|
-
throw new Error(`Node type "${nodeType}" not found in schema`);
|
|
54
|
-
}
|
|
55
|
-
if (nodeType === 'heading' && level) {
|
|
56
|
-
return setBlockType(type, { level: level });
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return setBlockType(type);
|
|
60
|
-
}
|
|
29
|
+
else {
|
|
30
|
+
return setBlockType(type);
|
|
61
31
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
32
|
+
};
|
|
33
|
+
const createWrapInCommand = (schema, nodeType) => {
|
|
34
|
+
const type = schema.nodes[nodeType];
|
|
35
|
+
if (!type) {
|
|
36
|
+
throw new Error(`Node type "${nodeType}" not found in schema`);
|
|
37
|
+
}
|
|
38
|
+
return wrapIn(type);
|
|
39
|
+
};
|
|
40
|
+
const createListCommand = (schema, listType) => {
|
|
41
|
+
const type = schema.nodes[listType];
|
|
42
|
+
if (!type) {
|
|
43
|
+
throw new Error(`List type "${listType}" not found in schema`);
|
|
68
44
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
return wrapInList(type);
|
|
46
|
+
};
|
|
47
|
+
const commandMapping = {
|
|
48
|
+
strong: createToggleMarkCommand,
|
|
49
|
+
em: createToggleMarkCommand,
|
|
50
|
+
underline: createToggleMarkCommand,
|
|
51
|
+
headerlevel1: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.one),
|
|
52
|
+
headerlevel2: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.two),
|
|
53
|
+
headerlevel3: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.three),
|
|
54
|
+
blockquote: createWrapInCommand,
|
|
55
|
+
/* eslint-disable camelcase */
|
|
56
|
+
ordered_list: createListCommand,
|
|
57
|
+
bullet_list: createListCommand,
|
|
58
|
+
/* eslint-enable camelcase */
|
|
59
|
+
link: createToggleMarkCommand,
|
|
60
|
+
};
|
|
61
|
+
export class MenuCommandFactory {
|
|
62
|
+
constructor(schema) {
|
|
63
|
+
this.schema = schema;
|
|
64
|
+
}
|
|
65
|
+
getCommand(mark, url) {
|
|
66
|
+
const commandFunc = commandMapping[mark];
|
|
67
|
+
if (!commandFunc) {
|
|
68
|
+
throw new Error(`The Mark "${mark}" is not supported`);
|
|
73
69
|
}
|
|
74
|
-
return
|
|
70
|
+
return commandFunc(this.schema, mark, url);
|
|
71
|
+
}
|
|
72
|
+
buildKeymap() {
|
|
73
|
+
return {
|
|
74
|
+
'Mod-B': this.getCommand(EditorMenuTypes.Bold),
|
|
75
|
+
'Mod-I': this.getCommand(EditorMenuTypes.Italic),
|
|
76
|
+
'Mod-Shift-1': this.getCommand(EditorMenuTypes.HeaderLevel1),
|
|
77
|
+
'Mod-Shift-2': this.getCommand(EditorMenuTypes.HeaderLevel2),
|
|
78
|
+
'Mod-Shift-3': this.getCommand(EditorMenuTypes.HeaderLevel3),
|
|
79
|
+
};
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
//# sourceMappingURL=menu-commands.js.map
|
package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-commands.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-commands.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/menu-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,
|
|
1
|
+
{"version":3,"file":"menu-commands.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/menu-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,MAAM,uBAAuB,GAAG,CAC5B,MAAc,EACd,QAAgB,EAChB,GAAY,EACL,EAAE;EACT,MAAM,QAAQ,GAAyB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;EAC9D,IAAI,CAAC,QAAQ,EAAE;IACX,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,uBAAuB,CAAC,CAAC;GAC7D;EAED,IAAI,QAAQ,KAAK,eAAe,CAAC,IAAI,IAAI,GAAG,EAAE;IAC1C,MAAM,KAAK,GAAG;MACV,IAAI,EAAE,GAAG;MACT,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI;KAChD,CAAC;IAEF,OAAO,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;GACtC;EAED,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,GAAW,EAAW,EAAE;EAC5C,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC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","sourcesContent":["import { toggleMark, setBlockType, wrapIn } from 'prosemirror-commands';\nimport { Schema, MarkType, NodeType } from 'prosemirror-model';\nimport { wrapInList } from 'prosemirror-schema-list';\nimport { Command } from 'prosemirror-state';\nimport { EditorMenuTypes, LevelMapping } from './types';\n\ntype CommandFunction = (\n schema: Schema,\n mark: EditorMenuTypes,\n url?: string,\n) => Command;\n\ninterface CommandMapping {\n [key: string]: CommandFunction;\n}\n\nconst createToggleMarkCommand = (\n schema: Schema,\n markName: string,\n url?: string,\n): Command => {\n const markType: MarkType | undefined = schema.marks[markName];\n if (!markType) {\n throw new Error(`Mark \"${markName}\" not found in schema`);\n }\n\n if (markName === EditorMenuTypes.Link && url) {\n const attrs = {\n href: url,\n target: isExternalLink(url) ? '_blank' : null,\n };\n\n return toggleMark(markType, attrs);\n }\n\n return toggleMark(markType);\n};\n\nconst isExternalLink = (url: string): boolean => {\n return !url.startsWith(window.location.origin);\n};\n\nconst createSetNodeTypeCommand = (\n schema: Schema,\n nodeType: string,\n level?: number,\n): Command => {\n const type: NodeType | undefined = schema.nodes[nodeType];\n if (!type) {\n throw new Error(`Node type \"${nodeType}\" not found in schema`);\n }\n\n if (nodeType === 'heading' && level) {\n return setBlockType(type, { level: level });\n } else {\n return setBlockType(type);\n }\n};\n\nconst createWrapInCommand = (schema: Schema, nodeType: string): Command => {\n const type: NodeType | undefined = schema.nodes[nodeType];\n if (!type) {\n throw new Error(`Node type \"${nodeType}\" not found in schema`);\n }\n\n return wrapIn(type);\n};\n\nconst createListCommand = (schema: Schema, listType: string): Command => {\n const type: NodeType | undefined = schema.nodes[listType];\n if (!type) {\n throw new Error(`List type \"${listType}\" not found in schema`);\n }\n\n return wrapInList(type);\n};\n\nconst commandMapping: CommandMapping = {\n strong: createToggleMarkCommand,\n em: createToggleMarkCommand,\n underline: createToggleMarkCommand,\n headerlevel1: (schema) =>\n createSetNodeTypeCommand(\n schema,\n LevelMapping.Heading,\n LevelMapping.one,\n ),\n headerlevel2: (schema) =>\n createSetNodeTypeCommand(\n schema,\n LevelMapping.Heading,\n LevelMapping.two,\n ),\n headerlevel3: (schema) =>\n createSetNodeTypeCommand(\n schema,\n LevelMapping.Heading,\n LevelMapping.three,\n ),\n blockquote: createWrapInCommand,\n /* eslint-disable camelcase */\n ordered_list: createListCommand,\n bullet_list: createListCommand,\n /* eslint-enable camelcase */\n link: createToggleMarkCommand,\n};\n\nexport class MenuCommandFactory {\n private schema: Schema;\n\n constructor(schema: Schema) {\n this.schema = schema;\n }\n\n public getCommand(mark: EditorMenuTypes, url?: string) {\n const commandFunc = commandMapping[mark];\n if (!commandFunc) {\n throw new Error(`The Mark \"${mark}\" is not supported`);\n }\n\n return commandFunc(this.schema, mark, url);\n }\n\n buildKeymap() {\n return {\n 'Mod-B': this.getCommand(EditorMenuTypes.Bold),\n 'Mod-I': this.getCommand(EditorMenuTypes.Italic),\n 'Mod-Shift-1': this.getCommand(EditorMenuTypes.HeaderLevel1),\n 'Mod-Shift-2': this.getCommand(EditorMenuTypes.HeaderLevel2),\n 'Mod-Shift-3': this.getCommand(EditorMenuTypes.HeaderLevel3),\n };\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EditorMenuTypes } from './types';
|
|
1
2
|
const getCommandSymbols = () => {
|
|
2
3
|
const macUserAgent = /Macintosh|MacIntel|MacPPC|Mac68K/;
|
|
3
4
|
if (navigator.userAgent.match(macUserAgent)) {
|
|
@@ -8,14 +9,14 @@ const getCommandSymbols = () => {
|
|
|
8
9
|
const { mod, shift } = getCommandSymbols();
|
|
9
10
|
export const textEditorMenuItems = [
|
|
10
11
|
{
|
|
11
|
-
value:
|
|
12
|
+
value: EditorMenuTypes.Bold,
|
|
12
13
|
text: 'Bold',
|
|
13
14
|
commandText: `${mod} B`,
|
|
14
15
|
icon: '-lime-text-bold',
|
|
15
16
|
iconOnly: true,
|
|
16
17
|
},
|
|
17
18
|
{
|
|
18
|
-
value:
|
|
19
|
+
value: EditorMenuTypes.Italic,
|
|
19
20
|
text: 'Italic',
|
|
20
21
|
commandText: `${mod} I`,
|
|
21
22
|
icon: '-lime-text-italic',
|
|
@@ -23,21 +24,21 @@ export const textEditorMenuItems = [
|
|
|
23
24
|
},
|
|
24
25
|
{ separator: true },
|
|
25
26
|
{
|
|
26
|
-
value:
|
|
27
|
+
value: EditorMenuTypes.HeaderLevel1,
|
|
27
28
|
text: 'Header Level 1',
|
|
28
29
|
commandText: `${mod} ${shift} 1`,
|
|
29
30
|
icon: '-lime-text-h-heading-1',
|
|
30
31
|
iconOnly: true,
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
|
-
value:
|
|
34
|
+
value: EditorMenuTypes.HeaderLevel2,
|
|
34
35
|
text: 'Header Level 2',
|
|
35
36
|
commandText: `${mod} ${shift} 2`,
|
|
36
37
|
icon: '-lime-text-h-heading-2',
|
|
37
38
|
iconOnly: true,
|
|
38
39
|
},
|
|
39
40
|
{
|
|
40
|
-
value:
|
|
41
|
+
value: EditorMenuTypes.HeaderLevel3,
|
|
41
42
|
text: 'Header Level 3',
|
|
42
43
|
commandText: `${mod} ${shift} 3`,
|
|
43
44
|
icon: '-lime-text-h-heading-3',
|
|
@@ -45,19 +46,19 @@ export const textEditorMenuItems = [
|
|
|
45
46
|
},
|
|
46
47
|
{ separator: true },
|
|
47
48
|
{
|
|
48
|
-
value:
|
|
49
|
+
value: EditorMenuTypes.BulletList,
|
|
49
50
|
text: 'Bullet list',
|
|
50
51
|
icon: '-lime-text-bulleted-list',
|
|
51
52
|
iconOnly: true,
|
|
52
53
|
},
|
|
53
54
|
{
|
|
54
|
-
value:
|
|
55
|
+
value: EditorMenuTypes.OrderedList,
|
|
55
56
|
text: 'Numbered list',
|
|
56
57
|
icon: '-lime-text-ordered-list',
|
|
57
58
|
iconOnly: true,
|
|
58
59
|
},
|
|
59
60
|
{
|
|
60
|
-
value:
|
|
61
|
+
value: EditorMenuTypes.Blockquote,
|
|
61
62
|
text: 'Blockquote',
|
|
62
63
|
icon: '-lime-text-blockquote',
|
|
63
64
|
iconOnly: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-items.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/menu-items.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"menu-items.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/menu-items.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,iBAAiB,GAAG,GAIxB,EAAE;EACA,MAAM,YAAY,GAAG,kCAAkC,CAAC;EACxD,IAAI,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;IACzC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;GAChD;EAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,iBAAiB,EAAE,CAAC;AAE3C,MAAM,CAAC,MAAM,mBAAmB,GAE5B;EACA;IACI,KAAK,EAAE,eAAe,CAAC,IAAI;IAC3B,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,GAAG,GAAG,IAAI;IACvB,IAAI,EAAE,iBAAiB;IACvB,QAAQ,EAAE,IAAI;GACjB;EACD;IACI,KAAK,EAAE,eAAe,CAAC,MAAM;IAC7B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,GAAG,GAAG,IAAI;IACvB,IAAI,EAAE,mBAAmB;IACzB,QAAQ,EAAE,IAAI;GACjB;EACD,EAAE,SAAS,EAAE,IAAI,EAAE;EACnB;IACI,KAAK,EAAE,eAAe,CAAC,YAAY;IACnC,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI;IAChC,IAAI,EAAE,wBAAwB;IAC9B,QAAQ,EAAE,IAAI;GACjB;EACD;IACI,KAAK,EAAE,eAAe,CAAC,YAAY;IACnC,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI;IAChC,IAAI,EAAE,wBAAwB;IAC9B,QAAQ,EAAE,IAAI;GACjB;EACD;IACI,KAAK,EAAE,eAAe,CAAC,YAAY;IACnC,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI;IAChC,IAAI,EAAE,wBAAwB;IAC9B,QAAQ,EAAE,IAAI;GACjB;EACD,EAAE,SAAS,EAAE,IAAI,EAAE;EACnB;IACI,KAAK,EAAE,eAAe,CAAC,UAAU;IACjC,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,0BAA0B;IAChC,QAAQ,EAAE,IAAI;GACjB;EACD;IACI,KAAK,EAAE,eAAe,CAAC,WAAW;IAClC,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,yBAAyB;IAC/B,QAAQ,EAAE,IAAI;GACjB;EACD;IACI,KAAK,EAAE,eAAe,CAAC,UAAU;IACjC,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,uBAAuB;IAC7B,QAAQ,EAAE,IAAI;GACjB;CACJ,CAAC","sourcesContent":["import { ActionBarItem } from 'src/components/action-bar/action-bar.types';\nimport { ListSeparator } from 'src/components/list/list-item.types';\nimport { EditorMenuTypes } from './types';\n\nconst getCommandSymbols = (): {\n mod: string;\n option: string;\n shift: string;\n} => {\n const macUserAgent = /Macintosh|MacIntel|MacPPC|Mac68K/;\n if (navigator.userAgent.match(macUserAgent)) {\n return { mod: '⌘', option: '⌥', shift: '⇧' };\n }\n\n return { mod: 'Ctrl', option: 'Alt', shift: 'Shift' };\n};\n\nconst { mod, shift } = getCommandSymbols();\n\nexport const textEditorMenuItems: Array<\n ActionBarItem<EditorMenuTypes> | ListSeparator\n> = [\n {\n value: EditorMenuTypes.Bold,\n text: 'Bold',\n commandText: `${mod} B`,\n icon: '-lime-text-bold',\n iconOnly: true,\n },\n {\n value: EditorMenuTypes.Italic,\n text: 'Italic',\n commandText: `${mod} I`,\n icon: '-lime-text-italic',\n iconOnly: true,\n },\n { separator: true },\n {\n value: EditorMenuTypes.HeaderLevel1,\n text: 'Header Level 1',\n commandText: `${mod} ${shift} 1`,\n icon: '-lime-text-h-heading-1',\n iconOnly: true,\n },\n {\n value: EditorMenuTypes.HeaderLevel2,\n text: 'Header Level 2',\n commandText: `${mod} ${shift} 2`,\n icon: '-lime-text-h-heading-2',\n iconOnly: true,\n },\n {\n value: EditorMenuTypes.HeaderLevel3,\n text: 'Header Level 3',\n commandText: `${mod} ${shift} 3`,\n icon: '-lime-text-h-heading-3',\n iconOnly: true,\n },\n { separator: true },\n {\n value: EditorMenuTypes.BulletList,\n text: 'Bullet list',\n icon: '-lime-text-bulleted-list',\n iconOnly: true,\n },\n {\n value: EditorMenuTypes.OrderedList,\n text: 'Numbered list',\n icon: '-lime-text-ordered-list',\n iconOnly: true,\n },\n {\n value: EditorMenuTypes.Blockquote,\n text: 'Blockquote',\n icon: '-lime-text-blockquote',\n iconOnly: true,\n },\n];\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `EditorMenuType` type is used to specify the type of menu items that can be added to the editor toolbar.
|
|
3
|
+
* Each one represents a different type to be used for creating the prosemirror commands relevant to the button.
|
|
4
|
+
* The values correspond to the types that can be used with the `prosemirror-commands` library.
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export const EditorMenuTypes = {
|
|
8
|
+
Bold: 'strong',
|
|
9
|
+
Italic: 'em',
|
|
10
|
+
Blockquote: 'blockquote',
|
|
11
|
+
HeaderLevel1: 'headerlevel1',
|
|
12
|
+
HeaderLevel2: 'headerlevel2',
|
|
13
|
+
HeaderLevel3: 'headerlevel3',
|
|
14
|
+
Link: 'link',
|
|
15
|
+
OrderedList: 'ordered_list',
|
|
16
|
+
BulletList: 'bullet_list',
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* `LevelMapping` is used to map string identifiers to numerical header levels.
|
|
20
|
+
* It provides a way to represent different levels of headings in ProseMirror commands.
|
|
21
|
+
*
|
|
22
|
+
* The `Heading` identifier is not a valid level and is used to identify the node type.
|
|
23
|
+
* The numerical values are used for creating ProseMirror commands to set the level of a heading node in the editor.
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
export const LevelMapping = {
|
|
27
|
+
Heading: 'heading',
|
|
28
|
+
one: 1,
|
|
29
|
+
two: 2,
|
|
30
|
+
three: 3,
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/text-editor/prosemirror-adapter/menu/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG;EAC3B,IAAI,EAAE,QAAQ;EACd,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,YAAY;EACxB,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,YAAY,EAAE,cAAc;EAC5B,IAAI,EAAE,MAAM;EACZ,WAAW,EAAE,cAAc;EAC3B,UAAU,EAAE,aAAa;CAC5B,CAAC;AAKF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;EACxB,OAAO,EAAE,SAAS;EAClB,GAAG,EAAE,CAAC;EACN,GAAG,EAAE,CAAC;EACN,KAAK,EAAE,CAAC;CACX,CAAC","sourcesContent":["/**\n * The `EditorMenuType` type is used to specify the type of menu items that can be added to the editor toolbar.\n * Each one represents a different type to be used for creating the prosemirror commands relevant to the button.\n * The values correspond to the types that can be used with the `prosemirror-commands` library.\n * @beta\n */\n\nexport const EditorMenuTypes = {\n Bold: 'strong',\n Italic: 'em',\n Blockquote: 'blockquote',\n HeaderLevel1: 'headerlevel1',\n HeaderLevel2: 'headerlevel2',\n HeaderLevel3: 'headerlevel3',\n Link: 'link',\n OrderedList: 'ordered_list',\n BulletList: 'bullet_list',\n};\n\nexport type EditorMenuTypes =\n (typeof EditorMenuTypes)[keyof typeof EditorMenuTypes];\n\n/**\n * `LevelMapping` is used to map string identifiers to numerical header levels.\n * It provides a way to represent different levels of headings in ProseMirror commands.\n *\n * The `Heading` identifier is not a valid level and is used to identify the node type.\n * The numerical values are used for creating ProseMirror commands to set the level of a heading node in the editor.\n * @beta\n */\nexport const LevelMapping = {\n Heading: 'heading',\n one: 1,\n two: 2,\n three: 3,\n};\n\nexport type LevelMapping = (typeof LevelMapping)[keyof typeof LevelMapping];\n\nexport type ProseMirrorAdapterElementWithFocus =\n HTMLLimelProsemirrorAdapterElement & {\n setFocus: () => void;\n };\n"]}
|
|
@@ -5,6 +5,7 @@ import { Schema, DOMParser } from 'prosemirror-model';
|
|
|
5
5
|
import { schema } from 'prosemirror-schema-basic';
|
|
6
6
|
import { addListNodes } from 'prosemirror-schema-list';
|
|
7
7
|
import { exampleSetup } from 'prosemirror-example-setup';
|
|
8
|
+
import { keymap } from 'prosemirror-keymap';
|
|
8
9
|
import { MenuCommandFactory } from './menu/menu-commands';
|
|
9
10
|
import { textEditorMenuItems } from './menu/menu-items';
|
|
10
11
|
import { markdownConverter } from '../utils/markdown-converter';
|
|
@@ -20,6 +21,7 @@ import { HTMLConverter } from '../utils/html-converter';
|
|
|
20
21
|
*/
|
|
21
22
|
export class ProsemirrorAdapter {
|
|
22
23
|
constructor() {
|
|
24
|
+
this.editorKeyMap = {};
|
|
23
25
|
this.initializeTextEditor = async () => {
|
|
24
26
|
this.actionBarItems = textEditorMenuItems;
|
|
25
27
|
const mySchema = new Schema({
|
|
@@ -34,13 +36,19 @@ export class ProsemirrorAdapter {
|
|
|
34
36
|
await this.contentConverter.parseAsHTML(this.value, schema);
|
|
35
37
|
}
|
|
36
38
|
const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
|
|
39
|
+
this.menuCommandFactory = new MenuCommandFactory(mySchema);
|
|
40
|
+
this.editorKeyMap = this.menuCommandFactory.buildKeymap();
|
|
41
|
+
const keymapPlugin = keymap(this.editorKeyMap);
|
|
37
42
|
this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
|
|
38
43
|
state: EditorState.create({
|
|
39
44
|
doc: initialDoc,
|
|
40
|
-
plugins:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
plugins: [
|
|
46
|
+
...exampleSetup({
|
|
47
|
+
schema: mySchema,
|
|
48
|
+
menuBar: false,
|
|
49
|
+
}),
|
|
50
|
+
keymapPlugin,
|
|
51
|
+
],
|
|
44
52
|
}),
|
|
45
53
|
dispatchTransaction: (transaction) => {
|
|
46
54
|
const newState = this.view.state.apply(transaction);
|
|
@@ -55,10 +63,9 @@ export class ProsemirrorAdapter {
|
|
|
55
63
|
};
|
|
56
64
|
this.handleActionBarItem = (event) => {
|
|
57
65
|
event.preventDefault();
|
|
58
|
-
const {
|
|
59
|
-
const mark = text.replace(/\s/g, '').toLowerCase();
|
|
66
|
+
const { value } = event.detail;
|
|
60
67
|
try {
|
|
61
|
-
const command = this.menuCommandFactory.
|
|
68
|
+
const command = this.menuCommandFactory.getCommand(value);
|
|
62
69
|
this.executeCommand(command);
|
|
63
70
|
}
|
|
64
71
|
catch (error) {
|
|
@@ -118,7 +125,11 @@ export class ProsemirrorAdapter {
|
|
|
118
125
|
transaction = tr;
|
|
119
126
|
});
|
|
120
127
|
this.view.dispatch(transaction);
|
|
121
|
-
this.
|
|
128
|
+
this.setFocus();
|
|
129
|
+
}
|
|
130
|
+
setFocus() {
|
|
131
|
+
var _a;
|
|
132
|
+
(_a = this.view) === null || _a === void 0 ? void 0 : _a.focus();
|
|
122
133
|
}
|
|
123
134
|
static get is() { return "limel-prosemirror-adapter"; }
|
|
124
135
|
static get encapsulation() { return "shadow"; }
|
package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosemirror-adapter.js","sourceRoot":"","sources":["../../../../src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,CAAC,GACJ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;;;;;GAQG;AAMH,MAAM,OAAO,kBAAkB;;IAwEnB,yBAAoB,GAAG,KAAK,IAAI,EAAE;MACtC,IAAI,CAAC,cAAc,GAAG,mBAAmB,CAAC;MAE1C,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC;QACxB,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,CAAC;QACnE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK;OAC3B,CAAC,CAAC;MAEH,wDAAwD;MACxD,MAAM,qBAAqB,GAAG,QAAQ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AAC;IAEhC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;EACtB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\nimport { EditorState } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\nimport { Schema, DOMParser } from 'prosemirror-model';\nimport { schema } from 'prosemirror-schema-basic';\nimport { addListNodes } from 'prosemirror-schema-list';\nimport { exampleSetup } from 'prosemirror-example-setup';\nimport { ActionBarItem } from 'src/components/action-bar/action-bar.types';\nimport { ListSeparator } from 'src/components/list/list-item.types';\nimport { MenuCommandFactory } from './menu/menu-commands';\nimport { textEditorMenuItems } from './menu/menu-items';\nimport { ContentTypeConverter } from '../utils/content-type-converter';\nimport { markdownConverter } from '../utils/markdown-converter';\nimport { HTMLConverter } from '../utils/html-converter';\n\n/**\n * The ProseMirror adapter offers a rich text editing experience with markdown support.\n * [Read more...](https://prosemirror.net/)\n *\n * @exampleComponent limel-example-prosemirror-adapter-basic\n * @exampleComponent limel-example-prosemirror-adapter-with-custom-menu\n * @beta\n * @private\n */\n@Component({\n tag: 'limel-prosemirror-adapter',\n shadow: true,\n styleUrl: 'prosemirror-adapter.scss',\n})\nexport class ProsemirrorAdapter {\n /**\n * The type of content that the editor should handle and emit, defaults to `markdown`\n *\n * Assumed to be set only once, so not reactive to changes\n */\n @Prop()\n public contentType: 'markdown' | 'html' = 'markdown';\n\n /**\n * The value of the editor, expected to be markdown\n */\n @Prop()\n public value: string;\n\n @Element()\n private host: HTMLLimelTextEditorElement;\n\n @State()\n private view: EditorView;\n\n @State()\n private actionBarItems: Array<ActionBarItem | ListSeparator> = [];\n\n private menuCommandFactory: MenuCommandFactory;\n\n /**\n * Dispatched when a change is made to the editor\n */\n @Event()\n private change: EventEmitter<string>;\n\n @Watch('value')\n protected watchValue(newValue: string) {\n if (\n !this.view ||\n newValue === this.contentConverter.serialize(this.view, schema)\n ) {\n return;\n }\n\n this.updateView(newValue);\n }\n\n private contentConverter: ContentTypeConverter;\n\n public componentWillLoad() {\n if (this.contentType === 'markdown') {\n this.contentConverter = new markdownConverter();\n } else if (this.contentType === 'html') {\n this.contentConverter = new HTMLConverter();\n }\n }\n\n public componentDidLoad() {\n // Stencil complains loudly about triggering rerenders in\n // componentDidLoad, but we have to, so we're using setTimeout to\n // suppress the warning. /Ads\n setTimeout(this.initializeTextEditor, 0);\n }\n\n public render() {\n return [\n <div id=\"editor\" />,\n <limel-action-bar\n accessibleLabel=\"Toolbar\"\n actions={this.actionBarItems}\n onItemSelected={this.handleActionBarItem}\n />,\n ];\n }\n\n private initializeTextEditor = async () => {\n this.actionBarItems = textEditorMenuItems;\n\n const mySchema = new Schema({\n nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),\n marks: schema.spec.marks,\n });\n\n // Parse initial content directly if 'value' is provided\n const initialContentElement = document.createElement('div');\n initialContentElement.innerHTML = '<p></p>';\n if (this.value) {\n initialContentElement.innerHTML =\n await this.contentConverter.parseAsHTML(this.value, schema);\n }\n\n const initialDoc = DOMParser.fromSchema(mySchema).parse(\n initialContentElement,\n );\n\n this.view = new EditorView(\n this.host.shadowRoot.querySelector('#editor'),\n {\n state: EditorState.create({\n doc: initialDoc,\n plugins: exampleSetup({\n schema: mySchema,\n menuBar: false,\n }),\n }),\n dispatchTransaction: (transaction) => {\n const newState = this.view.state.apply(transaction);\n this.view.updateState(newState);\n\n this.change.emit(\n this.contentConverter.serialize(this.view, schema),\n );\n },\n },\n );\n\n this.menuCommandFactory = new MenuCommandFactory(mySchema);\n\n if (this.value) {\n this.updateView(this.value);\n }\n };\n\n private async updateView(content: string) {\n const html = await this.contentConverter.parseAsHTML(content, schema);\n const prosemirrorDOMparser = DOMParser.fromSchema(\n this.view.state.schema,\n );\n const domParser = new window.DOMParser();\n const doc = domParser.parseFromString(html, 'text/html');\n const prosemirrorDoc = prosemirrorDOMparser.parse(doc.body);\n const tr = this.view.state.tr;\n tr.replaceWith(0, tr.doc.content.size, prosemirrorDoc.content);\n\n this.view.dispatch(tr);\n }\n\n private handleActionBarItem = (event: CustomEvent<ActionBarItem>) => {\n event.preventDefault();\n\n const { text } = event.detail;\n const mark = text.replace(/\\s/g, '').toLowerCase();\n try {\n const command = this.menuCommandFactory.createCommand(mark);\n this.executeCommand(command);\n } catch (error) {\n throw new Error(`Error executing command: ${error}`);\n }\n };\n\n private executeCommand(command) {\n const { state } = this.view;\n const selection = state.selection;\n\n let transaction = state.tr;\n\n if (!selection.empty) {\n transaction.setSelection(selection);\n }\n\n command(state, (tr) => {\n transaction = tr;\n });\n this.view.dispatch(transaction);\n\n this.view.focus();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prosemirror-adapter.js","sourceRoot":"","sources":["../../../../src/components/text-editor/prosemirror-adapter/prosemirror-adapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,CAAC,GACJ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE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,EAAE,CAAC;IAC9B,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;EAC3B,CAAC;EAcO,cAAc,CAAC,OAAO;IAC1B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IAElC,IAAI,WAAW,GAAG,KAAK,CAAC,EAAE,CAAC;IAE3B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;MAClB,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KACvC;IAED,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE;MAClB,WAAW,GAAG,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEhC,IAAI,CAAC,QAAQ,EAAE,CAAC;EACpB,CAAC;EAEM,QAAQ;;IACX,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,EAAE,CAAC;EACvB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\nimport { EditorState } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\nimport { Schema, DOMParser } from 'prosemirror-model';\nimport { schema } from 'prosemirror-schema-basic';\nimport { addListNodes } from 'prosemirror-schema-list';\nimport { exampleSetup } from 'prosemirror-example-setup';\nimport { keymap } from 'prosemirror-keymap';\nimport { ActionBarItem } from 'src/components/action-bar/action-bar.types';\nimport { ListSeparator } from 'src/components/list/list-item.types';\nimport { MenuCommandFactory } from './menu/menu-commands';\nimport { textEditorMenuItems } from './menu/menu-items';\nimport { ContentTypeConverter } from '../utils/content-type-converter';\nimport { markdownConverter } from '../utils/markdown-converter';\nimport { HTMLConverter } from '../utils/html-converter';\nimport { EditorMenuTypes } from './menu/types';\n\n/**\n * The ProseMirror adapter offers a rich text editing experience with markdown support.\n * [Read more...](https://prosemirror.net/)\n *\n * @exampleComponent limel-example-prosemirror-adapter-basic\n * @exampleComponent limel-example-prosemirror-adapter-with-custom-menu\n * @beta\n * @private\n */\n@Component({\n tag: 'limel-prosemirror-adapter',\n shadow: true,\n styleUrl: 'prosemirror-adapter.scss',\n})\nexport class ProsemirrorAdapter {\n /**\n * The type of content that the editor should handle and emit, defaults to `markdown`\n *\n * Assumed to be set only once, so not reactive to changes\n */\n @Prop()\n public contentType: 'markdown' | 'html' = 'markdown';\n\n /**\n * The value of the editor, expected to be markdown\n */\n @Prop()\n public value: string;\n\n @Element()\n private host: HTMLLimelTextEditorElement;\n\n @State()\n private view: EditorView;\n\n @State()\n private actionBarItems: Array<\n ActionBarItem<EditorMenuTypes> | ListSeparator\n > = [];\n\n private menuCommandFactory: MenuCommandFactory;\n private editorKeyMap = {};\n\n /**\n * Dispatched when a change is made to the editor\n */\n @Event()\n private change: EventEmitter<string>;\n\n @Watch('value')\n protected watchValue(newValue: string) {\n if (\n !this.view ||\n newValue === this.contentConverter.serialize(this.view, schema)\n ) {\n return;\n }\n\n this.updateView(newValue);\n }\n\n private contentConverter: ContentTypeConverter;\n\n public componentWillLoad() {\n if (this.contentType === 'markdown') {\n this.contentConverter = new markdownConverter();\n } else if (this.contentType === 'html') {\n this.contentConverter = new HTMLConverter();\n }\n }\n\n public componentDidLoad() {\n // Stencil complains loudly about triggering rerenders in\n // componentDidLoad, but we have to, so we're using setTimeout to\n // suppress the warning. /Ads\n setTimeout(this.initializeTextEditor, 0);\n }\n\n public render() {\n return [\n <div id=\"editor\" />,\n <limel-action-bar\n accessibleLabel=\"Toolbar\"\n actions={this.actionBarItems}\n onItemSelected={this.handleActionBarItem}\n />,\n ];\n }\n\n private initializeTextEditor = async () => {\n this.actionBarItems = textEditorMenuItems;\n\n const mySchema = new Schema({\n nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),\n marks: schema.spec.marks,\n });\n\n // Parse initial content directly if 'value' is provided\n const initialContentElement = document.createElement('div');\n initialContentElement.innerHTML = '<p></p>';\n if (this.value) {\n initialContentElement.innerHTML =\n await this.contentConverter.parseAsHTML(this.value, schema);\n }\n\n const initialDoc = DOMParser.fromSchema(mySchema).parse(\n initialContentElement,\n );\n\n this.menuCommandFactory = new MenuCommandFactory(mySchema);\n\n this.editorKeyMap = this.menuCommandFactory.buildKeymap();\n\n const keymapPlugin = keymap(this.editorKeyMap);\n\n this.view = new EditorView(\n this.host.shadowRoot.querySelector('#editor'),\n {\n state: EditorState.create({\n doc: initialDoc,\n plugins: [\n ...exampleSetup({\n schema: mySchema,\n menuBar: false,\n }),\n keymapPlugin,\n ],\n }),\n dispatchTransaction: (transaction) => {\n const newState = this.view.state.apply(transaction);\n this.view.updateState(newState);\n\n this.change.emit(\n this.contentConverter.serialize(this.view, schema),\n );\n },\n },\n );\n\n this.menuCommandFactory = new MenuCommandFactory(mySchema);\n\n if (this.value) {\n this.updateView(this.value);\n }\n };\n\n private async updateView(content: string) {\n const html = await this.contentConverter.parseAsHTML(content, schema);\n const prosemirrorDOMparser = DOMParser.fromSchema(\n this.view.state.schema,\n );\n const domParser = new window.DOMParser();\n const doc = domParser.parseFromString(html, 'text/html');\n const prosemirrorDoc = prosemirrorDOMparser.parse(doc.body);\n const tr = this.view.state.tr;\n tr.replaceWith(0, tr.doc.content.size, prosemirrorDoc.content);\n\n this.view.dispatch(tr);\n }\n\n private handleActionBarItem = (event: CustomEvent<ActionBarItem>) => {\n event.preventDefault();\n\n const { value } = event.detail;\n try {\n const command = this.menuCommandFactory.getCommand(value);\n this.executeCommand(command);\n } catch (error) {\n throw new Error(`Error executing command: ${error}`);\n }\n };\n\n private executeCommand(command) {\n const { state } = this.view;\n const selection = state.selection;\n\n let transaction = state.tr;\n\n if (!selection.empty) {\n transaction.setSelection(selection);\n }\n\n command(state, (tr) => {\n transaction = tr;\n });\n this.view.dispatch(transaction);\n\n this.setFocus();\n }\n\n public setFocus() {\n this.view?.focus();\n }\n}\n"]}
|
|
@@ -30,8 +30,15 @@ const DockButton = class {
|
|
|
30
30
|
event.stopPropagation();
|
|
31
31
|
this.itemSelected.emit(this.item);
|
|
32
32
|
};
|
|
33
|
-
this.focusCustomComponentElement = () => {
|
|
33
|
+
this.focusCustomComponentElement = (entries) => {
|
|
34
34
|
var _a, _b, _c;
|
|
35
|
+
const entry = entries.find((e) => e.target === this.customComponentElement);
|
|
36
|
+
if (!entry) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!entry.isIntersecting) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
35
42
|
if ((_b = (_a = this.customComponentElement) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.delegatesFocus) {
|
|
36
43
|
(_c = this.customComponentElement) === null || _c === void 0 ? void 0 : _c.focus();
|
|
37
44
|
}
|
|
@@ -59,8 +66,15 @@ const DockButton = class {
|
|
|
59
66
|
if (!this.isOpen) {
|
|
60
67
|
return;
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
if (!this.intersectionObserver) {
|
|
70
|
+
this.intersectionObserver = new IntersectionObserver(this.focusCustomComponentElement);
|
|
71
|
+
this.intersectionObserver.observe(this.customComponentElement);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
disconnectedCallback() {
|
|
75
|
+
var _a;
|
|
76
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
77
|
+
this.intersectionObserver = undefined;
|
|
64
78
|
}
|
|
65
79
|
renderPopover() {
|
|
66
80
|
var _a;
|