@atlaskit/editor-toolbar-model 0.2.0 → 0.2.1

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,11 @@
1
1
  # @atlaskit/editor-toolbar-model
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
@@ -42,8 +42,31 @@ var createComponentRegistry = exports.createComponentRegistry = function createC
42
42
  var register = function register(newComponents) {
43
43
  components.push.apply(components, (0, _toConsumableArray2.default)(newComponents));
44
44
  };
45
+
46
+ /**
47
+ * Similer to `register` but first checks the registry against `newComponents` using its
48
+ * key and type, if it already exists it replaces the item instead of simply appending it.
49
+ *
50
+ * Most likely you should avoid using this and just use the `register` method as it's preferred
51
+ * to register components statically.
52
+ */
53
+ var safeRegister = function safeRegister(newComponents) {
54
+ newComponents.forEach(function (newComponent) {
55
+ var existingIndex = components.findIndex(function (existingComponent) {
56
+ return existingComponent.type === newComponent.type && existingComponent.key === newComponent.key;
57
+ });
58
+ if (existingIndex !== -1) {
59
+ // Replace existing component
60
+ components[existingIndex] = newComponent;
61
+ } else {
62
+ // Add new component
63
+ components.push(newComponent);
64
+ }
65
+ });
66
+ };
45
67
  return {
46
68
  register: register,
69
+ safeRegister: safeRegister,
47
70
  components: components
48
71
  };
49
72
  };
@@ -34,8 +34,29 @@ export const createComponentRegistry = () => {
34
34
  const register = newComponents => {
35
35
  components.push(...newComponents);
36
36
  };
37
+
38
+ /**
39
+ * Similer to `register` but first checks the registry against `newComponents` using its
40
+ * key and type, if it already exists it replaces the item instead of simply appending it.
41
+ *
42
+ * Most likely you should avoid using this and just use the `register` method as it's preferred
43
+ * to register components statically.
44
+ */
45
+ const safeRegister = newComponents => {
46
+ newComponents.forEach(newComponent => {
47
+ const existingIndex = components.findIndex(existingComponent => existingComponent.type === newComponent.type && existingComponent.key === newComponent.key);
48
+ if (existingIndex !== -1) {
49
+ // Replace existing component
50
+ components[existingIndex] = newComponent;
51
+ } else {
52
+ // Add new component
53
+ components.push(newComponent);
54
+ }
55
+ });
56
+ };
37
57
  return {
38
58
  register,
59
+ safeRegister,
39
60
  components
40
61
  };
41
62
  };
@@ -35,8 +35,31 @@ export var createComponentRegistry = function createComponentRegistry() {
35
35
  var register = function register(newComponents) {
36
36
  components.push.apply(components, _toConsumableArray(newComponents));
37
37
  };
38
+
39
+ /**
40
+ * Similer to `register` but first checks the registry against `newComponents` using its
41
+ * key and type, if it already exists it replaces the item instead of simply appending it.
42
+ *
43
+ * Most likely you should avoid using this and just use the `register` method as it's preferred
44
+ * to register components statically.
45
+ */
46
+ var safeRegister = function safeRegister(newComponents) {
47
+ newComponents.forEach(function (newComponent) {
48
+ var existingIndex = components.findIndex(function (existingComponent) {
49
+ return existingComponent.type === newComponent.type && existingComponent.key === newComponent.key;
50
+ });
51
+ if (existingIndex !== -1) {
52
+ // Replace existing component
53
+ components[existingIndex] = newComponent;
54
+ } else {
55
+ // Add new component
56
+ components.push(newComponent);
57
+ }
58
+ });
59
+ };
38
60
  return {
39
61
  register: register,
62
+ safeRegister: safeRegister,
40
63
  components: components
41
64
  };
42
65
  };
@@ -32,5 +32,6 @@ import type { RegisterComponent } from './types';
32
32
  */
33
33
  export declare const createComponentRegistry: () => {
34
34
  register: (newComponents: RegisterComponent[]) => void;
35
+ safeRegister: (newComponents: RegisterComponent[]) => void;
35
36
  components: RegisterComponent[];
36
37
  };
@@ -32,5 +32,6 @@ import type { RegisterComponent } from './types';
32
32
  */
33
33
  export declare const createComponentRegistry: () => {
34
34
  register: (newComponents: RegisterComponent[]) => void;
35
+ safeRegister: (newComponents: RegisterComponent[]) => void;
35
36
  components: RegisterComponent[];
36
37
  };
package/package.json CHANGED
@@ -21,9 +21,9 @@
21
21
  ],
22
22
  "atlaskit:src": "src/index.ts",
23
23
  "dependencies": {
24
- "@atlaskit/css": "^0.12.0",
25
- "@atlaskit/primitives": "^14.12.0",
26
- "@atlaskit/tokens": "^6.1.0",
24
+ "@atlaskit/css": "^0.13.0",
25
+ "@atlaskit/primitives": "^14.13.0",
26
+ "@atlaskit/tokens": "^6.2.0",
27
27
  "@babel/runtime": "^7.0.0",
28
28
  "@compiled/react": "^0.18.3"
29
29
  },
@@ -33,7 +33,7 @@
33
33
  "devDependencies": {
34
34
  "@af/integration-testing": "workspace:^",
35
35
  "@af/visual-regression": "workspace:^",
36
- "@atlaskit/editor-toolbar": "^0.6.0",
36
+ "@atlaskit/editor-toolbar": "^0.8.0",
37
37
  "@atlaskit/ssr": "workspace:^",
38
38
  "@testing-library/react": "^13.4.0",
39
39
  "react-dom": "^18.2.0"
@@ -74,7 +74,7 @@
74
74
  }
75
75
  },
76
76
  "name": "@atlaskit/editor-toolbar-model",
77
- "version": "0.2.0",
77
+ "version": "0.2.1",
78
78
  "description": "register and render toolbar component",
79
79
  "author": "Atlassian Pty Ltd",
80
80
  "license": "Apache-2.0",