@dile/editor 2.3.0 → 2.3.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/package.json +3 -3
- package/src/DileEditor.js +14 -2
- package/src/DileI18nMixin.js +7 -0
- package/src/dile-editor-image-dialog.js +3 -2
- package/src/dile-editor-link-dialog.js +4 -3
- package/src/dile-editor-markdown.js +6 -2
- package/src/dile-editor-toolbar-item.js +3 -2
- package/src/dile-editor-toolbar.js +16 -5
- package/src/i18n/en.js +8 -0
- package/src/i18n/es.js +8 -0
- package/src/prosemirror/menu-items.js +6 -6
- package/src/prosemirror/menu-plugin.js +2 -1
- package/src/translationService.js +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/editor",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Webcomponent to create a user editor interface, configured on various ways",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@dile/icons": "^2.1.0",
|
|
33
|
-
"@dile/ui": "^2.3.
|
|
33
|
+
"@dile/ui": "^2.3.1",
|
|
34
34
|
"lit": "^2.7.0 || ^3.0.0",
|
|
35
35
|
"prosemirror-commands": "^1.5.0",
|
|
36
36
|
"prosemirror-example-setup": "^1.2.1",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"prosemirror-state": "^1.4.2",
|
|
42
42
|
"prosemirror-view": "^1.30.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "ea951d488df2f6ae44dec2b4b4487549caca09e6"
|
|
45
45
|
}
|
package/src/DileEditor.js
CHANGED
|
@@ -5,8 +5,9 @@ import '@dile/ui/components/pages/pages.js';
|
|
|
5
5
|
import '@dile/ui/components/tabs/tabs.js';
|
|
6
6
|
import { messageStyles } from '@dile/ui/components/input/index.js';
|
|
7
7
|
import { defaultToolbarConfig } from './defaultToolbarConfig.js';
|
|
8
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
8
9
|
|
|
9
|
-
export class DileEditor extends DileEmmitChange(LitElement) {
|
|
10
|
+
export class DileEditor extends DileI18nMixin(DileEmmitChange(LitElement)) {
|
|
10
11
|
static styles = [
|
|
11
12
|
messageStyles,
|
|
12
13
|
css`
|
|
@@ -112,6 +113,11 @@ export class DileEditor extends DileEmmitChange(LitElement) {
|
|
|
112
113
|
max-width: 100%;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
.ProseMirror code {
|
|
117
|
+
background-color: #eee;
|
|
118
|
+
padding: 0.4rem;
|
|
119
|
+
}
|
|
120
|
+
|
|
115
121
|
dile-tabs {
|
|
116
122
|
margin-bottom: 0.3rem;
|
|
117
123
|
}
|
|
@@ -165,6 +171,8 @@ export class DileEditor extends DileEmmitChange(LitElement) {
|
|
|
165
171
|
|
|
166
172
|
/** Menu config */
|
|
167
173
|
_menuConfig: { type: Object },
|
|
174
|
+
|
|
175
|
+
/** Language config */
|
|
168
176
|
};
|
|
169
177
|
}
|
|
170
178
|
|
|
@@ -184,6 +192,9 @@ export class DileEditor extends DileEmmitChange(LitElement) {
|
|
|
184
192
|
if(changedProperties.has('value') && this.isValueExternalyUpdated) {
|
|
185
193
|
this.updateEditorContent(this.value);
|
|
186
194
|
}
|
|
195
|
+
if(changedProperties.has('value')) {
|
|
196
|
+
this.emmitChange();
|
|
197
|
+
}
|
|
187
198
|
}
|
|
188
199
|
|
|
189
200
|
firstUpdated() {
|
|
@@ -220,7 +231,7 @@ export class DileEditor extends DileEmmitChange(LitElement) {
|
|
|
220
231
|
attrForSelected="name"
|
|
221
232
|
@dile-selected-changed=${this.tabSelectedChange}
|
|
222
233
|
>
|
|
223
|
-
<dile-tab name="design"
|
|
234
|
+
<dile-tab name="design">${this.translations.design_view}</dile-tab>
|
|
224
235
|
<dile-tab name="markdown">Markdown</dile-tab>
|
|
225
236
|
</dile-tabs>
|
|
226
237
|
</nav>
|
|
@@ -239,6 +250,7 @@ export class DileEditor extends DileEmmitChange(LitElement) {
|
|
|
239
250
|
._menuConfig=${this._menuConfig}
|
|
240
251
|
@dile-editor-markdown-initialized=${this.setInitialized}
|
|
241
252
|
.addicionalCommands=${this.addicionalCommands}
|
|
253
|
+
language="${this.language}"
|
|
242
254
|
></dile-editor-markdown>
|
|
243
255
|
</section>
|
|
244
256
|
</dile-pages>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DileI18nMixin as OriginalDileI18nMixin } from '@dile/ui/mixins/i18n/DileI18nMixin.js';
|
|
2
|
+
import { translationService } from './translationService';
|
|
3
|
+
|
|
4
|
+
export const DileI18nMixin = (superclass) =>
|
|
5
|
+
class extends OriginalDileI18nMixin(translationService)(superclass) {
|
|
6
|
+
|
|
7
|
+
};
|
|
@@ -3,8 +3,9 @@ import { NodeSelection } from "prosemirror-state"
|
|
|
3
3
|
import { schema } from "prosemirror-markdown";
|
|
4
4
|
import '@dile/ui/components/menu-overlay/menu-overlay.js';
|
|
5
5
|
import '@dile/ui/components/button/button.js';
|
|
6
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
6
7
|
|
|
7
|
-
export class DileEditorImageDialog extends LitElement {
|
|
8
|
+
export class DileEditorImageDialog extends DileI18nMixin(LitElement) {
|
|
8
9
|
static styles = [
|
|
9
10
|
css`
|
|
10
11
|
:host {
|
|
@@ -34,7 +35,7 @@ export class DileEditorImageDialog extends LitElement {
|
|
|
34
35
|
<div>Alt:</div>
|
|
35
36
|
<div><input type="text" id="alt"></div>
|
|
36
37
|
</section>
|
|
37
|
-
<dile-button @click=${this.accept}
|
|
38
|
+
<dile-button @click=${this.accept}>${this.translations.accept}</dile-button> <dile-button @click=${this.close}>${this.translations.cancel}</dile-button>
|
|
38
39
|
</div>
|
|
39
40
|
</dile-menu-overlay>
|
|
40
41
|
`;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit';
|
|
2
2
|
import '@dile/ui/components/menu-overlay/menu-overlay.js';
|
|
3
3
|
import '@dile/ui/components/button/button.js';
|
|
4
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
4
5
|
|
|
5
|
-
export class DileEditorLinkDialog extends LitElement {
|
|
6
|
+
export class DileEditorLinkDialog extends DileI18nMixin(LitElement) {
|
|
6
7
|
static styles = [
|
|
7
8
|
css`
|
|
8
9
|
:host {
|
|
@@ -33,10 +34,10 @@ export class DileEditorLinkDialog extends LitElement {
|
|
|
33
34
|
<section class="grid">
|
|
34
35
|
<div>URL:</div>
|
|
35
36
|
<div><input type="text" id="url"></div>
|
|
36
|
-
<div
|
|
37
|
+
<div>${this.translations.title}:</div>
|
|
37
38
|
<div><input type="text" id="title"></div>
|
|
38
39
|
</section>
|
|
39
|
-
<dile-button @click=${this.accept}
|
|
40
|
+
<dile-button @click=${this.accept}>${this.translations.accept}</dile-button> <dile-button @click=${this.close}>${this.translations.cancel}</dile-button>
|
|
40
41
|
</div>
|
|
41
42
|
</dile-menu-overlay>
|
|
42
43
|
`;
|
|
@@ -12,11 +12,15 @@ import { history } from "prosemirror-history";
|
|
|
12
12
|
import { buildKeymap } from "prosemirror-example-setup";
|
|
13
13
|
import './dile-editor-toolbar.js';
|
|
14
14
|
import { menuPlugin } from './prosemirror/menu-plugin.js';
|
|
15
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
15
16
|
|
|
16
|
-
export class DileEditorMarkdown extends LitElement {
|
|
17
|
+
export class DileEditorMarkdown extends DileI18nMixin(LitElement) {
|
|
17
18
|
|
|
18
19
|
static styles = [
|
|
19
20
|
css`
|
|
21
|
+
* {
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
}
|
|
20
24
|
:host {
|
|
21
25
|
display: block;
|
|
22
26
|
}
|
|
@@ -67,7 +71,7 @@ export class DileEditorMarkdown extends LitElement {
|
|
|
67
71
|
history(),
|
|
68
72
|
keymap(buildKeymap(schema)),
|
|
69
73
|
keymap(baseKeymap),
|
|
70
|
-
menuPlugin(this._menuConfig, this.addicionalCommands),
|
|
74
|
+
menuPlugin(this._menuConfig, this.addicionalCommands, this.language),
|
|
71
75
|
]
|
|
72
76
|
})
|
|
73
77
|
}
|
|
@@ -2,8 +2,9 @@ import { LitElement, html, css } from 'lit';
|
|
|
2
2
|
import '@dile/ui/components/icon/icon.js';
|
|
3
3
|
import './dile-editor-link-dialog.js';
|
|
4
4
|
import './dile-editor-image-dialog.js';
|
|
5
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
5
6
|
|
|
6
|
-
export class DileEditorToolbarItem extends LitElement {
|
|
7
|
+
export class DileEditorToolbarItem extends DileI18nMixin(LitElement) {
|
|
7
8
|
static styles = [
|
|
8
9
|
css`
|
|
9
10
|
:host {
|
|
@@ -37,7 +38,7 @@ export class DileEditorToolbarItem extends LitElement {
|
|
|
37
38
|
.icon=${this.item.icon}
|
|
38
39
|
@click=${this.doCommand}
|
|
39
40
|
></dile-icon>
|
|
40
|
-
${this.item.dialogTemplate ? this.item.dialogTemplate : ''}
|
|
41
|
+
${this.item.dialogTemplate ? this.item.dialogTemplate(this.language) : ''}
|
|
41
42
|
`;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -5,8 +5,9 @@ import '@dile/ui/components/select/select.js';
|
|
|
5
5
|
import { getToolbarItems, getUndoItems, getBlockItems } from './prosemirror/menu-items.js';
|
|
6
6
|
import { linkCommand } from './prosemirror/markdown-commands.js';
|
|
7
7
|
import { schema } from "prosemirror-markdown";
|
|
8
|
+
import { DileI18nMixin } from './DileI18nMixin.js';
|
|
8
9
|
|
|
9
|
-
export class DileEditorToolbar extends LitElement {
|
|
10
|
+
export class DileEditorToolbar extends DileI18nMixin(LitElement) {
|
|
10
11
|
static styles = [
|
|
11
12
|
css`
|
|
12
13
|
:host {
|
|
@@ -25,6 +26,7 @@ export class DileEditorToolbar extends LitElement {
|
|
|
25
26
|
margin-bottom: 0;
|
|
26
27
|
--dile-input-border-width: 0;
|
|
27
28
|
--dile-input-padding: 3px;
|
|
29
|
+
--dile-input-background-color: var(--dile-editor-toolbar-block-background-color, #eee);
|
|
28
30
|
}
|
|
29
31
|
.marks, .blocks {
|
|
30
32
|
display: flex;
|
|
@@ -58,8 +60,11 @@ export class DileEditorToolbar extends LitElement {
|
|
|
58
60
|
this.addicionalCommands = {}
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
get blockselect() {
|
|
64
|
+
return this.shadowRoot.getElementById('blockselect');
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
firstUpdated() {
|
|
62
|
-
this.blockselect = this.shadowRoot.getElementById('blockselect');
|
|
63
68
|
this.toolbarItems = getToolbarItems(this.menuConfig, this.addicionalCommands.toolbarItems || []);
|
|
64
69
|
this.undoItems = getUndoItems(this.menuConfig, this.addicionalCommands.undoItems || []);
|
|
65
70
|
this.blockItems = getBlockItems(this.menuConfig, this.addicionalCommands.blockItems || []);
|
|
@@ -92,6 +97,7 @@ export class DileEditorToolbar extends LitElement {
|
|
|
92
97
|
@accept-link-dialog=${this.doLinkCommand}
|
|
93
98
|
@accept-image-dialog=${this.doImageCommand}
|
|
94
99
|
.editorView=${this.editorView}
|
|
100
|
+
language="${this.language}"
|
|
95
101
|
></dile-editor-toolbar-item>
|
|
96
102
|
`
|
|
97
103
|
: ''
|
|
@@ -115,8 +121,9 @@ export class DileEditorToolbar extends LitElement {
|
|
|
115
121
|
>
|
|
116
122
|
<select slot="select">
|
|
117
123
|
${this.blockItems.map(item => html`
|
|
118
|
-
<option value="${item.commandName}">${item.commandName}</option>
|
|
119
|
-
|
|
124
|
+
<option value="${item.commandName}">${this.translations[item.commandName] || item.commandName}</option>
|
|
125
|
+
`)}
|
|
126
|
+
<option value="-"></option>
|
|
120
127
|
</select>
|
|
121
128
|
</dile-select>
|
|
122
129
|
</div>
|
|
@@ -151,7 +158,11 @@ export class DileEditorToolbar extends LitElement {
|
|
|
151
158
|
this.toolbarItems = this.computeActive(this.toolbarItems);
|
|
152
159
|
this.undoItems = this.computeActive(this.undoItems);
|
|
153
160
|
let currentBlock = this.blockItems.find(item => !item.command(this.editorView.state, null, this.editorView))
|
|
154
|
-
|
|
161
|
+
if(currentBlock) {
|
|
162
|
+
this.blockselect?.quietChange(currentBlock.commandName);
|
|
163
|
+
} else {
|
|
164
|
+
this.blockselect?.quietChange('-');
|
|
165
|
+
}
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
computeActive(items) {
|
package/src/i18n/en.js
ADDED
package/src/i18n/es.js
ADDED
|
@@ -47,7 +47,7 @@ export const getToolbarItems = (config, additionalItems) => [
|
|
|
47
47
|
command: linkCommand,
|
|
48
48
|
commandName: 'link',
|
|
49
49
|
icon: insertLinkIcon,
|
|
50
|
-
dialogTemplate: html`<dile-editor-link-dialog id="linkDialog"></dile-editor-link-dialog> `,
|
|
50
|
+
dialogTemplate:(language) => html`<dile-editor-link-dialog language="${language}" id="linkDialog"></dile-editor-link-dialog> `,
|
|
51
51
|
}),
|
|
52
52
|
new ToolbarRemoveLink({
|
|
53
53
|
commandName: 'removeLink',
|
|
@@ -57,7 +57,7 @@ export const getToolbarItems = (config, additionalItems) => [
|
|
|
57
57
|
command: linkCommand,
|
|
58
58
|
commandName: 'image',
|
|
59
59
|
icon: imageIcon,
|
|
60
|
-
dialogTemplate: html`<dile-editor-image-dialog id="imageDialog"></dile-editor-image-dialog> `,
|
|
60
|
+
dialogTemplate:(language) => html`<dile-editor-image-dialog language="${language}" id="imageDialog"></dile-editor-image-dialog> `,
|
|
61
61
|
}),
|
|
62
62
|
new ToolbarItem({
|
|
63
63
|
command: setUnorderedListCommand,
|
|
@@ -92,14 +92,14 @@ export const getUndoItems = (config, additionalItems) => [
|
|
|
92
92
|
].filter(item => config[item.commandName] !== false);
|
|
93
93
|
|
|
94
94
|
export const getBlockItems = (config, additionalItems) => [
|
|
95
|
-
{
|
|
96
|
-
command: setCodeCommand,
|
|
97
|
-
commandName: 'code',
|
|
98
|
-
},
|
|
99
95
|
{
|
|
100
96
|
command: setParagraphCommand,
|
|
101
97
|
commandName: 'paragraph',
|
|
102
98
|
},
|
|
99
|
+
{
|
|
100
|
+
command: setCodeCommand,
|
|
101
|
+
commandName: 'code',
|
|
102
|
+
},
|
|
103
103
|
{
|
|
104
104
|
command: headingCommandCreator(1),
|
|
105
105
|
commandName: 'h1',
|
|
@@ -2,7 +2,7 @@ import { Plugin } from "prosemirror-state";
|
|
|
2
2
|
|
|
3
3
|
const toolbarElement = 'dile-editor-toolbar';
|
|
4
4
|
|
|
5
|
-
export const menuPlugin = (menuConfig, addicionalCommands) => new Plugin({
|
|
5
|
+
export const menuPlugin = (menuConfig, addicionalCommands, language) => new Plugin({
|
|
6
6
|
view(editorView) {
|
|
7
7
|
let toolbar;
|
|
8
8
|
if (!editorView.dom.parentElement.querySelector(toolbarElement)) {
|
|
@@ -10,6 +10,7 @@ export const menuPlugin = (menuConfig, addicionalCommands) => new Plugin({
|
|
|
10
10
|
toolbar.menuConfig = menuConfig;
|
|
11
11
|
toolbar.editorView = editorView;
|
|
12
12
|
toolbar.addicionalCommands = addicionalCommands;
|
|
13
|
+
toolbar.language = language;
|
|
13
14
|
editorView.dom.parentNode.insertBefore(toolbar, editorView.dom);
|
|
14
15
|
} else {
|
|
15
16
|
toolbar = editorView.dom.parentElement.querySelector(toolbarElement);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {TranslationService as OriginalTranslationService} from '@dile/ui/mixins/i18n/TranslationService.js';
|
|
2
|
+
|
|
3
|
+
class TranslationService extends OriginalTranslationService {
|
|
4
|
+
async importLanguage(language) {
|
|
5
|
+
const module = await import(`./i18n/${language}.js`);
|
|
6
|
+
return module;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async importFallback() {
|
|
10
|
+
const defaultModule = await import('./i18n/en.js');
|
|
11
|
+
return defaultModule;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const translationService = new TranslationService();
|