Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .release-please/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"packages": {
"packages/editor": {},
"packages/latex-extension": {}
"packages/latex-extension": {},
"packages/page-constructor-extension": {}
}
}
3 changes: 2 additions & 1 deletion .release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"packages/editor": "15.39.0",
"packages/latex-extension": "0.1.0"
"packages/latex-extension": "0.1.0",
"packages/page-constructor-extension": "0.0.0"
}
11 changes: 11 additions & 0 deletions demo/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
check: true,
reactDocgen: 'react-docgen-typescript',
},
webpackFinal: (config) => {

Check warning on line 30 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

'config' is already declared in the upper scope on line 15 column 7
config.plugins?.push(
new webpack.DefinePlugin({
__VERSION__: `'${pkg.version}-storybook'`,
Expand All @@ -37,12 +37,12 @@
}),
);

config.resolve ||= {};

Check warning on line 40 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.resolve.alias ||= {};

Check warning on line 41 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.resolve.fallback ||= {};

Check warning on line 42 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'

// Node.js polyfills for browser
config.resolve.fallback = {

Check warning on line 45 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
...config.resolve.fallback,
fs: false,
path: require.resolve('path-browserify'),
Expand All @@ -50,8 +50,19 @@
process: require.resolve('process/browser'),
};

config.ignoreWarnings ||= [];

Check warning on line 53 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.ignoreWarnings.push(/\.js\.map$/);
config.module ||= {};

Check warning on line 55 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.module.rules ||= [];

Check warning on line 56 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.module.rules.push({
test: /\.(js|css)\.map$/,
include: /node_modules/,
type: 'asset/resource' as const,
generator: {emit: false},
});

config.watchOptions ||= {};

Check warning on line 64 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'
config.watchOptions.ignored = /node_modules([\\]+|\/)+(?!@gravity-ui\/markdown-editor)/;

Check warning on line 65 in demo/.storybook/main.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'config'

return config;
},
Expand Down
3 changes: 3 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
"@diplodoc/html-extension": "catalog:peer-diplodoc",
"@diplodoc/latex-extension": "catalog:peer-diplodoc",
"@diplodoc/mermaid-extension": "catalog:peer-diplodoc",
"@diplodoc/page-constructor-extension": "catalog:peer-diplodoc",
"@diplodoc/quote-link-extension": "catalog:peer-diplodoc",
"@diplodoc/tabs-extension": "catalog:peer-diplodoc",
"@diplodoc/transform": "catalog:peer-diplodoc",
"@gravity-ui/components": "catalog:peer-gravity",
"@gravity-ui/markdown-editor": "workspace:*",
"@gravity-ui/markdown-editor-latex-extension": "workspace:*",
"@gravity-ui/markdown-editor-page-constructor-extension": "workspace:*",
"@gravity-ui/page-constructor": "catalog:peer-gravity",
"@gravity-ui/uikit": "catalog:peer-gravity",
"markdown-it": "catalog:peers"
},
Expand Down
13 changes: 13 additions & 0 deletions demo/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
wLatexBlockItemData,
wLatexInlineItemData,
} from '@gravity-ui/markdown-editor-latex-extension/configs';
import {YfmPageConstructorExtension} from '@gravity-ui/markdown-editor-page-constructor-extension';
import {wYfmPageConstructorItemData} from '@gravity-ui/markdown-editor-page-constructor-extension/configs';
import {Button, DropdownMenu} from '@gravity-ui/uikit';

import {getPlugins} from '../defaults/md-plugins';
Expand All @@ -54,6 +56,7 @@ const wCommandMenuConfig = wysiwygToolbarConfigs.wCommandMenuConfig.concat(
wLatexInlineItemData,
wLatexBlockItemData,
wysiwygToolbarConfigs.wMermaidItemData,
wYfmPageConstructorItemData,
wysiwygToolbarConfigs.wYfmHtmlBlockItemData,
);

