@udecode/plate-alignment
Advanced tools
Comparing version 6.3.0 to 6.4.0
# @udecode/plate-alignment | ||
## 6.4.0 | ||
### Patch Changes | ||
- [#1184](https://github.com/udecode/plate/pull/1184) by [@ghingis](https://github.com/ghingis) – now uses `getElementOverrideProps` / `getLeafOverrideProps` | ||
## 6.3.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ELEMENT_DEFAULT, unsetNodes, setNodes } from '@udecode/plate-common'; | ||
import { getElementOverrideProps, ELEMENT_DEFAULT, unsetNodes, setNodes } from '@udecode/plate-common'; | ||
import { getPlatePluginOptions, getPlatePluginType } from '@udecode/plate-core'; | ||
@@ -1186,43 +1186,2 @@ import { Editor } from 'slate'; | ||
function toVal(mix) { | ||
var k, y, str=''; | ||
if (typeof mix === 'string' || typeof mix === 'number') { | ||
str += mix; | ||
} else if (typeof mix === 'object') { | ||
if (Array.isArray(mix)) { | ||
for (k=0; k < mix.length; k++) { | ||
if (mix[k]) { | ||
if (y = toVal(mix[k])) { | ||
str && (str += ' '); | ||
str += y; | ||
} | ||
} | ||
} | ||
} else { | ||
for (k in mix) { | ||
if (mix[k]) { | ||
str && (str += ' '); | ||
str += k; | ||
} | ||
} | ||
} | ||
} | ||
return str; | ||
} | ||
function clsx () { | ||
var i=0, tmp, x, str=''; | ||
while (i < arguments.length) { | ||
if (tmp = arguments[i++]) { | ||
if (x = toVal(tmp)) { | ||
str && (str += ' '); | ||
str += x; | ||
} | ||
} | ||
} | ||
return str; | ||
} | ||
const getAlignOverrideProps = () => editor => { | ||
@@ -1235,29 +1194,9 @@ const { | ||
} = getPlatePluginOptions(editor, KEY_ALIGN); | ||
return ({ | ||
element, | ||
style, | ||
className | ||
}) => { | ||
if (!element) return; | ||
const { | ||
align | ||
} = element; | ||
if (!align || align === defaultAlignment || !alignments.includes(align)) return; | ||
const isBlock = Editor.isBlock(editor, element); | ||
if (!isBlock) return; | ||
if (types.includes(element.type)) { | ||
const res = {}; | ||
if (classNames !== null && classNames !== void 0 && classNames[align]) { | ||
res.className = clsx(className, classNames[align]); | ||
} else { | ||
res.style = { ...style, | ||
textAlign: align | ||
}; | ||
} | ||
return res; | ||
} | ||
}; | ||
return getElementOverrideProps(editor, { | ||
type: KEY_ALIGN, | ||
defaultOption: defaultAlignment, | ||
options: alignments, | ||
types, | ||
classNames | ||
}); | ||
}; | ||
@@ -1277,3 +1216,5 @@ | ||
alignments: DEFAULT_ALIGNMENTS, | ||
defaultAlignment: DEFAULT_ALIGNMENT | ||
defaultAlignment: DEFAULT_ALIGNMENT, | ||
// The following props will be used by the getOverrideProps | ||
cssPropName: 'textAlign' | ||
}); | ||
@@ -1280,0 +1221,0 @@ return editor; |
@@ -1190,43 +1190,2 @@ 'use strict'; | ||
function toVal(mix) { | ||
var k, y, str=''; | ||
if (typeof mix === 'string' || typeof mix === 'number') { | ||
str += mix; | ||
} else if (typeof mix === 'object') { | ||
if (Array.isArray(mix)) { | ||
for (k=0; k < mix.length; k++) { | ||
if (mix[k]) { | ||
if (y = toVal(mix[k])) { | ||
str && (str += ' '); | ||
str += y; | ||
} | ||
} | ||
} | ||
} else { | ||
for (k in mix) { | ||
if (mix[k]) { | ||
str && (str += ' '); | ||
str += k; | ||
} | ||
} | ||
} | ||
} | ||
return str; | ||
} | ||
function clsx () { | ||
var i=0, tmp, x, str=''; | ||
while (i < arguments.length) { | ||
if (tmp = arguments[i++]) { | ||
if (x = toVal(tmp)) { | ||
str && (str += ' '); | ||
str += x; | ||
} | ||
} | ||
} | ||
return str; | ||
} | ||
const getAlignOverrideProps = () => editor => { | ||
@@ -1239,29 +1198,9 @@ const { | ||
} = plateCore.getPlatePluginOptions(editor, KEY_ALIGN); | ||
return ({ | ||
element, | ||
style, | ||
className | ||
}) => { | ||
if (!element) return; | ||
const { | ||
align | ||
} = element; | ||
if (!align || align === defaultAlignment || !alignments.includes(align)) return; | ||
const isBlock = slate.Editor.isBlock(editor, element); | ||
if (!isBlock) return; | ||
if (types.includes(element.type)) { | ||
const res = {}; | ||
if (classNames !== null && classNames !== void 0 && classNames[align]) { | ||
res.className = clsx(className, classNames[align]); | ||
} else { | ||
res.style = { ...style, | ||
textAlign: align | ||
}; | ||
} | ||
return res; | ||
} | ||
}; | ||
return plateCommon.getElementOverrideProps(editor, { | ||
type: KEY_ALIGN, | ||
defaultOption: defaultAlignment, | ||
options: alignments, | ||
types, | ||
classNames | ||
}); | ||
}; | ||
@@ -1281,3 +1220,5 @@ | ||
alignments: DEFAULT_ALIGNMENTS, | ||
defaultAlignment: DEFAULT_ALIGNMENT | ||
defaultAlignment: DEFAULT_ALIGNMENT, | ||
// The following props will be used by the getOverrideProps | ||
cssPropName: 'textAlign' | ||
}); | ||
@@ -1284,0 +1225,0 @@ return editor; |
@@ -0,1 +1,2 @@ | ||
import { CSSProperties } from 'react'; | ||
export declare type Alignment = 'left' | 'center' | 'right' | 'justify'; | ||
@@ -23,3 +24,19 @@ export interface AlignPluginOptions { | ||
types?: string[]; | ||
/** The following props will be used by the getOverrideProps */ | ||
/** | ||
* camelCase name of the css property that the getOverrideProps will use | ||
* if not provided it will fall back to the plugin key | ||
* @default 'textAlign' | ||
*/ | ||
cssPropName?: keyof CSSProperties; | ||
/** | ||
* Transformation function that will be used to transform the value from the text | ||
* if not provided the value will be used as is | ||
* @default undefined | ||
*/ | ||
transformCssValue?: (params: { | ||
options: AlignPluginOptions; | ||
value: Alignment; | ||
}) => number | string; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@udecode/plate-alignment", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"description": "Text alignment plugin for Plate", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@udecode/plate-common": "6.3.0", | ||
"@udecode/plate-common": "6.4.0", | ||
"@udecode/plate-core": "6.2.0" | ||
@@ -38,0 +38,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205175
2242
+ Added@udecode/plate-common@6.4.0(transitive)
- Removed@udecode/plate-common@6.3.0(transitive)
Updated@udecode/plate-common@6.4.0