@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.
Files changed (233) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/analytics/.agents/skills/analysis-workspace/SKILL.md +10 -0
  3. package/corpus/templates/analytics/.agents/skills/data-querying/SKILL.md +1 -1
  4. package/corpus/templates/analytics/AGENTS.md +11 -22
  5. package/corpus/templates/analytics/actions/list-data-dictionary.ts +7 -9
  6. package/corpus/templates/analytics/actions/search-analytics-query-catalog.ts +1 -1
  7. package/corpus/templates/analytics/app/components/AnalyticsReviewArtifactPreview.tsx +201 -0
  8. package/corpus/templates/analytics/app/i18n/en-US.ts +2 -0
  9. package/corpus/templates/analytics/app/pages/Settings.tsx +50 -3
  10. package/corpus/templates/analytics/changelog/2026-09-25-first-run-onboarding-records-setup-choices-and-builder-conne.md +6 -0
  11. package/corpus/templates/analytics/changelog/2026-09-25-human-review-previews-analytics-dashboards-as-real-charts.md +6 -0
  12. package/corpus/templates/analytics/changelog/2026-09-25-org-admins-can-review-agent-runs-from-settings.md +6 -0
  13. package/corpus/templates/analytics/changelog/2026-09-25-proactive-query-context.md +6 -0
  14. package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +98 -2
  15. package/corpus/templates/analytics/server/lib/analytics-agent-context.ts +557 -0
  16. package/corpus/templates/analytics/server/lib/analytics-query-catalog.ts +217 -46
  17. package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +2 -2
  18. package/corpus/templates/analytics/server/lib/dashboards-store.ts +39 -5
  19. package/corpus/templates/analytics/server/lib/data-dictionary-context.ts +4 -0
  20. package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +268 -2
  21. package/corpus/templates/analytics/server/plugins/agent-chat.ts +44 -9
  22. package/corpus/templates/calendar/AGENTS.md +5 -0
  23. package/corpus/templates/calendar/CHANGELOG.md +6 -0
  24. package/corpus/templates/calendar/actions/get-event-rules-status.ts +47 -0
  25. package/corpus/templates/calendar/actions/list-events.ts +50 -4
  26. package/corpus/templates/calendar/actions/undo-calendar-event-rule.ts +229 -0
  27. package/corpus/templates/calendar/actions/update-settings.ts +8 -0
  28. package/corpus/templates/calendar/app/i18n/en-US.ts +27 -0
  29. package/corpus/templates/calendar/app/pages/Settings.tsx +196 -1
  30. package/corpus/templates/calendar/changelog/2026-09-25-calendar-feeds-with-the-same-url-keep-their-own-names-and-co.md +6 -0
  31. package/corpus/templates/calendar/changelog/2026-09-25-calendar-invitation-rules-surface-expired-connections-and-un.md +6 -0
  32. package/corpus/templates/calendar/changelog/2026-09-25-restore-locally-hidden-events-from-activity-after-disconnect.md +6 -0
  33. package/corpus/templates/calendar/server/lib/calendar-settings.ts +44 -10
  34. package/corpus/templates/calendar/server/lib/google-api.ts +15 -1
  35. package/corpus/templates/calendar/server/lib/google-calendar.ts +1 -1
  36. package/corpus/templates/calendar/server/plugins/event-rules.ts +628 -0
  37. package/corpus/templates/calendar/shared/api.ts +13 -0
  38. package/corpus/templates/calendar/shared/settings.ts +71 -1
  39. package/corpus/templates/clips/actions/create-recording.ts +83 -2
  40. package/corpus/templates/clips/actions/finalize-recording.ts +610 -110
  41. package/corpus/templates/clips/actions/get-recording-player-data.ts +6 -0
  42. package/corpus/templates/clips/actions/import-loom-recording.ts +2 -0
  43. package/corpus/templates/clips/actions/lib/create-recording-schema.ts +7 -0
  44. package/corpus/templates/clips/actions/lib/loom-import-job.ts +15 -1
  45. package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +126 -26
  46. package/corpus/templates/clips/app/hooks/use-drop-video-upload.ts +75 -15
  47. package/corpus/templates/clips/app/routes/_app.r.$recordingId.tsx +5 -1
  48. package/corpus/templates/clips/app/routes/record.tsx +134 -40
  49. package/corpus/templates/clips/chrome-extension/src/background.ts +3 -0
  50. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +73 -16
  51. package/corpus/templates/clips/desktop/src/lib/recorder.ts +188 -18
  52. package/corpus/templates/clips/desktop/src/lib/recording-request.ts +1 -0
  53. package/corpus/templates/clips/server/db/schema.ts +4 -0
  54. package/corpus/templates/clips/server/jobs/media-verification.ts +78 -4
  55. package/corpus/templates/clips/server/jobs/recording-failure-backfill.ts +142 -0
  56. package/corpus/templates/clips/server/lib/media-verification-state.ts +29 -0
  57. package/corpus/templates/clips/server/lib/post-finalize-dispatch.ts +2 -0
  58. package/corpus/templates/clips/server/lib/recording-failures.ts +111 -0
  59. package/corpus/templates/clips/server/lib/recordings.ts +6 -1
  60. package/corpus/templates/clips/server/lib/s3-upload-provider.ts +8 -3
  61. package/corpus/templates/clips/server/lib/upload-lease.ts +25 -6
  62. package/corpus/templates/clips/server/plugins/calendar-jobs.ts +2 -0
  63. package/corpus/templates/clips/server/plugins/db.ts +18 -0
  64. package/corpus/templates/clips/server/routes/api/_agent-native-background/post-finalize-worker.post.ts +48 -5
  65. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/abort.post.ts +322 -31
  66. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +223 -61
  67. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/interrupt.post.ts +62 -4
  68. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/reset-chunks.post.ts +74 -7
  69. package/corpus/templates/clips/shared/recording-core.ts +27 -0
  70. package/corpus/templates/design/actions/get-design.ts +35 -6
  71. package/corpus/templates/mail/.agents/skills/inbox-automations/SKILL.md +4 -0
  72. package/corpus/templates/mail/actions/consolidate-ai-filter-rules.ts +41 -0
  73. package/corpus/templates/mail/actions/get-ai-priority.ts +48 -8
  74. package/corpus/templates/mail/actions/record-ai-priority-feedback.ts +69 -0
  75. package/corpus/templates/mail/actions/update-mail-preferences.ts +2 -0
  76. package/corpus/templates/mail/app/components/email/EmailList.tsx +179 -32
  77. package/corpus/templates/mail/app/components/email/EmailListItem.tsx +97 -9
  78. package/corpus/templates/mail/app/components/email/EmailThread.tsx +55 -1
  79. package/corpus/templates/mail/app/components/email/ImportanceFeedbackMenu.tsx +52 -0
  80. package/corpus/templates/mail/app/components/email/compose-autocomplete.ts +2 -1
  81. package/corpus/templates/mail/app/components/layout/AppLayout.tsx +219 -188
  82. package/corpus/templates/mail/app/components/onboarding/AiInboxSetup.tsx +338 -0
  83. package/corpus/templates/mail/app/components/settings/AiFilterSection.tsx +597 -781
  84. package/corpus/templates/mail/app/components/settings/AiRulePromptField.tsx +37 -0
  85. package/corpus/templates/mail/app/global.css +42 -26
  86. package/corpus/templates/mail/app/hooks/use-ai-priority-feedback.ts +43 -0
  87. package/corpus/templates/mail/app/hooks/use-automations.ts +23 -0
  88. package/corpus/templates/mail/app/i18n/en-US.ts +58 -3
  89. package/corpus/templates/mail/app/pages/InboxPage.tsx +47 -10
  90. package/corpus/templates/mail/changelog/2026-09-25-editing-importance-rules-preserves-disabled-instructions-and.md +6 -0
  91. package/corpus/templates/mail/changelog/2026-09-25-handle-astral-unicode-letters-in-autocomplete-word-boundarie.md +6 -0
  92. package/corpus/templates/mail/changelog/2026-09-25-jev-priority-feedback-and-inbox-settings.md +6 -0
  93. package/corpus/templates/mail/changelog/2026-09-25-keep-existing-ai-filter-rules-intact-when-saving-a-prompt.md +6 -0
  94. package/corpus/templates/mail/server/lib/automation-engine.ts +21 -12
  95. package/corpus/templates/mail/server/lib/automations.ts +100 -1
  96. package/corpus/templates/mail/shared/types.ts +3 -0
  97. package/corpus/templates/plan/app/i18n/en-US.ts +6 -0
  98. package/corpus/templates/plan/app/lib/plan-invite-suggestion.ts +43 -0
  99. package/corpus/templates/plan/app/pages/PlansPage.tsx +249 -4
  100. package/corpus/templates/slides/actions/create-deck.ts +11 -1
  101. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +117 -1
  102. package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +373 -330
  103. package/corpus/templates/slides/app/components/design-system/builder-index-response.ts +36 -5
  104. package/corpus/templates/slides/app/components/editor/BlockBubbleMenu.tsx +21 -53
  105. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +347 -671
  106. package/corpus/templates/slides/app/components/editor/bullet-editing.ts +55 -8
  107. package/corpus/templates/slides/app/components/editor/in-place-text-session.ts +2082 -0
  108. package/corpus/templates/slides/app/components/editor/list-editing.ts +174 -16
  109. package/corpus/templates/slides/app/components/editor/rich-text-selection.ts +497 -62
  110. package/corpus/templates/slides/app/components/editor/slide-text-targets.ts +102 -20
  111. package/corpus/templates/slides/app/context/DeckContext.tsx +9 -4
  112. package/corpus/templates/slides/app/global.css +7 -219
  113. package/corpus/templates/slides/app/i18n/en-US.ts +3 -0
  114. package/corpus/templates/slides/app/lib/sanitize-slide-html.ts +7 -0
  115. package/corpus/templates/slides/app/lib/slide-image-replacement.ts +203 -1
  116. package/corpus/templates/slides/app/lib/slide-source-map.ts +43 -0
  117. package/corpus/templates/slides/app/pages/DeckEditor.tsx +182 -4
  118. package/corpus/templates/slides/app/routes/settings.tsx +33 -2
  119. package/corpus/templates/slides/changelog/2026-09-25-improve-slides-design-system-setup-feedback.md +6 -0
  120. package/corpus/templates/slides/changelog/2026-09-25-org-admins-can-review-agent-runs-from-settings.md +6 -0
  121. package/corpus/templates/slides/changelog/2026-09-25-text-on-a-slide-is-now-edited-in-place-clicking-into-it-chan.md +6 -0
  122. package/corpus/templates/slides/package.json +0 -12
  123. package/corpus/templates/slides/scripts/edit-fidelity/README.md +4 -2
  124. package/corpus/templates/slides/scripts/edit-fidelity/run.ts +12 -3
  125. package/corpus/templates/slides/vite.config.ts +1 -10
  126. package/dist/agent/jev-tool-prefetch.d.ts +29 -3
  127. package/dist/agent/jev-tool-prefetch.js +161 -34
  128. package/dist/agent/production-agent.d.ts +11 -0
  129. package/dist/agent/production-agent.js +39 -8
  130. package/dist/app-config/runtime.d.ts +1 -0
  131. package/dist/app-config/runtime.js +4 -0
  132. package/dist/app-config/schema.d.ts +1 -0
  133. package/dist/client/AgentSidebar.d.ts +3 -1
  134. package/dist/client/AgentSidebar.js +8 -12
  135. package/dist/client/analytics/index.d.ts +1 -1
  136. package/dist/client/analytics/index.js +1 -1
  137. package/dist/client/analytics.d.ts +2 -0
  138. package/dist/client/analytics.js +9 -0
  139. package/dist/client/api-path.js +5 -2
  140. package/dist/client/chat/run-recovery.d.ts +0 -3
  141. package/dist/client/chat/run-recovery.js +13 -23
  142. package/dist/client/index.d.ts +1 -1
  143. package/dist/client/index.js +1 -1
  144. package/dist/client/observability/ObservabilityDashboard.d.ts +3 -0
  145. package/dist/client/observability/ObservabilityDashboard.js +366 -71
  146. package/dist/client/observability/ObservabilityReviewSummaryButton.d.ts +4 -1
  147. package/dist/client/observability/ObservabilityReviewSummaryButton.js +13 -9
  148. package/dist/client/observability/OutputPreview.d.ts +9 -4
  149. package/dist/client/observability/OutputPreview.js +230 -52
  150. package/dist/client/onboarding/FirstRunOnboarding.js +67 -4
  151. package/dist/client/onboarding/use-onboarding.js +2 -0
  152. package/dist/client/sharing/ShareButton.d.ts +2 -0
  153. package/dist/client/sharing/ShareButton.js +1 -0
  154. package/dist/client/sharing/useShareButtonController.d.ts +1 -0
  155. package/dist/client/sharing/useShareButtonController.js +29 -8
  156. package/dist/collab/awareness.d.ts +2 -2
  157. package/dist/collab/struct-routes.d.ts +1 -1
  158. package/dist/deploy/build.js +9 -1
  159. package/dist/embeddings/index.d.ts +3 -1
  160. package/dist/embeddings/index.js +20 -10
  161. package/dist/jobs/sweep-hooks.d.ts +7 -0
  162. package/dist/jobs/sweep-hooks.js +28 -0
  163. package/dist/localization/default-messages.d.ts +1 -0
  164. package/dist/localization/default-messages.js +1 -0
  165. package/dist/mcp/screen-memory-stdio.d.ts +7 -7
  166. package/dist/notifications/routes.d.ts +1 -1
  167. package/dist/observability/actions/authorization.d.ts +1 -0
  168. package/dist/observability/actions/authorization.js +22 -0
  169. package/dist/observability/actions/get-observability-review-detail.d.ts +5 -0
  170. package/dist/observability/actions/get-observability-review-detail.js +10 -2
  171. package/dist/observability/actions/get-observability-review-summary-source.d.ts +2 -0
  172. package/dist/observability/actions/get-observability-review-summary-source.js +3 -2
  173. package/dist/observability/actions/save-observability-instruction-update.js +2 -1
  174. package/dist/observability/actions/save-observability-review-summary.js +21 -10
  175. package/dist/observability/migrations.js +25 -0
  176. package/dist/observability/reviews.d.ts +3 -1
  177. package/dist/observability/reviews.js +410 -53
  178. package/dist/observability/routes.d.ts +6 -6
  179. package/dist/observability/store.d.ts +15 -0
  180. package/dist/observability/store.js +131 -11
  181. package/dist/observability/types.d.ts +18 -0
  182. package/dist/org/handlers.d.ts +1 -1
  183. package/dist/org/index.d.ts +1 -1
  184. package/dist/progress/routes.d.ts +1 -1
  185. package/dist/provider-api/actions/custom-provider-registration.d.ts +5 -5
  186. package/dist/provider-api/actions/provider-api.d.ts +8 -8
  187. package/dist/secrets/routes.d.ts +3 -3
  188. package/dist/server/agent-chat/plugin-options.d.ts +4 -20
  189. package/dist/server/agent-chat/prompt-resources.d.ts +16 -0
  190. package/dist/server/agent-chat/prompt-resources.js +385 -22
  191. package/dist/server/agent-chat-plugin.d.ts +3 -1
  192. package/dist/server/agent-chat-plugin.js +149 -27
  193. package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
  194. package/dist/server/index.d.ts +3 -0
  195. package/dist/server/index.js +3 -0
  196. package/dist/server/prompts/framework-core-compact.js +1 -1
  197. package/dist/server/prompts/framework-core.js +1 -1
  198. package/dist/server/realtime-token.d.ts +1 -1
  199. package/dist/server/request-context.d.ts +6 -3
  200. package/dist/server/transcribe-voice.d.ts +1 -1
  201. package/dist/settings/org-settings.d.ts +4 -2
  202. package/dist/settings/org-settings.js +3 -3
  203. package/dist/settings/store.d.ts +3 -1
  204. package/dist/settings/store.js +8 -3
  205. package/dist/styles/agent-native.css +5 -0
  206. package/dist/templates/default/app/i18n/ar-SA.ts +1 -0
  207. package/dist/templates/default/app/i18n/de-DE.ts +1 -0
  208. package/dist/templates/default/app/i18n/en-US.ts +1 -0
  209. package/dist/templates/default/app/i18n/es-ES.ts +1 -0
  210. package/dist/templates/default/app/i18n/fr-FR.ts +1 -0
  211. package/dist/templates/default/app/i18n/hi-IN.ts +1 -0
  212. package/dist/templates/default/app/i18n/ja-JP.ts +1 -0
  213. package/dist/templates/default/app/i18n/ko-KR.ts +1 -0
  214. package/dist/templates/default/app/i18n/pt-BR.ts +1 -0
  215. package/dist/templates/default/app/i18n/zh-CN.ts +1 -0
  216. package/dist/templates/default/app/i18n/zh-TW.ts +1 -0
  217. package/dist/tracking/registry.js +11 -4
  218. package/package.json +4 -3
  219. package/src/templates/default/app/i18n/ar-SA.ts +1 -0
  220. package/src/templates/default/app/i18n/de-DE.ts +1 -0
  221. package/src/templates/default/app/i18n/en-US.ts +1 -0
  222. package/src/templates/default/app/i18n/es-ES.ts +1 -0
  223. package/src/templates/default/app/i18n/fr-FR.ts +1 -0
  224. package/src/templates/default/app/i18n/hi-IN.ts +1 -0
  225. package/src/templates/default/app/i18n/ja-JP.ts +1 -0
  226. package/src/templates/default/app/i18n/ko-KR.ts +1 -0
  227. package/src/templates/default/app/i18n/pt-BR.ts +1 -0
  228. package/src/templates/default/app/i18n/zh-CN.ts +1 -0
  229. package/src/templates/default/app/i18n/zh-TW.ts +1 -0
  230. package/corpus/templates/slides/app/components/editor/SlideBubbleMenu.tsx +0 -488
  231. package/corpus/templates/slides/app/components/editor/SlideInlineEditor.tsx +0 -589
  232. package/corpus/templates/slides/app/components/editor/SlideRichTextEditor.tsx +0 -1347
  233. package/corpus/templates/slides/app/components/editor/SlideSlashMenu.tsx +0 -373
