@arpproject/recrate 0.1.7 → 0.1.8

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.
Files changed (188) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/recrate.css +4 -4
  3. package/dist/recrate.es.js +34674 -114061
  4. package/package.json +41 -32
  5. package/.eslintrc.json +0 -37
  6. package/.storybook/main.ts +0 -40
  7. package/.storybook/preview.tsx +0 -46
  8. package/babel.config.json +0 -5
  9. package/docker-compose.yml +0 -30
  10. package/docs/.nojekyll +0 -1
  11. package/docs/assets/highlight.css +0 -99
  12. package/docs/assets/icons.js +0 -18
  13. package/docs/assets/icons.svg +0 -1
  14. package/docs/assets/main.js +0 -60
  15. package/docs/assets/navigation.js +0 -1
  16. package/docs/assets/search.js +0 -1
  17. package/docs/assets/style.css +0 -1448
  18. package/docs/classes/src_crate_builder_CrateManager_crate_manager.CrateManager.html +0 -240
  19. package/docs/classes/src_crate_builder_CrateManager_profile_manager.ProfileManager.html +0 -42
  20. package/docs/classes/src_crate_builder_editor_state.EditorState.html +0 -28
  21. package/docs/classes/src_crate_builder_types.CrateManagerType.html +0 -57
  22. package/docs/classes/src_crate_builder_types.ProfileManagerType.html +0 -13
  23. package/docs/functions/src_crate_builder_CrateManager_lib.isURL.html +0 -2
  24. package/docs/functions/src_crate_builder_CrateManager_lib.mintNewCrate.html +0 -3
  25. package/docs/functions/src_crate_builder_CrateManager_lib.normalise.html +0 -5
  26. package/docs/functions/src_crate_builder_CrateManager_lib.normaliseEntityType.html +0 -1
  27. package/docs/index.html +0 -58
  28. package/docs/interfaces/src_crate_builder_types.NormalisedCrate.html +0 -3
  29. package/docs/interfaces/src_crate_builder_types.NormalisedEntityDefinition.html +0 -4
  30. package/docs/interfaces/src_crate_builder_types.NormalisedProfile.html +0 -9
  31. package/docs/interfaces/src_crate_builder_types.ProfileLayout.html +0 -2
  32. package/docs/interfaces/src_crate_builder_types.ProfileLayoutGroup.html +0 -9
  33. package/docs/interfaces/src_crate_builder_types.UnverifiedCrate.html +0 -3
  34. package/docs/interfaces/src_crate_builder_types.UnverifiedEntityDefinition.html +0 -4
  35. package/docs/modules/src_crate_builder_CrateManager_crate_manager.html +0 -2
  36. package/docs/modules/src_crate_builder_CrateManager_lib.html +0 -6
  37. package/docs/modules/src_crate_builder_CrateManager_profile_manager.html +0 -2
  38. package/docs/modules/src_crate_builder_editor_state.html +0 -2
  39. package/docs/modules/src_crate_builder_types.html +0 -16
  40. package/docs/types/src_crate_builder_types.EntityReference.html +0 -1
  41. package/docs/types/src_crate_builder_types.NormalisedContext.html +0 -1
  42. package/docs/types/src_crate_builder_types.PrimitiveType.html +0 -1
  43. package/docs/types/src_crate_builder_types.ProfileAssociation.html +0 -1
  44. package/docs/types/src_crate_builder_types.ProfileInput.html +0 -1
  45. package/docs/types/src_crate_builder_types.UnverifiedContext.html +0 -1
  46. package/docs/variables/src_crate_builder_CrateManager_lib.urlProtocols.html +0 -1
  47. package/index.html +0 -13
  48. package/load-data-packs.cjs +0 -38
  49. package/postcss.config.cjs +0 -6
  50. package/public/favicon.ico +0 -0
  51. package/public/index.html +0 -43
  52. package/public/logo192.png +0 -0
  53. package/public/logo512.png +0 -0
  54. package/public/manifest.json +0 -25
  55. package/public/marker-icon.png +0 -0
  56. package/public/marker-shadow.png +0 -0
  57. package/public/robots.txt +0 -3
  58. package/react-app-env.d.ts +0 -1
  59. package/rollup.config.js +0 -26
  60. package/src/app/App.tsx +0 -13
  61. package/src/app/EmbeddedComponent.tsx +0 -432
  62. package/src/app/index.html +0 -20
  63. package/src/app/index.tsx +0 -19
  64. package/src/app/lookup.ts +0 -141
  65. package/src/app/override-styles.css +0 -96
  66. package/src/crate-builder/CrateManager/contexts/1.1-context.jsonld +0 -2660
  67. package/src/crate-builder/CrateManager/contexts/1.2-DRAFT-context.jsonld +0 -2918
  68. package/src/crate-builder/CrateManager/contexts.ts +0 -42
  69. package/src/crate-builder/CrateManager/crate-manager-benchmarking.spec.ts +0 -31
  70. package/src/crate-builder/CrateManager/crate-manager-loading-exporting.spec.ts +0 -431
  71. package/src/crate-builder/CrateManager/crate-manager-operations.spec.ts +0 -298
  72. package/src/crate-builder/CrateManager/crate-manager.spec.ts +0 -2336
  73. package/src/crate-builder/CrateManager/crate-manager.ts +0 -2111
  74. package/src/crate-builder/CrateManager/lib.spec.ts +0 -133
  75. package/src/crate-builder/CrateManager/lib.ts +0 -170
  76. package/src/crate-builder/CrateManager/profile-manager.spec.ts +0 -593
  77. package/src/crate-builder/CrateManager/profile-manager.ts +0 -367
  78. package/src/crate-builder/CrateManager/schema-type-definitions.json +0 -35122
  79. package/src/crate-builder/CrateManager/validate-identifier.spec.ts +0 -82
  80. package/src/crate-builder/CrateManager/validate-identifier.ts +0 -65
  81. package/src/crate-builder/RenderEntity/Add.tsx +0 -249
  82. package/src/crate-builder/RenderEntity/AddControl.stories.tsx +0 -126
  83. package/src/crate-builder/RenderEntity/AddControl.tsx +0 -84
  84. package/src/crate-builder/RenderEntity/AutoComplete.tsx +0 -215
  85. package/src/crate-builder/RenderEntity/BulkAdd.tsx +0 -136
  86. package/src/crate-builder/RenderEntity/DeleteProperty.tsx +0 -33
  87. package/src/crate-builder/RenderEntity/DialogAddProperty.tsx +0 -83
  88. package/src/crate-builder/RenderEntity/DialogBrowseEntities.tsx +0 -136
  89. package/src/crate-builder/RenderEntity/DialogEditContext.tsx +0 -107
  90. package/src/crate-builder/RenderEntity/DialogPreviewCrate.tsx +0 -54
  91. package/src/crate-builder/RenderEntity/DialogSaveCrateAsTemplate.tsx +0 -65
  92. package/src/crate-builder/RenderEntity/DialogSaveEntityTemplate.tsx +0 -87
  93. package/src/crate-builder/RenderEntity/DisplayPropertyName.stories.tsx +0 -30
  94. package/src/crate-builder/RenderEntity/DisplayPropertyName.tsx +0 -21
  95. package/src/crate-builder/RenderEntity/EntityId.tsx +0 -75
  96. package/src/crate-builder/RenderEntity/EntityName.tsx +0 -49
  97. package/src/crate-builder/RenderEntity/EntityProperty.tsx +0 -188
  98. package/src/crate-builder/RenderEntity/EntityPropertyInstance.tsx +0 -255
  99. package/src/crate-builder/RenderEntity/EntityType.tsx +0 -95
  100. package/src/crate-builder/RenderEntity/ItemLink.tsx +0 -37
  101. package/src/crate-builder/RenderEntity/PaginateLinkedEntities.stories.tsx +0 -43
  102. package/src/crate-builder/RenderEntity/PaginateLinkedEntities.tsx +0 -141
  103. package/src/crate-builder/RenderEntity/PropertyHelp.tsx +0 -39
  104. package/src/crate-builder/RenderEntity/RenderControls.tsx +0 -278
  105. package/src/crate-builder/RenderEntity/RenderLinkedItem.tsx +0 -139
  106. package/src/crate-builder/RenderEntity/RenderPropertyHelp.tsx +0 -41
  107. package/src/crate-builder/RenderEntity/RenderReverseConnections.tsx +0 -150
  108. package/src/crate-builder/RenderEntity/RenderTypes.tsx +0 -102
  109. package/src/crate-builder/RenderEntity/Shell2.tsx +0 -576
  110. package/src/crate-builder/RenderEntity/UnlinkEntity.tsx +0 -30
  111. package/src/crate-builder/RenderEntity/auto-complete.lib.ts +0 -184
  112. package/src/crate-builder/RenderEntity/keys.ts +0 -4
  113. package/src/crate-builder/RenderEntity/layout.spec.js +0 -593
  114. package/src/crate-builder/RenderEntity/layout.ts +0 -220
  115. package/src/crate-builder/Shell.tsx +0 -337
  116. package/src/crate-builder/component.css +0 -65
  117. package/src/crate-builder/editor-state.ts +0 -114
  118. package/src/crate-builder/emotionCache.ts +0 -8
  119. package/src/crate-builder/helpers.ts +0 -16
  120. package/src/crate-builder/i18n.ts +0 -22
  121. package/src/crate-builder/lib/validate-iri.js +0 -69
  122. package/src/crate-builder/lib/validate-iri.ts +0 -57
  123. package/src/crate-builder/locales/en.js +0 -149
  124. package/src/crate-builder/locales/hu.js +0 -147
  125. package/src/crate-builder/primitives/Boolean.stories.tsx +0 -33
  126. package/src/crate-builder/primitives/Boolean.tsx +0 -67
  127. package/src/crate-builder/primitives/Date.stories.tsx +0 -32
  128. package/src/crate-builder/primitives/Date.tsx +0 -58
  129. package/src/crate-builder/primitives/DateTime.stories.tsx +0 -32
  130. package/src/crate-builder/primitives/DateTime.tsx +0 -64
  131. package/src/crate-builder/primitives/Geo.stories.tsx +0 -57
  132. package/src/crate-builder/primitives/Geo.tsx +0 -225
  133. package/src/crate-builder/primitives/Map.SelectArea.js +0 -359
  134. package/src/crate-builder/primitives/Map.stories.tsx +0 -61
  135. package/src/crate-builder/primitives/Map.tsx +0 -124
  136. package/src/crate-builder/primitives/Number.stories.tsx +0 -74
  137. package/src/crate-builder/primitives/Number.tsx +0 -166
  138. package/src/crate-builder/primitives/Select.stories.tsx +0 -66
  139. package/src/crate-builder/primitives/Select.tsx +0 -121
  140. package/src/crate-builder/primitives/SelectObject.stories.tsx +0 -29
  141. package/src/crate-builder/primitives/SelectObject.tsx +0 -105
  142. package/src/crate-builder/primitives/SelectUrl.stories.tsx +0 -42
  143. package/src/crate-builder/primitives/SelectUrl.tsx +0 -110
  144. package/src/crate-builder/primitives/Text.stories.tsx +0 -106
  145. package/src/crate-builder/primitives/Text.tsx +0 -197
  146. package/src/crate-builder/primitives/Time.stories.tsx +0 -38
  147. package/src/crate-builder/primitives/Time.tsx +0 -71
  148. package/src/crate-builder/primitives/Url.stories.tsx +0 -43
  149. package/src/crate-builder/primitives/Url.tsx +0 -75
  150. package/src/crate-builder/primitives/Value.stories.tsx +0 -37
  151. package/src/crate-builder/primitives/Value.tsx +0 -30
  152. package/src/crate-builder/primitives/date-libs.ts +0 -12
  153. package/src/crate-builder/profile-schema.json +0 -145
  154. package/src/crate-builder/property-definitions.ts +0 -78
  155. package/src/crate-builder/recrate.css +0 -3
  156. package/src/crate-builder/store.ts +0 -14
  157. package/src/crate-builder/tailwind.css +0 -5
  158. package/src/crate-builder/types.d.ts +0 -318
  159. package/src/examples/collection/collections-entity-example.json +0 -131
  160. package/src/examples/collection/crate-builder-entity-example.json +0 -33
  161. package/src/examples/item/complex-collection/ro-crate-metadata.json +0 -174
  162. package/src/examples/item/complex-item/ro-crate-metadata.json +0 -769
  163. package/src/examples/item/crate-with-language.json +0 -38
  164. package/src/examples/item/empty/ro-crate-metadata.json +0 -20
  165. package/src/examples/item/item-with-relationship-and-action/ro-crate-metadata.json +0 -66
  166. package/src/examples/item/large-crate/ro-crate-metadata.json +0 -5762
  167. package/src/examples/item/multiple-types/ro-crate-metadata.json +0 -20
  168. package/src/examples/item/ridiculously-big-collection/ro-crate-metadata.json +0 -162977
  169. package/src/examples/profile/aroma.complex.profile.json +0 -11098
  170. package/src/examples/profile/aroma.profile.json +0 -9158
  171. package/src/examples/profile/nyingarn-item-profile.json +0 -426
  172. package/src/examples/profile/profile-to-test-inverse-associations.json +0 -73
  173. package/src/examples/profile/profile-to-test-multiple-types.json +0 -31
  174. package/src/examples/profile/profile-with-all-primitives-and-groups.json +0 -207
  175. package/src/examples/profile/profile-with-all-primitives.json +0 -244
  176. package/src/examples/profile/profile-with-constraints.json +0 -446
  177. package/src/examples/profile/profile-with-resolve.json +0 -57
  178. package/src/examples/profile/vocabulary-creation-profile.json +0 -231
  179. package/src/images.d.ts +0 -5
  180. package/src/index.ts +0 -12
  181. package/src/types.ts +0 -104
  182. package/tailwind.config.js +0 -21
  183. package/tsconfig.app.json +0 -31
  184. package/tsconfig.json +0 -26
  185. package/typedoc.json +0 -11
  186. package/update-deps.sh +0 -4
  187. package/vite-env.d.ts +0 -1
  188. package/vite.config.ts +0 -46
