@acorex/cdk 22.1.8 → 22.2.0-next.1

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 (90) 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 +223 -108
  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 +158 -68
  15. package/fesm2022/acorex-cdk-drag-drop.mjs.map +1 -1
  16. package/fesm2022/acorex-cdk-drawer.mjs +15 -13
  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 +37 -14
  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 +21 -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-scrollbar.mjs +903 -0
  35. package/fesm2022/acorex-cdk-overlay-scrollbar.mjs.map +1 -0
  36. package/fesm2022/acorex-cdk-overlay.mjs +259 -25
  37. package/fesm2022/acorex-cdk-overlay.mjs.map +1 -1
  38. package/fesm2022/acorex-cdk-pan-view.mjs +3 -3
  39. package/fesm2022/acorex-cdk-pan-view.mjs.map +1 -1
  40. package/fesm2022/acorex-cdk-qrcode.mjs.map +1 -1
  41. package/fesm2022/acorex-cdk-resizable.mjs +483 -200
  42. package/fesm2022/acorex-cdk-resizable.mjs.map +1 -1
  43. package/fesm2022/acorex-cdk-selection.mjs +10 -10
  44. package/fesm2022/acorex-cdk-selection.mjs.map +1 -1
  45. package/fesm2022/acorex-cdk-shimmer.mjs +220 -0
  46. package/fesm2022/acorex-cdk-shimmer.mjs.map +1 -0
  47. package/fesm2022/acorex-cdk-sliding-item.mjs +3 -3
  48. package/fesm2022/acorex-cdk-sliding-item.mjs.map +1 -1
  49. package/fesm2022/acorex-cdk-sticky.mjs +3 -3
  50. package/fesm2022/acorex-cdk-sticky.mjs.map +1 -1
  51. package/fesm2022/acorex-cdk-text-editor.mjs +942 -0
  52. package/fesm2022/acorex-cdk-text-editor.mjs.map +1 -0
  53. package/fesm2022/acorex-cdk-uploader.mjs +9 -9
  54. package/fesm2022/acorex-cdk-uploader.mjs.map +1 -1
  55. package/fesm2022/acorex-cdk-viewport-guard.mjs +616 -0
  56. package/fesm2022/acorex-cdk-viewport-guard.mjs.map +1 -0
  57. package/fesm2022/acorex-cdk-virtual-scroll.mjs +10 -10
  58. package/fesm2022/acorex-cdk-virtual-scroll.mjs.map +1 -1
  59. package/fesm2022/acorex-cdk-wysiwyg.mjs +694 -37
  60. package/fesm2022/acorex-cdk-wysiwyg.mjs.map +1 -1
  61. package/fesm2022/acorex-cdk-z-index.mjs +3 -3
  62. package/fesm2022/acorex-cdk-z-index.mjs.map +1 -1
  63. package/fesm2022/acorex-cdk.mjs.map +1 -1
  64. package/overlay-scrollbar/README.md +54 -0
  65. package/package.json +33 -7
  66. package/shimmer/README.md +11 -0
  67. package/text-editor/README.md +5 -0
  68. package/types/acorex-cdk-auto-follow-scroll.d.ts +72 -0
  69. package/types/acorex-cdk-carousel.d.ts +2 -0
  70. package/types/acorex-cdk-clipboard.d.ts +1 -1
  71. package/types/acorex-cdk-common.d.ts +46 -19
  72. package/types/acorex-cdk-drag-drop.d.ts +43 -17
  73. package/types/acorex-cdk-full-screen.d.ts +18 -43
  74. package/types/acorex-cdk-gesture.d.ts +11 -1
  75. package/types/acorex-cdk-highlight.d.ts +1 -28
  76. package/types/acorex-cdk-horizontal-scroll.d.ts +3 -0
  77. package/types/acorex-cdk-list-navigation.d.ts +5 -0
  78. package/types/acorex-cdk-outline.d.ts +20 -0
  79. package/types/acorex-cdk-overlay-scrollbar.d.ts +155 -0
  80. package/types/acorex-cdk-overlay.d.ts +60 -4
  81. package/types/acorex-cdk-resizable.d.ts +80 -38
  82. package/types/acorex-cdk-shimmer.d.ts +68 -0
  83. package/types/acorex-cdk-text-editor.d.ts +156 -0
  84. package/types/acorex-cdk-uploader.d.ts +1 -1
  85. package/types/acorex-cdk-viewport-guard.d.ts +99 -0
  86. package/types/acorex-cdk-wysiwyg.d.ts +121 -14
  87. package/wysiwyg/README.md +3 -1
  88. package/fesm2022/acorex-cdk-double-click.mjs +0 -178
  89. package/fesm2022/acorex-cdk-double-click.mjs.map +0 -1
  90. package/types/acorex-cdk-double-click.d.ts +0 -66
