@agent-native/core 0.189.0 → 0.190.0-nightly-20260925211446
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/corpus/README.md +1 -1
- package/corpus/templates/analytics/.agents/skills/analysis-workspace/SKILL.md +10 -0
- package/corpus/templates/analytics/.agents/skills/data-querying/SKILL.md +1 -1
- package/corpus/templates/analytics/AGENTS.md +11 -22
- package/corpus/templates/analytics/actions/list-data-dictionary.ts +7 -9
- package/corpus/templates/analytics/actions/search-analytics-query-catalog.ts +1 -1
- package/corpus/templates/analytics/app/components/AnalyticsReviewArtifactPreview.tsx +201 -0
- package/corpus/templates/analytics/app/i18n/en-US.ts +2 -0
- package/corpus/templates/analytics/app/pages/Settings.tsx +50 -3
- package/corpus/templates/analytics/changelog/2026-09-25-first-run-onboarding-records-setup-choices-and-builder-conne.md +6 -0
- package/corpus/templates/analytics/changelog/2026-09-25-human-review-previews-analytics-dashboards-as-real-charts.md +6 -0
- package/corpus/templates/analytics/changelog/2026-09-25-org-admins-can-review-agent-runs-from-settings.md +6 -0
- package/corpus/templates/analytics/changelog/2026-09-25-proactive-query-context.md +6 -0
- package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +98 -2
- package/corpus/templates/analytics/server/lib/analytics-agent-context.ts +557 -0
- package/corpus/templates/analytics/server/lib/analytics-query-catalog.ts +217 -46
- package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +2 -2
- package/corpus/templates/analytics/server/lib/dashboards-store.ts +39 -5
- package/corpus/templates/analytics/server/lib/data-dictionary-context.ts +4 -0
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +268 -2
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +44 -9
- package/corpus/templates/calendar/AGENTS.md +5 -0
- package/corpus/templates/calendar/CHANGELOG.md +6 -0
- package/corpus/templates/calendar/actions/get-event-rules-status.ts +47 -0
- package/corpus/templates/calendar/actions/list-events.ts +50 -4
- package/corpus/templates/calendar/actions/undo-calendar-event-rule.ts +229 -0
- package/corpus/templates/calendar/actions/update-settings.ts +8 -0
- package/corpus/templates/calendar/app/i18n/en-US.ts +27 -0
- package/corpus/templates/calendar/app/pages/Settings.tsx +196 -1
- package/corpus/templates/calendar/changelog/2026-09-25-calendar-feeds-with-the-same-url-keep-their-own-names-and-co.md +6 -0
- package/corpus/templates/calendar/changelog/2026-09-25-calendar-invitation-rules-surface-expired-connections-and-un.md +6 -0
- package/corpus/templates/calendar/changelog/2026-09-25-restore-locally-hidden-events-from-activity-after-disconnect.md +6 -0
- package/corpus/templates/calendar/server/lib/calendar-settings.ts +44 -10
- package/corpus/templates/calendar/server/lib/google-api.ts +15 -1
- package/corpus/templates/calendar/server/lib/google-calendar.ts +1 -1
- package/corpus/templates/calendar/server/plugins/event-rules.ts +628 -0
- package/corpus/templates/calendar/shared/api.ts +13 -0
- package/corpus/templates/calendar/shared/settings.ts +71 -1
- package/corpus/templates/clips/actions/create-recording.ts +83 -2
- package/corpus/templates/clips/actions/finalize-recording.ts +610 -110
- package/corpus/templates/clips/actions/get-recording-player-data.ts +6 -0
- package/corpus/templates/clips/actions/import-loom-recording.ts +2 -0
- package/corpus/templates/clips/actions/lib/create-recording-schema.ts +7 -0
- package/corpus/templates/clips/actions/lib/loom-import-job.ts +15 -1
- package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +126 -26
- package/corpus/templates/clips/app/hooks/use-drop-video-upload.ts +75 -15
- package/corpus/templates/clips/app/routes/_app.r.$recordingId.tsx +5 -1
- package/corpus/templates/clips/app/routes/record.tsx +134 -40
- package/corpus/templates/clips/chrome-extension/src/background.ts +3 -0
- package/corpus/templates/clips/chrome-extension/src/offscreen.ts +73 -16
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +188 -18
- package/corpus/templates/clips/desktop/src/lib/recording-request.ts +1 -0
- package/corpus/templates/clips/server/db/schema.ts +4 -0
- package/corpus/templates/clips/server/jobs/media-verification.ts +78 -4
- package/corpus/templates/clips/server/jobs/recording-failure-backfill.ts +142 -0
- package/corpus/templates/clips/server/lib/media-verification-state.ts +29 -0
- package/corpus/templates/clips/server/lib/post-finalize-dispatch.ts +2 -0
- package/corpus/templates/clips/server/lib/recording-failures.ts +111 -0
- package/corpus/templates/clips/server/lib/recordings.ts +6 -1
- package/corpus/templates/clips/server/lib/s3-upload-provider.ts +8 -3
- package/corpus/templates/clips/server/lib/upload-lease.ts +25 -6
- package/corpus/templates/clips/server/plugins/calendar-jobs.ts +2 -0
- package/corpus/templates/clips/server/plugins/db.ts +18 -0
- package/corpus/templates/clips/server/routes/api/_agent-native-background/post-finalize-worker.post.ts +48 -5
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/abort.post.ts +322 -31
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +223 -61
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/interrupt.post.ts +62 -4
- package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/reset-chunks.post.ts +74 -7
- package/corpus/templates/clips/shared/recording-core.ts +27 -0
- package/corpus/templates/design/actions/get-design.ts +35 -6
- package/corpus/templates/mail/.agents/skills/inbox-automations/SKILL.md +4 -0
- package/corpus/templates/mail/actions/consolidate-ai-filter-rules.ts +41 -0
- package/corpus/templates/mail/actions/get-ai-priority.ts +48 -8
- package/corpus/templates/mail/actions/record-ai-priority-feedback.ts +69 -0
- package/corpus/templates/mail/actions/update-mail-preferences.ts +2 -0
- package/corpus/templates/mail/app/components/email/EmailList.tsx +179 -32
- package/corpus/templates/mail/app/components/email/EmailListItem.tsx +97 -9
- package/corpus/templates/mail/app/components/email/EmailThread.tsx +55 -1
- package/corpus/templates/mail/app/components/email/ImportanceFeedbackMenu.tsx +52 -0
- package/corpus/templates/mail/app/components/email/compose-autocomplete.ts +2 -1
- package/corpus/templates/mail/app/components/layout/AppLayout.tsx +219 -188
- package/corpus/templates/mail/app/components/onboarding/AiInboxSetup.tsx +338 -0
- package/corpus/templates/mail/app/components/settings/AiFilterSection.tsx +597 -781
- package/corpus/templates/mail/app/components/settings/AiRulePromptField.tsx +37 -0
- package/corpus/templates/mail/app/global.css +42 -26
- package/corpus/templates/mail/app/hooks/use-ai-priority-feedback.ts +43 -0
- package/corpus/templates/mail/app/hooks/use-automations.ts +23 -0
- package/corpus/templates/mail/app/i18n/en-US.ts +58 -3
- package/corpus/templates/mail/app/pages/InboxPage.tsx +47 -10
- package/corpus/templates/mail/changelog/2026-09-25-editing-importance-rules-preserves-disabled-instructions-and.md +6 -0
- package/corpus/templates/mail/changelog/2026-09-25-handle-astral-unicode-letters-in-autocomplete-word-boundarie.md +6 -0
- package/corpus/templates/mail/changelog/2026-09-25-jev-priority-feedback-and-inbox-settings.md +6 -0
- package/corpus/templates/mail/changelog/2026-09-25-keep-existing-ai-filter-rules-intact-when-saving-a-prompt.md +6 -0
- package/corpus/templates/mail/server/lib/automation-engine.ts +21 -12
- package/corpus/templates/mail/server/lib/automations.ts +100 -1
- package/corpus/templates/mail/shared/types.ts +3 -0
- package/corpus/templates/plan/app/i18n/en-US.ts +6 -0
- package/corpus/templates/plan/app/lib/plan-invite-suggestion.ts +43 -0
- package/corpus/templates/plan/app/pages/PlansPage.tsx +249 -4
- package/corpus/templates/slides/actions/create-deck.ts +11 -1
- package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +117 -1
- package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +373 -330
- package/corpus/templates/slides/app/components/design-system/builder-index-response.ts +36 -5
- package/corpus/templates/slides/app/components/editor/BlockBubbleMenu.tsx +21 -53
- package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +347 -671
- package/corpus/templates/slides/app/components/editor/bullet-editing.ts +55 -8
- package/corpus/templates/slides/app/components/editor/in-place-text-session.ts +2082 -0
- package/corpus/templates/slides/app/components/editor/list-editing.ts +174 -16
- package/corpus/templates/slides/app/components/editor/rich-text-selection.ts +497 -62
- package/corpus/templates/slides/app/components/editor/slide-text-targets.ts +102 -20
- package/corpus/templates/slides/app/context/DeckContext.tsx +9 -4
- package/corpus/templates/slides/app/global.css +7 -219
- package/corpus/templates/slides/app/i18n/en-US.ts +3 -0
- package/corpus/templates/slides/app/lib/sanitize-slide-html.ts +7 -0
- package/corpus/templates/slides/app/lib/slide-image-replacement.ts +203 -1
- package/corpus/templates/slides/app/lib/slide-source-map.ts +43 -0
- package/corpus/templates/slides/app/pages/DeckEditor.tsx +182 -4
- package/corpus/templates/slides/app/routes/settings.tsx +33 -2
- package/corpus/templates/slides/changelog/2026-09-25-improve-slides-design-system-setup-feedback.md +6 -0
- package/corpus/templates/slides/changelog/2026-09-25-org-admins-can-review-agent-runs-from-settings.md +6 -0
- package/corpus/templates/slides/changelog/2026-09-25-text-on-a-slide-is-now-edited-in-place-clicking-into-it-chan.md +6 -0
- package/corpus/templates/slides/package.json +0 -12
- package/corpus/templates/slides/scripts/edit-fidelity/README.md +4 -2
- package/corpus/templates/slides/scripts/edit-fidelity/run.ts +12 -3
- package/corpus/templates/slides/vite.config.ts +1 -10
- package/dist/agent/jev-tool-prefetch.d.ts +29 -3
- package/dist/agent/jev-tool-prefetch.js +161 -34
- package/dist/agent/production-agent.d.ts +11 -0
- package/dist/agent/production-agent.js +39 -8
- package/dist/app-config/runtime.d.ts +1 -0
- package/dist/app-config/runtime.js +4 -0
- package/dist/app-config/schema.d.ts +1 -0
- package/dist/client/AgentSidebar.d.ts +3 -1
- package/dist/client/AgentSidebar.js +8 -12
- package/dist/client/analytics/index.d.ts +1 -1
- package/dist/client/analytics/index.js +1 -1
- package/dist/client/analytics.d.ts +2 -0
- package/dist/client/analytics.js +9 -0
- package/dist/client/api-path.js +5 -2
- package/dist/client/chat/run-recovery.d.ts +0 -3
- package/dist/client/chat/run-recovery.js +13 -23
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/observability/ObservabilityDashboard.d.ts +3 -0
- package/dist/client/observability/ObservabilityDashboard.js +366 -71
- package/dist/client/observability/ObservabilityReviewSummaryButton.d.ts +4 -1
- package/dist/client/observability/ObservabilityReviewSummaryButton.js +13 -9
- package/dist/client/observability/OutputPreview.d.ts +9 -4
- package/dist/client/observability/OutputPreview.js +230 -52
- package/dist/client/onboarding/FirstRunOnboarding.js +67 -4
- package/dist/client/onboarding/use-onboarding.js +2 -0
- package/dist/client/sharing/ShareButton.d.ts +2 -0
- package/dist/client/sharing/ShareButton.js +1 -0
- package/dist/client/sharing/useShareButtonController.d.ts +1 -0
- package/dist/client/sharing/useShareButtonController.js +29 -8
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/deploy/build.js +9 -1
- package/dist/embeddings/index.d.ts +3 -1
- package/dist/embeddings/index.js +20 -10
- package/dist/jobs/sweep-hooks.d.ts +7 -0
- package/dist/jobs/sweep-hooks.js +28 -0
- package/dist/localization/default-messages.d.ts +1 -0
- package/dist/localization/default-messages.js +1 -0
- package/dist/mcp/screen-memory-stdio.d.ts +7 -7
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/actions/authorization.d.ts +1 -0
- package/dist/observability/actions/authorization.js +22 -0
- package/dist/observability/actions/get-observability-review-detail.d.ts +5 -0
- package/dist/observability/actions/get-observability-review-detail.js +10 -2
- package/dist/observability/actions/get-observability-review-summary-source.d.ts +2 -0
- package/dist/observability/actions/get-observability-review-summary-source.js +3 -2
- package/dist/observability/actions/save-observability-instruction-update.js +2 -1
- package/dist/observability/actions/save-observability-review-summary.js +21 -10
- package/dist/observability/migrations.js +25 -0
- package/dist/observability/reviews.d.ts +3 -1
- package/dist/observability/reviews.js +410 -53
- package/dist/observability/routes.d.ts +6 -6
- package/dist/observability/store.d.ts +15 -0
- package/dist/observability/store.js +131 -11
- package/dist/observability/types.d.ts +18 -0
- package/dist/org/handlers.d.ts +1 -1
- package/dist/org/index.d.ts +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +5 -5
- package/dist/provider-api/actions/provider-api.d.ts +8 -8
- package/dist/secrets/routes.d.ts +3 -3
- package/dist/server/agent-chat/plugin-options.d.ts +4 -20
- package/dist/server/agent-chat/prompt-resources.d.ts +16 -0
- package/dist/server/agent-chat/prompt-resources.js +385 -22
- package/dist/server/agent-chat-plugin.d.ts +3 -1
- package/dist/server/agent-chat-plugin.js +149 -27
- package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/server/prompts/framework-core-compact.js +1 -1
- package/dist/server/prompts/framework-core.js +1 -1
- package/dist/server/realtime-token.d.ts +1 -1
- package/dist/server/request-context.d.ts +6 -3
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/settings/org-settings.d.ts +4 -2
- package/dist/settings/org-settings.js +3 -3
- package/dist/settings/store.d.ts +3 -1
- package/dist/settings/store.js +8 -3
- package/dist/styles/agent-native.css +5 -0
- package/dist/templates/default/app/i18n/ar-SA.ts +1 -0
- package/dist/templates/default/app/i18n/de-DE.ts +1 -0
- package/dist/templates/default/app/i18n/en-US.ts +1 -0
- package/dist/templates/default/app/i18n/es-ES.ts +1 -0
- package/dist/templates/default/app/i18n/fr-FR.ts +1 -0
- package/dist/templates/default/app/i18n/hi-IN.ts +1 -0
- package/dist/templates/default/app/i18n/ja-JP.ts +1 -0
- package/dist/templates/default/app/i18n/ko-KR.ts +1 -0
- package/dist/templates/default/app/i18n/pt-BR.ts +1 -0
- package/dist/templates/default/app/i18n/zh-CN.ts +1 -0
- package/dist/templates/default/app/i18n/zh-TW.ts +1 -0
- package/dist/tracking/registry.js +11 -4
- package/package.json +4 -3
- package/src/templates/default/app/i18n/ar-SA.ts +1 -0
- package/src/templates/default/app/i18n/de-DE.ts +1 -0
- package/src/templates/default/app/i18n/en-US.ts +1 -0
- package/src/templates/default/app/i18n/es-ES.ts +1 -0
- package/src/templates/default/app/i18n/fr-FR.ts +1 -0
- package/src/templates/default/app/i18n/hi-IN.ts +1 -0
- package/src/templates/default/app/i18n/ja-JP.ts +1 -0
- package/src/templates/default/app/i18n/ko-KR.ts +1 -0
- package/src/templates/default/app/i18n/pt-BR.ts +1 -0
- package/src/templates/default/app/i18n/zh-CN.ts +1 -0
- package/src/templates/default/app/i18n/zh-TW.ts +1 -0
- package/corpus/templates/slides/app/components/editor/SlideBubbleMenu.tsx +0 -488
- package/corpus/templates/slides/app/components/editor/SlideInlineEditor.tsx +0 -589
- package/corpus/templates/slides/app/components/editor/SlideRichTextEditor.tsx +0 -1347
- package/corpus/templates/slides/app/components/editor/SlideSlashMenu.tsx +0 -373
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* owns persistence; these helpers deliberately only touch the live edit DOM.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { sanitizeSlideHtml } from "@/lib/sanitize-slide-html";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
extractWithoutCopiedIdentity,
|
|
10
|
+
stripCopiedIdentity,
|
|
11
|
+
} from "./bullet-editing";
|
|
12
|
+
|
|
6
13
|
export const INLINE_TEXT_STYLE_KEYS = [
|
|
7
14
|
"color",
|
|
8
15
|
"fontFamily",
|
|
@@ -31,6 +38,8 @@ export interface InlineTextStyleApplication {
|
|
|
31
38
|
range?: Range;
|
|
32
39
|
}
|
|
33
40
|
|
|
41
|
+
export type InlineTextFormat = "bold" | "italic" | "underline" | "strike";
|
|
42
|
+
|
|
34
43
|
const CSS_PROPERTY_NAMES: Record<InlineTextStyleKey, string> = {
|
|
35
44
|
color: "color",
|
|
36
45
|
fontFamily: "font-family",
|
|
@@ -42,6 +51,13 @@ const CSS_PROPERTY_NAMES: Record<InlineTextStyleKey, string> = {
|
|
|
42
51
|
lineHeight: "line-height",
|
|
43
52
|
};
|
|
44
53
|
|
|
54
|
+
const INLINE_STYLE_SPAN = "span[data-slide-inline-style]";
|
|
55
|
+
|
|
56
|
+
const DECORATION_LINE: Record<"underline" | "strike", string> = {
|
|
57
|
+
underline: "underline",
|
|
58
|
+
strike: "line-through",
|
|
59
|
+
};
|
|
60
|
+
|
|
45
61
|
function hasRangeInside(editable: HTMLElement, range: Range) {
|
|
46
62
|
return (
|
|
47
63
|
editable.contains(range.startContainer) &&
|
|
@@ -63,48 +79,29 @@ function applyPatch(element: HTMLElement, patch: InlineTextStylePatch) {
|
|
|
63
79
|
}
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
function
|
|
67
|
-
let candidate =
|
|
68
|
-
range.startContainer instanceof HTMLElement
|
|
69
|
-
? range.startContainer
|
|
70
|
-
: range.startContainer.parentElement;
|
|
71
|
-
const selectedText = range.toString();
|
|
72
|
-
|
|
73
|
-
while (candidate && candidate !== editable) {
|
|
74
|
-
if (
|
|
75
|
-
candidate instanceof HTMLSpanElement &&
|
|
76
|
-
candidate.dataset.slideInlineStyle === "true" &&
|
|
77
|
-
candidate.contains(range.startContainer) &&
|
|
78
|
-
candidate.contains(range.endContainer) &&
|
|
79
|
-
candidate.textContent === selectedText
|
|
80
|
-
) {
|
|
81
|
-
return candidate;
|
|
82
|
-
}
|
|
83
|
-
candidate = candidate.parentElement;
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function elementAttributesMatch(a: HTMLSpanElement, b: HTMLSpanElement) {
|
|
82
|
+
function elementAttributesMatch(a: Element, b: Element) {
|
|
89
83
|
if (a.attributes.length !== b.attributes.length) return false;
|
|
90
84
|
return Array.from(a.attributes).every(
|
|
91
85
|
(attribute) => b.getAttribute(attribute.name) === attribute.value,
|
|
92
86
|
);
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Removes only markup this module creates. Author spans are never removed or
|
|
91
|
+
* merged, even when empty or identical: an empty span is often a decorative
|
|
92
|
+
* dot, and merging author runs rewrites what the stored slide says.
|
|
93
|
+
*/
|
|
94
|
+
export function normalizeInlineTextSpans(editable: HTMLElement) {
|
|
95
|
+
const spans = Array.from(
|
|
96
|
+
editable.querySelectorAll<HTMLSpanElement>(INLINE_STYLE_SPAN),
|
|
97
|
+
);
|
|
101
98
|
for (const span of spans.reverse()) {
|
|
102
99
|
if (!span.isConnected) continue;
|
|
103
100
|
if (!span.textContent && span.children.length === 0) {
|
|
104
101
|
span.remove();
|
|
105
102
|
continue;
|
|
106
103
|
}
|
|
107
|
-
if (span.attributes.length ===
|
|
104
|
+
if (span.attributes.length === 1) {
|
|
108
105
|
span.replaceWith(...Array.from(span.childNodes));
|
|
109
106
|
}
|
|
110
107
|
}
|
|
@@ -112,12 +109,13 @@ export function normalizeInlineTextSpans(
|
|
|
112
109
|
let merged = true;
|
|
113
110
|
while (merged) {
|
|
114
111
|
merged = false;
|
|
115
|
-
for (const span of Array.from(
|
|
112
|
+
for (const span of Array.from(
|
|
113
|
+
editable.querySelectorAll<HTMLSpanElement>(INLINE_STYLE_SPAN),
|
|
114
|
+
)) {
|
|
116
115
|
const next = span.nextSibling;
|
|
117
116
|
if (
|
|
118
117
|
next instanceof HTMLSpanElement &&
|
|
119
|
-
|
|
120
|
-
next !== preserve &&
|
|
118
|
+
next.matches(INLINE_STYLE_SPAN) &&
|
|
121
119
|
elementAttributesMatch(span, next)
|
|
122
120
|
) {
|
|
123
121
|
span.append(...Array.from(next.childNodes));
|
|
@@ -178,42 +176,70 @@ export function restoreEditableTextRange(
|
|
|
178
176
|
return true;
|
|
179
177
|
}
|
|
180
178
|
|
|
179
|
+
/** Text that is page structure rather than a run a span can style. */
|
|
180
|
+
function isStylableText(text: Text) {
|
|
181
|
+
// ponytail: whitespace-only text holding a newline is treated as source
|
|
182
|
+
// indentation; styling a deliberately blank line would need layout reads.
|
|
183
|
+
if (/^\s*\n\s*$/.test(text.data)) return false;
|
|
184
|
+
return !text.parentElement?.closest("style, script, template, svg");
|
|
185
|
+
}
|
|
186
|
+
|
|
181
187
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* prior inline color or font on a nested span without touching unselected text.
|
|
188
|
+
* Splits text nodes at the range ends and returns each selected text run.
|
|
189
|
+
* Only text nodes are split, so no author element is ever cut in two.
|
|
185
190
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
if (!range || stylePatchEntries(patch).length === 0)
|
|
193
|
-
return { scope: "block" };
|
|
194
|
-
|
|
195
|
-
let wrapper = selectedInlineWrapper(editable, range);
|
|
196
|
-
if (!wrapper) {
|
|
197
|
-
const fragment = range.extractContents();
|
|
198
|
-
wrapper = document.createElement("span");
|
|
199
|
-
wrapper.dataset.slideInlineStyle = "true";
|
|
200
|
-
wrapper.append(fragment);
|
|
201
|
-
range.insertNode(wrapper);
|
|
191
|
+
function splitSelectedText(editable: HTMLElement, range: Range): Text[] {
|
|
192
|
+
const { startContainer, startOffset, endContainer, endOffset } = range;
|
|
193
|
+
const walker = document.createTreeWalker(editable, NodeFilter.SHOW_TEXT);
|
|
194
|
+
const intersecting: Text[] = [];
|
|
195
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
196
|
+
if (range.intersectsNode(node)) intersecting.push(node as Text);
|
|
202
197
|
}
|
|
198
|
+
return intersecting.flatMap((text) => {
|
|
199
|
+
const from = text === startContainer ? startOffset : 0;
|
|
200
|
+
const to = text === endContainer ? endOffset : text.length;
|
|
201
|
+
if (from >= to || !isStylableText(text)) return [];
|
|
202
|
+
let selected = text;
|
|
203
|
+
if (to < selected.length) selected.splitText(to);
|
|
204
|
+
if (from > 0) selected = selected.splitText(from);
|
|
205
|
+
return [selected];
|
|
206
|
+
});
|
|
207
|
+
}
|
|
203
208
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
209
|
+
/** The run's own style span: reused when it wraps exactly this run. */
|
|
210
|
+
function innermostStyleSpan(text: Text): HTMLSpanElement {
|
|
211
|
+
const parent = text.parentElement;
|
|
212
|
+
if (
|
|
213
|
+
parent instanceof HTMLSpanElement &&
|
|
214
|
+
parent.matches(INLINE_STYLE_SPAN) &&
|
|
215
|
+
parent.childNodes.length === 1
|
|
216
|
+
) {
|
|
217
|
+
return parent;
|
|
210
218
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
const span = document.createElement("span");
|
|
220
|
+
span.dataset.slideInlineStyle = "true";
|
|
221
|
+
text.replaceWith(span);
|
|
222
|
+
span.append(text);
|
|
223
|
+
return span;
|
|
224
|
+
}
|
|
214
225
|
|
|
226
|
+
function styleSelectedText(
|
|
227
|
+
editable: HTMLElement,
|
|
228
|
+
selection: Selection | null,
|
|
229
|
+
style: (texts: Text[]) => void,
|
|
230
|
+
): InlineTextStyleApplication {
|
|
231
|
+
const range = getEditableTextRange(editable, selection);
|
|
232
|
+
if (!range) return { scope: "block" };
|
|
233
|
+
const texts = splitSelectedText(editable, range);
|
|
234
|
+
if (texts.length === 0) return { scope: "selection", range };
|
|
235
|
+
style(texts);
|
|
236
|
+
normalizeInlineTextSpans(editable);
|
|
237
|
+
|
|
238
|
+
// Anchor on the text nodes: normalization moves them but never replaces them.
|
|
239
|
+
const last = texts[texts.length - 1];
|
|
215
240
|
const nextRange = document.createRange();
|
|
216
|
-
nextRange.
|
|
241
|
+
nextRange.setStart(texts[0], 0);
|
|
242
|
+
nextRange.setEnd(last, last.length);
|
|
217
243
|
if (selection) {
|
|
218
244
|
selection.removeAllRanges();
|
|
219
245
|
selection.addRange(nextRange);
|
|
@@ -221,6 +247,256 @@ export function applyInlineTextStyle(
|
|
|
221
247
|
return { scope: "selection", range: nextRange };
|
|
222
248
|
}
|
|
223
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Styles precisely the selected text. Each selected run gets its own innermost
|
|
252
|
+
* `span[data-slide-inline-style]`, so the patch beats any nested author style
|
|
253
|
+
* while no author element is split, merged, or removed.
|
|
254
|
+
*/
|
|
255
|
+
export function applyInlineTextStyle(
|
|
256
|
+
editable: HTMLElement,
|
|
257
|
+
patch: InlineTextStylePatch,
|
|
258
|
+
selection: Selection | null = window.getSelection(),
|
|
259
|
+
): InlineTextStyleApplication {
|
|
260
|
+
if (stylePatchEntries(patch).length === 0) return { scope: "block" };
|
|
261
|
+
return styleSelectedText(editable, selection, (texts) => {
|
|
262
|
+
for (const text of texts) applyPatch(innermostStyleSpan(text), patch);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function decorationLines(value: string) {
|
|
267
|
+
return value.split(/\s+/).filter((line) => line && line !== "none");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function ownDecorationLines(element: Element) {
|
|
271
|
+
const computed = window.getComputedStyle(element);
|
|
272
|
+
return decorationLines(
|
|
273
|
+
computed.getPropertyValue("text-decoration-line") ||
|
|
274
|
+
computed.getPropertyValue("text-decoration"),
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Decorations are not inherited: a run is underlined when any ancestor up to
|
|
280
|
+
* the editable draws the line, whatever the run's own computed value says.
|
|
281
|
+
*/
|
|
282
|
+
function isFormatActive(
|
|
283
|
+
text: Text,
|
|
284
|
+
format: InlineTextFormat,
|
|
285
|
+
editable: HTMLElement,
|
|
286
|
+
) {
|
|
287
|
+
const element = text.parentElement;
|
|
288
|
+
if (!element) return false;
|
|
289
|
+
if (format === "bold") {
|
|
290
|
+
const weight = window.getComputedStyle(element).fontWeight;
|
|
291
|
+
return weight === "bold" || weight === "bolder" || Number(weight) >= 600;
|
|
292
|
+
}
|
|
293
|
+
if (format === "italic") {
|
|
294
|
+
return /italic|oblique/.test(window.getComputedStyle(element).fontStyle);
|
|
295
|
+
}
|
|
296
|
+
for (
|
|
297
|
+
let current: Element | null = element;
|
|
298
|
+
current && editable.contains(current);
|
|
299
|
+
current = current.parentElement
|
|
300
|
+
) {
|
|
301
|
+
if (ownDecorationLines(current).includes(DECORATION_LINE[format])) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function setOwnDecorationLine(element: HTMLElement, line: string, on: boolean) {
|
|
309
|
+
const lines = new Set(ownDecorationLines(element));
|
|
310
|
+
if (on) lines.add(line);
|
|
311
|
+
else lines.delete(line);
|
|
312
|
+
element.style.setProperty(
|
|
313
|
+
"text-decoration-line",
|
|
314
|
+
lines.size ? [...lines].join(" ") : "none",
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Stops `element` drawing `line`, writing `none` only when a rule would still draw it. */
|
|
319
|
+
function clearOwnDecorationLine(element: HTMLElement, line: string) {
|
|
320
|
+
const lines = new Set(ownDecorationLines(element));
|
|
321
|
+
lines.delete(line);
|
|
322
|
+
const rest = lines.size ? [...lines].join(" ") : "none";
|
|
323
|
+
// Its own `text-decoration` shorthand stays one declaration.
|
|
324
|
+
if (element.style.getPropertyValue("text-decoration")) {
|
|
325
|
+
element.style.setProperty("text-decoration-line", rest);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
element.style.removeProperty("text-decoration-line");
|
|
329
|
+
const drawn = ownDecorationLines(element);
|
|
330
|
+
if (
|
|
331
|
+
drawn.length !== lines.size ||
|
|
332
|
+
drawn.some((drawnLine) => !lines.has(drawnLine))
|
|
333
|
+
) {
|
|
334
|
+
element.style.setProperty("text-decoration-line", rest);
|
|
335
|
+
}
|
|
336
|
+
if (element.style.length === 0) element.removeAttribute("style");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const DECORATION_LOOK = [
|
|
340
|
+
"text-decoration-color",
|
|
341
|
+
"text-decoration-style",
|
|
342
|
+
"text-decoration-thickness",
|
|
343
|
+
] as const;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Removes `line` from the selected runs. A line is drawn over all the text
|
|
347
|
+
* of the element declaring it and nothing inside can cancel it, so every
|
|
348
|
+
* element drawing it over the selection stops, and each unselected run those
|
|
349
|
+
* elements covered draws it again with the look it had.
|
|
350
|
+
*/
|
|
351
|
+
function removeDecorationLine(
|
|
352
|
+
editable: HTMLElement,
|
|
353
|
+
texts: Text[],
|
|
354
|
+
format: "underline" | "strike",
|
|
355
|
+
) {
|
|
356
|
+
const line = DECORATION_LINE[format];
|
|
357
|
+
const selected = new Set<Node>(texts);
|
|
358
|
+
const drawing = new Set<HTMLElement>();
|
|
359
|
+
for (const text of texts) {
|
|
360
|
+
for (
|
|
361
|
+
let ancestor = text.parentElement;
|
|
362
|
+
ancestor && editable.contains(ancestor);
|
|
363
|
+
ancestor = ancestor.parentElement
|
|
364
|
+
) {
|
|
365
|
+
if (ownDecorationLines(ancestor).includes(line)) drawing.add(ancestor);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const redraw: [Text, [string, string][]][] = [];
|
|
369
|
+
for (const element of drawing) {
|
|
370
|
+
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
|
371
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
372
|
+
const text = node as Text;
|
|
373
|
+
if (selected.has(text) || !text.data || !isStylableText(text)) continue;
|
|
374
|
+
let source = text.parentElement!;
|
|
375
|
+
while (!drawing.has(source)) source = source.parentElement!;
|
|
376
|
+
if (source !== element) continue;
|
|
377
|
+
const computed = window.getComputedStyle(source);
|
|
378
|
+
redraw.push([
|
|
379
|
+
text,
|
|
380
|
+
DECORATION_LOOK.map((property) => [
|
|
381
|
+
property,
|
|
382
|
+
computed.getPropertyValue(property),
|
|
383
|
+
]),
|
|
384
|
+
]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
for (const element of drawing) clearOwnDecorationLine(element, line);
|
|
388
|
+
for (const [text, look] of redraw) {
|
|
389
|
+
if (isFormatActive(text, format, editable)) continue;
|
|
390
|
+
const span = innermostStyleSpan(text);
|
|
391
|
+
setOwnDecorationLine(span, line, true);
|
|
392
|
+
const computed = window.getComputedStyle(span);
|
|
393
|
+
for (const [property, value] of look) {
|
|
394
|
+
if (value && computed.getPropertyValue(property) !== value) {
|
|
395
|
+
span.style.setProperty(property, value);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const FORMAT_DECLARATION = {
|
|
402
|
+
bold: ["font-weight", "700", "400"],
|
|
403
|
+
italic: ["font-style", "italic", "normal"],
|
|
404
|
+
} as const;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Toggles a format from the selection's effective computed value. The run's
|
|
408
|
+
* own declaration is dropped first and the explicit value (700/400,
|
|
409
|
+
* italic/normal) is written only when what it inherits differs, so bold on
|
|
410
|
+
* then off leaves no markup, while un-bolding a heading made bold by its class
|
|
411
|
+
* still works without touching the class. A line is switched off where it is
|
|
412
|
+
* drawn, on the author element itself (see `removeDecorationLine`), never by
|
|
413
|
+
* splitting that element.
|
|
414
|
+
*/
|
|
415
|
+
export function toggleInlineTextFormat(
|
|
416
|
+
editable: HTMLElement,
|
|
417
|
+
format: InlineTextFormat,
|
|
418
|
+
selection: Selection | null = window.getSelection(),
|
|
419
|
+
): InlineTextStyleApplication {
|
|
420
|
+
return styleSelectedText(editable, selection, (texts) => {
|
|
421
|
+
const on = !texts.every((text) => isFormatActive(text, format, editable));
|
|
422
|
+
if (format === "underline" || format === "strike") {
|
|
423
|
+
if (!on) {
|
|
424
|
+
removeDecorationLine(editable, texts, format);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
for (const text of texts) {
|
|
428
|
+
setOwnDecorationLine(
|
|
429
|
+
innermostStyleSpan(text),
|
|
430
|
+
DECORATION_LINE[format],
|
|
431
|
+
true,
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const [property, onValue, offValue] = FORMAT_DECLARATION[format];
|
|
437
|
+
for (const text of texts) {
|
|
438
|
+
const span = innermostStyleSpan(text);
|
|
439
|
+
span.style.removeProperty(property);
|
|
440
|
+
if (isFormatActive(text, format, editable) !== on) {
|
|
441
|
+
span.style.setProperty(property, on ? onValue : offValue);
|
|
442
|
+
}
|
|
443
|
+
if (span.style.length === 0) span.removeAttribute("style");
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** Moves the part of `link` on one side of `text` into its own copy of the link. */
|
|
449
|
+
function splitLinkPart(
|
|
450
|
+
link: HTMLElement,
|
|
451
|
+
text: Text,
|
|
452
|
+
side: "before" | "after",
|
|
453
|
+
) {
|
|
454
|
+
const part = document.createRange();
|
|
455
|
+
if (side === "before") {
|
|
456
|
+
part.setStart(link, 0);
|
|
457
|
+
part.setEndBefore(text);
|
|
458
|
+
} else {
|
|
459
|
+
part.setStartAfter(text);
|
|
460
|
+
part.setEnd(link, link.childNodes.length);
|
|
461
|
+
}
|
|
462
|
+
if (!part.toString()) return;
|
|
463
|
+
const copy = link.cloneNode(false) as HTMLElement;
|
|
464
|
+
stripCopiedIdentity(copy);
|
|
465
|
+
copy.append(extractWithoutCopiedIdentity(part));
|
|
466
|
+
link[side](copy);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Links, or unlinks, precisely the selected text. Each selected run is
|
|
471
|
+
* wrapped in its own `<a>`. A run inside a link is split out of it first, so
|
|
472
|
+
* linking keeps that link's attributes (a link inside a link is split apart
|
|
473
|
+
* when the slide is parsed again) and unlinking leaves the unselected rest of
|
|
474
|
+
* the link linked.
|
|
475
|
+
*/
|
|
476
|
+
export function setInlineTextLink(
|
|
477
|
+
editable: HTMLElement,
|
|
478
|
+
href: string | null,
|
|
479
|
+
selection: Selection | null = window.getSelection(),
|
|
480
|
+
): InlineTextStyleApplication {
|
|
481
|
+
return styleSelectedText(editable, selection, (texts) => {
|
|
482
|
+
for (const text of texts) {
|
|
483
|
+
const link = text.parentElement?.closest("a");
|
|
484
|
+
if (link && editable.contains(link)) {
|
|
485
|
+
splitLinkPart(link, text, "before");
|
|
486
|
+
splitLinkPart(link, text, "after");
|
|
487
|
+
if (href === null) link.replaceWith(...Array.from(link.childNodes));
|
|
488
|
+
else link.setAttribute("href", href);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (href === null) continue;
|
|
492
|
+
const anchor = document.createElement("a");
|
|
493
|
+
anchor.setAttribute("href", href);
|
|
494
|
+
text.replaceWith(anchor);
|
|
495
|
+
anchor.append(text);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
224
500
|
function selectionTextElements(editable: HTMLElement, range: Range) {
|
|
225
501
|
const walker = document.createTreeWalker(editable, NodeFilter.SHOW_TEXT);
|
|
226
502
|
const elements = new Set<HTMLElement>();
|
|
@@ -282,3 +558,162 @@ export function getInlineTextStyleSnapshotForRange(
|
|
|
282
558
|
}
|
|
283
559
|
return { scope: safeRange ? "selection" : "block", values, mixed };
|
|
284
560
|
}
|
|
561
|
+
|
|
562
|
+
const SLIDE_CLIPBOARD_BLOCK_TAGS = new Set([
|
|
563
|
+
"ADDRESS",
|
|
564
|
+
"ARTICLE",
|
|
565
|
+
"ASIDE",
|
|
566
|
+
"BLOCKQUOTE",
|
|
567
|
+
"DIV",
|
|
568
|
+
"DL",
|
|
569
|
+
"FIGCAPTION",
|
|
570
|
+
"FIGURE",
|
|
571
|
+
"FOOTER",
|
|
572
|
+
"FORM",
|
|
573
|
+
"H1",
|
|
574
|
+
"H2",
|
|
575
|
+
"H3",
|
|
576
|
+
"H4",
|
|
577
|
+
"H5",
|
|
578
|
+
"H6",
|
|
579
|
+
"HEADER",
|
|
580
|
+
"LI",
|
|
581
|
+
"MAIN",
|
|
582
|
+
"NAV",
|
|
583
|
+
"OL",
|
|
584
|
+
"P",
|
|
585
|
+
"PRE",
|
|
586
|
+
"SECTION",
|
|
587
|
+
"TABLE",
|
|
588
|
+
"TBODY",
|
|
589
|
+
"TD",
|
|
590
|
+
"TFOOT",
|
|
591
|
+
"TH",
|
|
592
|
+
"THEAD",
|
|
593
|
+
"TR",
|
|
594
|
+
"UL",
|
|
595
|
+
]);
|
|
596
|
+
|
|
597
|
+
const SLIDE_CLIPBOARD_LAYOUT_STYLE_PROPERTIES = [
|
|
598
|
+
"position",
|
|
599
|
+
"inset",
|
|
600
|
+
"top",
|
|
601
|
+
"right",
|
|
602
|
+
"bottom",
|
|
603
|
+
"left",
|
|
604
|
+
"width",
|
|
605
|
+
"height",
|
|
606
|
+
"min-width",
|
|
607
|
+
"min-height",
|
|
608
|
+
"max-width",
|
|
609
|
+
"max-height",
|
|
610
|
+
"margin",
|
|
611
|
+
"margin-top",
|
|
612
|
+
"margin-right",
|
|
613
|
+
"margin-bottom",
|
|
614
|
+
"margin-left",
|
|
615
|
+
"box-sizing",
|
|
616
|
+
"visibility",
|
|
617
|
+
"pointer-events",
|
|
618
|
+
"user-select",
|
|
619
|
+
"flex",
|
|
620
|
+
"flex-grow",
|
|
621
|
+
"flex-shrink",
|
|
622
|
+
"flex-basis",
|
|
623
|
+
"align-self",
|
|
624
|
+
"z-index",
|
|
625
|
+
"transform",
|
|
626
|
+
"transform-origin",
|
|
627
|
+
] as const;
|
|
628
|
+
|
|
629
|
+
function hasSlideClipboardText(element: Element): boolean {
|
|
630
|
+
return (
|
|
631
|
+
Boolean(element.textContent?.trim()) ||
|
|
632
|
+
element.querySelector("img") !== null
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function isSlideClipboardBlock(element: Element): boolean {
|
|
637
|
+
return SLIDE_CLIPBOARD_BLOCK_TAGS.has(element.tagName);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** Keep selected rich text, but discard editor context and source geometry. */
|
|
641
|
+
export function normalizeSlideClipboardHtml(html: string): string | null {
|
|
642
|
+
if (!html || typeof DOMParser === "undefined") return null;
|
|
643
|
+
const sanitized = sanitizeSlideHtml(html);
|
|
644
|
+
if (!sanitized.trim()) return null;
|
|
645
|
+
|
|
646
|
+
const doc = new DOMParser().parseFromString(sanitized, "text/html");
|
|
647
|
+
doc
|
|
648
|
+
.querySelectorAll(
|
|
649
|
+
"style, .fmd-layout-spacer, [data-slide-layout-spacer-for]",
|
|
650
|
+
)
|
|
651
|
+
.forEach((element) => element.remove());
|
|
652
|
+
doc.querySelectorAll<HTMLImageElement>("img").forEach((image) => {
|
|
653
|
+
if (!image.getAttribute("src")?.trim().toLowerCase().startsWith("data:")) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
const alt = image.getAttribute("alt");
|
|
657
|
+
if (alt) image.replaceWith(doc.createTextNode(alt));
|
|
658
|
+
else image.remove();
|
|
659
|
+
});
|
|
660
|
+
doc.querySelectorAll<HTMLElement>("*").forEach((element) => {
|
|
661
|
+
if (
|
|
662
|
+
element.style.visibility === "hidden" ||
|
|
663
|
+
(element.style.pointerEvents === "none" &&
|
|
664
|
+
element.style.userSelect === "none")
|
|
665
|
+
) {
|
|
666
|
+
element.remove();
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
// Editor state and identity: a pasted copy answering to its source's id
|
|
670
|
+
// or object id breaks selection, freeform moves, and export.
|
|
671
|
+
for (const attribute of Array.from(element.attributes)) {
|
|
672
|
+
if (attribute.name.startsWith("data-") || attribute.name === "id")
|
|
673
|
+
element.removeAttribute(attribute.name);
|
|
674
|
+
}
|
|
675
|
+
for (const property of SLIDE_CLIPBOARD_LAYOUT_STYLE_PROPERTIES) {
|
|
676
|
+
element.style.removeProperty(property);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
for (const node of Array.from(doc.body.childNodes)) {
|
|
681
|
+
if (node.nodeType === Node.TEXT_NODE && !node.textContent?.trim()) {
|
|
682
|
+
node.remove();
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const wrapper = doc.body.firstElementChild;
|
|
687
|
+
if (
|
|
688
|
+
doc.body.children.length === 1 &&
|
|
689
|
+
wrapper?.tagName === "DIV" &&
|
|
690
|
+
!wrapper.attributes.length
|
|
691
|
+
) {
|
|
692
|
+
while (wrapper.firstChild) doc.body.append(wrapper.firstChild);
|
|
693
|
+
wrapper.remove();
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const children = Array.from(doc.body.children);
|
|
697
|
+
if (!children.some(isSlideClipboardBlock)) {
|
|
698
|
+
const paragraph = doc.createElement("p");
|
|
699
|
+
while (doc.body.firstChild) paragraph.append(doc.body.firstChild);
|
|
700
|
+
doc.body.append(paragraph);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
const content = Array.from(doc.body.children);
|
|
704
|
+
const firstTextIndex = content.findIndex(hasSlideClipboardText);
|
|
705
|
+
if (firstTextIndex < 0) return null;
|
|
706
|
+
let lastTextIndex = -1;
|
|
707
|
+
content.forEach((element, index) => {
|
|
708
|
+
if (hasSlideClipboardText(element)) lastTextIndex = index;
|
|
709
|
+
});
|
|
710
|
+
content.slice(0, firstTextIndex).forEach((element) => element.remove());
|
|
711
|
+
content.slice(firstTextIndex + 1, lastTextIndex + 1).forEach((element) => {
|
|
712
|
+
if (element.tagName === "P" && !hasSlideClipboardText(element)) {
|
|
713
|
+
element.innerHTML = "<br>";
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
content.slice(lastTextIndex + 1).forEach((element) => element.remove());
|
|
717
|
+
|
|
718
|
+
return doc.body.innerHTML;
|
|
719
|
+
}
|