@acorex/cdk 22.1.7 → 22.2.0-next.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.
Files changed (81) hide show
  1. package/auto-follow-scroll/README.md +9 -0
  2. package/fesm2022/acorex-cdk-accordion.mjs +19 -19
  3. package/fesm2022/acorex-cdk-accordion.mjs.map +1 -1
  4. package/fesm2022/acorex-cdk-auto-follow-scroll.mjs +187 -0
  5. package/fesm2022/acorex-cdk-auto-follow-scroll.mjs.map +1 -0
  6. package/fesm2022/acorex-cdk-carousel.mjs +25 -7
  7. package/fesm2022/acorex-cdk-carousel.mjs.map +1 -1
  8. package/fesm2022/acorex-cdk-clipboard.mjs +6 -6
  9. package/fesm2022/acorex-cdk-clipboard.mjs.map +1 -1
  10. package/fesm2022/acorex-cdk-common.mjs +146 -92
  11. package/fesm2022/acorex-cdk-common.mjs.map +1 -1
  12. package/fesm2022/acorex-cdk-dom.mjs +3 -3
  13. package/fesm2022/acorex-cdk-dom.mjs.map +1 -1
  14. package/fesm2022/acorex-cdk-drag-drop.mjs +161 -69
  15. package/fesm2022/acorex-cdk-drag-drop.mjs.map +1 -1
  16. package/fesm2022/acorex-cdk-drawer.mjs +11 -11
  17. package/fesm2022/acorex-cdk-drawer.mjs.map +1 -1
  18. package/fesm2022/acorex-cdk-focus-trap.mjs +3 -3
  19. package/fesm2022/acorex-cdk-focus-trap.mjs.map +1 -1
  20. package/fesm2022/acorex-cdk-full-screen.mjs +26 -147
  21. package/fesm2022/acorex-cdk-full-screen.mjs.map +1 -1
  22. package/fesm2022/acorex-cdk-gesture.mjs +30 -4
  23. package/fesm2022/acorex-cdk-gesture.mjs.map +1 -1
  24. package/fesm2022/acorex-cdk-highlight.mjs +8 -78
  25. package/fesm2022/acorex-cdk-highlight.mjs.map +1 -1
  26. package/fesm2022/acorex-cdk-horizontal-scroll.mjs +27 -10
  27. package/fesm2022/acorex-cdk-horizontal-scroll.mjs.map +1 -1
  28. package/fesm2022/acorex-cdk-input-mask.mjs +3 -3
  29. package/fesm2022/acorex-cdk-input-mask.mjs.map +1 -1
  30. package/fesm2022/acorex-cdk-list-navigation.mjs +10 -10
  31. package/fesm2022/acorex-cdk-list-navigation.mjs.map +1 -1
  32. package/fesm2022/acorex-cdk-outline.mjs +277 -74
  33. package/fesm2022/acorex-cdk-outline.mjs.map +1 -1
  34. package/fesm2022/acorex-cdk-overlay.mjs +224 -21
  35. package/fesm2022/acorex-cdk-overlay.mjs.map +1 -1
  36. package/fesm2022/acorex-cdk-pan-view.mjs +3 -3
  37. package/fesm2022/acorex-cdk-pan-view.mjs.map +1 -1
  38. package/fesm2022/acorex-cdk-qrcode.mjs.map +1 -1
  39. package/fesm2022/acorex-cdk-resizable.mjs +483 -200
  40. package/fesm2022/acorex-cdk-resizable.mjs.map +1 -1
  41. package/fesm2022/acorex-cdk-selection.mjs +10 -10
  42. package/fesm2022/acorex-cdk-selection.mjs.map +1 -1
  43. package/fesm2022/acorex-cdk-shimmer.mjs +220 -0
  44. package/fesm2022/acorex-cdk-shimmer.mjs.map +1 -0
  45. package/fesm2022/acorex-cdk-sliding-item.mjs +3 -3
  46. package/fesm2022/acorex-cdk-sliding-item.mjs.map +1 -1
  47. package/fesm2022/acorex-cdk-sticky.mjs +3 -3
  48. package/fesm2022/acorex-cdk-sticky.mjs.map +1 -1
  49. package/fesm2022/acorex-cdk-uploader.mjs +9 -9
  50. package/fesm2022/acorex-cdk-uploader.mjs.map +1 -1
  51. package/fesm2022/acorex-cdk-viewport-guard.mjs +616 -0
  52. package/fesm2022/acorex-cdk-viewport-guard.mjs.map +1 -0
  53. package/fesm2022/acorex-cdk-virtual-scroll.mjs +10 -10
  54. package/fesm2022/acorex-cdk-virtual-scroll.mjs.map +1 -1
  55. package/fesm2022/acorex-cdk-wysiwyg.mjs +689 -37
  56. package/fesm2022/acorex-cdk-wysiwyg.mjs.map +1 -1
  57. package/fesm2022/acorex-cdk-z-index.mjs +3 -3
  58. package/fesm2022/acorex-cdk-z-index.mjs.map +1 -1
  59. package/fesm2022/acorex-cdk.mjs.map +1 -1
  60. package/package.json +23 -7
  61. package/shimmer/README.md +11 -0
  62. package/types/acorex-cdk-auto-follow-scroll.d.ts +72 -0
  63. package/types/acorex-cdk-carousel.d.ts +2 -0
  64. package/types/acorex-cdk-clipboard.d.ts +1 -1
  65. package/types/acorex-cdk-common.d.ts +36 -19
  66. package/types/acorex-cdk-drag-drop.d.ts +43 -17
  67. package/types/acorex-cdk-full-screen.d.ts +18 -43
  68. package/types/acorex-cdk-gesture.d.ts +11 -1
  69. package/types/acorex-cdk-highlight.d.ts +1 -28
  70. package/types/acorex-cdk-horizontal-scroll.d.ts +3 -0
  71. package/types/acorex-cdk-outline.d.ts +20 -0
  72. package/types/acorex-cdk-overlay.d.ts +60 -4
  73. package/types/acorex-cdk-resizable.d.ts +80 -38
  74. package/types/acorex-cdk-shimmer.d.ts +68 -0
  75. package/types/acorex-cdk-uploader.d.ts +1 -1
  76. package/types/acorex-cdk-viewport-guard.d.ts +99 -0
  77. package/types/acorex-cdk-wysiwyg.d.ts +118 -14
  78. package/wysiwyg/README.md +3 -1
  79. package/fesm2022/acorex-cdk-double-click.mjs +0 -178
  80. package/fesm2022/acorex-cdk-double-click.mjs.map +0 -1
  81. package/types/acorex-cdk-double-click.d.ts +0 -66
