le-kit 0.1.6 → 0.1.8
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/{dist/le-kit/assets/custom-elements.json → custom-elements.json} +889 -889
- package/dist/cjs/{index-WzJ78D5H.js → index-D7B9TPh8.js} +41 -9
- package/dist/cjs/index-D7B9TPh8.js.map +1 -0
- package/dist/cjs/index.cjs.js +4 -2
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/le-box.cjs.entry.js +2 -2
- package/dist/cjs/le-button.le-checkbox.le-component.le-popover.le-slot.le-string-input.entry.cjs.js.map +1 -1
- package/dist/cjs/le-button_6.cjs.entry.js +8 -10
- package/dist/cjs/le-card.cjs.entry.js +2 -2
- package/dist/cjs/le-kit.cjs.js +1 -1
- package/dist/cjs/le-number-input.cjs.entry.js +2 -2
- package/dist/cjs/le-popup.cjs.entry.js +1 -1
- package/dist/cjs/le-round-progress.cjs.entry.js +1 -1
- package/dist/cjs/le-stack.cjs.entry.js +2 -2
- package/dist/cjs/le-text.cjs.entry.js +2 -2
- package/dist/cjs/le-turntable.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{utils-CBjH2E8A.js → utils-DrsoID-a.js} +3 -3
- package/dist/cjs/{utils-CBjH2E8A.js.map → utils-DrsoID-a.js.map} +1 -1
- package/dist/collection/components/le-component/le-component.js +5 -5
- package/dist/collection/components/le-component/le-component.js.map +1 -1
- package/dist/collection/components/le-popup/le-popup.js +7 -7
- package/dist/collection/components/le-slot/le-slot.js +5 -5
- package/dist/collection/components/le-slot/le-slot.js.map +1 -1
- package/dist/collection/global/app.js +37 -0
- package/dist/collection/global/app.js.map +1 -1
- package/dist/collection/index.js +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/le-box.js +1 -1
- package/dist/components/le-button.js +1 -1
- package/dist/components/le-button2.js +45 -10
- package/dist/components/le-button2.js.map +1 -1
- package/dist/components/le-card.js +1 -1
- package/dist/components/le-checkbox.js +1 -1
- package/dist/components/le-component.js +1 -1
- package/dist/components/le-number-input.js +1 -1
- package/dist/components/le-popup.js +1 -1
- package/dist/components/le-slot.js +1 -1
- package/dist/components/le-stack.js +1 -1
- package/dist/components/le-string-input.js +1 -1
- package/dist/components/le-text.js +1 -1
- package/dist/core/cjs/index-D7B9TPh8.js +1835 -0
- package/dist/core/cjs/index-D7B9TPh8.js.map +1 -0
- package/dist/core/cjs/index.cjs.js +119 -0
- package/dist/core/cjs/index.cjs.js.map +1 -0
- package/dist/core/cjs/le-box.cjs.entry.js +184 -0
- package/dist/core/cjs/le-box.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-button.cjs.entry.js +92 -0
- package/dist/core/cjs/le-button.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-card.cjs.entry.js +29 -0
- package/dist/core/cjs/le-card.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-checkbox.cjs.entry.js +61 -0
- package/dist/core/cjs/le-checkbox.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-kit.cjs.js +25 -0
- package/dist/core/cjs/le-kit.cjs.js.map +1 -0
- package/dist/core/cjs/le-number-input.cjs.entry.js +202 -0
- package/dist/core/cjs/le-number-input.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-popover.cjs.entry.js +348 -0
- package/dist/core/cjs/le-popover.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-popup.cjs.entry.js +212 -0
- package/dist/core/cjs/le-popup.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-round-progress.cjs.entry.js +106 -0
- package/dist/core/cjs/le-round-progress.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-stack.cjs.entry.js +135 -0
- package/dist/core/cjs/le-stack.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-string-input.cjs.entry.js +95 -0
- package/dist/core/cjs/le-string-input.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-text.cjs.entry.js +335 -0
- package/dist/core/cjs/le-text.entry.cjs.js.map +1 -0
- package/dist/core/cjs/le-turntable.cjs.entry.js +139 -0
- package/dist/core/cjs/le-turntable.entry.cjs.js.map +1 -0
- package/dist/core/cjs/loader.cjs.js +13 -0
- package/dist/core/cjs/loader.cjs.js.map +1 -0
- package/dist/core/cjs/utils-DrsoID-a.js +152 -0
- package/dist/core/cjs/utils-DrsoID-a.js.map +1 -0
- package/dist/core/collection/collection-manifest.json +24 -0
- package/dist/core/collection/components/le-box/le-box.default.css +37 -0
- package/dist/core/collection/components/le-box/le-box.js +614 -0
- package/dist/core/collection/components/le-box/le-box.js.map +1 -0
- package/dist/core/collection/components/le-button/le-button.default.css +263 -0
- package/dist/core/collection/components/le-button/le-button.js +368 -0
- package/dist/core/collection/components/le-button/le-button.js.map +1 -0
- package/dist/core/collection/components/le-card/le-card.default.css +74 -0
- package/dist/core/collection/components/le-card/le-card.js +102 -0
- package/dist/core/collection/components/le-card/le-card.js.map +1 -0
- package/dist/core/collection/components/le-checkbox/le-checkbox.css +93 -0
- package/dist/core/collection/components/le-checkbox/le-checkbox.js +192 -0
- package/dist/core/collection/components/le-checkbox/le-checkbox.js.map +1 -0
- package/dist/core/collection/components/le-number-input/le-number-input.css +135 -0
- package/dist/core/collection/components/le-number-input/le-number-input.js +515 -0
- package/dist/core/collection/components/le-number-input/le-number-input.js.map +1 -0
- package/dist/core/collection/components/le-popover/le-popover.css +143 -0
- package/dist/core/collection/components/le-popover/le-popover.js +693 -0
- package/dist/core/collection/components/le-popover/le-popover.js.map +1 -0
- package/dist/core/collection/components/le-popup/le-popup.api.js +101 -0
- package/dist/core/collection/components/le-popup/le-popup.api.js.map +1 -0
- package/dist/core/collection/components/le-popup/le-popup.css +222 -0
- package/dist/core/collection/components/le-popup/le-popup.js +596 -0
- package/dist/core/collection/components/le-popup/le-popup.js.map +1 -0
- package/dist/core/collection/components/le-round-progress/le-round-progress.css +34 -0
- package/dist/core/collection/components/le-round-progress/le-round-progress.js +184 -0
- package/dist/core/collection/components/le-round-progress/le-round-progress.js.map +1 -0
- package/dist/core/collection/components/le-stack/le-stack.default.css +37 -0
- package/dist/core/collection/components/le-stack/le-stack.js +389 -0
- package/dist/core/collection/components/le-stack/le-stack.js.map +1 -0
- package/dist/core/collection/components/le-string-input/le-string-input.css +83 -0
- package/dist/core/collection/components/le-string-input/le-string-input.js +359 -0
- package/dist/core/collection/components/le-string-input/le-string-input.js.map +1 -0
- package/dist/core/collection/components/le-text/le-text.default.css +169 -0
- package/dist/core/collection/components/le-text/le-text.js +475 -0
- package/dist/core/collection/components/le-text/le-text.js.map +1 -0
- package/dist/core/collection/components/le-turntable/le-turntable.css +10 -0
- package/dist/core/collection/components/le-turntable/le-turntable.js +210 -0
- package/dist/core/collection/components/le-turntable/le-turntable.js.map +1 -0
- package/dist/core/collection/global/app.js +167 -0
- package/dist/core/collection/global/app.js.map +1 -0
- package/dist/core/collection/index.js +15 -0
- package/dist/core/collection/index.js.map +1 -0
- package/dist/core/collection/types/blocks.js +115 -0
- package/dist/core/collection/types/blocks.js.map +1 -0
- package/dist/core/collection/types/options.js +2 -0
- package/dist/core/collection/types/options.js.map +1 -0
- package/dist/core/collection/utils/utils.js +141 -0
- package/dist/core/collection/utils/utils.js.map +1 -0
- package/dist/{esm/index-CdjJ98OT.js → core/esm/index-PS-3Rz-c.js} +40 -9
- package/dist/core/esm/index-PS-3Rz-c.js.map +1 -0
- package/dist/core/esm/index.js +106 -0
- package/dist/core/esm/index.js.map +1 -0
- package/dist/core/esm/le-box.entry.js +182 -0
- package/dist/core/esm/le-box.entry.js.map +1 -0
- package/dist/core/esm/le-button.entry.js +90 -0
- package/dist/core/esm/le-button.entry.js.map +1 -0
- package/dist/core/esm/le-card.entry.js +27 -0
- package/dist/core/esm/le-card.entry.js.map +1 -0
- package/dist/core/esm/le-checkbox.entry.js +59 -0
- package/dist/core/esm/le-checkbox.entry.js.map +1 -0
- package/dist/core/esm/le-kit.js +21 -0
- package/dist/core/esm/le-kit.js.map +1 -0
- package/dist/core/esm/le-number-input.entry.js +200 -0
- package/dist/core/esm/le-number-input.entry.js.map +1 -0
- package/dist/core/esm/le-popover.entry.js +346 -0
- package/dist/core/esm/le-popover.entry.js.map +1 -0
- package/dist/core/esm/le-popup.entry.js +210 -0
- package/dist/core/esm/le-popup.entry.js.map +1 -0
- package/dist/core/esm/le-round-progress.entry.js +104 -0
- package/dist/core/esm/le-round-progress.entry.js.map +1 -0
- package/dist/core/esm/le-stack.entry.js +133 -0
- package/dist/core/esm/le-stack.entry.js.map +1 -0
- package/dist/core/esm/le-string-input.entry.js +93 -0
- package/dist/core/esm/le-string-input.entry.js.map +1 -0
- package/dist/core/esm/le-text.entry.js +333 -0
- package/dist/core/esm/le-text.entry.js.map +1 -0
- package/dist/core/esm/le-turntable.entry.js +137 -0
- package/dist/core/esm/le-turntable.entry.js.map +1 -0
- package/dist/core/esm/loader.js +11 -0
- package/dist/core/esm/loader.js.map +1 -0
- package/dist/{esm/utils-CzfSUhYB.js → core/esm/utils-lgjSfQP0.js} +3 -3
- package/dist/core/esm/utils-lgjSfQP0.js.map +1 -0
- package/dist/core/index.cjs.js +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/le-kit/index.esm.js +2 -0
- package/dist/core/le-kit/index.esm.js.map +1 -0
- package/dist/core/le-kit/le-box.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-button.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-card.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-checkbox.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-kit.css +1 -0
- package/dist/core/le-kit/le-kit.esm.js +2 -0
- package/dist/core/le-kit/le-kit.esm.js.map +1 -0
- package/dist/core/le-kit/le-number-input.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-popover.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-popup.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-round-progress.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-stack.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-string-input.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-text.entry.esm.js.map +1 -0
- package/dist/core/le-kit/le-turntable.entry.esm.js.map +1 -0
- package/dist/core/le-kit/loader.esm.js.map +1 -0
- package/dist/core/le-kit/p-1c5262eb.entry.js +2 -0
- package/dist/core/le-kit/p-1c5262eb.entry.js.map +1 -0
- package/dist/core/le-kit/p-32c08678.entry.js +2 -0
- package/dist/core/le-kit/p-32c08678.entry.js.map +1 -0
- package/dist/core/le-kit/p-38e7ec05.entry.js +2 -0
- package/dist/core/le-kit/p-38e7ec05.entry.js.map +1 -0
- package/dist/core/le-kit/p-4bf51acc.entry.js +2 -0
- package/dist/core/le-kit/p-4bf51acc.entry.js.map +1 -0
- package/dist/core/le-kit/p-86961f34.entry.js +2 -0
- package/dist/core/le-kit/p-86961f34.entry.js.map +1 -0
- package/dist/core/le-kit/p-9ee92c29.entry.js +2 -0
- package/dist/{le-kit/p-CvDc0yWN.js → core/le-kit/p-DN2JVY-7.js} +2 -2
- package/dist/core/le-kit/p-DN2JVY-7.js.map +1 -0
- package/dist/core/le-kit/p-PS-3Rz-c.js +3 -0
- package/dist/core/le-kit/p-PS-3Rz-c.js.map +1 -0
- package/dist/core/le-kit/p-a07048f8.entry.js +2 -0
- package/dist/core/le-kit/p-a07048f8.entry.js.map +1 -0
- package/dist/core/le-kit/p-a24b042d.entry.js +2 -0
- package/dist/core/le-kit/p-a24b042d.entry.js.map +1 -0
- package/dist/core/le-kit/p-bbc9e13e.entry.js +2 -0
- package/dist/core/le-kit/p-bbc9e13e.entry.js.map +1 -0
- package/dist/core/le-kit/p-c4223c60.entry.js +2 -0
- package/dist/core/le-kit/p-c4223c60.entry.js.map +1 -0
- package/dist/core/le-kit/p-dcf1343d.entry.js +2 -0
- package/dist/core/le-kit/p-fb4e68e0.entry.js +2 -0
- package/dist/core/le-kit/p-fb4e68e0.entry.js.map +1 -0
- package/dist/core/loader/cdn.js +1 -0
- package/dist/core/loader/index.cjs.js +1 -0
- package/dist/core/loader/index.d.ts +24 -0
- package/dist/core/loader/index.es2017.js +1 -0
- package/dist/core/loader/index.js +2 -0
- package/dist/core/types/components/le-box/le-box.d.ts +111 -0
- package/dist/core/types/components/le-button/le-button.d.ts +78 -0
- package/dist/core/types/components/le-card/le-card.d.ts +37 -0
- package/dist/core/types/components/le-checkbox/le-checkbox.d.ts +46 -0
- package/dist/core/types/components/le-number-input/le-number-input.d.ts +106 -0
- package/dist/core/types/components/le-popover/le-popover.d.ts +109 -0
- package/dist/core/types/components/le-popup/le-popup.api.d.ts +73 -0
- package/dist/core/types/components/le-popup/le-popup.d.ts +122 -0
- package/dist/core/types/components/le-round-progress/le-round-progress.d.ts +37 -0
- package/dist/core/types/components/le-stack/le-stack.d.ts +73 -0
- package/dist/core/types/components/le-string-input/le-string-input.d.ts +83 -0
- package/dist/core/types/components/le-text/le-text.d.ts +141 -0
- package/dist/core/types/components/le-turntable/le-turntable.d.ts +55 -0
- package/dist/core/types/components.d.ts +1752 -0
- package/dist/core/types/global/app.d.ts +73 -0
- package/dist/core/types/index.d.ts +15 -0
- package/dist/core/types/stencil-public-runtime.d.ts +1756 -0
- package/dist/core/types/types/blocks.d.ts +136 -0
- package/dist/core/types/types/options.d.ts +124 -0
- package/dist/core/types/utils/utils.d.ts +54 -0
- package/dist/docs.json +8 -8
- package/dist/esm/index-PS-3Rz-c.js +1818 -0
- package/dist/{le-kit/p-CdjJ98OT.js.map → esm/index-PS-3Rz-c.js.map} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/le-box.entry.js +2 -2
- package/dist/esm/le-button.le-checkbox.le-component.le-popover.le-slot.le-string-input.entry.js.map +1 -1
- package/dist/esm/le-button_6.entry.js +8 -10
- package/dist/esm/le-card.entry.js +2 -2
- package/dist/esm/le-kit.js +2 -2
- package/dist/esm/le-number-input.entry.js +2 -2
- package/dist/esm/le-popup.entry.js +1 -1
- package/dist/esm/le-round-progress.entry.js +1 -1
- package/dist/esm/le-stack.entry.js +2 -2
- package/dist/esm/le-text.entry.js +2 -2
- package/dist/esm/le-turntable.entry.js +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/utils-lgjSfQP0.js +146 -0
- package/dist/esm/{utils-CzfSUhYB.js.map → utils-lgjSfQP0.js.map} +1 -1
- package/dist/le-kit/index.esm.js +1 -1
- package/dist/le-kit/le-button.le-checkbox.le-component.le-popover.le-slot.le-string-input.entry.esm.js.map +1 -1
- package/dist/le-kit/le-kit.esm.js +1 -1
- package/dist/le-kit/p-27710b5b.entry.js +2 -0
- package/dist/le-kit/{p-0633b3ab.entry.js.map → p-27710b5b.entry.js.map} +1 -1
- package/dist/le-kit/{p-1452a995.entry.js → p-34102cef.entry.js} +2 -2
- package/dist/le-kit/{p-95764888.entry.js → p-56a80e6d.entry.js} +2 -2
- package/dist/le-kit/p-615ea10f.entry.js +2 -0
- package/dist/le-kit/p-615ea10f.entry.js.map +1 -0
- package/dist/le-kit/{p-bc20e30d.entry.js → p-935bb2d4.entry.js} +2 -2
- package/dist/le-kit/{p-220528ee.entry.js → p-9d3dc4e5.entry.js} +2 -2
- package/dist/le-kit/p-DN2JVY-7.js +2 -0
- package/dist/le-kit/{p-CvDc0yWN.js.map → p-DN2JVY-7.js.map} +1 -1
- package/dist/le-kit/p-PS-3Rz-c.js +3 -0
- package/dist/le-kit/p-PS-3Rz-c.js.map +1 -0
- package/dist/le-kit/{p-3551598e.entry.js → p-ccabc638.entry.js} +2 -2
- package/dist/le-kit/p-ccabc638.entry.js.map +1 -0
- package/dist/le-kit/{p-722899f0.entry.js → p-d8157b06.entry.js} +2 -2
- package/dist/le-kit/p-d8157b06.entry.js.map +1 -0
- package/dist/le-kit/p-e8c2ca0e.entry.js +2 -0
- package/dist/le-kit/{p-d32eddad.entry.js.map → p-e8c2ca0e.entry.js.map} +1 -1
- package/dist/types/global/app.d.ts +33 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +21 -3
- package/readme.md +22 -0
- package/dist/cjs/index-WzJ78D5H.js.map +0 -1
- package/dist/collection/assets/.gitkeep +0 -1
- package/dist/collection/assets/custom-elements.json +0 -4305
- package/dist/esm/index-CdjJ98OT.js.map +0 -1
- package/dist/le-kit/p-0633b3ab.entry.js +0 -2
- package/dist/le-kit/p-32ff3dbe.entry.js +0 -2
- package/dist/le-kit/p-32ff3dbe.entry.js.map +0 -1
- package/dist/le-kit/p-CdjJ98OT.js +0 -3
- package/dist/le-kit/p-d32eddad.entry.js +0 -2
- /package/dist/{le-kit/p-3551598e.entry.js.map → core/le-kit/p-9ee92c29.entry.js.map} +0 -0
- /package/dist/{le-kit/p-722899f0.entry.js.map → core/le-kit/p-dcf1343d.entry.js.map} +0 -0
- /package/dist/le-kit/{p-1452a995.entry.js.map → p-34102cef.entry.js.map} +0 -0
- /package/dist/le-kit/{p-95764888.entry.js.map → p-56a80e6d.entry.js.map} +0 -0
- /package/dist/le-kit/{p-bc20e30d.entry.js.map → p-935bb2d4.entry.js.map} +0 -0
- /package/dist/le-kit/{p-220528ee.entry.js.map → p-9d3dc4e5.entry.js.map} +0 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { h, Host } from "@stencil/core";
|
|
2
|
+
import { observeModeChanges } from "../../utils/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A text component with rich text editing capabilities in admin mode.
|
|
5
|
+
*
|
|
6
|
+
* `le-text` renders semantic text elements (headings, paragraphs, code, quotes)
|
|
7
|
+
* and provides a Notion-like rich text editor in admin mode with formatting
|
|
8
|
+
* toolbar for bold, italic, links, and paragraph type selection.
|
|
9
|
+
*
|
|
10
|
+
* @slot - Default slot for text content
|
|
11
|
+
*
|
|
12
|
+
* @cssprop --le-text-color - Text color
|
|
13
|
+
* @cssprop --le-text-font-size - Font size
|
|
14
|
+
* @cssprop --le-text-line-height - Line height
|
|
15
|
+
* @cssprop --le-text-font-weight - Font weight
|
|
16
|
+
*
|
|
17
|
+
* @csspart text - The text container element
|
|
18
|
+
*
|
|
19
|
+
* @cmsEditable true
|
|
20
|
+
* @cmsCategory Content
|
|
21
|
+
*/
|
|
22
|
+
export class LeText {
|
|
23
|
+
el;
|
|
24
|
+
/**
|
|
25
|
+
* The semantic variant/type of text element
|
|
26
|
+
* @allowedValues p | h1 | h2 | h3 | h4 | h5 | h6 | code | quote | label | small
|
|
27
|
+
*/
|
|
28
|
+
variant = 'p';
|
|
29
|
+
/**
|
|
30
|
+
* Text alignment
|
|
31
|
+
* @allowedValues left | center | right | justify
|
|
32
|
+
*/
|
|
33
|
+
align = 'left';
|
|
34
|
+
/**
|
|
35
|
+
* Text color (CSS value or theme token)
|
|
36
|
+
*/
|
|
37
|
+
color;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the text should truncate with ellipsis
|
|
40
|
+
*/
|
|
41
|
+
truncate = false;
|
|
42
|
+
/**
|
|
43
|
+
* Maximum number of lines before truncating (requires truncate=true)
|
|
44
|
+
*/
|
|
45
|
+
maxLines;
|
|
46
|
+
/**
|
|
47
|
+
* Internal state to track admin mode
|
|
48
|
+
*/
|
|
49
|
+
adminMode = false;
|
|
50
|
+
/**
|
|
51
|
+
* The HTML content being edited
|
|
52
|
+
*/
|
|
53
|
+
content = '';
|
|
54
|
+
/**
|
|
55
|
+
* Whether the editor is focused (shows toolbar)
|
|
56
|
+
*/
|
|
57
|
+
isFocused = false;
|
|
58
|
+
/**
|
|
59
|
+
* Current selection state for toolbar button highlighting
|
|
60
|
+
*/
|
|
61
|
+
selectionState = {
|
|
62
|
+
isBold: false,
|
|
63
|
+
isItalic: false,
|
|
64
|
+
isUnderline: false,
|
|
65
|
+
isStrikethrough: false,
|
|
66
|
+
isLink: false,
|
|
67
|
+
blockType: 'p',
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Reference to the contenteditable element
|
|
71
|
+
*/
|
|
72
|
+
editorRef;
|
|
73
|
+
/**
|
|
74
|
+
* Reference to the slot element
|
|
75
|
+
*/
|
|
76
|
+
slotRef;
|
|
77
|
+
disconnectModeObserver;
|
|
78
|
+
connectedCallback() {
|
|
79
|
+
this.disconnectModeObserver = observeModeChanges(this.el, (mode) => {
|
|
80
|
+
const wasAdmin = this.adminMode;
|
|
81
|
+
this.adminMode = mode === 'admin';
|
|
82
|
+
if (this.adminMode && !wasAdmin) {
|
|
83
|
+
// Entering admin mode - read content from slot
|
|
84
|
+
requestAnimationFrame(() => this.readSlottedContent());
|
|
85
|
+
}
|
|
86
|
+
else if (!this.adminMode && wasAdmin) {
|
|
87
|
+
// Leaving admin mode - sync content back to slot
|
|
88
|
+
this.syncContentToSlot();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
disconnectedCallback() {
|
|
93
|
+
this.disconnectModeObserver?.();
|
|
94
|
+
}
|
|
95
|
+
onVariantChange() {
|
|
96
|
+
// When variant changes in admin mode, update the content wrapper
|
|
97
|
+
if (this.adminMode && this.editorRef) {
|
|
98
|
+
this.syncContentToSlot();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Read content from slotted elements
|
|
103
|
+
*/
|
|
104
|
+
readSlottedContent() {
|
|
105
|
+
if (!this.slotRef)
|
|
106
|
+
return;
|
|
107
|
+
const assignedNodes = this.slotRef.assignedNodes({ flatten: true });
|
|
108
|
+
// Collect all content from assigned nodes
|
|
109
|
+
let html = '';
|
|
110
|
+
assignedNodes.forEach(node => {
|
|
111
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
112
|
+
html += node.textContent;
|
|
113
|
+
}
|
|
114
|
+
else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
115
|
+
html += node.innerHTML || node.textContent;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
this.content = html.trim();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Sync edited content back to the slot
|
|
122
|
+
*/
|
|
123
|
+
syncContentToSlot() {
|
|
124
|
+
if (!this.editorRef)
|
|
125
|
+
return;
|
|
126
|
+
const newContent = this.editorRef.innerHTML;
|
|
127
|
+
// Update the light DOM content
|
|
128
|
+
// We need to update the actual slotted content
|
|
129
|
+
const slot = this.slotRef;
|
|
130
|
+
if (slot) {
|
|
131
|
+
const assignedNodes = slot.assignedNodes({ flatten: true });
|
|
132
|
+
if (assignedNodes.length > 0) {
|
|
133
|
+
const firstNode = assignedNodes[0];
|
|
134
|
+
if (firstNode.nodeType === Node.ELEMENT_NODE) {
|
|
135
|
+
firstNode.innerHTML = newContent;
|
|
136
|
+
}
|
|
137
|
+
else if (firstNode.nodeType === Node.TEXT_NODE) {
|
|
138
|
+
// Replace text node with the new content
|
|
139
|
+
const parent = firstNode.parentNode;
|
|
140
|
+
if (parent) {
|
|
141
|
+
// Create a temporary element to parse HTML
|
|
142
|
+
const temp = document.createElement('span');
|
|
143
|
+
temp.innerHTML = newContent;
|
|
144
|
+
// Replace the text node
|
|
145
|
+
parent.replaceChild(temp, firstNode);
|
|
146
|
+
// Unwrap the span if it only contains text
|
|
147
|
+
if (temp.childNodes.length === 1 && temp.firstChild?.nodeType === Node.TEXT_NODE) {
|
|
148
|
+
parent.replaceChild(temp.firstChild, temp);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// No assigned nodes, set innerHTML on the host's light DOM
|
|
155
|
+
this.el.innerHTML = newContent;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Handle input in the contenteditable
|
|
161
|
+
*/
|
|
162
|
+
handleInput = () => {
|
|
163
|
+
if (this.editorRef) {
|
|
164
|
+
this.content = this.editorRef.innerHTML;
|
|
165
|
+
this.updateSelectionState();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Handle focus on the editor
|
|
170
|
+
*/
|
|
171
|
+
handleFocus = () => {
|
|
172
|
+
this.isFocused = true;
|
|
173
|
+
this.updateSelectionState();
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Handle blur on the editor
|
|
177
|
+
*/
|
|
178
|
+
handleBlur = (e) => {
|
|
179
|
+
// Check if focus moved to toolbar
|
|
180
|
+
const relatedTarget = e.relatedTarget;
|
|
181
|
+
const toolbar = this.el.shadowRoot?.querySelector('.le-text-toolbar');
|
|
182
|
+
if (toolbar?.contains(relatedTarget)) {
|
|
183
|
+
// Focus moved to toolbar, keep it open
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// Small delay to allow toolbar clicks to register
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
if (!this.el.shadowRoot?.activeElement) {
|
|
189
|
+
this.isFocused = false;
|
|
190
|
+
this.syncContentToSlot();
|
|
191
|
+
}
|
|
192
|
+
}, 150);
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Handle selection change to update toolbar state
|
|
196
|
+
*/
|
|
197
|
+
handleSelectionChange = () => {
|
|
198
|
+
this.updateSelectionState();
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Update the selection state for toolbar highlighting
|
|
202
|
+
*/
|
|
203
|
+
updateSelectionState() {
|
|
204
|
+
const selection = window.getSelection();
|
|
205
|
+
if (!selection || selection.rangeCount === 0)
|
|
206
|
+
return;
|
|
207
|
+
this.selectionState = {
|
|
208
|
+
isBold: document.queryCommandState('bold'),
|
|
209
|
+
isItalic: document.queryCommandState('italic'),
|
|
210
|
+
isUnderline: document.queryCommandState('underline'),
|
|
211
|
+
isStrikethrough: document.queryCommandState('strikeThrough'),
|
|
212
|
+
isLink: this.isSelectionInLink(selection),
|
|
213
|
+
blockType: this.variant,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Check if current selection is within a link
|
|
218
|
+
*/
|
|
219
|
+
isSelectionInLink(selection) {
|
|
220
|
+
if (!selection.anchorNode)
|
|
221
|
+
return false;
|
|
222
|
+
let node = selection.anchorNode;
|
|
223
|
+
while (node && node !== this.editorRef) {
|
|
224
|
+
if (node.nodeName === 'A')
|
|
225
|
+
return true;
|
|
226
|
+
node = node.parentNode;
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Execute a formatting command
|
|
232
|
+
*/
|
|
233
|
+
execCommand(command, value) {
|
|
234
|
+
// Focus the editor first
|
|
235
|
+
this.editorRef?.focus();
|
|
236
|
+
// Execute the command
|
|
237
|
+
document.execCommand(command, false, value);
|
|
238
|
+
// Update state
|
|
239
|
+
this.handleInput();
|
|
240
|
+
this.updateSelectionState();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Toggle bold formatting
|
|
244
|
+
*/
|
|
245
|
+
toggleBold = (e) => {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
this.execCommand('bold');
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Toggle italic formatting
|
|
251
|
+
*/
|
|
252
|
+
toggleItalic = (e) => {
|
|
253
|
+
e.preventDefault();
|
|
254
|
+
this.execCommand('italic');
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Toggle underline formatting
|
|
258
|
+
*/
|
|
259
|
+
toggleUnderline = (e) => {
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
this.execCommand('underline');
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Toggle strikethrough formatting
|
|
265
|
+
*/
|
|
266
|
+
toggleStrikethrough = (e) => {
|
|
267
|
+
e.preventDefault();
|
|
268
|
+
this.execCommand('strikeThrough');
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Add or edit a link
|
|
272
|
+
*/
|
|
273
|
+
toggleLink = (e) => {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
if (this.selectionState.isLink) {
|
|
276
|
+
// Remove link
|
|
277
|
+
this.execCommand('unlink');
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
// Add link
|
|
281
|
+
const url = prompt('Enter URL:', 'https://');
|
|
282
|
+
if (url) {
|
|
283
|
+
this.execCommand('createLink', url);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Change the block type/variant
|
|
289
|
+
*/
|
|
290
|
+
changeVariant = (e) => {
|
|
291
|
+
const select = e.target;
|
|
292
|
+
this.variant = select.value;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Render the formatting toolbar
|
|
296
|
+
*/
|
|
297
|
+
renderToolbar() {
|
|
298
|
+
return (h("div", { class: "le-text-toolbar" }, h("select", { class: "le-text-toolbar-select", onChange: this.changeVariant, onMouseDown: (e) => e.preventDefault() }, h("option", { value: "p", selected: this.variant === 'p' }, "Paragraph"), h("option", { value: "h1", selected: this.variant === 'h1' }, "Heading 1"), h("option", { value: "h2", selected: this.variant === 'h2' }, "Heading 2"), h("option", { value: "h3", selected: this.variant === 'h3' }, "Heading 3"), h("option", { value: "h4", selected: this.variant === 'h4' }, "Heading 4"), h("option", { value: "h5", selected: this.variant === 'h5' }, "Heading 5"), h("option", { value: "h6", selected: this.variant === 'h6' }, "Heading 6"), h("option", { value: "quote", selected: this.variant === 'quote' }, "Quote"), h("option", { value: "code", selected: this.variant === 'code' }, "Code"), h("option", { value: "label", selected: this.variant === 'label' }, "Label"), h("option", { value: "small", selected: this.variant === 'small' }, "Small")), h("div", { class: "le-text-toolbar-divider" }), h("button", { type: "button", class: { 'le-text-toolbar-btn': true, 'active': this.selectionState.isBold }, onMouseDown: this.toggleBold, title: "Bold (Ctrl+B)" }, h("strong", null, "B")), h("button", { type: "button", class: { 'le-text-toolbar-btn': true, 'active': this.selectionState.isItalic }, onMouseDown: this.toggleItalic, title: "Italic (Ctrl+I)" }, h("em", null, "I")), h("button", { type: "button", class: { 'le-text-toolbar-btn': true, 'active': this.selectionState.isUnderline }, onMouseDown: this.toggleUnderline, title: "Underline (Ctrl+U)" }, h("span", { style: { textDecoration: 'underline' } }, "U")), h("button", { type: "button", class: { 'le-text-toolbar-btn': true, 'active': this.selectionState.isStrikethrough }, onMouseDown: this.toggleStrikethrough, title: "Strikethrough" }, h("span", { style: { textDecoration: 'line-through' } }, "S")), h("div", { class: "le-text-toolbar-divider" }), h("button", { type: "button", class: { 'le-text-toolbar-btn': true, 'active': this.selectionState.isLink }, onMouseDown: this.toggleLink, title: this.selectionState.isLink ? 'Remove link' : 'Add link' }, "\uD83D\uDD17")));
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get the semantic tag for the current variant
|
|
302
|
+
*/
|
|
303
|
+
getTag() {
|
|
304
|
+
switch (this.variant) {
|
|
305
|
+
case 'quote':
|
|
306
|
+
return 'blockquote';
|
|
307
|
+
case 'code':
|
|
308
|
+
return 'pre';
|
|
309
|
+
case 'label':
|
|
310
|
+
return 'label';
|
|
311
|
+
case 'small':
|
|
312
|
+
return 'small';
|
|
313
|
+
default:
|
|
314
|
+
return this.variant; // h1-h6, p
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
render() {
|
|
318
|
+
const Tag = this.getTag();
|
|
319
|
+
const textStyle = {};
|
|
320
|
+
if (this.color) {
|
|
321
|
+
textStyle.color = this.color;
|
|
322
|
+
}
|
|
323
|
+
if (this.align) {
|
|
324
|
+
textStyle.textAlign = this.align;
|
|
325
|
+
}
|
|
326
|
+
const textClass = {
|
|
327
|
+
'le-text': true,
|
|
328
|
+
[`variant-${this.variant}`]: true,
|
|
329
|
+
'truncate': this.truncate,
|
|
330
|
+
[`max-lines-${this.maxLines}`]: this.truncate && this.maxLines,
|
|
331
|
+
};
|
|
332
|
+
// Admin mode - show rich text editor
|
|
333
|
+
if (this.adminMode) {
|
|
334
|
+
return (h(Host, { class: "admin-mode" }, h("div", { class: "le-text-editor-wrapper" }, this.isFocused && this.renderToolbar(), h(Tag, { class: textClass, part: "text", style: textStyle }, h("div", { ref: (el) => this.editorRef = el, class: "le-text-editor", contentEditable: true, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, onKeyUp: this.handleSelectionChange, onMouseUp: this.handleSelectionChange, innerHTML: this.content })), h("div", { class: "hidden-slot" }, h("slot", { ref: (el) => this.slotRef = el, onSlotchange: () => this.readSlottedContent() })))));
|
|
335
|
+
}
|
|
336
|
+
// Default mode - render semantic element with slotted content
|
|
337
|
+
return (h(Host, null, h(Tag, { class: textClass, part: "text", style: textStyle }, h("slot", { ref: (el) => this.slotRef = el }))));
|
|
338
|
+
}
|
|
339
|
+
static get is() { return "le-text"; }
|
|
340
|
+
static get encapsulation() { return "shadow"; }
|
|
341
|
+
static get originalStyleUrls() {
|
|
342
|
+
return {
|
|
343
|
+
"$": ["le-text.default.css"]
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
static get styleUrls() {
|
|
347
|
+
return {
|
|
348
|
+
"$": ["le-text.default.css"]
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
static get properties() {
|
|
352
|
+
return {
|
|
353
|
+
"variant": {
|
|
354
|
+
"type": "string",
|
|
355
|
+
"mutable": true,
|
|
356
|
+
"complexType": {
|
|
357
|
+
"original": "'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'code' | 'quote' | 'label' | 'small'",
|
|
358
|
+
"resolved": "\"code\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"label\" | \"p\" | \"quote\" | \"small\"",
|
|
359
|
+
"references": {}
|
|
360
|
+
},
|
|
361
|
+
"required": false,
|
|
362
|
+
"optional": false,
|
|
363
|
+
"docs": {
|
|
364
|
+
"tags": [{
|
|
365
|
+
"name": "allowedValues",
|
|
366
|
+
"text": "p | h1 | h2 | h3 | h4 | h5 | h6 | code | quote | label | small"
|
|
367
|
+
}],
|
|
368
|
+
"text": "The semantic variant/type of text element"
|
|
369
|
+
},
|
|
370
|
+
"getter": false,
|
|
371
|
+
"setter": false,
|
|
372
|
+
"reflect": true,
|
|
373
|
+
"attribute": "variant",
|
|
374
|
+
"defaultValue": "'p'"
|
|
375
|
+
},
|
|
376
|
+
"align": {
|
|
377
|
+
"type": "string",
|
|
378
|
+
"mutable": false,
|
|
379
|
+
"complexType": {
|
|
380
|
+
"original": "'left' | 'center' | 'right' | 'justify'",
|
|
381
|
+
"resolved": "\"center\" | \"justify\" | \"left\" | \"right\"",
|
|
382
|
+
"references": {}
|
|
383
|
+
},
|
|
384
|
+
"required": false,
|
|
385
|
+
"optional": false,
|
|
386
|
+
"docs": {
|
|
387
|
+
"tags": [{
|
|
388
|
+
"name": "allowedValues",
|
|
389
|
+
"text": "left | center | right | justify"
|
|
390
|
+
}],
|
|
391
|
+
"text": "Text alignment"
|
|
392
|
+
},
|
|
393
|
+
"getter": false,
|
|
394
|
+
"setter": false,
|
|
395
|
+
"reflect": true,
|
|
396
|
+
"attribute": "align",
|
|
397
|
+
"defaultValue": "'left'"
|
|
398
|
+
},
|
|
399
|
+
"color": {
|
|
400
|
+
"type": "string",
|
|
401
|
+
"mutable": false,
|
|
402
|
+
"complexType": {
|
|
403
|
+
"original": "string",
|
|
404
|
+
"resolved": "string",
|
|
405
|
+
"references": {}
|
|
406
|
+
},
|
|
407
|
+
"required": false,
|
|
408
|
+
"optional": true,
|
|
409
|
+
"docs": {
|
|
410
|
+
"tags": [],
|
|
411
|
+
"text": "Text color (CSS value or theme token)"
|
|
412
|
+
},
|
|
413
|
+
"getter": false,
|
|
414
|
+
"setter": false,
|
|
415
|
+
"reflect": false,
|
|
416
|
+
"attribute": "color"
|
|
417
|
+
},
|
|
418
|
+
"truncate": {
|
|
419
|
+
"type": "boolean",
|
|
420
|
+
"mutable": false,
|
|
421
|
+
"complexType": {
|
|
422
|
+
"original": "boolean",
|
|
423
|
+
"resolved": "boolean",
|
|
424
|
+
"references": {}
|
|
425
|
+
},
|
|
426
|
+
"required": false,
|
|
427
|
+
"optional": false,
|
|
428
|
+
"docs": {
|
|
429
|
+
"tags": [],
|
|
430
|
+
"text": "Whether the text should truncate with ellipsis"
|
|
431
|
+
},
|
|
432
|
+
"getter": false,
|
|
433
|
+
"setter": false,
|
|
434
|
+
"reflect": false,
|
|
435
|
+
"attribute": "truncate",
|
|
436
|
+
"defaultValue": "false"
|
|
437
|
+
},
|
|
438
|
+
"maxLines": {
|
|
439
|
+
"type": "number",
|
|
440
|
+
"mutable": false,
|
|
441
|
+
"complexType": {
|
|
442
|
+
"original": "number",
|
|
443
|
+
"resolved": "number",
|
|
444
|
+
"references": {}
|
|
445
|
+
},
|
|
446
|
+
"required": false,
|
|
447
|
+
"optional": true,
|
|
448
|
+
"docs": {
|
|
449
|
+
"tags": [],
|
|
450
|
+
"text": "Maximum number of lines before truncating (requires truncate=true)"
|
|
451
|
+
},
|
|
452
|
+
"getter": false,
|
|
453
|
+
"setter": false,
|
|
454
|
+
"reflect": false,
|
|
455
|
+
"attribute": "max-lines"
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
static get states() {
|
|
460
|
+
return {
|
|
461
|
+
"adminMode": {},
|
|
462
|
+
"content": {},
|
|
463
|
+
"isFocused": {},
|
|
464
|
+
"selectionState": {}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
static get elementRef() { return "el"; }
|
|
468
|
+
static get watchers() {
|
|
469
|
+
return [{
|
|
470
|
+
"propName": "variant",
|
|
471
|
+
"methodName": "onVariantChange"
|
|
472
|
+
}];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=le-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"le-text.js","sourceRoot":"","sources":["../../../src-core/components/le-text/le-text.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,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EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,EAAqB,EACjD,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,GACvC,CACJ,CACF,CAEH,CACR,CAAC;QACJ,CAAC;QAED,8DAA8D;QAC9D,OAAO,CACL,EAAC,IAAI;YACH,EAAC,GAAG,IACF,KAAK,EAAE,SAAS,EAChB,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,SAAS;gBAEhB,YAAM,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,EAAqB,GAAS,CAC5D,CACD,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Prop, State, h, Host, Element, Watch } from '@stencil/core';\nimport { observeModeChanges } from '../../utils/utils';\n\n/**\n * A text component with rich text editing capabilities in admin mode.\n *\n * `le-text` renders semantic text elements (headings, paragraphs, code, quotes)\n * and provides a Notion-like rich text editor in admin mode with formatting\n * toolbar for bold, italic, links, and paragraph type selection.\n *\n * @slot - Default slot for text content\n *\n * @cssprop --le-text-color - Text color\n * @cssprop --le-text-font-size - Font size\n * @cssprop --le-text-line-height - Line height\n * @cssprop --le-text-font-weight - Font weight\n *\n * @csspart text - The text container element\n *\n * @cmsEditable true\n * @cmsCategory Content\n */\n@Component({\n tag: 'le-text',\n styleUrl: 'le-text.default.css',\n shadow: true,\n})\nexport class LeText {\n @Element() el: HTMLElement;\n\n /**\n * The semantic variant/type of text element\n * @allowedValues p | h1 | h2 | h3 | h4 | h5 | h6 | code | quote | label | small\n */\n @Prop({ mutable: true, reflect: true }) variant: 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'code' | 'quote' | 'label' | 'small' = 'p';\n\n /**\n * Text alignment\n * @allowedValues left | center | right | justify\n */\n @Prop({ reflect: true }) align: 'left' | 'center' | 'right' | 'justify' = 'left';\n\n /**\n * Text color (CSS value or theme token)\n */\n @Prop() color?: string;\n\n /**\n * Whether the text should truncate with ellipsis\n */\n @Prop() truncate: boolean = false;\n\n /**\n * Maximum number of lines before truncating (requires truncate=true)\n */\n @Prop() maxLines?: number;\n\n /**\n * Internal state to track admin mode\n */\n @State() private adminMode: boolean = false;\n\n /**\n * The HTML content being edited\n */\n @State() private content: string = '';\n\n /**\n * Whether the editor is focused (shows toolbar)\n */\n @State() private isFocused: boolean = false;\n\n /**\n * Current selection state for toolbar button highlighting\n */\n @State() private selectionState: SelectionState = {\n isBold: false,\n isItalic: false,\n isUnderline: false,\n isStrikethrough: false,\n isLink: false,\n blockType: 'p',\n };\n\n /**\n * Reference to the contenteditable element\n */\n private editorRef?: HTMLDivElement;\n\n /**\n * Reference to the slot element\n */\n private slotRef?: HTMLSlotElement;\n\n private disconnectModeObserver?: () => void;\n\n connectedCallback() {\n this.disconnectModeObserver = observeModeChanges(this.el, (mode) => {\n const wasAdmin = this.adminMode;\n this.adminMode = mode === 'admin';\n \n if (this.adminMode && !wasAdmin) {\n // Entering admin mode - read content from slot\n requestAnimationFrame(() => this.readSlottedContent());\n } else if (!this.adminMode && wasAdmin) {\n // Leaving admin mode - sync content back to slot\n this.syncContentToSlot();\n }\n });\n }\n\n disconnectedCallback() {\n this.disconnectModeObserver?.();\n }\n\n @Watch('variant')\n onVariantChange() {\n // When variant changes in admin mode, update the content wrapper\n if (this.adminMode && this.editorRef) {\n this.syncContentToSlot();\n }\n }\n\n /**\n * Read content from slotted elements\n */\n private readSlottedContent() {\n if (!this.slotRef) return;\n \n const assignedNodes = this.slotRef.assignedNodes({ flatten: true });\n \n // Collect all content from assigned nodes\n let html = '';\n assignedNodes.forEach(node => {\n if (node.nodeType === Node.TEXT_NODE) {\n html += node.textContent;\n } else if (node.nodeType === Node.ELEMENT_NODE) {\n html += (node as Element).innerHTML || node.textContent;\n }\n });\n \n this.content = html.trim();\n }\n\n /**\n * Sync edited content back to the slot\n */\n private syncContentToSlot() {\n if (!this.editorRef) return;\n \n const newContent = this.editorRef.innerHTML;\n \n // Update the light DOM content\n // We need to update the actual slotted content\n const slot = this.slotRef;\n if (slot) {\n const assignedNodes = slot.assignedNodes({ flatten: true });\n if (assignedNodes.length > 0) {\n const firstNode = assignedNodes[0];\n if (firstNode.nodeType === Node.ELEMENT_NODE) {\n (firstNode as Element).innerHTML = newContent;\n } else if (firstNode.nodeType === Node.TEXT_NODE) {\n // Replace text node with the new content\n const parent = firstNode.parentNode;\n if (parent) {\n // Create a temporary element to parse HTML\n const temp = document.createElement('span');\n temp.innerHTML = newContent;\n // Replace the text node\n parent.replaceChild(temp, firstNode);\n // Unwrap the span if it only contains text\n if (temp.childNodes.length === 1 && temp.firstChild?.nodeType === Node.TEXT_NODE) {\n parent.replaceChild(temp.firstChild, temp);\n }\n }\n }\n } else {\n // No assigned nodes, set innerHTML on the host's light DOM\n this.el.innerHTML = newContent;\n }\n }\n }\n\n /**\n * Handle input in the contenteditable\n */\n private handleInput = () => {\n if (this.editorRef) {\n this.content = this.editorRef.innerHTML;\n this.updateSelectionState();\n }\n };\n\n /**\n * Handle focus on the editor\n */\n private handleFocus = () => {\n this.isFocused = true;\n this.updateSelectionState();\n };\n\n /**\n * Handle blur on the editor\n */\n private handleBlur = (e: FocusEvent) => {\n // Check if focus moved to toolbar\n const relatedTarget = e.relatedTarget as HTMLElement;\n const toolbar = this.el.shadowRoot?.querySelector('.le-text-toolbar');\n \n if (toolbar?.contains(relatedTarget)) {\n // Focus moved to toolbar, keep it open\n return;\n }\n \n // Small delay to allow toolbar clicks to register\n setTimeout(() => {\n if (!this.el.shadowRoot?.activeElement) {\n this.isFocused = false;\n this.syncContentToSlot();\n }\n }, 150);\n };\n\n /**\n * Handle selection change to update toolbar state\n */\n private handleSelectionChange = () => {\n this.updateSelectionState();\n };\n\n /**\n * Update the selection state for toolbar highlighting\n */\n private updateSelectionState() {\n const selection = window.getSelection();\n if (!selection || selection.rangeCount === 0) return;\n\n this.selectionState = {\n isBold: document.queryCommandState('bold'),\n isItalic: document.queryCommandState('italic'),\n isUnderline: document.queryCommandState('underline'),\n isStrikethrough: document.queryCommandState('strikeThrough'),\n isLink: this.isSelectionInLink(selection),\n blockType: this.variant,\n };\n }\n\n /**\n * Check if current selection is within a link\n */\n private isSelectionInLink(selection: Selection): boolean {\n if (!selection.anchorNode) return false;\n \n let node: Node | null = selection.anchorNode;\n while (node && node !== this.editorRef) {\n if (node.nodeName === 'A') return true;\n node = node.parentNode;\n }\n return false;\n }\n\n /**\n * Execute a formatting command\n */\n private execCommand(command: string, value?: string) {\n // Focus the editor first\n this.editorRef?.focus();\n \n // Execute the command\n document.execCommand(command, false, value);\n \n // Update state\n this.handleInput();\n this.updateSelectionState();\n }\n\n /**\n * Toggle bold formatting\n */\n private toggleBold = (e: Event) => {\n e.preventDefault();\n this.execCommand('bold');\n };\n\n /**\n * Toggle italic formatting\n */\n private toggleItalic = (e: Event) => {\n e.preventDefault();\n this.execCommand('italic');\n };\n\n /**\n * Toggle underline formatting\n */\n private toggleUnderline = (e: Event) => {\n e.preventDefault();\n this.execCommand('underline');\n };\n\n /**\n * Toggle strikethrough formatting\n */\n private toggleStrikethrough = (e: Event) => {\n e.preventDefault();\n this.execCommand('strikeThrough');\n };\n\n /**\n * Add or edit a link\n */\n private toggleLink = (e: Event) => {\n e.preventDefault();\n \n if (this.selectionState.isLink) {\n // Remove link\n this.execCommand('unlink');\n } else {\n // Add link\n const url = prompt('Enter URL:', 'https://');\n if (url) {\n this.execCommand('createLink', url);\n }\n }\n };\n\n /**\n * Change the block type/variant\n */\n private changeVariant = (e: Event) => {\n const select = e.target as HTMLSelectElement;\n this.variant = select.value as typeof this.variant;\n };\n\n /**\n * Render the formatting toolbar\n */\n private renderToolbar() {\n return (\n <div class=\"le-text-toolbar\">\n <select \n class=\"le-text-toolbar-select\"\n onChange={this.changeVariant}\n onMouseDown={(e) => e.preventDefault()}\n >\n <option value=\"p\" selected={this.variant === 'p'}>Paragraph</option>\n <option value=\"h1\" selected={this.variant === 'h1'}>Heading 1</option>\n <option value=\"h2\" selected={this.variant === 'h2'}>Heading 2</option>\n <option value=\"h3\" selected={this.variant === 'h3'}>Heading 3</option>\n <option value=\"h4\" selected={this.variant === 'h4'}>Heading 4</option>\n <option value=\"h5\" selected={this.variant === 'h5'}>Heading 5</option>\n <option value=\"h6\" selected={this.variant === 'h6'}>Heading 6</option>\n <option value=\"quote\" selected={this.variant === 'quote'}>Quote</option>\n <option value=\"code\" selected={this.variant === 'code'}>Code</option>\n <option value=\"label\" selected={this.variant === 'label'}>Label</option>\n <option value=\"small\" selected={this.variant === 'small'}>Small</option>\n </select>\n \n <div class=\"le-text-toolbar-divider\"></div>\n \n <button\n type=\"button\"\n class={{ 'le-text-toolbar-btn': true, 'active': this.selectionState.isBold }}\n onMouseDown={this.toggleBold}\n title=\"Bold (Ctrl+B)\"\n >\n <strong>B</strong>\n </button>\n \n <button\n type=\"button\"\n class={{ 'le-text-toolbar-btn': true, 'active': this.selectionState.isItalic }}\n onMouseDown={this.toggleItalic}\n title=\"Italic (Ctrl+I)\"\n >\n <em>I</em>\n </button>\n \n <button\n type=\"button\"\n class={{ 'le-text-toolbar-btn': true, 'active': this.selectionState.isUnderline }}\n onMouseDown={this.toggleUnderline}\n title=\"Underline (Ctrl+U)\"\n >\n <span style={{ textDecoration: 'underline' }}>U</span>\n </button>\n \n <button\n type=\"button\"\n class={{ 'le-text-toolbar-btn': true, 'active': this.selectionState.isStrikethrough }}\n onMouseDown={this.toggleStrikethrough}\n title=\"Strikethrough\"\n >\n <span style={{ textDecoration: 'line-through' }}>S</span>\n </button>\n \n <div class=\"le-text-toolbar-divider\"></div>\n \n <button\n type=\"button\"\n class={{ 'le-text-toolbar-btn': true, 'active': this.selectionState.isLink }}\n onMouseDown={this.toggleLink}\n title={this.selectionState.isLink ? 'Remove link' : 'Add link'}\n >\n 🔗\n </button>\n </div>\n );\n }\n\n /**\n * Get the semantic tag for the current variant\n */\n private getTag(): string {\n switch (this.variant) {\n case 'quote':\n return 'blockquote';\n case 'code':\n return 'pre';\n case 'label':\n return 'label';\n case 'small':\n return 'small';\n default:\n return this.variant; // h1-h6, p\n }\n }\n\n render() {\n const Tag = this.getTag();\n \n const textStyle: { [key: string]: string } = {};\n if (this.color) {\n textStyle.color = this.color;\n }\n if (this.align) {\n textStyle.textAlign = this.align;\n }\n\n const textClass = {\n 'le-text': true,\n [`variant-${this.variant}`]: true,\n 'truncate': this.truncate,\n [`max-lines-${this.maxLines}`]: this.truncate && this.maxLines,\n };\n\n // Admin mode - show rich text editor\n if (this.adminMode) {\n return (\n <Host class=\"admin-mode\">\n \n <div class=\"le-text-editor-wrapper\">\n {this.isFocused && this.renderToolbar()}\n <Tag \n class={textClass}\n part=\"text\"\n style={textStyle}\n >\n <div\n ref={(el) => this.editorRef = el}\n class=\"le-text-editor\"\n contentEditable={true}\n onInput={this.handleInput}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n onKeyUp={this.handleSelectionChange}\n onMouseUp={this.handleSelectionChange}\n innerHTML={this.content}\n ></div>\n </Tag>\n {/* Hidden slot to receive light DOM content */}\n <div class=\"hidden-slot\">\n <slot \n ref={(el) => this.slotRef = el as HTMLSlotElement}\n onSlotchange={() => this.readSlottedContent()}\n ></slot>\n </div>\n </div>\n \n </Host>\n );\n }\n\n // Default mode - render semantic element with slotted content\n return (\n <Host>\n <Tag \n class={textClass}\n part=\"text\"\n style={textStyle}\n >\n <slot ref={(el) => this.slotRef = el as HTMLSlotElement}></slot>\n </Tag>\n </Host>\n );\n }\n}\n\n/**\n * Selection state for toolbar\n */\ninterface SelectionState {\n isBold: boolean;\n isItalic: boolean;\n isUnderline: boolean;\n isStrikethrough: boolean;\n isLink: boolean;\n blockType: string;\n}\n"]}
|