@@ -10,7 +10,7 @@
10
10
  * No React exports, so this stays Fast-Refresh friendly and unit-testable.
11
11
  */
12
12
 
13
- import { isBulletMarker } from "./bullet-editing";
13
+ import { isBulletMarker, isBulletRow } from "./bullet-editing";
14
14
 
15
15
  export type SlideListKind = "bullet" | "ordered";
16
16
 
@@ -32,6 +32,50 @@ const LIST_STYLE: Record<SlideListKind, string> = {
32
32
  "margin:0;padding-left:1.25em;list-style-position:outside;list-style-type:decimal;",
33
33
  };
34
34
 
35
+ const ROW_TEXT_PROPERTY =
36
+ /^(color|font(-.+)?|letter-spacing|word-spacing|line-height|text-(transform|shadow|decoration(-.+)?))$/;
37
+
38
+ const HEADING_TAG = /^H[1-6]$/;
39
+
40
+ /** What a heading's tag gives its text, which is lost with the tag. */
41
+ const HEADING_TEXT_PROPERTIES = [
42
+ "color",
43
+ "font-family",
44
+ "font-size",
45
+ "font-style",
46
+ "font-weight",
47
+ "letter-spacing",
48
+ "line-height",
49
+ "text-transform",
50
+ ] as const;
51
+
52
+ export type TextLook = [property: string, value: string][];
53
+
54
+ /**
55
+ * A heading's computed text look, or null for any other element. A heading
56
+ * holds only phrasing content, so a list made of one takes its place (or its
57
+ * line's) and has to carry the look its tag gave it.
58
+ */
59
+ export function headingTextLook(element: Element): TextLook | null {
60
+ if (!HEADING_TAG.test(element.tagName)) return null;
61
+ const computed = element.ownerDocument.defaultView!.getComputedStyle(element);
62
+ return HEADING_TEXT_PROPERTIES.map((property) => [
63
+ property,
64
+ computed.getPropertyValue(property),
65
+ ]);
66
+ }
67
+
68
+ /** Restates each part of `look` that `target` (in the document) now differs from. */
69
+ export function keepTextLook(target: HTMLElement, look: TextLook | null) {
70
+ if (!look) return;
71
+ const computed = target.ownerDocument.defaultView!.getComputedStyle(target);
72
+ for (const [property, value] of look) {
73
+ if (value && computed.getPropertyValue(property) !== value) {
74
+ target.style.setProperty(property, value);
75
+ }
76
+ }
77
+ }
78
+
35
79
  function isListTag(element: Element): boolean {
36
80
  return element.tagName === "UL" || element.tagName === "OL";
37
81
  }
