@ember-eui/core 8.0.43 → 8.0.45

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.
@@ -21,7 +21,7 @@ import { argOrDefaultDecorator } from '../helpers/arg-or-default.js';
21
21
  import classNames from '../helpers/class-names.js';
22
22
  import ResizeObserver from '../modifiers/resize-observer.js';
23
23
  import validatableControl from '../modifiers/validatable-control.js';
24
- import MarkdownActions from '../utils/markdown/markdown-actions.js';
24
+ import MarkdownActions, { insertText } from '../utils/markdown/markdown-actions.js';
25
25
  import { MODE_EDITING, MODE_VIEWING } from '../utils/markdown/markdown-modes.js';
26
26
  import { defaultParsingPlugins } from '../utils/markdown/plugins/markdown-default-plugins/parsing-plugins.js';
27
27
  import { defaultProcessingPlugins } from '../utils/markdown/plugins/markdown-default-plugins/processing-plugins.js';
@@ -32,8 +32,9 @@ import EuiMarkdownEditorDropZone from './eui-markdown-editor-drop-zone.js';
32
32
  import EuiMarkdownEditorTextArea from './eui-markdown-editor-text-area.js';
33
33
  import EuiMarkdownEditorToolbarComponent from './eui-markdown-editor-toolbar.js';
34
34
  import EuiMarkdownEditorToolbarComponent$1 from './eui-markdown-format.js';
35
+ import EuiModal from './eui-modal.js';
35
36
 
36
- var _dec, _dec2, _dec3, _dec4, _dec5, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14;
37
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15;
37
38
  let cached = macroCondition(dependencySatisfies('ember-source', '>= 4.1.0-alpha.0')) ? importSync('@glimmer/tracking').cached : importSync('ember-cached-decorator-polyfill').cached;
