@posiwise/utils 0.0.149 → 0.0.151

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,5 +1,392 @@
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, Directive, inject } from "@angular/core";
3
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
4
+ import { QuillEditorComponent } from "ngx-quill";
5
+ import { ActivatedRoute } from "@angular/router";
6
+ import { EditorImageUploadService, PermissionService } from "@posiwise/common-services";
7
+ import { TranslocoPipe, translate } from "@jsverse/transloco";
8
+ import { NgbActiveModal, NgbModal } from "@ng-bootstrap/ng-bootstrap";
9
+ import * as i1 from "@angular/forms";
10
+ import { FormsModule } from "@angular/forms";
11
+ import { ButtonBusyDirective } from "@posiwise/directives";
1
12
  import Quill from "quill";
2
13
  import * as ImageResize from "quill-resize-image";
14
+ const EMBED = "no-drag-image";
15
+ function outsideHistory(quill, change) {
16
+ const history = quill.getModule?.("history");
17
+ if (!history) {
18
+ change();
19
+ return;
20
+ }
21
+ history.ignoreChange = true;
22
+ let delta;
23
+ try {
24
+ delta = change();
25
+ } finally {
26
+ history.ignoreChange = false;
27
+ }
28
+ if (delta) history.transform(delta);
29
+ }
30
+ function indexOfImage(quill, url) {
31
+ let index = 0;
32
+ for (const op of quill.getContents().ops) {
33
+ const insert = op.insert;
34
+ if (typeof insert === "object" && insert?.[EMBED]?.url === url) return index;
35
+ index += typeof insert === "string" ? insert.length : 1;
36
+ }
37
+ return -1;
38
+ }
39
+ function showImagePreview(quill, index, file) {
40
+ if (typeof URL.createObjectURL !== "function") return null;
41
+ const local = URL.createObjectURL(file);
42
+ outsideHistory(quill, () => quill.insertEmbed(index, EMBED, { url: local }, Quill.sources.API));
43
+ outsideHistory(quill, () => quill.insertText(index + 1, "\n", Quill.sources.API));
44
+ return (url) => {
45
+ const at = indexOfImage(quill, local);
46
+ if (at >= 0) outsideHistory(quill, () => quill.deleteText(at, 1, Quill.sources.API));
47
+ URL.revokeObjectURL(local);
48
+ if (at < 0 || !url) return null;
49
+ quill.insertEmbed(at, EMBED, { url }, Quill.sources.USER);
50
+ return at + 2;
51
+ };
52
+ }
53
+ const HOST_CLASS = "ql-upload-host";
54
+ const CHIP_CLASS = "ql-upload-indicator";
55
+ function showUploadIndicator(quill, label = "") {
56
+ const container = quill.container ?? quill.root.parentElement;
57
+ const host = container?.parentElement;
58
+ if (!container || !host) return () => void 0;
59
+ host.classList.add(HOST_CLASS);
60
+ const doc = host.ownerDocument;
61
+ const chip = doc.createElement("div");
62
+ chip.className = CHIP_CLASS;
63
+ chip.setAttribute("role", "status");
64
+ const spinner = doc.createElement("i");
65
+ spinner.className = "fa fa-spinner fa-spin";
66
+ spinner.setAttribute("aria-hidden", "true");
67
+ chip.append(spinner, ` ${label}`);
68
+ chip.style.setProperty("--upload-top", `${container.offsetTop}px`);
69
+ host.append(chip);
70
+ return () => {
71
+ chip.remove();
72
+ if (!host.querySelector(`.${CHIP_CLASS}`)) host.classList.remove(HOST_CLASS);
73
+ };
74
+ }
75
+ const EDITOR_IMAGE_TYPES = [
76
+ "image/png",
77
+ "image/jpeg",
78
+ "image/gif",
79
+ "image/webp"
80
+ ];
81
+ function insertImageUrl(quill, index, url) {
82
+ quill.insertEmbed(index, "no-drag-image", { url }, Quill.sources.USER);
83
+ quill.insertText(index + 1, "\n", Quill.sources.USER);
84
+ }
85
+ async function uploadOne(quill, at, item, toUrl, busyLabel) {
86
+ const hide = showUploadIndicator(quill, busyLabel);
87
+ const settlePreview = item instanceof File ? showImagePreview(quill, at, item) : null;
88
+ let url;
89
+ try {
90
+ url = await toUrl(item).catch(() => null);
91
+ } finally {
92
+ hide();
93
+ }
94
+ if (settlePreview) return settlePreview(url) ?? at;
95
+ if (!url) return at;
96
+ insertImageUrl(quill, at, url);
97
+ return at + 2;
98
+ }
99
+ async function insertUploadedImages(quill, index, items, toUrl, busyLabel) {
100
+ let at = index;
101
+ quill.root.setAttribute("aria-busy", "true");
102
+ try {
103
+ for (const item of items) {
104
+ const next = await uploadOne(quill, at, item, toUrl, busyLabel);
105
+ if (next !== at) {
106
+ at = next;
107
+ quill.setSelection(at, Quill.sources.SILENT);
108
+ }
109
+ }
110
+ } finally {
111
+ quill.root.removeAttribute("aria-busy");
112
+ }
113
+ }
114
+ function pickImageFiles(onPicked, doc = document) {
115
+ const input = doc.createElement("input");
116
+ input.type = "file";
117
+ input.accept = EDITOR_IMAGE_TYPES.join(",");
118
+ input.multiple = true;
119
+ input.addEventListener("change", () => {
120
+ const files = Array.from(input.files ?? []);
121
+ if (files.length) onPicked(files);
122
+ });
123
+ input.click();
124
+ }
125
+ async function chooseImage(quill, options) {
126
+ const index = quill.getSelection(true)?.index ?? 0;
127
+ if (!options.choose) {
128
+ pickImageFiles((files) => insertUploadedImages(quill, index, files, options.upload, options.busyLabel?.()));
129
+ return;
130
+ }
131
+ const choice = await options.choose();
132
+ if (!choice) return;
133
+ if ("url" in choice) insertImageUrl(quill, index, choice.url);
134
+ else await insertUploadedImages(quill, index, choice.files, options.upload, options.busyLabel?.());
135
+ }
136
+ function imageUploaderModule(options) {
137
+ return {
138
+ mimetypes: EDITOR_IMAGE_TYPES,
139
+ handler(range, files) {
140
+ insertUploadedImages(this.quill, range.index, files, options.upload, options.busyLabel?.());
141
+ }
142
+ };
143
+ }
144
+ const DROP_CLASS = "ql-image-drop";
145
+ var ImageDropHint = class {
146
+ constructor(quill, options) {
147
+ const container = quill.container;
148
+ const show = (event) => {
149
+ if (Array.from(event.dataTransfer?.types ?? []).includes("Files")) {
150
+ container.setAttribute("data-drop-label", options?.label?.() ?? "");
151
+ container.classList.add(DROP_CLASS);
152
+ }
153
+ };
154
+ const hide = (event) => {
155
+ if (event.type === "drop" || !container.contains(event.relatedTarget)) container.classList.remove(DROP_CLASS);
156
+ };
157
+ container.addEventListener("dragenter", show);
158
+ container.addEventListener("dragover", show);
159
+ container.addEventListener("dragleave", hide);
160
+ container.addEventListener("drop", hide);
161
+ }
162
+ };
163
+ const LINK = /^https?:\/\/\S+$/i;
164
+ var EditorImageDialogComponent = class EditorImageDialogComponent {
165
+ constructor() {
166
+ this.modal = inject(NgbActiveModal);
167
+ this.cdr = inject(ChangeDetectorRef);
168
+ this.accept = EDITOR_IMAGE_TYPES.join(",");
169
+ this.link = "";
170
+ this.triedLink = false;
171
+ this.importing = false;
172
+ }
173
+ get linkValid() {
174
+ return LINK.test(this.link.trim());
175
+ }
176
+ async addLink() {
177
+ this.triedLink = true;
178
+ if (!this.linkValid || this.importing) return;
179
+ this.importing = true;
180
+ try {
181
+ const url = await this.importUrl(this.link.trim());
182
+ this.modal.close({ url });
183
+ } catch {} finally {
184
+ this.importing = false;
185
+ this.cdr.markForCheck();
186
+ }
187
+ }
188
+ filesPicked(input) {
189
+ const files = Array.from(input.files ?? []);
190
+ if (files.length) this.modal.close({ files });
191
+ }
192
+ static {
193
+ this.ɵfac = i0.ɵɵngDeclareFactory({
194
+ minVersion: "12.0.0",
195
+ version: "22.2.3",
196
+ ngImport: i0,
197
+ type: EditorImageDialogComponent,
198
+ deps: [],
199
+ target: i0.ɵɵFactoryTarget.Component
200
+ });
201
+ }
202
+ static {
203
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
204
+ minVersion: "17.0.0",
205
+ version: "22.2.3",
206
+ type: EditorImageDialogComponent,
207
+ isStandalone: true,
208
+ selector: "pw-editor-image-dialog",
209
+ ngImport: i0,
210
+ template: "<div class=\"pw-editor-image\">\n <div class=\"pw-editor-image__header\">\n <h5 class=\"pw-editor-image__title\" id=\"pw-editor-image-title\">{{ 'Common.Upload.Image.Title' | transloco }}</h5>\n <button type=\"button\"\n class=\"btn-close\"\n [disabled]=\"importing\"\n [attr.aria-label]=\"'Button.Cancel' | transloco\"\n (click)=\"modal.dismiss()\">\n </button>\n </div>\n\n <form class=\"pw-editor-image__link\" (ngSubmit)=\"addLink()\">\n <label class=\"form-label\" for=\"pw-editor-image-link\">{{ 'Common.Upload.Image.LinkLabel' | transloco }}</label>\n <div class=\"input-group\">\n <input id=\"pw-editor-image-link\"\n name=\"link\"\n type=\"url\"\n class=\"form-control\"\n autocomplete=\"off\"\n [readonly]=\"importing\"\n [class.is-invalid]=\"triedLink && !linkValid\"\n [placeholder]=\"'Common.Upload.Image.LinkPlaceholder' | transloco\"\n [(ngModel)]=\"link\">\n <button type=\"submit\" class=\"btn btn-primary\" [buttonBusy]=\"importing\">{{ 'Common.Upload.Image.Add' | transloco }}</button>\n </div>\n @if (triedLink && !linkValid) {\n <div class=\"invalid-feedback d-block\" role=\"alert\">{{ 'Common.Upload.Image.LinkInvalid' | transloco }}</div>\n }\n </form>\n\n <div class=\"pw-editor-image__or\">{{ 'Common.Upload.Image.Or' | transloco }}</div>\n\n <input #fileInput\n type=\"file\"\n class=\"d-none\"\n tabindex=\"-1\"\n [attr.aria-label]=\"'Common.Upload.Image.Upload' | transloco\"\n multiple\n [accept]=\"accept\"\n (change)=\"filesPicked(fileInput)\">\n <button type=\"button\" class=\"btn btn-outline-primary w-100\" [disabled]=\"importing\" (click)=\"fileInput.click()\">\n <i class=\"fa fa-upload\" aria-hidden=\"true\"></i>\n {{ 'Common.Upload.Image.Upload' | transloco }}\n </button>\n <p class=\"pw-editor-image__hint\">{{ 'Common.Upload.Image.Hint' | transloco }}</p>\n</div>\n",
211
+ styles: [".pw-editor-image{padding:24px}.pw-editor-image__header{display:flex;align-items:center;gap:12px;margin-bottom:20px}.pw-editor-image__title{flex:1;margin:0;font-size:16px;font-weight:600;color:var(--titles)}.pw-editor-image__or{display:flex;align-items:center;gap:12px;margin:20px 0;font-size:13px;color:var(--text)}.pw-editor-image__or:before,.pw-editor-image__or:after{content:\"\";flex:1;border-top:1px solid var(--bs-border-color)}.pw-editor-image__hint{margin:12px 0 0;font-size:13px;color:var(--text)}\n"],
212
+ dependencies: [
213
+ {
214
+ kind: "directive",
215
+ type: ButtonBusyDirective,
216
+ selector: "[buttonBusy]",
217
+ inputs: ["buttonBusy", "busyText"]
218
+ },
219
+ {
220
+ kind: "ngmodule",
221
+ type: FormsModule
222
+ },
223
+ {
224
+ kind: "directive",
225
+ type: i1.ɵNgNoValidate,
226
+ selector: "form:not([ngNoForm]):not([ngNativeValidate])"
227
+ },
228
+ {
229
+ kind: "directive",
230
+ type: i1.DefaultValueAccessor,
231
+ selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
232
+ },
233
+ {
234
+ kind: "directive",
235
+ type: i1.NgControlStatus,
236
+ selector: "[formControlName],[ngModel],[formControl]"
237
+ },
238
+ {
239
+ kind: "directive",
240
+ type: i1.NgControlStatusGroup,
241
+ selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]"
242
+ },
243
+ {
244
+ kind: "directive",
245
+ type: i1.NgModel,
246
+ selector: "[ngModel]:not([formControlName]):not([formControl])",
247
+ inputs: [
248
+ "name",
249
+ "disabled",
250
+ "ngModel",
251
+ "ngModelOptions"
252
+ ],
253
+ outputs: ["ngModelChange"],
254
+ exportAs: ["ngModel"]
255
+ },
256
+ {
257
+ kind: "directive",
258
+ type: i1.NgForm,
259
+ selector: "form:not([ngNoForm]):not([formGroup]):not([formArray]),ng-form,[ngForm]",
260
+ inputs: ["ngFormOptions"],
261
+ outputs: ["ngSubmit"],
262
+ exportAs: ["ngForm"]
263
+ },
264
+ {
265
+ kind: "pipe",
266
+ type: TranslocoPipe,
267
+ name: "transloco"
268
+ }
269
+ ],
270
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
271
+ });
272
+ }
273
+ };
274
+ i0.ɵɵngDeclareClassMetadata({
275
+ minVersion: "12.0.0",
276
+ version: "22.2.3",
277
+ ngImport: i0,
278
+ type: EditorImageDialogComponent,
279
+ decorators: [{
280
+ type: Component,
281
+ args: [{
282
+ selector: "pw-editor-image-dialog",
283
+ changeDetection: ChangeDetectionStrategy.OnPush,
284
+ imports: [
285
+ ButtonBusyDirective,
286
+ FormsModule,
287
+ TranslocoPipe
288
+ ],
289
+ template: "<div class=\"pw-editor-image\">\n <div class=\"pw-editor-image__header\">\n <h5 class=\"pw-editor-image__title\" id=\"pw-editor-image-title\">{{ 'Common.Upload.Image.Title' | transloco }}</h5>\n <button type=\"button\"\n class=\"btn-close\"\n [disabled]=\"importing\"\n [attr.aria-label]=\"'Button.Cancel' | transloco\"\n (click)=\"modal.dismiss()\">\n </button>\n </div>\n\n <form class=\"pw-editor-image__link\" (ngSubmit)=\"addLink()\">\n <label class=\"form-label\" for=\"pw-editor-image-link\">{{ 'Common.Upload.Image.LinkLabel' | transloco }}</label>\n <div class=\"input-group\">\n <input id=\"pw-editor-image-link\"\n name=\"link\"\n type=\"url\"\n class=\"form-control\"\n autocomplete=\"off\"\n [readonly]=\"importing\"\n [class.is-invalid]=\"triedLink && !linkValid\"\n [placeholder]=\"'Common.Upload.Image.LinkPlaceholder' | transloco\"\n [(ngModel)]=\"link\">\n <button type=\"submit\" class=\"btn btn-primary\" [buttonBusy]=\"importing\">{{ 'Common.Upload.Image.Add' | transloco }}</button>\n </div>\n @if (triedLink && !linkValid) {\n <div class=\"invalid-feedback d-block\" role=\"alert\">{{ 'Common.Upload.Image.LinkInvalid' | transloco }}</div>\n }\n </form>\n\n <div class=\"pw-editor-image__or\">{{ 'Common.Upload.Image.Or' | transloco }}</div>\n\n <input #fileInput\n type=\"file\"\n class=\"d-none\"\n tabindex=\"-1\"\n [attr.aria-label]=\"'Common.Upload.Image.Upload' | transloco\"\n multiple\n [accept]=\"accept\"\n (change)=\"filesPicked(fileInput)\">\n <button type=\"button\" class=\"btn btn-outline-primary w-100\" [disabled]=\"importing\" (click)=\"fileInput.click()\">\n <i class=\"fa fa-upload\" aria-hidden=\"true\"></i>\n {{ 'Common.Upload.Image.Upload' | transloco }}\n </button>\n <p class=\"pw-editor-image__hint\">{{ 'Common.Upload.Image.Hint' | transloco }}</p>\n</div>\n",
290
+ styles: [".pw-editor-image{padding:24px}.pw-editor-image__header{display:flex;align-items:center;gap:12px;margin-bottom:20px}.pw-editor-image__title{flex:1;margin:0;font-size:16px;font-weight:600;color:var(--titles)}.pw-editor-image__or{display:flex;align-items:center;gap:12px;margin:20px 0;font-size:13px;color:var(--text)}.pw-editor-image__or:before,.pw-editor-image__or:after{content:\"\";flex:1;border-top:1px solid var(--bs-border-color)}.pw-editor-image__hint{margin:12px 0 0;font-size:13px;color:var(--text)}\n"]
291
+ }]
292
+ }]
293
+ });
294
+ function openEditorImageDialog(modal, importUrl) {
295
+ const ref = modal.open(EditorImageDialogComponent, {
296
+ centered: true,
297
+ size: "md",
298
+ beforeDismiss: () => !dialog?.importing
299
+ });
300
+ const dialog = ref.componentInstance;
301
+ dialog.importUrl = importUrl;
302
+ return ref.result.then((choice) => choice ?? null, () => null);
303
+ }
304
+ function defaultImageUpload() {
305
+ let route;
306
+ try {
307
+ route = inject(ActivatedRoute, { optional: true });
308
+ } catch {
309
+ return;
310
+ }
311
+ return editorImageUpload(() => uploadSubscriptionId(route));
312
+ }
313
+ function editorImageUpload(subscriptionId) {
314
+ let service;
315
+ let modal;
316
+ try {
317
+ service = inject(EditorImageUploadService, { optional: true });
318
+ modal = inject(NgbModal, { optional: true });
319
+ } catch {
320
+ return;
321
+ }
322
+ if (!service) return;
323
+ const { upload, importUrl } = service.forSubscription(subscriptionId);
324
+ return {
325
+ upload,
326
+ importUrl,
327
+ choose: modal ? () => openEditorImageDialog(modal, importUrl) : void 0,
328
+ dropLabel: () => translate("Common.Upload.Image.Drop"),
329
+ busyLabel: () => translate("Common.Upload.Image.Uploading")
330
+ };
331
+ }
332
+ function uploadSubscriptionId(route) {
333
+ const selected = PermissionService.selectedSubscription;
334
+ const path = route?.snapshot?.pathFromRoot ?? [];
335
+ const firstSegment = path.flatMap((r) => r.url ?? []).map((segment) => segment.path)[0];
336
+ const slug = path.map((r) => r.params?.["slug"]).find((value) => value && value === firstSegment);
337
+ if (slug && selected?.slug !== slug) return;
338
+ return selected?.id;
339
+ }
340
+ const EXTERNAL = /^https?:\/\//i;
341
+ function isOwnImage(src) {
342
+ return src.startsWith("/") || /\/editor_images\/\d+\//.test(src);
343
+ }
344
+ function needsImport(src) {
345
+ return !!src && EXTERNAL.test(src) && !isOwnImage(src);
346
+ }
347
+ function droppedImageLinks(data) {
348
+ const html = data?.getData("text/html");
349
+ if (html) {
350
+ const doc = new DOMParser().parseFromString(html, "text/html");
351
+ const srcs = Array.from(doc.images, (img) => img.getAttribute("src")).filter(needsImport);
352
+ if (srcs.length) return srcs;
353
+ }
354
+ const link = data?.getData("text/uri-list")?.split("\n")[0]?.trim();
355
+ return needsImport(link) ? [link] : [];
356
+ }
357
+ var ImageLinkImport = class {
358
+ constructor(quill, options) {
359
+ this.quill = quill;
360
+ this.options = options;
361
+ this.pending = [];
362
+ if (!options?.importUrl) return;
363
+ const Delta = Quill.import("delta");
364
+ quill.clipboard.addMatcher("IMG", (node, delta) => {
365
+ const src = node instanceof Element ? node.getAttribute("src") : null;
366
+ if (!needsImport(src)) return delta;
367
+ this.pending.push(src);
368
+ return new Delta();
369
+ });
370
+ quill.root.addEventListener("paste", () => setTimeout(() => this.importPending(), 0));
371
+ quill.root.addEventListener("drop", (event) => this.onDrop(event));
372
+ }
373
+ importPending() {
374
+ const links = this.pending.splice(0);
375
+ if (links.length) this.insert(links);
376
+ }
377
+ onDrop(event) {
378
+ if (event.dataTransfer?.files?.length) return;
379
+ const links = droppedImageLinks(event.dataTransfer);
380
+ if (links.length) {
381
+ event.preventDefault();
382
+ this.insert(links);
383
+ }
384
+ }
385
+ insert(links) {
386
+ const index = this.quill.getSelection(true)?.index ?? this.quill.getLength();
387
+ insertUploadedImages(this.quill, index, links, this.options.importUrl, this.options.busyLabel?.());
388
+ }
389
+ };
3
390
  const DATA_URI_IMAGE = /^data:image\//i;