@@ -1,88 +1,745 @@
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';
3
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
+ }
238
+
239
+ /**
240
+ * @deprecated Use `AXTextEditor` from `@acorex/cdk/text-editor` instead.
241
+ */
4
242
  class AXWysiwyg {
5
243
  constructor() {
6
- this.quillObj = signal(null, /* @ts-ignore */
7
- ...(ngDevMode ? [{ debugName: "quillObj" }] : /* istanbul ignore next */ []));
244
+ this.editor = signal(null, /* @ts-ignore */
245
+ ...(ngDevMode ? [{ debugName: "editor" }] : /* istanbul ignore next */ []));
246
+ this.state = signal(AX_EMPTY_WYSIWYG_STATE, /* @ts-ignore */
247
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
248
+ this.ready = signal(false, /* @ts-ignore */
249
+ ...(ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []));
8
250
  this.platformId = inject(PLATFORM_ID);
251
+ this.destroyed = false;
252
+ this.applyingContent = false;
9
253
  }
10
- async init(container, option) {
11
- if (!isPlatformBrowser(this.platformId))
254
+ async init(container, options = {}) {
255
+ if (!isPlatformBrowser(this.platformId)) {
12
256
  return;
13
- await import('quill').then((e) => {
14
- const wysiwygObject = new e.default(container, option);
15
- this.quillObj.set(wysiwygObject);
257
+ }
258
+ const element = typeof container === 'string' ? document.querySelector(container) : container;
259
+ if (!element) {
260
+ return;
261
+ }
262
+ this.destroyed = false;
263
+ const editable = options.readOnly === true ? false : (options.editable ?? true);
264
+ const extensions = await loadAXWysiwygExtensions({
265
+ features: options.features,
266
+ placeholder: options.placeholder,
267
+ });
268
+ if (this.destroyed) {
269
+ return;
270
+ }
271
+ const { Editor } = await import('@tiptap/core');
272
+ if (this.destroyed) {
273
+ return;
274
+ }
275
+ const allExtensions = [...extensions, ...(options.extensions ?? [])];
276
+ const editor = new Editor({
277
+ element,
278
+ extensions: allExtensions,
279
+ content: options.content ?? '',
280
+ editable,
281
+ editorProps: {
282
+ attributes: {
283
+ class: 'tiptap',
284
+ },
285
+ },
286
+ onUpdate: ({ editor: ed }) => {
287
+ this.refreshState(ed);
288
+ if (!this.applyingContent) {
289
+ options.onUpdate?.(ed);
290
+ }
291
+ },
292
+ onSelectionUpdate: ({ editor: ed }) => {
293
+ this.refreshState(ed);
294
+ options.onSelectionUpdate?.(ed);
295
+ },
296
+ onFocus: ({ editor: ed }) => {
297
+ this.refreshState(ed);
298
+ options.onFocus?.(ed);
299
+ },
300
+ onBlur: ({ editor: ed }) => {
301
+ this.refreshState(ed);
302
+ options.onBlur?.(ed);
303
+ },
16
304
  });
305
+ this.editor.set(editor);
306
+ this.ready.set(true);
307
+ this.refreshState(editor);
308
+ }
309
+ destroy() {
310
+ this.destroyed = true;
311
+ const ed = this.editor();
312
+ ed?.destroy();
313
+ this.editor.set(null);
314
+ this.ready.set(false);
315
+ this.state.set(AX_EMPTY_WYSIWYG_STATE);
316
+ }
317
+ setContent(value, emit = false) {
318
+ const ed = this.editor();
319
+ if (!ed) {
320
+ return;
321
+ }
322
+ const html = value?.trim() ? value : '';
323
+ this.applyingContent = true;
324
+ try {
325
+ ed.commands.setContent(html, { emitUpdate: emit });
326
+ this.refreshState(ed);
327
+ }
328
+ finally {
329
+ this.applyingContent = false;
330
+ }
331
+ }
332
+ getHTML() {
333
+ return this.editor()?.getHTML() ?? '';
334
+ }
335
+ get JSONoutput() {
336
+ return this.editor()?.getJSON() ?? null;
337
+ }
338
+ getText() {
339
+ return this.editor()?.getText() ?? '';
340
+ }
341
+ isEmpty() {
342
+ return this.editor()?.isEmpty ?? true;
343
+ }
344
+ setEditable(editable) {
345
+ this.editor()?.setEditable(editable);
346
+ const ed = this.editor();
347
+ if (ed) {
348
+ this.refreshState(ed);
349
+ }
350
+ }
351
+ get HTMLoutput() {
352
+ return this.getHTML();
17
353
  }
18
354
  bold(value) {
19
- this.quillObj().format('bold', value);
355
+ this.setMarkActive('bold', value);
20
356
  }
21
357
  italic(value) {
22
- this.quillObj().format('italic', value);
358
+ this.setMarkActive('italic', value);
23
359
  }
24
360
  underLine(value) {
25
- this.quillObj().format('underline', value);
361
+ this.setMarkActive('underline', value);
26
362
  }
27
363
  strike(value) {
28
- this.quillObj().format('strike', value);
364
+ this.setMarkActive('strike', value);
29
365
  }
30
366
  color(value) {
31
- this.quillObj().format('color', value);
367
+ if (value) {
368
+ this.setColor(value);
369
+ }
370
+ else {
371
+ this.unsetColor();
372
+ }
32
373
  }
33
374
  header(value) {
34
- this.quillObj().format('header', value);
375
+ const ed = this.editor();
376
+ if (!ed) {
377
+ return;
378
+ }
379
+ if (value >= 1 && value <= 6) {
380
+ ed.chain()
381
+ .focus()
382
+ .toggleHeading({ level: value })
383
+ .run();
384
+ }
385
+ else {
386
+ ed.chain().focus().setParagraph().run();
387
+ }
35
388
  }
36
389
  list(value) {
37
- this.quillObj().format('list', value);
390
+ const ed = this.editor();
391
+ if (!ed) {
392
+ return;
393
+ }
394
+ const chain = ed.chain().focus();
395
+ if (value === 'bullet') {
396
+ chain.toggleBulletList().run();
397
+ }
398
+ else if (value === 'ordered') {
399
+ chain.toggleOrderedList().run();
400
+ }
401
+ else {
402
+ chain.liftListItem('listItem').run();
403
+ }
38
404
  }
39
405
  align(value) {
40
406
  if (value === 'left') {
41
- this.quillObj().format('align', '');
407
+ this.setTextAlign('left');
42
408
  }
43
409
  else {
44
- this.quillObj().format('align', value);
410
+ this.setTextAlign(value);
45
411
  }
46
412
  }
47
413
  direction(value) {
48
- this.quillObj().format('direction', value);
414
+ this.setTextDirection(value);
49
415
  }
50
416
  fontSize(value, range) {
51
- this.quillObj().formatText(range.index, range.length, 'size', value);
417
+ const ed = this.editor();
418
+ if (!ed || !range) {
419
+ return;
420
+ }
421
+ const from = range.index;
422
+ const to = range.index + range.length;
423
+ if (value === false) {
424
+ ed.chain().focus().setTextSelection({ from, to }).setAxWysiwygFontSize(null).run();
425
+ return;
426
+ }
427
+ ed.chain().focus().setTextSelection({ from, to }).setAxWysiwygFontSize(value).run();
52
428
  }
53
- get HTMLoutput() {
54
- return this.quillObj().root.innerHTML;
429
+ background(value) {
430
+ if (value) {
431
+ this.setHighlight(value);
432
+ }
433
+ else {
434
+ this.unsetHighlight();
435
+ }
436
+ }
437
+ addImage(value) {
438
+ this.insertImage(value);
439
+ }
440
+ insertVideo(src) {
441
+ this.editor()?.chain().focus().setVideo({ src }).run();
442
+ }
443
+ codeBlock(range, status) {
444
+ const ed = this.editor();
445
+ if (!ed || !range) {
446
+ return;
447
+ }
448
+ const from = range.index;
449
+ const to = range.index + range.length;
450
+ if (status) {
451
+ ed.chain().focus().setTextSelection({ from, to }).toggleCodeBlock().run();
452
+ }
453
+ else {
454
+ ed.chain().focus().setTextSelection({ from, to }).setParagraph().run();
455
+ }
456
+ }
457
+ focus() {
458
+ this.editor()?.commands.focus();
459
+ }
460
+ blur() {
461
+ this.editor()?.commands.blur();
462
+ }
463
+ toggleBold() {
464
+ this.editor()?.chain().focus().toggleBold().run();
465
+ }
466
+ toggleItalic() {
467
+ this.editor()?.chain().focus().toggleItalic().run();
468
+ }
469
+ toggleUnderline() {
470
+ this.editor()?.chain().focus().toggleUnderline().run();
471
+ }
472
+ toggleStrike() {
473
+ this.editor()?.chain().focus().toggleStrike().run();
474
+ }
475
+ toggleCode() {
476
+ this.editor()?.chain().focus().toggleCode().run();
477
+ }
478
+ toggleCodeBlock() {
479
+ this.editor()?.chain().focus().toggleCodeBlock().run();
480
+ }
481
+ toggleHeading(level) {
482
+ this.editor()?.chain().focus().toggleHeading({ level }).run();
483
+ }
484
+ setParagraph() {
485
+ this.editor()?.chain().focus().setParagraph().run();
486
+ }
487
+ toggleBulletList() {
488
+ this.editor()?.chain().focus().toggleBulletList().run();
489
+ }
490
+ toggleOrderedList() {
491
+ this.editor()?.chain().focus().toggleOrderedList().run();
492
+ }
493
+ toggleBlockquote() {
494
+ this.editor()?.chain().focus().toggleBlockquote().run();
495
+ }
496
+ setTextAlign(align) {
497
+ this.editor()?.chain().focus().setTextAlign(align).run();
498
+ }
499
+ setTextDirection(direction) {
500
+ this.editor()?.chain().focus().setAxWysiwygTextDirection(direction).run();
501
+ }
502
+ setFontSize(size) {
503
+ this.editor()?.chain().focus().setAxWysiwygFontSize(size).run();
504
+ }
505
+ setColor(color) {
506
+ this.editor()?.chain().focus().setColor(color).run();
507
+ }
508
+ unsetColor() {
509
+ this.editor()?.chain().focus().unsetColor().run();
510
+ }
511
+ setHighlight(color) {
512
+ this.editor()?.chain().focus().setHighlight({ color }).run();
513
+ }
514
+ unsetHighlight() {
515
+ this.editor()?.chain().focus().unsetHighlight().run();
516
+ }
517
+ setLink(href) {
518
+ this.editor()?.chain().focus().extendMarkRange('link').setLink({ href }).run();
519
+ }
520
+ unsetLink() {
521
+ this.editor()?.chain().focus().unsetLink().run();
522
+ }
523
+ insertImage(src, alt) {
524
+ this.editor()?.chain().focus().setImage({ src, alt }).run();
55
525
  }
56
526
  undo() {
57
- this.quillObj().history.undo();
527
+ const ed = this.editor();
528
+ if (!ed) {
529
+ return;
530
+ }
531
+ ed.chain().focus().undo().run();
532
+ this.refreshState(ed);
58
533
  }
59
534
  redo() {
60
- this.quillObj().history.redo();
535
+ const ed = this.editor();
536
+ if (!ed) {
537
+ return;
538
+ }
539
+ ed.chain().focus().redo().run();
540
+ this.refreshState(ed);
61
541
  }
62
- background(value) {
63
- this.quillObj().format('background', value);
542
+ clearFormatting() {
543
+ this.editor()?.chain().focus().clearNodes().unsetAllMarks().run();
64
544
  }
65
- addImage(value) {
66
- const range = this.quillObj().getSelection();
67
- const currentIndex = range?.index;
68
- this.quillObj().insertEmbed(currentIndex, 'image', value);
545
+ execute(command, payload) {
546
+ switch (command) {
547
+ case 'bold':
548
+ this.toggleBold();
549
+ break;
550
+ case 'italic':
551
+ this.toggleItalic();
552
+ break;
553
+ case 'underline':
554
+ this.toggleUnderline();
555
+ break;
556
+ case 'strike':
557
+ this.toggleStrike();
558
+ break;
559
+ case 'code':
560
+ this.toggleCode();
561
+ break;
562
+ case 'codeBlock':
563
+ this.toggleCodeBlock();
564
+ break;
565
+ case 'heading':
566
+ if (typeof payload === 'number') {
567
+ this.toggleHeading(payload);
568
+ }
569
+ break;
570
+ case 'paragraph':
571
+ this.setParagraph();
572
+ break;
573
+ case 'bulletList':
574
+ this.toggleBulletList();
575
+ break;
576
+ case 'orderedList':
577
+ this.toggleOrderedList();
578
+ break;
579
+ case 'blockquote':
580
+ this.toggleBlockquote();
581
+ break;
582
+ case 'textAlign':
583
+ if (typeof payload === 'string') {
584
+ this.setTextAlign(payload);
585
+ }
586
+ break;
587
+ case 'direction':
588
+ if (payload === 'rtl' || payload === 'ltr') {
589
+ this.setTextDirection(payload);
590
+ }
591
+ break;
592
+ case 'fontSize':
593
+ if (payload === null) {
594
+ this.setFontSize(null);
595
+ }
596
+ else if (payload === 'small' || payload === 'large' || payload === 'huge') {
597
+ this.setFontSize(payload);
598
+ }
599
+ break;
600
+ case 'color':
601
+ if (typeof payload === 'string') {
602
+ this.setColor(payload);
603
+ }
604
+ else {
605
+ this.unsetColor();
606
+ }
607
+ break;
608
+ case 'highlight':
609
+ if (typeof payload === 'string') {
610
+ this.setHighlight(payload);
611
+ }
612
+ else {
613
+ this.unsetHighlight();
614
+ }
615
+ break;
616
+ case 'link':
617
+ if (typeof payload === 'string' && payload) {
618
+ this.setLink(payload);
619
+ }
620
+ else {
621
+ this.unsetLink();
622
+ }
623
+ break;
624
+ case 'image':
625
+ if (typeof payload === 'string') {
626
+ this.insertImage(payload);
627
+ }
628
+ break;
629
+ case 'video':
630
+ if (typeof payload === 'string') {
631
+ this.insertVideo(payload);
632
+ }
633
+ break;
634
+ case 'undo':
635
+ this.undo();
636
+ break;
637
+ case 'redo':
638
+ this.redo();
639
+ break;
640
+ case 'clearFormatting':
641
+ this.clearFormatting();
642
+ break;
643
+ }
69
644
  }
70
- focus() {
71
- this.quillObj().focus();
645
+ isActive(name, attrs) {
646
+ return this.editor()?.isActive(name, attrs) ?? false;
72
647
  }
73
- blur() {
74
- this.quillObj().blur();
648
+ can(command) {
649
+ const ed = this.editor();
650
+ if (!ed) {
651
+ return false;
652
+ }
653
+ if (command === 'undo') {
654
+ return ed.can().undo();
655
+ }
656
+ return ed.can().redo();
75
657
  }
76
- codeBlock(range, status) {
77
- if (!range)
658
+ setMarkActive(name, active) {
659
+ const ed = this.editor();
660
+ if (!ed) {
78
661
  return;
79
- this.quillObj().formatLine(range.index, range.length, 'code-block', status);
662
+ }
663
+ const chain = ed.chain().focus();
664
+ switch (name) {
665
+ case 'bold':
666
+ active ? chain.setBold().run() : chain.unsetBold().run();
667
+ break;
668
+ case 'italic':
669
+ active ? chain.setItalic().run() : chain.unsetItalic().run();
670
+ break;
671
+ case 'underline':
672
+ active ? chain.setUnderline().run() : chain.unsetUnderline().run();
673
+ break;
674
+ case 'strike':
675
+ active ? chain.setStrike().run() : chain.unsetStrike().run();
676
+ break;
677
+ }
80
678
  }
679
+ refreshState(editor) {
680
+ const textColor = editor.getAttributes('textStyle')['color'];
681
+ const fontSizeCss = editor.getAttributes('textStyle')['fontSize'];
682
+ const highlightColor = editor.getAttributes('highlight')['color'];
683
+ const linkHref = editor.getAttributes('link')['href'];
684
+ const dir = (editor.getAttributes('paragraph')['dir'] || editor.getAttributes('heading')['dir']);
685
+ let headingLevel = null;
686
+ for (let level = 1; level <= 6; level++) {
687
+ if (editor.isActive('heading', { level })) {
688
+ headingLevel = level;
689
+ break;
690
+ }
691
+ }
692
+ let textAlign = null;
693
+ for (const align of ['left', 'center', 'right', 'justify']) {
694
+ if (editor.isActive({ textAlign: align })) {
695
+ textAlign = align;
696
+ break;
697
+ }
698
+ }
699
+ let fontSize = null;
700
+ if (fontSizeCss) {
701
+ for (const [token, css] of Object.entries(AX_WYSIWYG_FONT_SIZE_VALUES)) {
702
+ if (fontSizeCss === css) {
703
+ fontSize = token;
704
+ break;
705
+ }
706
+ }
707
+ }
708
+ this.state.set({
709
+ bold: editor.isActive('bold'),
710
+ italic: editor.isActive('italic'),
711
+ underline: editor.isActive('underline'),
712
+ strike: editor.isActive('strike'),
713
+ code: editor.isActive('code'),
714
+ codeBlock: editor.isActive('codeBlock'),
715
+ headingLevel,
716
+ bulletList: editor.isActive('bulletList'),
717
+ orderedList: editor.isActive('orderedList'),
718
+ blockquote: editor.isActive('blockquote'),
719
+ textAlign,
720
+ textColor: textColor ?? null,
721
+ highlightColor: highlightColor ?? null,
722
+ linkHref: linkHref ?? null,
723
+ fontSize,
724
+ textDirection: dir ?? null,
725
+ canUndo: editor.can().undo(),
726
+ canRedo: editor.can().redo(),
727
+ isEmpty: editor.isEmpty,
728
+ isFocused: editor.isFocused,
729
+ });
730
+ }
731
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
732
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg }); }
81
733
  }
734
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: AXWysiwyg, decorators: [{
735
+ type: Injectable
736
+ }] });
737
+
738
+ /** @deprecated Use `@acorex/cdk/text-editor` and `@acorex/components/text-editor` instead. */
82
739
 
83
740
  /**
84
741
  * Generated bundle index. Do not edit.
85
742
  */
86
743
 
87
- export { AXWysiwyg };
744
+ export { AXWysiwyg, AX_DEFAULT_WYSIWYG_FEATURES, AX_EMPTY_WYSIWYG_STATE, loadAXWysiwygExtensions };
88
745
  //# sourceMappingURL=acorex-cdk-wysiwyg.mjs.map