@ember-eui/core 7.0.5 → 7.0.6

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.
@@ -1,14 +1,6 @@
1
1
  {{! This hbs was inspired by https://github.com/ampatspell/ember-cli-remark-static/blob/v3.0.5/addon/components/remark.hbs }}
2
- <EuiText
3
- class="euiMarkdownFormat"
4
- @color={{@color}}
5
- @grow={{@grow}}
6
- @size={{@textSize}}
7
- @textAlign={{@textAlign}}
8
- {{did-insert this.setRootNode}}
9
- {{did-update this.update @value}}
10
- ...attributes
11
- >
2
+ {{#if this.result}}
3
+ {{this.result.element}}
12
4
  {{#each this.result.components as |CompNode|}}
13
5
  {{#in-element CompNode.element}}
14
6
  {{#let
@@ -22,4 +14,4 @@
22
14
  {{/let}}
23
15
  {{/in-element}}
24
16
  {{/each}}
25
- </EuiText>
17
+ {{/if}}
@@ -3,12 +3,11 @@ import {
3
3
  defaultParsingPlugins,
4
4
  defaultProcessingPlugins
5
5
  } from '../../utils/markdown/plugins/markdown-default-plugins';
6
- import { cached, tracked } from '@glimmer/tracking';
6
+ import { cached } from '@glimmer/tracking';
7
7
  import unified, { Processor } from 'unified';
8
- import { DynamicComponent, toDOM } from '../../utils/markdown/plugins/to-dom';
8
+ import { toDOM } from '../../utils/markdown/plugins/to-dom';
9
9
  import type { RehypeNode } from '../../utils/markdown/markdown-types';
10
10
  import type EuiMarkdownEditorComponent from '../eui-markdown-editor';
11
-
12
11
  export interface EuiMarkdownEditorToolbarArgs {
13
12
  parsingPluginList?: typeof defaultParsingPlugins;
14
13
  processingPluginList?: typeof defaultProcessingPlugins;
@@ -17,16 +16,6 @@ export interface EuiMarkdownEditorToolbarArgs {
17
16
  }
18
17
 
19
18
  export default class EuiMarkdownEditorToolbarComponent extends Component<EuiMarkdownEditorToolbarArgs> {
20
- @tracked rootNode?: HTMLDivElement;
21
- @tracked result?:
22
- | {
23
- element: Node | undefined;
24
- components: DynamicComponent[];
25
- }
26
- | string;
27
-
28
- _lastValue?: string;
29
-
30
19
  get parsingPluginList() {
31
20
  return this.args.parsingPluginList || defaultParsingPlugins;
32
21
  }
@@ -35,11 +24,6 @@ export default class EuiMarkdownEditorToolbarComponent extends Component<EuiMark
35
24
  return this.args.processingPluginList || defaultProcessingPlugins;
36
25
  }
37
26
 
38
- setRootNode = (node: HTMLDivElement) => {
39
- this.rootNode = node;
40
- this.update();
41
- };
42
-
43
27
  @cached
44
28
  get processor() {
45
29
  const Compiler = (tree: any) => {
@@ -56,19 +40,16 @@ export default class EuiMarkdownEditorToolbarComponent extends Component<EuiMark
56
40
  .use(identityCompiler);
57
41
  }
58
42
 
59
- update = () => {
60
- if (this.rootNode) {
61
- if (this.args.value === this._lastValue) return;
62
- this._lastValue = this.args.value;
63
- this.rootNode.innerHTML = '';
64
- try {
65
- const processed = this.processor.processSync(this.args.value);
66
- this.result = toDOM(processed.result as RehypeNode, this.rootNode);
67
- //eslint-disable-next-line
68
- } catch (e) {
69
- this.result = this.args.value;
70
- }
43
+ @cached
44
+ get result() {
45
+ try {
46
+ const processed = this.processor.processSync(this.args.value);
47
+ return toDOM(processed.result as RehypeNode, {
48
+ rootClasses: ['euiMarkdownFormat', 'euiText', 'euiText--medium']
49
+ });
50
+ //eslint-disable-next-line
51
+ } catch (e) {
52
+ return this.args.value;
71
53
  }
72
- this.result = this.args.value;
73
- };
54
+ }
74
55
  }
@@ -13,7 +13,12 @@ const createDocument = () => {
13
13
 
14
14
  export interface DynamicComponent {}
15
15
 
16
- export const toDOM = (tree: RehypeNode, rootNode?: HTMLDivElement) => {
16
+ export const toDOM = (
17
+ tree: RehypeNode,
18
+ options?: {
19
+ rootClasses?: string[];
20
+ }
21
+ ) => {
17
22
  let document = createDocument();
18
23
  let components: DynamicComponent[] = [];
19
24
 
@@ -30,14 +35,14 @@ export const toDOM = (tree: RehypeNode, rootNode?: HTMLDivElement) => {
30
35
  const createElement = (
31
36
  name: string,
32
37
  node: RehypeNode,
33
- className?: string
38
+ classesToAdd?: string[] | string
34
39
  ) => {
35
40
  let element = document.createElement(name);
36
41
  let properties = node.properties;
37
- let classNames = [];
42
+ let finalClassNames = [];
38
43
  if (properties) {
39
44
  if (properties.className) {
40
- classNames.push(...(properties.className as string[]));
45
+ finalClassNames.push(...(properties.className as string[]));
41
46
  }
42
47
  for (let key in properties) {
43
48
  if (attributes.includes(key)) {
@@ -51,12 +56,15 @@ export const toDOM = (tree: RehypeNode, rootNode?: HTMLDivElement) => {
51
56
  }
52
57
  }
53
58
  }
54
- if (className) {
55
- classNames.push(className);
56
- }
57
- if (classNames.length) {
58
- element.setAttribute('class', classNames.join(' '));
59
+ if (classesToAdd) {
60
+ if (Array.isArray(classesToAdd)) {
61
+ finalClassNames.push(...classesToAdd);
62
+ } else {
63
+ finalClassNames.push(classesToAdd);
64
+ }
59
65
  }
66
+
67
+ element.classList.add(...finalClassNames);
60
68
  return element;
61
69
  };
62
70
 
@@ -64,10 +72,11 @@ export const toDOM = (tree: RehypeNode, rootNode?: HTMLDivElement) => {
64
72
  if (node) {
65
73
  let { type } = node;
66
74
  if (type === 'root') {
67
- if (rootNode) {
68
- return toElements(rootNode, node.children);
69
- }
70
- let element = createElement('div', node, 'root');
75
+ let element = createElement(
76
+ 'div',
77
+ node,
78
+ options?.rootClasses || ['root']
79
+ );
71
80
  return toElements(element, node.children);
72
81
  } else if (type === 'element') {
73
82
  let element = createElement(node.tagName, node);
@@ -76,7 +85,9 @@ export const toDOM = (tree: RehypeNode, rootNode?: HTMLDivElement) => {
76
85
  return document.createTextNode(node.value);
77
86
  } else if (type === 'component') {
78
87
  let { inline } = node.properties;
79
- let element = createElement(inline ? 'span' : 'div', node, 'component');
88
+ let element = createElement(inline ? 'span' : 'div', node, [
89
+ 'component'
90
+ ]);
80
91
  let { _children, ...properties } = node.properties;
81
92
  let content = toElements(document.createElement('span'), node.children);
82
93
  components.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-eui/core",
3
- "version": "7.0.5",
3
+ "version": "7.0.6",
4
4
  "description": "Ember Components for Elastic UI",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -186,5 +186,5 @@
186
186
  "volta": {
187
187
  "extends": "../../package.json"
188
188
  },
189
- "gitHead": "6139d68366c00ad82afcf493aada44ef4d16240f"
189
+ "gitHead": "dd0f213c42296e63e079c7e13331bf1005dd3566"
190
190
  }