@atlaskit/editor-plugin-rule 17.0.1 → 18.1.0

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 (43) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/pm-plugins/commands.js +69 -2
  3. package/dist/cjs/rulePlugin.js +1 -1
  4. package/dist/cjs/ui/DividerOptions.compiled.css +12 -0
  5. package/dist/cjs/ui/DividerOptions.js +165 -0
  6. package/dist/cjs/ui/constants.js +8 -0
  7. package/dist/cjs/ui/icons/DashedStrokeIcon.js +33 -0
  8. package/dist/cjs/ui/icons/DottedStrokeIcon.js +34 -0
  9. package/dist/cjs/ui/icons/FadeStrokeIcon.js +43 -0
  10. package/dist/cjs/ui/icons/SketchStrokeIcon.js +24 -0
  11. package/dist/cjs/ui/icons/SolidStrokeIcon.js +32 -0
  12. package/dist/cjs/ui/toolbar.js +39 -8
  13. package/dist/es2019/pm-plugins/commands.js +66 -1
  14. package/dist/es2019/rulePlugin.js +2 -2
  15. package/dist/es2019/ui/DividerOptions.compiled.css +12 -0
  16. package/dist/es2019/ui/DividerOptions.js +147 -0
  17. package/dist/es2019/ui/constants.js +2 -0
  18. package/dist/es2019/ui/icons/DashedStrokeIcon.js +24 -0
  19. package/dist/es2019/ui/icons/DottedStrokeIcon.js +25 -0
  20. package/dist/es2019/ui/icons/FadeStrokeIcon.js +34 -0
  21. package/dist/es2019/ui/icons/SketchStrokeIcon.js +15 -0
  22. package/dist/es2019/ui/icons/SolidStrokeIcon.js +23 -0
  23. package/dist/es2019/ui/toolbar.js +39 -9
  24. package/dist/esm/pm-plugins/commands.js +67 -1
  25. package/dist/esm/rulePlugin.js +2 -2
  26. package/dist/esm/ui/DividerOptions.compiled.css +12 -0
  27. package/dist/esm/ui/DividerOptions.js +156 -0
  28. package/dist/esm/ui/constants.js +2 -0
  29. package/dist/esm/ui/icons/DashedStrokeIcon.js +26 -0
  30. package/dist/esm/ui/icons/DottedStrokeIcon.js +27 -0
  31. package/dist/esm/ui/icons/FadeStrokeIcon.js +36 -0
  32. package/dist/esm/ui/icons/SketchStrokeIcon.js +17 -0
  33. package/dist/esm/ui/icons/SolidStrokeIcon.js +25 -0
  34. package/dist/esm/ui/toolbar.js +40 -9
  35. package/dist/types/pm-plugins/commands.d.ts +3 -0
  36. package/dist/types/ui/DividerOptions.d.ts +14 -0
  37. package/dist/types/ui/constants.d.ts +5 -0
  38. package/dist/types/ui/icons/DashedStrokeIcon.d.ts +2 -0
  39. package/dist/types/ui/icons/DottedStrokeIcon.d.ts +2 -0
  40. package/dist/types/ui/icons/FadeStrokeIcon.d.ts +2 -0
  41. package/dist/types/ui/icons/SketchStrokeIcon.d.ts +2 -0
  42. package/dist/types/ui/icons/SolidStrokeIcon.d.ts +2 -0
  43. package/package.json +11 -6
