@geckou/ui-vue 0.3.0 → 0.3.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.
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -70,8 +71,8 @@ defineProps<{
70
71
  style="grid-area: tag;"
71
72
  />
72
73
  <AuthorInfo
73
- v-if="postConfig.author"
74
- :avatarUrls="article._embedded.author[0].avatar_urls"
74
+ v-if="postConfig.author && returnAuthor(article)"
75
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
75
76
  :thumbnail="{
76
77
  size: 'large',
77
78
  shape: 'circle'
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -91,8 +92,8 @@ defineProps<{
91
92
  delimiter="/"
92
93
  />
93
94
  <AuthorInfo
94
- v-if="postConfig.author"
95
- :avatarUrls="article._embedded.author[0].avatar_urls"
95
+ v-if="postConfig.author && returnAuthor(article)"
96
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
96
97
  :class="$style.author"
97
98
  :thumbnail="{
98
99
  size: 'medium',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -54,8 +55,8 @@ defineProps<{
54
55
  style="grid-area: date;"
55
56
  />
56
57
  <AuthorInfo
57
- v-if="postConfig.author"
58
- :name="article._embedded.author[0].name"
58
+ v-if="postConfig.author && returnAuthor(article)"
59
+ :name="returnAuthor(article)?.name"
59
60
  :class="$style.author"
60
61
  :text="{
61
62
  color : 'var(--white)',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -77,8 +78,8 @@ defineProps<{
77
78
  style="grid-area: excerpt;"
78
79
  />
79
80
  <AuthorInfo
80
- v-if="postConfig.author"
81
- :avatarUrls="article._embedded.author[0].avatar_urls"
81
+ v-if="postConfig.author && returnAuthor(article)"
82
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
82
83
  :thumbnail="{
83
84
  size : 'large',
84
85
  shape: 'square',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -76,8 +77,8 @@ defineProps<{
76
77
  style="grid-area: tag;"
77
78
  />
78
79
  <AuthorInfo
79
- v-if="postConfig.author"
80
- :name="article._embedded.author[0].name"
80
+ v-if="postConfig.author && returnAuthor(article)"
81
+ :name="returnAuthor(article)?.name"
81
82
  :class="$style.author"
82
83
  :text="{
83
84
  color : 'var(--gray)',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -41,8 +42,8 @@ defineProps<{
41
42
  style="grid-area: date;"
42
43
  />
43
44
  <AuthorInfo
44
- v-if="postConfig.author"
45
- :avatarUrls="article._embedded.author[0].avatar_urls"
45
+ v-if="postConfig.author && returnAuthor(article)"
46
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
46
47
  :thumbnail="{
47
48
  shape: 'circle',
48
49
  }"
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -78,9 +79,9 @@ defineProps<{
78
79
  style="grid-area: tag;"
79
80
  />
80
81
  <AuthorInfo
81
- v-if="postConfig.author"
82
- :avatarUrls="article._embedded.author[0].avatar_urls"
83
- :name="article._embedded.author[0].name"
82
+ v-if="postConfig.author && returnAuthor(article)"
83
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
84
+ :name="returnAuthor(article)?.name"
84
85
  :class="$style.author"
85
86
  :text="{
86
87
  fontSize: 'small',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -45,8 +46,8 @@ defineProps<{
45
46
  style="grid-area: heading;"
46
47
  />
47
48
  <AuthorInfo
48
- v-if="postConfig.author"
49
- :name="article._embedded.author[0].name"
49
+ v-if="postConfig.author && returnAuthor(article)"
50
+ :name="returnAuthor(article)?.name"
50
51
  :class="$style.author"
51
52
  :text="{
52
53
  color : 'var(--gray)',
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -66,9 +67,9 @@ defineProps<{
66
67
  style="grid-area: date;"
67
68
  />
68
69
  <AuthorInfo
69
- v-if="postConfig.author"
70
- :avatarUrls="article._embedded.author[0].avatar_urls"
71
- :name="article._embedded.author[0].name"
70
+ v-if="postConfig.author && returnAuthor(article)"
71
+ :avatarUrls="returnAuthor(article)?.avatar_urls"
72
+ :name="returnAuthor(article)?.name"
72
73
  :class="$style.author"
73
74
  style="grid-area: author;"
74
75
  />
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { returnAuthor } from '../../../scripts/utils'
2
3
  import type {
3
4
  Article,
4
5
  Category,
@@ -77,8 +78,8 @@ defineProps<{
77
78
  style="grid-area: tag;"
78
79
  />
79
80
  <AuthorInfo
80
- v-if="postConfig.author"
81
- :name="article._embedded.author[0].name"
81
+ v-if="postConfig.author && returnAuthor(article)"
82
+ :name="returnAuthor(article)?.name"
82
83
  :class="$style.author"
83
84
  :text="{
84
85
  color : 'var(--gray)',
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import type {
3
3
  Option,
4
+ SelectValue,
4
5
  CheckBoxStyleForEachStatus,
5
6
  } from '../types'
6
7
  import {
@@ -12,12 +13,12 @@ import LabeledCheckbox from '../components/LabeledCheckbox.vue'
12
13
  import ErrorMessage from '../components/ErrorMessage.vue'
13
14
  import { COLOR } from '../const'
14
15
 
15
- const emit = defineEmits<{ (e: 'update:modelValue', newValue: string[]): void }>()
16
+ const emit = defineEmits<{ (e: 'update:modelValue', newValue: SelectValue[]): void }>()
16
17
 
17
18
  const props = withDefaults(defineProps<{
18
19
  name : string
19
20
  options: Array<Option>
20
- modelValue?: string[]
21
+ modelValue?: SelectValue[]
21
22
  isDisabled? : boolean
22
23
  isRequired?: boolean
23
24
  cssStyle?: CheckBoxStyleForEachStatus
@@ -32,12 +33,12 @@ const checkBoxes = ref(props.options.map(option => ({
32
33
  checked: props.modelValue?.includes(option.value) || false,
33
34
  })))
34
35
 
35
- const checkedValues = computed<string[]>(() => checkBoxes.value.filter(checkBox => checkBox.checked).map(checkBox => checkBox.value))
36
+ const checkedValues = computed<SelectValue[]>(() => checkBoxes.value.filter(checkBox => checkBox.checked).map(checkBox => checkBox.value))
36
37
  const errorMessage = ref('')
37
38
  const validateInput = () => errorMessage.value = props.isRequired && checkedValues.value.length === 0 ? '必須項目です' : ''
38
39
 
39
40
  watch(checkedValues, (newValue, oldValue) => {
40
- const isArraysEqual = (a: string[], b: string[]): boolean => a.length === b.length && a.every((val, index) => val === b[index])
41
+ const isArraysEqual = (a: SelectValue[], b: SelectValue[]): boolean => a.length === b.length && a.every((val, index) => val === b[index])
41
42
  if (oldValue && isArraysEqual(newValue, oldValue)) return
42
43
  validateInput()
43
44
  emit('update:modelValue', newValue)
@@ -30,8 +30,8 @@ defineExpose({
30
30
  <div
31
31
  :class="[
32
32
  $style.popup,
33
- $style[`x-${props.position.x}`],
34
- $style[`y-${props.position.y}`],
33
+ $style[`x-${position.x}`],
34
+ $style[`y-${position.y}`],
35
35
  { [$style.show]: isShown },
36
36
  ]"
37
37
  >
@@ -1,4 +1,4 @@
1
- import type { Article, PostConfig, WpTerm } from '../types'
1
+ import type { Article, PostConfig, WpAuthor, WpTerm } from '../types'
2
2
 
3
3
  export const generateQueryObject = (url: string): Record<string, string> => {
4
4
  const regex = /[?&]([^=#]+)=([^&#]*)/g
@@ -11,12 +11,20 @@ export const generateQueryObject = (url: string): Record<string, string> => {
11
11
  return queryObject
12
12
  }
13
13
 
14
+ /**
15
+ * 投稿の著者を取り出す。
16
+ * _embedded は ?_embed を付けていないレスポンスでは存在しないため、
17
+ * 各カードで直接辿らずここを通す
18
+ */
19
+ export const returnAuthor = (articleObject: Article): WpAuthor | undefined =>
20
+ articleObject?._embedded?.author?.[0]
21
+
14
22
  export const returnTagList = (articleObject: Article): string[] => {
15
23
  const terms = articleObject?.['_embedded']?.['wp:term']?.[1] ?? []
16
24
  return terms.map((tag: WpTerm) => tag.name)
17
25
  }
18
26
 
19
- export const returnArticlePath = (postConfig: PostConfig, domain: string, articleId: string) => {
27
+ export const returnArticlePath = (postConfig: PostConfig, domain: string, articleId: string | number) => {
20
28
  // ドメイン末尾とパス先頭のスラッシュが重ならないようにする
21
29
  const base = String(domain).replace(/\/+$/, '')
22
30
  const path = String(postConfig.article_page_path ?? '').replace(/^\/+/, '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geckou/ui-vue",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A set of reusable Vue UI components (forms & article lists) by Geckou",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",