@milkdown/crepe 7.20.0 → 7.21.1
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/lib/cjs/builder.js +1 -0
- package/lib/cjs/builder.js.map +1 -1
- package/lib/cjs/feature/ai/index.js +1492 -0
- package/lib/cjs/feature/ai/index.js.map +1 -0
- package/lib/cjs/feature/block-edit/index.js +1 -0
- package/lib/cjs/feature/block-edit/index.js.map +1 -1
- package/lib/cjs/feature/code-mirror/index.js +1 -0
- package/lib/cjs/feature/code-mirror/index.js.map +1 -1
- package/lib/cjs/feature/cursor/index.js +1 -0
- package/lib/cjs/feature/cursor/index.js.map +1 -1
- package/lib/cjs/feature/image-block/index.js +1 -0
- package/lib/cjs/feature/image-block/index.js.map +1 -1
- package/lib/cjs/feature/latex/index.js +2 -0
- package/lib/cjs/feature/latex/index.js.map +1 -1
- package/lib/cjs/feature/link-tooltip/index.js +1 -0
- package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
- package/lib/cjs/feature/list-item/index.js +1 -0
- package/lib/cjs/feature/list-item/index.js.map +1 -1
- package/lib/cjs/feature/placeholder/index.js +1 -0
- package/lib/cjs/feature/placeholder/index.js.map +1 -1
- package/lib/cjs/feature/table/index.js +1 -0
- package/lib/cjs/feature/table/index.js.map +1 -1
- package/lib/cjs/feature/toolbar/index.js +488 -3
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/feature/top-bar/index.js +1 -0
- package/lib/cjs/feature/top-bar/index.js.map +1 -1
- package/lib/cjs/index.js +1424 -25
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/llm-providers/anthropic/index.js +152 -0
- package/lib/cjs/llm-providers/anthropic/index.js.map +1 -0
- package/lib/cjs/llm-providers/openai/index.js +143 -0
- package/lib/cjs/llm-providers/openai/index.js.map +1 -0
- package/lib/esm/builder.js +1 -0
- package/lib/esm/builder.js.map +1 -1
- package/lib/esm/feature/ai/index.js +1487 -0
- package/lib/esm/feature/ai/index.js.map +1 -0
- package/lib/esm/feature/block-edit/index.js +1 -0
- package/lib/esm/feature/block-edit/index.js.map +1 -1
- package/lib/esm/feature/code-mirror/index.js +1 -0
- package/lib/esm/feature/code-mirror/index.js.map +1 -1
- package/lib/esm/feature/cursor/index.js +1 -0
- package/lib/esm/feature/cursor/index.js.map +1 -1
- package/lib/esm/feature/image-block/index.js +1 -0
- package/lib/esm/feature/image-block/index.js.map +1 -1
- package/lib/esm/feature/latex/index.js +2 -0
- package/lib/esm/feature/latex/index.js.map +1 -1
- package/lib/esm/feature/link-tooltip/index.js +1 -0
- package/lib/esm/feature/link-tooltip/index.js.map +1 -1
- package/lib/esm/feature/list-item/index.js +1 -0
- package/lib/esm/feature/list-item/index.js.map +1 -1
- package/lib/esm/feature/placeholder/index.js +1 -0
- package/lib/esm/feature/placeholder/index.js.map +1 -1
- package/lib/esm/feature/table/index.js +1 -0
- package/lib/esm/feature/table/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +490 -5
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/feature/top-bar/index.js +1 -0
- package/lib/esm/feature/top-bar/index.js.map +1 -1
- package/lib/esm/index.js +1414 -15
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/llm-providers/anthropic/index.js +150 -0
- package/lib/esm/llm-providers/anthropic/index.js.map +1 -0
- package/lib/esm/llm-providers/openai/index.js +141 -0
- package/lib/esm/llm-providers/openai/index.js.map +1 -0
- package/lib/theme/common/ai.css +446 -0
- package/lib/theme/common/code-mirror.css +14 -0
- package/lib/theme/common/diff.css +177 -0
- package/lib/theme/common/style.css +2 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/feature/ai/ai.spec.d.ts +2 -0
- package/lib/types/feature/ai/ai.spec.d.ts.map +1 -0
- package/lib/types/feature/ai/commands.d.ts +24 -0
- package/lib/types/feature/ai/commands.d.ts.map +1 -0
- package/lib/types/feature/ai/context.d.ts +4 -0
- package/lib/types/feature/ai/context.d.ts.map +1 -0
- package/lib/types/feature/ai/diff-actions/index.d.ts +12 -0
- package/lib/types/feature/ai/diff-actions/index.d.ts.map +1 -0
- package/lib/types/feature/ai/diff-actions/view.d.ts +21 -0
- package/lib/types/feature/ai/diff-actions/view.d.ts.map +1 -0
- package/lib/types/feature/ai/index.d.ts +7 -0
- package/lib/types/feature/ai/index.d.ts.map +1 -0
- package/lib/types/feature/ai/instruction-tooltip/component.d.ts +26 -0
- package/lib/types/feature/ai/instruction-tooltip/component.d.ts.map +1 -0
- package/lib/types/feature/ai/instruction-tooltip/index.d.ts +17 -0
- package/lib/types/feature/ai/instruction-tooltip/index.d.ts.map +1 -0
- package/lib/types/feature/ai/instruction-tooltip/suggestions.d.ts +50 -0
- package/lib/types/feature/ai/instruction-tooltip/suggestions.d.ts.map +1 -0
- package/lib/types/feature/ai/instruction-tooltip/view.d.ts +19 -0
- package/lib/types/feature/ai/instruction-tooltip/view.d.ts.map +1 -0
- package/lib/types/feature/ai/streaming-indicator.d.ts +9 -0
- package/lib/types/feature/ai/streaming-indicator.d.ts.map +1 -0
- package/lib/types/feature/ai/types.d.ts +58 -0
- package/lib/types/feature/ai/types.d.ts.map +1 -0
- package/lib/types/feature/index.d.ts +4 -1
- package/lib/types/feature/index.d.ts.map +1 -1
- package/lib/types/feature/latex/inline-tooltip/inline-tooltip.spec.d.ts +2 -0
- package/lib/types/feature/latex/inline-tooltip/inline-tooltip.spec.d.ts.map +1 -0
- package/lib/types/feature/latex/inline-tooltip/view.d.ts.map +1 -1
- package/lib/types/feature/loader.d.ts.map +1 -1
- package/lib/types/feature/toolbar/config.d.ts.map +1 -1
- package/lib/types/feature/toolbar/index.d.ts +1 -0
- package/lib/types/feature/toolbar/index.d.ts.map +1 -1
- package/lib/types/icons/ai.d.ts +2 -0
- package/lib/types/icons/ai.d.ts.map +1 -0
- package/lib/types/icons/chevron-left.d.ts +2 -0
- package/lib/types/icons/chevron-left.d.ts.map +1 -0
- package/lib/types/icons/chevron-right.d.ts +2 -0
- package/lib/types/icons/chevron-right.d.ts.map +1 -0
- package/lib/types/icons/enter-key.d.ts +2 -0
- package/lib/types/icons/enter-key.d.ts.map +1 -0
- package/lib/types/icons/grammar-check.d.ts +2 -0
- package/lib/types/icons/grammar-check.d.ts.map +1 -0
- package/lib/types/icons/index.d.ts +11 -0
- package/lib/types/icons/index.d.ts.map +1 -1
- package/lib/types/icons/longer.d.ts +2 -0
- package/lib/types/icons/longer.d.ts.map +1 -0
- package/lib/types/icons/retry.d.ts +2 -0
- package/lib/types/icons/retry.d.ts.map +1 -0
- package/lib/types/icons/send-prompt.d.ts +2 -0
- package/lib/types/icons/send-prompt.d.ts.map +1 -0
- package/lib/types/icons/send.d.ts +2 -0
- package/lib/types/icons/send.d.ts.map +1 -0
- package/lib/types/icons/shorter.d.ts +2 -0
- package/lib/types/icons/shorter.d.ts.map +1 -0
- package/lib/types/icons/translate.d.ts +2 -0
- package/lib/types/icons/translate.d.ts.map +1 -0
- package/lib/types/llm-providers/anthropic/index.d.ts +21 -0
- package/lib/types/llm-providers/anthropic/index.d.ts.map +1 -0
- package/lib/types/llm-providers/openai/index.d.ts +15 -0
- package/lib/types/llm-providers/openai/index.d.ts.map +1 -0
- package/lib/types/llm-providers/providers.spec.d.ts +2 -0
- package/lib/types/llm-providers/providers.spec.d.ts.map +1 -0
- package/lib/types/llm-providers/shared.d.ts +17 -0
- package/lib/types/llm-providers/shared.d.ts.map +1 -0
- package/package.json +18 -2
- package/src/feature/ai/ai.spec.ts +742 -0
- package/src/feature/ai/commands.ts +257 -0
- package/src/feature/ai/context.ts +45 -0
- package/src/feature/ai/diff-actions/index.ts +95 -0
- package/src/feature/ai/diff-actions/view.ts +237 -0
- package/src/feature/ai/index.ts +118 -0
- package/src/feature/ai/instruction-tooltip/component.tsx +414 -0
- package/src/feature/ai/instruction-tooltip/index.ts +101 -0
- package/src/feature/ai/instruction-tooltip/suggestions.ts +249 -0
- package/src/feature/ai/instruction-tooltip/view.ts +159 -0
- package/src/feature/ai/streaming-indicator.ts +183 -0
- package/src/feature/ai/types.ts +178 -0
- package/src/feature/index.ts +8 -2
- package/src/feature/latex/inline-tooltip/inline-tooltip.spec.ts +81 -0
- package/src/feature/latex/inline-tooltip/view.ts +2 -0
- package/src/feature/loader.ts +4 -0
- package/src/feature/toolbar/config.ts +27 -1
- package/src/feature/toolbar/index.ts +1 -0
- package/src/icons/ai.ts +14 -0
- package/src/icons/chevron-left.ts +15 -0
- package/src/icons/chevron-right.ts +15 -0
- package/src/icons/enter-key.ts +13 -0
- package/src/icons/grammar-check.ts +13 -0
- package/src/icons/index.ts +11 -0
- package/src/icons/longer.ts +13 -0
- package/src/icons/retry.ts +13 -0
- package/src/icons/send-prompt.ts +13 -0
- package/src/icons/send.ts +13 -0
- package/src/icons/shorter.ts +13 -0
- package/src/icons/translate.ts +13 -0
- package/src/llm-providers/anthropic/index.ts +133 -0
- package/src/llm-providers/openai/index.ts +110 -0
- package/src/llm-providers/providers.spec.ts +472 -0
- package/src/llm-providers/shared.ts +170 -0
- package/src/theme/common/ai.css +430 -0
- package/src/theme/common/code-mirror.css +14 -0
- package/src/theme/common/diff.css +196 -0
- package/src/theme/common/style.css +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/core/slice.ts","../../../../src/icons/align-center.ts","../../../../src/icons/align-left.ts","../../../../src/icons/align-right.ts","../../../../src/icons/drag-handle.ts","../../../../src/icons/plus.ts","../../../../src/icons/remove.ts","../../../../src/feature/index.ts","../../../../src/feature/table/index.ts"],"sourcesContent":["import { createSlice, type Ctx } from '@milkdown/kit/ctx'\n\nimport type { CrepeFeature } from '../feature'\nimport type { CrepeBuilder } from './builder'\n\n/// @internal\n/// The feature flags context.\n/// ⚠️ Most of the time, you should use `useCrepeFeatures` to get the features.\nexport const FeaturesCtx = createSlice([] as CrepeFeature[], 'FeaturesCtx')\n\n/// @internal\n/// The crepe editor context.\n/// ⚠️ Most of the time, you should use `useCrepe` to get the crepe editor instance.\nexport const CrepeCtx = createSlice({} as CrepeBuilder, 'CrepeCtx')\n\n/// The crepe editor context.\n/// You can use this context to access the crepe editor instance within Milkdown plugins.\n/// ```ts\n/// import { crepeCtx } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// return () => {\n/// const crepe = useCrepe(ctx)\n/// crepe.setReadonly(true)\n/// }\n/// }\n/// ```\nexport function useCrepe(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.get<CrepeBuilder, 'CrepeCtx'>('CrepeCtx')\n}\n\n/// Check the enabled FeatureFlags\n/// ```ts\n/// import { useCrepeFeatures } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// const features = useCrepeFeatures(ctx)\n/// if (features.get().includes(CrepeFeature.CodeMirror)) {\n/// // Do something with CodeMirror\n/// }\n/// }\nexport function useCrepeFeatures(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.use<CrepeFeature[], 'FeaturesCtx'>('FeaturesCtx')\n}\n\n/// @internal\nexport function crepeFeatureConfig(feature: CrepeFeature) {\n return (ctx: Ctx) => {\n useCrepeFeatures(ctx).update((features) => {\n if (features.includes(feature)) {\n return features\n }\n return [...features, feature]\n })\n }\n}\n","export const alignCenterIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM8.25 16.625C8.0375 16.625 7.85942 16.5531 7.71575 16.4093C7.57192 16.2654 7.5 16.0872 7.5 15.8748C7.5 15.6621 7.57192 15.484 7.71575 15.3405C7.85942 15.1968 8.0375 15.125 8.25 15.125H15.75C15.9625 15.125 16.1406 15.1969 16.2843 15.3408C16.4281 15.4846 16.5 15.6628 16.5 15.8753C16.5 16.0879 16.4281 16.266 16.2843 16.4095C16.1406 16.5532 15.9625 16.625 15.75 16.625H8.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM8.25 8.875C8.0375 8.875 7.85942 8.80308 7.71575 8.65925C7.57192 8.51542 7.5 8.33725 7.5 8.12475C7.5 7.91208 7.57192 7.734 7.71575 7.5905C7.85942 7.44683 8.0375 7.375 8.25 7.375H15.75C15.9625 7.375 16.1406 7.44692 16.2843 7.59075C16.4281 7.73458 16.5 7.91275 16.5 8.12525C16.5 8.33792 16.4281 8.516 16.2843 8.6595C16.1406 8.80317 15.9625 8.875 15.75 8.875H8.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignLeftIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM4.25 16.625C4.0375 16.625 3.85942 16.5531 3.71575 16.4093C3.57192 16.2654 3.5 16.0872 3.5 15.8748C3.5 15.6621 3.57192 15.484 3.71575 15.3405C3.85942 15.1968 4.0375 15.125 4.25 15.125H13.75C13.9625 15.125 14.1406 15.1969 14.2843 15.3408C14.4281 15.4846 14.5 15.6628 14.5 15.8753C14.5 16.0879 14.4281 16.266 14.2843 16.4095C14.1406 16.5532 13.9625 16.625 13.75 16.625H4.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM4.25 8.875C4.0375 8.875 3.85942 8.80308 3.71575 8.65925C3.57192 8.51542 3.5 8.33725 3.5 8.12475C3.5 7.91208 3.57192 7.734 3.71575 7.5905C3.85942 7.44683 4.0375 7.375 4.25 7.375H13.75C13.9625 7.375 14.1406 7.44692 14.2843 7.59075C14.4281 7.73458 14.5 7.91275 14.5 8.12525C14.5 8.33792 14.4281 8.516 14.2843 8.6595C14.1406 8.80317 13.9625 8.875 13.75 8.875H4.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignRightIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25ZM10.25 8.875C10.0375 8.875 9.85942 8.80308 9.71575 8.65925C9.57192 8.51542 9.5 8.33725 9.5 8.12475C9.5 7.91208 9.57192 7.734 9.71575 7.5905C9.85942 7.44683 10.0375 7.375 10.25 7.375H19.75C19.9625 7.375 20.1406 7.44692 20.2843 7.59075C20.4281 7.73458 20.5 7.91275 20.5 8.12525C20.5 8.33792 20.4281 8.516 20.2843 8.6595C20.1406 8.80317 19.9625 8.875 19.75 8.875H10.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM10.25 16.625C10.0375 16.625 9.85942 16.5531 9.71575 16.4093C9.57192 16.2654 9.5 16.0872 9.5 15.8748C9.5 15.6621 9.57192 15.484 9.71575 15.3405C9.85942 15.1968 10.0375 15.125 10.25 15.125H19.75C19.9625 15.125 20.1406 15.1969 20.2843 15.3408C20.4281 15.4846 20.5 15.6628 20.5 15.8753C20.5 16.0879 20.4281 16.266 20.2843 16.4095C20.1406 16.5532 19.9625 16.625 19.75 16.625H10.25ZM4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25Z\"\n />\n </svg>\n`\n","export const dragHandleIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n >\n <path\n d=\"M3.5 9.83366C3.35833 9.83366 3.23961 9.78571 3.14383 9.68983C3.04794 9.59394 3 9.47516 3 9.33349C3 9.19171 3.04794 9.07299 3.14383 8.97733C3.23961 8.88155 3.35833 8.83366 3.5 8.83366H12.5C12.6417 8.83366 12.7604 8.8816 12.8562 8.97749C12.9521 9.07338 13 9.19216 13 9.33383C13 9.4756 12.9521 9.59433 12.8562 9.68999C12.7604 9.78577 12.6417 9.83366 12.5 9.83366H3.5ZM3.5 7.16699C3.35833 7.16699 3.23961 7.11905 3.14383 7.02316C3.04794 6.92727 3 6.80849 3 6.66683C3 6.52505 3.04794 6.40633 3.14383 6.31066C3.23961 6.21488 3.35833 6.16699 3.5 6.16699H12.5C12.6417 6.16699 12.7604 6.21494 12.8562 6.31083C12.9521 6.40671 13 6.52549 13 6.66716C13 6.80894 12.9521 6.92766 12.8562 7.02333C12.7604 7.1191 12.6417 7.16699 12.5 7.16699H3.5Z\"\n />\n </svg>\n`\n","export const plusIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <g clip-path=\"url(#clip0_971_7676)\">\n <path\n d=\"M18 13H13V18C13 18.55 12.55 19 12 19C11.45 19 11 18.55 11 18V13H6C5.45 13 5 12.55 5 12C5 11.45 5.45 11 6 11H11V6C11 5.45 11.45 5 12 5C12.55 5 13 5.45 13 6V11H18C18.55 11 19 11.45 19 12C19 12.55 18.55 13 18 13Z\"\n />\n </g>\n <defs>\n <clipPath id=\"clip0_971_7676\">\n <rect width=\"24\" height=\"24\" />\n </clipPath>\n </defs>\n </svg>\n`\n","export const removeIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z\"\n />\n </svg>\n`\n","import type { BlockEditFeatureConfig } from './block-edit'\nimport type { CodeMirrorFeatureConfig } from './code-mirror'\nimport type { CursorFeatureConfig } from './cursor'\nimport type { ImageBlockFeatureConfig } from './image-block'\nimport type { LatexFeatureConfig } from './latex'\nimport type { LinkTooltipFeatureConfig } from './link-tooltip'\nimport type { ListItemFeatureConfig } from './list-item'\nimport type { PlaceholderFeatureConfig } from './placeholder'\nimport type { TableFeatureConfig } from './table'\nimport type { ToolbarFeatureConfig } from './toolbar'\nimport type { TopBarFeatureConfig } from './top-bar'\n\n/// The crepe editor feature flags.\n/// Every feature is enabled by default.\n/// Every feature is a string literal type.\nexport enum CrepeFeature {\n /// Syntax highlighting and editing for code blocks with language support, theme customization, and preview capabilities.\n CodeMirror = 'code-mirror',\n\n /// Support for bullet lists, ordered lists, and todo lists with customizable icons and formatting.\n ListItem = 'list-item',\n\n /// Enhanced link editing and preview with customizable tooltips, edit/remove actions, and copy functionality.\n LinkTooltip = 'link-tooltip',\n\n /// Enhanced cursor experience with drop cursor and gap cursor for better content placement.\n Cursor = 'cursor',\n\n /// Image upload and management with resizing, captions, and support for both inline and block images.\n ImageBlock = 'image-block',\n\n /// Drag-and-drop block management and slash commands for quick content insertion and organization.\n BlockEdit = 'block-edit',\n\n /// Formatting toolbar for selected text with customizable icons and actions.\n Toolbar = 'toolbar',\n\n /// Document or block level placeholders to guide users when content is empty.\n Placeholder = 'placeholder',\n\n /// Full-featured table editing with row/column management, alignment options, and drag-and-drop functionality.\n Table = 'table',\n\n /// Mathematical formula support with both inline and block math rendering using KaTeX.\n Latex = 'latex',\n\n /// Fixed top toolbar with heading selector, formatting buttons, insert actions, and block commands.\n TopBar = 'top-bar',\n}\n\nexport interface CrepeFeatureConfig {\n [CrepeFeature.Cursor]?: CursorFeatureConfig\n [CrepeFeature.ListItem]?: ListItemFeatureConfig\n [CrepeFeature.LinkTooltip]?: LinkTooltipFeatureConfig\n [CrepeFeature.ImageBlock]?: ImageBlockFeatureConfig\n [CrepeFeature.BlockEdit]?: BlockEditFeatureConfig\n [CrepeFeature.Placeholder]?: PlaceholderFeatureConfig\n [CrepeFeature.Toolbar]?: ToolbarFeatureConfig\n [CrepeFeature.CodeMirror]?: CodeMirrorFeatureConfig\n [CrepeFeature.Table]?: TableFeatureConfig\n [CrepeFeature.Latex]?: LatexFeatureConfig\n [CrepeFeature.TopBar]?: TopBarFeatureConfig\n}\n\nexport const defaultFeatures: Record<CrepeFeature, boolean> = {\n [CrepeFeature.Cursor]: true,\n [CrepeFeature.ListItem]: true,\n [CrepeFeature.LinkTooltip]: true,\n [CrepeFeature.ImageBlock]: true,\n [CrepeFeature.BlockEdit]: true,\n [CrepeFeature.Placeholder]: true,\n [CrepeFeature.Toolbar]: true,\n [CrepeFeature.CodeMirror]: true,\n [CrepeFeature.Table]: true,\n [CrepeFeature.Latex]: true,\n [CrepeFeature.TopBar]: false,\n}\n","import {\n tableBlock,\n tableBlockConfig,\n} from '@milkdown/kit/component/table-block'\n\nimport type { DefineFeature } from '../shared'\n\nimport { crepeFeatureConfig } from '../../core/slice'\nimport {\n alignCenterIcon,\n alignLeftIcon,\n alignRightIcon,\n dragHandleIcon,\n plusIcon,\n removeIcon,\n} from '../../icons'\nimport { CrepeFeature } from '../index'\n\ninterface TableConfig {\n addRowIcon: string\n addColIcon: string\n deleteRowIcon: string\n deleteColIcon: string\n alignLeftIcon: string\n alignCenterIcon: string\n alignRightIcon: string\n colDragHandleIcon: string\n rowDragHandleIcon: string\n}\n\nexport type TableFeatureConfig = Partial<TableConfig>\n\nexport const table: DefineFeature<TableFeatureConfig> = (editor, config) => {\n editor\n .config(crepeFeatureConfig(CrepeFeature.Table))\n .config((ctx) => {\n ctx.update(tableBlockConfig.key, (defaultConfig) => ({\n ...defaultConfig,\n renderButton: (renderType) => {\n switch (renderType) {\n case 'add_row':\n return config?.addRowIcon ?? plusIcon\n case 'add_col':\n return config?.addColIcon ?? plusIcon\n case 'delete_row':\n return config?.deleteRowIcon ?? removeIcon\n case 'delete_col':\n return config?.deleteColIcon ?? removeIcon\n case 'align_col_left':\n return config?.alignLeftIcon ?? alignLeftIcon\n case 'align_col_center':\n return config?.alignCenterIcon ?? alignCenterIcon\n case 'align_col_right':\n return config?.alignRightIcon ?? alignRightIcon\n case 'col_drag_handle':\n return config?.colDragHandleIcon ?? dragHandleIcon\n case 'row_drag_handle':\n return config?.rowDragHandleIcon ?? dragHandleIcon\n }\n },\n }))\n })\n .use(tableBlock)\n}\n"],"names":["createSlice","CrepeFeature","tableBlockConfig","tableBlock"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/core/slice.ts","../../../../src/icons/align-center.ts","../../../../src/icons/align-left.ts","../../../../src/icons/align-right.ts","../../../../src/icons/drag-handle.ts","../../../../src/icons/plus.ts","../../../../src/icons/remove.ts","../../../../src/feature/index.ts","../../../../src/feature/table/index.ts"],"sourcesContent":["import { createSlice, type Ctx } from '@milkdown/kit/ctx'\n\nimport type { CrepeFeature } from '../feature'\nimport type { CrepeBuilder } from './builder'\n\n/// @internal\n/// The feature flags context.\n/// ⚠️ Most of the time, you should use `useCrepeFeatures` to get the features.\nexport const FeaturesCtx = createSlice([] as CrepeFeature[], 'FeaturesCtx')\n\n/// @internal\n/// The crepe editor context.\n/// ⚠️ Most of the time, you should use `useCrepe` to get the crepe editor instance.\nexport const CrepeCtx = createSlice({} as CrepeBuilder, 'CrepeCtx')\n\n/// The crepe editor context.\n/// You can use this context to access the crepe editor instance within Milkdown plugins.\n/// ```ts\n/// import { crepeCtx } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// return () => {\n/// const crepe = useCrepe(ctx)\n/// crepe.setReadonly(true)\n/// }\n/// }\n/// ```\nexport function useCrepe(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.get<CrepeBuilder, 'CrepeCtx'>('CrepeCtx')\n}\n\n/// Check the enabled FeatureFlags\n/// ```ts\n/// import { useCrepeFeatures } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// const features = useCrepeFeatures(ctx)\n/// if (features.get().includes(CrepeFeature.CodeMirror)) {\n/// // Do something with CodeMirror\n/// }\n/// }\nexport function useCrepeFeatures(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.use<CrepeFeature[], 'FeaturesCtx'>('FeaturesCtx')\n}\n\n/// @internal\nexport function crepeFeatureConfig(feature: CrepeFeature) {\n return (ctx: Ctx) => {\n useCrepeFeatures(ctx).update((features) => {\n if (features.includes(feature)) {\n return features\n }\n return [...features, feature]\n })\n }\n}\n","export const alignCenterIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM8.25 16.625C8.0375 16.625 7.85942 16.5531 7.71575 16.4093C7.57192 16.2654 7.5 16.0872 7.5 15.8748C7.5 15.6621 7.57192 15.484 7.71575 15.3405C7.85942 15.1968 8.0375 15.125 8.25 15.125H15.75C15.9625 15.125 16.1406 15.1969 16.2843 15.3408C16.4281 15.4846 16.5 15.6628 16.5 15.8753C16.5 16.0879 16.4281 16.266 16.2843 16.4095C16.1406 16.5532 15.9625 16.625 15.75 16.625H8.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM8.25 8.875C8.0375 8.875 7.85942 8.80308 7.71575 8.65925C7.57192 8.51542 7.5 8.33725 7.5 8.12475C7.5 7.91208 7.57192 7.734 7.71575 7.5905C7.85942 7.44683 8.0375 7.375 8.25 7.375H15.75C15.9625 7.375 16.1406 7.44692 16.2843 7.59075C16.4281 7.73458 16.5 7.91275 16.5 8.12525C16.5 8.33792 16.4281 8.516 16.2843 8.6595C16.1406 8.80317 15.9625 8.875 15.75 8.875H8.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignLeftIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM4.25 16.625C4.0375 16.625 3.85942 16.5531 3.71575 16.4093C3.57192 16.2654 3.5 16.0872 3.5 15.8748C3.5 15.6621 3.57192 15.484 3.71575 15.3405C3.85942 15.1968 4.0375 15.125 4.25 15.125H13.75C13.9625 15.125 14.1406 15.1969 14.2843 15.3408C14.4281 15.4846 14.5 15.6628 14.5 15.8753C14.5 16.0879 14.4281 16.266 14.2843 16.4095C14.1406 16.5532 13.9625 16.625 13.75 16.625H4.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM4.25 8.875C4.0375 8.875 3.85942 8.80308 3.71575 8.65925C3.57192 8.51542 3.5 8.33725 3.5 8.12475C3.5 7.91208 3.57192 7.734 3.71575 7.5905C3.85942 7.44683 4.0375 7.375 4.25 7.375H13.75C13.9625 7.375 14.1406 7.44692 14.2843 7.59075C14.4281 7.73458 14.5 7.91275 14.5 8.12525C14.5 8.33792 14.4281 8.516 14.2843 8.6595C14.1406 8.80317 13.9625 8.875 13.75 8.875H4.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignRightIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25ZM10.25 8.875C10.0375 8.875 9.85942 8.80308 9.71575 8.65925C9.57192 8.51542 9.5 8.33725 9.5 8.12475C9.5 7.91208 9.57192 7.734 9.71575 7.5905C9.85942 7.44683 10.0375 7.375 10.25 7.375H19.75C19.9625 7.375 20.1406 7.44692 20.2843 7.59075C20.4281 7.73458 20.5 7.91275 20.5 8.12525C20.5 8.33792 20.4281 8.516 20.2843 8.6595C20.1406 8.80317 19.9625 8.875 19.75 8.875H10.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM10.25 16.625C10.0375 16.625 9.85942 16.5531 9.71575 16.4093C9.57192 16.2654 9.5 16.0872 9.5 15.8748C9.5 15.6621 9.57192 15.484 9.71575 15.3405C9.85942 15.1968 10.0375 15.125 10.25 15.125H19.75C19.9625 15.125 20.1406 15.1969 20.2843 15.3408C20.4281 15.4846 20.5 15.6628 20.5 15.8753C20.5 16.0879 20.4281 16.266 20.2843 16.4095C20.1406 16.5532 19.9625 16.625 19.75 16.625H10.25ZM4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25Z\"\n />\n </svg>\n`\n","export const dragHandleIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n >\n <path\n d=\"M3.5 9.83366C3.35833 9.83366 3.23961 9.78571 3.14383 9.68983C3.04794 9.59394 3 9.47516 3 9.33349C3 9.19171 3.04794 9.07299 3.14383 8.97733C3.23961 8.88155 3.35833 8.83366 3.5 8.83366H12.5C12.6417 8.83366 12.7604 8.8816 12.8562 8.97749C12.9521 9.07338 13 9.19216 13 9.33383C13 9.4756 12.9521 9.59433 12.8562 9.68999C12.7604 9.78577 12.6417 9.83366 12.5 9.83366H3.5ZM3.5 7.16699C3.35833 7.16699 3.23961 7.11905 3.14383 7.02316C3.04794 6.92727 3 6.80849 3 6.66683C3 6.52505 3.04794 6.40633 3.14383 6.31066C3.23961 6.21488 3.35833 6.16699 3.5 6.16699H12.5C12.6417 6.16699 12.7604 6.21494 12.8562 6.31083C12.9521 6.40671 13 6.52549 13 6.66716C13 6.80894 12.9521 6.92766 12.8562 7.02333C12.7604 7.1191 12.6417 7.16699 12.5 7.16699H3.5Z\"\n />\n </svg>\n`\n","export const plusIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <g clip-path=\"url(#clip0_971_7676)\">\n <path\n d=\"M18 13H13V18C13 18.55 12.55 19 12 19C11.45 19 11 18.55 11 18V13H6C5.45 13 5 12.55 5 12C5 11.45 5.45 11 6 11H11V6C11 5.45 11.45 5 12 5C12.55 5 13 5.45 13 6V11H18C18.55 11 19 11.45 19 12C19 12.55 18.55 13 18 13Z\"\n />\n </g>\n <defs>\n <clipPath id=\"clip0_971_7676\">\n <rect width=\"24\" height=\"24\" />\n </clipPath>\n </defs>\n </svg>\n`\n","export const removeIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z\"\n />\n </svg>\n`\n","import type { AIFeatureConfig } from './ai'\nimport type { BlockEditFeatureConfig } from './block-edit'\nimport type { CodeMirrorFeatureConfig } from './code-mirror'\nimport type { CursorFeatureConfig } from './cursor'\nimport type { ImageBlockFeatureConfig } from './image-block'\nimport type { LatexFeatureConfig } from './latex'\nimport type { LinkTooltipFeatureConfig } from './link-tooltip'\nimport type { ListItemFeatureConfig } from './list-item'\nimport type { PlaceholderFeatureConfig } from './placeholder'\nimport type { TableFeatureConfig } from './table'\nimport type { ToolbarFeatureConfig } from './toolbar'\nimport type { TopBarFeatureConfig } from './top-bar'\n\n/// The crepe editor feature flags.\n/// Most features are enabled by default; `TopBar` and `AI` are opt-in.\n/// See `defaultFeatures` for the per-flag default.\nexport enum CrepeFeature {\n /// Syntax highlighting and editing for code blocks with language support, theme customization, and preview capabilities.\n CodeMirror = 'code-mirror',\n\n /// Support for bullet lists, ordered lists, and todo lists with customizable icons and formatting.\n ListItem = 'list-item',\n\n /// Enhanced link editing and preview with customizable tooltips, edit/remove actions, and copy functionality.\n LinkTooltip = 'link-tooltip',\n\n /// Enhanced cursor experience with drop cursor and gap cursor for better content placement.\n Cursor = 'cursor',\n\n /// Image upload and management with resizing, captions, and support for both inline and block images.\n ImageBlock = 'image-block',\n\n /// Drag-and-drop block management and slash commands for quick content insertion and organization.\n BlockEdit = 'block-edit',\n\n /// Formatting toolbar for selected text with customizable icons and actions.\n Toolbar = 'toolbar',\n\n /// Document or block level placeholders to guide users when content is empty.\n Placeholder = 'placeholder',\n\n /// Full-featured table editing with row/column management, alignment options, and drag-and-drop functionality.\n Table = 'table',\n\n /// Mathematical formula support with both inline and block math rendering using KaTeX.\n Latex = 'latex',\n\n /// Fixed top toolbar with heading selector, formatting buttons, insert actions, and block commands.\n TopBar = 'top-bar',\n\n /// AI-assisted editing: streaming input, diff review, and provider integration.\n AI = 'ai',\n}\n\nexport interface CrepeFeatureConfig {\n [CrepeFeature.Cursor]?: CursorFeatureConfig\n [CrepeFeature.ListItem]?: ListItemFeatureConfig\n [CrepeFeature.LinkTooltip]?: LinkTooltipFeatureConfig\n [CrepeFeature.ImageBlock]?: ImageBlockFeatureConfig\n [CrepeFeature.BlockEdit]?: BlockEditFeatureConfig\n [CrepeFeature.Placeholder]?: PlaceholderFeatureConfig\n [CrepeFeature.Toolbar]?: ToolbarFeatureConfig\n [CrepeFeature.CodeMirror]?: CodeMirrorFeatureConfig\n [CrepeFeature.Table]?: TableFeatureConfig\n [CrepeFeature.Latex]?: LatexFeatureConfig\n [CrepeFeature.TopBar]?: TopBarFeatureConfig\n [CrepeFeature.AI]?: AIFeatureConfig\n}\n\nexport const defaultFeatures: Record<CrepeFeature, boolean> = {\n [CrepeFeature.Cursor]: true,\n [CrepeFeature.ListItem]: true,\n [CrepeFeature.LinkTooltip]: true,\n [CrepeFeature.ImageBlock]: true,\n [CrepeFeature.BlockEdit]: true,\n [CrepeFeature.Placeholder]: true,\n [CrepeFeature.Toolbar]: true,\n [CrepeFeature.CodeMirror]: true,\n [CrepeFeature.Table]: true,\n [CrepeFeature.Latex]: true,\n [CrepeFeature.TopBar]: false,\n [CrepeFeature.AI]: false,\n}\n","import {\n tableBlock,\n tableBlockConfig,\n} from '@milkdown/kit/component/table-block'\n\nimport type { DefineFeature } from '../shared'\n\nimport { crepeFeatureConfig } from '../../core/slice'\nimport {\n alignCenterIcon,\n alignLeftIcon,\n alignRightIcon,\n dragHandleIcon,\n plusIcon,\n removeIcon,\n} from '../../icons'\nimport { CrepeFeature } from '../index'\n\ninterface TableConfig {\n addRowIcon: string\n addColIcon: string\n deleteRowIcon: string\n deleteColIcon: string\n alignLeftIcon: string\n alignCenterIcon: string\n alignRightIcon: string\n colDragHandleIcon: string\n rowDragHandleIcon: string\n}\n\nexport type TableFeatureConfig = Partial<TableConfig>\n\nexport const table: DefineFeature<TableFeatureConfig> = (editor, config) => {\n editor\n .config(crepeFeatureConfig(CrepeFeature.Table))\n .config((ctx) => {\n ctx.update(tableBlockConfig.key, (defaultConfig) => ({\n ...defaultConfig,\n renderButton: (renderType) => {\n switch (renderType) {\n case 'add_row':\n return config?.addRowIcon ?? plusIcon\n case 'add_col':\n return config?.addColIcon ?? plusIcon\n case 'delete_row':\n return config?.deleteRowIcon ?? removeIcon\n case 'delete_col':\n return config?.deleteColIcon ?? removeIcon\n case 'align_col_left':\n return config?.alignLeftIcon ?? alignLeftIcon\n case 'align_col_center':\n return config?.alignCenterIcon ?? alignCenterIcon\n case 'align_col_right':\n return config?.alignRightIcon ?? alignRightIcon\n case 'col_drag_handle':\n return config?.colDragHandleIcon ?? dragHandleIcon\n case 'row_drag_handle':\n return config?.rowDragHandleIcon ?? dragHandleIcon\n }\n },\n }))\n })\n .use(tableBlock)\n}\n"],"names":["createSlice","CrepeFeature","tableBlockConfig","tableBlock"],"mappings":"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"}
|
|
@@ -10,8 +10,11 @@ var clsx = require('clsx');
|
|
|
10
10
|
var linkTooltip = require('@milkdown/kit/component/link-tooltip');
|
|
11
11
|
var commonmark = require('@milkdown/kit/preset/commonmark');
|
|
12
12
|
var gfm = require('@milkdown/kit/preset/gfm');
|
|
13
|
-
var
|
|
13
|
+
var exception = require('@milkdown/kit/exception');
|
|
14
|
+
var diff = require('@milkdown/kit/plugin/diff');
|
|
15
|
+
var streaming = require('@milkdown/kit/plugin/streaming');
|
|
14
16
|
var utils = require('@milkdown/kit/utils');
|
|
17
|
+
var prose = require('@milkdown/kit/prose');
|
|
15
18
|
var katex = require('katex');
|
|
16
19
|
|
|
17
20
|
ctx.createSlice([], "FeaturesCtx");
|
|
@@ -42,12 +45,28 @@ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
|
|
|
42
45
|
CrepeFeature2["Table"] = "table";
|
|
43
46
|
CrepeFeature2["Latex"] = "latex";
|
|
44
47
|
CrepeFeature2["TopBar"] = "top-bar";
|
|
48
|
+
CrepeFeature2["AI"] = "ai";
|
|
45
49
|
return CrepeFeature2;
|
|
46
50
|
})(CrepeFeature || {});
|
|
47
51
|
|
|
48
52
|
function keepAlive(..._args) {
|
|
49
53
|
}
|
|
50
54
|
|
|
55
|
+
const aiIcon = `
|
|
56
|
+
<svg
|
|
57
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
58
|
+
width="24"
|
|
59
|
+
height="24"
|
|
60
|
+
viewBox="0 0 24 24"
|
|
61
|
+
>
|
|
62
|
+
<path
|
|
63
|
+
fill="currentColor"
|
|
64
|
+
d="M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25zm0 14l1.25-2.75L23 19l-2.75-1.25L19 15l-1.25 2.75L15 19l2.75 1.25zM9 20l3-6.5L18 10l-6-3.5L9 0L6 6.5L0 10l6 3.5z"
|
|
65
|
+
transform="translate(3 3) scale(0.75)"
|
|
66
|
+
/>
|
|
67
|
+
</svg>
|
|
68
|
+
`;
|
|
69
|
+
|
|
51
70
|
const boldIcon = `
|
|
52
71
|
<svg
|
|
53
72
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -187,6 +206,457 @@ class GroupBuilder {
|
|
|
187
206
|
_groups = new WeakMap();
|
|
188
207
|
_getGroupInstance = new WeakMap();
|
|
189
208
|
|
|
209
|
+
function defaultBuildContext(ctx, instruction) {
|
|
210
|
+
var _a;
|
|
211
|
+
const view = ctx.get(core.editorViewCtx);
|
|
212
|
+
const serializer = ctx.get(core.serializerCtx);
|
|
213
|
+
const { state } = view;
|
|
214
|
+
const document = serializer(state.doc);
|
|
215
|
+
let selection = "";
|
|
216
|
+
if (!state.selection.empty) {
|
|
217
|
+
const { from, to } = state.selection;
|
|
218
|
+
const slice = state.doc.slice(from, to);
|
|
219
|
+
const { schema } = state.doc.type;
|
|
220
|
+
let wrapper = schema.topNodeType.createAndFill(null, slice.content);
|
|
221
|
+
if (!wrapper) {
|
|
222
|
+
const paragraph = (_a = schema.nodes.paragraph) == null ? void 0 : _a.createAndFill(
|
|
223
|
+
null,
|
|
224
|
+
slice.content
|
|
225
|
+
);
|
|
226
|
+
if (paragraph) wrapper = schema.topNodeType.createAndFill(null, paragraph);
|
|
227
|
+
}
|
|
228
|
+
selection = wrapper ? serializer(wrapper) : state.doc.textBetween(from, to);
|
|
229
|
+
}
|
|
230
|
+
return { document, selection, instruction };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const aiProviderConfig = utils.$ctx(
|
|
234
|
+
{
|
|
235
|
+
provider: void 0,
|
|
236
|
+
buildContext: void 0,
|
|
237
|
+
diffReviewOnEnd: true,
|
|
238
|
+
onError: (error) => {
|
|
239
|
+
console.error(`[milkdown/ai] [${error.code}]`, error);
|
|
240
|
+
},
|
|
241
|
+
aiIcon: void 0
|
|
242
|
+
},
|
|
243
|
+
"aiProviderConfig"
|
|
244
|
+
);
|
|
245
|
+
const aiSessionCtx = utils.$ctx(
|
|
246
|
+
{
|
|
247
|
+
abortController: null,
|
|
248
|
+
label: "",
|
|
249
|
+
lastInstruction: "",
|
|
250
|
+
lastLabel: void 0,
|
|
251
|
+
lastFrom: -1,
|
|
252
|
+
lastTo: -1,
|
|
253
|
+
diffOwnedByAI: false
|
|
254
|
+
},
|
|
255
|
+
"aiSession"
|
|
256
|
+
);
|
|
257
|
+
function emitAIError(ctx, error) {
|
|
258
|
+
const config = ctx.get(aiProviderConfig.key);
|
|
259
|
+
try {
|
|
260
|
+
config.onError(error);
|
|
261
|
+
} catch (handlerError) {
|
|
262
|
+
console.error("[milkdown/ai] onError handler failed:", handlerError);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function clearActiveSession(ctx) {
|
|
266
|
+
const current = ctx.get(aiSessionCtx.key);
|
|
267
|
+
ctx.set(aiSessionCtx.key, {
|
|
268
|
+
...current,
|
|
269
|
+
abortController: null,
|
|
270
|
+
label: ""
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async function runProvider(ctx, provider, promptContext, abortController) {
|
|
274
|
+
try {
|
|
275
|
+
const iterable = provider(promptContext, abortController.signal);
|
|
276
|
+
const commands = ctx.get(core.commandsCtx);
|
|
277
|
+
for await (const chunk of iterable) {
|
|
278
|
+
if (abortController.signal.aborted) break;
|
|
279
|
+
commands.call(streaming.pushChunkCmd.key, chunk);
|
|
280
|
+
}
|
|
281
|
+
if (abortController.signal.aborted) return;
|
|
282
|
+
const config = ctx.get(aiProviderConfig.key);
|
|
283
|
+
if (config.diffReviewOnEnd) {
|
|
284
|
+
const cur = ctx.get(aiSessionCtx.key);
|
|
285
|
+
ctx.set(aiSessionCtx.key, { ...cur, diffOwnedByAI: true });
|
|
286
|
+
}
|
|
287
|
+
const dispatched = commands.call(streaming.endStreamingCmd.key, {
|
|
288
|
+
diffReview: config.diffReviewOnEnd
|
|
289
|
+
});
|
|
290
|
+
if (config.diffReviewOnEnd && !dispatched) {
|
|
291
|
+
const cur = ctx.get(aiSessionCtx.key);
|
|
292
|
+
ctx.set(aiSessionCtx.key, { ...cur, diffOwnedByAI: false });
|
|
293
|
+
}
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (abortController.signal.aborted) return;
|
|
296
|
+
const milkdownError = exception.aiProviderError(error);
|
|
297
|
+
emitAIError(ctx, milkdownError);
|
|
298
|
+
const commands = ctx.get(core.commandsCtx);
|
|
299
|
+
commands.call(streaming.abortStreamingCmd.key, { keep: false });
|
|
300
|
+
} finally {
|
|
301
|
+
const current = ctx.get(aiSessionCtx.key);
|
|
302
|
+
if (current.abortController === abortController) {
|
|
303
|
+
clearActiveSession(ctx);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
utils.$command("RunAI", (ctx) => {
|
|
308
|
+
return (options) => (state, dispatch) => {
|
|
309
|
+
var _a, _b, _c, _d;
|
|
310
|
+
if (!(options == null ? void 0 : options.instruction)) return false;
|
|
311
|
+
const config = ctx.get(aiProviderConfig.key);
|
|
312
|
+
if (!config.provider) return false;
|
|
313
|
+
const session = ctx.get(aiSessionCtx.key);
|
|
314
|
+
if (session.abortController) return false;
|
|
315
|
+
if ((_a = streaming.streamingPluginKey.getState(state)) == null ? void 0 : _a.active) return false;
|
|
316
|
+
if ((_b = diff.diffPluginKey.getState(state)) == null ? void 0 : _b.active) return false;
|
|
317
|
+
if (!dispatch) return true;
|
|
318
|
+
const abortController = new AbortController();
|
|
319
|
+
const { from, to } = state.selection;
|
|
320
|
+
ctx.set(aiSessionCtx.key, {
|
|
321
|
+
abortController,
|
|
322
|
+
label: (_c = options.label) != null ? _c : "",
|
|
323
|
+
lastInstruction: options.instruction,
|
|
324
|
+
lastLabel: options.label,
|
|
325
|
+
lastFrom: from,
|
|
326
|
+
lastTo: to,
|
|
327
|
+
// Reset every run; only the success path that hands off to diff
|
|
328
|
+
// review flips it back on.
|
|
329
|
+
diffOwnedByAI: false
|
|
330
|
+
});
|
|
331
|
+
const commands = ctx.get(core.commandsCtx);
|
|
332
|
+
const insertAt = state.selection.empty ? "cursor" : "selection";
|
|
333
|
+
if (!commands.call(streaming.startStreamingCmd.key, { insertAt })) {
|
|
334
|
+
clearActiveSession(ctx);
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
let promptContext;
|
|
338
|
+
try {
|
|
339
|
+
const buildContext = (_d = config.buildContext) != null ? _d : defaultBuildContext;
|
|
340
|
+
promptContext = buildContext(ctx, options.instruction);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
const milkdownError = exception.aiBuildContextError(error);
|
|
343
|
+
emitAIError(ctx, milkdownError);
|
|
344
|
+
commands.call(streaming.abortStreamingCmd.key, { keep: false });
|
|
345
|
+
clearActiveSession(ctx);
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
void runProvider(ctx, config.provider, promptContext, abortController);
|
|
349
|
+
return true;
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
utils.$command("AbortAI", (ctx) => {
|
|
353
|
+
return (options) => (state, dispatch) => {
|
|
354
|
+
var _a;
|
|
355
|
+
const session = ctx.get(aiSessionCtx.key);
|
|
356
|
+
if (!dispatch) return !!session.abortController;
|
|
357
|
+
if (!session.abortController) return false;
|
|
358
|
+
session.abortController.abort();
|
|
359
|
+
clearActiveSession(ctx);
|
|
360
|
+
if ((_a = streaming.streamingPluginKey.getState(state)) == null ? void 0 : _a.active) {
|
|
361
|
+
const commands = ctx.get(core.commandsCtx);
|
|
362
|
+
commands.call(streaming.abortStreamingCmd.key, options);
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
keepAlive(vue.h);
|
|
369
|
+
function renderHighlighted(label, query) {
|
|
370
|
+
const q = query.trim();
|
|
371
|
+
if (!q) return [label];
|
|
372
|
+
const lower = label.toLowerCase();
|
|
373
|
+
const lq = q.toLowerCase();
|
|
374
|
+
const idx = lower.indexOf(lq);
|
|
375
|
+
if (idx === -1) return [label];
|
|
376
|
+
return [
|
|
377
|
+
label.slice(0, idx),
|
|
378
|
+
vue.h("mark", null, label.slice(idx, idx + q.length)),
|
|
379
|
+
label.slice(idx + q.length)
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
vue.defineComponent({
|
|
383
|
+
props: {
|
|
384
|
+
placeholder: { type: Object, required: true },
|
|
385
|
+
resetSignal: { type: Object, required: true },
|
|
386
|
+
suggestions: { type: Object, required: true },
|
|
387
|
+
chrome: { type: Object, required: true },
|
|
388
|
+
onConfirm: { type: Function, required: true },
|
|
389
|
+
onCancel: { type: Function, required: true }
|
|
390
|
+
},
|
|
391
|
+
setup({
|
|
392
|
+
placeholder,
|
|
393
|
+
resetSignal,
|
|
394
|
+
suggestions,
|
|
395
|
+
chrome,
|
|
396
|
+
onConfirm,
|
|
397
|
+
onCancel
|
|
398
|
+
}) {
|
|
399
|
+
const inputValue = vue.ref("");
|
|
400
|
+
const view = vue.ref({ kind: "main" });
|
|
401
|
+
const selectedIndex = vue.ref(0);
|
|
402
|
+
const inputRef = vue.ref(null);
|
|
403
|
+
const listRef = vue.ref(null);
|
|
404
|
+
const listboxId = `ai-instruction-list-${Math.random().toString(36).slice(2, 9)}`;
|
|
405
|
+
const optionId = (idx) => `${listboxId}-opt-${idx}`;
|
|
406
|
+
vue.watch(resetSignal, () => {
|
|
407
|
+
inputValue.value = "";
|
|
408
|
+
view.value = { kind: "main" };
|
|
409
|
+
selectedIndex.value = 0;
|
|
410
|
+
});
|
|
411
|
+
const allItems = vue.computed(() => {
|
|
412
|
+
if (view.value.kind === "submenu") {
|
|
413
|
+
const submenu = suggestions.submenus[view.value.id];
|
|
414
|
+
if (!submenu) return [];
|
|
415
|
+
return submenu.items.map(({ id, item }) => ({
|
|
416
|
+
id,
|
|
417
|
+
icon: item.icon,
|
|
418
|
+
label: item.label,
|
|
419
|
+
hasSubmenu: false,
|
|
420
|
+
prompt: { text: item.prompt, streamingLabel: item.streamingLabel }
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
return suggestions.main.map((entry) => {
|
|
424
|
+
if (entry.kind === "item") {
|
|
425
|
+
return {
|
|
426
|
+
id: entry.id,
|
|
427
|
+
icon: entry.item.icon,
|
|
428
|
+
label: entry.item.label,
|
|
429
|
+
hasSubmenu: false,
|
|
430
|
+
prompt: {
|
|
431
|
+
text: entry.item.prompt,
|
|
432
|
+
streamingLabel: entry.item.streamingLabel
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
id: entry.id,
|
|
438
|
+
icon: entry.def.icon,
|
|
439
|
+
label: entry.def.label,
|
|
440
|
+
hasSubmenu: true
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
const currentSubmenuDef = vue.computed(() => {
|
|
445
|
+
var _a, _b;
|
|
446
|
+
if (view.value.kind !== "submenu") return null;
|
|
447
|
+
return (_b = (_a = suggestions.submenus[view.value.id]) == null ? void 0 : _a.def) != null ? _b : null;
|
|
448
|
+
});
|
|
449
|
+
const filteredItems = vue.computed(() => {
|
|
450
|
+
const q = inputValue.value.trim().toLowerCase();
|
|
451
|
+
if (!q) return allItems.value;
|
|
452
|
+
return allItems.value.filter(
|
|
453
|
+
(item) => item.label.toLowerCase().includes(q)
|
|
454
|
+
);
|
|
455
|
+
});
|
|
456
|
+
const showSendAsPrompt = vue.computed(() => inputValue.value.trim().length > 0);
|
|
457
|
+
const totalItems = vue.computed(
|
|
458
|
+
() => filteredItems.value.length + (showSendAsPrompt.value ? 1 : 0)
|
|
459
|
+
);
|
|
460
|
+
vue.watch([filteredItems, view, showSendAsPrompt], () => {
|
|
461
|
+
selectedIndex.value = showSendAsPrompt.value ? filteredItems.value.length : 0;
|
|
462
|
+
});
|
|
463
|
+
const focusInput = () => {
|
|
464
|
+
void vue.nextTick(() => {
|
|
465
|
+
var _a;
|
|
466
|
+
return (_a = inputRef.value) == null ? void 0 : _a.focus();
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
const enterSubmenu = (id) => {
|
|
470
|
+
view.value = { kind: "submenu", id };
|
|
471
|
+
inputValue.value = "";
|
|
472
|
+
selectedIndex.value = 0;
|
|
473
|
+
focusInput();
|
|
474
|
+
};
|
|
475
|
+
const exitSubmenu = () => {
|
|
476
|
+
view.value = { kind: "main" };
|
|
477
|
+
inputValue.value = "";
|
|
478
|
+
selectedIndex.value = 0;
|
|
479
|
+
focusInput();
|
|
480
|
+
};
|
|
481
|
+
const runItem = (item) => {
|
|
482
|
+
if (item.hasSubmenu) {
|
|
483
|
+
enterSubmenu(item.id);
|
|
484
|
+
} else if (item.prompt) {
|
|
485
|
+
onConfirm(item.prompt.text, item.prompt.streamingLabel);
|
|
486
|
+
inputValue.value = "";
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
const submitRaw = () => {
|
|
490
|
+
const v = inputValue.value.trim();
|
|
491
|
+
if (!v) return;
|
|
492
|
+
onConfirm(v);
|
|
493
|
+
inputValue.value = "";
|
|
494
|
+
};
|
|
495
|
+
const onSelectCurrent = () => {
|
|
496
|
+
const idx = selectedIndex.value;
|
|
497
|
+
const items = filteredItems.value;
|
|
498
|
+
if (idx < items.length) {
|
|
499
|
+
runItem(items[idx]);
|
|
500
|
+
} else if (showSendAsPrompt.value) {
|
|
501
|
+
submitRaw();
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
const scrollToSelected = () => {
|
|
505
|
+
void vue.nextTick(() => {
|
|
506
|
+
const list = listRef.value;
|
|
507
|
+
if (!list) return;
|
|
508
|
+
const el = list.querySelector(
|
|
509
|
+
`[data-index="${selectedIndex.value}"]`
|
|
510
|
+
);
|
|
511
|
+
el == null ? void 0 : el.scrollIntoView({ block: "nearest" });
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
const onKeydown = (e) => {
|
|
515
|
+
e.stopPropagation();
|
|
516
|
+
if (e.key === "ArrowDown") {
|
|
517
|
+
e.preventDefault();
|
|
518
|
+
if (totalItems.value === 0) return;
|
|
519
|
+
selectedIndex.value = (selectedIndex.value + 1) % totalItems.value;
|
|
520
|
+
scrollToSelected();
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (e.key === "ArrowUp") {
|
|
524
|
+
e.preventDefault();
|
|
525
|
+
if (totalItems.value === 0) return;
|
|
526
|
+
selectedIndex.value = (selectedIndex.value - 1 + totalItems.value) % totalItems.value;
|
|
527
|
+
scrollToSelected();
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (e.key === "Enter") {
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
onSelectCurrent();
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (e.key === "Escape") {
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
if (view.value.kind === "submenu") exitSubmenu();
|
|
538
|
+
else onCancel();
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (e.key === "Backspace" && inputValue.value === "" && view.value.kind === "submenu") {
|
|
542
|
+
e.preventDefault();
|
|
543
|
+
exitSubmenu();
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const onItemPointerDown = (e) => {
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
};
|
|
549
|
+
return () => {
|
|
550
|
+
const items = filteredItems.value;
|
|
551
|
+
const showPrompt = showSendAsPrompt.value;
|
|
552
|
+
const submenuDef = currentSubmenuDef.value;
|
|
553
|
+
return /* @__PURE__ */ vue.h("div", { class: "ai-instruction" }, /* @__PURE__ */ vue.h("div", { class: "ai-instruction-input" }, /* @__PURE__ */ vue.h("span", { class: "ai-instruction-input-prefix" }, /* @__PURE__ */ vue.h(component.Icon, { icon: chrome.aiIcon })), /* @__PURE__ */ vue.h(
|
|
554
|
+
"input",
|
|
555
|
+
{
|
|
556
|
+
ref: inputRef,
|
|
557
|
+
class: "ai-instruction-input-field",
|
|
558
|
+
role: "combobox",
|
|
559
|
+
"aria-expanded": "true",
|
|
560
|
+
"aria-autocomplete": "list",
|
|
561
|
+
"aria-controls": listboxId,
|
|
562
|
+
"aria-activedescendant": totalItems.value > 0 ? optionId(selectedIndex.value) : void 0,
|
|
563
|
+
placeholder: submenuDef ? submenuDef.searchPlaceholder : placeholder.value,
|
|
564
|
+
value: inputValue.value,
|
|
565
|
+
onInput: (e) => {
|
|
566
|
+
inputValue.value = e.target.value;
|
|
567
|
+
},
|
|
568
|
+
onKeydown
|
|
569
|
+
}
|
|
570
|
+
), /* @__PURE__ */ vue.h(
|
|
571
|
+
"button",
|
|
572
|
+
{
|
|
573
|
+
type: "button",
|
|
574
|
+
class: "ai-instruction-submit",
|
|
575
|
+
"aria-label": chrome.submitButtonLabel,
|
|
576
|
+
disabled: !showPrompt,
|
|
577
|
+
onMousedown: onItemPointerDown,
|
|
578
|
+
onClick: submitRaw
|
|
579
|
+
},
|
|
580
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: chrome.sendIcon })
|
|
581
|
+
)), /* @__PURE__ */ vue.h(
|
|
582
|
+
"div",
|
|
583
|
+
{
|
|
584
|
+
class: "ai-instruction-list",
|
|
585
|
+
ref: listRef,
|
|
586
|
+
id: listboxId,
|
|
587
|
+
role: "listbox",
|
|
588
|
+
"aria-label": chrome.listboxLabel
|
|
589
|
+
},
|
|
590
|
+
submenuDef && /* @__PURE__ */ vue.h(
|
|
591
|
+
"button",
|
|
592
|
+
{
|
|
593
|
+
type: "button",
|
|
594
|
+
class: "ai-instruction-back",
|
|
595
|
+
onMousedown: onItemPointerDown,
|
|
596
|
+
onClick: exitSubmenu
|
|
597
|
+
},
|
|
598
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-back-icon", "aria-hidden": "true" }, /* @__PURE__ */ vue.h(component.Icon, { icon: chrome.chevronLeftIcon })),
|
|
599
|
+
/* @__PURE__ */ vue.h("span", null, submenuDef.title)
|
|
600
|
+
),
|
|
601
|
+
items.length > 0 && /* @__PURE__ */ vue.h("div", { class: "ai-instruction-section" }, /* @__PURE__ */ vue.h("div", { class: "ai-instruction-section-header" }, chrome.suggestionsHeaderLabel), items.map((item, idx) => /* @__PURE__ */ vue.h(
|
|
602
|
+
"div",
|
|
603
|
+
{
|
|
604
|
+
key: item.id,
|
|
605
|
+
id: optionId(idx),
|
|
606
|
+
"data-index": idx,
|
|
607
|
+
role: "option",
|
|
608
|
+
"aria-selected": idx === selectedIndex.value,
|
|
609
|
+
class: [
|
|
610
|
+
"ai-instruction-item",
|
|
611
|
+
idx === selectedIndex.value ? "active" : ""
|
|
612
|
+
],
|
|
613
|
+
onMousedown: onItemPointerDown,
|
|
614
|
+
onClick: () => runItem(item),
|
|
615
|
+
onPointerenter: () => {
|
|
616
|
+
selectedIndex.value = idx;
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-icon" }, /* @__PURE__ */ vue.h(component.Icon, { icon: item.icon })),
|
|
620
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-label" }, renderHighlighted(item.label, inputValue.value)),
|
|
621
|
+
item.hasSubmenu && /* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-arrow" }, /* @__PURE__ */ vue.h(component.Icon, { icon: chrome.chevronRightIcon }))
|
|
622
|
+
))),
|
|
623
|
+
showPrompt && /* @__PURE__ */ vue.h("div", { class: "ai-instruction-section" }, /* @__PURE__ */ vue.h("div", { class: "ai-instruction-section-header" }, chrome.sendAsPromptHeaderLabel), /* @__PURE__ */ vue.h(
|
|
624
|
+
"div",
|
|
625
|
+
{
|
|
626
|
+
id: optionId(items.length),
|
|
627
|
+
"data-index": items.length,
|
|
628
|
+
role: "option",
|
|
629
|
+
"aria-selected": selectedIndex.value === items.length,
|
|
630
|
+
class: [
|
|
631
|
+
"ai-instruction-item",
|
|
632
|
+
"ai-instruction-item-prompt",
|
|
633
|
+
selectedIndex.value === items.length ? "active" : ""
|
|
634
|
+
],
|
|
635
|
+
onMousedown: onItemPointerDown,
|
|
636
|
+
onClick: submitRaw,
|
|
637
|
+
onPointerenter: () => {
|
|
638
|
+
selectedIndex.value = items.length;
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-icon" }, /* @__PURE__ */ vue.h(component.Icon, { icon: chrome.sendPromptIcon })),
|
|
642
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-label" }, chrome.sendAsPromptLabel, " ", /* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-quote" }, '"', inputValue.value, '"')),
|
|
643
|
+
/* @__PURE__ */ vue.h("span", { class: "ai-instruction-item-shortcut" }, /* @__PURE__ */ vue.h(component.Icon, { icon: chrome.enterKeyIcon }))
|
|
644
|
+
))
|
|
645
|
+
));
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
const defaultAPI = {
|
|
651
|
+
show: () => {
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const aiInstructionTooltipAPI = utils.$ctx(
|
|
655
|
+
{ ...defaultAPI },
|
|
656
|
+
"aiInstructionTooltipAPI"
|
|
657
|
+
);
|
|
658
|
+
tooltip.tooltipFactory("CREPE_AI_INSTRUCTION");
|
|
659
|
+
|
|
190
660
|
const mathInlineId = "math_inline";
|
|
191
661
|
const mathInlineSchema = utils.$nodeSchema(mathInlineId, () => ({
|
|
192
662
|
group: "inline",
|
|
@@ -272,7 +742,7 @@ const toggleLatexCommand = utils.$command("ToggleLatex", (ctx) => {
|
|
|
272
742
|
});
|
|
273
743
|
|
|
274
744
|
function getGroups(config, ctx) {
|
|
275
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
745
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
276
746
|
const groupBuilder = new GroupBuilder();
|
|
277
747
|
groupBuilder.addGroup("formatting", "Formatting").addItem("bold", {
|
|
278
748
|
icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon,
|
|
@@ -355,7 +825,22 @@ function getGroups(config, ctx) {
|
|
|
355
825
|
commands.call(linkTooltip.toggleLinkCommand.key);
|
|
356
826
|
}
|
|
357
827
|
});
|
|
358
|
-
(
|
|
828
|
+
if (ctx && (flags == null ? void 0 : flags.includes(CrepeFeature.AI))) {
|
|
829
|
+
const aiCfg = ctx.get(aiProviderConfig.key);
|
|
830
|
+
if (aiCfg.provider) {
|
|
831
|
+
functionGroup.addItem("ai", {
|
|
832
|
+
icon: (_h = (_g = config == null ? void 0 : config.aiIcon) != null ? _g : aiCfg.aiIcon) != null ? _h : aiIcon,
|
|
833
|
+
active: () => false,
|
|
834
|
+
onRun: (ctx2) => {
|
|
835
|
+
const api = ctx2.get(aiInstructionTooltipAPI.key);
|
|
836
|
+
const view = ctx2.get(core.editorViewCtx);
|
|
837
|
+
const { from, to } = view.state.selection;
|
|
838
|
+
api.show(from, to);
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
(_i = config == null ? void 0 : config.buildToolbar) == null ? void 0 : _i.call(config, groupBuilder);
|
|
359
844
|
return groupBuilder.build();
|
|
360
845
|
}
|
|
361
846
|
|