Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap to using defineComponent for Vue (req. 2.7+) #732

Merged
merged 4 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## master

Changes:

- Swap `vue-identitycon` to use `defineComponent` (requires vue 2.7+)


## 3.0.2 Mar 11, 2023

Changes:
Expand Down
2 changes: 1 addition & 1 deletion packages/react-qr/src/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/react-qr authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import { u8aConcat, u8aToHex, u8aToString } from '@polkadot/util';
import { randomAsU8a } from '@polkadot/util-crypto';
Expand Down
2 changes: 1 addition & 1 deletion packages/reactnative-identicon/src/icons/Empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Props } from '../types.js';

import React from 'react';
import { View } from 'react-native';
import Svg, { Circle } from 'react-native-svg';
import { Circle, Svg } from 'react-native-svg';

export default function Empty ({ size }: Props): React.ReactElement<Props> {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/reactnative-identicon/src/icons/Polkadot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Props } from '../types.js';

import React, { useMemo } from 'react';
import { View } from 'react-native';
import Svg, { Circle as SvgCircle } from 'react-native-svg';
import { Circle as SvgCircle, Svg } from 'react-native-svg';

import { polkadotIcon } from '@polkadot/ui-shared';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-keyring/src/options/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import type { KeyringStruct } from '../types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/colors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import type { ColorGen } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/container.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import { container } from './container.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xmlserializer from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/seeder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import type { Seeder } from './types.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xmlserializer from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/svg/circle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xs from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/svg/element.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xs from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/svg/rect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xs from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/beachball/svg/svg.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import xs from 'xmlserializer';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/polkadot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2023 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev/node/test/node" />
/// <reference types="@polkadot/dev/node/test/node.d.ts" />

import { polkadotIcon } from './polkadot.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getRotation (isSixPoint: boolean): { r: number; ro2: number; r3o4: numb
return { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 };
}

