@bettercms-ai/kit 4.0.0 → 4.2.0-next.0
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/adapters/lossy.d.ts +4 -0
- package/dist/adapters/lossy.js +4 -0
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/prod-types.d.ts +4 -0
- package/dist/adapters/prod-types.js +4 -1
- package/dist/adapters/prod-types.js.map +1 -1
- package/dist/adapters/schema.js +7 -0
- package/dist/adapters/schema.js.map +1 -1
- package/dist/context.d.ts +91 -0
- package/dist/context.js +58 -1
- package/dist/context.js.map +1 -1
- package/dist/controls/choice.d.ts +1 -1
- package/dist/controls/choice.js +21 -2
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/index.d.ts +1 -0
- package/dist/controls/index.js +3 -2
- package/dist/controls/index.js.map +1 -1
- package/dist/controls/link.d.ts +23 -2
- package/dist/controls/link.js +456 -4
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/media-v16.d.ts +27 -0
- package/dist/controls/media-v16.js +261 -0
- package/dist/controls/media-v16.js.map +1 -0
- package/dist/controls/media.js +63 -1
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/reference-services.d.ts +8 -0
- package/dist/controls/reference.js +78 -2
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/ai-runs.d.ts +13 -0
- package/dist/controls/rich-text/ai-runs.js +71 -0
- package/dist/controls/rich-text/ai-runs.js.map +1 -0
- package/dist/controls/rich-text/block-tool.d.ts +31 -0
- package/dist/controls/rich-text/block-tool.js +62 -0
- package/dist/controls/rich-text/block-tool.js.map +1 -0
- package/dist/controls/rich-text/blocks.d.ts +6 -1
- package/dist/controls/rich-text/blocks.js +406 -24
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/catalog.d.ts +45 -7
- package/dist/controls/rich-text/catalog.js +507 -37
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/code-head.d.ts +30 -0
- package/dist/controls/rich-text/code-head.js +230 -0
- package/dist/controls/rich-text/code-head.js.map +1 -0
- package/dist/controls/rich-text/codec.d.ts +1 -1
- package/dist/controls/rich-text/codec.js +4 -1
- package/dist/controls/rich-text/codec.js.map +1 -1
- package/dist/controls/rich-text/dom.d.ts +27 -0
- package/dist/controls/rich-text/dom.js +77 -7
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.js +243 -55
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.js +1 -0
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/controls/rich-text/rewriteSelection.d.ts +25 -0
- package/dist/controls/rich-text/rewriteSelection.js +28 -0
- package/dist/controls/rich-text/rewriteSelection.js.map +1 -0
- package/dist/controls/rich-text/slash-preview.d.ts +8 -0
- package/dist/controls/rich-text/slash-preview.js +300 -0
- package/dist/controls/rich-text/slash-preview.js.map +1 -0
- package/dist/controls/rich-text/table-grid.d.ts +22 -0
- package/dist/controls/rich-text/table-grid.js +1057 -0
- package/dist/controls/rich-text/table-grid.js.map +1 -0
- package/dist/controls/rich-text/toolbar.js +61 -18
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/text.d.ts +6 -0
- package/dist/controls/text.js +95 -5
- package/dist/controls/text.js.map +1 -1
- package/dist/core/facets.d.ts +1 -0
- package/dist/core/facets.js +1 -0
- package/dist/core/facets.js.map +1 -1
- package/dist/engine/array.d.ts +7 -0
- package/dist/engine/array.js +164 -45
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/field-shell.d.ts +12 -0
- package/dist/engine/field-shell.js +222 -64
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +42 -4
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.d.ts +71 -10
- package/dist/engine/grouping.js +227 -29
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +2 -2
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/kit-field.js +38 -4
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.d.ts +2 -0
- package/dist/engine/schema-form.js +9 -2
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/kit.css +59 -0
- package/dist/lib/reduced-motion.d.ts +1 -0
- package/dist/lib/reduced-motion.js +19 -0
- package/dist/lib/reduced-motion.js.map +1 -0
- package/dist/schema/table.d.ts +2 -1
- package/dist/schema/table.js +5 -0
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/types.d.ts +6 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +215 -0
- package/dist/tokens.css +274 -0
- package/dist/ui/block-icon-picker.d.ts +38 -0
- package/dist/ui/block-icon-picker.js +141 -0
- package/dist/ui/block-icon-picker.js.map +1 -0
- package/dist/ui/button.js +1 -0
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/code-language-menu.d.ts +24 -0
- package/dist/ui/code-language-menu.js +123 -0
- package/dist/ui/code-language-menu.js.map +1 -0
- package/dist/ui/content-fields.d.ts +47 -0
- package/dist/ui/content-fields.js +279 -0
- package/dist/ui/content-fields.js.map +1 -0
- package/dist/ui/controls.js +3 -2
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/floating-panel.js +3 -2
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/foundations.d.ts +118 -0
- package/dist/ui/foundations.js +565 -0
- package/dist/ui/foundations.js.map +1 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +7 -1
- package/dist/ui/inspector.d.ts +412 -0
- package/dist/ui/inspector.js +1218 -0
- package/dist/ui/inspector.js.map +1 -0
- package/dist/ui/overlay.d.ts +7 -2
- package/dist/ui/overlay.js +55 -20
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/shortcut-hint.js +1 -1
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/tab.js +3 -2
- package/dist/ui/tab.js.map +1 -1
- package/dist/ui/toast.d.ts +5 -3
- package/dist/ui/toast.js +83 -11
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-card.d.ts +45 -0
- package/dist/ui/tooltip-card.js +135 -0
- package/dist/ui/tooltip-card.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { cn } from "../../lib/cn.js";
|
|
2
|
-
import { useKitEnv, useKitServices } from "../../context.js";
|
|
2
|
+
import { AI_REWRITE_COMMANDS, useKitEnv, useKitLook, useKitServices } from "../../context.js";
|
|
3
3
|
import { Button } from "../../ui/button.js";
|
|
4
4
|
import { platformKeys, shortcutHintsOn } from "../../ui/shortcut-hint.js";
|
|
5
|
+
import { useKitReducedMotion } from "../../lib/reduced-motion.js";
|
|
5
6
|
import { Menu, MenuContent, MenuItem, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuSub, MenuSubContent, MenuSubTrigger, MenuTrigger, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Tooltip } from "../../ui/overlay.js";
|
|
6
7
|
import { Input, Textarea } from "../../ui/input.js";
|
|
7
8
|
import { LinkPopoverBody } from "../link.js";
|
|
8
9
|
import { ExpandedEditorModal } from "../../ui/expanded-editor-modal.js";
|
|
9
|
-
import { closestBlock, createIsland, defaultModel, editingHost, esc, hydrate, isEmptyHtml, ownsMenu, placeCaret, rangeRect, rid, sanitize, serialize, textBeforeCaret, topBlock } from "./dom.js";
|
|
10
|
+
import { closestBlock, createIsland, defaultModel, editingHost, esc, hydrate, isEmptyHtml, ownsMenu, placeCaret, rangeRect, rid, sanitize, serialize, textBeforeCaret, textToParas, topBlock } from "./dom.js";
|
|
10
11
|
import { COMPONENT_INSERT_TOAST } from "../component-services.js";
|
|
11
12
|
import { eventKey } from "../../lib/key-event.js";
|
|
13
|
+
import { aiCommandsOffered, mapRewriteOntoRuns, textRuns } from "./ai-runs.js";
|
|
12
14
|
import { ALL_FEATURES } from "./codec.js";
|
|
15
|
+
import { FORMATTING_REMOVED, LINK_SENTINEL, linkAttrs, selectionShape, unwrapLinkSentinels } from "./rewriteSelection.js";
|
|
13
16
|
import { createOutlineStore, outlineOf } from "./toc.js";
|
|
14
17
|
import { CatalogComponentsProvider, InsertMenuContent, SlashMenuPanel, blockAllowed, catalogKey, noteRecent, useCatalog } from "./catalog.js";
|
|
15
18
|
import { openComponentPanel } from "./component-panel.js";
|
|
@@ -20,12 +23,13 @@ import { EMPTY_FMT, FormatToolbar, MARK_FEATURE, stylesFor } from "./toolbar.js"
|
|
|
20
23
|
import { SelectionBubble } from "./floating.js";
|
|
21
24
|
import { applyTextLink, fromLinkValue, textLinkOf, toLinkValue } from "./link-form.js";
|
|
22
25
|
import { checklistShortcut, insertChecklist, syncTaskA11y, toggleTaskAtPointer, toggleTaskFromKey } from "./checklist.js";
|
|
26
|
+
import { CodeHead, measureCodes, recolourCodes, sameCodes } from "./code-head.js";
|
|
23
27
|
import { FN_MARK, FOOTNOTE_POPOVER_CLASS, FOOTNOTE_REFUSED, FootnoteEditor, FootnotesList, backToMarker, caretAfterMarker, insertFootnote, renumberFootnotes } from "./footnote.js";
|
|
24
28
|
import { ButtonLinkPanel, applyButton, buttonAt, buttonInitial, insertButton, removeButton } from "./button.js";
|
|
25
29
|
import * as React from "react";
|
|
26
30
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
27
31
|
import { IconArrowBarToDown, IconArrowBarToUp, IconCode, IconCopy, IconGripVertical, IconPlus, IconTransform, IconTrash } from "@tabler/icons-react";
|
|
28
|
-
import { AnimatePresence, motion
|
|
32
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
29
33
|
import { createPortal, flushSync } from "react-dom";
|
|
30
34
|
//#region src/controls/rich-text/editor.tsx
|
|
31
35
|
/**
|
|
@@ -46,6 +50,7 @@ import { createPortal, flushSync } from "react-dom";
|
|
|
46
50
|
* Everything the editor offers is limited to what the field accepts (`features`): a toolbar button, a slash command, a
|
|
47
51
|
* Markdown shortcut or pasted markup the field cannot hold is not offered, or is turned into what it can hold and said so.
|
|
48
52
|
*/
|
|
53
|
+
var V16_QUOTE_CLASS = "[&_blockquote:not([data-rt-isolate]_*)]:border-kit-insp-accent [&_blockquote:not([data-rt-isolate]_*)]:py-0.5 [&_blockquote:not([data-rt-isolate]_*)]:text-[17px] [&_blockquote:not([data-rt-isolate]_*)]:leading-7 [&_blockquote:not([data-rt-isolate]_*)]:text-kit-insp-tip-body";
|
|
49
54
|
var RT_PROSE = "text-kit-base leading-[1.6] text-kit-fg [&>*+*]:mt-3 [&_span[class]:not([data-rt-isolate]_*)]:!text-inherit [&_span[class]:not([data-rt-isolate]_*)]:![-webkit-text-fill-color:currentColor] [&_span[class]:not([data-rt-isolate]_*)]:!bg-none [&_span[class]:not([data-rt-isolate]_*)]:!opacity-100 [&_span[class]:not([data-rt-isolate]_*)]:!visible [&_h1:not([data-rt-isolate]_*)]:text-[28px] [&_h1:not([data-rt-isolate]_*)]:font-semibold [&_h1:not([data-rt-isolate]_*)]:leading-9 [&_h1:not([data-rt-isolate]_*)]:tracking-[-0.01em] [&_h2:not([data-rt-isolate]_*)]:text-[22px] [&_h2:not([data-rt-isolate]_*)]:font-semibold [&_h2:not([data-rt-isolate]_*)]:leading-8 [&_h2:not([data-rt-isolate]_*)]:tracking-[-0.01em] [&_h3:not([data-rt-isolate]_*)]:text-kit-lg [&_h3:not([data-rt-isolate]_*)]:font-semibold [&_h4:not([data-rt-isolate]_*)]:text-kit-md [&_h4:not([data-rt-isolate]_*)]:font-semibold [&_h5:not([data-rt-isolate]_*)]:text-kit-base [&_h5:not([data-rt-isolate]_*)]:font-semibold [&_h6:not([data-rt-isolate]_*)]:text-kit-sm [&_h6:not([data-rt-isolate]_*)]:font-semibold [&_h6:not([data-rt-isolate]_*)]:uppercase [&_h6:not([data-rt-isolate]_*)]:tracking-wide [&_h6:not([data-rt-isolate]_*)]:text-kit-fg-2 [&>h1]:mt-6 [&>h2]:mt-6 [&>h3]:mt-5 [&>*:first-child]:mt-0 [&_ul:not([data-rt-isolate]_*)]:list-disc [&_ul:not([data-rt-isolate]_*)]:pl-5 [&_ol:not([data-rt-isolate]_*)]:list-decimal [&_ol:not([data-rt-isolate]_*)]:pl-5 [&_li:not([data-rt-isolate]_*)]:pl-1 [&_li+li:not([data-rt-isolate]_*)]:mt-1 [&_li:not([data-rt-isolate]_*)]:marker:text-kit-fg-3 [&_ul[data-task]:not([data-rt-isolate]_*)]:list-none [&_ul[data-task]:not([data-rt-isolate]_*)]:pl-0 [&_ul[data-task]>li:not([data-rt-isolate]_*)]:relative [&_ul[data-task]>li:not([data-rt-isolate]_*)]:pl-7 [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:absolute [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:left-0 [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:top-[0.2em] [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:flex [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:size-4 [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:items-center [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:justify-center [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:rounded-kit-md [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:border [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:border-kit-line-strong [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:bg-kit-surface [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:text-[11px] [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:font-semibold [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:leading-none [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:content-[''] [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:text-kit-fg-3 [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:line-through [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:before:border-kit-inverse [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:before:bg-kit-inverse [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:before:text-kit-fg-inverse [&_ul[data-task]>li[data-checked=true]:not([data-rt-isolate]_*)]:before:content-['✓'] [&_blockquote:not([data-rt-isolate]_*)]:border-l-2 [&_blockquote:not([data-rt-isolate]_*)]:border-kit-line-strong [&_blockquote:not([data-rt-isolate]_*)]:pl-4 [&_blockquote:not([data-rt-isolate]_*)]:text-kit-fg-2 [&_blockquote:not([data-rt-isolate]_*)]:italic [&_a:not([data-rt-isolate]_*)]:text-kit-accent-fg [&_a:not([data-rt-isolate]_*)]:underline [&_a:not([data-rt-isolate]_*)]:decoration-kit-accent-line [&_a:not([data-rt-isolate]_*)]:underline-offset-2 [&_a[data-button]:not([data-rt-isolate]_*)]:inline-flex [&_a[data-button]:not([data-rt-isolate]_*)]:h-9 [&_a[data-button]:not([data-rt-isolate]_*)]:items-center [&_a[data-button]:not([data-rt-isolate]_*)]:rounded-kit-md [&_a[data-button]:not([data-rt-isolate]_*)]:bg-kit-inverse [&_a[data-button]:not([data-rt-isolate]_*)]:px-3.5 [&_a[data-button]:not([data-rt-isolate]_*)]:text-kit-sm [&_a[data-button]:not([data-rt-isolate]_*)]:font-medium [&_a[data-button]:not([data-rt-isolate]_*)]:text-kit-fg-inverse [&_a[data-button]:not([data-rt-isolate]_*)]:no-underline [&_abbr:not([data-rt-isolate]_*)]:cursor-help [&_abbr:not([data-rt-isolate]_*)]:underline [&_abbr:not([data-rt-isolate]_*)]:decoration-dotted [&_abbr:not([data-rt-isolate]_*)]:underline-offset-2 [&_sup:not([data-rt-isolate]_*)]:text-[0.7em] [&_sup:not([data-rt-isolate]_*)]:leading-none [&_code:not([data-rt-isolate]_*)]:rounded-kit-md [&_code:not([data-rt-isolate]_*)]:bg-kit-muted [&_code:not([data-rt-isolate]_*)]:px-1 [&_code:not([data-rt-isolate]_*)]:py-px [&_code:not([data-rt-isolate]_*)]:font-kit-mono [&_code:not([data-rt-isolate]_*)]:text-[0.9em] [&_pre:not([data-rt-isolate]_*)]:overflow-x-auto [&_pre:not([data-rt-isolate]_*)]:whitespace-pre [&_pre:not([data-rt-isolate]_*)]:rounded-kit-lg [&_pre:not([data-rt-isolate]_*)]:bg-kit-code [&_pre:not([data-rt-isolate]_*)]:text-kit-code-fg [&_pre:not([data-rt-isolate]_*)]:p-3 [&_pre:not([data-rt-isolate]_*)]:font-kit-mono [&_pre:not([data-rt-isolate]_*)]:text-kit-sm [&_pre:not([data-rt-isolate]_*)]:border [&_pre:not([data-rt-isolate]_*)]:border-kit-line [&_pre_code:not([data-rt-isolate]_*)]:rounded-none [&_pre_code:not([data-rt-isolate]_*)]:bg-transparent [&_pre_code:not([data-rt-isolate]_*)]:p-0 [&_pre_code:not([data-rt-isolate]_*)]:text-[1em] [&_hr:not([data-rt-isolate]_*)]:my-6 [&_hr:not([data-rt-isolate]_*)]:border-kit-line [&_figure:not([data-rt-isolate]_*)]:my-4 [&_img:not([data-rt-isolate]_*)]:rounded-kit-lg [&_img:not([data-rt-isolate]_*)]:border [&_img:not([data-rt-isolate]_*)]:border-kit-line [&_figcaption:not([data-rt-isolate]_*)]:mt-1.5 [&_figcaption:not([data-rt-isolate]_*)]:text-center [&_figcaption:not([data-rt-isolate]_*)]:text-kit-sm [&_figcaption:not([data-rt-isolate]_*)]:text-kit-fg-3 [&_figure_img:not([data-rt-isolate]_*)]:block [&_figure[data-size=s]_img:not([data-rt-isolate]_*)]:w-1/3 [&_figure[data-size=m]_img:not([data-rt-isolate]_*)]:w-1/2 [&_figure[data-size=l]_img:not([data-rt-isolate]_*)]:w-3/4 [&_figure[data-align=center]_img:not([data-rt-isolate]_*)]:mx-auto [&_figure[data-align=right]_img:not([data-rt-isolate]_*)]:ml-auto [&_figure[data-align=full]_img:not([data-rt-isolate]_*)]:w-full [&_div[data-callout]:not([data-rt-isolate]_*)]:rounded-kit-lg [&_div[data-callout]:not([data-rt-isolate]_*)]:border [&_div[data-callout]:not([data-rt-isolate]_*)]:border-kit-info-line [&_div[data-callout]:not([data-rt-isolate]_*)]:bg-kit-info-soft [&_div[data-callout]:not([data-rt-isolate]_*)]:px-4 [&_div[data-callout]:not([data-rt-isolate]_*)]:py-3 [&_div[data-callout]:not([data-rt-isolate]_*)]:text-kit-fg [&_div[data-callout=tip]:not([data-rt-isolate]_*)]:border-kit-success-line [&_div[data-callout=tip]:not([data-rt-isolate]_*)]:bg-kit-success-soft [&_div[data-callout=warning]:not([data-rt-isolate]_*)]:border-kit-warning-line [&_div[data-callout=warning]:not([data-rt-isolate]_*)]:bg-kit-warning-soft [&_div[data-callout]>p[data-title]:not([data-rt-isolate]_*)]:font-medium [&_details:not([data-rt-isolate]_*)]:rounded-kit-md [&_summary:not([data-rt-isolate]_*)]:cursor-pointer [&_summary:not([data-rt-isolate]_*)]:font-medium [&_details>div:not([data-rt-isolate]_*)]:mt-1 [&_details>div:not([data-rt-isolate]_*)]:border-l [&_details>div:not([data-rt-isolate]_*)]:border-kit-line [&_details>div:not([data-rt-isolate]_*)]:pl-4 [&_details>div:not([data-rt-isolate]_*)]:ml-1 [&_div[data-rt=columns]:not([data-rt-isolate]_*)]:grid [&_div[data-rt=columns]:not([data-rt-isolate]_*)]:gap-4 [&_div[data-cols='2']:not([data-rt-isolate]_*)]:grid-cols-2 [&_div[data-cols='3']:not([data-rt-isolate]_*)]:grid-cols-3 [&_div[data-cols='4']:not([data-rt-isolate]_*)]:grid-cols-4 [&_div[data-gap=s]:not([data-rt-isolate]_*)]:gap-2 [&_div[data-gap=l]:not([data-rt-isolate]_*)]:gap-7 [&_div[data-rt=file]:not([data-rt-isolate]_*)]:rounded-kit-lg [&_div[data-rt=file]:not([data-rt-isolate]_*)]:border [&_div[data-rt=file]:not([data-rt-isolate]_*)]:border-kit-line [&_div[data-rt=file]:not([data-rt-isolate]_*)]:px-3 [&_div[data-rt=file]:not([data-rt-isolate]_*)]:py-2.5 [&_div[data-rt=file]:not([data-rt-isolate]_*)]:text-kit-sm [&_div[data-embed]:not([data-rt-isolate]_*)]:flex [&_div[data-embed]:not([data-rt-isolate]_*)]:aspect-video [&_div[data-embed]:not([data-rt-isolate]_*)]:items-center [&_div[data-embed]:not([data-rt-isolate]_*)]:justify-center [&_div[data-embed]:not([data-rt-isolate]_*)]:rounded-kit-lg [&_div[data-embed]:not([data-rt-isolate]_*)]:border [&_div[data-embed]:not([data-rt-isolate]_*)]:border-kit-line [&_div[data-embed]:not([data-rt-isolate]_*)]:bg-kit-subtle [&_div[data-embed]:not([data-rt-isolate]_*)]:text-kit-sm [&_div[data-embed]:not([data-rt-isolate]_*)]:text-kit-fg-3 [&_div[data-block]:not([data-rt-isolate]_*)]:flex [&_div[data-block]:not([data-rt-isolate]_*)]:items-center [&_div[data-block]:not([data-rt-isolate]_*)]:gap-2 [&_div[data-block]:not([data-rt-isolate]_*)]:rounded-kit-lg [&_div[data-block]:not([data-rt-isolate]_*)]:border [&_div[data-block]:not([data-rt-isolate]_*)]:border-dashed [&_div[data-block]:not([data-rt-isolate]_*)]:border-kit-accent-line [&_div[data-block]:not([data-rt-isolate]_*)]:bg-kit-accent-softer [&_div[data-block]:not([data-rt-isolate]_*)]:px-3 [&_div[data-block]:not([data-rt-isolate]_*)]:py-3 [&_div[data-block]:not([data-rt-isolate]_*)]:text-kit-sm [&_div[data-block]:not([data-rt-isolate]_*)]:text-kit-accent-fg [&_table:not([data-rt-isolate]_*)]:w-full [&_table:not([data-rt-isolate]_*)]:border-collapse [&_table:not([data-rt-isolate]_*)]:text-kit-sm [&_td:not([data-rt-isolate]_*)]:border [&_td:not([data-rt-isolate]_*)]:border-kit-line [&_td:not([data-rt-isolate]_*)]:px-2.5 [&_td:not([data-rt-isolate]_*)]:py-1.5 [&_td:not([data-rt-isolate]_*)]:align-top [&_th:not([data-rt-isolate]_*)]:border [&_th:not([data-rt-isolate]_*)]:border-kit-line [&_th:not([data-rt-isolate]_*)]:bg-kit-subtle [&_th:not([data-rt-isolate]_*)]:px-2.5 [&_th:not([data-rt-isolate]_*)]:py-1.5 [&_th:not([data-rt-isolate]_*)]:text-left [&_th:not([data-rt-isolate]_*)]:align-top [&_th:not([data-rt-isolate]_*)]:font-medium";
|
|
50
55
|
/** Panel density (≈340px inspector): 13px text, smaller headings. */
|
|
51
56
|
var RT_PANEL = "text-kit-sm leading-[1.6] [&_h1:not([data-rt-isolate]_*)]:text-kit-xl [&_h1:not([data-rt-isolate]_*)]:leading-7 [&_h2:not([data-rt-isolate]_*)]:text-kit-lg [&_h2:not([data-rt-isolate]_*)]:leading-7 [&_h3:not([data-rt-isolate]_*)]:text-kit-md [&_h4:not([data-rt-isolate]_*)]:text-kit-base [&_h5:not([data-rt-isolate]_*)]:text-kit-sm [&_h6:not([data-rt-isolate]_*)]:text-kit-xs";
|
|
@@ -252,6 +257,8 @@ var CODE_LANGUAGES = [
|
|
|
252
257
|
label: "YAML"
|
|
253
258
|
}
|
|
254
259
|
];
|
|
260
|
+
/** Look "v16": one half of the block handle pill (prototype content.css:488-491): 22×24, radius 5, a quiet grey that darkens with the pill. */
|
|
261
|
+
var V16_HANDLE_BTN = "flex h-6 w-[22px] items-center justify-center rounded-[5px] text-kit-insp-faint outline-none transition-colors duration-100 group-hover/bh:text-kit-insp-quiet hover:!bg-kit-insp-card-hover hover:!text-kit-insp-tip-title focus-visible:bg-kit-insp-card-hover focus-visible:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card-hover data-[popup-open]:text-kit-insp-tip-title [&_svg]:size-3.5";
|
|
255
262
|
var LANG_NONE = "_none";
|
|
256
263
|
var LANG_OTHER = "_other";
|
|
257
264
|
var CODE_LANGUAGE_REASON = "Use letters, numbers and hyphens, like cpp or csharp.";
|
|
@@ -297,6 +304,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
297
304
|
valueRef.current = value;
|
|
298
305
|
const services = useKitServices();
|
|
299
306
|
const env = useKitEnv();
|
|
307
|
+
const v16 = useKitLook() === "v16";
|
|
300
308
|
const featureKey = features.join(",");
|
|
301
309
|
const allows = React.useCallback((f) => features.includes(f), [featureKey]);
|
|
302
310
|
const [empty, setEmpty] = React.useState(isEmptyHtml(value));
|
|
@@ -308,7 +316,8 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
308
316
|
const setModalOpen = (o) => onExpandedOpenChange ? onExpandedOpenChange(o) : setModalOwn(o);
|
|
309
317
|
const [md, setMd] = React.useState(null);
|
|
310
318
|
const [mdConfirm, setMdConfirm] = React.useState(false);
|
|
311
|
-
const reduceMotion =
|
|
319
|
+
const reduceMotion = useKitReducedMotion();
|
|
320
|
+
const slashReduce = !!useKitReducedMotion();
|
|
312
321
|
const [bubble, setBubble] = React.useState(null);
|
|
313
322
|
/** Comment was picked: the toolbar stays away until the next click or key inside this editor */
|
|
314
323
|
const [quiet, setQuiet] = React.useState(false);
|
|
@@ -332,6 +341,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
332
341
|
const [langOther, setLangOther] = React.useState(null);
|
|
333
342
|
const langId = React.useId();
|
|
334
343
|
const canAI = env.can("ai.use") && !!services.aiRewrite;
|
|
344
|
+
const canAiCommand = aiCommandsOffered(v16, env.can("ai.use"), services.aiCommand);
|
|
335
345
|
const aiAttempt = React.useRef(0);
|
|
336
346
|
const [link, setLink] = React.useState(null);
|
|
337
347
|
const [drag, setDrag] = React.useState(null);
|
|
@@ -353,6 +363,13 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
353
363
|
const [gutterRoom, setGutterRoom] = React.useState(false);
|
|
354
364
|
const blurTimer = React.useRef(void 0);
|
|
355
365
|
const [notice, setNotice] = React.useState(null);
|
|
366
|
+
const [codes, setCodes] = React.useState([]);
|
|
367
|
+
const v16Ref = React.useRef(v16);
|
|
368
|
+
v16Ref.current = v16;
|
|
369
|
+
const placeCodes = React.useCallback((force) => {
|
|
370
|
+
const next = v16Ref.current ? measureCodes(ref.current, scroller.current) : [];
|
|
371
|
+
setCodes((p) => !force && sameCodes(p, next) ? p : next);
|
|
372
|
+
}, []);
|
|
356
373
|
const expanded = !!inModal;
|
|
357
374
|
const toolbarOpen = !readOnly && (focused || menus.style || menus.more || insertOpen || expanded || !!md || !!link);
|
|
358
375
|
const scrollable = !!maxHeight && !expanded;
|
|
@@ -400,6 +417,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
400
417
|
el.querySelectorAll(":scope > ol[data-rt=\"footnotes\"]").forEach((n) => n.remove());
|
|
401
418
|
el.querySelectorAll(FN_MARK).forEach((m) => m.setAttribute("contenteditable", "false"));
|
|
402
419
|
hydrate(el);
|
|
420
|
+
if (v16Ref.current) recolourCodes(el);
|
|
403
421
|
syncTaskA11y(el);
|
|
404
422
|
setFootnotes(renumberFootnotes(el));
|
|
405
423
|
outline.current.set(outlineOf(el));
|
|
@@ -482,6 +500,14 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
482
500
|
ro.observe(w);
|
|
483
501
|
return () => ro.disconnect();
|
|
484
502
|
}, []);
|
|
503
|
+
React.useLayoutEffect(() => placeCodes());
|
|
504
|
+
React.useEffect(() => {
|
|
505
|
+
const el = ref.current;
|
|
506
|
+
if (!v16 || !el || typeof ResizeObserver === "undefined") return;
|
|
507
|
+
const ro = new ResizeObserver(() => placeCodes());
|
|
508
|
+
ro.observe(el);
|
|
509
|
+
return () => ro.disconnect();
|
|
510
|
+
}, [v16, placeCodes]);
|
|
485
511
|
const [stickyTop, setStickyTop] = React.useState(0);
|
|
486
512
|
React.useEffect(() => {
|
|
487
513
|
const w = wrap.current;
|
|
@@ -638,7 +664,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
638
664
|
const s = window.getSelection();
|
|
639
665
|
return topBlock(el, s && s.rangeCount && el.contains(s.anchorNode) ? s.anchorNode : document.activeElement);
|
|
640
666
|
};
|
|
641
|
-
const deleteBlock = (b) => {
|
|
667
|
+
const deleteBlock = (b, label = "Block deleted") => {
|
|
642
668
|
const el = ref.current;
|
|
643
669
|
if (!el || !el.contains(b)) return;
|
|
644
670
|
const next = b.nextSibling;
|
|
@@ -652,7 +678,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
652
678
|
setGutter(null);
|
|
653
679
|
setBlockMenu(false);
|
|
654
680
|
emit();
|
|
655
|
-
notify(
|
|
681
|
+
notify(label, { action: {
|
|
656
682
|
label: "Undo",
|
|
657
683
|
onClick: () => {
|
|
658
684
|
const root = ref.current;
|
|
@@ -664,15 +690,34 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
664
690
|
}
|
|
665
691
|
} });
|
|
666
692
|
};
|
|
693
|
+
/** look v16 "Turn into" on a block island: the block becomes `nodes`, the caret goes to the first, Undo puts it back */
|
|
694
|
+
const replaceBlock = (b, nodes, label) => {
|
|
695
|
+
const el = ref.current;
|
|
696
|
+
if (!el || !el.contains(b) || !nodes.length) return;
|
|
697
|
+
b.replaceWith(...nodes);
|
|
698
|
+
setGutter(null);
|
|
699
|
+
emit();
|
|
700
|
+
placeCaret(nodes[0]);
|
|
701
|
+
notify(label, { action: {
|
|
702
|
+
label: "Undo",
|
|
703
|
+
onClick: () => {
|
|
704
|
+
if (!nodes[0].isConnected) return;
|
|
705
|
+
nodes[0].before(b);
|
|
706
|
+
nodes.forEach((n) => n.remove());
|
|
707
|
+
emit();
|
|
708
|
+
}
|
|
709
|
+
} });
|
|
710
|
+
};
|
|
667
711
|
const duplicateBlock$1 = (b) => {
|
|
668
712
|
const c = duplicateBlock(b);
|
|
669
713
|
emit();
|
|
670
714
|
if (gutter) placeGutter(c);
|
|
671
715
|
};
|
|
672
716
|
const moveBlock$1 = (b, dir) => {
|
|
673
|
-
if (!moveBlock(b, dir)) return;
|
|
717
|
+
if (!moveBlock(b, dir)) return false;
|
|
674
718
|
emit();
|
|
675
719
|
if (gutter) requestAnimationFrame(() => placeGutter(b));
|
|
720
|
+
return true;
|
|
676
721
|
};
|
|
677
722
|
const turnInto$1 = (b, tag) => {
|
|
678
723
|
const el = ref.current;
|
|
@@ -747,7 +792,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
747
792
|
emit();
|
|
748
793
|
refresh();
|
|
749
794
|
};
|
|
750
|
-
const slashCat = useCatalog(slash?.query ?? "", allows, slash?.folder ?? false, components ?? null);
|
|
795
|
+
const slashCat = useCatalog(slash?.query ?? "", allows, slash?.folder ?? false, components ?? null, canAiCommand, !!slash?.ai);
|
|
751
796
|
const caretRect = () => {
|
|
752
797
|
const s = window.getSelection();
|
|
753
798
|
if (!s || !s.rangeCount) return null;
|
|
@@ -759,9 +804,16 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
759
804
|
folder: true,
|
|
760
805
|
active: 1
|
|
761
806
|
});
|
|
807
|
+
if (it.kind === "ai") return setSlash((s) => s && {
|
|
808
|
+
...s,
|
|
809
|
+
ai: true,
|
|
810
|
+
folder: false,
|
|
811
|
+
active: 1
|
|
812
|
+
});
|
|
762
813
|
if (it.kind === "back") return setSlash((s) => s && {
|
|
763
814
|
...s,
|
|
764
815
|
folder: false,
|
|
816
|
+
ai: false,
|
|
765
817
|
active: 0
|
|
766
818
|
});
|
|
767
819
|
const sl = slash;
|
|
@@ -781,8 +833,96 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
781
833
|
} catch {}
|
|
782
834
|
if (it.kind === "component") flushSync(() => emit());
|
|
783
835
|
}
|
|
836
|
+
if (it.ai) {
|
|
837
|
+
emit();
|
|
838
|
+
return runAiCommand(it.ai, it.label, sl ? topBlock(ref.current, sl.node) : null);
|
|
839
|
+
}
|
|
784
840
|
insertBlock(it);
|
|
785
841
|
};
|
|
842
|
+
/**
|
|
843
|
+
* Look v16, a "BetterCMS AI" command picked in the slash menu (prototype content.jsx:1210, F2115-F2121). The host's
|
|
844
|
+
* `aiCommand` service writes; a rewrite command replaces the text block right above the caret's line, the others
|
|
845
|
+
* write new paragraphs at that line. Every write carries an Undo; a refusal and a failure are named.
|
|
846
|
+
*/
|
|
847
|
+
const runAiCommand = (kind, label, at) => {
|
|
848
|
+
const run = services.aiCommand;
|
|
849
|
+
const root = ref.current;
|
|
850
|
+
if (!run || !root) return;
|
|
851
|
+
const words = (n) => (n.textContent ?? "").replace(/\u200b/g, "");
|
|
852
|
+
const above = [];
|
|
853
|
+
for (const k of Array.from(root.children)) {
|
|
854
|
+
if (k === at) break;
|
|
855
|
+
above.push(k);
|
|
856
|
+
}
|
|
857
|
+
const rewrite = AI_REWRITE_COMMANDS.includes(kind);
|
|
858
|
+
const near = [...above].reverse().find((n) => words(n).trim());
|
|
859
|
+
const target = rewrite && near instanceof HTMLElement && /^(P|H[1-6]|BLOCKQUOTE)$/.test(near.tagName) ? near : null;
|
|
860
|
+
if (rewrite && !target) {
|
|
861
|
+
notify(`Nothing above to ${kind === "translate" ? "translate" : kind === "spelling" ? "check" : "rewrite"}`, { description: "Put the caret on the line under a paragraph, heading or quote, then pick the command again." });
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
const before = target ? target.innerHTML : "";
|
|
865
|
+
target?.normalize();
|
|
866
|
+
const runs = target ? textRuns(target) : [];
|
|
867
|
+
const context = {
|
|
868
|
+
text: Array.from(root.children).map(words).filter((t) => t.trim()).join("\n\n"),
|
|
869
|
+
before: above.map(words).filter((t) => t.trim()).join("\n\n"),
|
|
870
|
+
target: target ? words(target) : "",
|
|
871
|
+
line: at ? words(at).trim() : "",
|
|
872
|
+
runs: runs.length > 1 ? runs.map((r) => r.run.text) : []
|
|
873
|
+
};
|
|
874
|
+
notify(`BetterCMS AI · ${label}`);
|
|
875
|
+
Promise.resolve().then(() => run(kind, context)).then((out) => {
|
|
876
|
+
const el = ref.current;
|
|
877
|
+
const text = typeof out === "string" ? out.trim() : "";
|
|
878
|
+
if (!el || !text) return;
|
|
879
|
+
if (target) {
|
|
880
|
+
if (!el.contains(target) || words(target) !== context.target) {
|
|
881
|
+
notify("The text changed before BetterCMS AI came back", { description: "Nothing was replaced. Pick the command again to retry." });
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const flat = (s) => s.replace(/\s*\n+\s*/g, " ");
|
|
885
|
+
const pieces = mapRewriteOntoRuns(runs.map((r) => r.run), text);
|
|
886
|
+
const marked = runs.some((r) => r.run.marked);
|
|
887
|
+
if (pieces && runs.every((r) => r.node.isConnected && target.contains(r.node))) runs.forEach((r, i) => r.node.data = flat(pieces[i]));
|
|
888
|
+
else target.textContent = flat(text.split("␞").join(""));
|
|
889
|
+
const kept = !!pieces;
|
|
890
|
+
emit();
|
|
891
|
+
notify(`${label}: done`, {
|
|
892
|
+
...marked && !kept ? { description: "Its formatting was removed: the new text did not line up with the old." } : {},
|
|
893
|
+
action: {
|
|
894
|
+
label: "Undo",
|
|
895
|
+
onClick: () => {
|
|
896
|
+
if (!target.isConnected) return;
|
|
897
|
+
target.innerHTML = before;
|
|
898
|
+
emit();
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const tpl = document.createElement("template");
|
|
905
|
+
tpl.innerHTML = textToParas(text.replace(/\n{3,}/g, "\n\n"));
|
|
906
|
+
const nodes = Array.from(tpl.content.children);
|
|
907
|
+
if (!nodes.length) return;
|
|
908
|
+
const line = at && el.contains(at) ? at : null;
|
|
909
|
+
const emptyLine = line && line.tagName === "P" && !words(line).trim() ? line : null;
|
|
910
|
+
if (emptyLine) emptyLine.replaceWith(...nodes);
|
|
911
|
+
else if (line) line.after(...nodes);
|
|
912
|
+
else el.append(...nodes);
|
|
913
|
+
placeCaret(nodes[nodes.length - 1]);
|
|
914
|
+
emit();
|
|
915
|
+
notify(`${label}: done`, { action: {
|
|
916
|
+
label: "Undo",
|
|
917
|
+
onClick: () => {
|
|
918
|
+
if (!nodes[0].isConnected) return;
|
|
919
|
+
if (emptyLine) nodes[0].before(emptyLine);
|
|
920
|
+
nodes.forEach((n) => n.remove());
|
|
921
|
+
emit();
|
|
922
|
+
}
|
|
923
|
+
} });
|
|
924
|
+
}, (err) => notify("BetterCMS AI could not finish", { description: err instanceof Error ? err.message : String(err) }));
|
|
925
|
+
};
|
|
786
926
|
const toggleInlineCode = () => {
|
|
787
927
|
const el = ref.current;
|
|
788
928
|
const s = window.getSelection();
|
|
@@ -810,9 +950,10 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
810
950
|
if (e.key === "Escape") {
|
|
811
951
|
e.preventDefault();
|
|
812
952
|
e.stopPropagation();
|
|
813
|
-
setSlash(slash.folder ? {
|
|
953
|
+
setSlash(slash.folder || slash.ai ? {
|
|
814
954
|
...slash,
|
|
815
955
|
folder: false,
|
|
956
|
+
ai: false,
|
|
816
957
|
active: 0
|
|
817
958
|
} : null);
|
|
818
959
|
return;
|
|
@@ -929,7 +1070,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
929
1070
|
const onWrapKeyDown = (e) => {
|
|
930
1071
|
if (e.defaultPrevented) return;
|
|
931
1072
|
const mod = e.metaKey || e.ctrlKey;
|
|
932
|
-
if (mod && e.key === "Enter" &&
|
|
1073
|
+
if (mod && !hideFullscreen && (e.key === "Enter" || v16 && e.shiftKey && e.key.toLowerCase() === "f")) {
|
|
933
1074
|
e.preventDefault();
|
|
934
1075
|
setModalOpen(true);
|
|
935
1076
|
return;
|
|
@@ -1000,7 +1141,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1000
1141
|
setSlash({
|
|
1001
1142
|
...slash,
|
|
1002
1143
|
query: q,
|
|
1003
|
-
active: slash.folder ? 1 : 0
|
|
1144
|
+
active: slash.folder || slash.ai ? 1 : 0
|
|
1004
1145
|
});
|
|
1005
1146
|
};
|
|
1006
1147
|
const openLink = () => {
|
|
@@ -1121,12 +1262,32 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1121
1262
|
return;
|
|
1122
1263
|
}
|
|
1123
1264
|
el.focus({ preventScroll: true });
|
|
1265
|
+
const shape = selectionShape(range, el);
|
|
1266
|
+
const attrs = shape.link ? linkAttrs(shape.link) : null;
|
|
1124
1267
|
const s = window.getSelection();
|
|
1125
1268
|
s?.removeAllRanges();
|
|
1126
1269
|
s?.addRange(range);
|
|
1127
1270
|
insertTextAtCaret(out);
|
|
1271
|
+
if (shape.link && attrs && (!el.contains(shape.link) || !shape.link.textContent?.includes(out))) {
|
|
1272
|
+
const node = s?.focusNode;
|
|
1273
|
+
const off = s?.focusOffset ?? 0;
|
|
1274
|
+
if (s && node && node.nodeType === Node.TEXT_NODE && off >= out.length) {
|
|
1275
|
+
const r = document.createRange();
|
|
1276
|
+
r.setStart(node, off - out.length);
|
|
1277
|
+
r.setEnd(node, off);
|
|
1278
|
+
s.removeAllRanges();
|
|
1279
|
+
s.addRange(r);
|
|
1280
|
+
const sentinel = `${LINK_SENTINEL}${rid()}`;
|
|
1281
|
+
if (exec("createLink", sentinel)) el.querySelectorAll("a[href]").forEach((a) => {
|
|
1282
|
+
if (a.getAttribute("href") !== sentinel) return;
|
|
1283
|
+
for (const [k, v] of attrs) a.setAttribute(k, v);
|
|
1284
|
+
});
|
|
1285
|
+
s.collapseToEnd();
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
unwrapLinkSentinels(el);
|
|
1128
1289
|
emit();
|
|
1129
|
-
notify("Rewritten with AI", { description: hints ? platformKeys("Press ⌘Z to undo") : void 0 });
|
|
1290
|
+
notify(shape.loses ? FORMATTING_REMOVED : "Rewritten with AI", { description: hints ? platformKeys("Press ⌘Z to undo") : void 0 });
|
|
1130
1291
|
}, (err) => notify("Could not rewrite the selection", { description: err instanceof Error ? err.message : String(err) }));
|
|
1131
1292
|
};
|
|
1132
1293
|
const onGripDown = (e) => {
|
|
@@ -1171,9 +1332,13 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1171
1332
|
}
|
|
1172
1333
|
setDrag((d) => {
|
|
1173
1334
|
if (d && d.target !== d.from) {
|
|
1335
|
+
const same = d.target ? d.target === d.from.nextElementSibling : d.from === ref.current?.lastElementChild;
|
|
1174
1336
|
if (d.target) d.target.before(d.from);
|
|
1175
1337
|
else ref.current?.append(d.from);
|
|
1176
|
-
setTimeout(
|
|
1338
|
+
setTimeout(() => {
|
|
1339
|
+
emit();
|
|
1340
|
+
if (v16 && !same) services.toast?.("Block moved");
|
|
1341
|
+
}, 0);
|
|
1177
1342
|
}
|
|
1178
1343
|
return null;
|
|
1179
1344
|
});
|
|
@@ -1356,6 +1521,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1356
1521
|
const api = React.useRef({
|
|
1357
1522
|
emit,
|
|
1358
1523
|
deleteBlock,
|
|
1524
|
+
replaceBlock,
|
|
1359
1525
|
exitIsland,
|
|
1360
1526
|
record,
|
|
1361
1527
|
oneStep,
|
|
@@ -1370,6 +1536,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1370
1536
|
api.current = {
|
|
1371
1537
|
emit,
|
|
1372
1538
|
deleteBlock,
|
|
1539
|
+
replaceBlock,
|
|
1373
1540
|
exitIsland,
|
|
1374
1541
|
record,
|
|
1375
1542
|
oneStep,
|
|
@@ -1385,7 +1552,8 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1385
1552
|
readOnly,
|
|
1386
1553
|
dense,
|
|
1387
1554
|
emit: () => api.current.emit(),
|
|
1388
|
-
remove: (x) => api.current.deleteBlock(x),
|
|
1555
|
+
remove: (x, label) => api.current.deleteBlock(x, label),
|
|
1556
|
+
replace: (x, nodes, label) => api.current.replaceBlock(x, nodes, label),
|
|
1389
1557
|
exit: (x) => api.current.exitIsland(x),
|
|
1390
1558
|
record: (x, before, label, coalesce) => api.current.record(x, before, label, coalesce),
|
|
1391
1559
|
step: (label, write, before) => api.current.oneStep(label, write, before),
|
|
@@ -1479,6 +1647,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1479
1647
|
setFocused(false);
|
|
1480
1648
|
setBubble(null);
|
|
1481
1649
|
ref.current?.querySelectorAll("[data-hint]").forEach((n) => n.removeAttribute("data-hint"));
|
|
1650
|
+
if (v16) recolourCodes(ref.current);
|
|
1482
1651
|
if (valueRef.current !== known.current && !md) load(valueRef.current);
|
|
1483
1652
|
}, 400);
|
|
1484
1653
|
},
|
|
@@ -1710,16 +1879,23 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1710
1879
|
notify("That drop is not an image from the media library");
|
|
1711
1880
|
}
|
|
1712
1881
|
},
|
|
1713
|
-
className: cn(RT_PROSE, dense && "text-kit-sm leading-[1.6] [&_h1:not([data-rt-isolate]_*)]:text-kit-xl [&_h1:not([data-rt-isolate]_*)]:leading-7 [&_h2:not([data-rt-isolate]_*)]:text-kit-lg [&_h2:not([data-rt-isolate]_*)]:leading-7 [&_h3:not([data-rt-isolate]_*)]:text-kit-md [&_h4:not([data-rt-isolate]_*)]:text-kit-base [&_h5:not([data-rt-isolate]_*)]:text-kit-sm [&_h6:not([data-rt-isolate]_*)]:text-kit-xs", "peer relative outline-none focus-visible:shadow-none [&_*:not([data-rt-isolate]_*)]:outline-none", "[&>p[data-hint]]:before:pointer-events-none [&>p[data-hint]]:before:float-left [&>p[data-hint]]:before:h-0 [&>p[data-hint]]:before:text-kit-fg-4 [&>p[data-hint]]:before:content-[attr(data-hint)]", "[&_a[data-button]:not([data-rt-isolate]_*)]:cursor-pointer [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:cursor-pointer", "[&_sup[data-rt=fn]]:mx-px [&_sup[data-rt=fn]]:cursor-pointer [&_sup[data-rt=fn]]:rounded-kit-sm [&_sup[data-rt=fn]]:px-0.5 [&_sup[data-rt=fn]]:text-[0.72em] [&_sup[data-rt=fn]]:leading-[0] [&_sup[data-rt=fn]]:font-semibold [&_sup[data-rt=fn]]:text-kit-accent-fg [&_sup[data-rt=fn]:hover]:bg-kit-accent-soft", dense ? "px-2.5 py-2" : "px-4 py-3.5", minH)
|
|
1882
|
+
className: cn(RT_PROSE, dense && "text-kit-sm leading-[1.6] [&_h1:not([data-rt-isolate]_*)]:text-kit-xl [&_h1:not([data-rt-isolate]_*)]:leading-7 [&_h2:not([data-rt-isolate]_*)]:text-kit-lg [&_h2:not([data-rt-isolate]_*)]:leading-7 [&_h3:not([data-rt-isolate]_*)]:text-kit-md [&_h4:not([data-rt-isolate]_*)]:text-kit-base [&_h5:not([data-rt-isolate]_*)]:text-kit-sm [&_h6:not([data-rt-isolate]_*)]:text-kit-xs", v16 && "[&>pre]:!relative [&>pre]:!my-5 [&>pre]:!rounded-[10px] [&>pre]:!border-0 [&>pre]:!bg-kit-insp-code-bg [&>pre]:!pb-[14px] [&>pre]:!pl-[60px] [&>pre]:!pr-4 [&>pre]:!pt-[50px] [&>pre]:![font:12.5px/22px_'JetBrains_Mono',ui-monospace,SFMono-Regular,Menlo,monospace] [&>pre]:!text-kit-insp-code-fg [&>pre]:caret-white [&>pre]:!whitespace-pre [&>pre]:overflow-x-auto [&>pre]:[scrollbar-width:thin] [&>pre[data-rt-wrap]]:!whitespace-pre-wrap [&>pre[data-rt-wrap]]:!pl-4 [&>pre[data-rt-wrap]]:overflow-x-visible [&_span[data-rt-hl=c]]:text-kit-insp-code-cmt [&_span[data-rt-hl=k]]:text-kit-insp-code-kw [&_span[data-rt-hl=s]]:text-kit-insp-code-str [&_span[data-rt-hl=n]]:text-kit-insp-code-num [&_span[data-rt-hl=f]]:text-kit-insp-code-fn", v16 && V16_QUOTE_CLASS, "peer relative outline-none focus-visible:shadow-none [&_*:not([data-rt-isolate]_*)]:outline-none", "[&>p[data-hint]]:before:pointer-events-none [&>p[data-hint]]:before:float-left [&>p[data-hint]]:before:h-0 [&>p[data-hint]]:before:text-kit-fg-4 [&>p[data-hint]]:before:content-[attr(data-hint)]", "[&_a[data-button]:not([data-rt-isolate]_*)]:cursor-pointer [&_ul[data-task]>li:not([data-rt-isolate]_*)]:before:cursor-pointer", "[&_sup[data-rt=fn]]:mx-px [&_sup[data-rt=fn]]:cursor-pointer [&_sup[data-rt=fn]]:rounded-kit-sm [&_sup[data-rt=fn]]:px-0.5 [&_sup[data-rt=fn]]:text-[0.72em] [&_sup[data-rt=fn]]:leading-[0] [&_sup[data-rt=fn]]:font-semibold [&_sup[data-rt=fn]]:text-kit-accent-fg [&_sup[data-rt=fn]:hover]:bg-kit-accent-soft", dense ? "px-2.5 py-2" : "px-4 py-3.5", minH)
|
|
1714
1883
|
}),
|
|
1715
1884
|
empty ? /* @__PURE__ */ jsx("div", {
|
|
1716
1885
|
"aria-hidden": true,
|
|
1717
1886
|
className: cn("pointer-events-none absolute text-kit-fg-4 peer-focus:hidden", dense ? "text-kit-sm" : "text-kit-base", dense ? "left-2.5 top-2" : "left-4 top-3.5"),
|
|
1718
1887
|
children: ph
|
|
1719
1888
|
}) : null,
|
|
1889
|
+
v16 ? codes.map((s, i) => /* @__PURE__ */ jsx(CodeHead, {
|
|
1890
|
+
s,
|
|
1891
|
+
readOnly,
|
|
1892
|
+
onLanguage: setCodeLanguage,
|
|
1893
|
+
onLayout: () => requestAnimationFrame(() => placeCodes(true)),
|
|
1894
|
+
notify: (m) => notify(m)
|
|
1895
|
+
}, i)) : null,
|
|
1720
1896
|
gutter && showGutter ? /* @__PURE__ */ jsxs("div", {
|
|
1721
1897
|
"data-rt-gutter": "",
|
|
1722
|
-
className: cn("absolute z-[3] flex
|
|
1898
|
+
className: cn("absolute z-[3] flex", gutterMode === "outside" ? "-left-12 pr-1" : "left-0", v16 && gutterMode === "outside" ? (gBlock?.getAttribute("data-rt-island") === "table" ? "-left-[78px] " : "-left-[54px] ") + "group/bh items-center gap-px rounded-[7px] p-px pr-px transition-[background-color,box-shadow] duration-100 hover:bg-kit-insp-tip-bg hover:shadow-[0_0_0_1px_var(--kit-insp-tip-line),0_1px_2px_rgb(0_0_0/0.06),0_2px_8px_-2px_rgb(0_0_0/0.06)] [@media(hover:hover)]:motion-safe:animate-[kit-fade-in_120ms_ease-out]" : "items-start"),
|
|
1723
1899
|
style: { top: gutter.top + Math.max(-2, Math.min(4, gutter.height / 2 - 12)) },
|
|
1724
1900
|
children: [gutterMode === "outside" ? /* @__PURE__ */ jsxs(Popover, {
|
|
1725
1901
|
open: gutterInsert,
|
|
@@ -1730,41 +1906,48 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1730
1906
|
}
|
|
1731
1907
|
setGutterInsert(o);
|
|
1732
1908
|
},
|
|
1733
|
-
children: [
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1909
|
+
children: [
|
|
1910
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
1911
|
+
content: "Add a block below",
|
|
1912
|
+
disabled: gutterInsert,
|
|
1913
|
+
children: /* @__PURE__ */ jsx(PopoverTrigger, {
|
|
1914
|
+
"aria-label": "Add a block below",
|
|
1915
|
+
className: v16 ? V16_HANDLE_BTN : cn("flex items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg data-[popup-open]:bg-kit-hover data-[popup-open]:text-kit-fg", btn),
|
|
1916
|
+
children: /* @__PURE__ */ jsx(IconPlus, {
|
|
1917
|
+
stroke: 1.5,
|
|
1918
|
+
"aria-hidden": true
|
|
1919
|
+
})
|
|
1742
1920
|
})
|
|
1743
|
-
})
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
inserted.current
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1921
|
+
}),
|
|
1922
|
+
v16 ? /* @__PURE__ */ jsx("i", {
|
|
1923
|
+
"aria-hidden": true,
|
|
1924
|
+
className: "h-3.5 w-px bg-transparent transition-colors duration-100 group-hover/bh:bg-kit-insp-tip-line"
|
|
1925
|
+
}) : null,
|
|
1926
|
+
gutterInsert ? /* @__PURE__ */ jsx(InsertMenuContent, {
|
|
1927
|
+
side: "bottom",
|
|
1928
|
+
align: "start",
|
|
1929
|
+
allows,
|
|
1930
|
+
keepFocusOnClose: () => inserted.current,
|
|
1931
|
+
onInsert: (it) => {
|
|
1932
|
+
const b = gutterTarget.current;
|
|
1933
|
+
const el = ref.current;
|
|
1934
|
+
inserted.current = true;
|
|
1935
|
+
setGutterInsert(false);
|
|
1936
|
+
if (!b || !el || !el.contains(b)) return;
|
|
1937
|
+
const p = document.createElement("p");
|
|
1938
|
+
p.innerHTML = "<br>";
|
|
1939
|
+
b.after(p);
|
|
1940
|
+
el.focus({ preventScroll: true });
|
|
1941
|
+
placeCaret(p);
|
|
1942
|
+
insertBlock(it);
|
|
1943
|
+
}
|
|
1944
|
+
}) : null
|
|
1945
|
+
]
|
|
1763
1946
|
}) : null, /* @__PURE__ */ jsxs(Menu, {
|
|
1764
1947
|
open: blockMenu,
|
|
1765
1948
|
onOpenChange: setBlockMenu,
|
|
1766
1949
|
children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
1767
|
-
content: "Drag to move, click for options",
|
|
1950
|
+
content: v16 ? "Drag to move · click for menu" : "Drag to move, click for options",
|
|
1768
1951
|
disabled: blockMenu || !!drag,
|
|
1769
1952
|
children: /* @__PURE__ */ jsx(MenuTrigger, {
|
|
1770
1953
|
"aria-label": "Block options",
|
|
@@ -1775,18 +1958,18 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1775
1958
|
setBlockMenu(true);
|
|
1776
1959
|
}
|
|
1777
1960
|
},
|
|
1778
|
-
className: cn("flex cursor-grab items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg active:cursor-grabbing", gutterMode === "inset" ? "h-[22px] w-4 rounded-kit-sm [&_svg:not([data-rt-isolate]_*)]:size-3.5" : btn, (blockMenu || drag) && "bg-kit-hover text-kit-fg"),
|
|
1961
|
+
className: v16 && gutterMode !== "inset" ? cn(V16_HANDLE_BTN, "cursor-grab active:cursor-grabbing", (blockMenu || drag) && "bg-kit-insp-tip-line text-kit-insp-tip-title") : cn("flex cursor-grab items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg active:cursor-grabbing", gutterMode === "inset" ? "h-[22px] w-4 rounded-kit-sm [&_svg:not([data-rt-isolate]_*)]:size-3.5" : btn, (blockMenu || drag) && "bg-kit-hover text-kit-fg"),
|
|
1779
1962
|
children: /* @__PURE__ */ jsx(IconGripVertical, {
|
|
1780
1963
|
stroke: 1.5,
|
|
1781
1964
|
"aria-hidden": true
|
|
1782
1965
|
})
|
|
1783
1966
|
})
|
|
1784
1967
|
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
1785
|
-
className: "w-56",
|
|
1968
|
+
className: v16 ? "w-[200px] min-w-[200px] rounded-[10px]" : "w-56",
|
|
1786
1969
|
align: "start",
|
|
1787
1970
|
finalFocus: false,
|
|
1788
1971
|
children: [
|
|
1789
|
-
turnStyles.length > 1 ? /* @__PURE__ */ jsxs(MenuSub, { children: [/* @__PURE__ */ jsx(MenuSubTrigger, {
|
|
1972
|
+
turnStyles.length > 1 && !v16 ? /* @__PURE__ */ jsxs(MenuSub, { children: [/* @__PURE__ */ jsx(MenuSubTrigger, {
|
|
1790
1973
|
icon: /* @__PURE__ */ jsx(IconTransform, { stroke: 1.5 }),
|
|
1791
1974
|
disabled: !gIsText,
|
|
1792
1975
|
children: "Turn into"
|
|
@@ -1798,7 +1981,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1798
1981
|
children: t.label
|
|
1799
1982
|
}, t.tag))
|
|
1800
1983
|
})] }) : null,
|
|
1801
|
-
gBlock?.tagName === "PRE" && allows("pre") ? /* @__PURE__ */ jsxs(MenuSub, { children: [/* @__PURE__ */ jsx(MenuSubTrigger, {
|
|
1984
|
+
gBlock?.tagName === "PRE" && allows("pre") && !v16 ? /* @__PURE__ */ jsxs(MenuSub, { children: [/* @__PURE__ */ jsx(MenuSubTrigger, {
|
|
1802
1985
|
icon: /* @__PURE__ */ jsx(IconCode, { stroke: 1.5 }),
|
|
1803
1986
|
children: "Language"
|
|
1804
1987
|
}), /* @__PURE__ */ jsx(MenuSubContent, {
|
|
@@ -1841,14 +2024,14 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1841
2024
|
icon: /* @__PURE__ */ jsx(IconArrowBarToUp, { stroke: 1.5 }),
|
|
1842
2025
|
shortcut: "⌘⇧↑",
|
|
1843
2026
|
disabled: !gBlock?.previousElementSibling,
|
|
1844
|
-
onClick: () => gBlock && moveBlock$1(gBlock, -1),
|
|
2027
|
+
onClick: () => gBlock && moveBlock$1(gBlock, -1) && v16 && services.toast?.("Block moved"),
|
|
1845
2028
|
children: "Move up"
|
|
1846
2029
|
}),
|
|
1847
2030
|
/* @__PURE__ */ jsx(MenuItem, {
|
|
1848
2031
|
icon: /* @__PURE__ */ jsx(IconArrowBarToDown, { stroke: 1.5 }),
|
|
1849
2032
|
shortcut: "⌘⇧↓",
|
|
1850
2033
|
disabled: !gBlock?.nextElementSibling,
|
|
1851
|
-
onClick: () => gBlock && moveBlock$1(gBlock, 1),
|
|
2034
|
+
onClick: () => gBlock && moveBlock$1(gBlock, 1) && v16 && services.toast?.("Block moved"),
|
|
1852
2035
|
children: "Move down"
|
|
1853
2036
|
}),
|
|
1854
2037
|
/* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
@@ -1856,7 +2039,7 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1856
2039
|
danger: true,
|
|
1857
2040
|
icon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.5 }),
|
|
1858
2041
|
onClick: () => gBlock && deleteBlock(gBlock),
|
|
1859
|
-
children: "Delete"
|
|
2042
|
+
children: v16 ? "Delete block" : "Delete"
|
|
1860
2043
|
})
|
|
1861
2044
|
]
|
|
1862
2045
|
})]
|
|
@@ -1996,13 +2179,16 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
1996
2179
|
}), /* @__PURE__ */ jsx(motion.div, {
|
|
1997
2180
|
initial: {
|
|
1998
2181
|
opacity: 0,
|
|
1999
|
-
y: flipUp ? -4 : 4
|
|
2182
|
+
y: slashReduce ? 0 : flipUp ? -4 : 4
|
|
2000
2183
|
},
|
|
2001
2184
|
animate: {
|
|
2002
2185
|
opacity: 1,
|
|
2003
2186
|
y: 0
|
|
2004
2187
|
},
|
|
2005
|
-
transition: {
|
|
2188
|
+
transition: {
|
|
2189
|
+
duration: .14,
|
|
2190
|
+
ease: "easeOut"
|
|
2191
|
+
},
|
|
2006
2192
|
style: {
|
|
2007
2193
|
left: Math.min(window.innerWidth - 330, Math.max(8, slash.rect.left)),
|
|
2008
2194
|
...flipUp ? { bottom: window.innerHeight - slash.rect.top + 6 } : { top: slash.rect.bottom + 6 }
|
|
@@ -2012,6 +2198,8 @@ function RichTextEditor({ value, onChange, readOnly: readOnlyProp, placeholder,
|
|
|
2012
2198
|
children: /* @__PURE__ */ jsx(SlashMenuPanel, {
|
|
2013
2199
|
query: slash.query,
|
|
2014
2200
|
folder: slash.folder,
|
|
2201
|
+
aiOffered: canAiCommand,
|
|
2202
|
+
aiView: !!slash.ai,
|
|
2015
2203
|
active: slash.active,
|
|
2016
2204
|
allows,
|
|
2017
2205
|
setActive: (a) => setSlash((s) => s && {
|