@limetech/lime-elements 37.45.0 → 37.45.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/CHANGELOG.md +22 -0
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +21 -6
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +21 -6
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js.map +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +21 -6
- 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-1ffe31d4.entry.js → p-a0fc1875.entry.js} +2 -2
- package/dist/lime-elements/p-a0fc1875.entry.js.map +1 -0
- package/dist/types/components/text-editor/prosemirror-adapter/prosemirror-adapter.d.ts +2 -0
- package/package.json +1 -1
- package/dist/lime-elements/p-1ffe31d4.entry.js.map +0 -1
|
@@ -25,6 +25,7 @@ import { strikethrough } from './menu/menu-schema-extender';
|
|
|
25
25
|
*/
|
|
26
26
|
export class ProsemirrorAdapter {
|
|
27
27
|
constructor() {
|
|
28
|
+
this.suppressChangeEvent = false;
|
|
28
29
|
this.getActionBarItems = () => {
|
|
29
30
|
this.actionBarItems = getTextEditorMenuItems().map(this.getTranslatedItem);
|
|
30
31
|
};
|
|
@@ -41,6 +42,12 @@ export class ProsemirrorAdapter {
|
|
|
41
42
|
this.handleTransaction = (transaction) => {
|
|
42
43
|
const newState = this.view.state.apply(transaction);
|
|
43
44
|
this.view.updateState(newState);
|
|
45
|
+
if (this.suppressChangeEvent) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (transaction.getMeta('pointer')) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
44
51
|
this.change.emit(this.contentConverter.serialize(this.view, this.schema));
|
|
45
52
|
};
|
|
46
53
|
this.handleActionBarItem = (event) => {
|
|
@@ -111,13 +118,19 @@ export class ProsemirrorAdapter {
|
|
|
111
118
|
h("limel-action-bar", { accessibleLabel: "Toolbar", actions: this.actionBarItems, onItemSelected: this.handleActionBarItem }),
|
|
112
119
|
];
|
|
113
120
|
}
|
|
121
|
+
disconnectedCallback() {
|
|
122
|
+
this.view.destroy();
|
|
123
|
+
}
|
|
114
124
|
setupContentConverter() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
if (this.contentType === 'markdown') {
|
|
126
|
+
this.contentConverter = new markdownConverter();
|
|
127
|
+
}
|
|
128
|
+
else if (this.contentType === 'html') {
|
|
129
|
+
this.contentConverter = new HTMLConverter();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
throw new Error(`Unsupported content type: ${this.contentType}. Only 'markdown' and 'html' are supported.`);
|
|
133
|
+
}
|
|
121
134
|
}
|
|
122
135
|
async initializeTextEditor() {
|
|
123
136
|
this.schema = this.initializeSchema();
|
|
@@ -161,6 +174,7 @@ export class ProsemirrorAdapter {
|
|
|
161
174
|
});
|
|
162
175
|
}
|
|
163
176
|
async updateView(content) {
|
|
177
|
+
this.suppressChangeEvent = true;
|
|
164
178
|
const html = await this.contentConverter.parseAsHTML(content, this.schema);
|
|
165
179
|
const prosemirrorDOMparser = DOMParser.fromSchema(this.view.state.schema);
|
|
166
180
|
const domParser = new window.DOMParser();
|
|
@@ -169,6 +183,7 @@ export class ProsemirrorAdapter {
|
|
|
169
183
|
const tr = this.view.state.tr;
|
|
170
184
|
tr.replaceWith(0, tr.doc.content.size, prosemirrorDoc.content);
|
|
171
185
|
this.view.dispatch(tr);
|
|
186
|
+
this.suppressChangeEvent = false;
|
|
172
187
|
}
|
|
173
188
|
dispatchMenuCommand(command) {
|
|
174
189
|
const { state } = this.view;
|
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,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnE,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,EAAqB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D;;;;;;;;GAQG;AAMH,MAAM,OAAO,kBAAkB;;IAwFnB,sBAAiB,GAAG,GAAG,EAAE;MAC7B,IAAI,CAAC,cAAc,GAAG,sBAAsB,EAAE,CAAC,GAAG,CAC9C,IAAI,CAAC,iBAAiB,CACzB,CAAC;IACN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Content":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\nimport { EditorState, Plugin, PluginKey } 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 { CommandWithActive, MenuCommandFactory } from './menu/menu-commands';\nimport { menuTranslationIDs, getTextEditorMenuItems } 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';\nimport translate from 'src/global/translations';\nimport { isItem } from 'src/components/action-bar/isItem';\nimport { cloneDeep } from 'lodash-es';\nimport { Languages } from '../../date-picker/date.types';\nimport { strikethrough } from './menu/menu-schema-extender';\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 /**\n * Defines the language for translations.\n */\n @Prop({ reflect: true })\n public language: Languages;\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 schema: Schema;\n private contentConverter: ContentTypeConverter;\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, this.schema)\n ) {\n return;\n }\n\n this.updateView(newValue);\n }\n\n public componentWillLoad() {\n this.getActionBarItems();\n this.setupContentConverter();\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(() => {\n this.initializeTextEditor();\n }, 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 setupContentConverter() {\n /* eslint-disable multiline-ternary */\n this.contentConverter =\n this.contentType === 'markdown'\n ? new markdownConverter()\n : new HTMLConverter();\n /* eslint-enable multiline-ternary */\n }\n\n private getActionBarItems = () => {\n this.actionBarItems = getTextEditorMenuItems().map(\n this.getTranslatedItem,\n );\n };\n\n private getTranslatedItem = (item) => {\n const newItem = cloneDeep(item);\n\n if (isItem(item)) {\n const translationId = menuTranslationIDs[item.value];\n\n if (translationId) {\n newItem.text = translate.get(translationId, this.language);\n }\n }\n\n return newItem;\n };\n\n private async initializeTextEditor() {\n this.schema = this.initializeSchema();\n const initialDoc = await this.parseInitialContent();\n this.menuCommandFactory = new MenuCommandFactory(this.schema);\n this.view = new EditorView(\n this.host.shadowRoot.querySelector('#editor'),\n {\n state: this.createEditorState(initialDoc),\n dispatchTransaction: this.handleTransaction,\n },\n );\n if (this.value) {\n this.updateView(this.value);\n }\n }\n\n private initializeSchema() {\n return new Schema({\n nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),\n marks: schema.spec.marks.append({\n strikethrough: strikethrough,\n }),\n });\n }\n\n private async parseInitialContent() {\n const initialContentElement = document.createElement('div');\n\n if (this.value) {\n initialContentElement.innerHTML =\n await this.contentConverter.parseAsHTML(\n this.value,\n this.schema,\n );\n } else {\n initialContentElement.innerHTML = '<p></p>';\n }\n\n return DOMParser.fromSchema(this.schema).parse(initialContentElement);\n }\n\n private createEditorState(initialDoc) {\n return EditorState.create({\n doc: initialDoc,\n plugins: [\n ...exampleSetup({ schema: this.schema, menuBar: false }),\n keymap(this.menuCommandFactory.buildKeymap()),\n this.createMenuStateTrackingPlugin(this.actionBarItems),\n ],\n });\n }\n\n private async updateView(content: string) {\n const html = await this.contentConverter.parseAsHTML(\n content,\n this.schema,\n );\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 this.view.dispatch(tr);\n }\n\n private handleTransaction = (transaction) => {\n const newState = this.view.state.apply(transaction);\n this.view.updateState(newState);\n this.change.emit(\n this.contentConverter.serialize(this.view, this.schema),\n );\n };\n\n private handleActionBarItem = (\n event: CustomEvent<ActionBarItem<EditorMenuTypes>>,\n ) => {\n event.preventDefault();\n const { value } = event.detail;\n\n try {\n const command = this.menuCommandFactory.getCommand(value);\n this.dispatchMenuCommand(command);\n } catch (error) {\n throw new Error(`Error executing command: ${error}`);\n }\n };\n\n private dispatchMenuCommand(command) {\n const { state } = this.view;\n const selection = state.selection;\n let transaction = state.tr;\n if (!selection.empty) {\n transaction.setSelection(selection);\n }\n\n command(state, (tr) => {\n transaction = tr;\n });\n this.view.dispatch(transaction);\n this.setFocus();\n }\n\n public setFocus() {\n this.view?.focus();\n }\n\n actionBarPluginKey = new PluginKey('actionBarPlugin');\n\n private updateActionBarItems = (\n actionBarItems: Array<ActionBarItem<EditorMenuTypes> | ListSeparator>,\n view: EditorView,\n ) => {\n const updatedItems = cloneDeep(actionBarItems);\n updatedItems.forEach((item) => {\n if (isItem(item)) {\n const command: CommandWithActive =\n this.menuCommandFactory.getCommand(item.value);\n if (command && command.active) {\n item.selected = command.active(view.state);\n } else {\n item.selected = false;\n }\n }\n });\n this.actionBarItems = updatedItems;\n };\n\n private createMenuStateTrackingPlugin = (\n actionBarItems: Array<ActionBarItem<EditorMenuTypes> | ListSeparator>,\n ) => {\n return new Plugin({\n key: this.actionBarPluginKey,\n view: () => ({\n update: (view) => {\n this.updateActionBarItems(actionBarItems, view);\n },\n }),\n });\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,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChF,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,EAAqB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAA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Ac,CAAC,OAAO,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvB,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;EACrC,CAAC;EAiCO,mBAAmB,CAAC,OAAO;IAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IAClC,IAAI,WAAW,GAAG,KAAK,CAAC,EAAE,CAAC;IAC3B,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;IAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;EACpB,CAAC;EAEM,QAAQ;;IACX,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,EAAE,CAAC;EACvB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\nimport { EditorState, Plugin, PluginKey, Transaction } 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 { CommandWithActive, MenuCommandFactory } from './menu/menu-commands';\nimport { menuTranslationIDs, getTextEditorMenuItems } 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';\nimport translate from 'src/global/translations';\nimport { isItem } from 'src/components/action-bar/isItem';\nimport { cloneDeep } from 'lodash-es';\nimport { Languages } from '../../date-picker/date.types';\nimport { strikethrough } from './menu/menu-schema-extender';\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 /**\n * Defines the language for translations.\n */\n @Prop({ reflect: true })\n public language: Languages;\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 schema: Schema;\n private contentConverter: ContentTypeConverter;\n private suppressChangeEvent = false;\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, this.schema)\n ) {\n return;\n }\n\n this.updateView(newValue);\n }\n\n public componentWillLoad() {\n this.getActionBarItems();\n this.setupContentConverter();\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(() => {\n this.initializeTextEditor();\n }, 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 public disconnectedCallback() {\n this.view.destroy();\n }\n\n private setupContentConverter() {\n if (this.contentType === 'markdown') {\n this.contentConverter = new markdownConverter();\n } else if (this.contentType === 'html') {\n this.contentConverter = new HTMLConverter();\n } else {\n throw new Error(\n `Unsupported content type: ${this.contentType}. Only 'markdown' and 'html' are supported.`,\n );\n }\n }\n\n private getActionBarItems = () => {\n this.actionBarItems = getTextEditorMenuItems().map(\n this.getTranslatedItem,\n );\n };\n\n private getTranslatedItem = (item) => {\n const newItem = cloneDeep(item);\n\n if (isItem(item)) {\n const translationId = menuTranslationIDs[item.value];\n\n if (translationId) {\n newItem.text = translate.get(translationId, this.language);\n }\n }\n\n return newItem;\n };\n\n private async initializeTextEditor() {\n this.schema = this.initializeSchema();\n const initialDoc = await this.parseInitialContent();\n this.menuCommandFactory = new MenuCommandFactory(this.schema);\n this.view = new EditorView(\n this.host.shadowRoot.querySelector('#editor'),\n {\n state: this.createEditorState(initialDoc),\n dispatchTransaction: this.handleTransaction,\n },\n );\n if (this.value) {\n this.updateView(this.value);\n }\n }\n\n private initializeSchema() {\n return new Schema({\n nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),\n marks: schema.spec.marks.append({\n strikethrough: strikethrough,\n }),\n });\n }\n\n private async parseInitialContent() {\n const initialContentElement = document.createElement('div');\n\n if (this.value) {\n initialContentElement.innerHTML =\n await this.contentConverter.parseAsHTML(\n this.value,\n this.schema,\n );\n } else {\n initialContentElement.innerHTML = '<p></p>';\n }\n\n return DOMParser.fromSchema(this.schema).parse(initialContentElement);\n }\n\n private createEditorState(initialDoc) {\n return EditorState.create({\n doc: initialDoc,\n plugins: [\n ...exampleSetup({ schema: this.schema, menuBar: false }),\n keymap(this.menuCommandFactory.buildKeymap()),\n this.createMenuStateTrackingPlugin(this.actionBarItems),\n ],\n });\n }\n\n private async updateView(content: string) {\n this.suppressChangeEvent = true;\n const html = await this.contentConverter.parseAsHTML(\n content,\n this.schema,\n );\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 this.view.dispatch(tr);\n this.suppressChangeEvent = false;\n }\n\n private handleTransaction = (transaction: Transaction) => {\n const newState = this.view.state.apply(transaction);\n this.view.updateState(newState);\n\n if (this.suppressChangeEvent) {\n return;\n }\n\n if (transaction.getMeta('pointer')) {\n return;\n }\n\n this.change.emit(\n this.contentConverter.serialize(this.view, this.schema),\n );\n };\n\n private handleActionBarItem = (\n event: CustomEvent<ActionBarItem<EditorMenuTypes>>,\n ) => {\n event.preventDefault();\n const { value } = event.detail;\n\n try {\n const command = this.menuCommandFactory.getCommand(value);\n this.dispatchMenuCommand(command);\n } catch (error) {\n throw new Error(`Error executing command: ${error}`);\n }\n };\n\n private dispatchMenuCommand(command) {\n const { state } = this.view;\n const selection = state.selection;\n let transaction = state.tr;\n if (!selection.empty) {\n transaction.setSelection(selection);\n }\n\n command(state, (tr) => {\n transaction = tr;\n });\n this.view.dispatch(transaction);\n this.setFocus();\n }\n\n public setFocus() {\n this.view?.focus();\n }\n\n actionBarPluginKey = new PluginKey('actionBarPlugin');\n\n private updateActionBarItems = (\n actionBarItems: Array<ActionBarItem<EditorMenuTypes> | ListSeparator>,\n view: EditorView,\n ) => {\n const updatedItems = cloneDeep(actionBarItems);\n updatedItems.forEach((item) => {\n if (isItem(item)) {\n const command: CommandWithActive =\n this.menuCommandFactory.getCommand(item.value);\n if (command && command.active) {\n item.selected = command.active(view.state);\n } else {\n item.selected = false;\n }\n }\n });\n this.actionBarItems = updatedItems;\n };\n\n private createMenuStateTrackingPlugin = (\n actionBarItems: Array<ActionBarItem<EditorMenuTypes> | ListSeparator>,\n ) => {\n return new Plugin({\n key: this.actionBarPluginKey,\n view: () => ({\n update: (view) => {\n this.updateActionBarItems(actionBarItems, view);\n },\n }),\n });\n };\n}\n"]}
|
|
@@ -25556,6 +25556,7 @@ const ProsemirrorAdapter = class {
|
|
|
25556
25556
|
constructor(hostRef) {
|
|
25557
25557
|
registerInstance(this, hostRef);
|
|
25558
25558
|
this.change = createEvent(this, "change", 7);
|
|
25559
|
+
this.suppressChangeEvent = false;
|
|
25559
25560
|
this.getActionBarItems = () => {
|
|
25560
25561
|
this.actionBarItems = getTextEditorMenuItems().map(this.getTranslatedItem);
|
|
25561
25562
|
};
|
|
@@ -25572,6 +25573,12 @@ const ProsemirrorAdapter = class {
|
|
|
25572
25573
|
this.handleTransaction = (transaction) => {
|
|
25573
25574
|
const newState = this.view.state.apply(transaction);
|
|
25574
25575
|
this.view.updateState(newState);
|
|
25576
|
+
if (this.suppressChangeEvent) {
|
|
25577
|
+
return;
|
|
25578
|
+
}
|
|
25579
|
+
if (transaction.getMeta('pointer')) {
|
|
25580
|
+
return;
|
|
25581
|
+
}
|
|
25575
25582
|
this.change.emit(this.contentConverter.serialize(this.view, this.schema));
|
|
25576
25583
|
};
|
|
25577
25584
|
this.handleActionBarItem = (event) => {
|
|
@@ -25642,13 +25649,19 @@ const ProsemirrorAdapter = class {
|
|
|
25642
25649
|
h("limel-action-bar", { accessibleLabel: "Toolbar", actions: this.actionBarItems, onItemSelected: this.handleActionBarItem }),
|
|
25643
25650
|
];
|
|
25644
25651
|
}
|
|
25652
|
+
disconnectedCallback() {
|
|
25653
|
+
this.view.destroy();
|
|
25654
|
+
}
|
|
25645
25655
|
setupContentConverter() {
|
|
25646
|
-
|
|
25647
|
-
|
|
25648
|
-
|
|
25649
|
-
|
|
25650
|
-
|
|
25651
|
-
|
|
25656
|
+
if (this.contentType === 'markdown') {
|
|
25657
|
+
this.contentConverter = new markdownConverter();
|
|
25658
|
+
}
|
|
25659
|
+
else if (this.contentType === 'html') {
|
|
25660
|
+
this.contentConverter = new HTMLConverter();
|
|
25661
|
+
}
|
|
25662
|
+
else {
|
|
25663
|
+
throw new Error(`Unsupported content type: ${this.contentType}. Only 'markdown' and 'html' are supported.`);
|
|
25664
|
+
}
|
|
25652
25665
|
}
|
|
25653
25666
|
async initializeTextEditor() {
|
|
25654
25667
|
this.schema = this.initializeSchema();
|
|
@@ -25692,6 +25705,7 @@ const ProsemirrorAdapter = class {
|
|
|
25692
25705
|
});
|
|
25693
25706
|
}
|
|
25694
25707
|
async updateView(content) {
|
|
25708
|
+
this.suppressChangeEvent = true;
|
|
25695
25709
|
const html = await this.contentConverter.parseAsHTML(content, this.schema);
|
|
25696
25710
|
const prosemirrorDOMparser = DOMParser.fromSchema(this.view.state.schema);
|
|
25697
25711
|
const domParser = new window.DOMParser();
|
|
@@ -25700,6 +25714,7 @@ const ProsemirrorAdapter = class {
|
|
|
25700
25714
|
const tr = this.view.state.tr;
|
|
25701
25715
|
tr.replaceWith(0, tr.doc.content.size, prosemirrorDoc.content);
|
|
25702
25716
|
this.view.dispatch(tr);
|
|
25717
|
+
this.suppressChangeEvent = false;
|
|
25703
25718
|
}
|
|
25704
25719
|
dispatchMenuCommand(command) {
|
|
25705
25720
|
const { state } = this.view;
|