@@ -56,6 +100,26 @@ export function detectSlideListKind(
56
100
  return list.tagName === "OL" ? "ordered" : "bullet";
57
101
  }
58
102
 
103
+ /** Styled bullet rows directly inside `element` (see `bullet-editing.ts`). */
104
+ function bulletRows(element: HTMLElement): HTMLElement[] {
105
+ if (isListTag(element)) return [];
106
+ return Array.from(element.children).filter(
107
+ (child): child is HTMLElement =>
108
+ child instanceof HTMLElement && isBulletRow(child),
109
+ );
110
+ }
111
+
112
+ /** The kind the list control shows: styled bullet rows are a bullet list too. */
113
+ export function activeSlideListKind(
114
+ element: HTMLElement | null,
115
+ ): SlideListKind | null {
116
+ if (!element) return null;
117
+ return (
118
+ detectSlideListKind(element) ??
119
+ (bulletRows(element).length > 0 ? "bullet" : null)
120
+ );
121
+ }
122
+
59
123
  /**
60
124
  * Swap an element's tag while keeping its attributes and children. UL and OL
61
125
  * differ only by tag, so switching list kind in place would otherwise leave an
@@ -111,29 +175,40 @@ function blockChildren(source: HTMLElement): HTMLElement[] | null {
111
175
  return blocks.length > 0 ? blocks : null;
112
176
  }
113
177
 
178
+ interface Line {
179
+ html: string;
180
+ /** The look of the heading the line was, which its item keeps. */
181
+ look: TextLook | null;
182
+ }
183
+
114
184
  /**
115
185
  * The inner HTML of each line the object currently holds. A styled bullet row
116
186
  * contributes only its text, so converting agent-generated bullets to a real
117
187
  * list drops the now-duplicated marker instead of rendering two markers.
118
188
  */