38
39
  const getCursorNode = (textareaRef, parsed) => {
39
40
  const {
@@ -70,6 +71,23 @@ const getCursorNodeModifier = modifier(function getCursorNodeModifier(textarea,
70
71
  textarea.removeEventListener('mouseup', fn);
71
72
  };
72
73
  });
74
+ function isNewLine(char) {
75
+ if (char == null) return true;
76
+ return !!char.match(/[\r\n]/);
77
+ }
78
+ function padWithNewlinesIfNeeded(textarea, text) {
79
+ const selectionStart = textarea.selectionStart;
80
+ const selectionEnd = textarea.selectionEnd;
81
+
82
+ // block parsing requires two leading new lines and none trailing, but we add an extra trailing line for readability
83
+ const isPrevNewLine = isNewLine(textarea.value[selectionStart - 1]);
84
+ const isPrevPrevNewLine = isNewLine(textarea.value[selectionStart - 2]);
85
+ const isNextNewLine = isNewLine(textarea.value[selectionEnd]);
86
+
87
+ // pad text with newlines as needed
88
+ text = `${isPrevNewLine ? '' : '\n'}${isPrevPrevNewLine ? '' : '\n'}${text}${isNextNewLine ? '' : '\n'}`;
89
+ return text;
90
+ }
73
91
  let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
74
92
  <div
75
93
  class={{classNames
@@ -89,6 +107,7 @@ let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
89
107
  @selectedNode={{this.selectedNode}}
90
108
  @markdownActions={{this.markdownActions}}
91
109
  @onClickPreview={{this.setViewMode}}
110
+ @openPluginEditor={{this.openPluginEditor}}
92
111
  @viewMode={{this.viewMode}}
93
112
  @uiPlugins={{this.toolbarPlugins}}
94
113
  {{didInsert this.setEditorToolbarRef}}
@@ -133,6 +152,17 @@ let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
133
152
  ...attributes
134
153
  />
135
154
  </EuiMarkdownEditorDropZone>
155
+ {{#if this.pluginEditorPlugin.editor}}
156
+ <EuiModal @onClose={{set this "pluginEditorPlugin" undefined}}>
157
+ {{#let (component this.pluginEditorPlugin.editor) as |Editor|}}
158
+ <Editor
159
+ @node={{this.selectedNode}}
160
+ @onCancel={{set this "pluginEditorPlugin" undefined}}
161
+ @onSave={{this.onEditorPluginSave}}
162
+ />
163
+ {{/let}}
164
+ </EuiModal>
165
+ {{/if}}
136
166
  </div>
137
167
  </div>
138
168
  `, {
@@ -153,7 +183,8 @@ let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
153
183
  getCursorNodeModifier,
154
184
  on,
155
185
  pick,
156
- validatableControl
186
+ validatableControl,
187
+ EuiModal
157
188
  })
158
189
  }), (_dec = argOrDefaultDecorator(defaultParsingPlugins), _dec2 = argOrDefaultDecorator(250), _dec3 = argOrDefaultDecorator(500), _dec4 = argOrDefaultDecorator(true), _dec5 = argOrDefaultDecorator(defaultProcessingPlugins), (_class = class EuiMarkdownEditorComponent extends Component {
159
190
  get toolbarPlugins() {
@@ -161,25 +192,58 @@ let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
161
192
  }
162
193
  constructor(owner, args) {
163
194
  super(owner, args);
195
+ _initializerDefineProperty(this, "pluginEditorPlugin", _descriptor, this);
164
196
  // Defaults
165
- _initializerDefineProperty(this, "parsingPluginList", _descriptor, this);
166
- _initializerDefineProperty(this, "height", _descriptor2, this);
167
- _initializerDefineProperty(this, "maxHeight", _descriptor3, this);
168
- _initializerDefineProperty(this, "autoExpandPreview", _descriptor4, this);
169
- _initializerDefineProperty(this, "processingPluginList", _descriptor5, this);
170
- _initializerDefineProperty(this, "selectedNode", _descriptor6, this);
171
- _initializerDefineProperty(this, "editorId", _descriptor7, this);
172
- _initializerDefineProperty(this, "viewMode", _descriptor8, this);
173
- _initializerDefineProperty(this, "textareaRef", _descriptor9, this);
174
- _initializerDefineProperty(this, "previewRef", _descriptor10, this);
175
- _initializerDefineProperty(this, "editorToolbarRef", _descriptor11, this);
176
- _initializerDefineProperty(this, "currentHeight", _descriptor12, this);
177
- _initializerDefineProperty(this, "editorFooterHeight", _descriptor13, this);
178
- _initializerDefineProperty(this, "editorToolbarHeight", _descriptor14, this);
197
+ _initializerDefineProperty(this, "parsingPluginList", _descriptor2, this);
198
+ _initializerDefineProperty(this, "height", _descriptor3, this);
199
+ _initializerDefineProperty(this, "maxHeight", _descriptor4, this);
200
+ _initializerDefineProperty(this, "autoExpandPreview", _descriptor5, this);
201
+ _initializerDefineProperty(this, "processingPluginList", _descriptor6, this);
202
+ _initializerDefineProperty(this, "selectedNode", _descriptor7, this);
203
+ _initializerDefineProperty(this, "editorId", _descriptor8, this);
204
+ _initializerDefineProperty(this, "viewMode", _descriptor9, this);
205
+ _initializerDefineProperty(this, "textareaRef", _descriptor10, this);
206
+ _initializerDefineProperty(this, "previewRef", _descriptor11, this);
207
+ _initializerDefineProperty(this, "editorToolbarRef", _descriptor12, this);
208
+ _initializerDefineProperty(this, "currentHeight", _descriptor13, this);
209
+ _initializerDefineProperty(this, "editorFooterHeight", _descriptor14, this);
210
+ _initializerDefineProperty(this, "editorToolbarHeight", _descriptor15, this);
179
211
  _defineProperty(this, "markdownActions", void 0);
180
- this.markdownActions = new MarkdownActions(this.editorId,
181
- // @ts-expect-error
182
- this.toolbarPlugins);
212
+ _defineProperty(this, "getCursorNode", () => {});
213
+ _defineProperty(this, "openPluginEditor", plugin => {
214
+ this.pluginEditorPlugin = plugin;
215
+ });
216
+ _defineProperty(this, "onEditorPluginSave", (markdown, config) => {
217
+ let {
218
+ selectedNode,
219
+ textareaRef
220
+ } = this;
221
+ if (this.pluginEditorPlugin && selectedNode &&
222
+ // @ts-expect-error
223
+ selectedNode.type === this.pluginEditorPlugin.name &&
224
+ // @ts-expect-error
225
+ selectedNode.position) {
226
+ // modifying an existing node
227
+ textareaRef.setSelectionRange(
228
+ // @ts-expect-error
229
+ selectedNode.position.start.offset,
230
+ // @ts-expect-error
231
+ selectedNode.position.end.offset);
232
+ } else {
233
+ // creating a new node
234
+ if (config.block) {
235
+ // inject newlines if needed
236
+ markdown = padWithNewlinesIfNeeded(textareaRef, markdown);
237
+ }
238
+ }
239
+ insertText(textareaRef, {
240
+ text: markdown,
241
+ selectionStart: undefined,
242
+ selectionEnd: undefined
243
+ });
244
+ this.pluginEditorPlugin = undefined;
245
+ });
246
+ this.markdownActions = new MarkdownActions(this.editorId, this.toolbarPlugins);
183
247
  this.currentHeight = this.height;
184
248
  }
185
249
  get previewHeight() {
@@ -294,88 +358,93 @@ let EuiMarkdownEditorComponent = setComponentTemplate(precompileTemplate(`
294
358
  setSelectedNode(node) {
295
359
  this.selectedNode = node;
296
360
  }
297
- }, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "parsingPluginList", [_dec], {
361
+ }, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "pluginEditorPlugin", [tracked], {
362
+ configurable: true,
363
+ enumerable: true,
364
+ writable: true,
365
+ initializer: null
366
+ }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "parsingPluginList", [_dec], {
298
367
  configurable: true,
299
368
  enumerable: true,
300
369
  writable: true,
301
370
  initializer: null
302
- }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "height", [_dec2], {
371
+ }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "height", [_dec2], {
303
372
  configurable: true,
304
373
  enumerable: true,
305
374
  writable: true,
306
375
  initializer: null
307
- }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "maxHeight", [_dec3], {
376
+ }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "maxHeight", [_dec3], {
308
377
  configurable: true,
309
378
  enumerable: true,
310
379
  writable: true,
311
380
  initializer: null
312
- }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "autoExpandPreview", [_dec4], {
381
+ }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "autoExpandPreview", [_dec4], {
313
382
  configurable: true,
314
383
  enumerable: true,
315
384
  writable: true,
316
385
  initializer: null
317
- }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "processingPluginList", [_dec5], {
386
+ }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "processingPluginList", [_dec5], {
318
387
  configurable: true,
319
388
  enumerable: true,
320
389
  writable: true,
321
390
  initializer: null
322
- }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "selectedNode", [tracked], {
391
+ }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "selectedNode", [tracked], {
323
392
  configurable: true,
324
393
  enumerable: true,
325
394
  writable: true,
326
395
  initializer: function () {
327
396
  return null;
328
397
  }
329
- }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "editorId", [tracked], {
398
+ }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "editorId", [tracked], {
330
399
  configurable: true,
331
400
  enumerable: true,
332
401
  writable: true,
333
402
  initializer: function () {
334
403
  return this.args.editorId ?? guidFor({});
335
404
  }
336
- }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "viewMode", [tracked], {
405
+ }), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "viewMode", [tracked], {
337
406
  configurable: true,
338
407
  enumerable: true,
339
408
  writable: true,
340
409
  initializer: function () {
341
410
  return this.args.initialViewMode || MODE_EDITING;
342
411
  }
343
- }), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "textareaRef", [tracked], {
412
+ }), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, "textareaRef", [tracked], {
344
413
  configurable: true,
345
414
  enumerable: true,
346
415
  writable: true,
347
416
  initializer: function () {
348
417
  return null;
349
418
  }
350
- }), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, "previewRef", [tracked], {
419
+ }), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, "previewRef", [tracked], {
351
420
  configurable: true,
352
421
  enumerable: true,
353
422
  writable: true,
354
423
  initializer: function () {
355
424
  return null;
356
425
  }
357
- }), _descriptor11 = _applyDecoratedDescriptor(_class.prototype, "editorToolbarRef", [tracked], {
426
+ }), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, "editorToolbarRef", [tracked], {
358
427
  configurable: true,
359
428
  enumerable: true,
360
429
  writable: true,
361
430
  initializer: function () {
362
431
  return null;
363
432
  }
364
- }), _descriptor12 = _applyDecoratedDescriptor(_class.prototype, "currentHeight", [tracked], {
433
+ }), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, "currentHeight", [tracked], {
365
434
  configurable: true,
366
435
  enumerable: true,
367
436
  writable: true,
368
437
  initializer: function () {
369
438
  return 250;
370
439
  }
371
- }), _descriptor13 = _applyDecoratedDescriptor(_class.prototype, "editorFooterHeight", [tracked], {
440
+ }), _descriptor14 = _applyDecoratedDescriptor(_class.prototype, "editorFooterHeight", [tracked], {
372
441
  configurable: true,
373
442
  enumerable: true,
374
443
  writable: true,
375
444
  initializer: function () {
376
445
  return 0;
377
446
  }
378
- }), _descriptor14 = _applyDecoratedDescriptor(_class.prototype, "editorToolbarHeight", [tracked], {
447
+ }), _descriptor15 = _applyDecoratedDescriptor(_class.prototype, "editorToolbarHeight", [tracked], {
379
448
  configurable: true,
380
449
  enumerable: true,
381
450
  writable: true,