@innovastudio/contentbuilder 1.5.227 → 1.5.229

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.
package/index.d.ts CHANGED
@@ -34,6 +34,12 @@ interface ContentBuilderOptions {
34
34
  livePreviewReloadEvery?: number;
35
35
  scriptPath?: string;
36
36
  plugins?: any[];
37
+ /** Add-ons: objects returned by an add-on factory, e.g.
38
+ * `addons: [Typography()]`. Each add-on adds editor features through
39
+ * the add-on API. */
40
+ addons?: ContentBuilderAddon[];
41
+ /** Set by ContentBox: host services for add-ons, e.g. `{ codechat: () => codechat }`. */
42
+ addonServices?: { codechat?: () => any } | null;
37
43
  pluginPath?: string;
38
44
  disableConfig?: boolean;
39
45
  modulePath?: string;
@@ -139,6 +145,8 @@ interface ContentBuilderOptions {
139
145
  imageResize?: boolean;
140
146
  /** Show the floating image tool on a selected image. Default true. */
141
147
  imageTool?: boolean;
148
+ /** Show the Style button (aspect ratio, border radius, hover effects, duration) on the image tool. Default true. */
149
+ imageStyle?: boolean;
142
150
  imageselect?: string;
143
151
  fileselect?: string;
144
152
  videoselect?: string;
@@ -423,6 +431,248 @@ interface ContentBuilderOptions {
423
431
  //---
424
432
  }
425
433
 
434
+ /** An add-on, as returned by an add-on factory. */
435
+ interface ContentBuilderAddon {
436
+ /** Unique name. */
437
+ name: string;
438
+ version?: string;
439
+ /** Add-on API major version it was built for, e.g. '1'. */
440
+ requires?: string;
441
+ /** Called once per editor. May return a teardown function, called on destroy(). */
442
+ setup(api: ContentBuilderAddonApi): void | (() => void) | Promise<void | (() => void)>;
443
+ }
444
+
445
+ /** The open Kanvas editor, as an add-on gets it (api.kanvas.onOpen). */
446
+ interface ContentBuilderKanvas {
447
+ /** Rectangle, Lasso and Brush in the dialog's top bar; `bar` floats under the selection while
448
+ * there is one. Drawing again replaces the selection (the brush paints onto it). bounds and
449
+ * mask are in pixels of renderResult(); message() shows an error next to the tools. */
450
+ selectionTools(opts?: { bar?: HTMLElement }): {
451
+ exists(): boolean;
452
+ bounds(padding?: number): { x: number; y: number; width: number; height: number } | null;
453
+ mask(opts?: { region?: { x: number; y: number; width: number; height: number }; feather?: number; invert?: boolean }): HTMLCanvasElement;
454
+ onChange(fn: () => void): void;
455
+ clear(): void;
456
+ lock(on: boolean): void;
457
+ message(text: string | null, isError?: boolean): void;
458
+ destroy(): void };
459
+ /** The current result, every edit applied, at full resolution. */
460
+ renderResult(): HTMLCanvasElement;
461
+ /** Show an image in place of the result without committing it; null shows the result again. */
462
+ showPreview(image: CanvasImageSource | null): void;
463
+ /** Make an image the photo being edited, as one undo step. */
464
+ replaceImage(image: CanvasImageSource | Blob): Promise<void>;
465
+ toast(text: string): void;
466
+ }
467
+
468
+ /** What an add-on can use. One per editor and add-on. */
469
+ interface ContentBuilderAddonApi {
470
+ readonly version: number;
471
+ readonly name: string;
472
+ readonly host: 'contentbuilder' | 'contentbox';
473
+ /** Builder options an add-on may read (endpoints, image models, ...). */
474
+ readonly options: Readonly<Record<string, any>>;
475
+ /** Translate a label through the editor's language file. */
476
+ out(text: string): string;
477
+ hooks: {
478
+ /** Add a hook; returns a function that removes it.
479
+ * 'paste' (synchronous): ({ html, text }) => ({ html, text }), before pasted HTML is inserted. */
480
+ add(name: 'paste', fn: (value: { html: string; text: string }) => { html: string; text: string } | void): () => void;
481
+ /** 'beforeUpload' (may be async): every upload passes through it before it reaches the
482
+ * upload handler. Return the file to upload (the same one to leave it unchanged).
483
+ * kind is the handler the editor picked. */
484
+ add(name: 'beforeUpload', fn: (file: File, info: { kind: 'image' | 'video' | 'audio' | 'media' | 'file' }) => File | Blob | void | Promise<File | Blob | void>): () => void;
485
+ };
486
+ ui: {
487
+ /** A button. place 'text' (default): the text tools (ContentBuilder: the text toolbar's More
488
+ * panel; ContentBox: the Text panel); `group` puts it in the Insert, AI or Tools menu there,
489
+ * `on` adds copies where there is no caret ('element': the element toolbar, 'svg': beside a
490
+ * selected drawing, 'rows': while blocks are marked). place 'image': the image toolbar,
491
+ * shown only for images `when(img)` accepts. place 'svg': the small tool beside a selected
492
+ * drawing or `data-cb-object` block, shown only for elements `when(el)` accepts. place
493
+ * 'box' (ContentBox): the Box panel. onClick gets that element (the box for 'box').
494
+ * hides: the tool's own buttons to hide for those elements (image: 'edit', 'change',
495
+ * 'link', 'style'; svg: 'settings'). */
496
+ addButton(def: { id?: string; place?: 'text' | 'image' | 'svg' | 'box'; title: string; html: string; onClick: (e: MouseEvent, target?: HTMLImageElement | SVGSVGElement | HTMLElement) => void; pos?: number; when?: (el: HTMLImageElement | SVGSVGElement | HTMLElement) => boolean; hides?: ('edit' | 'change' | 'link' | 'style' | 'settings')[]; on?: ('svg' | 'element' | 'rows')[]; group?: 'insert' | 'ai' | 'tools'; menuTitle?: string }): HTMLElement | null;
497
+ /** The items other add-ons put in a menu of the More panel, in order. title is the
498
+ * name shown in the menu; run() does what a click does. This add-on's own items are
499
+ * left out. */
500
+ menuItems(group: 'insert' | 'ai' | 'tools'): { id: string; title: string; html: string; run(): void }[];
501
+ /** The add-on's own CSS, added once, removed with the last editor. Scope rules under [data-cb-ui]. */
502
+ addStyles(css: string): void;
503
+ /** A plain dialog in the editor's own shell (focus, Escape, drag). */
504
+ openDialog(opts: { title: string; body: string | HTMLElement; actions?: { label: string; primary?: boolean; onClick?: (dialog: { close(): void }) => void }[]; onClose?: () => void; width?: string }): { element: HTMLElement; body: HTMLElement; close(): void; button(index: number): HTMLButtonElement };
505
+ /** A small panel tied to a spot in the content (a caret range or an element): under it, or above when there is no room, following it as the page scrolls. Tab and Shift+Tab go round its controls. Escape closes it and puts the caret back; a press outside closes it unless closeOnOutside is false. */
506
+ openPopover(opts: { anchor: Range | Element; body: string | HTMLElement; label?: string; width?: string; closeOnOutside?: boolean; onClose?: (reason: 'escape' | 'outside' | 'close' | 'editor') => void }): { element: HTMLElement; body: HTMLElement; close(reason?: string): void; reposition(): void };
507
+ /** Runs instead of the table toolbar's own Table Settings dialog (the cog). Returns a function that gives the cog back. */
508
+ tableSettings(fn: (target: { table: HTMLTableElement; cell: HTMLTableCellElement }) => void): () => void;
509
+ /** Be the editor's icon picker: the editor's own add-an-icon buttons (text toolbar, ContentBox's Text panel) are hidden, Icon leaves content.blocks(), and every other way to an icon calls fn instead of the built-in icon window: { icon } to change a clicked icon (a font icon <i> or an add-on's <svg>), { place } for the quick add panel's Icon (place(html) puts html on a new line there), else { range } (the caret, or null). Returns a function that gives the editor its own picker back. */
510
+ iconPicker(fn: (target: { icon: Element | null; place: ((html: string) => void) | null; range: Range | null }) => void): () => void;
511
+ /** The editor's colour picker; onPick runs on every change ('' = no colour). */
512
+ pickColor(opts: { color?: string; onPick?: (color: string) => void; onClose?: () => void }): boolean;
513
+ /** Quiet editing: true hides the tools always shown in the page (row, column, element and
514
+ * section tools, and the outlines), so the page is seen as it is published; a clicked
515
+ * object (image, link, spacer, table, plugin, video) still gets its own tool. With
516
+ * { all: true } the editor's bars and panels go too (text toolbar, snippet panel,
517
+ * ContentBox's side bar and control panel), the page takes the window, and an object's
518
+ * settings open in ContentBuilder's floating tools instead of the panel; formatting
519
+ * stays on the keyboard. false shows them again. Each editor on a page has its own.
520
+ * Turned off when the add-on is removed. */
521
+ setQuiet(on: boolean, opts?: { all?: boolean }): void;
522
+ /** Whether quiet editing is on in this editor. */
523
+ isQuiet(): boolean;
524
+ /** The editor's own icon, as markup, so an add-on's buttons look like the editor's:
525
+ * 'bold', 'italic', 'underline', 'strikethrough', 'clean', 'link', 'unlink', 'up',
526
+ * 'down', 'duplicate', 'delete', 'settings'. '' for another name. */
527
+ icon(name: string): string;
528
+ /** Hide the element tool (add, more, delete, settings beside a clicked element), for an
529
+ * add-on that offers the same another way; as the Preferences' "hide element tool".
530
+ * Returns a function that shows it again; also shown again when the add-on is removed. */
531
+ hideElementTool(): () => void;
532
+ /** List what was found, grouped, before anything changes. Each row shows the spot
533
+ * in its sentence (from struck, to marked); a click shows it in the page. onApply
534
+ * gets the rows left ticked. With nothing found it still opens and shows `empty`. */
535
+ review(opts: {
536
+ title?: string;
537
+ /** A change { range, from, to } has a tick box; an issue { element or range, text, note,
538
+ * thumb, input, choice } explains a problem and can take a fix (item.value, item.chosen). */
539
+ groups: { label: string; description?: string; items: ({ range: Range; from: string; to: string; [key: string]: any } | { element?: Element; range?: Range; text: string; note?: string; thumb?: string; input?: { label: string; placeholder?: string }; choice?: { label: string }; [key: string]: any })[] }[];
540
+ /** The line above the list. */
541
+ intro?: string;
542
+ /** What to say when nothing was found. */
543
+ empty?: string;
544
+ applyLabel?: string;
545
+ /** The ticked changes, and the issues filled in (item.value typed or item.chosen ticked). */
546
+ onApply(items: any[]): void;
547
+ }): void;
548
+ };
549
+ /** Kanvas, the image editor (imageEditor: 'kanvas'). */
550
+ kanvas: {
551
+ /** fn(kanvas) runs each time a Kanvas dialog opens, with the open editor. Returns a function
552
+ * that stops it. */
553
+ onOpen(fn: (kanvas: ContentBuilderKanvas) => void): () => void;
554
+ };
555
+ /** AI requests through the editor's own AI set-up: the routes, provider and image model the host
556
+ * configured (the same ones Code Chat uses). */
557
+ ai: {
558
+ /** The image models in the editor's list that take an input image. */
559
+ imageModels(): { id: string; label: string; sizes: string[] }[];
560
+ /** The image model the editor is set to (its AI settings), never another one; canEdit: it takes
561
+ * an input image. null when AI images are not set up. */
562
+ imageModel(): { id: string; label: string; sizes: string[]; canEdit: boolean } | null;
563
+ /** One image request; resolves to the saved image's URL. `model` is required (usually
564
+ * imageModel().id) and must be one of imageModels(); `size` is one of that model's sizes. */
565
+ image(req: { prompt: string; images?: string[]; model: string; size?: string; signal?: AbortSignal | null }): Promise<string>;
566
+ /** The text model the editor is set to (the model chosen in the chat settings), never
567
+ * another one; null when AI text requests are not set up (no sendCommandUrl). */
568
+ textModel(): { id: string; label: string } | null;
569
+ /** One text request through the editor's route (sendCommandUrl); resolves to the answer
570
+ * text. `model` is required (usually textModel().id). */
571
+ text(req: { system?: string; prompt: string; model: string; temperature?: number; signal?: AbortSignal | null }): Promise<string>;
572
+ };
573
+ fonts: {
574
+ /** The fonts in the editor's font list. */
575
+ list(): { value: string; label: string; fontFamily: string; group: string }[];
576
+ /** Add a font (an entry as in the `fonts` option), in the "added" group at the top of the list. */
577
+ add(font: { label?: string; fontFamily: string; fontStyle?: string; fontDisplay?: string; provider?: string; cssUrl?: string }): void;
578
+ /** Take a font out of the list (its value: the family name). Text already set in it keeps the font. */
579
+ remove(value: string): void;
580
+ /** A row under every font list; `group` is the header over the fonts added with add(). The click closes the list; call reopen() to open it again. Returns a function that removes the row. */
581
+ setAction(action: { label: string; onClick: (reopen: () => void) => void; group?: string } | null): () => void;
582
+ };
583
+ markdown: {
584
+ /** Markdown (GitHub flavour) to HTML; insert the result with content.insertHtml(), which sanitizes it. */
585
+ toHtml(text: string): string;
586
+ };
587
+ content: {
588
+ /** Insert HTML at a range (default: the current selection), the way paste does:
589
+ * sanitized, one undo step, embedded (data:) images uploaded through the editor's
590
+ * upload. False when there is nowhere to insert. */
591
+ /** opts.after(area): runs on the editable area right after the insert, in the same undo step. */
592
+ insertHtml(html: string, range?: Range | null, opts?: { after?: (area: HTMLElement) => void }): boolean;
593
+ /** Insert an SVG drawing (an icon) as one undo step; only drawing elements are kept. Returns the inserted <svg>.
594
+ * opts.line: on a line of its own (a chart, an equation on its own line), with the caret on the line below. */
595
+ insertSvg(svg: string, range?: Range | null, opts?: { line?: boolean }): SVGSVGElement | null;
596
+ /** The items of the editor's quick add panel (+) that work in this editor, whatever the
597
+ * panel shows (quickAddButtons does not apply): 'paragraph', 'headline', 'heading1'...
598
+ * 'heading4', 'list', 'quote', 'preformatted', 'button', 'twobutton', 'image', 'table',
599
+ * 'icon', 'svg', 'social', 'spacer', 'line', 'map', 'youtube', 'video', 'audio', 'form',
600
+ * 'code', 'more'. */
601
+ blocks(): string[];
602
+ /** Insert what the quick add panel's item inserts, right after `after` (an element in a
603
+ * column), as one undo step. Returns the new elements in order; empty for 'more', which
604
+ * opens the snippets window. */
605
+ addBlock(id: string, after?: Element): HTMLElement[];
606
+ /** Whether the site set a file picker for images (filePicker, imageSelect or onImageSelectClick). */
607
+ hasImagePicker(): boolean;
608
+ /** Whether the site set an image upload (onImageUpload): only then does uploadImages()
609
+ * upload; without one an embedded image stays in the page. */
610
+ canUpload(): boolean;
611
+ /** Insert an image at the range (default: the current selection): the editor's own Insert
612
+ * Image window opens (upload, an address, or Select from the site's picker). With
613
+ * { picker: true } the site's file picker opens straight away and the chosen image goes
614
+ * in, as one undo step (false when no picker is set). With { src } that image goes in at
615
+ * once (an address, or a data: URL, uploaded as a pasted image is), the caret after it.
616
+ * False when there is nowhere to insert. */
617
+ insertImage(range?: Range | null, opts?: { picker?: boolean; src?: string }): boolean;
618
+ /** Add a full-width row holding html at the end of an editable area (default: the last one),
619
+ * in the page's own grid, with its row tools. Returns the new row, or null. Call it inside
620
+ * edit() to make it part of one undo step. */
621
+ addRow(html: string, area?: HTMLElement): HTMLElement | null;
622
+ /** The SVG drawing the user selected in the text by clicking it (an icon or equation), or null. */
623
+ selectedSvg(): SVGSVGElement | null;
624
+ /** ContentBox: a whole section (e.g. the one a place 'box' button's box is in) as clean HTML, its own tag included; '' elsewhere. */
625
+ sectionHtml(section: HTMLElement): string;
626
+ /** ContentBox: replace a section with new markup as one undo step; it stays selected. Returns the new section, or null. */
627
+ replaceSection(section: HTMLElement, html: string): HTMLElement | null;
628
+ /** Clipboard content cleaned exactly as pasting it into the page would (Word and Google Docs
629
+ * clean-up, the user's paste setting), ready for insertHtml(). range: where it will go
630
+ * (default: the current selection). */
631
+ cleanPaste(clip: { html?: string; text?: string }, range?: Range | null): string;
632
+ /** Upload the embedded (data:) images in or at an element of the content through the editor's
633
+ * upload, as pasted images are; for content an add-on changed itself. */
634
+ uploadImages(el: Element): boolean;
635
+ /** The page's content as clean HTML, every area in page order. */
636
+ html(): string;
637
+ /** The editable areas. */
638
+ areas(): HTMLElement[];
639
+ /** False for text the user does not edit here (plugin blocks, code, locked parts). A plugin's
640
+ * editable part (.is-subblock, e.g. a Tabs panel) is edited text: true. */
641
+ isEditable(node: Node): boolean;
642
+ /** The blocks (rows) the user marked by dragging beside the content; empty when none. A text
643
+ * button with `on: ['rows']` is also shown in the default toolbar while blocks are marked. */
644
+ markedRows(): HTMLElement[];
645
+ /** Remove the marks (the blocks stay). */
646
+ unmarkRows(): void;
647
+ /** The current selection inside the content, or null. */
648
+ selection(): Range | null;
649
+ /** The block the user selected whole (a click or the arrow keys) that is not text: a plugin,
650
+ * a video, a spacer, a picture or drawing on its own line. Returns the column's child that
651
+ * holds it (what moving or removing acts on), or null. */
652
+ selectedBlock(): HTMLElement | null;
653
+ /** Whether the editor has an element settings window (the element tool's Settings). */
654
+ hasElementSettings(): boolean;
655
+ /** Open the element settings window for el (a line of text, a spacer, a picture's line; not
656
+ * a plugin, which has its own), as the element tool's Settings does. False when there is none. */
657
+ elementSettings(el: Element): boolean;
658
+ /** Format the selected text as the text toolbar does: 'bold', 'italic', 'underline',
659
+ * 'strikethrough', 'clean' (clear formatting; links stay), 'unlink', or 'link' (opens
660
+ * the editor's link window). One undo step. False when the selection is not in editable text. */
661
+ format(command: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'clean' | 'link' | 'unlink'): boolean;
662
+ /** What the selected text is (block: the first line's tag; list: 'ul', 'ol' or null),
663
+ * or null outside editable text. */
664
+ formatState(): { bold: boolean; italic: boolean; underline: boolean; strikethrough: boolean; link: boolean; block: string | null; list: string | null } | null;
665
+ /** Turn the selected lines into another kind, keeping their text: 'p', 'h1' to 'h6',
666
+ * 'blockquote', 'pre', or 'ul' / 'ol' (a list). One undo step. False when nothing changed. */
667
+ setBlock(kind: string): boolean;
668
+ /** ContentBox: fn(box) runs each time the selected box changes (null when none is selected).
669
+ * Never runs in ContentBuilder. Returns a function that stops it. */
670
+ onSelectBox(fn: (box: HTMLElement | null) => void): () => void;
671
+ /** Change the content as one undo step. Return false from fn when nothing changed. */
672
+ edit<T>(fn: () => T): T;
673
+ };
674
+ }
675
+
426
676
  /** Options for builder.modal(). Only `html` is required. */
427
677
  interface ModalOptions {
428
678
  /** Title bar text. Omit for a bare dialog with a floating close button. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@innovastudio/contentbuilder",
4
- "version": "1.5.227",
4
+ "version": "1.5.229",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "types": "index.d.ts",