From 8dccf53c40d13a3288cad44d30954cdcbd225bf0 Mon Sep 17 00:00:00 2001 From: kennylam <909118+kennylam@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:14:50 -0400 Subject: [PATCH] chore(mixin): import `carbon-components` mixin (#10400) * chore(mixin): import carbon-component into package * chore(deps): bump package version to beta.2 --- .../packages/carbon-web-components/package.json | 2 +- .../components/date-picker/fix-events-plugin.ts | 2 +- .../src/components/date-picker/focus-plugin.ts | 2 +- .../date-picker/shadow-dom-events-plugin.ts | 2 +- .../src/components/ui-shell/side-nav.ts | 2 +- .../src/globals/mixins/form.ts | 4 ++-- .../src/globals/mixins/host-listener.ts | 4 ++-- .../src/globals/mixins/on.ts | 16 ++++++++++++++++ .../wrappers/createReactCustomElementType.ts | 2 +- .../tests/utils/event-manager.ts | 4 ++-- 10 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 web-components/packages/carbon-web-components/src/globals/mixins/on.ts diff --git a/web-components/packages/carbon-web-components/package.json b/web-components/packages/carbon-web-components/package.json index 905f78d05034..9c0b6802c87e 100644 --- a/web-components/packages/carbon-web-components/package.json +++ b/web-components/packages/carbon-web-components/package.json @@ -1,6 +1,6 @@ { "name": "@carbon/web-components", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "publishConfig": { "access": "public" }, diff --git a/web-components/packages/carbon-web-components/src/components/date-picker/fix-events-plugin.ts b/web-components/packages/carbon-web-components/src/components/date-picker/fix-events-plugin.ts index 22b1b27c8a88..69e459cb6751 100644 --- a/web-components/packages/carbon-web-components/src/components/date-picker/fix-events-plugin.ts +++ b/web-components/packages/carbon-web-components/src/components/date-picker/fix-events-plugin.ts @@ -9,7 +9,7 @@ import { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance'; import { Plugin } from 'flatpickr/dist/types/options'; -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../../globals/mixins/on'; import Handle from '../../globals/internal/handle'; import CDSDatePickerInput from './date-picker-input'; diff --git a/web-components/packages/carbon-web-components/src/components/date-picker/focus-plugin.ts b/web-components/packages/carbon-web-components/src/components/date-picker/focus-plugin.ts index 1a2e6816263d..cde6badaa7e9 100644 --- a/web-components/packages/carbon-web-components/src/components/date-picker/focus-plugin.ts +++ b/web-components/packages/carbon-web-components/src/components/date-picker/focus-plugin.ts @@ -9,7 +9,7 @@ import { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance'; import { Plugin } from 'flatpickr/dist/types/options'; -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../../globals/mixins/on'; import Handle from '../../globals/internal/handle'; import CDSDatePickerInput from './date-picker-input'; diff --git a/web-components/packages/carbon-web-components/src/components/date-picker/shadow-dom-events-plugin.ts b/web-components/packages/carbon-web-components/src/components/date-picker/shadow-dom-events-plugin.ts index 6d4fdf522f3e..23acc731cdc3 100644 --- a/web-components/packages/carbon-web-components/src/components/date-picker/shadow-dom-events-plugin.ts +++ b/web-components/packages/carbon-web-components/src/components/date-picker/shadow-dom-events-plugin.ts @@ -9,7 +9,7 @@ import { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance'; import { Plugin } from 'flatpickr/dist/types/options'; -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../../globals/mixins/on'; import Handle from '../../globals/internal/handle'; import { find } from '../../globals/internal/collection-helpers'; diff --git a/web-components/packages/carbon-web-components/src/components/ui-shell/side-nav.ts b/web-components/packages/carbon-web-components/src/components/ui-shell/side-nav.ts index ddb0b94cff9d..b7fa81b53104 100644 --- a/web-components/packages/carbon-web-components/src/components/ui-shell/side-nav.ts +++ b/web-components/packages/carbon-web-components/src/components/ui-shell/side-nav.ts @@ -9,7 +9,7 @@ import { LitElement, html } from 'lit'; import { property, customElement } from 'lit/decorators.js'; -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../../globals/mixins/on'; import { prefix } from '../../globals/settings'; import HostListenerMixin from '../../globals/mixins/host-listener'; import HostListener from '../../globals/decorators/host-listener'; diff --git a/web-components/packages/carbon-web-components/src/globals/mixins/form.ts b/web-components/packages/carbon-web-components/src/globals/mixins/form.ts index 80f05d3f9dfb..e4711d7be6a5 100644 --- a/web-components/packages/carbon-web-components/src/globals/mixins/form.ts +++ b/web-components/packages/carbon-web-components/src/globals/mixins/form.ts @@ -1,13 +1,13 @@ /** * @license * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ -import on from 'carbon-components/es/globals/js/misc/on'; +import on from './on'; import Handle from '../internal/handle'; /** diff --git a/web-components/packages/carbon-web-components/src/globals/mixins/host-listener.ts b/web-components/packages/carbon-web-components/src/globals/mixins/host-listener.ts index 44aa88e5bd65..41a9b244b298 100644 --- a/web-components/packages/carbon-web-components/src/globals/mixins/host-listener.ts +++ b/web-components/packages/carbon-web-components/src/globals/mixins/host-listener.ts @@ -1,13 +1,13 @@ /** * @license * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ -import on from 'carbon-components/es/globals/js/misc/on'; +import on from './on'; import Handle from '../internal/handle'; /** diff --git a/web-components/packages/carbon-web-components/src/globals/mixins/on.ts b/web-components/packages/carbon-web-components/src/globals/mixins/on.ts new file mode 100644 index 000000000000..caea03ee23e9 --- /dev/null +++ b/web-components/packages/carbon-web-components/src/globals/mixins/on.ts @@ -0,0 +1,16 @@ +/** + * Copyright IBM Corp. 2016, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +export default function on(element: any, ...args: any) { + element.addEventListener(...args); + return { + release() { + element.removeEventListener(...args); + return null; + }, + }; +} diff --git a/web-components/packages/carbon-web-components/src/globals/wrappers/createReactCustomElementType.ts b/web-components/packages/carbon-web-components/src/globals/wrappers/createReactCustomElementType.ts index 94efde9bc902..4462ce041aac 100644 --- a/web-components/packages/carbon-web-components/src/globals/wrappers/createReactCustomElementType.ts +++ b/web-components/packages/carbon-web-components/src/globals/wrappers/createReactCustomElementType.ts @@ -8,7 +8,7 @@ */ import React, { Component, createElement, forwardRef } from 'react'; -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../mixins/on'; import Handle from '../internal/handle'; /** diff --git a/web-components/packages/carbon-web-components/tests/utils/event-manager.ts b/web-components/packages/carbon-web-components/tests/utils/event-manager.ts index 01ca7cffaa41..0a979786569b 100644 --- a/web-components/packages/carbon-web-components/tests/utils/event-manager.ts +++ b/web-components/packages/carbon-web-components/tests/utils/event-manager.ts @@ -1,13 +1,13 @@ /** * @license * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ -import on from 'carbon-components/es/globals/js/misc/on'; +import on from '../../src/globals/mixins/on'; import Handle from '../../src/globals/internal/handle'; interface CustomEventListener {