@@ -0,0 +1,12 @@
1
+ ._1vy41mok>button{border-radius:var(--ds-radius-large,8px)}
2
+ ._2rko1mok{border-radius:var(--ds-radius-large,8px)}
3
+ ._zulpu2gc{gap:var(--ds-space-100,8px)}
4
+ ._18zrutpp{padding-inline:var(--ds-space-150,9pt)}
5
+ ._1rjc1b66{padding-block:var(--ds-space-050,4px)}._16jlkb7n{flex-grow:1}
6
+ ._18m915vq{overflow-y:hidden}
7
+ ._1bsb1osq{width:100%}
8
+ ._1e0c1txw{display:flex}
9
+ ._1reo15vq{overflow-x:hidden}
10
+ ._4t3i5jys{height:11pc}
11
+ ._r55q1osq>button{width:100%}
12
+ ._ug5l1h6o>button{justify-content:center}
@@ -0,0 +1,147 @@
1
+ /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.1 */
2
+ import "./DividerOptions.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { useCallback } from 'react';
5
+ import { useIntl } from 'react-intl';
6
+ import IconButton from '@atlaskit/button/icon/button';
7
+ import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
8
+ import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
9
+ import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
10
+ import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
11
+ import { Box, Text } from '@atlaskit/primitives/compiled';
12
+ import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
13
+ import { FadeStrokeIcon } from './icons/FadeStrokeIcon';
14
+ import { SketchStrokeIcon } from './icons/SketchStrokeIcon';
15
+ import { SolidStrokeIcon } from './icons/SolidStrokeIcon';
16
+ import { DashedStrokeIcon } from './icons/DashedStrokeIcon';
17
+ import { DottedStrokeIcon } from './icons/DottedStrokeIcon';
18
+ const styles = {
19
+ container: "_18zrutpp _4t3i5jys",
20
+ section: "_1rjc1b66",
21
+ dividerOptionsContainer: "_zulpu2gc _1e0c1txw _1bsb1osq",
22
+ dividerOptionsButtonContainer: "_1rjc1b66"
23
+ };
24
+ const dividerOptionsButtonStyles = null;
25
+ const SmallWeightIcon = iconProps => /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
26
+ color: "var(--ds-icon-subtle, #505258)",
27
+ label: iconProps.label
28
+ });
29
+ const MediumWeightIcon = iconProps => /*#__PURE__*/React.createElement(StrokeWeightMediumIcon, {
30
+ color: "var(--ds-icon-subtle, #505258)",
31
+ label: iconProps.label
32
+ });
33
+ const LargeWeightIcon = iconProps => /*#__PURE__*/React.createElement(StrokeWeightLargeIcon, {
34
+ color: "var(--ds-icon-subtle, #505258)",
35
+ label: iconProps.label
36
+ });
37
+ const weightOptions = [{
38
+ icon: SmallWeightIcon,
39
+ label: messages.smallDivider,
40
+ value: 1
41
+ }, {
42
+ icon: MediumWeightIcon,
43
+ label: messages.mediumDivider,
44
+ value: 2
45
+ }, {
46
+ icon: LargeWeightIcon,
47
+ label: messages.largeDivider,
48
+ value: 3
49
+ }];
50
+ const styleOptionRows = [
51
+ // row 1
52
+ [{
53
+ icon: SolidStrokeIcon,
54
+ label: messages.solidDivider,
55
+ value: 'solid'
56
+ }, {
57
+ icon: DashedStrokeIcon,
58
+ label: messages.dashedDivider,
59
+ value: 'dashed'
60
+ }, {
61
+ icon: DottedStrokeIcon,
62
+ label: messages.dottedDivider,
63
+ value: 'dotted'
64
+ }],
65
+ // row 2
66
+ [{
67
+ icon: SketchStrokeIcon,
68
+ label: messages.sketchDivider,
69
+ value: 'sketch'
70
+ }, {
71
+ icon: FadeStrokeIcon,
72
+ label: messages.fadeDivider,
73
+ value: 'fade'
74
+ }]];
75
+ const DividerOptionButton = ({
76
+ icon,
77
+ isSelected,
78
+ label,
79
+ onSelect,
80
+ value
81
+ }) => {
82
+ const handleClick = useCallback(() => onSelect === null || onSelect === void 0 ? void 0 : onSelect(value), [onSelect, value]);
83
+ return /*#__PURE__*/React.createElement("div", {
84
+ className: ax(["_2rko1mok _1reo15vq _18m915vq _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq"])
85
+ }, /*#__PURE__*/React.createElement(IconButton, {
86
+ icon: icon,
87
+ isSelected: isSelected,
88
+ label: label,
89
+ onClick: handleClick
90
+ }));
91
+ };
92
+ export const DividerOptions = ({
93
+ onStyleChange,
94
+ onWeightChange,
95
+ style,
96
+ weight
97
+ }) => {
98
+ const {
99
+ formatMessage
100
+ } = useIntl();
101
+ const selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
102
+ const selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
103
+ return /*#__PURE__*/React.createElement(Box, {
104
+ xcss: styles.container
105
+ }, /*#__PURE__*/React.createElement(Box, {
106
+ xcss: styles.section
107
+ }, /*#__PURE__*/React.createElement(Text, {
108
+ weight: "bold",
109
+ color: "color.text.subtle"
110
+ }, formatMessage(messages.weight)), /*#__PURE__*/React.createElement(Box, {
111
+ xcss: styles.dividerOptionsButtonContainer
112
+ }, /*#__PURE__*/React.createElement(Box, {
113
+ xcss: styles.dividerOptionsContainer
114
+ }, weightOptions.map(({
115
+ icon,
116
+ label,
117
+ value
118
+ }) => /*#__PURE__*/React.createElement(DividerOptionButton, {
119
+ key: value,
120
+ icon: icon,
121
+ isSelected: selectedWeight === value,
122
+ label: formatMessage(label),
123
+ onSelect: onWeightChange,
124
+ value: value
125
+ }))))), /*#__PURE__*/React.createElement(Box, {
126
+ xcss: styles.section
127
+ }, /*#__PURE__*/React.createElement(Text, {
128
+ weight: "bold",
129
+ color: "color.text.subtle"
130
+ }, formatMessage(messages.style)), styleOptionRows.map(options => /*#__PURE__*/React.createElement(Box, {
131
+ key: options[0].value,
132
+ xcss: styles.dividerOptionsButtonContainer
133
+ }, /*#__PURE__*/React.createElement(Box, {
134
+ xcss: styles.dividerOptionsContainer
135
+ }, options.map(({
136
+ icon,
137
+ label,
138
+ value
139
+ }) => /*#__PURE__*/React.createElement(DividerOptionButton, {
140
+ key: value,
141
+ icon: icon,
142
+ isSelected: selectedStyle === value,
143
+ label: formatMessage(label),
144
+ onSelect: onStyleChange,
145
+ value: value
146
+ })))))));
147
+ };
@@ -0,0 +1,2 @@
1
+ export const DEFAULT_DIVIDER_STYLE = 'solid';
2
+ export const DEFAULT_DIVIDER_WEIGHT = 2;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ const CustomGlyph = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "44",
4
+ height: "8",
5
+ viewBox: "0 0 44 8",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("g", {
9
+ clipPath: "url(#clip0_238_17349)"
10
+ }, /*#__PURE__*/React.createElement("path", {
11
+ d: "M-78 4H122",
12
+ stroke: "var(--ds-icon-subtle, #505258)",
13
+ strokeWidth: "2",
14
+ strokeDasharray: "4 6"
15
+ })), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
16
+ id: "clip0_238_17349"
17
+ }, /*#__PURE__*/React.createElement("rect", {
18
+ width: "44",
19
+ height: "8",
20
+ fill: "white"
21
+ }))));
22
+ export const DashedStrokeIcon = () => {
23
+ return /*#__PURE__*/React.createElement(CustomGlyph, null);
24
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ const CustomGlyph = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "44",
4
+ height: "8",
5
+ viewBox: "0 0 44 8",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("g", {
9
+ clipPath: "url(#clip0_238_2909)"
10
+ }, /*#__PURE__*/React.createElement("path", {
11
+ d: "M-78 4H122",
12
+ stroke: "var(--ds-icon, #292A2E)",
13
+ strokeWidth: "2",
14
+ strokeLinecap: "round",
15
+ strokeDasharray: "0.01 6"
16
+ })), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
17
+ id: "clip0_238_2909"
18
+ }, /*#__PURE__*/React.createElement("rect", {
19
+ width: "44",
20
+ height: "8",
21
+ fill: "white"
22
+ }))));
23
+ export const DottedStrokeIcon = () => {
24
+ return /*#__PURE__*/React.createElement(CustomGlyph, null);
25
+ };
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ const CustomGlyph = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "79",
4
+ height: "2",
5
+ viewBox: "0 0 79 2",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("path", {
9
+ d: "M0 1C1.31667 1.06667 2.63333 1.13 3.95 1.19C15.8 1.73 27.65 2 39.5 2C51.35 2 63.2 1.73 75.05 1.19C76.3667 1.13 77.6833 1.06667 79 1C77.6833 0.933333 76.3667 0.87 75.05 0.81C63.2 0.27 51.35 0 39.5 0C27.65 0 15.8 0.27 3.95 0.81C2.63333 0.87 1.31667 0.933333 0 1Z",
10
+ fill: "url(#paint0_linear_238_2941)"
11
+ }), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("linearGradient", {
12
+ id: "paint0_linear_238_2941",
13
+ x1: "0",
14
+ y1: "1.5",
15
+ x2: "79",
16
+ y2: "1.5",
17
+ gradientUnits: "userSpaceOnUse"
18
+ }, /*#__PURE__*/React.createElement("stop", {
19
+ stopColor: "var(--ds-icon, #292A2E)",
20
+ stopOpacity: 0
21
+ }), /*#__PURE__*/React.createElement("stop", {
22
+ offset: "0.274038",
23
+ stopColor: "var(--ds-icon, #292A2E)"
24
+ }), /*#__PURE__*/React.createElement("stop", {
25
+ offset: "0.740385",
26
+ stopColor: "var(--ds-icon, #292A2E)"
27
+ }), /*#__PURE__*/React.createElement("stop", {
28
+ offset: "1",
29
+ stopColor: "var(--ds-icon, #292A2E)",
30
+ stopOpacity: 0
31
+ }))));
32
+ export const FadeStrokeIcon = () => {
33
+ return /*#__PURE__*/React.createElement(CustomGlyph, null);
34
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ const CustomGlyph = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "83",
4
+ height: "6",
5
+ viewBox: "0 0 83 6",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("path", {
9
+ d: "M0.428223 4.0112C0.428223 4.0112 6.35543 1.20063 10.4282 1.0112C15.2535 0.786762 17.5977 4.0112 22.4282 4.0112C27.2587 4.0112 29.5977 1.01007 34.4282 1.0112C38.8335 1.01222 41.0265 3.33342 45.4282 3.5112C50.7856 3.72757 53.5691 0.845277 58.9282 1.0112C63.5219 1.15342 65.8325 3.47137 70.4282 3.5112C75.215 3.55267 77.6415 1.04949 82.4282 1.0112",
10
+ stroke: "var(--ds-icon, #292A2E)",
11
+ strokeWidth: "2"
12
+ }));
13
+ export const SketchStrokeIcon = () => {
14
+ return /*#__PURE__*/React.createElement(CustomGlyph, null);
15
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ const CustomGlyph = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "44",
4
+ height: "8",
5
+ viewBox: "0 0 44 8",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("g", {
9
+ clipPath: "url(#clip0_238_17340)"
10
+ }, /*#__PURE__*/React.createElement("path", {
11
+ d: "M-78 4H122",
12
+ stroke: "var(--ds-icon, #292A2E)",
13
+ strokeWidth: "2"
14
+ })), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
15
+ id: "clip0_238_17340"
16
+ }, /*#__PURE__*/React.createElement("rect", {
17
+ width: "44",
18
+ height: "8",
19
+ fill: "white"
20
+ }))));
21
+ export const SolidStrokeIcon = () => {
22
+ return /*#__PURE__*/React.createElement(CustomGlyph, null);
23
+ };
@@ -2,12 +2,15 @@ import React from 'react';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
4
  import commonMessages from '@atlaskit/editor-common/messages';
