Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create API methods for manipulating with block elements #135

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b170900
create API methods for manipulating with block elements
Darginec05 May 5, 2024
2eba977
get Element implemnted
Darginec05 May 9, 2024
c345cdb
working on API with elements
Darginec05 May 11, 2024
960229a
Merge branch 'master' of github.com:Darginec05/Editor-Yopta into 131-…
Darginec05 May 17, 2024
3bd8cc4
merge
Darginec05 May 17, 2024
a118f0a
pass element path to props
Darginec05 May 18, 2024
8c9a9a5
Merge branch 'master' of github.com:Darginec05/Editor-Yopta into 131-…
Darginec05 May 18, 2024
c336e08
finish API of elements
Darginec05 May 21, 2024
1d74f79
add new API object Elements and Blocks
Darginec05 May 24, 2024
611df90
remove elements API from editor.blocks
Darginec05 May 24, 2024
ed6b56e
extend API for elements
Darginec05 May 25, 2024
ee3e3e6
Merge branch 'master' of github.com:Darginec05/Editor-Yopta into 131-…
Darginec05 May 26, 2024
1d6484b
remvoe unused pacakge
Darginec05 May 27, 2024
e728140
fix bug with prev block
Darginec05 May 29, 2024
7fcc71a
update peer deps
Darginec05 May 29, 2024
abd2670
Publish
Darginec05 May 29, 2024
29e4ae3
Publish
Darginec05 May 29, 2024
26df3e6
fix error with arrow down and up
Darginec05 May 30, 2024
8624ba9
Publish
Darginec05 May 30, 2024
018d25b
udpate exampels
Darginec05 May 30, 2024
7acee1f
update value for examples
Darginec05 May 30, 2024
1824c9b
Fix update block & fix element API`s
Darginec05 May 31, 2024
9f78b25
fix arrow up and arrow down
Darginec05 May 31, 2024
28c70e7
Publish
Darginec05 May 31, 2024
0b5539a
added example with carousel plugin
Darginec05 Jun 5, 2024
66e50e5
Publish
Darginec05 Jun 5, 2024
ef021df
add carousel block options
Darginec05 Jun 5, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"private": true,
"scripts": {
"start": "yarn lerna run start --scope @yoopta/editor --scope @yoopta/embed --scope @yoopta/action-menu-list --scope @yoopta/toolbar --scope @yoopta/paragraph --scope @yoopta/blockquote --scope @yoopta/headings --parallel --ignore development",
"start": "yarn lerna run start --scope @yoopta/editor --scope @yoopta/lists --scope @yoopta/accordion --parallel --ignore development",
Darginec05 marked this conversation as resolved.
Show resolved Hide resolved
"build": "yarn clean && yarn lerna run build --parallel --ignore development",
"clean": "find ./packages -type d -name dist ! -path './packages/development/*' -exec rm -rf {} +",
"serve": "cd ./packages/development && yarn dev",
Expand Down
11 changes: 11 additions & 0 deletions packages/accordion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `yoopta-accordion`

> TODO: description
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if README is mandatory file for publishing the plugin to npm, it's a bit misleading.


## Usage

```
const accordion = require('yoopta-accordion');

