@limetech/lime-elements 37.28.0 → 37.28.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.
@@ -20,6 +20,36 @@ import { HTMLConverter } from '../utils/html-converter';
20
20
  */
21
21
  export class ProsemirrorAdapter {
22
22
  constructor() {
23
+ this.initializeTextEditor = async () => {
24
+ this.actionBarItems = textEditorMenuItems;
25
+ const mySchema = new Schema({
26
+ nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
27
+ marks: schema.spec.marks,
28
+ });
29
+ // Parse initial content directly if 'value' is provided
30
+ const initialContentElement = document.createElement('div');
31
+ initialContentElement.innerHTML = '<p></p>';
32
+ if (this.value) {
33
+ initialContentElement.innerHTML =
34
+ await this.contentConverter.parseAsHTML(this.value, schema);
35
+ }
36
+ const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
37
+ this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
38
+ state: EditorState.create({
39
+ doc: initialDoc,
40
+ plugins: exampleSetup({
41
+ schema: mySchema,
42
+ menuBar: false,
43
+ }),
44
+ }),
45
+ dispatchTransaction: (transaction) => {
46
+ const newState = this.view.state.apply(transaction);
47
+ this.view.updateState(newState);
48
+ this.change.emit(this.contentConverter.serialize(this.view, schema));
49
+ },
50
+ });
51
+ this.menuCommandFactory = new MenuCommandFactory(mySchema);
52
+ };
23
53
  this.handleActionBarItem = (event) => {
24
54
  event.preventDefault();
25
55
  const { text } = event.detail;
@@ -57,36 +87,6 @@ export class ProsemirrorAdapter {
57
87
  h("div", { id: "editor" }),
58
88
  ];
59
89
  }
60
- async initializeTextEditor() {
61
- this.actionBarItems = textEditorMenuItems;
62
- const mySchema = new Schema({
63
- nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
64
- marks: schema.spec.marks,
65
- });
66
- // Parse initial content directly if 'value' is provided
67
- const initialContentElement = document.createElement('div');
68
- initialContentElement.innerHTML = '<p></p>';
69
- if (this.value) {
70
- initialContentElement.innerHTML =
71
- await this.contentConverter.parseAsHTML(this.value, schema);
72
- }
73
- const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
74
- this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
75
- state: EditorState.create({
76
- doc: initialDoc,
77
- plugins: exampleSetup({
78
- schema: mySchema,
79
- menuBar: false,
80
- }),
81
- }),
82
- dispatchTransaction: (transaction) => {
83
- const newState = this.view.state.apply(transaction);
84
- this.view.updateState(newState);
85
- this.change.emit(this.contentConverter.serialize(this.view, schema));
86
- },
87
- });
88
- this.menuCommandFactory = new MenuCommandFactory(mySchema);
89
- }
90
90
  executeCommand(command) {
91
91
  const { state } = this.view;
92
92
  const selection = state.selection;
@@ -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,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;A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AAkB,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;EAC/D,CAAC;EAeO,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,IAAI,CAAC,KAAK,EAAE,CAAC;EACtB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\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 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 <limel-action-bar\n accessibleLabel=\"Toolbar\"\n actions={this.actionBarItems}\n onItemSelected={this.handleActionBarItem}\n />,\n <div id=\"editor\" />,\n ];\n }\n\n private async initializeTextEditor() {\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\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,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,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,CAAC;EAEM,MAAM;IACT,OAAO;MACH,wBACI,eAAe,EAAC,SAAS,EACzB,OAAO,EAAE,IAAI,CAAC,cAAc,EAC5B,cAAc,EAAE,IAAI,CAAC,mBAAmB,GAC1C;MACF,WAAK,EAAE,EAAC,QAAQ,GAAG;KACtB,CAAC;EACN,CAAC;EA2DO,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,IAAI,CAAC,KAAK,EAAE,CAAC;EACtB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n Prop,\n State,\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 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 <limel-action-bar\n accessibleLabel=\"Toolbar\"\n actions={this.actionBarItems}\n onItemSelected={this.handleActionBarItem}\n />,\n <div id=\"editor\" />,\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\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"]}
@@ -24714,6 +24714,36 @@ const ProsemirrorAdapter = class {
24714
24714
  constructor(hostRef) {
24715
24715
  registerInstance(this, hostRef);
24716
24716
  this.change = createEvent(this, "change", 7);
24717
+ this.initializeTextEditor = async () => {
24718
+ this.actionBarItems = textEditorMenuItems;
24719
+ const mySchema = new Schema({
24720
+ nodes: addListNodes(schema$1.spec.nodes, 'paragraph block*', 'block'),
24721
+ marks: schema$1.spec.marks,
24722
+ });
24723
+ // Parse initial content directly if 'value' is provided
24724
+ const initialContentElement = document.createElement('div');
24725
+ initialContentElement.innerHTML = '<p></p>';
24726
+ if (this.value) {
24727
+ initialContentElement.innerHTML =
24728
+ await this.contentConverter.parseAsHTML(this.value, schema$1);
24729
+ }
24730
+ const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
24731
+ this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
24732
+ state: EditorState.create({
24733
+ doc: initialDoc,
24734
+ plugins: exampleSetup({
24735
+ schema: mySchema,
24736
+ menuBar: false,
24737
+ }),
24738
+ }),
24739
+ dispatchTransaction: (transaction) => {
24740
+ const newState = this.view.state.apply(transaction);
24741
+ this.view.updateState(newState);
24742
+ this.change.emit(this.contentConverter.serialize(this.view, schema$1));
24743
+ },
24744
+ });
24745
+ this.menuCommandFactory = new MenuCommandFactory(mySchema);
24746
+ };
24717
24747
  this.handleActionBarItem = (event) => {
24718
24748
  event.preventDefault();
24719
24749
  const { text } = event.detail;
@@ -24751,36 +24781,6 @@ const ProsemirrorAdapter = class {
24751
24781
  h("div", { id: "editor" }),
24752
24782
  ];
24753
24783
  }
24754
- async initializeTextEditor() {
24755
- this.actionBarItems = textEditorMenuItems;
24756
- const mySchema = new Schema({
24757
- nodes: addListNodes(schema$1.spec.nodes, 'paragraph block*', 'block'),
24758
- marks: schema$1.spec.marks,
24759
- });
24760
- // Parse initial content directly if 'value' is provided
24761
- const initialContentElement = document.createElement('div');
24762
- initialContentElement.innerHTML = '<p></p>';
24763
- if (this.value) {
24764
- initialContentElement.innerHTML =
24765
- await this.contentConverter.parseAsHTML(this.value, schema$1);
24766
- }
24767
- const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
24768
- this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
24769
- state: EditorState.create({
24770
- doc: initialDoc,
24771
- plugins: exampleSetup({
24772
- schema: mySchema,
24773
- menuBar: false,
24774
- }),
24775
- }),
24776
- dispatchTransaction: (transaction) => {
24777
- const newState = this.view.state.apply(transaction);
24778
- this.view.updateState(newState);
24779
- this.change.emit(this.contentConverter.serialize(this.view, schema$1));
24780
- },
24781
- });
24782
- this.menuCommandFactory = new MenuCommandFactory(mySchema);
24783
- }
24784
24784
  executeCommand(command) {
24785
24785
  const { state } = this.view;
24786
24786
  const selection = state.selection;