draftail-text-utils 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. draftail_text_utils/__init__.py +4 -0
  2. draftail_text_utils/apps.py +7 -0
  3. draftail_text_utils/conf.py +482 -0
  4. draftail_text_utils/migrations/__init__.py +0 -0
  5. draftail_text_utils/rich_text/__init__.py +0 -0
  6. draftail_text_utils/rich_text/base.py +267 -0
  7. draftail_text_utils/rich_text/font_family.py +61 -0
  8. draftail_text_utils/rich_text/font_size.py +94 -0
  9. draftail_text_utils/rich_text/highlight_color.py +99 -0
  10. draftail_text_utils/rich_text/text_alignment.py +70 -0
  11. draftail_text_utils/rich_text/text_color.py +95 -0
  12. draftail_text_utils/static/draftail_text_utils/css/draftail_text_utils.css +5 -0
  13. draftail_text_utils/static/draftail_text_utils/css/font_family.css +57 -0
  14. draftail_text_utils/static/draftail_text_utils/css/font_size.css +102 -0
  15. draftail_text_utils/static/draftail_text_utils/css/highlight_color.css +117 -0
  16. draftail_text_utils/static/draftail_text_utils/css/text_alignment.css +72 -0
  17. draftail_text_utils/static/draftail_text_utils/css/text_color.css +117 -0
  18. draftail_text_utils/static/draftail_text_utils/js/font_family.js +149 -0
  19. draftail_text_utils/static/draftail_text_utils/js/font_size.js +408 -0
  20. draftail_text_utils/static/draftail_text_utils/js/font_size_entity.js +39 -0
  21. draftail_text_utils/static/draftail_text_utils/js/highlight_color.js +350 -0
  22. draftail_text_utils/static/draftail_text_utils/js/highlight_color_entity.js +43 -0
  23. draftail_text_utils/static/draftail_text_utils/js/text_alignment.js +139 -0
  24. draftail_text_utils/static/draftail_text_utils/js/text_color.js +343 -0
  25. draftail_text_utils/static/draftail_text_utils/js/text_color_entity.js +42 -0
  26. draftail_text_utils/templates/draftail_text_utils/icons/align-center.svg +1 -0
  27. draftail_text_utils/templates/draftail_text_utils/icons/align-justify.svg +1 -0
  28. draftail_text_utils/templates/draftail_text_utils/icons/align-left.svg +1 -0
  29. draftail_text_utils/templates/draftail_text_utils/icons/align-right.svg +1 -0
  30. draftail_text_utils/templates/draftail_text_utils/icons/font.svg +1 -0
  31. draftail_text_utils/templates/draftail_text_utils/icons/highlighter.svg +1 -0
  32. draftail_text_utils/templates/draftail_text_utils/icons/palette.svg +1 -0
  33. draftail_text_utils/templates/draftail_text_utils/icons/text-height.svg +1 -0
  34. draftail_text_utils/templatetags/__init__.py +0 -0
  35. draftail_text_utils/templatetags/draftail_text_utils_tags.py +29 -0
  36. draftail_text_utils/wagtail_hooks.py +266 -0
  37. draftail_text_utils-0.1.7.dist-info/METADATA +63 -0
  38. draftail_text_utils-0.1.7.dist-info/RECORD +39 -0
  39. draftail_text_utils-0.1.7.dist-info/WHEEL +4 -0