119
- function readLines(source: HTMLElement): string[] {
189
+ function readLines(source: HTMLElement): Line[] {
120
190
  const blocks = blockChildren(source);
121
-
122
191
  if (blocks) {
123
- return blocks.flatMap((block) => {
124
- const stripped = block.cloneNode(true) as HTMLElement;
125
- for (const child of Array.from(stripped.children)) {
126
- if (isBulletMarker(child)) child.remove();
127
- }
128
- const html = stripped.innerHTML.trim();
129
- return html ? [html] : [];
130
- });
192
+ return blocks.flatMap((block) =>
193
+ lineHtml(block).map((html) => ({ html, look: headingTextLook(block) })),
194
+ );
131
195
  }
132
196
 
133
197
  return source.innerHTML
134
198
  .split(/<br\s*\/?>/i)
135
199
  .map((line) => line.trim())
136
- .filter(Boolean);
200
+ .filter(Boolean)
201
+ .map((html) => ({ html, look: null }));
202
+ }
203
+
204
+ /** One block's line, without the marker a styled bullet row draws. */
205
+ function lineHtml(block: HTMLElement): string[] {
206
+ const stripped = block.cloneNode(true) as HTMLElement;
207
+ for (const child of Array.from(stripped.children)) {
208
+ if (isBulletMarker(child)) child.remove();
209
+ }
210
+ const html = stripped.innerHTML.trim();
211
+ return html ? [html] : [];
137
212
  }
138
213
 
139
214
  function itemHtml(list: HTMLElement): string[] {
@@ -142,13 +217,22 @@ function itemHtml(list: HTMLElement): string[] {
142
217
  .map((item) => item.innerHTML);
143
218
  }
144
219
 
145
- function buildList(
220
+ /** An empty list of `kind`, with its markers restated for preflight. */
221
+ export function createSlideList(
146
222
  doc: Document,
147
223
  kind: SlideListKind,
148
- lines: string[],
149
224
  ): HTMLElement {
150
225
  const list = doc.createElement(LIST_TAG[kind]);
151
226
  list.setAttribute("style", LIST_STYLE[kind]);
227
+ return list;
228
+ }
229
+
230
+ function buildList(
231
+ doc: Document,
232
+ kind: SlideListKind,
233
+ lines: string[],
234
+ ): HTMLElement {
235
+ const list = createSlideList(doc, kind);
152
236
  for (const line of lines) {
153
237
  const item = doc.createElement("li");
154
238
  item.innerHTML = line;
@@ -181,10 +265,27 @@ export function toggleSlideList(
181
265
  const existing = listElement(element);
182
266
 
183
267
  if (!existing) {
268
+ const rows = bulletRows(element);
269
+ if (rows.length > 0) return toggleBulletRows(element, rows, kind);
184
270
  const lines = readLines(element);
185
271
  if (lines.length === 0) return null;
186
- element.replaceChildren(buildList(doc, kind, lines));
187
- return element;
272
+ // A <p> cannot hold a list: parsing the saved slide would close the
273
+ // paragraph before it and leave the list and its text unstyled. A
274
+ // heading may hold only phrasing content either.
275
+ const look = headingTextLook(element);
276
+ const holder =
277
+ element.tagName === "P" || look ? retag(element, "DIV") : element;
278
+ const list = buildList(
279
+ doc,
280
+ kind,
281
+ lines.map((line) => line.html),
282
+ );
283
+ holder.replaceChildren(list);
284
+ keepTextLook(holder, look);
285
+ Array.from(list.children).forEach((item, index) =>
286
+ keepTextLook(item as HTMLElement, lines[index].look),
287
+ );
288
+ return holder;
188
289
  }
189
290
 
190
291
  const lines = itemHtml(existing);
@@ -217,3 +318,60 @@ export function toggleSlideList(
217
318
  existing.replaceWith(buildLines(doc, lines));
218
319
  return element;
219
320
  }
321
+
322
+ /**
323
+ * Styled bullet rows already are a bullet list, and only the rows are: a
324
+ * label beside them stays as it is. Toggling bullets drops the row markers;
325
+ * numbering replaces each run of adjacent rows with an ordered list where
326
+ * that run stood, so rows never move past the content between them.
327
+ */
328
+ function toggleBulletRows(
329
+ element: HTMLElement,
330
+ rows: HTMLElement[],
331
+ kind: SlideListKind,
332
+ ): HTMLElement {
333
+ if (kind === "bullet") {
334
+ for (const row of rows) {
335
+ const marker = row.firstElementChild;
336
+ if (marker && isBulletMarker(marker)) marker.remove();
337
+ }
338
+ return element;
339
+ }
340
+ const runs: HTMLElement[][] = [];
341
+ rows.forEach((row, index) => {
342
+ if (index > 0 && rows[index - 1].nextElementSibling === row) {
343
+ runs[runs.length - 1].push(row);
344
+ } else {
345
+ runs.push([row]);
346
+ }
347
+ });
348
+ for (const run of runs) numberRows(element, run, kind);
349
+ return element;
350
+ }
351
+
352
+ function numberRows(
353
+ element: HTMLElement,
354
+ rows: HTMLElement[],
355
+ kind: SlideListKind,
356
+ ) {
357
+ const list = createSlideList(element.ownerDocument, kind);
358
+ for (const row of rows) {
359
+ const [line] = lineHtml(row);
360
+ if (line === undefined) continue;
361
+ const item = element.ownerDocument.createElement("li");
362
+ item.innerHTML = line;
363
+ // The row's own text look is the item's; its flex layout is not.
364
+ for (let index = 0; index < row.style.length; index += 1) {
365
+ const name = row.style.item(index);
366
+ if (!ROW_TEXT_PROPERTY.test(name)) continue;
367
+ item.style.setProperty(
368
+ name,
369
+ row.style.getPropertyValue(name),
370
+ row.style.getPropertyPriority(name),
371
+ );
372
+ }
373
+ list.append(item);
374
+ }
375
+ rows[0].before(list);
376
+ for (const row of rows) row.remove();
377
+ }