@@ -1,88 +1,740 @@
1
1
  import { isPlatformBrowser } from '@angular/common';
2
- import { signal, inject, PLATFORM_ID } from '@angular/core';
2
+ import * as i0 from '@angular/core';
3
+ import { signal, inject, PLATFORM_ID, Injectable } from '@angular/core';
4
+ import { Extension, Node, mergeAttributes } from '@tiptap/core';
5
+
6
+ const AX_WYSIWYG_FONT_SIZE_VALUES = {
7
+ small: '0.75em',
8
+ large: '1.5em',
9
+ huge: '2.5em',
10
+ };
11
+ const AXWysiwygFontSizeExtension = Extension.create({
12
+ name: 'axWysiwygFontSize',
13
+ addGlobalAttributes() {
14
+ return [
15
+ {
16
+ types: ['textStyle'],
17
+ attributes: {
18
+ fontSize: {
19
+ default: null,
20
+ parseHTML: (element) => element.style.fontSize?.replace(/['"]+/g, '') || null,
21
+ renderHTML: (attributes) => {
22
+ if (!attributes['fontSize']) {
23
+ return {};
24
+ }
25
+ return { style: `font-size: ${attributes['fontSize']}` };
26
+ },
27
+ },
28
+ },
29
+ },
30
+ ];
31
+ },
32
+ addCommands() {
33
+ return {
34
+ setAxWysiwygFontSize: (size) => ({ chain }) => {
35
+ if (!size) {
36
+ return chain().focus().unsetMark('textStyle').run();
37
+ }
38
+ const cssSize = AX_WYSIWYG_FONT_SIZE_VALUES[size];
39
+ return chain().focus().setMark('textStyle', { fontSize: cssSize }).run();
40
+ },
41
+ };
42
+ },
43
+ });
44
+
45
+ const AX_DEFAULT_WYSIWYG_FEATURES = {
46
+ textAlign: true,
47
+ image: true,
48
+ link: true,
49
+ video: true,
50
+ color: true,
51
+ highlight: true,
52
+ placeholder: true,
53
+ fontSize: true,
54
+ textDirection: true,
55
+ };
56
+ const AX_EMPTY_WYSIWYG_STATE = {
57
+ bold: false,
58
+ italic: false,
59
+ underline: false,
60
+ strike: false,
61
+ code: false,
62
+ codeBlock: false,
63
+ headingLevel: null,
64
+ bulletList: false,
65
+ orderedList: false,
66
+ blockquote: false,
67
+ textAlign: null,
68
+ textColor: null,
69
+ highlightColor: null,
70
+ linkHref: null,
71
+ fontSize: null,
72
+ textDirection: null,
73
+ canUndo: false,
74
+ canRedo: false,
75
+ isEmpty: true,
76
+ isFocused: false,
77
+ };
78
+
79
+ const AXWysiwygTextDirectionExtension = Extension.create({
80
+ name: 'axWysiwygTextDirection',
81
+ addGlobalAttributes() {
82
+ return [
83
+ {
84
+ types: ['paragraph', 'heading'],
85
+ attributes: {
86
+ dir: {
87
+ default: null,
88
+ parseHTML: (element) => element.getAttribute('dir'),
89
+ renderHTML: (attributes) => {
90
+ if (!attributes['dir']) {
91
+ return {};
92
+ }
93
+ return { dir: attributes['dir'] };
94
+ },
95
+ },
96
+ },
97
+ },
98
+ ];
99
+ },
100
+ addCommands() {
101
+ return {
102
+ setAxWysiwygTextDirection: (direction) => ({ chain }) => chain()
103
+ .focus()
104
+ .updateAttributes('paragraph', { dir: direction })
105
+ .updateAttributes('heading', { dir: direction })
106
+ .run(),
107
+ };
108
+ },
109
+ });
110
+
111
+ function toEmbedSrc(src) {
112
+ const trimmed = src.trim();
113
+ if (!trimmed) {
114
+ return trimmed;
115
+ }
116
+ try {
117
+ const url = new URL(trimmed);
118
+ if (url.hostname.includes('youtube.com') && url.searchParams.get('v')) {
119
+ return `https://www.youtube.com/embed/${url.searchParams.get('v')}`;
120
+ }
121
+ if (url.hostname === 'youtu.be') {
122
+ return `https://www.youtube.com/embed/${url.pathname.slice(1)}`;
123
+ }
124
+ }
125
+ catch {
126
+ return trimmed;
127
+ }
128
+ return trimmed;
129
+ }
130
+ const AXWysiwygVideoExtension = Node.create({
131
+ name: 'video',
132
+ group: 'block',
133
+ atom: true,
134
+ addOptions() {
135
+ return {
136
+ inline: false,
137
+ allowBase64: false,
138
+ HTMLAttributes: {},
139
+ };
140
+ },
141
+ addAttributes() {
142
+ return {
143
+ src: {
144
+ default: null,
145
+ },
146
+ };
147
+ },
148
+ parseHTML() {
149
+ return [
150
+ {
151
+ tag: 'div[data-wysiwyg-video] iframe',
152
+ },
153
+ {
154
+ tag: 'iframe[src]',
155
+ },
156
+ ];
157
+ },
158
+ renderHTML({ HTMLAttributes }) {
159
+ const src = HTMLAttributes['src'];
160
+ return [
161
+ 'div',
162
+ mergeAttributes(this.options.HTMLAttributes, { 'data-wysiwyg-video': '' }),
163
+ [
164
+ 'iframe',
165
+ mergeAttributes({
166
+ src,
167
+ frameborder: '0',
168
+ allowfullscreen: 'true',
169
+ allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
170
+ }),
171
+ ],
172
+ ];
173
+ },
174
+ addCommands() {
175
+ return {
176
+ setVideo: ({ src }) => ({ commands }) => commands.insertContent({
177
+ type: this.name,
178
+ attrs: { src: toEmbedSrc(src) },
179
+ }),
180
+ };
181
+ },
182
+ });
183
+
184
+ async function loadAXWysiwygExtensions(options) {
185
+ const features = { ...AX_DEFAULT_WYSIWYG_FEATURES, ...options?.features };
186
+ const [starterKitMod, textStyleMod, colorMod, highlightMod, underlineMod] = await Promise.all([
187
+ import('@tiptap/starter-kit'),
188
+ import('@tiptap/extension-text-style'),
189
+ import('@tiptap/extension-color'),
190
+ import('@tiptap/extension-highlight'),
191
+ import('@tiptap/extension-underline'),
192
+ ]);
193
+ const extensions = [
194
+ starterKitMod.default.configure({
195
+ link: features.link ? { openOnClick: false } : false,
196
+ }),
197
+ underlineMod.default,
198
+ ];
199
+ if (features.color || features.fontSize) {
200
+ extensions.push(textStyleMod.TextStyle);
201
+ }
202
+ if (features.color) {
203
+ extensions.push(colorMod.Color);
204
+ }
205
+ if (features.highlight) {
206
+ extensions.push(highlightMod.default.configure({ multicolor: true }));
207
+ }
208
+ if (features.fontSize) {
209
+ extensions.push(AXWysiwygFontSizeExtension);
210
+ }
211
+ if (features.textDirection) {
212
+ extensions.push(AXWysiwygTextDirectionExtension);
213
+ }
214
+ if (features.textAlign) {
215
+ const textAlignMod = await import('@tiptap/extension-text-align');
216
+ extensions.push(textAlignMod.default.configure({
217
+ types: ['heading', 'paragraph'],
218
+ }));
219
+ }
220
+ if (features.image) {
221
+ const imageMod = await import('@tiptap/extension-image');
222
+ extensions.push(imageMod.default.configure({
223
+ inline: true,
224
+ allowBase64: true,
225
+ }));
226
+ }
227
+ if (features.video) {
228
+ extensions.push(AXWysiwygVideoExtension);
229
+ }
230
+ if (features.placeholder && options?.placeholder) {
231
+ const { Placeholder } = await import('@tiptap/extensions');
232
+ extensions.push(Placeholder.configure({
233
+ placeholder: options.placeholder,
234
+ }));
235
+ }
236
+ return extensions;
237
+ }
3
238
 
4
239
  class AXWysiwyg {
5
240
  constructor() {
6
- this.quillObj = signal(null, /* @ts-ignore */
7
- ...(ngDevMode ? [{ debugName: "quillObj" }] : /* istanbul ignore next */ []));
241
+ this.editor = signal(null, /* @ts-ignore */
242
+ ...(ngDevMode ? [{ debugName: "editor" }] : /* istanbul ignore next */ []));
243
+ this.state = signal(AX_EMPTY_WYSIWYG_STATE, /* @ts-ignore */
244
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
245
+ this.ready = signal(false, /* @ts-ignore */
246
+ ...(ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []));
8
247
  this.platformId = inject(PLATFORM_ID);
248
+ this.destroyed = false;
249
+ this.applyingContent = false;
9
250
  }
10
- async init(container, option) {
11
- if (!isPlatformBrowser(this.platformId))
251
+ async init(container, options = {}) {
252
+ if (!isPlatformBrowser(this.platformId)) {
253
+ return;
254
+ }
255
+ const element = typeof container === 'string' ? document.querySelector(container) : container;
256
+ if (!element) {
12
257
  return;
13
- await import('quill').then((e) => {
14
- const wysiwygObject = new e.default(container, option);
15
- this.quillObj.set(wysiwygObject);
258
+ }
259
+ this.destroyed = false;
260
+ const editable = options.readOnly === true ? false : (options.editable ?? true);
261
+ const extensions = await loadAXWysiwygExtensions({
262
+ features: options.features,
263
+ placeholder: options.placeholder,
16
264
  });
265
+ if (this.destroyed) {
266
+ return;
267
+ }
268
+ const { Editor } = await import('@tiptap/core');
269
+ if (this.destroyed) {
270
+ return;
271
+ }
272
+ const allExtensions = [...extensions, ...(options.extensions ?? [])];
273
+ const editor = new Editor({
274
+ element,
275
+ extensions: allExtensions,
276
+ content: options.content ?? '',
277
+ editable,
278
+ editorProps: {
279
+ attributes: {
280
+ class: 'tiptap',
281
+ },
282
+ },
283
+ onUpdate: ({ editor: ed }) => {
284
+ this.refreshState(ed);
285
+ if (!this.applyingContent) {
286
+ options.onUpdate?.(ed);
287
+ }
288
+ },
289
+ onSelectionUpdate: ({ editor: ed }) => {
290
+ this.refreshState(ed);
291
+ options.onSelectionUpdate?.(ed);
292
+ },
293
+ onFocus: ({ editor: ed }) => {
294
+ this.refreshState(ed);
295
+ options.onFocus?.(ed);
296
+ },
297
+ onBlur: ({ editor: ed }) => {
298
+ this.refreshState(ed);
299
+ options.onBlur?.(ed);
300
+ },
301
+ });
302
+ this.editor.set(editor);
303
+ this.ready.set(true);
304
+ this.refreshState(editor);
305
+ }
306
+ destroy() {
307
+ this.destroyed = true;
308
+ const ed = this.editor();
309
+ ed?.destroy();
310
+ this.editor.set(null);
311
+ this.ready.set(false);
312
+ this.state.set(AX_EMPTY_WYSIWYG_STATE);
313
+ }
314
+ setContent(value, emit = false) {
315
+ const ed = this.editor();
316
+ if (!ed) {
317
+ return;
318
+ }
319
+ const html = value?.trim() ? value : '';
320
+ this.applyingContent = true;
321
+ try {
322
+ ed.commands.setContent(html, { emitUpdate: emit });
323
+ this.refreshState(ed);
324
+ }
325
+ finally {
326
+ this.applyingContent = false;
327
+ }
328
+ }
329
+ getHTML() {
330
+ return this.editor()?.getHTML() ?? '';
331
+ }
332
+ get JSONoutput() {
333
+ return this.editor()?.getJSON() ?? null;
334
+ }
335
+ getText() {
336
+ return this.editor()?.getText() ?? '';
337
+ }
338
+ isEmpty() {
339
+ return this.editor()?.isEmpty ?? true;
340
+ }
341
+ setEditable(editable) {
342
+ this.editor()?.setEditable(editable);
343
+ const ed = this.editor();
344
+ if (ed) {
345
+ this.refreshState(ed);
346
+ }
347
+ }
348
+ get HTMLoutput() {
349
+ return this.getHTML();
17
350
  }
18
351
  bold(value) {
19
- this.quillObj().format('bold', value);
352
+ this.setMarkActive('bold', value);
20
353
  }
21
354
  italic(value) {
22
- this.quillObj().format('italic', value);
355
+ this.setMarkActive('italic', value);
23
356
  }
24
357
  underLine(value) {
25
- this.quillObj().format('underline', value);
358
+ this.setMarkActive('underline', value);
26
359
  }
27
360
  strike(value) {
28
- this.quillObj().format('strike', value);
361
+ this.setMarkActive('strike', value);
29
362
  }
30
363
  color(value) {
31
- this.quillObj().format('color', value);
364
+ if (value) {
365
+ this.setColor(value);
366
+ }
367
+ else {
368
+ this.unsetColor();
369
+ }
32
370
  }
33
371
  header(value) {
34
- this.quillObj().format('header', value);
372
+ const ed = this.editor();
373
+ if (!ed) {
374
+ return;
375
+ }
376
+ if (value >= 1 && value <= 6) {
377
+ ed.chain()
378
+ .focus()
379
+ .toggleHeading({ level: value })
380
+ .run();
381
+ }
382
+ else {
383
+ ed.chain().focus().setParagraph().run();
384
+ }
35
385
  }
36
386
  list(value) {
37
- this.quillObj().format('list', value);
387
+ const ed = this.editor();
388
+ if (!ed) {
389
+ return;
390
+ }
391
+ const chain = ed.chain().focus();
392
+ if (value === 'bullet') {
393
+ chain.toggleBulletList().run();
394
+ }
395
+ else if (value === 'ordered') {
396
+ chain.toggleOrderedList().run();
397
+ }
398
+ else {
399
+ chain.liftListItem('listItem').run();
400
+ }
38
401
  }
39
402
  align(value) {
40
403
  if (value === 'left') {
41
- this.quillObj().format('align', '');
404
+ this.setTextAlign('left');
42
405
  }
43
406
  else {
44
- this.quillObj().format('align', value);
407
+ this.setTextAlign(value);
45
408
  }
46
409
  }
47
410
  direction(value) {
48
- this.quillObj().format('direction', value);
411
+ this.setTextDirection(value);
49
412
  }
50
413
  fontSize(value, range) {
51
- this.quillObj().formatText(range.index, range.length, 'size', value);
414
+ const ed = this.editor();
415
+ if (!ed || !range) {
416
+ return;
417
+ }
418
+ const from = range.index;
419
+ const to = range.index + range.length;
420
+ if (value === false) {
421
+ ed.chain().focus().setTextSelection({ from, to }).setAxWysiwygFontSize(null).run();
422
+ return;
423
+ }
424
+ ed.chain().focus().setTextSelection({ from, to }).setAxWysiwygFontSize(value).run();
52
425
  }
53
- get HTMLoutput() {
54
- return this.quillObj().root.innerHTML;
426
+ background(value) {
427
+ if (value) {
428
+ this.setHighlight(value);
429
+ }
430
+ else {
431
+ this.unsetHighlight();
432
+ }
433
+ }
434
+ addImage(value) {
435
+ this.insertImage(value);
436
+ }
437
+ insertVideo(src) {
438
+ this.editor()?.chain().focus().setVideo({ src }).run();
439
+ }
440
+ codeBlock(range, status) {
441
+ const ed = this.editor();
442
+ if (!ed || !range) {
443
+ return;
444
+ }
445
+ const from = range.index;
446
+ const to = range.index + range.length;
447
+ if (status) {
448
+ ed.chain().focus().setTextSelection({ from, to }).toggleCodeBlock().run();
449
+ }
450
+ else {
451
+ ed.chain().focus().setTextSelection({ from, to }).setParagraph().run();
452
+ }
453
+ }
454
+ focus() {
455
+ this.editor()?.commands.focus();
456
+ }
457
+ blur() {
458
+ this.editor()?.commands.blur();
459
+ }
460
+ toggleBold() {
461
+ this.editor()?.chain().focus().toggleBold().run();
462
+ }
463
+ toggleItalic() {
464
+ this.editor()?.chain().focus().toggleItalic().run();
465
+ }
466
+ toggleUnderline() {
467
+ this.editor()?.chain().focus().toggleUnderline().run();
468
+ }
469
+ toggleStrike() {
470
+ this.editor()?.chain().focus().toggleStrike().run();
471
+ }
472
+ toggleCode() {
473
+ this.editor()?.chain().focus().toggleCode().run();
474
+ }
475
+ toggleCodeBlock() {
476
+ this.editor()?.chain().focus().toggleCodeBlock().run();
477
+ }
478
+ toggleHeading(level) {
479
+ this.editor()?.chain().focus().toggleHeading({ level }).run();
480
+ }
481
+ setParagraph() {
482
+ this.editor()?.chain().focus().setParagraph().run();
483
+ }
484
+ toggleBulletList() {
485
+ this.editor()?.chain().focus().toggleBulletList().run();
486
+ }
487
+ toggleOrderedList() {
488
+ this.editor()?.chain().focus().toggleOrderedList().run();
489
+ }
490
+ toggleBlockquote() {
491
+ this.editor()?.chain().focus().toggleBlockquote().run();
492
+ }
493
+ setTextAlign(align) {
494
+ this.editor()?.chain().focus().setTextAlign(align).run();
495
+ }
496
+ setTextDirection(direction) {
497
+ this.editor()?.chain().focus().setAxWysiwygTextDirection(direction).run();
498
+ }
499
+ setFontSize(size) {
500
+ this.editor()?.chain().focus().setAxWysiwygFontSize(size).run();
501
+ }
502
+ setColor(color) {
503
+ this.editor()?.chain().focus().setColor(color).run();
504
+ }
505
+ unsetColor() {
506
+ this.editor()?.chain().focus().unsetColor().run();
507
+ }
508
+ setHighlight(color) {
509
+ this.editor()?.chain().focus().setHighlight({ color }).run();
510
+ }
511
+ unsetHighlight() {
512
+ this.editor()?.chain().focus().unsetHighlight().run();
513
+ }
514
+ setLink(href) {
515
+ this.editor()?.chain().focus().extendMarkRange('link').setLink({ href }).run();
516
+ }
517
+ unsetLink() {
518
+ this.editor()?.chain().focus().unsetLink().run();
519
+ }
520
+ insertImage(src, alt) {
521
+ this.editor()?.chain().focus().setImage({ src, alt }).run();
55
522
  }
56
523
  undo() {
57
- this.quillObj().history.undo();
524
+ const ed = this.editor();
525
+ if (!ed) {
526
+ return;
527
+ }
528
+ ed.chain().focus().undo().run();
529
+ this.refreshState(ed);
58
530
  }
59
531
  redo() {
60
- this.quillObj().history.redo();
532
+ const ed = this.editor();
533
+ if (!ed) {
534
+ return;
535
+ }
536
+ ed.chain().focus().redo().run();
537
+ this.refreshState(ed);
61
538
  }
62
- background(value) {
63
- this.quillObj().format('background', value);
539
+ clearFormatting() {
540
+ this.editor()?.chain().focus().clearNodes().unsetAllMarks().run();
64
541
  }
65
- addImage(value) {
66
- const range = this.quillObj().getSelection();
67
- const currentIndex = range?.index;
68
- this.quillObj().insertEmbed(currentIndex, 'image', value);
542
+ execute(command, payload) {
543
+ switch (command) {
544
+ case 'bold':
545
+ this.toggleBold();
546
+ break;
547
+ case 'italic':
548
+ this.toggleItalic();
549
+ break;
550
+ case 'underline':
551
+ this.toggleUnderline();
552
+ break;
553
+ case 'strike':
554
+ this.toggleStrike();
555
+ break;
556
+ case 'code':
557
+ this.toggleCode();
558
+ break;
559
+ case 'codeBlock':
560
+ this.toggleCodeBlock();
561
+ break;
562
+ case 'heading':
563
+ if (typeof payload === 'number') {
564
+ this.toggleHeading(payload);
565
+ }
566
+ break;
567
+ case 'paragraph':
568
+ this.setParagraph();
569
+ break;
570
+ case 'bulletList':
571
+ this.toggleBulletList();
572
+ break;
573
+ case 'orderedList':
574
+ this.toggleOrderedList();
575
+ break;
576
+ case 'blockquote':
577
+ this.toggleBlockquote();
578
+ break;
579
+ case 'textAlign':
580
+ if (typeof payload === 'string') {
581
+ this.setTextAlign(payload);
582
+ }
583
+ break;
584
+ case 'direction':
585
+ if (payload === 'rtl' || payload === 'ltr') {
586
+ this.setTextDirection(payload);
587
+ }
588
+ break;
589
+ case 'fontSize':
590
+ if (payload === null) {
591
+ this.setFontSize(null);
592
+ }
593
+ else if (payload === 'small' || payload === 'large' || payload === 'huge') {
594
+ this.setFontSize(payload);
595
+ }
596
+ break;
597
+ case 'color':
598
+ if (typeof payload === 'string') {
599
+ this.setColor(payload);
600
+ }
601
+ else {
602
+ this.unsetColor();
603
+ }
604
+ break;
605
+ case 'highlight':
606
+ if (typeof payload === 'string') {
607
+ this.setHighlight(payload);
608
+ }
609
+ else {
610
+ this.unsetHighlight();
611
+ }
612
+ break;
613
+ case 'link':
614
+ if (typeof payload === 'string' && payload) {
615
+ this.setLink(payload);
616
+ }
617
+ else {
618
+ this.unsetLink();
619
+ }
620
+ break;
621
+ case 'image':
622
+ if (typeof payload === 'string') {
623
+ this.insertImage(payload);
624
+ }
625
+ break;
626
+ case 'video':
627
+ if (typeof payload === 'string') {
628
+ this.insertVideo(payload);
629
+ }
630
+ break;
631
+ case 'undo':
632
+ this.undo();
633
+ break;
634
+ case 'redo':
635
+ this.redo();
636
+ break;
637
+ case 'clearFormatting':
638
+ this.clearFormatting();
639
+ break;
640
+ }
69
641
  }
70
- focus() {
71
- this.quillObj().focus();
642
+ isActive(name, attrs) {
643
+ return this.editor()?.isActive(name, attrs) ?? false;
72
644
  }
73
- blur() {
74
- this.quillObj().blur();
645
+ can(command) {
646
+ const ed = this.editor();
647
+ if (!ed) {
648
+ return false;
649
+ }
650
+ if (command === 'undo') {
651
+ return ed.can().undo();
652
+ }
653
+ return ed.can().redo();
75
654
  }
76
- codeBlock(range, status) {
77
- if (!range)
655
+ setMarkActive(name, active) {
656
+ const ed = this.editor();
657
+ if (!ed) {
78
658
  return;
79
- this.quillObj().formatLine(range.index, range.length, 'code-block', status);
659
+ }
660
+ const chain = ed.chain().focus();
661
+ switch (name) {
662
+ case 'bold':
663
+ active ? chain.setBold().run() : chain.unsetBold().run();
664
+ break;
665
+ case 'italic':
666
+ active ? chain.setItalic().run() : chain.unsetItalic().run();
667
+ break;
668
+ case 'underline':
669
+ active ? chain.setUnderline().run() : chain.unsetUnderline().run();
670
+ break;
671
+ case 'strike':
672
+ active ? chain.setStrike().run() : chain.unsetStrike().run();
673
+ break;
674
+ }
675
+ }
676
+ refreshState(editor) {
677
+ const textColor = editor.getAttributes('textStyle')['color'];
678
+ const fontSizeCss = editor.getAttributes('textStyle')['fontSize'];
679
+ const highlightColor = editor.getAttributes('highlight')['color'];
680
+ const linkHref = editor.getAttributes('link')['href'];
681
+ const dir = (editor.getAttributes('paragraph')['dir'] || editor.getAttributes('heading')['dir']);
682
+ let headingLevel = null;
683
+ for (let level = 1; level <= 6; level++) {
684
+ if (editor.isActive('heading', { level })) {
685
+ headingLevel = level;
686
+ break;
687
+ }
688
+ }
689
+ let textAlign = null;
690
+ for (const align of ['left', 'center', 'right', 'justify']) {
691
+ if (editor.isActive({ textAlign: align })) {
692
+ textAlign = align;
693
+ break;
694
+ }
695
+ }
696
+ let fontSize = null;
697
+ if (fontSizeCss) {
698
+ for (const [token, css] of Object.entries(AX_WYSIWYG_FONT_SIZE_VALUES)) {
699
+ if (fontSizeCss === css) {
700
+ fontSize = token;
701
+ break;
702
+ }
703
+ }
704
+ }
705
+ this.state.set({
706
+ bold: editor.isActive('bold'),
707
+ italic: editor.isActive('italic'),
708
+ underline: editor.isActive('underline'),
709
+ strike: editor.isActive('strike'),
710
+ code: editor.isActive('code'),
711
+ codeBlock: editor.isActive('codeBlock'),
712
+ headingLevel,
713
+ bulletList: editor.isActive('bulletList'),
714
+ orderedList: editor.isActive('orderedList'),
715
+ blockquote: editor.isActive('blockquote'),
716
+ textAlign,
717
+ textColor: textColor ?? null,
718
+ highlightColor: highlightColor ?? null,
719
+ linkHref: linkHref ?? null,
720
+ fontSize,
721
+ textDirection: dir ?? null,
722
+ canUndo: editor.can().undo(),
723
+ canRedo: editor.can().redo(),
724
+ isEmpty: editor.isEmpty,
725
+ isFocused: editor.isFocused,
726
+ });
80
727
  }
728
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
729
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg }); }
81
730
  }
731
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg, decorators: [{
732
+ type: Injectable
733
+ }] });
82
734
 
83
735
  /**
84
736
  * Generated bundle index. Do not edit.
85
737
  */
86
738
 
87
- export { AXWysiwyg };
739
+ export { AXWysiwyg, AX_DEFAULT_WYSIWYG_FEATURES, AX_EMPTY_WYSIWYG_STATE, loadAXWysiwygExtensions };
88
740
  //# sourceMappingURL=acorex-cdk-wysiwyg.mjs.map