@atlaskit/css 0.6.2 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/css
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#168289](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/168289)
8
+ [`5fe404687ca98`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5fe404687ca98) -
9
+ Add a test helper to reduce issues when migrating to Compiled CSS.
10
+
11
+ Change dom `Node`'s `textContent` property to remove `Compiled CSS definitions` except for
12
+ `Compiled style nodes`.
13
+
3
14
  ## 0.6.2
4
15
 
5
16
  ### Patch Changes
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ require("./inline-css");
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isExtendedElement = isExtendedElement;
8
+ exports.isStyleElement = isStyleElement;
9
+ exports.removeCssContent = removeCssContent;
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ 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; }
12
+ 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) { (0, _defineProperty2.default)(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; }
13
+ if (typeof Node !== 'undefined') {
14
+ /**
15
+ * Before overriding `textContent` property, we need to store the original, as well as a convenience
16
+ * property to access the original content with CSS. Remove CSS style definitions from `textContent` for none style nodes
17
+ */
18
+ var textContentDescriptor = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
19
+ Object.defineProperty(Node.prototype, 'textContentOriginal', {
20
+ enumerable: false,
21
+ get: function get() {
22
+ return textContentDescriptor.get.call(this);
23
+ },
24
+ set: undefined
25
+ });
26
+ Object.defineProperty(Node.prototype, 'textContentWithoutCss', {
27
+ enumerable: false,
28
+ get: function get() {
29
+ var _removeCssContent;
30
+ return (_removeCssContent = removeCssContent(this.textContentOriginal, this)) !== null && _removeCssContent !== void 0 ? _removeCssContent : '';
31
+ },
32
+ set: undefined
33
+ });
34
+ Object.defineProperty(Node.prototype, 'textContent', _objectSpread(_objectSpread({}, textContentDescriptor), {}, {
35
+ get: function get() {
36
+ return isStyleElement(this) ? this.textContentOriginal : this.textContentWithoutCss;
37
+ }
38
+ }));
39
+ }
40
+
41
+ /**
42
+ * Check if a node is a `style` node with type guard
43
+ * @param node Node
44
+ * @returns boolean
45
+ */
46
+ function isStyleElement(node) {
47
+ return isExtendedElement(node) && node.tagName.toLowerCase() === 'style' && node.hasAttribute('data-cmpld');
48
+ }
49
+ function isExtendedElement(node) {
50
+ return !!node && node.nodeType === node.ELEMENT_NODE && typeof node.textContentOriginal === 'string';
51
+ }
52
+
53
+ /**
54
+ * Return an array of CSS style definitions as text from a node and recursively through
55
+ * the nodes children
56
+ *
57
+ * @param node Node
58
+ * @returns string[]
59
+ */
60
+ function getInnerCssContent(node) {
61
+ if (isStyleElement(node)) {
62
+ return [node.textContentOriginal];
63
+ }
64
+ if (!node.hasChildNodes() || !isExtendedElement(node)) {
65
+ return [];
66
+ }
67
+ var output = [];
68
+ node.querySelectorAll('style[data-cmpld]').forEach(function (style) {
69
+ if (isStyleElement(style)) {
70
+ var text = style.textContentOriginal;
71
+ if (text) {
72
+ output.push(text);
73
+ }
74
+ }
75
+ });
76
+ return output;
77
+ }
78
+
79
+ /**
80
+ * Return text with the inline CSS style definitions removed
81
+ *
82
+ * @param text string
83
+ * @param node
84
+ * @returns string
85
+ */
86
+ function removeCssContent(text, node) {
87
+ if (text === 0) {
88
+ return test.toString();
89
+ }
90
+ if (!text) {
91
+ return '';
92
+ }
93
+ return getInnerCssContent(node).reduce(function (cleanedText, cssContent) {
94
+ return cleanedText.replace(cssContent, '');
95
+ }, text.toString());
96
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ import './inline-css';
@@ -0,0 +1,83 @@
1
+ if (typeof Node !== 'undefined') {
2
+ /**
3
+ * Before overriding `textContent` property, we need to store the original, as well as a convenience
4
+ * property to access the original content with CSS. Remove CSS style definitions from `textContent` for none style nodes
5
+ */
6
+ const textContentDescriptor = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
7
+ Object.defineProperty(Node.prototype, 'textContentOriginal', {
8
+ enumerable: false,
9
+ get() {
10
+ return textContentDescriptor.get.call(this);
11
+ },
12
+ set: undefined
13
+ });
14
+ Object.defineProperty(Node.prototype, 'textContentWithoutCss', {
15
+ enumerable: false,
16
+ get() {
17
+ var _removeCssContent;
18
+ return (_removeCssContent = removeCssContent(this.textContentOriginal, this)) !== null && _removeCssContent !== void 0 ? _removeCssContent : '';
19
+ },
20
+ set: undefined
21
+ });
22
+ Object.defineProperty(Node.prototype, 'textContent', {
23
+ ...textContentDescriptor,
24
+ get() {
25
+ return isStyleElement(this) ? this.textContentOriginal : this.textContentWithoutCss;
26
+ }
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Check if a node is a `style` node with type guard
32
+ * @param node Node
33
+ * @returns boolean
34
+ */
35
+ export function isStyleElement(node) {
36
+ return isExtendedElement(node) && node.tagName.toLowerCase() === 'style' && node.hasAttribute('data-cmpld');
37
+ }
38
+ export function isExtendedElement(node) {
39
+ return !!node && node.nodeType === node.ELEMENT_NODE && typeof node.textContentOriginal === 'string';
40
+ }
41
+
42
+ /**
43
+ * Return an array of CSS style definitions as text from a node and recursively through
44
+ * the nodes children
45
+ *
46
+ * @param node Node
47
+ * @returns string[]
48
+ */
49
+ function getInnerCssContent(node) {
50
+ if (isStyleElement(node)) {
51
+ return [node.textContentOriginal];
52
+ }
53
+ if (!node.hasChildNodes() || !isExtendedElement(node)) {
54
+ return [];
55
+ }
56
+ const output = [];
57
+ node.querySelectorAll('style[data-cmpld]').forEach(style => {
58
+ if (isStyleElement(style)) {
59
+ const text = style.textContentOriginal;
60
+ if (text) {
61
+ output.push(text);
62
+ }
63
+ }
64
+ });
65
+ return output;
66
+ }
67
+
68
+ /**
69
+ * Return text with the inline CSS style definitions removed
70
+ *
71
+ * @param text string
72
+ * @param node
73
+ * @returns string
74
+ */
75
+ export function removeCssContent(text, node) {
76
+ if (text === 0) {
77
+ return test.toString();
78
+ }
79
+ if (!text) {
80
+ return '';
81
+ }
82
+ return getInnerCssContent(node).reduce((cleanedText, cssContent) => cleanedText.replace(cssContent, ''), text.toString());
83
+ }
File without changes
@@ -0,0 +1 @@
1
+ import './inline-css';
@@ -0,0 +1,87 @@
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; }
4
+ if (typeof Node !== 'undefined') {
5
+ /**
6
+ * Before overriding `textContent` property, we need to store the original, as well as a convenience
7
+ * property to access the original content with CSS. Remove CSS style definitions from `textContent` for none style nodes
8
+ */
9
+ var textContentDescriptor = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
10
+ Object.defineProperty(Node.prototype, 'textContentOriginal', {
11
+ enumerable: false,
12
+ get: function get() {
13
+ return textContentDescriptor.get.call(this);
14
+ },
15
+ set: undefined
16
+ });
17
+ Object.defineProperty(Node.prototype, 'textContentWithoutCss', {
18
+ enumerable: false,
19
+ get: function get() {
20
+ var _removeCssContent;
21
+ return (_removeCssContent = removeCssContent(this.textContentOriginal, this)) !== null && _removeCssContent !== void 0 ? _removeCssContent : '';
22
+ },
23
+ set: undefined
24
+ });
25
+ Object.defineProperty(Node.prototype, 'textContent', _objectSpread(_objectSpread({}, textContentDescriptor), {}, {
26
+ get: function get() {
27
+ return isStyleElement(this) ? this.textContentOriginal : this.textContentWithoutCss;
28
+ }
29
+ }));
30
+ }
31
+
32
+ /**
33
+ * Check if a node is a `style` node with type guard
34
+ * @param node Node
35
+ * @returns boolean
36
+ */
37
+ export function isStyleElement(node) {
38
+ return isExtendedElement(node) && node.tagName.toLowerCase() === 'style' && node.hasAttribute('data-cmpld');
39
+ }
40
+ export function isExtendedElement(node) {
41
+ return !!node && node.nodeType === node.ELEMENT_NODE && typeof node.textContentOriginal === 'string';
42
+ }
43
+
44
+ /**
45
+ * Return an array of CSS style definitions as text from a node and recursively through
46
+ * the nodes children
47
+ *
48
+ * @param node Node
49
+ * @returns string[]
50
+ */
51
+ function getInnerCssContent(node) {
52
+ if (isStyleElement(node)) {
53
+ return [node.textContentOriginal];
54
+ }
55
+ if (!node.hasChildNodes() || !isExtendedElement(node)) {
56
+ return [];
57
+ }
58
+ var output = [];
59
+ node.querySelectorAll('style[data-cmpld]').forEach(function (style) {
60
+ if (isStyleElement(style)) {
61
+ var text = style.textContentOriginal;
62
+ if (text) {
63
+ output.push(text);
64
+ }
65
+ }
66
+ });
67
+ return output;
68
+ }
69
+
70
+ /**
71
+ * Return text with the inline CSS style definitions removed
72
+ *
73
+ * @param text string
74
+ * @param node
75
+ * @returns string
76
+ */
77
+ export function removeCssContent(text, node) {
78
+ if (text === 0) {
79
+ return test.toString();
80
+ }
81
+ if (!text) {
82
+ return '';
83
+ }
84
+ return getInnerCssContent(node).reduce(function (cleanedText, cssContent) {
85
+ return cleanedText.replace(cssContent, '');
86
+ }, text.toString());
87
+ }
File without changes
@@ -0,0 +1 @@
1
+ import './inline-css';
@@ -0,0 +1,16 @@
1
+ import { type HTMLElementExtended, type HTMLStyleElementExtended } from './types';
2
+ /**
3
+ * Check if a node is a `style` node with type guard
4
+ * @param node Node
5
+ * @returns boolean
6
+ */
7
+ export declare function isStyleElement(node: Node): node is HTMLStyleElementExtended;
8
+ export declare function isExtendedElement(node?: Node): node is HTMLElementExtended;
9
+ /**
10
+ * Return text with the inline CSS style definitions removed
11
+ *
12
+ * @param text string
13
+ * @param node
14
+ * @returns string
15
+ */
16
+ export declare function removeCssContent(text: string | number | null | undefined, node: Node): string;
@@ -0,0 +1,5 @@
1
+ export type HTMLElementExtended<T extends HTMLElement = HTMLElement> = T & {
2
+ textContentOriginal: string;
3
+ textContentWithoutCss: string;
4
+ };
5
+ export type HTMLStyleElementExtended = HTMLElementExtended<HTMLStyleElement>;
@@ -0,0 +1 @@
1
+ import './inline-css';
@@ -0,0 +1,16 @@
1
+ import { type HTMLElementExtended, type HTMLStyleElementExtended } from './types';
2
+ /**
3
+ * Check if a node is a `style` node with type guard
4
+ * @param node Node
5
+ * @returns boolean
6
+ */
7
+ export declare function isStyleElement(node: Node): node is HTMLStyleElementExtended;
8
+ export declare function isExtendedElement(node?: Node): node is HTMLElementExtended;
9
+ /**
10
+ * Return text with the inline CSS style definitions removed
11
+ *
12
+ * @param text string
13
+ * @param node
14
+ * @returns string
15
+ */
16
+ export declare function removeCssContent(text: string | number | null | undefined, node: Node): string;
@@ -0,0 +1,5 @@
1
+ export type HTMLElementExtended<T extends HTMLElement = HTMLElement> = T & {
2
+ textContentOriginal: string;
3
+ textContentWithoutCss: string;
4
+ };
5
+ export type HTMLStyleElementExtended = HTMLElementExtended<HTMLStyleElement>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/css",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Style components backed by Atlassian Design System design tokens powered by Compiled CSS-in-JS.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,11 +44,13 @@
44
44
  ],
45
45
  "atlaskit:src": "src/index.tsx",
46
46
  "af:exports": {
47
- ".": "./src/index.tsx"
47
+ ".": "./src/index.tsx",
48
+ "./test-utils": "./src/test-utils/index.tsx"
48
49
  },
49
50
  "dependencies": {
50
- "@atlaskit/tokens": "^2.2.0",
51
+ "@atlaskit/tokens": "^2.4.0",
51
52
  "@babel/runtime": "^7.0.0",
53
+ "@compiled/jest": "^0.10.5",
52
54
  "@compiled/react": "^0.18.1"
53
55
  },
54
56
  "peerDependencies": {
@@ -57,7 +59,7 @@
57
59
  "devDependencies": {
58
60
  "@af/integration-testing": "*",
59
61
  "@af/visual-regression": "*",
60
- "@atlaskit/ds-lib": "^3.2.0",
62
+ "@atlaskit/ds-lib": "^3.3.0",
61
63
  "@atlaskit/ssr": "*",
62
64
  "@atlaskit/visual-regression": "*",
63
65
  "@emotion/react": "^11.7.1",
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@atlaskit/css/test-utils",
3
+ "main": "../dist/cjs/test-utils/index.js",
4
+ "module": "../dist/esm/test-utils/index.js",
5
+ "module:es2019": "../dist/es2019/test-utils/index.js",
6
+ "sideEffects": [
7
+ "**/*.compiled.css"
8
+ ],
9
+ "types": "../dist/types/test-utils/index.d.ts",
10
+ "typesVersions": {
11
+ ">=4.5 <5.4": {
12
+ "*": [
13
+ "../dist/types-ts4.5/test-utils/index.d.ts"
14
+ ]
15
+ }
16
+ }
17
+ }