plate icon indicating copy to clipboard operation
plate copied to clipboard

Feat/mark affinity

Open felixfeng33 opened this issue 1 year ago • 8 comments

@12joan We have discussion at #2530 .Are these the contents you expressed?

felixfeng33 avatar Apr 23 '24 07:04 felixfeng33

⚠️ No Changeset found

Latest commit: 841e8ab99a976a0d30fd51ff2ca008a477882387

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Apr 23 '24 07:04 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 7:20am

vercel[bot] avatar Apr 23 '24 07:04 vercel[bot]

@12joan I have accept your suggestion. I intend to spilt this feature into three plugin.This is the createNaturalMarkAffinityPlugin one. it exclude the mark which have padding-left or padding-right like MARK_CODE. Due to limitations with Slate, we cannot set the cursor to the far left and within the code.and this mark have padding-left it will be strange. It should create a new plugin to handle this case.Right now I have no ideal. image

The third plugin will conflict with the first plugin, resulting in a cursor that moves in steps.

felixfeng33 avatar Apr 26 '24 07:04 felixfeng33

it exclude the mark which have padding-left or padding-right like MARK_CODE. Due to limitations with Slate, we cannot set the cursor to the far left and within the code.and this mark have padding-left it will be strange. It should create a new plugin to handle this case.Right now I have no ideal. image

Is this the bug where setting the affinity to the left while at the start of an inline code mark creates a new, empty inline code mark to the left of it? If it's possible to fix that (which I'm not 100% sure it is), that would have to be fixed in slate-react.

In my app, I've addressed this by switching to an inline code style without any padding. image

12joan avatar Apr 26 '24 07:04 12joan

it exclude the mark which have padding-left or padding-right like MARK_CODE. Due to limitations with Slate, we cannot set the cursor to the far left and within the code.and this mark have padding-left it will be strange. It should create a new plugin to handle this case.Right now I have no ideal. image

Is this the bug where setting the affinity to the left while at the start of an inline code mark creates a new, empty inline code mark to the left of it? If it's possible to fix that (which I'm not 100% sure it is), that would have to be fixed in slate-react.

In my app, I've addressed this by switching to an inline code style without any padding. image

yeah,it have to be fixed in slate-react I think it will be not easy.

felixfeng33 avatar Apr 26 '24 07:04 felixfeng33

Thank your valuable advice. @12joan

felixfeng33 avatar Apr 26 '24 08:04 felixfeng33

@gooroodev are you able to review this?

admsev avatar May 26 '24 22:05 admsev

Appreciate the heads-up, @admsev!

Summary of Changes

  1. New Package Addition:

    • Added a new package @udecode/plate-marks-affinity to manage mark affinity in the editor.
  2. Dependency Updates:

    • Updated apps/www/package.json to include the new package as a dependency.
  3. Playground Demo:

    • Modified apps/www/src/registry/default/example/playground-demo.tsx to integrate the new mark affinity plugin.
    • Added new constants for various marks such as MARK_BOLD, MARK_ITALIC, etc., to the imports.
    • Integrated createMarkAffinityPlugin with valid marks in the usePlaygroundPlugins function.
  4. New Package Files:

    • Created new files in the packages/mark-affinity directory:
      • .npmignore
      • README.md
      • package.json
      • src/createMarkAffinityPlugin.ts
      • src/index.ts
      • src/queries/getMarkBoundary.ts
      • src/queries/getMarkBoundaryAffinity.ts
      • src/queries/index.ts
      • src/transforms/index.ts
      • src/transforms/setMarkBoundaryAffinity.ts
      • src/types.ts
      • src/withMarkAffinity.ts
      • tsconfig.json
  5. Utility Updates:

    • Modified packages/utils/src/environment.ts to include a new constant IS_FIREFOX.

Issues, Bugs, or Typos

  1. Typo in README:

    • In packages/mark-affinity/README.md, the word "futures" should be corrected to "features".
  2. Comment Issue:

    • In withMarkAffinity.ts, there's a TODO comment that seems incomplete: //TODO: note the comment_x. It should be either completed or removed if not needed.
  3. Unnecessary Null Checks:

    • In getMarkBoundary.ts, the return type of getNodeEntry is already nullable, so the explicit ?? null checks might be redundant.

Code Improvements

  1. Typo Correction in README:

    - This package implements the following futures:
    + This package implements the following features:
    
  2. Complete or Remove TODO Comment:

    - //TODO: note the comment_x
    
  3. Simplify Null Checks in getMarkBoundary.ts:

    - const adjacentNode = getNodeEntry(editor, adjacentPath) ?? null;
    + const adjacentNode = getNodeEntry(editor, adjacentPath);
    
    - const adjacentLeafEntry =
    -   adjacentNode && isText(adjacentNode[0])
    -     ? (adjacentNode as NodeEntry<TText>)
    -     : null;
    + const adjacentLeafEntry = adjacentNode && isText(adjacentNode[0])
    +   ? (adjacentNode as NodeEntry<TText>)
    +   : null;
    

General Review of Code Quality and Style

  1. Code Consistency:

    • The code is consistent in terms of style and follows typical TypeScript and React best practices.
    • Proper use of TypeScript interfaces and types enhances code readability and maintainability.
  2. Documentation:

    • The newly added README.md provides a brief overview and a link to further documentation, which is good for new users of the package.
  3. Modular Design:

    • The new functionality is well encapsulated within its package, adhering to the modular design principles.
  4. Code Comments:

    • The code is well-commented, explaining the purpose of various functions and the logic behind certain decisions.
  5. Error Handling:

    • The code generally checks for null or undefined values, ensuring robustness.

Overall, the changes are well-structured and integrate seamlessly with the existing codebase. The new functionality for managing mark affinity is clearly defined and implemented in a modular fashion.

Yours, Gooroo.dev. Please add a reaction or reply with your thoughts!

gooroodev avatar May 26 '24 22:05 gooroodev