4
391
  const PASTED_IMAGE_MESSAGE = "That image was pasted, so it would be stored inside the article itself rather than on the image host — which makes the page much heavier for every reader. Upload the image somewhere first, then use the image button in the toolbar to add it by URL.";
5
392
  function clipboardHasImageFile(clipboardData) {
@@ -13,6 +400,7 @@ function isEmbeddedImageSrc(src) {
13
400
  var PasteGuard = class {
14
401
  constructor(quill, options) {
15
402
  this.notify = options?.onBlocked ?? ((message) => globalThis.alert?.(message));
403
+ this.allowImageFiles = options?.allowImageFiles ?? false;
16
404
  quill.root.addEventListener("paste", (event) => this.handlePaste(event), true);
17
405
  const Delta = Quill.import("delta");
18
406
  quill.clipboard.addMatcher("IMG", (node, delta) => {
@@ -22,12 +410,71 @@ var PasteGuard = class {
22
410
  });
23
411
  }
24
412
  handlePaste(event) {
25
- if (!clipboardHasImageFile(event.clipboardData)) return;
413
+ if (this.allowImageFiles || !clipboardHasImageFile(event.clipboardData)) return;
26
414
  event.preventDefault();
27
415
  event.stopPropagation();
28
416
  this.notify(PASTED_IMAGE_MESSAGE);
29
417
  }
30
418
  };
419
+ var EditorImageUploadDirective = class EditorImageUploadDirective {
420
+ constructor() {
421
+ this.editor = inject(QuillEditorComponent, { self: true });
422
+ this.destroyRef = inject(DestroyRef);
423
+ this.options = defaultImageUpload();
424
+ }
425
+ ngOnInit() {
426
+ if (!this.options) return;
427
+ this.editor.onEditorCreated.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((quill) => wireImageUpload(quill, this.options));
428
+ }
429
+ static {
430
+ this.ɵfac = i0.ɵɵngDeclareFactory({
431
+ minVersion: "12.0.0",
432
+ version: "22.2.3",
433
+ ngImport: i0,
434
+ type: EditorImageUploadDirective,
435
+ deps: [],
436
+ target: i0.ɵɵFactoryTarget.Directive
437
+ });
438
+ }
439
+ static {
440
+ this.ɵdir = i0.ɵɵngDeclareDirective({
441
+ minVersion: "14.0.0",
442
+ version: "22.2.3",
443
+ type: EditorImageUploadDirective,
444
+ isStandalone: true,
445
+ selector: "[pwEditorImages]",
446
+ ngImport: i0
447
+ });
448
+ }
449
+ };
450
+ i0.ɵɵngDeclareClassMetadata({
451
+ minVersion: "12.0.0",
452
+ version: "22.2.3",
453
+ ngImport: i0,
454
+ type: EditorImageUploadDirective,
455
+ decorators: [{
456
+ type: Directive,
457
+ args: [{
458
+ selector: "[pwEditorImages]",
459
+ standalone: true
460
+ }]
461
+ }]
462
+ });
463
+ function wireImageUpload(quill, options) {
464
+ const editor = quill;
465
+ quill.getModule("toolbar")?.addHandler("image", () => chooseImage(editor, options));
466
+ const uploader = quill.getModule("uploader");
467
+ if (uploader) {
468
+ uploader.options.mimetypes = EDITOR_IMAGE_TYPES;
469
+ uploader.options.handler = imageUploaderModule(options).handler;
470
+ }
471
+ new PasteGuard(quill, { allowImageFiles: true });
472
+ new ImageDropHint(quill, { label: options.dropLabel });
473
+ new ImageLinkImport(quill, {
474
+ importUrl: options.importUrl,
475
+ busyLabel: options.busyLabel
476
+ });
477
+ }
31
478
  const BlockEmbed = Quill.import("formats/image");
32
479
  var NoDragImage = class extends BlockEmbed {
33
480
  static create(value) {
@@ -102,6 +549,111 @@ NoDragImage["tagName"] = "img";
102
549
  Quill.register(NoDragImage);
103
550
  Quill.register("modules/noDragDrop", NoDragDrop);
104
551
  Quill.register("modules/imageResize", ImageResize.default || ImageResize);
552
+ function createAlignButtons(container) {
553
+ const buttonContainer = document.createElement("div");
554
+ buttonContainer.setAttribute("class", "media-align-buttons");
555
+ buttonContainer.style.position = "absolute";
556
+ buttonContainer.style.top = "0";
557
+ buttonContainer.style.right = "0";
558
+ buttonContainer.style.display = "flex";
559
+ buttonContainer.setAttribute("contenteditable", "false");
560
+ const leftButton = createButton("Left", () => {
561
+ container.style.textAlign = "left";
562
+ container.setAttribute("data-align", "left");
563
+ });
564
+ const centerButton = createButton("Center", () => {
565
+ container.style.textAlign = "center";
566
+ container.setAttribute("data-align", "center");
567
+ });
568
+ const rightButton = createButton("Right", () => {
569
+ container.style.textAlign = "right";
570
+ container.setAttribute("data-align", "right");
571
+ });
572
+ buttonContainer.appendChild(leftButton);
573
+ buttonContainer.appendChild(centerButton);
574
+ buttonContainer.appendChild(rightButton);
575
+ return buttonContainer;
576
+ }
577
+ function createRemoveButton(container) {
578
+ const wrapper = document.createElement("div");
579
+ wrapper.setAttribute("class", "media-remove-button");
580
+ wrapper.style.position = "absolute";
581
+ wrapper.style.top = "0";
582
+ wrapper.style.left = "0";
583
+ wrapper.style.display = "flex";
584
+ wrapper.setAttribute("contenteditable", "false");
585
+ const removeButton = createButton("Remove", () => {
586
+ const mediaContainer = container.classList.contains("media-container") ? container : container.closest(".media-container");
587
+ if (mediaContainer) {
588
+ const blot = Quill.find(mediaContainer);
589
+ if (blot && "remove" in blot && typeof blot.remove === "function") blot.remove();
590
+ else mediaContainer.remove();
591
+ }
592
+ });
593
+ removeButton.style.background = "rgb(243, 67, 67)";
594
+ removeButton.style.color = "white";
595
+ removeButton.style.border = "none";
596
+ removeButton.style.padding = "2px 8px";
597
+ removeButton.style.marginTop = "2px";
598
+ removeButton.style.borderRadius = "4px";
599
+ removeButton.title = "Remove video";
600
+ wrapper.appendChild(removeButton);
601
+ return wrapper;
602
+ }
603
+ function createResizeButtons(container) {
604
+ const buttonContainer = document.createElement("div");
605
+ buttonContainer.setAttribute("class", "media-resize-buttons");
606
+ buttonContainer.style.position = "absolute";
607
+ buttonContainer.style.bottom = "5px";
608
+ buttonContainer.style.right = "5px";
609
+ buttonContainer.style.display = "flex";
610
+ buttonContainer.setAttribute("contenteditable", "false");
611
+ const updateWidthAndHeight = (mediaElement, width, height) => {
612
+ mediaElement.style.width = width;
613
+ mediaElement.style.height = height;
614
+ container.setAttribute("data-width", width);
615
+ container.setAttribute("data-height", height);
616
+ };
617
+ const increaseWidthButton = createButton("Increase Width", () => {
618
+ const mediaElement = container.querySelector(".no-drag-media");
619
+ const currentWidth = parseInt(mediaElement.style.width || "100%");
620
+ updateWidthAndHeight(mediaElement, `${currentWidth + 20}px`, mediaElement.style.height);
621
+ });
622
+ const decreaseWidthButton = createButton("Decrease Width", () => {
623
+ const mediaElement = container.querySelector(".no-drag-media");
624
+ const currentWidth = parseInt(mediaElement.style.width || "100%");
625
+ updateWidthAndHeight(mediaElement, `${Math.max(100, currentWidth - 20)}px`, mediaElement.style.height);
626
+ });
627
+ const increaseHeightButton = createButton("Increase Height", () => {
628
+ const mediaElement = container.querySelector(".no-drag-media");
629
+ const currentHeight = parseInt(mediaElement.style.height || "200px");
630
+ updateWidthAndHeight(mediaElement, mediaElement.style.width, `${currentHeight + 20}px`);
631
+ });
632
+ const decreaseHeightButton = createButton("Decrease Height", () => {
633
+ const mediaElement = container.querySelector(".no-drag-media");
634
+ const currentHeight = parseInt(mediaElement.style.height || "200px");
635
+ updateWidthAndHeight(mediaElement, mediaElement.style.width, `${Math.max(100, currentHeight - 20)}px`);
636
+ });
637
+ buttonContainer.appendChild(increaseWidthButton);
638
+ buttonContainer.appendChild(decreaseWidthButton);
639
+ buttonContainer.appendChild(increaseHeightButton);
640
+ buttonContainer.appendChild(decreaseHeightButton);
641
+ return buttonContainer;
642
+ }
643
+ function createButton(label, onClick) {
644
+ const button = document.createElement("button");
645
+ button.innerHTML = label;
646
+ button.style.margin = "0 5px";
647
+ button.style.cursor = "pointer";
648
+ button.setAttribute("contenteditable", "false");
649
+ button.style.pointerEvents = "auto";
650
+ button.onclick = (event) => {
651
+ event.preventDefault();
652
+ event.stopPropagation();
653
+ onClick();
654
+ };
655
+ return button;
656
+ }
105
657
  const BlockEmbedVideo = Quill.import("blots/block/embed");
106
658
  var NoDragVideo = class extends BlockEmbedVideo {
107
659
  static create(value) {
@@ -133,128 +685,23 @@ var NoDragVideo = class extends BlockEmbedVideo {
133
685
  container.style.height = "auto";
134
686
  container.appendChild(node);
135
687
  if (!container.querySelector(".media-remove-button")) {
136
- const removeButton = this.createRemoveButton(container);
688
+ const removeButton = createRemoveButton(container);
137
689
  removeButton.setAttribute("contenteditable", "false");
138
690
  container.appendChild(removeButton);
139
691
  }
140
692
  if (!container.querySelector(".media-align-buttons")) {
141
- const alignButtons = this.createAlignButtons(container);
693
+ const alignButtons = createAlignButtons(container);
142
694
  alignButtons.setAttribute("contenteditable", "false");
143
695
  container.appendChild(alignButtons);
144
696
  }
145
697
  if (!container.querySelector(".media-resize-buttons")) {
146
- const resizeButtons = this.createResizeButtons(container);
698
+ const resizeButtons = createResizeButtons(container);
147
699
  resizeButtons.setAttribute("contenteditable", "false");
148
700
  container.appendChild(resizeButtons);
149
701
  }
150
702
  container.setAttribute("contenteditable", "false");
151
703
  return container;
152
704
  }
153
- static createAlignButtons(container) {
154
- const buttonContainer = document.createElement("div");
155
- buttonContainer.setAttribute("class", "media-align-buttons");
156
- buttonContainer.style.position = "absolute";
157
- buttonContainer.style.top = "0";
158
- buttonContainer.style.right = "0";
159
- buttonContainer.style.display = "flex";
160
- buttonContainer.setAttribute("contenteditable", "false");
161
- const leftButton = this.createButton("Left", () => {
162
- container.style.textAlign = "left";
163
- container.setAttribute("data-align", "left");
164
- });
165
- const centerButton = this.createButton("Center", () => {
166
- container.style.textAlign = "center";
167
- container.setAttribute("data-align", "center");
168
- });
169
- const rightButton = this.createButton("Right", () => {
170
- container.style.textAlign = "right";
171
- container.setAttribute("data-align", "right");
172
- });
173
- buttonContainer.appendChild(leftButton);
174
- buttonContainer.appendChild(centerButton);
175
- buttonContainer.appendChild(rightButton);
176
- return buttonContainer;
177
- }
178
- static createRemoveButton(container) {
179
- const wrapper = document.createElement("div");
180
- wrapper.setAttribute("class", "media-remove-button");
181
- wrapper.style.position = "absolute";
182
- wrapper.style.top = "0";
183
- wrapper.style.left = "0";
184
- wrapper.style.display = "flex";
185
- wrapper.setAttribute("contenteditable", "false");
186
- const removeButton = this.createButton("Remove", () => {
187
- const mediaContainer = container.classList.contains("media-container") ? container : container.closest(".media-container");
188
- if (mediaContainer) {
189
- const blot = Quill.find(mediaContainer);
190
- if (blot && "remove" in blot && typeof blot.remove === "function") blot.remove();
191
- else mediaContainer.remove();
192
- }
193
- });
194
- removeButton.style.background = "rgb(243, 67, 67)";
195
- removeButton.style.color = "white";
196
- removeButton.style.border = "none";
197
- removeButton.style.padding = "2px 8px";
198
- removeButton.style.marginTop = "2px";
199
- removeButton.style.borderRadius = "4px";
200
- removeButton.title = "Remove video";
201
- wrapper.appendChild(removeButton);
202
- return wrapper;
203
- }
204
- static createResizeButtons(container) {
205
- const buttonContainer = document.createElement("div");
206
- buttonContainer.setAttribute("class", "media-resize-buttons");
207
- buttonContainer.style.position = "absolute";
208
- buttonContainer.style.bottom = "5px";
209
- buttonContainer.style.right = "5px";
210
- buttonContainer.style.display = "flex";
211
- buttonContainer.setAttribute("contenteditable", "false");
212
- const updateWidthAndHeight = (mediaElement, width, height) => {
213
- mediaElement.style.width = width;
214
- mediaElement.style.height = height;
215
- container.setAttribute("data-width", width);
216
- container.setAttribute("data-height", height);
217
- };
218
- const increaseWidthButton = this.createButton("Increase Width", () => {
219
- const mediaElement = container.querySelector(".no-drag-media");
220
- const currentWidth = parseInt(mediaElement.style.width || "100%");
221
- updateWidthAndHeight(mediaElement, `${currentWidth + 20}px`, mediaElement.style.height);
222
- });
223
- const decreaseWidthButton = this.createButton("Decrease Width", () => {
224
- const mediaElement = container.querySelector(".no-drag-media");
225
- const currentWidth = parseInt(mediaElement.style.width || "100%");
226
- updateWidthAndHeight(mediaElement, `${Math.max(100, currentWidth - 20)}px`, mediaElement.style.height);
227
- });
228
- const increaseHeightButton = this.createButton("Increase Height", () => {
229
- const mediaElement = container.querySelector(".no-drag-media");
230
- const currentHeight = parseInt(mediaElement.style.height || "200px");
231
- updateWidthAndHeight(mediaElement, mediaElement.style.width, `${currentHeight + 20}px`);
232
- });
233
- const decreaseHeightButton = this.createButton("Decrease Height", () => {
234
- const mediaElement = container.querySelector(".no-drag-media");
235
- const currentHeight = parseInt(mediaElement.style.height || "200px");
236
- updateWidthAndHeight(mediaElement, mediaElement.style.width, `${Math.max(100, currentHeight - 20)}px`);
237
- });
238
- buttonContainer.appendChild(increaseWidthButton);
239
- buttonContainer.appendChild(decreaseWidthButton);
240
- buttonContainer.appendChild(increaseHeightButton);
241
- buttonContainer.appendChild(decreaseHeightButton);
242
- return buttonContainer;
243
- }
244
- static createButton(label, onClick) {
245
- const button = document.createElement("button");
246
- button.innerHTML = label;
247
- button.style.margin = "0 5px";
248
- button.style.cursor = "pointer";
249
- button.setAttribute("contenteditable", "false");
250
- button.style.pointerEvents = "auto";
251
- button.onclick = (event) => {
252
- event.preventDefault();
253
- event.stopPropagation();
254
- onClick();
255
- };
256
- return button;
257
- }
258
705
  static value(container) {
259
706
  const iframe = container.querySelector("iframe");
260
707
  return {
@@ -275,8 +722,10 @@ var QuillHelper = class {
275
722
  if (!Quill.imports["modules/imageResize"]) Quill.register("modules/imageResize", ImageResize.default || ImageResize);
276
723
  if (!Quill.imports["modules/noDragDrop"]) Quill.register("modules/noDragDrop", NoDragDrop);
277
724
  if (!Quill.imports["modules/pasteGuard"]) Quill.register("modules/pasteGuard", PasteGuard);
725
+ if (!Quill.imports["modules/imageDropHint"]) Quill.register("modules/imageDropHint", ImageDropHint);
726
+ if (!Quill.imports["modules/imageLinkImport"]) Quill.register("modules/imageLinkImport", ImageLinkImport);
278
727
  }
279
- static getEditorConfig(additionalToolbarConfig = []) {
728
+ static getEditorConfig(additionalToolbarConfig = [], imageUpload = defaultImageUpload()) {
280
729
  return {
281
730
  toolbar: {
282
731
  container: [...[
@@ -313,6 +762,10 @@ var QuillHelper = class {
313
762
  ], ...additionalToolbarConfig],
314
763
  handlers: {
315
764
  image: function() {
765
+ if (imageUpload) {
766
+ chooseImage(this.quill, imageUpload);
767
+ return;
768
+ }
316
769
  const range = this.quill.getSelection();
317
770
  const value = prompt("Enter image URL:");
318
771
  if (value) {
@@ -345,11 +798,21 @@ var QuillHelper = class {
345
798
  }
346
799
  },
347
800
  imageResize: { displaySize: true },
348
- noDragDrop: true,
349
- pasteGuard: true
801
+ ...imageUpload ? {
802
+ uploader: imageUploaderModule(imageUpload),
803
+ imageDropHint: { label: imageUpload.dropLabel },
804
+ imageLinkImport: {
805
+ importUrl: imageUpload.importUrl,
806
+ busyLabel: imageUpload.busyLabel
807
+ },
808
+ pasteGuard: { allowImageFiles: true }
809
+ } : {
810
+ noDragDrop: true,
811
+ pasteGuard: true
812
+ }
350
813
  };
351
814
  }
352
815
  };
353
- export { PASTED_IMAGE_MESSAGE, PasteGuard, QuillHelper, clipboardHasImageFile, isEmbeddedImageSrc };
816
+ export { EDITOR_IMAGE_TYPES, EditorImageUploadDirective, ImageDropHint, PASTED_IMAGE_MESSAGE, PasteGuard, QuillHelper, chooseImage, clipboardHasImageFile, editorImageUpload, imageUploaderModule, insertUploadedImages, isEmbeddedImageSrc, pickImageFiles, wireImageUpload };
354
817
 
355
818
  //# sourceMappingURL=posiwise-utils-quill.mjs.map