@lit-pigeon/editor 0.3.0 → 0.3.2
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/README.md +53 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -11
- package/dist/rich-text-bridge.js +47 -0
- package/dist/rich-text.js +1339 -1385
- package/package.json +22 -5
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @lit-pigeon/editor
|
|
2
|
+
|
|
3
|
+
The [Lit](https://lit.dev) Web Components UI for the
|
|
4
|
+
[Lit Pigeon](https://github.com/snxstudio/lit-pigeon) email editor — canvas,
|
|
5
|
+
block palette, property panels, toolbar, drag-and-drop, layers, asset manager,
|
|
6
|
+
merge-tag picker, and keyboard shortcuts. Importing the package registers the
|
|
7
|
+
`<pigeon-editor>` custom element, so it works in any framework (or none).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @lit-pigeon/editor
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Import the package once to define the custom element, then drop it into your
|
|
18
|
+
markup:
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<script type="module">
|
|
22
|
+
import '@lit-pigeon/editor';
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<pigeon-editor id="editor"></pigeon-editor>
|
|
26
|
+
|
|
27
|
+
<script type="module">
|
|
28
|
+
const editor = document.querySelector('#editor');
|
|
29
|
+
|
|
30
|
+
editor.addEventListener('pigeon:change', (e) => {
|
|
31
|
+
console.log('document', e.detail.document);
|
|
32
|
+
});
|
|
33
|
+
editor.addEventListener('pigeon:ready', () => console.log('ready'));
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`document` and `config` are set as live DOM **properties** (never stringified
|
|
38
|
+
attributes). The main component class is also exported for direct use or
|
|
39
|
+
type imports:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { PigeonEditor } from '@lit-pigeon/editor';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Prefer a framework wrapper? See
|
|
46
|
+
[`@lit-pigeon/react`](../react), [`@lit-pigeon/vue`](../vue),
|
|
47
|
+
[`@lit-pigeon/angular`](../angular), and [`@lit-pigeon/svelte`](../svelte).
|
|
48
|
+
|
|
49
|
+
Part of [Lit Pigeon](https://github.com/snxstudio/lit-pigeon) — open-source drag-and-drop email editor.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -683,7 +683,15 @@ export declare class PigeonPaletteItem extends LitElement {
|
|
|
683
683
|
columnCount: number;
|
|
684
684
|
static styles: CSSResult;
|
|
685
685
|
render(): TemplateResult<1>;
|
|
686
|
+
/** Suppresses the click that some browsers fire after a drag operation. */
|
|
687
|
+
private _didDrag;
|
|
688
|
+
private _onClick;
|
|
686
689
|
private _onKeyDown;
|
|
690
|
+
/**
|
|
691
|
+
* Click/keyboard equivalent of dragging this item onto the canvas: ask the
|
|
692
|
+
* editor to append the block/layout to the document.
|
|
693
|
+
*/
|
|
694
|
+
private _activate;
|
|
687
695
|
private _onDragStart;
|
|
688
696
|
private _onDragEnd;
|
|
689
697
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { css as b, LitElement as g, html as l, nothing as te } from "lit";
|
|
2
2
|
import { property as p, state as d, customElement as u } from "lit/decorators.js";
|
|
3
3
|
import { t as s, c as Bt, r as po } from "./templates.js";
|
|
4
|
-
import { P as
|
|
4
|
+
import { P as Kr } from "./templates.js";
|
|
5
5
|
import { getAllBlockDefinitions as co, getBlockDefinition as yt, updateBlock as ct, createBlock as Ye, insertBlock as ce, createColumn as Ie, insertRow as oe, createRow as Pe, cloneRowWithNewIds as jt, createBodySelection as Rt, deleteBlock as ho, deleteRow as Lt, duplicateBlock as go, duplicateRow as zt, generateId as Mt, EditorState as Ht, createHistoryPlugin as Ft, undo as uo, redo as bo, InMemoryTemplateStorage as vo, InMemoryRowLibraryStorage as fo, SYSTEM_LINK_TYPES as mo, createDocStep as dt, createDefaultDocument as _o, HISTORY_PLUGIN_NAME as Nt, canUndo as yo, canRedo as xo, createBlockSelection as ht, createRowSelection as Ut, createColumnSelection as $o, moveRow as wo, moveBlock as ko, updateRowAttributes as Co, addColumn as Io, removeColumn as Po, resizeColumns as To } from "@lit-pigeon/core";
|
|
6
6
|
import { unsafeHTML as eo } from "lit/directives/unsafe-html.js";
|
|
7
|
-
import { l as xt, r as So } from "./rich-text.js";
|
|
7
|
+
import { l as xt, r as So } from "./rich-text-bridge.js";
|
|
8
8
|
import { styleMap as Oo } from "lit/directives/style-map.js";
|
|
9
|
+
import "./rich-text.js";
|
|
9
10
|
const Kt = b`
|
|
10
11
|
/* base palette */
|
|
11
12
|
--pigeon-bg: #0f172a; /* slate-900 */
|
|
@@ -500,7 +501,7 @@ function Xe() {
|
|
|
500
501
|
function wt(e, t) {
|
|
501
502
|
e.dataTransfer && (e.dataTransfer.setData("application/json", JSON.stringify(t)), e.dataTransfer.effectAllowed = "move"), Bo(t);
|
|
502
503
|
}
|
|
503
|
-
function
|
|
504
|
+
function Fr(e) {
|
|
504
505
|
if (e.dataTransfer)
|
|
505
506
|
try {
|
|
506
507
|
const t = e.dataTransfer.getData("application/json");
|
|
@@ -525,7 +526,7 @@ const Lo = {
|
|
|
525
526
|
};
|
|
526
527
|
let W = class extends g {
|
|
527
528
|
constructor() {
|
|
528
|
-
super(...arguments), this.label = "", this.icon = "", this.dragType = "palette-block", this.blockType = "", this.columnCount = 1;
|
|
529
|
+
super(...arguments), this.label = "", this.icon = "", this.dragType = "palette-block", this.blockType = "", this.columnCount = 1, this._didDrag = !1;
|
|
529
530
|
}
|
|
530
531
|
render() {
|
|
531
532
|
const e = Lo[this.icon] ?? this.icon ?? "?", t = this.dragType === "palette-row" ? "Add layout" : "Add block";
|
|
@@ -536,7 +537,8 @@ let W = class extends g {
|
|
|
536
537
|
role="button"
|
|
537
538
|
tabindex="0"
|
|
538
539
|
aria-label="${t}: ${this.label}"
|
|
539
|
-
title="
|
|
540
|
+
title="Click to add, or drag onto the canvas"
|
|
541
|
+
@click=${this._onClick}
|
|
540
542
|
@dragstart=${this._onDragStart}
|
|
541
543
|
@dragend=${this._onDragEnd}
|
|
542
544
|
@keydown=${this._onKeyDown}
|
|
@@ -546,8 +548,18 @@ let W = class extends g {
|
|
|
546
548
|
</div>
|
|
547
549
|
`;
|
|
548
550
|
}
|
|
551
|
+
_onClick() {
|
|
552
|
+
this._didDrag || this._activate();
|
|
553
|
+
}
|
|
549
554
|
_onKeyDown(e) {
|
|
550
|
-
e.key !== "Enter" && e.key !== " " || (e.preventDefault(), this.
|
|
555
|
+
e.key !== "Enter" && e.key !== " " || (e.preventDefault(), this._activate());
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Click/keyboard equivalent of dragging this item onto the canvas: ask the
|
|
559
|
+
* editor to append the block/layout to the document.
|
|
560
|
+
*/
|
|
561
|
+
_activate() {
|
|
562
|
+
this.dispatchEvent(
|
|
551
563
|
new CustomEvent("palette-item-activate", {
|
|
552
564
|
detail: {
|
|
553
565
|
type: this.dragType,
|
|
@@ -557,10 +569,10 @@ let W = class extends g {
|
|
|
557
569
|
bubbles: !0,
|
|
558
570
|
composed: !0
|
|
559
571
|
})
|
|
560
|
-
)
|
|
572
|
+
);
|
|
561
573
|
}
|
|
562
574
|
_onDragStart(e) {
|
|
563
|
-
wt(e, {
|
|
575
|
+
this._didDrag = !0, wt(e, {
|
|
564
576
|
type: this.dragType,
|
|
565
577
|
blockType: this.blockType || void 0,
|
|
566
578
|
columnCount: this.columnCount
|
|
@@ -577,7 +589,9 @@ let W = class extends g {
|
|
|
577
589
|
});
|
|
578
590
|
}
|
|
579
591
|
_onDragEnd() {
|
|
580
|
-
|
|
592
|
+
setTimeout(() => {
|
|
593
|
+
this._didDrag = !1;
|
|
594
|
+
}, 0), this.dispatchEvent(new CustomEvent("palette-drag-end", {
|
|
581
595
|
bubbles: !0,
|
|
582
596
|
composed: !0
|
|
583
597
|
}));
|
|
@@ -8769,7 +8783,7 @@ export {
|
|
|
8769
8783
|
Re as PigeonSocialBlock,
|
|
8770
8784
|
je as PigeonSpacerBlock,
|
|
8771
8785
|
Ue as PigeonSpacingInput,
|
|
8772
|
-
|
|
8786
|
+
Kr as PigeonTemplatePicker,
|
|
8773
8787
|
de as PigeonTextBlock,
|
|
8774
8788
|
E as PigeonTextPanel,
|
|
8775
8789
|
K as PigeonToolbar,
|
|
@@ -8777,7 +8791,7 @@ export {
|
|
|
8777
8791
|
Vo as calculateRowDropIndex,
|
|
8778
8792
|
Xe as clearDragData,
|
|
8779
8793
|
De as getDragData,
|
|
8780
|
-
|
|
8794
|
+
Fr as readDragTransfer,
|
|
8781
8795
|
Bo as setDragData,
|
|
8782
8796
|
wt as writeDragTransfer
|
|
8783
8797
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let t = null;
|
|
2
|
+
function r() {
|
|
3
|
+
return t || (t = import("./rich-text.js").then((s) => s.default)), t;
|
|
4
|
+
}
|
|
5
|
+
class l {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._active = null, this._listeners = /* @__PURE__ */ new Set(), this._held = !1;
|
|
8
|
+
}
|
|
9
|
+
setActive(e) {
|
|
10
|
+
if (this._active !== e) {
|
|
11
|
+
this._active = e;
|
|
12
|
+
for (const i of this._listeners) i(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Clear only if `editor` is the currently-active one (avoids races on rapid focus changes). */
|
|
16
|
+
clearIfActive(e) {
|
|
17
|
+
this._active === e && this.setActive(null);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* "Focus hold" — set while the user operates a formatting control that lives
|
|
21
|
+
* outside the editable (the bubble's link field, the sidebar format panel's
|
|
22
|
+
* `<select>`/color inputs). Native form controls steal DOM focus, which would
|
|
23
|
+
* otherwise blur the editor and tear it down before the command runs. While
|
|
24
|
+
* held, the editor's blur handler keeps the editor alive and the active
|
|
25
|
+
* binding intact so the command can apply to the preserved selection.
|
|
26
|
+
*/
|
|
27
|
+
holdFocus() {
|
|
28
|
+
this._held = !0;
|
|
29
|
+
}
|
|
30
|
+
releaseFocus() {
|
|
31
|
+
this._held = !1;
|
|
32
|
+
}
|
|
33
|
+
isHeld() {
|
|
34
|
+
return this._held;
|
|
35
|
+
}
|
|
36
|
+
getActive() {
|
|
37
|
+
return this._active;
|
|
38
|
+
}
|
|
39
|
+
subscribe(e) {
|
|
40
|
+
return this._listeners.add(e), () => this._listeners.delete(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const h = new l();
|
|
44
|
+
export {
|
|
45
|
+
r as l,
|
|
46
|
+
h as r
|
|
47
|
+
};
|