function getCircleXY (isSixPoint: boolean): [number, number][] {
function getCircleXY (isSixPoint = false): [number, number][] {
const { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 } = getRotation(isSixPoint);

return [
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-shared/src/icons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export interface Circle {
}

export interface Options {
isAlternative: boolean;
isAlternative?: boolean;
size?: number;
}
2 changes: 1 addition & 1 deletion packages/vue-identicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"peerDependencies": {
"@polkadot/util": "*",
"@polkadot/util-crypto": "*",
"vue": "*"
"vue": "^2.7"
}
}
40 changes: 29 additions & 11 deletions packages/vue-identicon/src/Identicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { Prefix } from '@polkadot/util-crypto/address/types';

import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';

import { isHex, isU8a, u8aToHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
Expand Down Expand Up @@ -46,7 +46,7 @@ function encodeAccount (value: string | Uint8Array, prefix?: Prefix): Account {
* <Identicon :size="128" :theme="polkadot" :value="..." />
* ```
*/
export const Identicon = Vue.extend({
export const Identicon = defineComponent({
components: {
Beachball,
Empty,
Expand Down Expand Up @@ -81,19 +81,37 @@ export const Identicon = Vue.extend({
},
props: ['prefix', 'isAlternative', 'size', 'theme', 'value'],
render (h): VNode {
const { address, iconSize, isAlternativeIcon, publicKey, type } = this.$data as Data;
const { address, iconSize, isAlternativeIcon, publicKey, type } = this.$data;

if (type === 'empty') {
return h('Empty', { attrs: { key: address, size: iconSize } }, []);
return h('Empty', {
attrs: {
key: address,
size: iconSize
}
}, []);
} else if (type === 'jdenticon') {
return h('Jdenticon', { attrs: { key: address, publicKey, size: iconSize } }, []);
} else {
// handles: beachball and polkadot
// TODO: substrate
const cmp = type.charAt(0).toUpperCase() + type.slice(1);

return h(cmp, { attrs: { address, isAlternative: isAlternativeIcon, key: address, size: iconSize } }, []);
return h('Jdenticon', {
attrs: {
key: address,
publicKey,
size: iconSize
}
}, []);
} else if (type === 'substrate') {
throw new Error('substrate type is not supported');
}

const cmp = type.charAt(0).toUpperCase() + type.slice(1);

return h(cmp, {
attrs: {
address,
isAlternative: isAlternativeIcon,
key: address,
size: iconSize
}
}, []);
},
watch: {
value: function (): void {
Expand Down
17 changes: 10 additions & 7 deletions packages/vue-identicon/src/icons/Beachball.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0

import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';

import { beachballIcon } from '@polkadot/ui-shared';

type propsType = {
type PropsType = {
address: string;
size: number;
isAlternative: boolean;
Expand All @@ -15,13 +15,16 @@ type propsType = {
* @name Beachball
* @description The Beachball identicon
*/
export const Beachball = Vue.extend({
export const Beachball = defineComponent({
props: ['address', 'size', 'isAlternative'],
// eslint-disable-next-line quotes
render (h): VNode {
const { address, isAlternative, size } = this.$props as propsType;
const bb = beachballIcon(address, { isAlternative, size });
const { address, isAlternative, size } = this.$props as PropsType;

return h(Vue.component('VCBeachball', { template: bb.outerHTML }));
return h({
template: beachballIcon(address, {
isAlternative,
size
}).outerHTML
});
}
});
4 changes: 2 additions & 2 deletions packages/vue-identicon/src/icons/Empty.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0

import Vue from 'vue';
import { defineComponent } from 'vue';

/**
* @name Empty
* @description An empty identicon
*/
export const Empty = Vue.extend({
export const Empty = defineComponent({
props: ['size'],
template: `
<svg :height="size" :width="size" viewBox="0 0 64 64">
Expand Down
14 changes: 7 additions & 7 deletions packages/vue-identicon/src/icons/Jdenticon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import * as jdenticon from 'jdenticon';
import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';

type propsType = {
type PropsType = {
publicKey: string,
size: number
}
Expand All @@ -13,13 +13,13 @@ type propsType = {
* @name Jdenticon
* @description The substrate default via Jdenticon
*/
export const Jdenticon = Vue.extend({
export const Jdenticon = defineComponent({
props: ['publicKey', 'size'],
// eslint-disable-next-line quotes
render (h): VNode {
const { publicKey, size } = this.$props as propsType;
const cmp = Vue.component('CJdenticon', { template: jdenticon.toSvg(publicKey.substring(2), size) });
const { publicKey, size } = this.$props as PropsType;

return h(cmp);
return h({
template: jdenticon.toSvg(publicKey.substring(2), size)
});
}
});
23 changes: 11 additions & 12 deletions packages/vue-identicon/src/icons/Polkadot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0

import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';

import { polkadotIcon } from '@polkadot/ui-shared';

Expand All @@ -15,21 +15,20 @@ type propsType = {
* @name Polkadot
* @description The Polkadot default identicon
*/
export const Polkadot = Vue.extend({
export const Polkadot = defineComponent({
props: ['address', 'isAlternative', 'size'],
// eslint-disable-next-line quotes
render (h): VNode {
const { address, isAlternative, size } = this.$props as propsType;
const circles = polkadotIcon(address, {
isAlternative: isAlternative || false
}).map(({ cx,
cy,
fill,
r }) => {
return h('circle', { attrs: { cx, cy, fill, r } }, []);
}
const circles = polkadotIcon(address, { isAlternative }).map(({ cx, cy, fill, r }) =>
h('circle', { attrs: { cx, cy, fill, r } }, [])
);

return h('svg', { attrs: { height: size, viewBox: '0 0 64 64', width: size } }, circles);
return h('svg', {
attrs: {
height: size,
viewBox: '0 0 64 64',
width: size
}
}, circles);
}
});
2 changes: 0 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"extends": "@polkadot/dev/config/tsconfig.json",
"compilerOptions": {
"composite": true,
/* FIXME The default nodenext resolution is problematic with vue2 */
"moduleResolution": "node",
"paths": {
"@polkadot/react-identicon": ["react-identicon/src/index.ts"],
"@polkadot/react-qr": ["react-qr/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ __metadata:
peerDependencies:
"@polkadot/util": "*"
"@polkadot/util-crypto": "*"
vue: "*"
vue: ^2.7
languageName: unknown
linkType: soft

Expand Down