Expand Down Expand Up @@ -211,6 +214,16 @@ export const Playground = memo<PlaygroundProps>((props) => {
},
theme: {dark: 'dark', light: 'forest'},
})
.use(YfmPageConstructorExtension, {
autoSave: {
enabled:
storyAdditionalControls?.yfmPageConstructorAutoSaveEnabled ??
true,
delay:
storyAdditionalControls?.yfmPageConstructorAutoSaveDelay ??
1000,
},
})
.use(FoldingHeading)
.use(YfmHtmlBlock, {
useConfig: useYfmHtmlBlockStyles,
Expand Down
12 changes: 10 additions & 2 deletions demo/src/components/SplitModePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ import {
withMermaid,
} from '@gravity-ui/markdown-editor/view/hocs/withMermaid/index.js';
import {withYfmHtmlBlock} from '@gravity-ui/markdown-editor/view/hocs/withYfmHtml/index.js';
import {withYfmPageConstructor} from '@gravity-ui/markdown-editor-page-constructor-extension/view';
import {useThemeValue} from '@gravity-ui/uikit';
import type MarkdownIt from 'markdown-it';

import {LATEX_RUNTIME, MERMAID_RUNTIME, YFM_HTML_BLOCK_RUNTIME} from '../defaults/md-plugins';
import {
LATEX_RUNTIME,
MERMAID_RUNTIME,
PAGE_CONSTRUCTOR_RUNTIME,
YFM_HTML_BLOCK_RUNTIME,
} from '../defaults/md-plugins';
import useYfmHtmlBlockStyles from '../hooks/useYfmHtmlBlockStyles';

const ML_ATTR = 'data-ml';
const mermaidConfig: MermaidConfig = {theme: 'forest'};

const Preview = withMermaid({runtime: MERMAID_RUNTIME})(
withLatex({runtime: LATEX_RUNTIME})(
withYfmHtmlBlock({runtime: YFM_HTML_BLOCK_RUNTIME})(YfmStaticView),
withYfmPageConstructor({runtime: PAGE_CONSTRUCTOR_RUNTIME})(
withYfmHtmlBlock({runtime: YFM_HTML_BLOCK_RUNTIME})(YfmStaticView),
),
),
);

Expand Down
3 changes: 3 additions & 0 deletions demo/src/defaults/md-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@diplodoc/folding-headings-extension/runtime';
import {transform as yfmHtmlBlock} from '@diplodoc/html-extension';
import {transform as latex} from '@diplodoc/latex-extension';
import {transform as mermaid} from '@diplodoc/mermaid-extension';
import {transform as yfmPageConstructor} from '@diplodoc/page-constructor-extension';
import {transform as yfmTabs} from '@diplodoc/tabs-extension';
import anchors from '@diplodoc/transform/lib/plugins/anchors';
import checkbox from '@diplodoc/transform/lib/plugins/checkbox';
Expand All @@ -30,6 +31,7 @@ import type {PluginWithParams} from 'markdown-it/lib';
export const LATEX_RUNTIME = 'extension:latex';
export const MERMAID_RUNTIME = 'extension:mermaid';
export const YFM_HTML_BLOCK_RUNTIME = 'extension:yfm-html-block';
export const PAGE_CONSTRUCTOR_RUNTIME = 'extension:page-constructor';

type GetPluginsOptions = {
directiveSyntax?: RenderPreviewParams['directiveSyntax'];
Expand Down Expand Up @@ -88,6 +90,7 @@ export function getPlugins({
latex({bundle: false, validate: false, runtime: LATEX_RUNTIME}),
mark,
mermaid({bundle: false, runtime: MERMAID_RUNTIME}),
yfmPageConstructor({bundle: false, runtime: PAGE_CONSTRUCTOR_RUNTIME}),
sub,
yfmHtmlBlock({
bundle: false,
Expand Down
11 changes: 11 additions & 0 deletions demo/src/stories/yfm/YFM.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ export const MermaidDiagram: Story = {
},
},
};

export const YfmPageConstructor: Story = {
name: 'YFM Page Constructor',
args: {
initial: markup.yfmPageConstructor,
storyAdditionalControls: {
yfmPageConstructorAutoSaveEnabled: true,
yfmPageConstructorAutoSaveDelay: 500,
},
},
};
13 changes: 13 additions & 0 deletions demo/src/stories/yfm/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ sequenceDiagram
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice
\`\`\`
`.trim(),

yfmPageConstructor: `
&nbsp;

## YFM Page Constructor (optional feature)

::: page-constructor
blocks:
- type: 'header-block'
title: 'Title'
description: 'Description'
:::
`.trim(),

foldingHeadings: `
Expand Down
1 change: 1 addition & 0 deletions demo/tests/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ctViteConfig: ViteInlineConfig = {
alias: {
...aliasesFromTsConf,
'~@gravity-ui/uikit/styles/mixins': '@gravity-ui/uikit/styles/mixins',
'~@diplodoc/transform/dist/css/yfm.css': '@diplodoc/transform/dist/css/yfm.css',
},
},
optimizeDeps: {
Expand Down
6 changes: 6 additions & 0 deletions demo/tests/visual-tests/YfmExtensions.visual.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ test.describe('Extensions, YFM', () => {
await mount(<YFMStories.MermaidDiagram />);
await wait.loadersHidden();

await expectScreenshot();
});
test('YFM Page Constructor', async ({mount, expectScreenshot, wait}) => {
await mount(<YFMStories.YfmPageConstructor />);
await wait.loadersHidden();

await expectScreenshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,21 @@ export default defineConfig(
},
},
},
{
files: ['./packages/page-constructor-extension/**/*'],
languageOptions: {
parserOptions: {
project: './packages/page-constructor-extension/tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './packages/page-constructor-extension/tsconfig.json',
},
},
},
},
);
1 change: 1 addition & 0 deletions packages/page-constructor-extension/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
49 changes: 49 additions & 0 deletions packages/page-constructor-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @gravity-ui/markdown-editor-page-constructor-extension

Page Constructor extension for [@gravity-ui/markdown-editor](https://github.com/gravity-ui/markdown-editor).

Provides a WYSIWYG editing experience for [Page Constructor](https://github.com/gravity-ui/page-constructor) blocks inside the Markdown editor, as well as a preview HOC for split-mode rendering.

## Installation

```bash
npm install @gravity-ui/markdown-editor-page-constructor-extension
```

### Required peer dependencies

```bash
npm install @gravity-ui/markdown-editor @gravity-ui/uikit @gravity-ui/page-constructor @diplodoc/page-constructor-extension react react-dom
```

## Usage

### WYSIWYG extension

```typescript
import {YfmPageConstructorExtension} from '@gravity-ui/markdown-editor-page-constructor-extension';

builder.use(YfmPageConstructorExtension, {
autoSave: {enabled: true, delay: 1000},
});
```

### Toolbar button

```typescript
import {wYfmPageConstructorItemData} from '@gravity-ui/markdown-editor-page-constructor-extension/configs';
```

### Split-mode preview HOC

```typescript
import {withYfmPageConstructor} from '@gravity-ui/markdown-editor-page-constructor-extension/view';

const PAGE_CONSTRUCTOR_RUNTIME = 'extension:page-constructor';

const Preview = withYfmPageConstructor({runtime: PAGE_CONSTRUCTOR_RUNTIME})(YfmStaticView);
```

## License

MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
20 changes: 20 additions & 0 deletions packages/page-constructor-extension/gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';

import {series, task} from '@markdown-editor/gulp-tasks';
import {registerBuildTasks} from '@markdown-editor/gulp-tasks/build';

import pkg from './package.json' with {type: 'json'};

const __dirname = dirname(fileURLToPath(import.meta.url));

const BUILD_DIR = resolve('build');
const NODE_MODULES_DIR = resolve(__dirname, 'node_modules');

registerBuildTasks({
version: pkg.version,
buildDir: BUILD_DIR,
nodeModulesDir: NODE_MODULES_DIR,
});

task('default', series('clean', 'build'));
20 changes: 20 additions & 0 deletions packages/page-constructor-extension/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.cjs',
},
transformIgnorePatterns: ['node_modules/(?!(@gravity-ui|@diplodoc)/)'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: {
verbatimModuleSyntax: false,
},
},
],
},
};
Loading
Loading