@exmg/exm-markdown-editor 1.1.10 → 1.1.12

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.
@@ -48,9 +48,9 @@ export declare class MarkdownEditorElementBase extends MarkdownBaseClass {
48
48
  toolbarIcons?: ToolbarIcons;
49
49
  markedExtension?: TokenizerAndRendererExtension[];
50
50
  required: boolean;
51
+ supportingText: string;
51
52
  editorElement?: HTMLDivElement;
52
53
  previewElement?: Element | null;
53
- height: number;
54
54
  preview: boolean;
55
55
  editorConfiguration: EditorConfiguration;
56
56
  editorActions: MarkdownActions;
@@ -1,6 +1,5 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { html, nothing } from 'lit';
3
- import { styleMap } from 'lit/directives/style-map.js';
4
3
  import { query, property, state } from 'lit/decorators.js';
5
4
  import { defaultConfiguration } from './utils/configurations.js';
6
5
  import { ExmgElement, observer } from '@exmg/lit-base';
@@ -12,6 +11,7 @@ import { toolbarIcons } from './icons.js';
12
11
  import { MardownEditorValidator } from './validator/exm-markdown-editor-validator.js';
13
12
  import { createValidator, getValidityAnchor, mixinConstraintValidation, } from '@material/web/labs/behaviors/constraint-validation.js';
14
13
  import './exm-markdown-editor-toolbar.js';
14
+ import { classMap } from 'lit/directives/class-map.js';
15
15
  const MarkdownBaseClass = mixinConstraintValidation(mixinFormAssociated(mixinElementInternals(ExmgElement)));
16
16
  /**
17
17
  * Markdown editor element.
@@ -53,7 +53,7 @@ export class MarkdownEditorElementBase extends MarkdownBaseClass {
53
53
  this.toolbarActions = toolbarActions;
54
54
  this.toolbarIcons = toolbarIcons;
55
55
  this.required = false;
56
- this.height = 400;
56
+ this.supportingText = '';
57
57
  this.preview = true;
58
58
  this.editorConfiguration = defaultConfiguration;
59
59
  this.editorActions = markdownActions;
@@ -94,10 +94,7 @@ export class MarkdownEditorElementBase extends MarkdownBaseClass {
94
94
  /* Height */
95
95
  if (this.previewElement.hasAttribute('slot')) {
96
96
  (_a = this.shadowRoot.querySelector('#preview')) === null || _a === void 0 ? void 0 : _a.remove();
97
- this.previewElement.setAttribute('style', `height: ${this.height}px;`);
98
97
  }
99
- this.heightStyleMap = styleMap({ height: `${this.height}px` });
100
- this.codeMirrorEditor.getWrapperElement().style.height = `${this.height}px`;
101
98
  /** Blur global handling */
102
99
  this.blurHandlerBinding = this.handleBlur.bind(this);
103
100
  this.addEventListener('blur', this.handleBlur);
@@ -180,29 +177,25 @@ export class MarkdownEditorElementBase extends MarkdownBaseClass {
180
177
  this.preview = false;
181
178
  }
182
179
  render() {
180
+ const containerClasses = { 'has-label': !!this.label, 'preview-mode': this.preview };
181
+ const labelClasses = { 'not-empty': !!this.value, 'preview-mode': this.preview };
183
182
  return html `
184
- <div
185
- id="markdowdEditorContainer"
186
- class="container"
187
- @click=${this.disablePreview}
188
- style=${this.heightStyleMap}
189
- ?label=${this.label}
190
- ?preview=${this.preview}
191
- >
183
+ <div id="markdownEditorContainer" class="container ${classMap(containerClasses)}" @click=${this.disablePreview}>
184
+ <div class="background"></div>
185
+ <div class="state-layer"></div>
192
186
  ${this.label
193
- ? html `<label ?preview=${this.preview} for="markdowdEditorContainer">${this.label}</label>`
187
+ ? html `<label class="${classMap(labelClasses)}" for="markdownEditorContainer">${this.label}</label>`
194
188
  : nothing}
195
189
  <exm-markdown-editor-toolbar
196
- ?label=${this.label}
197
- ?preview=${this.preview}
198
190
  ?upload=${this.upload}
199
191
  @action=${this.handleAction}
200
192
  .actions=${this.toolbarActions || []}
201
193
  .icons=${this.toolbarIcons || []}
202
194
  ></exm-markdown-editor-toolbar>
203
- <div id="editor" ?preview=${this.preview} style=${this.heightStyleMap}></div>
204
- <div id="preview" ?preview=${this.preview} style=${this.heightStyleMap}></div>
205
- <slot name="preview" ?preview=${this.preview}></slot>
195
+ <div id="editor" class="editor"></div>
196
+ <div id="preview"></div>
197
+ <slot name="preview"></slot>
198
+ ${this.supportingText ? html `<div class="supporting-text">${this.supportingText}</div>` : nothing}
206
199
  </div>
207
200
  `;
208
201
  }
@@ -231,15 +224,15 @@ __decorate([
231
224
  __decorate([
232
225
  property({ type: Boolean, reflect: true })
233
226
  ], MarkdownEditorElementBase.prototype, "required", void 0);
227
+ __decorate([
228
+ property({ type: String, attribute: 'supporting-text' })
229
+ ], MarkdownEditorElementBase.prototype, "supportingText", void 0);
234
230
  __decorate([
235
231
  query('#editor')
236
232
  ], MarkdownEditorElementBase.prototype, "editorElement", void 0);
237
233
  __decorate([
238
234
  state()
239
235
  ], MarkdownEditorElementBase.prototype, "previewElement", void 0);
240
- __decorate([
241
- property({ type: Number })
242
- ], MarkdownEditorElementBase.prototype, "height", void 0);
243
236
  __decorate([
244
237
  state(),
245
238
  observer(function (preview) {
@@ -5,18 +5,18 @@ export const style = css `
5
5
  overflow: hidden;
6
6
  --editor-border-color: var(--exm-markdown-editor-border-color, var(--md-sys-color-on-surface-variant));
7
7
  --editor-border-color-focus: var(--exm-markdown-editor-border-color-focus, var(--md-sys-color-primary));
8
- --editor-background-color: var(--exm-markdown-editor-background-color, var(--md-sys-color-surface-container-high));
8
+ --editor-background-color: var(
9
+ --exm-markdown-editor-background-color,
10
+ var(--md-sys-color-surface-container-highest)
11
+ );
9
12
  --editor-code-background-color: var(
10
13
  --exm-markdown-editor-code-background-color,
11
- var(--md-sys-color-surface-container-high)
12
- );
13
- --editor-background-focus-color: var(
14
- --exm-markdown-editor-background-focus-color,
15
- var(--md-sys-color-surface-container-high)
14
+ var(--md-sys-color-surface-container-highest)
16
15
  );
16
+ --editor-background-focus-color: var(--exm-markdown-editor-background-focus-color, var(--md-sys-color-on-surface));
17
17
  --editor-code-background-focus-color: var(
18
18
  --exm-markdown-editor-code-background-focus-color,
19
- var(--md-sys-color-surface-container-highest)
19
+ var(--md-sys-color-on-surface)
20
20
  );
21
21
  --editor-label-focus-color: var(--exm-markdown-editor-label-focus-color, var(--md-sys-color-primary));
22
22
  --editor-label-color: var(--exm-markdown-editor-label-color, var(--md-sys-color-on-surface));
@@ -26,52 +26,60 @@ export const style = css `
26
26
  display: grid;
27
27
  position: relative;
28
28
  grid-template-columns: 100%;
29
- grid-template-rows: 0px 56px 1fr;
29
+ grid-template-rows: 0px 56px 1fr auto;
30
30
  transition: grid-template-rows 0.2s ease;
31
31
  border-top-right-radius: 4px;
32
- background-color: var(--editor-code-background-color, var(--md-sys-color-surface-container-high));
33
32
  border-top-left-radius: 4px;
33
+ overflow: hidden;
34
+ height: 100%;
34
35
  }
35
36
 
36
- .container[label] {
37
+ .container.has-label {
37
38
  grid-template-rows: 2rem 56px 1fr;
38
39
  }
39
40
 
40
- .container:hover {
41
- background-color: var(--editor-code-background-focus-color, var(--md-sys-color-surface-container-highest));
41
+ .background,
42
+ .state-layer {
43
+ grid-area: 1/1/4/2;
44
+ }
45
+
46
+ .background {
47
+ background-color: var(--editor-code-background-color, var(--md-sys-color-surface-container-highest));
48
+ border-bottom: 1px solid var(--editor-border-color-focus, var(--md-sys-color-primary));
42
49
  }
43
50
 
44
- .container::after {
51
+ .container:hover .state-layer {
52
+ background-color: var(--editor-code-background-focus-color, var(--md-sys-color-on-surface-variant));
53
+ opacity: 0.08;
54
+ }
55
+
56
+ .background::after {
45
57
  content: ' ';
46
58
  display: block;
47
59
  position: absolute;
48
60
  bottom: 0;
49
61
  width: 100%;
50
62
  height: 3px;
51
- background: var(--editor-border-color-focus, var(--md-sys-color-primary));
52
63
  }
53
64
 
54
- .container[preview] {
55
- background-color: var(--editor-background-color, var(--md-sys-color-surface-container-high));
56
- grid-template-rows: 0px 0.3rem 1fr;
65
+ .container.preview-mode {
66
+ grid-template-rows: 0px 0.3rem 1fr auto;
57
67
  }
58
68
 
59
- .container[preview][label] {
60
- grid-template-rows: 2rem 0.3rem 1fr;
69
+ .container.preview-mode.has-label {
70
+ grid-template-rows: 2rem 0.3rem 1fr auto;
61
71
  }
62
72
 
63
- .container[preview]:hover {
64
- background-color: var(--editor-code-background-focus-color, var(--md-sys-color-surface-container-highest));
73
+ .container.preview-mode:hover .state-layer {
65
74
  cursor: text;
66
75
  }
67
76
 
68
- .container[preview]::after {
69
- height: 1px;
70
- background: var(--editor-border-color, var(--md-sys-color-on-surface-variant));
77
+ label {
78
+ grid-area: 1/1/2/2;
71
79
  }
72
80
 
73
- label[for='markdowdEditorContainer'] {
74
- grid-row-start: 1;
81
+ label[for='markdownEditorContainer'],
82
+ label[for='markdownEditorContainer'].not-empty.preview-mode {
75
83
  padding: 0.5rem 0 0 1rem;
76
84
  font-size: 0.7rem;
77
85
  color: var(--editor-label-focus-color, var(--md-sys-color-primary));
@@ -79,7 +87,11 @@ export const style = css `
79
87
  transform: scale(1) translateY(0px);
80
88
  }
81
89
 
82
- label[for='markdowdEditorContainer'][preview] {
90
+ label[for='markdownEditorContainer'].not-empty.preview-mode {
91
+ color: var(--editor-label-color, var(--md-sys-color-on-surface));
92
+ }
93
+
94
+ label[for='markdownEditorContainer'].preview-mode {
83
95
  color: var(--editor-label-color, var(--md-sys-color-on-surface));
84
96
  padding-bottom: 1rem;
85
97
  transform: translateY(8px);
@@ -87,7 +99,7 @@ export const style = css `
87
99
  }
88
100
 
89
101
  exm-markdown-editor-toolbar {
90
- grid-row-start: 1;
102
+ grid-area: 2/1/3/2;
91
103
  visibility: visible;
92
104
  transition:
93
105
  visibility 0s,
@@ -95,40 +107,73 @@ export const style = css `
95
107
  opacity: 1;
96
108
  }
97
109
 
98
- exm-markdown-editor-toolbar[preview] {
110
+ .container.preview-mode exm-markdown-editor-toolbar {
99
111
  visibility: hidden;
100
112
  opacity: 0;
101
113
  }
102
114
 
103
- exm-markdown-editor-toolbar[label] {
104
- grid-row-start: 2;
115
+ .supporting-text {
116
+ grid-area: 4/1/5/2;
117
+
118
+ color: var(--md-filled-field-supporting-text-color, var(--md-sys-color-on-surface-variant, #49454f));
119
+ display: flex;
120
+ font-family: var(
121
+ --md-filled-field-supporting-text-font,
122
+ var(--md-sys-typescale-body-small-font, var(--md-ref-typeface-plain, Roboto))
123
+ );
124
+ font-size: var(--md-filled-field-supporting-text-size, var(--md-sys-typescale-body-small-size, 0.75rem));
125
+ line-height: var(
126
+ --md-filled-field-supporting-text-line-height,
127
+ var(--md-sys-typescale-body-small-line-height, 1rem)
128
+ );
129
+ font-weight: var(
130
+ --md-filled-field-supporting-text-weight,
131
+ var(--md-sys-typescale-body-small-weight, var(--md-ref-typeface-weight-regular, 400))
132
+ );
133
+ gap: 16px;
134
+ justify-content: space-between;
135
+ padding-inline-start: var(--md-filled-field-supporting-text-leading-space, 16px);
136
+ padding-inline-end: var(--md-filled-field-supporting-text-trailing-space, 16px);
137
+ padding-top: var(--md-filled-field-supporting-text-top-space, 4px);
105
138
  }
106
139
 
107
140
  #preview {
141
+ grid-area: 3/1/4/2;
108
142
  display: none;
109
- grid-row-start: 3;
143
+ position: relative;
110
144
  overflow: scroll;
111
145
  }
112
146
 
113
- #preview[preview] {
114
- display: block;
147
+ .preview-content {
148
+ height: 100%;
149
+ overflow: scroll;
115
150
  }
116
151
 
117
- #editor {
152
+ .container.preview-mode #preview {
118
153
  display: block;
119
- grid-row-start: 3;
120
154
  }
121
155
 
122
- #editor[preview] {
156
+ .editor {
157
+ grid-area: 3/1/4/2;
158
+ position: relative;
159
+ overflow: hidden;
160
+ }
161
+
162
+ .container.preview-mode .editor {
123
163
  display: none;
124
164
  }
125
165
 
166
+ .CodeMirror {
167
+ height: 100%;
168
+ overflow: scroll;
169
+ }
170
+
126
171
  slot[name='preview'] {
127
172
  display: none;
128
173
  grid-row-start: 3;
129
174
  }
130
175
 
131
- slot[name='preview'][preview] {
176
+ .container.preview-mode slot[name='preview'] {
132
177
  display: block;
133
178
  }
134
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-markdown-editor",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "36f7f6dd58a96ea7edda7af31b25e679555d79c4"
55
+ "gitHead": "1478e41cdcc8b109995cf78f8ccfadd7699c22aa"
56
56
  }