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

RTL direction support via properties panel (revised) #1213

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
131 changes: 90 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@playwright/test": "^1.43.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-commonjs": "^26.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@svgr/rollup": "^8.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { get } from 'min-dash';
import { useService, useDirection } from '../hooks';
import { SelectEntry, isSelectEntryEdited } from '@bpmn-io/properties-panel';

export function DirectionEntry(props) {
const { editField, field } = props;

const entries = [
{
id: 'direction',
component: Direction,
editField,
field,
isEdited: isSelectEntryEdited,
isDefaultVisible: (field) => field.type === 'default',
},
];

return entries;
}

function Direction(props) {
const { editField, field } = props;
const { setDirection } = useDirection();

const debounce = useService('debounce');

const path = ['direction'];

const getValue = () => {
const value = get(field, path, 'ltr');
return value;
};

const setValue = (value) => {
setDirection(value);
return editField(field, path, value || 'ltr');
};

const getOptions = () => [
{
label: 'Left to Right',
value: 'ltr',
},
{
label: 'Right to Left',
value: 'rtl',
},
];

return SelectEntry({
debounce,
element: field,
getValue,
id: 'direction',
label: 'Direction',
setValue,
getOptions,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export { RowCountEntry } from './RowCountEntry';
export { HeadersSourceSelectEntry } from './HeadersSourceSelectEntry';
export { ColumnsExpressionEntry } from './ColumnsExpressionEntry';
export { StaticColumnsSourceEntry } from './StaticColumnsSourceEntry';
export { DirectionEntry } from './DirectionEntry';
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're using vscode, install the prettier code formatter app, and also eslint, it will show you errors you're missing and adhere to our formatting rules.

If you're using another software to code I'm not sure if they have support for it but either way both have CLIs, so you can use the CLI to fix things up.

Copy link
Author

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AdornerEntry, GroupAppearanceEntry, LayouterAppearanceEntry } from '../entries';
import { AdornerEntry, GroupAppearanceEntry, LayouterAppearanceEntry, DirectionEntry } from '../entries';

export function AppearanceGroup(field, editField, getService) {
const entries = [
...AdornerEntry({ field, editField }),
...GroupAppearanceEntry({ field, editField }),
...LayouterAppearanceEntry({ field, editField }),
...DirectionEntry({ field, editField, getService }),
];

if (!entries.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useContext } from 'preact/hooks';
import { createContext } from 'preact';

const DirectionContext = createContext({
direction: 'ltr',
setDirection: (direction) => {},
});

export function useDirection() {
const context = useContext(DirectionContext);
if (!context) {
throw new Error('useDirection must be used within a DirectionProvider');
}
return context;
}

// // hooks/useDirection.js
// import { useContext } from 'preact/hooks';
// import { FormContext } from '../context/FormContext'; // Adjust the path as necessary

// export function useDirection() {
// const form = useContext(FormContext);
// const { schema } = form._getState();
// const direction = schema?.direction || 'ltr';
// return direction;
// }
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { useVariables } from './useVariables';
export { useService } from './usePropertiesPanelService';
export { useDirection } from './DirectionContext';
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
// import RepeatSvg from '../../render/components/icons/Repeat.svg';

// export class EditorRepeatRenderManager {
// constructor(formFields, formFieldRegistry) {
// this._formFields = formFields;
// this._formFieldRegistry = formFieldRegistry;
// this.RepeatFooter = this.RepeatFooter.bind(this);
// }

// /**
// * Checks whether a field should be repeatable.
// *
// * @param {string} id - The id of the field to check
// * @returns {boolean} - True if repeatable, false otherwise
// */
// isFieldRepeating(id) {
// if (!id) {
// return false;
// }

// const formField = this._formFieldRegistry.get(id);
// const formFieldDefinition = this._formFields.get(formField.type);
// return formFieldDefinition.config.repeatable && formField.isRepeating;
// }

// RepeatFooter() {
// return (
// <div className="fjs-repeat-render-footer">
// <RepeatSvg />
// <span>Repeatable</span>
// </div>
// );
// }
// }

// EditorRepeatRenderManager.$inject = ['formFields', 'formFieldRegistry'];

import RepeatSvg from '../../render/components/icons/Repeat.svg';

export class EditorRepeatRenderManager {
Expand All @@ -23,10 +60,12 @@ export class EditorRepeatRenderManager {
return formFieldDefinition.config.repeatable && formField.isRepeating;
}

RepeatFooter() {
RepeatFooter({ direction }) {
return (
<div className="fjs-repeat-render-footer">
<RepeatSvg />
<div className="fjs-repeat-render-footer" style={{ direction: direction }}>
<RepeatSvg
style={{ marginRight: direction === 'ltr' ? '8px' : '8px', marginLeft: direction === 'rtl' ? '8px' : '8px' }}
/>
<span>Repeatable</span>
</div>
);
Expand Down
Loading