// TODO: DEMONSTRATE API
```
40 changes: 40 additions & 0 deletions packages/accordion/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@yoopta/accordion",
"version": "4.0.0",
"description": "Accordion plugin for Yoopta Editor",
"author": "Darginec05 <[email protected]>",
"homepage": "https://github.com/Darginec05/Editor-Yoopta#readme",
"license": "MIT",
"private": false,
"main": "dist/index.js",
"type": "module",
"module": "dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/"
],
"peerDependencies": {
"@yoopta/editor": ">=4.0.0-rc.0",
"react": ">=17.0.2",
"react-dom": ">=17.0.2"
},
"dependencies": {
"lucide-react": "^0.378.0"
},
"publishConfig": {
"registry": "https://registry.yarnpkg.com"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Darginec05/Editor-Yoopta.git"
},
"scripts": {
"test": "node ./__tests__/yoopta-accordion.test.js",
"start": "rollup --config rollup.config.js --watch --bundleConfigAsCjs --environment NODE_ENV:development",
"prepublishOnly": "yarn build",
"build": "rollup --config rollup.config.js --bundleConfigAsCjs --environment NODE_ENV:production"
},
"bugs": {
"url": "https://github.com/Darginec05/Editor-Yoopta/issues"
}
}
7 changes: 7 additions & 0 deletions packages/accordion/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createRollupConfig } from '../../config/rollup';

const pkg = require('./package.json');
export default createRollupConfig({
pkg,
tailwindConfig: { content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'], prefix: 'yoo-accordion-' },
});
1 change: 1 addition & 0 deletions packages/accordion/src/icons/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/accordion/src/icons/default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/accordion/src/icons/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/accordion/src/icons/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/accordion/src/icons/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/accordion/src/icons/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/accordion/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Accordion } from './plugin';
import { AccordionItemElement } from './types';
import './styles.css';

declare module 'slate' {
interface CustomTypes {
Element: AccordionItemElement;
}
}

export default Accordion;
export { AccordionItemElement };
52 changes: 52 additions & 0 deletions packages/accordion/src/plugin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { YooptaPlugin } from '@yoopta/editor';
import { AccordionElementKeys, AccordionListItemProps } from '../types';
import { AccordionList } from '../renders/AccordionList';
import { AccordionItem } from '../renders/AccordionItem';
import { AccordionItemHeading } from '../renders/AccordionItemHeading';
import { AccordionItemContent } from '../renders/AccordionItemContent';

const Accordion = new YooptaPlugin<AccordionElementKeys, AccordionListItemProps>({
type: 'Accordion',
elements: {
'accordion-list': {
asRoot: true,
render: AccordionList,
children: ['accordion-list-item'],
},
'accordion-list-item': {
render: AccordionItem,
children: ['accordion-list-item-heading', 'accordion-list-item-content'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering an issue if you mistype the 'key', or if they will be the same within one plugin for multiple items

props: { isExpanded: false },
},
'accordion-list-item-heading': {
render: AccordionItemHeading,
},
'accordion-list-item-content': {
render: AccordionItemContent,
},
},
events: {
onKeyDown(editor, slate, { hotkeys, currentBlock }) {
return (event) => {
if (hotkeys.isEnter(event)) {
event.preventDefault();

editor.blocks.Accordion.createElement(
currentBlock.id,
'accordion-list-item',
{ isExpanded: true },
{ at: 'next', focus: true },
);
}
};
},
},
options: {
display: {
title: 'Accordion',
description: 'Create collapses',
},
},
});

export { Accordion };
6 changes: 6 additions & 0 deletions packages/accordion/src/react-svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.svg' {
Darginec05 marked this conversation as resolved.
Show resolved Hide resolved
import { ReactElement, SVGProps } from 'react';

const content: (props: SVGProps<SVGElement>) => ReactElement;
export default content;
}
14 changes: 14 additions & 0 deletions packages/accordion/src/renders/AccordionItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PluginElementRenderProps } from '@yoopta/editor';

export const AccordionItem = (props: PluginElementRenderProps) => {
const { element, attributes, children } = props;

return (
<li
{...attributes}
className="yoo-accordion-border yoo-accordion-border-[#525252] yoo-accordion-bg-[#303030] yoo-accordion-rounded-none yoo-accordion-relative yoo-accordion-w-full"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering those two [#525252] is a standard coloring schema for yoopta, or/and might be re-used from somewhere or taken from Props with default values as defined in the code?

>
{children}
</li>
);
};
12 changes: 12 additions & 0 deletions packages/accordion/src/renders/AccordionItemContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PluginElementRenderProps, useYooptaEditor } from '@yoopta/editor';
import { useEffect, useState } from 'react';

export const AccordionItemContent = (props: PluginElementRenderProps) => {
const { element, attributes, children, blockId } = props;

return (
<p {...attributes} className="yoo-accordion-text-white yoo-accordion-px-5 yoo-accordion-py-4">
{children}
</p>
);
};
49 changes: 49 additions & 0 deletions packages/accordion/src/renders/AccordionItemHeading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { PluginElementRenderProps, useYooptaEditor, useYooptaReadOnly } from '@yoopta/editor';
import { ChevronUp, Plus } from 'lucide-react';

export const AccordionItemHeading = (props: PluginElementRenderProps) => {
const { element, attributes, children, blockId } = props;
const editor = useYooptaEditor();
const isReadOnly = useYooptaReadOnly();

const onToggleExpand = () => {
const listItemEntry = editor.blocks.Accordion.getElement(blockId, 'accordion-list-item');

if (listItemEntry) {
const listItemElement = listItemEntry[0];

editor.blocks.Accordion.updateElement(blockId, 'accordion-list-item', {
isExpanded: !listItemElement.props?.isExpanded,
});
}
};

const onAddAccordionItem = () => {
editor.blocks.Accordion.createElement(
blockId,
'accordion-list-item',
{ isExpanded: true },
{ at: 'next', focus: true },
);
};

return (
<h2
{...attributes}
aria-expanded="false"
className="yoo-accordion-mb-0 yoo-accordion-group yoo-accordion-relative yoo-accordion-flex yoo-accordion-w-full yoo-accordion-items-center yoo-accordion-border-0 yoo-accordion-rounded-none yoo-accordion-text-[#3b71ca] !yoo-accordion-bg-[#424242] yoo-accordion-px-5 yoo-accordion-py-4 yoo-accordion-text-left"
>
{children}
{!isReadOnly && (
<div className="yoo-accordion-absolute yoo-accordion-right-[14px] yoo-accordion-z-10 yoo-accordion-top-1/2 -yoo-accordion-translate-y-1/2 yoo-accordion-flex yoo-accordion-gap-1">
<button contentEditable={false} onClick={onAddAccordionItem}>
<Plus strokeWidth={1} size={24} color="#fff" />
</button>
<button contentEditable={false} onClick={onToggleExpand}>
<ChevronUp strokeWidth={1} size={24} color="#fff" />
</button>
</div>
)}
</h2>
);
};
12 changes: 12 additions & 0 deletions packages/accordion/src/renders/AccordionList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PluginElementRenderProps, useYooptaEditor } from '@yoopta/editor';
import { useEffect } from 'react';

export const AccordionList = (props: PluginElementRenderProps) => {
const { element, attributes, children, blockId } = props;

return (
<ul {...attributes} className="yoo-accordion-p-0 yoo-accordion-m-0 yoo-accordion-my-2">
{children}
</ul>
);
};
1 change: 1 addition & 0 deletions packages/accordion/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@tailwind utilities;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

13 changes: 13 additions & 0 deletions packages/accordion/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SlateElement } from '@yoopta/editor';

export type AccordionElementKeys =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using enum here, those you can reuse and reference to it in other places like here

| 'accordion-list'
| 'accordion-list-item'
| 'accordion-list-item-heading'
| 'accordion-list-item-content';

export type AccordionListItemProps = {
isExpanded: boolean;
};

export type AccordionItemElement = SlateElement<'accordion-list-item', AccordionListItemProps>;
14 changes: 14 additions & 0 deletions packages/accordion/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../config/tsconfig.base.json",
"include": ["src/react-svg.d.ts", "css-modules.d.ts", "src"],
"exclude": ["dist", "src/**/*.test.tsx", "src/**/*.stories.tsx"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"references": [
{
"path": "../core"
}
]
}
9 changes: 4 additions & 5 deletions packages/action-menu/src/components/ActionMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useLayoutEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { DefaultActionMenuRender } from './DefaultActionMenuRender';
import {
useFloating,
Expand All @@ -18,7 +18,6 @@ import {
findSlateBySelectionPath,
HOTKEYS,
findPluginBlockBySelectionPath,
YooEditor,
} from '@yoopta/editor';
import { ActionMenuRenderProps, ActionMenuToolItem, ActionMenuToolProps } from '../types';
import { buildActionMenuRenderProps, mapActionMenuItems } from './utils';
Expand All @@ -39,7 +38,7 @@ const filterActionMenuItems = (block: YooptaBlock, text: string) => {
};

// [TODO] - add to props
const trigger = '/';
const TRIGGER = '/';

const ActionMenuList = ({ items, render }: ActionMenuToolProps) => {
const editor = useYooptaEditor();
Expand Down Expand Up @@ -71,9 +70,9 @@ const ActionMenuList = ({ items, render }: ActionMenuToolProps) => {
const onClose = () => setIsMenuOpen(false);

const onFilter = ({ text }) => {
const string = text.trim().replace(trigger, '');
const string = text.trim().replace(TRIGGER, '');

if (string.length === 0 || string === trigger) return setActions(blockTypes);
if (string.length === 0 || string === TRIGGER) return setActions(blockTypes);
const filteredActions = actions.filter((action) => filterActionMenuItems(editor.blocks[action.type], string));
const isSelectedItemInsideFilteredActions = filteredActions.some((item) => item.type === selectedAction.type);
if (filteredActions.length > 0 && !isSelectedItemInsideFilteredActions) setSelectedAction(filteredActions[0]);
Expand Down
Loading
Loading