@limetech/lime-elements 37.20.0 → 37.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +16080 -0
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -0
- package/dist/cjs/limel-text-editor.cjs.entry.js +13 -16048
- package/dist/cjs/limel-text-editor.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/text-editor/prosemirror-adapter.css +699 -0
- package/dist/collection/components/text-editor/prosemirror-adapter.js +122 -0
- package/dist/collection/components/text-editor/prosemirror-adapter.js.map +1 -0
- package/dist/collection/components/text-editor/text-editor.css +0 -699
- package/dist/collection/components/text-editor/text-editor.js +133 -45
- package/dist/collection/components/text-editor/text-editor.js.map +1 -1
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +16076 -0
- package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -0
- package/dist/esm/limel-text-editor.entry.js +14 -16049
- package/dist/esm/limel-text-editor.entry.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/lime-elements.esm.js.map +1 -1
- package/dist/lime-elements/{p-10edf8b8.entry.js → p-0f45a6cc.entry.js} +2 -2
- package/dist/lime-elements/p-0f45a6cc.entry.js.map +1 -0
- package/dist/lime-elements/p-210c09a6.entry.js +2 -0
- package/dist/lime-elements/p-210c09a6.entry.js.map +1 -0
- package/dist/types/components/text-editor/prosemirror-adapter.d.ts +32 -0
- package/dist/types/components/text-editor/text-editor.d.ts +52 -13
- package/dist/types/components.d.ts +137 -24
- package/package.json +1 -1
- package/dist/lime-elements/p-10edf8b8.entry.js.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { h, } from '@stencil/core';
|
|
2
|
+
import { EditorState } from 'prosemirror-state';
|
|
3
|
+
import { EditorView } from 'prosemirror-view';
|
|
4
|
+
import { Schema, DOMParser } from 'prosemirror-model';
|
|
5
|
+
import { schema } from 'prosemirror-schema-basic';
|
|
6
|
+
import { addListNodes } from 'prosemirror-schema-list';
|
|
7
|
+
import { exampleSetup } from 'prosemirror-example-setup';
|
|
8
|
+
import { buildFullMenu } from './menu/full-menu';
|
|
9
|
+
import { getFilteredMenu } from './menu/menu-filter';
|
|
10
|
+
/**
|
|
11
|
+
* The ProseMirror adapter offers a rich text editing experience with markdown support,
|
|
12
|
+
* in the sense that you can easily type markdown syntax and see the rendered
|
|
13
|
+
* result as rich text in real-time. For instance, you can type `# Hello, world!`
|
|
14
|
+
* and see it directly turning to a heading 1 (an `<h1>` HTML element).
|
|
15
|
+
*
|
|
16
|
+
* Naturally, you can use standard keyboard hotkeys such as <kbd>Ctrl</kbd> + <kbd>B</kbd>
|
|
17
|
+
* to toggle bold text, <kbd>Ctrl</kbd> + <kbd>I</kbd> to toggle italic text, and so on.
|
|
18
|
+
*
|
|
19
|
+
* @exampleComponent limel-example-prosemirror-adapter-basic
|
|
20
|
+
* @beta
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
export class ProsemirrorAdapter {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.getHTML = () => {
|
|
26
|
+
if (this.view.dom.textContent === '') {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return this.view.dom.innerHTML;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.value = undefined;
|
|
34
|
+
this.view = undefined;
|
|
35
|
+
}
|
|
36
|
+
componentWillLoad() { }
|
|
37
|
+
render() {
|
|
38
|
+
return h("div", { id: "editor" });
|
|
39
|
+
}
|
|
40
|
+
componentDidLoad() {
|
|
41
|
+
const mySchema = new Schema({
|
|
42
|
+
nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
|
|
43
|
+
marks: schema.spec.marks,
|
|
44
|
+
});
|
|
45
|
+
const menu = buildFullMenu(mySchema)
|
|
46
|
+
.map((items) => getFilteredMenu(items, undefined))
|
|
47
|
+
.filter((items) => items.length);
|
|
48
|
+
this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
|
|
49
|
+
state: EditorState.create({
|
|
50
|
+
doc: DOMParser.fromSchema(mySchema).parse(this.host.shadowRoot.querySelector('#editor')),
|
|
51
|
+
plugins: exampleSetup({
|
|
52
|
+
schema: mySchema,
|
|
53
|
+
menuContent: menu,
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
dispatchTransaction: (transaction) => {
|
|
57
|
+
const newState = this.view.state.apply(transaction);
|
|
58
|
+
this.view.updateState(newState);
|
|
59
|
+
this.change.emit({ html: this.getHTML() });
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (this.value) {
|
|
63
|
+
this.view.dom.innerHTML = this.value.html;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static get is() { return "limel-prosemirror-adapter"; }
|
|
67
|
+
static get encapsulation() { return "shadow"; }
|
|
68
|
+
static get originalStyleUrls() {
|
|
69
|
+
return {
|
|
70
|
+
"$": ["prosemirror-adapter.scss"]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
static get styleUrls() {
|
|
74
|
+
return {
|
|
75
|
+
"$": ["prosemirror-adapter.css"]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
static get properties() {
|
|
79
|
+
return {
|
|
80
|
+
"value": {
|
|
81
|
+
"type": "unknown",
|
|
82
|
+
"mutable": false,
|
|
83
|
+
"complexType": {
|
|
84
|
+
"original": "{ html: string }",
|
|
85
|
+
"resolved": "{ html: string; }",
|
|
86
|
+
"references": {}
|
|
87
|
+
},
|
|
88
|
+
"required": false,
|
|
89
|
+
"optional": false,
|
|
90
|
+
"docs": {
|
|
91
|
+
"tags": [],
|
|
92
|
+
"text": "The value of the editor"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
static get states() {
|
|
98
|
+
return {
|
|
99
|
+
"view": {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
static get events() {
|
|
103
|
+
return [{
|
|
104
|
+
"method": "change",
|
|
105
|
+
"name": "change",
|
|
106
|
+
"bubbles": true,
|
|
107
|
+
"cancelable": true,
|
|
108
|
+
"composed": true,
|
|
109
|
+
"docs": {
|
|
110
|
+
"tags": [],
|
|
111
|
+
"text": "Dispatched when a change is made to the editor"
|
|
112
|
+
},
|
|
113
|
+
"complexType": {
|
|
114
|
+
"original": "{ html: string }",
|
|
115
|
+
"resolved": "{ html: string; }",
|
|
116
|
+
"references": {}
|
|
117
|
+
}
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
static get elementRef() { return "host"; }
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=prosemirror-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prosemirror-adapter.js","sourceRoot":"","sources":["../../../src/components/text-editor/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;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAA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,EAAE,IAAoB;SACpC,CAAC;OACL,CAAC;MACF,mBAAmB,EAAE,CAAC,WAAW,EAAE,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEhC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;MAC/C,CAAC;KACJ,CACJ,CAAC;IAEF,IAAI,IAAI,CAAC,KAAK,EAAE;MACZ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;KAC7C;EACL,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASJ","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 { MenuElement, MenuItem } from 'prosemirror-menu';\nimport { buildFullMenu } from './menu/full-menu';\nimport { getFilteredMenu } from './menu/menu-filter';\n\n/**\n * The ProseMirror adapter offers a rich text editing experience with markdown support,\n * in the sense that you can easily type markdown syntax and see the rendered\n * result as rich text in real-time. For instance, you can type `# Hello, world!`\n * and see it directly turning to a heading 1 (an `<h1>` HTML element).\n *\n * Naturally, you can use standard keyboard hotkeys such as <kbd>Ctrl</kbd> + <kbd>B</kbd>\n * to toggle bold text, <kbd>Ctrl</kbd> + <kbd>I</kbd> to toggle italic text, and so on.\n *\n * @exampleComponent limel-example-prosemirror-adapter-basic\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 value of the editor\n */\n @Prop()\n public value: { html: string };\n\n @Element()\n private host: HTMLLimelTextEditorElement;\n\n @State()\n private view: EditorView;\n\n /**\n * Dispatched when a change is made to the editor\n */\n @Event()\n private change: EventEmitter<{ html: string }>;\n\n public componentWillLoad() {}\n\n public render() {\n return <div id=\"editor\" />;\n }\n\n public componentDidLoad() {\n const mySchema = new Schema({\n nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),\n marks: schema.spec.marks,\n });\n\n const menu: MenuElement[][] = buildFullMenu(mySchema)\n .map((items) => getFilteredMenu(items, undefined))\n .filter((items) => items.length);\n\n this.view = new EditorView(\n this.host.shadowRoot.querySelector('#editor'),\n {\n state: EditorState.create({\n doc: DOMParser.fromSchema(mySchema).parse(\n this.host.shadowRoot.querySelector('#editor'),\n ),\n plugins: exampleSetup({\n schema: mySchema,\n menuContent: menu as MenuItem[][],\n }),\n }),\n dispatchTransaction: (transaction) => {\n const newState = this.view.state.apply(transaction);\n this.view.updateState(newState);\n\n this.change.emit({ html: this.getHTML() });\n },\n },\n );\n\n if (this.value) {\n this.view.dom.innerHTML = this.value.html;\n }\n }\n\n private getHTML = (): string => {\n if (this.view.dom.textContent === '') {\n return '';\n } else {\n return this.view.dom.innerHTML;\n }\n };\n}\n"]}
|