@@ -0,0 +1,57 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ /* stylelint-disable declaration-property-value-allowed-list */
3
+ /* stylelint-disable declaration-no-important */
4
+ /* stylelint-disable scale-unlimited/declaration-strict-value */
5
+ /* stylelint-disable property-disallowed-list */
6
+ .Draftail--font-family-control {
7
+ cursor: default !important;
8
+ position: relative;
9
+ display: inline-block;
10
+ margin-inline-end: 0.625rem;
11
+ background: none !important;
12
+ border-width: 0 !important;
13
+ outline-width: 0 !important;
14
+ }
15
+
16
+ .Draftail--font-family-dropdown {
17
+ display: none;
18
+ position: absolute;
19
+ top: 100%;
20
+ left: 0;
21
+ z-index: 100;
22
+ min-width: 180px;
23
+ max-height: 260px;
24
+ overflow-y: auto;
25
+ margin: 0;
26
+ padding: 4px 0;
27
+ list-style: none;
28
+ background: var(--w-color-surface-page, #fff);
29
+ border: 1px solid var(--w-color-border-furniture, #ddd);
30
+ border-radius: 4px;
31
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
32
+ }
33
+
34
+ .Draftail--font-family-dropdown[aria-expanded='true'] {
35
+ display: block;
36
+ }
37
+
38
+ .Draftail--font-family-option {
39
+ padding: 6px 12px;
40
+ cursor: pointer;
41
+ font-size: 13px;
42
+ }
43
+
44
+ .Draftail--font-family-option:hover {
45
+ background: var(--w-color-surface-menu-hover, #f0f0f0);
46
+ }
47
+
48
+ .Draftail--font-family-option[aria-selected='true'] {
49
+ background: var(--w-color-surface-menu-hover, #e8e8e8);
50
+ font-weight: 600;
51
+ }
52
+
53
+ .Draftail--font-family-icon {
54
+ font-family: serif;
55
+ font-size: 14px;
56
+ font-weight: 700;
57
+ }
@@ -0,0 +1,102 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ /* stylelint-disable declaration-property-value-allowed-list */
3
+ /* stylelint-disable declaration-no-important */
4
+ /* stylelint-disable scale-unlimited/declaration-strict-value */
5
+ /* stylelint-disable property-disallowed-list */
6
+ .Draftail--font-size-control {
7
+ cursor: default !important;
8
+ position: relative;
9
+ display: inline-block;
10
+ background: none !important;
11
+ border-width: 0 !important;
12
+ outline-width: 0 !important;
13
+ }
14
+
15
+ .Draftail--font-size-control-row > * {
16
+ flex: 0 1 min-content;
17
+ margin-inline-end: 0;
18
+ }
19
+
20
+ .Draftail--font-size-control-row {
21
+ display: flex;
22
+ align-items: center;
23
+ gap: 0.25rem;
24
+ width: min-content;
25
+ }
26
+
27
+ .Draftail--font-size-decrement,
28
+ .Draftail--font-size-increment {
29
+ min-width: min-content;
30
+ padding-inline: 0.25rem;
31
+ }
32
+
33
+ .Draftail--font-size-decrement > span,
34
+ .Draftail--font-size-increment > span {
35
+ margin-top: -0.25rem;
36
+ }
37
+
38
+ .Draftail--font-size-input-wrapper {
39
+ display: inline-flex;
40
+ align-items: center;
41
+ justify-content: center;
42
+ }
43
+
44
+ input.Draftail--font-size-input {
45
+ display: inline-flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ min-height: 0;
49
+ height: 1.875rem;
50
+ font-size: 1rem;
51
+ min-width: 5rem;
52
+ padding-inline: 0.25rem;
53
+ }
54
+
55
+ input.Draftail--font-size-input::placeholder {
56
+ font-size: 0.75rem;
57
+ text-align: center;
58
+ top: -0.09375rem;
59
+ position: relative;
60
+ }
61
+
62
+ .Draftail--font-size-dropdown {
63
+ position: absolute;
64
+ z-index: 100;
65
+ min-width: 180px;
66
+ max-height: 260px;
67
+ overflow: auto;
68
+ margin: 0;
69
+ padding: 4px 0;
70
+ background: var(--w-color-surface-page, #fff);
71
+ border: 1px solid var(--w-color-border-furniture, #ddd);
72
+ border-radius: 4px;
73
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
74
+ }
75
+
76
+ .Draftail--font-size-dropdown[aria-expanded='false'] {
77
+ border: 0;
78
+ clip: rect(0 0 0 0);
79
+ clip-path: inset(50%);
80
+ height: 1px;
81
+ margin: -1px;
82
+ overflow: hidden;
83
+ padding: 0;
84
+ position: absolute;
85
+ white-space: nowrap;
86
+ width: 1px;
87
+ }
88
+
89
+ .Draftail--font-size-option {
90
+ padding: 6px 12px;
91
+ cursor: pointer;
92
+ font-size: 13px;
93
+ }
94
+
95
+ .Draftail--font-size-option:hover {
96
+ background: var(--w-color-surface-menu-hover, #f0f0f0);
97
+ }
98
+
99
+ .Draftail--font-size-option[aria-selected='true'] {
100
+ background: var(--w-color-surface-menu-hover, #e8e8e8);
101
+ font-weight: 600;
102
+ }
@@ -0,0 +1,117 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ /* stylelint-disable declaration-property-value-allowed-list */
3
+ /* stylelint-disable declaration-no-important */
4
+ /* stylelint-disable scale-unlimited/declaration-strict-value */
5
+ /* stylelint-disable property-disallowed-list */
6
+ /* stylelint-disable color-named */
7
+ /* stylelint-disable selector-type-no-unknown */
8
+ .Draftail--highlight-color-control {
9
+ cursor: default !important;
10
+ position: relative;
11
+ display: inline-block;
12
+ margin-inline-end: 0.625rem;
13
+ background: none !important;
14
+ border-width: 0 !important;
15
+ outline-width: 0 !important;
16
+ }
17
+
18
+ .Draftail--highlight-color-input-wrapper {
19
+ display: inline-flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ }
23
+
24
+ input.Draftail--highlight-color-input {
25
+ cursor: pointer;
26
+ display: inline-flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ min-height: 0;
30
+ height: 1.875rem;
31
+ font-size: 1rem;
32
+ padding-inline: 0.25rem;
33
+ }
34
+
35
+ input.Draftail--highlight-color-input::placeholder {
36
+ font-size: 0.75rem;
37
+ text-align: center;
38
+ top: -0.09375rem;
39
+ position: relative;
40
+ }
41
+
42
+ .Draftail--highlight-color-dropdown {
43
+ position: absolute;
44
+ top: 100%;
45
+ left: 0;
46
+ z-index: 100;
47
+ }
48
+
49
+ .Draftail--highlight-color-dropdown[aria-expanded='false'] {
50
+ border: 0;
51
+ clip: rect(0 0 0 0);
52
+ clip-path: inset(50%);
53
+ height: 1px;
54
+ margin: -1px;
55
+ overflow: hidden;
56
+ padding: 0;
57
+ position: absolute;
58
+ white-space: nowrap;
59
+ width: 1px;
60
+ }
61
+
62
+ .Draftail--highlight-color-dropdown[aria-expanded='true'] {
63
+ display: flex;
64
+ flex-flow: row wrap;
65
+ justify-content: center;
66
+ align-items: center;
67
+ gap: 4px;
68
+ min-width: calc((1.875rem * 4) + 24px);
69
+ max-height: 260px;
70
+ overflow: inherit;
71
+ margin: 0;
72
+ padding: 0.5rem 4px;
73
+ background: var(--w-color-surface-page, #fff);
74
+ border: 1px solid var(--w-color-border-furniture, #ddd);
75
+ border-radius: 4px;
76
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
77
+ }
78
+
79
+ .Draftail--highlight-color-option-wrapper {
80
+ flex: 1 0 calc(25% - 12px);
81
+ }
82
+
83
+ .Draftail--highlight-color-option {
84
+ position: relative;
85
+ background: attr(name type(<color>), black) !important;
86
+ border: 0.3125rem solid var(--w-color-surface-menu-hover, #e8e8e8);
87
+ }
88
+
89
+ .Draftail--highlight-color-option:hover,
90
+ .Draftail--highlight-color-option.Draftail-ToolbarButton--active {
91
+ border: 0.3125rem solid var(--w-color-text-button-outline-default, #007d7e) !important;
92
+ }
93
+
94
+ .Draftail--highlight-color-hr {
95
+ width: 100%;
96
+ }
97
+
98
+ .Draftail--highlight-color-option > .Draftail-ToolbarButton__label {
99
+ display: none;
100
+ }
101
+
102
+ .Draftail--highlight-color-option.Draftail-ToolbarButton--active
103
+ > .Draftail-ToolbarButton__label {
104
+ display: inline-block;
105
+ position: relative;
106
+ text-align: center;
107
+ top: -2px;
108
+ color: var(--w-color-text-button-outline-default, #007d7e);
109
+ }
110
+
111
+ color-input::part(gamut) {
112
+ display: none !important;
113
+ }
114
+
115
+ color-input::part(panel) {
116
+ max-inline-size: 15rem;
117
+ }
@@ -0,0 +1,72 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ /* stylelint-disable declaration-property-value-allowed-list */
3
+ /* stylelint-disable declaration-no-important */
4
+ /* stylelint-disable scale-unlimited/declaration-strict-value */
5
+ /* stylelint-disable property-disallowed-list */
6
+ .Draftail--text-alignment-control {
7
+ cursor: default !important;
8
+ position: relative;
9
+ display: inline-block;
10
+ margin-inline-end: 0.625rem;
11
+ background: none !important;
12
+ border-width: 0 !important;
13
+ outline-width: 0 !important;
14
+ }
15
+
16
+ .Draftail--text-alignment-dropdown {
17
+ display: none;
18
+ position: absolute;
19
+ top: 100%;
20
+ left: 0;
21
+ z-index: 100;
22
+ min-width: 180px;
23
+ max-height: 260px;
24
+ overflow: hidden;
25
+ margin: 0;
26
+ padding: 4px 0;
27
+ list-style: none;
28
+ background: var(--w-color-surface-page, #fff);
29
+ border: 1px solid var(--w-color-border-furniture, #ddd);
30
+ border-radius: 4px;
31
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
32
+ }
33
+
34
+ .Draftail--text-alignment-dropdown[aria-expanded='true'] {
35
+ display: flex;
36
+ align-items: center;
37
+ justify-content: space-evenly;
38
+ overflow: inherit;
39
+ }
40
+
41
+ .Draftail--text-alignment-option {
42
+ z-index: 10;
43
+ }
44
+
45
+ .Draftail--text-alignment-icon {
46
+ font-family: serif;
47
+ font-size: 14px;
48
+ font-weight: 700;
49
+ }
50
+
51
+ .Draftail-block--ALIGNMENT_LEFT {
52
+ text-align: start;
53
+ }
54
+
55
+ .Draftail-block--ALIGNMENT_CENTER {
56
+ text-align: center;
57
+ }
58
+
59
+ .Draftail-block--ALIGNMENT_RIGHT {
60
+ text-align: end;
61
+ }
62
+
63
+ .Draftail-block--ALIGNMENT_JUSTIFY {
64
+ text-align: justify;
65
+ }
66
+
67
+ .Draftail-block--ALIGNMENT_LEFT > *,
68
+ .Draftail-block--ALIGNMENT_CENTER > *,
69
+ .Draftail-block--ALIGNMENT_RIGHT > *,
70
+ .Draftail-block--ALIGNMENT_JUSTIFY > * {
71
+ text-align: inherit;
72
+ }
@@ -0,0 +1,117 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ /* stylelint-disable declaration-property-value-allowed-list */
3
+ /* stylelint-disable declaration-no-important */
4
+ /* stylelint-disable scale-unlimited/declaration-strict-value */
5
+ /* stylelint-disable property-disallowed-list */
6
+ /* stylelint-disable color-named */
7
+ /* stylelint-disable selector-type-no-unknown */
8
+ .Draftail--text-color-control {
9
+ cursor: default !important;
10
+ position: relative;
11
+ display: inline-block;
12
+ margin-inline-end: 0.625rem;
13
+ background: none !important;
14
+ border-width: 0 !important;
15
+ outline-width: 0 !important;
16
+ }
17
+
18
+ .Draftail--text-color-input-wrapper {
19
+ display: inline-flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ }
23
+
24
+ input.Draftail--text-color-input {
25
+ cursor: pointer;
26
+ display: inline-flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ min-height: 0;
30
+ height: 1.875rem;
31
+ font-size: 1rem;
32
+ padding-inline: 0.25rem;
33
+ }
34
+
35
+ input.Draftail--text-color-input::placeholder {
36
+ font-size: 0.75rem;
37
+ text-align: center;
38
+ top: -0.09375rem;
39
+ position: relative;
40
+ }
41
+
42
+ .Draftail--text-color-dropdown {
43
+ position: absolute;
44
+ top: 100%;
45
+ left: 0;
46
+ z-index: 100;
47
+ }
48
+
49
+ .Draftail--text-color-dropdown[aria-expanded='false'] {
50
+ border: 0;
51
+ clip: rect(0 0 0 0);
52
+ clip-path: inset(50%);
53
+ height: 1px;
54
+ margin: -1px;
55
+ overflow: hidden;
56
+ padding: 0;
57
+ position: absolute;
58
+ white-space: nowrap;
59
+ width: 1px;
60
+ }
61
+
62
+ .Draftail--text-color-dropdown[aria-expanded='true'] {
63
+ display: flex;
64
+ flex-flow: row wrap;
65
+ justify-content: center;
66
+ align-items: center;
67
+ gap: 4px;
68
+ min-width: calc((1.875rem * 4) + 24px);
69
+ max-height: 260px;
70
+ overflow: inherit;
71
+ margin: 0;
72
+ padding: 0.5rem 4px;
73
+ background: var(--w-color-surface-page, #fff);
74
+ border: 1px solid var(--w-color-border-furniture, #ddd);
75
+ border-radius: 4px;
76
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
77
+ }
78
+
79
+ .Draftail--text-color-option-wrapper {
80
+ flex: 1 0 calc(25% - 12px);
81
+ }
82
+
83
+ .Draftail--text-color-option {
84
+ position: relative;
85
+ background: attr(name type(<color>), black) !important;
86
+ border: 0.3125rem solid var(--w-color-surface-menu-hover, #e8e8e8);
87
+ }
88
+
89
+ .Draftail--text-color-option:hover,
90
+ .Draftail--text-color-option.Draftail-ToolbarButton--active {
91
+ border: 0.3125rem solid var(--w-color-text-button-outline-default, #007d7e) !important;
92
+ }
93
+
94
+ .Draftail--text-color-hr {
95
+ width: 100%;
96
+ }
97
+
98
+ .Draftail--text-color-option > .Draftail-ToolbarButton__label {
99
+ display: none;
100
+ }
101
+
102
+ .Draftail--text-color-option.Draftail-ToolbarButton--active
103
+ > .Draftail-ToolbarButton__label {
104
+ display: inline-block;
105
+ position: relative;
106
+ text-align: center;
107
+ top: -2px;
108
+ color: var(--w-color-text-button-outline-default, #007d7e);
109
+ }
110
+
111
+ color-input::part(gamut) {
112
+ display: none !important;
113
+ }
114
+
115
+ color-input::part(panel) {
116
+ max-inline-size: 15rem;
117
+ }
@@ -0,0 +1,149 @@
1
+ // https://github.com/wagtail/draftail/blob/main/src/components/Toolbar/ToolbarButton.tsx
2
+ // export interface ToolbarButtonProps {
3
+ // name?: string;
4
+ // active?: boolean;
5
+ // label?: string | null;
6
+ // title?: string | null;
7
+ // icon?: IconProp | null;
8
+ // className?: string | null;
9
+ // tooltipDirection?: "up" | "down";
10
+ // onClick?: ((name: string) => void) | null;
11
+ // }
12
+
13
+ (function () {
14
+ var React = window.React;
15
+ var RichUtils = window.DraftJS.RichUtils;
16
+ var ToolbarButton = window.Draftail.ToolbarButton;
17
+ var data = window.draftailTextUtils || {};
18
+ var options = data.customFontFamilies || [];
19
+ const type_ = 'font-family';
20
+ const control = JSON.parse(
21
+ document.getElementById(`draftail-plugin-control-${type_}`).textContent,
22
+ );
23
+
24
+ // ── Helper to find active font family ──
25
+ function getActiveOption(editorState) {
26
+ const currentStyle = editorState.getCurrentInlineStyle();
27
+ return options.find((opt) => currentStyle.has(opt.type));
28
+ }
29
+
30
+ class FontFamilyControl extends React.Component {
31
+ constructor(props) {
32
+ super(props);
33
+ this.state = {
34
+ isOpen: false,
35
+ };
36
+ this.controlRef = React.createRef();
37
+ }
38
+
39
+ componentDidMount() {
40
+ document.addEventListener('mousedown', this.handleClickOutside);
41
+ }
42
+
43
+ componentWillUnmount() {
44
+ document.removeEventListener('mousedown', this.handleClickOutside);
45
+ }
46
+
47
+ // ── close dropdown when clicking outside ──
48
+ handleClickOutside = (event) => {
49
+ if (
50
+ this.controlRef.current &&
51
+ !this.controlRef.current.contains(event.target)
52
+ ) {
53
+ this.setState({ isOpen: false });
54
+ }
55
+ };
56
+
57
+ // ── toggle dropdown (used by button) ──
58
+ toggleDropdown = (force) => {
59
+ this.setState((prevState) => ({
60
+ isOpen: typeof force === 'boolean' ? force : !prevState.isOpen,
61
+ }));
62
+ };
63
+
64
+ // ── apply a font family ──
65
+ handleOptionClick = (opt) => {
66
+ const { getEditorState, onChange } = this.props;
67
+ let newState = getEditorState();
68
+ const currentStyle = newState.getCurrentInlineStyle();
69
+
70
+ // Remove any active font-family styles first
71
+ options.forEach((item) => {
72
+ if (currentStyle.has(item.type)) {
73
+ newState = RichUtils.toggleInlineStyle(newState, item.type);
74
+ }
75
+ });
76
+
77
+ // Apply the selected one
78
+ newState = RichUtils.toggleInlineStyle(newState, opt.type);
79
+ onChange(newState);
80
+
81
+ // Close the dropdown
82
+ this.setState({ isOpen: false });
83
+ };
84
+
85
+ render() {
86
+ const { getEditorState } = this.props;
87
+ const editorState = getEditorState();
88
+ const activeOption = getActiveOption(editorState);
89
+ const isOpen = this.state.isOpen;
90
+ const icon = `#icon-${control.icon}`;
91
+
92
+ // ── Dropdown list ──
93
+ const dropdown = React.createElement(
94
+ 'ul',
95
+ {
96
+ 'className': 'Draftail--font-family-dropdown',
97
+ 'aria-expanded': isOpen,
98
+ },
99
+ options.map((opt) =>
100
+ React.createElement(
101
+ 'li',
102
+ {
103
+ 'key': opt.type,
104
+ 'onMouseDown': (e) => {
105
+ // Prevent the blur on the button before the click is processed
106
+ e.preventDefault();
107
+ this.handleOptionClick(opt);
108
+ },
109
+ 'style': { fontFamily: opt.style.fontFamily },
110
+ 'className': 'Draftail--font-family-option',
111
+ 'aria-selected': activeOption
112
+ ? activeOption.type === opt.type
113
+ : false,
114
+ },
115
+ opt.label,
116
+ ),
117
+ ),
118
+ );
119
+
120
+ // ── Toolbar button ──
121
+ const button = React.createElement(ToolbarButton, {
122
+ name: control.type.toUpperCase(),
123
+ active: !!activeOption,
124
+ title: activeOption ? activeOption.label : control.label,
125
+ icon: icon,
126
+ tooltipDirection: 'up',
127
+ onClick: () => this.toggleDropdown(),
128
+ });
129
+
130
+ return React.createElement(
131
+ 'div',
132
+ {
133
+ className: 'Draftail--font-family-control',
134
+ ref: this.controlRef,
135
+ },
136
+ dropdown,
137
+ button,
138
+ );
139
+ }
140
+ }
141
+
142
+ window.draftail.registerPlugin(
143
+ {
144
+ type: control.type,
145
+ inline: FontFamilyControl,
146
+ },
147
+ 'controls',
148
+ );
149
+ })();