-
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Make rules configurable through Plate plugin options
- Loading branch information
Showing
6 changed files
with
56 additions
and
28 deletions.
There are no files selected for viewing
51 changes: 31 additions & 20 deletions
51
packages/serializers/md/src/deserializer/createDeserializeMdPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
import { createPluginFactory, isUrl } from '@udecode/plate-core'; | ||
import { createPluginFactory, isUrl, Value } from '@udecode/plate-core'; | ||
import { | ||
remarkDefaultElementRules, | ||
remarkDefaultTextRules, | ||
} from '../remark-slate'; | ||
import { DeserializeMdPlugin } from './types'; | ||
import { deserializeMd } from './utils'; | ||
|
||
export const KEY_DESERIALIZE_MD = 'deserializeMd'; | ||
|
||
export const createDeserializeMdPlugin = createPluginFactory({ | ||
key: KEY_DESERIALIZE_MD, | ||
then: (editor) => ({ | ||
editor: { | ||
insertData: { | ||
format: 'text/plain', | ||
query: ({ data, dataTransfer }) => { | ||
const htmlData = dataTransfer.getData('text/html'); | ||
if (htmlData) return false; | ||
export const createDeserializeMdPlugin = createPluginFactory<DeserializeMdPlugin>( | ||
{ | ||
key: KEY_DESERIALIZE_MD, | ||
then: (editor) => ({ | ||
editor: { | ||
insertData: { | ||
format: 'text/plain', | ||
query: ({ data, dataTransfer }) => { | ||
const htmlData = dataTransfer.getData('text/html'); | ||
if (htmlData) return false; | ||
|
||
const { files } = dataTransfer; | ||
if (!files?.length) { | ||
// if content is simply a URL pass through to not break LinkPlugin | ||
if (isUrl(data)) { | ||
return false; | ||
const { files } = dataTransfer; | ||
if (!files?.length) { | ||
// if content is simply a URL pass through to not break LinkPlugin | ||
if (isUrl(data)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
return true; | ||
}, | ||
getFragment: ({ data }) => deserializeMd<Value>(editor, data), | ||
}, | ||
getFragment: ({ data }) => deserializeMd(editor, data), | ||
}, | ||
}), | ||
options: { | ||
elementRules: remarkDefaultElementRules, | ||
textRules: remarkDefaultTextRules, | ||
}, | ||
}), | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Value } from '@udecode/plate-core'; | ||
import { RemarkElementRules, RemarkTextRules } from '../remark-slate'; | ||
|
||
export interface DeserializeMdPlugin<V extends Value = Value> { | ||
elementRules: RemarkElementRules<V>; | ||
textRules: RemarkTextRules<V>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/serializers/md/src/remark-slate/remarkTransformElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters