@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,82 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { validateId } from "./validate-identifier";
3
-
4
- describe("Test @id's that should be valid", () => {
5
- test(`LICENCE.md should be valid`, () => {
6
- expect(validateId({ id: "LICENCE.md", type: "File" }).isValid).toBeTruthy;
7
- expect(validateId({ id: "LICENCE.md", type: "File, Licence" }).isValid).toBeTruthy;
8
- expect(validateId({ id: "LICENCE.md", type: ["File", "Licence"] }).isValid).toBeTruthy;
9
- });
10
- test(`/path/to/file should be valid`, () => {
11
- expect(validateId({ id: "/path/to/file", type: "Dataset" }).isValid).toBeTruthy;
12
- });
13
- test(`./ should be valid`, () => {
14
- expect(validateId({ id: "./", type: "Dataset" }).isValid).toBeTruthy;
15
- });
16
- test(`../ should be valid`, () => {
17
- expect(validateId({ id: "../", type: "Dataset" }).isValid).toBeTruthy;
18
- });
19
- test(`_:xxx should be valid`, () => {
20
- expect(validateId({ id: "_:xxx", type: "Dataset" }).isValid).toBeTruthy;
21
- });
22
- test(`#xxx should be valid`, () => {
23
- expect(validateId({ id: "#xxx", type: "Dataset" }).isValid).toBeTruthy;
24
- });
25
- test(`http://schema.org/name should be valid`, () => {
26
- expect(validateId({ id: "http://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
27
- });
28
- test(`https://schema.org/name should be valid`, () => {
29
- expect(validateId({ id: "https://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
30
- });
31
- test(`ftp://schema.org/name should be valid`, () => {
32
- expect(validateId({ id: "ftp://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
33
- });
34
- test(`ftps://schema.org/name should be valid`, () => {
35
- expect(validateId({ id: "ftps://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
36
- });
37
- test(`arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html`, () => {
38
- expect(
39
- validateId({
40
- id: "arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html",
41
- type: "Dataset",
42
- }).isValid
43
- ).toBeTruthy;
44
- });
45
- test(`arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/`, () => {
46
- expect(
47
- validateId({
48
- id: "arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/",
49
- type: "Dataset",
50
- }).isValid
51
- ).toBeTruthy;
52
- });
53
- test(`arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/`, () => {
54
- expect(
55
- validateId({
56
- id: "arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/",
57
- type: "Dataset",
58
- }).isValid
59
- ).toBeTruthy;
60
- });
61
- test(`arcp://name,gallery.example.org/`, () => {
62
- expect(validateId({ id: "arcp://name,gallery.example.org/a", type: "Dataset" }).isValid)
63
- .toBeTruthy;
64
- });
65
- });
66
- describe("Test @id's that should NOT be valid", () => {
67
- test(`no id passed`, () => {
68
- expect(validateId({ id: "", type: "Dataset" })).toEqual({ isValid: false, message: "No identifier was provided." });
69
- });
70
- test(`aaa should not be valid`, () => {
71
- expect(validateId({ id: "aaa", type: "Person" }).message).toEqual(
72
- "The identifier is not valid according to the RO Crate spec nor is it a valid IRI."
73
- );
74
- });
75
- test(`32a423d6-52ab-47e3-a9cd-54f418a48571 should not be valid`, () => {
76
- expect(
77
- validateId({ id: "32a423d6-52ab-47e3-a9cd-54f418a48571", type: "Person" }).message
78
- ).toEqual(
79
- `The identifier is not valid according to the RO Crate spec nor is it a valid IRI.`
80
- );
81
- });
82
- });
@@ -1,65 +0,0 @@
1
- import * as validateIriPkg from "../lib/validate-iri";
2
-
3
- type ValidateIdParams = {
4
- id: string | undefined;
5
- type: string | string[];
6
- };
7
-
8
- type ValidateIdResponse = { isValid: boolean; message?: string };
9
-
10
- export function validateId({ id, type }: ValidateIdParams): ValidateIdResponse {
11
- if (!id) {
12
- return { isValid: false, message: "No identifier was provided." };
13
- }
14
-
15
- // if it's the root descriptor - it's valid
16
- if (id === "ro-crate-metadata.json") {
17
- return { isValid: true };
18
- }
19
-
20
- if (type) {
21
- // if type matches File or Dataset then whatever is provided is valid
22
- type = Array.isArray(type) ? type.join(", ") : type;
23
- if (type.match(/file/i)) return { isValid: true };
24
- if (type.match(/Dataset/i)) return { isValid: true };
25
- }
26
-
27
- // @id is relative
28
- if (id.match(/^\/.*/)) return { isValid: true };
29
-
30
- // @id starting with . is valid
31
- if (id.match(/^\..*/)) return { isValid: true };
32
-
33
- // @id starting with # is valid
34
- if (id.match(/^\#.*/)) return { isValid: true };
35
-
36
- // @id with blank node is valid
37
- if (id.match(/^\_:.*/)) return { isValid: true };
38
-
39
- // arcp URI's are valid
40
- if (id.match(/arcp:\/\/name,.*/)) return { isValid: true };
41
- if (id.match(/arcp:\/\/uuid,.*/)) return { isValid: true };
42
- if (id.match(/arcp:\/\/ni,sha-256;,.*/)) return { isValid: true };
43
- // return { isValid: true };
44
-
45
- // otherwise check that the id is a valid IRI
46
- try {
47
- let result = validateIriPkg.validateIri(id, validateIriPkg.IriValidationStrategy.Strict);
48
- if (!result) {
49
- // it's valid
50
- return { isValid: true };
51
- }
52
- } catch (error) {
53
- return {
54
- isValid: false,
55
- message:
56
- "The identifier is not valid according to the RO Crate spec nor is it a valid IRI.",
57
- };
58
- }
59
-
60
- return {
61
- isValid: false,
62
- message:
63
- "The identifier is not valid according to the RO Crate spec nor is it a valid IRI.",
64
- };
65
- }
@@ -1,249 +0,0 @@
1
- import React, { useState, useMemo, useContext } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import AddControl from './AddControl';
4
- import Text from '../primitives/Text';
5
- import Date from '../primitives/Date';
6
- import DateTime from '../primitives/DateTime';
7
- import Time from '../primitives/Time';
8
- import Number from '../primitives/Number';
9
- import Url from '../primitives/Url';
10
- import Select from '../primitives/Select';
11
- import SelectUrl from '../primitives/SelectUrl';
12
- import SelectObject from '../primitives/SelectObject';
13
- import Geo from '../primitives/Geo';
14
- import AutoComplete from './AutoComplete';
15
- import Boolean from '../primitives/Boolean';
16
- import BulkAdd from './BulkAdd';
17
- import { ProfileManagerContext } from '../Shell';
18
-
19
- interface AddProps {
20
- property: string;
21
- definition: {
22
- id: string;
23
- type?: string;
24
- // Text-specific properties
25
- minLength?: number;
26
- maxLength?: number;
27
- regex?: string;
28
- dateFormat?: string[];
29
- // Number-specific properties
30
- minValue?: number;
31
- maxValue?: number;
32
- numberType?: string[];
33
- // Select-specific properties
34
- values?: string[];
35
- style?: 'dropdown' | 'radio' | 'checkbox';
36
- [key: string]: any;
37
- };
38
- embedded?: boolean;
39
- placeholder?: string;
40
- crateManager: any;
41
- onCreateProperty: (data: any) => void;
42
- onCreateEntity: (data: any) => void;
43
- onLinkEntity: (data: any) => void;
44
- }
45
-
46
- const Add: React.FC<AddProps> = ({
47
- property,
48
- definition,
49
- embedded = false,
50
- placeholder,
51
- crateManager,
52
- onCreateProperty,
53
- onCreateEntity,
54
- onLinkEntity
55
- }) => {
56
- const { t } = useTranslation();
57
- const profileManager = useContext(ProfileManagerContext);
58
-
59
- const [addType, setAddType] = useState<string | undefined>();
60
- const [localisedAddType, setLocalisedAddType] = useState<string | undefined>();
61
-
62
- const primitives = [
63
- 'Text', 'TextArea', 'Date', 'DateTime', 'Time',
64
- 'Number', 'Float', 'Integer', 'URL', 'Value',
65
- 'Select', 'SelectURL', 'SelectObject', 'Geo',
66
- 'Geometry', 'GeoCoordinates', 'GeoShape', 'Boolean'
67
- ];
68
-
69
- const types = useMemo(() => {
70
- if (!definition.type || definition.type === 'Value') return '';
71
- return definition.type;
72
- }, [definition.type]);
73
-
74
- const addSimpleType = useMemo(() => {
75
- return primitives.includes(addType || '');
76
- }, [addType, primitives]);
77
-
78
- const close = () => {
79
- setAddType(undefined);
80
- setLocalisedAddType(undefined);
81
- };
82
-
83
- const add = ({ type }: { type: string }) => {
84
- setAddType(type);
85
- setLocalisedAddType(profileManager?.getTypeLabel(type));
86
- };
87
-
88
- const bulkAdd = () => {
89
- setAddType('bulkAdd');
90
- };
91
-
92
- const createProperty = (data: any) => {
93
- onCreateProperty({ ...data, propertyId: definition.id });
94
- close();
95
- };
96
-
97
- const createEntity = (data: any) => {
98
- onCreateEntity({ ...data, property, propertyId: definition.id });
99
- close();
100
- };
101
-
102
- const linkEntity = (data: any) => {
103
- onLinkEntity({ ...data, property, propertyId: definition.id });
104
- close();
105
- };
106
-
107
- return (
108
- <div
109
- className={`flex flex-col my-2 p-1 rounded ${
110
- addType ? 'bg-indigo-200' : ''
111
- } ${addType?.match(/geo/gi) ? 'max-w-[715px]' : ''}`}
112
- >
113
- <AddControl
114
- crateManager={crateManager}
115
- types={types}
116
- selectedType={addType || ''}
117
- primitives={primitives}
118
- onAdd={add}
119
- onBulkAdd={bulkAdd}
120
- onClose={close}
121
- />
122
-
123
- {addSimpleType && (
124
- <div className="p-1">
125
- {addType === 'Text' && (
126
- <Text
127
- property={property}
128
- type="text"
129
- definition={definition}
130
- onSaveProperty={createProperty}
131
- placeholder={placeholder || t('add_text') || 'Add text'}
132
- />
133
- )}
134
- {addType === 'TextArea' && (
135
- <Text
136
- property={property}
137
- type="textarea"
138
- definition={definition}
139
- onSaveProperty={createProperty}
140
- placeholder={placeholder}
141
- />
142
- )}
143
- {addType === 'Date' && (
144
- <Date
145
- property={property}
146
- onSaveProperty={createProperty}
147
- />
148
- )}
149
- {addType === 'DateTime' && (
150
- <DateTime
151
- property={property}
152
- onSaveProperty={createProperty}
153
- />
154
- )}
155
- {addType && ['Number', 'Float', 'Integer'].includes(addType) && (
156
- <Number
157
- property={property}
158
- definition={definition}
159
- onSaveProperty={createProperty}
160
- />
161
- )}
162
- {addType === 'Time' && (
163
- <Time
164
- property={property}
165
- onSaveProperty={createProperty}
166
- />
167
- )}
168
- {addType === 'Select' && definition.values && (
169
- <Select
170
- property={property}
171
- definition={{
172
- values: definition.values,
173
- style: definition.style
174
- }}
175
- onSaveProperty={createProperty}
176
- />
177
- )}
178
- {addType === 'URL' && (
179
- <Url
180
- property={property}
181
- onCreateEntity={createEntity}
182
- />
183
- )}
184
- {addType === 'SelectURL' && definition.values && (
185
- <SelectUrl
186
- property={property}
187
- definition={{
188
- values: definition.values
189
- }}
190
- onCreateEntity={createEntity}
191
- />
192
- )}
193
- {addType === 'SelectObject' && definition.values && (
194
- <SelectObject
195
- property={property}
196
- definition={{
197
- values: definition.values
198
- }}
199
- onCreateEntity={createEntity}
200
- />
201
- )}
202
- {addType && ['Geo', 'Geometry', 'GeoCoordinates', 'GeoShape'].includes(addType) && (
203
- <Geo
204
- property={property}
205
- //onSaveProperty={createProperty}
206
- onCreateEntity={createEntity}
207
- onLinkEntity={linkEntity}
208
- />
209
- )}
210
- {addType === 'Boolean' && (
211
- <Boolean
212
- property={property}
213
- onSaveProperty={createProperty}
214
- />
215
- )}
216
- </div>
217
- )}
218
-
219
- {addType === 'bulkAdd' && (
220
- <BulkAdd
221
- types={types}
222
- primitives={primitives}
223
- onCreateEntity={createEntity}
224
- />
225
- )}
226
-
227
- {!addSimpleType && addType && addType !== 'bulkAdd' && (
228
- <div className="describo-property-type-entity">
229
- <div className="p-1 flex flex-row space-x-2 divide-y divide-gray-300 text-gray-600">
230
- <div className="w-full">
231
- {addType === 'ANY' ? (
232
- <div>{t('associate_any_prompt')}</div>
233
- ) : (
234
- <div>{t('associate_existing_prompt', { addType: localisedAddType || addType })}</div>
235
- )}
236
- <AutoComplete
237
- type={addType || ''}
238
- onLinkEntity={linkEntity}
239
- onCreateEntity={createEntity}
240
- />
241
- </div>
242
- </div>
243
- </div>
244
- )}
245
- </div>
246
- );
247
- };
248
-
249
- export default Add;
@@ -1,126 +0,0 @@
1
- import React from 'react';
2
- import { StoryFn, Meta } from '@storybook/react';
3
- import AddControl from './AddControl';
4
- import { ProfileManager } from '../CrateManager/profile-manager';
5
-
6
- const profileManager = new ProfileManager({});
7
-
8
- const crateManager = {
9
- getEntities: () => [],
10
- profileManager,
11
- };
12
-
13
- export default {
14
- title: 'Components/AddControl',
15
- component: AddControl,
16
- argTypes: {
17
- embedded: {
18
- control: 'boolean',
19
- },
20
- onAdd: { action: 'add' },
21
- onBulkAdd: { action: 'bulkAdd' },
22
- onClose: { action: 'close' },
23
- },
24
- } as Meta;
25
-
26
- interface AddControlProps {
27
- crateManager: any;
28
- types: string | string[];
29
- selectedType: string;
30
- primitives: string[];
31
- onAdd: (data: { type: string }) => void;
32
- onBulkAdd: () => void;
33
- onClose: () => void;
34
- help?: string;
35
- multiple?: boolean;
36
- embedded?: boolean;
37
- values?: Array<string | { '@id': string; '@type': string; name: string }>;
38
- }
39
-
40
- const Template: StoryFn<AddControlProps> = (args) => <AddControl {...args} />;
41
-
42
- Template.args = {
43
- types: ['Text'],
44
- selectedType: '',
45
- primitives: ['Text'],
46
- onAdd: (data: { type: string }) => console.log('Add:', data),
47
- onBulkAdd: () => console.log('Bulk Add'),
48
- onClose: () => console.log('Close')
49
- };
50
-
51
- export const TextPrimitives = Template.bind({});
52
- TextPrimitives.args = {
53
- types: ['Text', 'TextArea', 'URL'],
54
- selectedType: '',
55
- primitives: ['Text', 'TextArea', 'URL'],
56
- help: 'some help text',
57
- multiple: true,
58
- embedded: false,
59
- };
60
-
61
- export const DateTimePrimitives = Template.bind({});
62
- DateTimePrimitives.args = {
63
- types: ['Date', 'DateTime', 'Time'],
64
- selectedType: '',
65
- primitives: ['Date', 'DateTime', 'Time'],
66
- help: 'some help text',
67
- multiple: true,
68
- embedded: false,
69
- };
70
-
71
- export const NumberPrimitives = Template.bind({});
72
- NumberPrimitives.args = {
73
- types: ['Number', 'Float', 'Integer'],
74
- selectedType: '',
75
- primitives: ['Number', 'Float', 'Integer'],
76
- help: 'some help text',
77
- multiple: true,
78
- embedded: false,
79
- };
80
-
81
- export const SelectPrimitive = Template.bind({});
82
- SelectPrimitive.args = {
83
- types: ['Select'],
84
- selectedType: '',
85
- primitives: ['Select'],
86
- help: 'some help text',
87
- multiple: true,
88
- embedded: false,
89
- values: ['a', 'b', 'c'],
90
- };
91
-
92
- export const SelectUrlPrimitive = Template.bind({});
93
- SelectUrlPrimitive.args = {
94
- types: ['SelectURL'],
95
- selectedType: '',
96
- primitives: ['SelectURL'],
97
- help: 'some help text',
98
- multiple: true,
99
- embedded: false,
100
- values: ['http://schema.org/name', 'https://schema.org/name', 'arcp://name,...'],
101
- };
102
-
103
- export const SelectObjectPrimitive = Template.bind({});
104
- SelectObjectPrimitive.args = {
105
- types: ['SelectObject'],
106
- selectedType: '',
107
- primitives: ['SelectObject'],
108
- help: 'some help text',
109
- multiple: true,
110
- embedded: false,
111
- values: [
112
- { '@id': '#1', '@type': 'Dataset', name: '1' },
113
- { '@id': '#2', '@type': 'Dataset', name: '2' },
114
- { '@id': '#3', '@type': 'Dataset', name: '3' },
115
- ],
116
- };
117
-
118
- export const GeoPrimitives = Template.bind({});
119
- GeoPrimitives.args = {
120
- types: ['Geo', 'GeoCoordinates', 'GeoShape'],
121
- selectedType: '',
122
- primitives: ['Geo', 'GeoCoordinates', 'GeoShape'],
123
- help: 'some help text',
124
- multiple: true,
125
- embedded: false,
126
- };
@@ -1,84 +0,0 @@
1
- import React from 'react';
2
- import { Button } from 'antd';
3
- import { PlusOutlined, CloseOutlined, StarOutlined } from '@ant-design/icons';
4
- import { difference } from 'lodash';
5
- import { useContext } from 'react';
6
- import { ProfileManagerContext } from '../Shell';
7
-
8
- interface AddControlProps {
9
- crateManager: any;
10
- types: string | string[];
11
- selectedType: string;
12
- primitives: string[];
13
- onAdd: (data: { type: string }) => void;
14
- onBulkAdd: () => void;
15
- onClose: () => void;
16
- }
17
-
18
- const AddControl: React.FC<AddControlProps> = ({
19
- types,
20
- selectedType,
21
- primitives,
22
- onAdd,
23
- onBulkAdd,
24
- onClose
25
- }) => {
26
- const profileManager = useContext(ProfileManagerContext);
27
- const notOnlyPrimitives = difference(
28
- Array.isArray(types) ? types : [types],
29
- [...primitives, 'ANY']
30
- );
31
-
32
- const getTypeLabelFromProfile = (type: string) => {
33
- return profileManager?.getTypeLabel(type);
34
- };
35
-
36
- const toggle = (type: string) => {
37
- if (selectedType === type) {
38
- onClose();
39
- } else {
40
- onAdd({ type });
41
- }
42
- };
43
-
44
- const handleBulkAdd = () => {
45
- if (selectedType === 'bulkAdd') {
46
- onClose();
47
- } else {
48
- onBulkAdd();
49
- }
50
- };
51
-
52
- return (
53
- <div className="flex flex-row flex-wrap">
54
- {(Array.isArray(types) ? types : [types]).map((type, idx) => (
55
- <div key={idx} className="m-1">
56
- <Button
57
- onClick={() => toggle(type)}
58
- type="primary"
59
- size="middle"
60
- className="focus:outline-none focus:border-2 focus:border-green-600"
61
- icon={(!selectedType || selectedType !== type) ? <PlusOutlined /> : <CloseOutlined />}
62
- >
63
- &nbsp;{getTypeLabelFromProfile(type)}
64
- </Button>
65
- </div>
66
- ))}
67
- {notOnlyPrimitives.length > 0 && (
68
- <div className="m-1">
69
- <Button
70
- onClick={handleBulkAdd}
71
- type="primary"
72
- size="middle"
73
- className="focus:outline-none focus:border-2 focus:border-green-600"
74
- icon={(!selectedType || selectedType !== 'bulkAdd') ? <StarOutlined /> : <CloseOutlined />}
75
- >
76
- &nbsp; Bulk Add
77
- </Button>
78
- </div>
79
- )}
80
- </div>
81
- );
82
- };
83
-
84
- export default AddControl;