@@ -1,106 +0,0 @@
1
- import React from 'react';
2
- import { Meta, StoryObj } from '@storybook/react';
3
- import Text from './Text';
4
-
5
- const meta: Meta<typeof Text> = {
6
- component: Text,
7
- title: 'Primitives/Text',
8
- argTypes: {
9
- type: {
10
- options: ['text', 'textarea', 'url'],
11
- control: { type: 'radio' }
12
- },
13
- property: {
14
- control: { type: 'text' }
15
- },
16
- value: {
17
- control: { type: 'text' }
18
- },
19
- placeholder: {
20
- control: { type: 'text' }
21
- },
22
- onSaveProperty: { action: 'saveProperty' },
23
- definition: { control: 'object' }
24
- }
25
- };
26
-
27
- export default meta;
28
-
29
- type Story = StoryObj<typeof Text>;
30
-
31
- export const SimpleText: Story = {
32
- args: {
33
- type: 'text',
34
- property: 'text',
35
- value: 'http://schema.org/name'
36
- }
37
- };
38
-
39
- export const TextWithPlaceholder: Story = {
40
- args: {
41
- type: 'text',
42
- property: 'text',
43
- value: '',
44
- placeholder: 'Enter some text...'
45
- }
46
- };
47
-
48
- export const TextWithSpaces: Story = {
49
- args: {
50
- type: 'text',
51
- property: '@id',
52
- value: 'http://schema.org/name of person'
53
- }
54
- };
55
-
56
- export const TextArea: Story = {
57
- args: {
58
- type: 'textarea',
59
- property: 'description',
60
- value: 'This is a longer text that would be better displayed in a textarea.\n\nIt supports multiple paragraphs.'
61
- }
62
- };
63
-
64
- export const WithMinLengthConstraint: Story = {
65
- args: {
66
- type: 'text',
67
- property: 'constraint',
68
- value: 'short',
69
- definition: {
70
- minLength: 10
71
- }
72
- }
73
- };
74
-
75
- export const WithMaxLengthConstraint: Story = {
76
- args: {
77
- type: 'text',
78
- property: 'constraint',
79
- value: 'This text is too long for the constraint',
80
- definition: {
81
- maxLength: 10
82
- }
83
- }
84
- };
85
-
86
- export const WithRegexConstraint: Story = {
87
- args: {
88
- type: 'text',
89
- property: 'constraint',
90
- value: 'abc',
91
- definition: {
92
- regex: '^[0-9]+$' // Only numbers are allowed
93
- }
94
- }
95
- };
96
-
97
- export const WithDateFormatConstraint: Story = {
98
- args: {
99
- type: 'text',
100
- property: 'date',
101
- value: 'not a date',
102
- definition: {
103
- dateFormat: ['YYYY-MM-DD', 'MM/DD/YYYY']
104
- }
105
- }
106
- };
@@ -1,197 +0,0 @@
1
- import React, { useState, useEffect, useRef, useCallback } from 'react';
2
- import { Input, Button, Form, Typography } from 'antd';
3
- import { CheckOutlined } from '@ant-design/icons';
4
- import { useTranslation } from 'react-i18next';
5
- import { debounce, isBoolean } from 'lodash';
6
- import dayjs from 'dayjs';
7
-
8
- export interface TextProps {
9
- type?: 'text' | 'textarea' | 'url';
10
- property: string;
11
- definition?: {
12
- minLength?: number;
13
- maxLength?: number;
14
- regex?: string;
15
- dateFormat?: string[];
16
- };
17
- value?: string;
18
- placeholder?: string;
19
- onSaveProperty: (data: { property: string; value: string }) => void;
20
- }
21
-
22
- const Text: React.FC<TextProps> = ({
23
- type = 'text',
24
- property,
25
- definition,
26
- value = '',
27
- placeholder,
28
- onSaveProperty
29
- }) => {
30
- const { t } = useTranslation();
31
- const [displayValue, setDisplayValue] = useState<string>(decodeValue(value));
32
- const [isValidTextValue, setIsValidTextValue] = useState<boolean>(true);
33
- const textareaRef = useRef<HTMLTextAreaElement>(null);
34
- const saveButtonRef = useRef<HTMLButtonElement>(null);
35
-
36
- // Update internal value when prop value changes
37
- useEffect(() => {
38
- setDisplayValue(decodeValue(value));
39
- // Add validation call here to validate on value changes
40
- validateTextConstraints(decodeValue(value));
41
- }, [value]);
42
-
43
- // Add initial validation on mount
44
- useEffect(() => {
45
- validateTextConstraints(displayValue);
46
- }, []);
47
-
48
- // Create debounced save function
49
- const debouncedSave = useCallback(
50
- debounce(() => {
51
- save();
52
- }, 200, { leading: false, trailing: true }),
53
- [property, displayValue, type]
54
- );
55
-
56
- // Constraints from definition
57
- const constraints = {
58
- minLength: definition?.minLength,
59
- maxLength: definition?.maxLength,
60
- regex: definition?.regex,
61
- dateFormat: definition?.dateFormat,
62
- };
63
-
64
- function validateTextConstraints(valueToCheck?: string) {
65
- const valueToValidate = (valueToCheck ?? displayValue) ?? '';
66
-
67
- if (constraints.minLength !== undefined && constraints.minLength > valueToValidate.length) {
68
- setIsValidTextValue(false);
69
- } else if (
70
- constraints.maxLength !== undefined &&
71
- constraints.maxLength < valueToValidate.length
72
- ) {
73
- setIsValidTextValue(false);
74
- } else if (
75
- constraints.regex !== undefined &&
76
- !new RegExp(constraints.regex).test(valueToValidate)
77
- ) {
78
- setIsValidTextValue(false);
79
- } else if (
80
- constraints.dateFormat !== undefined &&
81
- !validateDateFormat(valueToValidate, constraints.dateFormat)
82
- ) {
83
- setIsValidTextValue(false);
84
- } else {
85
- setIsValidTextValue(true);
86
- }
87
- }
88
-
89
- function validateDateFormat(inputString: string, granularity: string[]) {
90
- let dateString = inputString;
91
- if (inputString.startsWith("-")) {
92
- dateString = dateString.substr(1);
93
- }
94
- return (
95
- Array.isArray(granularity) &&
96
- granularity.some(g => dayjs(dateString, g, true).isValid())
97
- );
98
- }
99
-
100
- function save() {
101
- if (isValidTextValue) {
102
- onSaveProperty({
103
- property,
104
- value: displayValue.trim()
105
- });
106
- }
107
- }
108
-
109
- function decodeValue(value?: string): string {
110
- if (isBoolean(value)) {
111
- return String(value);
112
- } else if (value) {
113
- try {
114
- return decodeURI(value) === 'undefined' ? '' : decodeURI(value);
115
- } catch (error) {
116
- return value;
117
- }
118
- }
119
- return '';
120
- }
121
-
122
- function getConstraintsString(): string {
123
- const message: string[] = [];
124
-
125
- Object.entries(constraints).forEach(([name, value]) => {
126
- if (name && value) {
127
- message.push(`${name}: ${value}`);
128
- }
129
- });
130
-
131
- return message.join(', ');
132
- }
133
-
134
- const handleTextareaChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
135
- const newValue = e.target.value;
136
- setDisplayValue(newValue);
137
- validateTextConstraints(newValue);
138
- };
139
-
140
- const handleTextChange = (e: React.ChangeEvent<HTMLInputElement>) => {
141
- const newValue = e.target.value;
142
- setDisplayValue(newValue);
143
- validateTextConstraints(newValue);
144
- };
145
-
146
- const handleBlur = (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => {
147
- if (e.relatedTarget !== saveButtonRef.current) {
148
- debouncedSave();
149
- }
150
- };
151
-
152
- return (
153
- <div className="flex flex-col w-full space-y-2 describo-property-type-text">
154
- <div className="flex flex-row gap-x-2">
155
- {type !== 'textarea' ? (
156
- <Input
157
- size='middle'
158
- type={type}
159
- value={displayValue}
160
- onChange={handleTextChange}
161
- onBlur={handleBlur}
162
- placeholder={placeholder}
163
- status={!isValidTextValue ? 'error' : ''}
164
- />
165
- ) : (
166
- <Input.TextArea
167
- ref={textareaRef}
168
- value={displayValue}
169
- onChange={handleTextareaChange}
170
- onBlur={handleBlur}
171
- placeholder={placeholder}
172
- status={!isValidTextValue ? 'error' : ''}
173
- autoSize={{ minRows: 3, maxRows: 6 }}
174
- />
175
- )}
176
-
177
- <Button
178
- ref={saveButtonRef}
179
- onClick={save}
180
- variant='solid'
181
- color="green"
182
- size="middle"
183
- danger={!isValidTextValue}
184
- icon={<CheckOutlined />}
185
- />
186
- </div>
187
-
188
- {!isValidTextValue && getConstraintsString() && (
189
- <Typography.Text type="danger">
190
- {t('text_constraints_error_message', { value: getConstraintsString() })}
191
- </Typography.Text>
192
- )}
193
- </div>
194
- );
195
- };
196
-
197
- export default Text;
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
- import { StoryFn, Meta } from '@storybook/react';
3
- import Time from './Time';
4
-
5
- export default {
6
- title: 'Primitives/Time',
7
- component: Time,
8
- argTypes: {
9
- property: {
10
- control: { type: 'text' }
11
- },
12
- value: {
13
- options: ['09:30', '11:00:03', '15:58', '18:34:21', 'time now'],
14
- control: { type: 'radio' }
15
- },
16
- onSaveProperty: { action: 'saveProperty' }
17
- }
18
- } as Meta<typeof Time>;
19
-
20
- const Template: StoryFn<typeof Time> = (args) => <Time {...args} />;
21
-
22
- export const Default = Template.bind({});
23
- Default.args = {
24
- property: 'currentTime',
25
- value: '09:30'
26
- };
27
-
28
- export const WithSeconds = Template.bind({});
29
- WithSeconds.args = {
30
- property: 'currentTime',
31
- value: '11:00:03'
32
- };
33
-
34
- export const InvalidTime = Template.bind({});
35
- InvalidTime.args = {
36
- property: 'currentTime',
37
- value: 'time now'
38
- };
@@ -1,71 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { Input, Typography } from 'antd';
3
- import { useTranslation } from 'react-i18next';
4
- import { throttle } from 'lodash';
5
-
6
- export interface TimeProps {
7
- property: string;
8
- value?: string;
9
- onSaveProperty: (data: { property: string; value: string }) => void;
10
- }
11
-
12
- const Time: React.FC<TimeProps> = ({
13
- property,
14
- value,
15
- onSaveProperty
16
- }) => {
17
- const { t } = useTranslation();
18
- const [internalValue, setInternalValue] = useState(value);
19
- const [isValidTime, setIsValidTime] = useState(checkTimeIsValid(value));
20
-
21
- useEffect(() => {
22
- setInternalValue(value);
23
- setIsValidTime(checkTimeIsValid(value));
24
- }, [value]);
25
-
26
- const throttledSave = throttle((newValue: string) => {
27
- const isValid = checkTimeIsValid(newValue);
28
- setIsValidTime(isValid);
29
- if (!isValid) return;
30
- onSaveProperty({
31
- property,
32
- value: newValue,
33
- });
34
- }, 1000);
35
-
36
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
37
- const newValue = e.target.value;
38
- setInternalValue(newValue);
39
- throttledSave(newValue);
40
- };
41
-
42
- function checkTimeIsValid(string?: string): boolean {
43
- try {
44
- if (!string) return true;
45
- if (string.match(/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/)) return true;
46
- if (string.match(/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/)) return true;
47
- }
48
- catch (error) { }
49
- return false;
50
- }
51
-
52
- return (
53
- <div className="flex flex-col w-full describo-property-type-time">
54
- <Input
55
- size='middle'
56
- value={internalValue || ''}
57
- onChange={handleChange}
58
- onBlur={(e) => throttledSave(e.target.value)}
59
- placeholder={t('provide_time') || ''}
60
- status={!isValidTime ? 'error' : ''}
61
- />
62
- {!isValidTime && (
63
- <Typography.Text type="danger">
64
- {t('invalid_time_value', { value: internalValue })}
65
- </Typography.Text>
66
- )}
67
- </div>
68
- );
69
- };
70
-
71
- export default Time;
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import { StoryFn, Meta } from '@storybook/react';
3
- import Url from './Url';
4
-
5
- export default {
6
- title: 'Primitives/Url',
7
- component: Url,
8
- argTypes: {
9
- property: {
10
- control: { type: 'text' }
11
- },
12
- value: {
13
- options: [
14
- 'http://schema.org/name',
15
- 'https://schema.org/name',
16
- 'arcp://name,cooee-corpus/item/1-001',
17
- 'arcp://uuid,c6179148-3cde-4435-8e66-304453f89d59',
18
- 'something not url'
19
- ],
20
- control: { type: 'radio' }
21
- },
22
- onCreateEntity: { action: 'createEntity' }
23
- }
24
- } as Meta<typeof Url>;
25
-
26
- const Template: StoryFn<typeof Url> = (args) => <Url {...args} />;
27
-
28
- export const Default = Template.bind({});
29
- Default.args = {
30
- property: 'url',
31
- value: 'http://schema.org/name'
32
- };
33
-
34
- export const InvalidUrl = Template.bind({});
35
- InvalidUrl.args = {
36
- property: 'url',
37
- value: 'something not url'
38
- };
39
-
40
- export const Empty = Template.bind({});
41
- Empty.args = {
42
- property: 'url'
43
- };
@@ -1,75 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { Input, Button, Typography, Select } from 'antd';
3
- import { CheckOutlined } from '@ant-design/icons';
4
- import { useTranslation } from 'react-i18next';
5
- import { throttle } from 'lodash';
6
- import { isURL } from '../CrateManager/lib';
7
-
8
- export interface UrlProps {
9
- property: string;
10
- value?: string;
11
- onCreateEntity: (data: { property: string; json: any }) => void;
12
- }
13
-
14
- const Url: React.FC<UrlProps> = ({
15
- property,
16
- value,
17
- onCreateEntity
18
- }) => {
19
- const { t } = useTranslation();
20
- const [internalValue, setInternalValue] = useState(value || '');
21
- const [isValidUrl, setIsValidUrl] = useState(value ? isURL(value) : true);
22
-
23
- useEffect(() => {
24
- setInternalValue(value || '');
25
- setIsValidUrl(value ? isURL(value) : true);
26
- }, [value]);
27
-
28
- const throttledSave = throttle(() => {
29
- if (isValidUrl) {
30
- onCreateEntity({
31
- property,
32
- json: {
33
- '@id': internalValue.trim(),
34
- '@type': 'URL',
35
- name: internalValue.trim(),
36
- },
37
- });
38
- }
39
- }, 1000);
40
-
41
- const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
42
- const newValue = e.target.value;
43
- setInternalValue(newValue);
44
- setIsValidUrl(isURL(newValue));
45
- };
46
-
47
- return (
48
- <div className="flex flex-col describo-property-type-url">
49
- <div className="flex flex-row flex-grow gap-x-2">
50
- <Input
51
- size='middle'
52
- value={internalValue}
53
- onChange={handleChange}
54
- onBlur={throttledSave}
55
- status={!isValidUrl ? 'error' : ''}
56
- />
57
- <Button
58
- onClick={throttledSave}
59
- variant='solid'
60
- color="green"
61
- size="middle"
62
- danger={!isValidUrl}
63
- icon={<CheckOutlined />}
64
- />
65
- </div>
66
- {!isValidUrl && (
67
- <Typography.Text type="danger">
68
- {t('invalid_url_value')}
69
- </Typography.Text>
70
- )}
71
- </div>
72
- );
73
- };
74
-
75
- export default Url;
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { StoryFn, Meta } from '@storybook/react';
3
- import Value from './Value';
4
-
5
- export default {
6
- title: 'Primitives/Value',
7
- component: Value,
8
- argTypes: {
9
- property: {
10
- control: { type: 'text' }
11
- },
12
- value: {
13
- options: ['1', 'http://schema.org/name', '{ "key": "value" }'],
14
- control: { type: 'select' }
15
- }
16
- }
17
- } as Meta<typeof Value>;
18
-
19
- const Template: StoryFn<typeof Value> = (args) => <Value {...args} />;
20
-
21
- export const Default = Template.bind({});
22
- Default.args = {
23
- property: 'value',
24
- value: '1'
25
- };
26
-
27
- export const ValidUrl = Template.bind({});
28
- ValidUrl.args = {
29
- property: 'value',
30
- value: 'http://schema.org/name'
31
- };
32
-
33
- export const InvalidValue = Template.bind({});
34
- InvalidValue.args = {
35
- property: 'value',
36
- value: '{ "key": "value" }' as any
37
- };
@@ -1,30 +0,0 @@
1
- import React from 'react';
2
- import { isString } from 'lodash';
3
- import { useTranslation } from 'react-i18next';
4
-
5
- export interface ValueProps {
6
- property: string;
7
- value: string;
8
- }
9
-
10
- const Value: React.FC<ValueProps> = ({
11
- property,
12
- value
13
- }) => {
14
- const { t } = useTranslation();
15
- const isValidString = isString(value);
16
-
17
- return (
18
- <div className="flex flex-col describo-property-type-value">
19
- {isValidString ? (
20
- <div>{value}</div>
21
- ) : (
22
- <div>
23
- {t('invalid_value_value', { type: value })}
24
- </div>
25
- )}
26
- </div>
27
- );
28
- };
29
-
30
- export default Value;
@@ -1,12 +0,0 @@
1
- import dayjs from 'dayjs';
2
-
3
- export function checkDateIsValid(date?: string): boolean {
4
- if (!date) return false;
5
- try {
6
- const dateObj = dayjs(date);
7
- return dateObj.isValid();
8
- } catch (error) {
9
- console.error(error);
10
- return false;
11
- }
12
- }