5
+ import { ruleMessages } from '@atlaskit/editor-common/messages/rule';
5
6
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
6
7
  import CopyIcon from '@atlaskit/icon/core/copy';
8
+ import CustomizeIcon from '@atlaskit/icon/core/customize';
7
9
  import DeleteIcon from '@atlaskit/icon/core/delete';
8
- import { removeHorizontalRule } from '../pm-plugins/commands';
9
- const getToolbarItems = (formatMessage, ruleNodeType, api) => {
10
- var _api$decorations, _api$analytics;
10
+ import { removeHorizontalRule, updateHorizontalRuleStyle, updateHorizontalRuleWeight } from '../pm-plugins/commands';
11
+ import { DividerOptions } from './DividerOptions';
12
+ const getToolbarItems = (formatMessage, ruleNodeType, ruleAttrs, api) => {
13
+ var _api$decorations, _api$analytics3;
11
14
  const hoverDecoration = api === null || api === void 0 ? void 0 : (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
12
15
  const hoverDecorationProps = className => ({
13
16
  onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
@@ -15,7 +18,34 @@ const getToolbarItems = (formatMessage, ruleNodeType, api) => {
15
18
  onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
16
19
  onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className)
17
20
  });
18
- const items = [];
21
+ const items = [{
22
+ id: 'divider-options',
23
+ type: 'dropdown',
24
+ testId: 'divider-options',
25
+ title: formatMessage(ruleMessages.dividerOptions),
26
+ iconBefore: CustomizeIcon,
27
+ options: {
28
+ width: 272,
29
+ height: 184,
30
+ render: ({
31
+ dispatchCommand
32
+ }) => /*#__PURE__*/React.createElement(DividerOptions, {
33
+ style: ruleAttrs.style,
34
+ weight: ruleAttrs.weight,
35
+ onStyleChange: style => {
36
+ var _api$analytics;
37
+ return dispatchCommand(updateHorizontalRuleStyle(style, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
38
+ },
39
+ onWeightChange: weight => {
40
+ var _api$analytics2;
41
+ return dispatchCommand(updateHorizontalRuleWeight(weight, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions));
42
+ }
43
+ })
44
+ }
45
+ }, {
46
+ type: 'separator',
47
+ fullHeight: true
48
+ }];
19
49
  const overflowMenuItems = [{
20
50
  type: 'overflow-dropdown',
21
51
  options: [{
@@ -34,7 +64,7 @@ const getToolbarItems = (formatMessage, ruleNodeType, api) => {
34
64
  icon: /*#__PURE__*/React.createElement(DeleteIcon, {
35
65
  label: ""
36
66
  }),
37
- onClick: removeHorizontalRule(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
67
+ onClick: removeHorizontalRule(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions),
38
68
  ...hoverDecorationProps()
39
69
  }]
40
70
  }];
@@ -51,8 +81,8 @@ export const getToolbarConfig = (state, intl, api) => {
51
81
  const {
52
82
  rule
53
83
  } = state.schema.nodes;
54
- const isRuleSelection = findSelectedNodeOfType(state.schema.nodes.rule)(state.selection);
55
- if (!isRuleSelection) {
84
+ const ruleNode = findSelectedNodeOfType(state.schema.nodes.rule)(state.selection);
85
+ if (!ruleNode) {
56
86
  return undefined;
57
87
  }
58
88
  const getDomRef = editorView => {
@@ -61,10 +91,10 @@ export const getToolbarConfig = (state, intl, api) => {
61
91
  return element;
62
92
  };
63
93
  return {
64
- title: 'Divider floating controls',
94
+ title: formatMessage(ruleMessages.dividerFloatingControls),
65
95
  getDomRef,
66
96
  nodeType: [rule],
67
- items: getToolbarItems(formatMessage, rule, api),
97
+ items: getToolbarItems(formatMessage, rule, ruleNode.node.attrs, api),
68
98
  scrollable: true
69
99
  };
70
100
  };
@@ -1,6 +1,10 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { createHorizontalRule } from './input-rule';
3
5
  import { findSelectedNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
6
+ import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from '../ui/constants';
7
+ import { createHorizontalRule } from './input-rule';
4
8
  export var insertHorizontalRule = function insertHorizontalRule(editorAnalyticsAPI) {
5
9
  return function (inputMethod) {
6
10
  return function (state, dispatch) {
@@ -36,4 +40,66 @@ export var removeHorizontalRule = function removeHorizontalRule(editorAnalyticsA
36
40
  }
37
41
  return true;
38
42
  };
43
+ };
44
+ export var updateHorizontalRuleWeight = function updateHorizontalRuleWeight(weight, editorAnalyticsAPI) {
45
+ return function (state, dispatch) {
46
+ var _selectedRule$node$at;
47
+ var rule = state.schema.nodes.rule;
48
+ var selectedRule = findSelectedNodeOfType(rule)(state.selection);
49
+ if (!selectedRule) {
50
+ return false;
51
+ }
52
+ var previousWeight = (_selectedRule$node$at = selectedRule.node.attrs.weight) !== null && _selectedRule$node$at !== void 0 ? _selectedRule$node$at : DEFAULT_DIVIDER_WEIGHT;
53
+ if (previousWeight === weight) {
54
+ return true;
55
+ }
56
+ if (dispatch) {
57
+ var updateTr = state.tr.setNodeMarkup(selectedRule.pos, undefined, _objectSpread(_objectSpread({}, selectedRule.node.attrs), {}, {
58
+ weight: weight
59
+ }));
60
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
61
+ action: ACTION.UPDATED,
62
+ actionSubject: ACTION_SUBJECT.DIVIDER,
63
+ attributes: {
64
+ inputMethod: INPUT_METHOD.FLOATING_TB,
65
+ previousWeight: previousWeight,
66
+ weight: weight
67
+ },
68
+ eventType: EVENT_TYPE.TRACK
69
+ })(updateTr);
70
+ dispatch(updateTr);
71
+ }
72
+ return true;
73
+ };
74
+ };
75
+ export var updateHorizontalRuleStyle = function updateHorizontalRuleStyle(style, editorAnalyticsAPI) {
76
+ return function (state, dispatch) {
77
+ var _selectedRule$node$at2;
78
+ var rule = state.schema.nodes.rule;
79
+ var selectedRule = findSelectedNodeOfType(rule)(state.selection);
80
+ if (!selectedRule) {
81
+ return false;
82
+ }
83
+ var previousStyle = (_selectedRule$node$at2 = selectedRule.node.attrs.style) !== null && _selectedRule$node$at2 !== void 0 ? _selectedRule$node$at2 : DEFAULT_DIVIDER_STYLE;
84
+ if (previousStyle === style) {
85
+ return true;
86
+ }
87
+ if (dispatch) {
88
+ var updateTr = state.tr.setNodeMarkup(selectedRule.pos, undefined, _objectSpread(_objectSpread({}, selectedRule.node.attrs), {}, {
89
+ style: style
90
+ }));
91
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
92
+ action: ACTION.UPDATED,
93
+ actionSubject: ACTION_SUBJECT.DIVIDER,
94
+ attributes: {
95
+ inputMethod: INPUT_METHOD.FLOATING_TB,
96
+ previousStyle: previousStyle,
97
+ style: style
98
+ },
99
+ eventType: EVENT_TYPE.TRACK
100
+ })(updateTr);
101
+ dispatch(updateTr);
102
+ }
103
+ return true;
104
+ };
39
105
  };
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import React from 'react';
5
- import { rule, ruleWithLocalId } from '@atlaskit/adf-schema/rule';
5
+ import { rule, ruleWithAttrs, ruleWithLocalId } from '@atlaskit/adf-schema/rule';
6
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
7
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
8
8
  import { IconDivider } from '@atlaskit/editor-common/assets';
@@ -32,7 +32,7 @@ export var rulePlugin = function rulePlugin(_ref) {
32
32
  nodes: function nodes() {
33
33
  return [{
34
34
  name: 'rule',
35
- node: fg('platform_editor_adf_with_localid') ? ruleWithLocalId : rule
35
+ node: isExperimentEnabled('platform_editor_lovability_dividers_attributes') ? ruleWithAttrs : fg('platform_editor_adf_with_localid') ? ruleWithLocalId : rule
36
36
  }];
37
37
  },
38
38
  actions: {
@@ -0,0 +1,12 @@
1
+ ._1vy41mok>button{border-radius:var(--ds-radius-large,8px)}
2
+ ._2rko1mok{border-radius:var(--ds-radius-large,8px)}
3
+ ._zulpu2gc{gap:var(--ds-space-100,8px)}
4
+ ._18zrutpp{padding-inline:var(--ds-space-150,9pt)}
5
+ ._1rjc1b66{padding-block:var(--ds-space-050,4px)}._16jlkb7n{flex-grow:1}
6
+ ._18m915vq{overflow-y:hidden}
7
+ ._1bsb1osq{width:100%}
8
+ ._1e0c1txw{display:flex}
9
+ ._1reo15vq{overflow-x:hidden}
10
+ ._4t3i5jys{height:11pc}
11
+ ._r55q1osq>button{width:100%}
12
+ ._ug5l1h6o>button{justify-content:center}
@@ -0,0 +1,156 @@
1
+ /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.1 */
2
+ import "./DividerOptions.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { useCallback } from 'react';
5
+ import { useIntl } from 'react-intl';
6
+ import IconButton from '@atlaskit/button/icon/button';
7
+ import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
8
+ import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
9
+ import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
10
+ import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
11
+ import { Box, Text } from '@atlaskit/primitives/compiled';
12
+ import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
13
+ import { FadeStrokeIcon } from './icons/FadeStrokeIcon';
14
+ import { SketchStrokeIcon } from './icons/SketchStrokeIcon';
15
+ import { SolidStrokeIcon } from './icons/SolidStrokeIcon';
16
+ import { DashedStrokeIcon } from './icons/DashedStrokeIcon';
17
+ import { DottedStrokeIcon } from './icons/DottedStrokeIcon';
18
+ var styles = {
19
+ container: "_18zrutpp _4t3i5jys",
20
+ section: "_1rjc1b66",
21
+ dividerOptionsContainer: "_zulpu2gc _1e0c1txw _1bsb1osq",
22
+ dividerOptionsButtonContainer: "_1rjc1b66"
23
+ };
24
+ var dividerOptionsButtonStyles = null;
25
+ var SmallWeightIcon = function SmallWeightIcon(iconProps) {
26
+ return /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
27
+ color: "var(--ds-icon-subtle, #505258)",
28
+ label: iconProps.label
29
+ });
30
+ };
31
+ var MediumWeightIcon = function MediumWeightIcon(iconProps) {
32
+ return /*#__PURE__*/React.createElement(StrokeWeightMediumIcon, {
33
+ color: "var(--ds-icon-subtle, #505258)",
34
+ label: iconProps.label
35
+ });
36
+ };
37
+ var LargeWeightIcon = function LargeWeightIcon(iconProps) {
38
+ return /*#__PURE__*/React.createElement(StrokeWeightLargeIcon, {
39
+ color: "var(--ds-icon-subtle, #505258)",
40
+ label: iconProps.label
41
+ });
42
+ };
43
+ var weightOptions = [{
44
+ icon: SmallWeightIcon,
45
+ label: messages.smallDivider,
46
+ value: 1
47
+ }, {
48
+ icon: MediumWeightIcon,
49
+ label: messages.mediumDivider,
50
+ value: 2
51
+ }, {
52
+ icon: LargeWeightIcon,
53
+ label: messages.largeDivider,
54
+ value: 3
55
+ }];
56
+ var styleOptionRows = [
57
+ // row 1
58
+ [{
59
+ icon: SolidStrokeIcon,
60
+ label: messages.solidDivider,
61
+ value: 'solid'
62
+ }, {
63
+ icon: DashedStrokeIcon,
64
+ label: messages.dashedDivider,
65
+ value: 'dashed'
66
+ }, {
67
+ icon: DottedStrokeIcon,
68
+ label: messages.dottedDivider,
69
+ value: 'dotted'
70
+ }],
71
+ // row 2
72
+ [{
73
+ icon: SketchStrokeIcon,
74
+ label: messages.sketchDivider,
75
+ value: 'sketch'
76
+ }, {
77
+ icon: FadeStrokeIcon,
78
+ label: messages.fadeDivider,
79
+ value: 'fade'
80
+ }]];
81
+ var DividerOptionButton = function DividerOptionButton(_ref) {
82
+ var icon = _ref.icon,
83
+ isSelected = _ref.isSelected,
84
+ label = _ref.label,
85
+ onSelect = _ref.onSelect,
86
+ value = _ref.value;
87
+ var handleClick = useCallback(function () {
88
+ return onSelect === null || onSelect === void 0 ? void 0 : onSelect(value);
89
+ }, [onSelect, value]);
90
+ return /*#__PURE__*/React.createElement("div", {
91
+ className: ax(["_2rko1mok _1reo15vq _18m915vq _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq"])
92
+ }, /*#__PURE__*/React.createElement(IconButton, {
93
+ icon: icon,
94
+ isSelected: isSelected,
95
+ label: label,
96
+ onClick: handleClick
97
+ }));
98
+ };
99
+ export var DividerOptions = function DividerOptions(_ref2) {
100
+ var onStyleChange = _ref2.onStyleChange,
101
+ onWeightChange = _ref2.onWeightChange,
102
+ style = _ref2.style,
103
+ weight = _ref2.weight;
104
+ var _useIntl = useIntl(),
105
+ formatMessage = _useIntl.formatMessage;
106
+ var selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
107
+ var selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
108
+ return /*#__PURE__*/React.createElement(Box, {
109
+ xcss: styles.container
110
+ }, /*#__PURE__*/React.createElement(Box, {
111
+ xcss: styles.section
112
+ }, /*#__PURE__*/React.createElement(Text, {
113
+ weight: "bold",
114
+ color: "color.text.subtle"
115
+ }, formatMessage(messages.weight)), /*#__PURE__*/React.createElement(Box, {
116
+ xcss: styles.dividerOptionsButtonContainer
117
+ }, /*#__PURE__*/React.createElement(Box, {
118
+ xcss: styles.dividerOptionsContainer
119
+ }, weightOptions.map(function (_ref3) {
120
+ var icon = _ref3.icon,
121
+ label = _ref3.label,
122
+ value = _ref3.value;
123
+ return /*#__PURE__*/React.createElement(DividerOptionButton, {
124
+ key: value,
125
+ icon: icon,
126
+ isSelected: selectedWeight === value,
127
+ label: formatMessage(label),
128
+ onSelect: onWeightChange,
129
+ value: value
130
+ });
131
+ })))), /*#__PURE__*/React.createElement(Box, {
132
+ xcss: styles.section
133
+ }, /*#__PURE__*/React.createElement(Text, {
134
+ weight: "bold",
135
+ color: "color.text.subtle"
136
+ }, formatMessage(messages.style)), styleOptionRows.map(function (options) {
137
+ return /*#__PURE__*/React.createElement(Box, {
138
+ key: options[0].value,
139
+ xcss: styles.dividerOptionsButtonContainer
140
+ }, /*#__PURE__*/React.createElement(Box, {
141
+ xcss: styles.dividerOptionsContainer
142
+ }, options.map(function (_ref4) {
143
+ var icon = _ref4.icon,
144
+ label = _ref4.label,
145
+ value = _ref4.value;
146
+ return /*#__PURE__*/React.createElement(DividerOptionButton, {
147
+ key: value,
148
+ icon: icon,
149
+ isSelected: selectedStyle === value,
150
+ label: formatMessage(label),
151
+ onSelect: onStyleChange,
152
+ value: value
153
+ });
154
+ })));
155
+ })));
156
+ };
@@ -0,0 +1,2 @@
1
+ export var DEFAULT_DIVIDER_STYLE = 'solid';
2
+ export var DEFAULT_DIVIDER_WEIGHT = 2;