@arpproject/recrate 0.1.7 → 0.1.9

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,220 +0,0 @@
1
- import difference from "lodash/difference";
2
- import orderBy from "lodash/orderBy";
3
- import uniqBy from "lodash/uniqBy";
4
- const coreProperties = ["@id", "@type", "@reverse", "name"];
5
- import type {
6
- ProfileManagerType,
7
- ProfileInput,
8
- ProfileLayout,
9
- ProfileLayoutGroup,
10
- NormalisedEntityDefinition,
11
- } from "../types";
12
-
13
- export function applyLayout({
14
- configuration,
15
- entity,
16
- extraProperties,
17
- profileManager: pm,
18
- }: {
19
- configuration: { [key: string]: any };
20
- entity: NormalisedEntityDefinition;
21
- extraProperties: string[];
22
- profileManager: ProfileManagerType;
23
- }): {
24
- renderTabs: boolean;
25
- missingRequiredData: boolean;
26
- entity: NormalisedEntityDefinition;
27
- tabs: ProfileLayoutGroup[];
28
- } {
29
- let missingRequiredData = false;
30
- let inputs = [];
31
-
32
- ({ missingRequiredData, entity, inputs } = getProfileInputs({
33
- configuration,
34
- entity,
35
- pm,
36
- }));
37
-
38
- if (extraProperties.length) {
39
- extraProperties.forEach((property) => {
40
- if (!entity[property]) entity[property] = [];
41
- });
42
- }
43
- let layouts = pm.getLayout({ entity });
44
- let renderTabs = false;
45
- let tabs = [] as ProfileLayoutGroup[];
46
- if (layouts) {
47
- renderTabs = true;
48
- tabs = applyLayoutToEntity({ layouts, inputs, entity });
49
- tabs = applyTabDataIndicators({ configuration, tabs, entity });
50
- }
51
-
52
- return { renderTabs, missingRequiredData, entity, tabs };
53
- }
54
-
55
- function getProfileInputs({
56
- configuration,
57
- entity,
58
- pm,
59
- }: {
60
- configuration: { [key: string]: any };
61
- entity: NormalisedEntityDefinition;
62
- pm: ProfileManagerType;
63
- }): {
64
- missingRequiredData: boolean;
65
- entity: NormalisedEntityDefinition;
66
- inputs: ProfileInput[];
67
- } {
68
- const inputs = pm.getInputsFromProfile({ entity });
69
-
70
- let missingRequiredData = false;
71
- for (let input of inputs) {
72
- if (input.name === "name") continue;
73
- if (!input.id) {
74
- console.error(`Excluding invalid input - missing id: ${input}`);
75
- continue;
76
- }
77
- if (!entity[input.name] && !configuration.readonly) {
78
- entity[input.name] = [];
79
- }
80
-
81
- if (input.required && (!entity[input.name] || !entity[input.name].length)) {
82
- missingRequiredData = true;
83
- }
84
- }
85
- return { missingRequiredData, entity, inputs };
86
- }
87
-
88
- function applyLayoutToEntity({
89
- layouts,
90
- inputs,
91
- entity,
92
- }: {
93
- layouts: ProfileLayout;
94
- inputs: ProfileInput[];
95
- entity: NormalisedEntityDefinition;
96
- }): ProfileLayoutGroup[] {
97
- // normalise the layouts
98
- let sort = false;
99
- for (let name of Object.keys(layouts)) {
100
- layouts[name].name = name;
101
- layouts[name].inputs = [];
102
- if (!layouts[name].properties) layouts[name].properties = [];
103
- if (layouts[name].order) sort = true;
104
- }
105
-
106
- // sort the profile inputs into their groups
107
- for (let input of inputs) {
108
- if (coreProperties.includes(input.name)) continue;
109
- if (!entity[input.name]) continue;
110
- if (input.hide) continue;
111
- if (input.group && layouts[input.group]) {
112
- layouts[input.group].inputs.push(input);
113
- }
114
- }
115
-
116
- // now sort any ungrouped inputs using the properties
117
- // array in each layout
118
- let ungroupedInputs = [];
119
- for (let input of inputs) {
120
- if (coreProperties.includes(input.name)) continue;
121
- if (!entity[input.name]) continue;
122
- if (input?.hide) continue;
123
- if (input.group && layouts[input.group]) continue;
124
- let matched = false;
125
- for (let name of Object.keys(layouts)) {
126
- if (
127
- layouts[name] &&
128
- layouts[name].properties &&
129
- (layouts[name].properties.includes(input.id) ||
130
- layouts[name].properties.includes(input.name))
131
- ) {
132
- layouts[name].inputs.push(input);
133
- matched = true;
134
- }
135
- }
136
- if (!matched) ungroupedInputs.push(input);
137
- }
138
-
139
- // and any that still aren't part of a group go into overflow
140
- for (let input of ungroupedInputs) {
141
- layouts.overflow.inputs.push(input);
142
- }
143
-
144
- // get a list of the properties defined on the entity
145
- // but which have no input definition and pop them
146
- // into the overflow group with a default Text configuration
147
- let profileInputs = inputs.map((i) => i.name);
148
- let entityProperties = Object.keys(entity);
149
- let missingInputs = difference(entityProperties, profileInputs);
150
- for (let input of missingInputs) {
151
- if (coreProperties.includes(input)) continue;
152
- layouts.overflow.inputs.push({
153
- id: "",
154
- name: input,
155
- multiple: true,
156
- type: ["Text"],
157
- });
158
- }
159
-
160
- let tabs: any[] = Object.keys(layouts)
161
- .map((k) => layouts[k])
162
- .filter((t) => t.name !== "appliesTo");
163
- if (sort) tabs = orderBy(tabs, "order");
164
-
165
- // if a properties array is defined
166
- // reorder the inputs by the order in that array
167
- for (let tab of tabs) {
168
- if (tab.properties.length) {
169
- let orderedInputs = [];
170
- let otherInputs = [];
171
- for (let property of tab.properties) {
172
- for (let input of tab.inputs) {
173
- if ([input.name, input.id].includes(property)) {
174
- orderedInputs.push(input);
175
- } else {
176
- otherInputs.push(input);
177
- }
178
- }
179
- }
180
- orderedInputs = uniqBy(orderedInputs, "name");
181
- otherInputs = uniqBy(otherInputs, "name");
182
- otherInputs = difference(otherInputs, orderedInputs);
183
- tab.inputs = [...orderedInputs, ...otherInputs];
184
- }
185
- }
186
- return tabs;
187
- }
188
-
189
- function applyTabDataIndicators({
190
- configuration,
191
- tabs,
192
- entity,
193
- }: {
194
- configuration: { [key: string]: any };
195
- tabs: ProfileLayoutGroup[];
196
- entity: NormalisedEntityDefinition;
197
- }): ProfileLayoutGroup[] {
198
- // special case: component in readonly mode
199
- if (configuration.readonly) {
200
- tabs = tabs.map((tab) => {
201
- tab.hasData = false;
202
- tab.missingRequiredData = false;
203
- return tab;
204
- });
205
- } else {
206
- for (let tab of tabs) {
207
- tab.missingRequiredData = false;
208
- tab.hasData = false;
209
- for (let input of tab.inputs) {
210
- if (input.required && !entity[input.name].length) {
211
- tab.missingRequiredData = true;
212
- }
213
- if (entity[input.name].length) {
214
- tab.hasData = true;
215
- }
216
- }
217
- }
218
- }
219
- return tabs;
220
- }
@@ -1,337 +0,0 @@
1
- import React, {
2
- useState,
3
- useEffect,
4
- useRef,
5
- useCallback,
6
- useMemo,
7
- useContext,
8
- JSX,
9
- } from "react";
10
- //import RenderEntity from "./RenderEntity/Shell";
11
- import RenderEntity from "./RenderEntity/Shell2";
12
- import {
13
- CrateManager,
14
- } from "./CrateManager/crate-manager";
15
- import {
16
- ProfileManager,
17
- } from "./CrateManager/profile-manager";
18
- import { useStateStore } from "./store";
19
- import i18next from "./i18n";
20
- import isEmpty from "lodash/isEmpty";
21
- import isFunction from "lodash/isFunction";
22
- import { CrateManagerType, ProfileManagerType, UnverifiedCrate } from "./types"; // Add appropriate types
23
- import { propertyDefinitions } from "./property-definitions";
24
- import { Lookup } from "./RenderEntity/auto-complete.lib";
25
- import { App as AntApp, ConfigProvider } from 'antd';
26
- import { createScopedCache } from './emotionCache';
27
- import { CacheProvider } from "@emotion/react";
28
-
29
- const antdCache = createScopedCache('recrate');
30
-
31
-
32
- export interface DescriboCrateBuilderProps {
33
- crate?: CrateManagerType["crate"];
34
- profile?: ProfileManagerType["profile"];
35
- entityId?: string;
36
- lookup?: any;
37
- enableContextEditor?: boolean;
38
- enableCratePreview?: boolean;
39
- enableBrowseEntities?: boolean;
40
- enableTemplateSave?: boolean;
41
- enableReverseLinkBrowser?: boolean;
42
- enableUrlMarkup?: boolean;
43
- enableEntityTimestamps?: boolean;
44
- purgeUnlinkedEntities?: boolean;
45
- readonly?: boolean;
46
- webComponent?: boolean;
47
- tabLocation?: string;
48
- showControls?: boolean;
49
- language?: string;
50
- resetTabOnEntityChange?: boolean;
51
- resetTabOnProfileChange?: boolean;
52
- onReady?: () => void;
53
- onError?: (errors: any) => void;
54
- onWarning?: (warnings: any) => void;
55
- onNavigation?: (info: { "@id": string; "@type": string[]; name: string }) => void;
56
- onSaveCrate?: (saveData: {crate: any}) => void,
57
- onSaveEntityTemplate?: (entity: any) => void;
58
- }
59
-
60
-
61
- // Use propertyDefinitions to define props
62
- export const ProfileManagerContext = React.createContext<any>(null);
63
- export const CrateManagerContext = React.createContext<any>(null);
64
- export const LookupsContext = React.createContext<any>(null);
65
-
66
- export function DescriboCrateBuilder(props: DescriboCrateBuilderProps): JSX.Element {
67
- const {
68
- crate,
69
- profile,
70
- entityId,
71
- lookup,
72
- enableContextEditor = propertyDefinitions.enableContextEditor.default,
73
- enableCratePreview = propertyDefinitions.enableCratePreview.default,
74
- enableBrowseEntities = propertyDefinitions.enableBrowseEntities.default,
75
- enableTemplateSave = propertyDefinitions.enableTemplateSave.default,
76
- enableReverseLinkBrowser = propertyDefinitions.enableReverseLinkBrowser.default,
77
- enableUrlMarkup = propertyDefinitions.enableUrlMarkup.default,
78
- enableEntityTimestamps = propertyDefinitions.enableEntityTimestamps.default,
79
- purgeUnlinkedEntities = propertyDefinitions.purgeUnlinkedEntities.default,
80
- readonly = propertyDefinitions.readonly.default,
81
- webComponent = propertyDefinitions.webComponent.default,
82
- tabLocation = propertyDefinitions.tabLocation.default,
83
- showControls = propertyDefinitions.showControls.default,
84
- language = propertyDefinitions.language.default,
85
- resetTabOnEntityChange = false,
86
- resetTabOnProfileChange = false,
87
- onReady,
88
- onError,
89
- onWarning,
90
- onNavigation,
91
- onSaveCrate,
92
- onSaveEntityTemplate,
93
- } = props;
94
-
95
- console.log("DescriboCrateBuilder props:", { crate, profile, entityId });
96
- const [ready, setReady] = useState(false);
97
- const [error, setError] = useState(false);
98
- const [contextEntity, setContextEntity] = useState<any | null>(null);
99
- const [cm, setCm] = useState<CrateManager | null>(null);
100
- const [pm, setPm] = useState<ProfileManager | null>(null);
101
- const [lookups, setLookups] = useState<typeof propertyDefinitions.lookup | null>(null);
102
- const state = useStateStore();
103
- const renderEntityRef = useRef<any>(null);
104
- const keys = useRef({ cm: 0, pm: 0, lookups: 0 });
105
-
106
- const configuration = useMemo(() => {
107
- const config = {
108
- enableContextEditor,
109
- enableCratePreview,
110
- enableBrowseEntities,
111
- enableTemplateSave,
112
- enableReverseLinkBrowser,
113
- enableUrlMarkup,
114
- enableEntityTimestamps,
115
- purgeUnlinkedEntities,
116
- readonly,
117
- webComponent,
118
- tabLocation,
119
- showControls,
120
- language,
121
- enableTemplateLookups: false,
122
- enableDataPackLookups: false,
123
- };
124
-
125
-
126
-
127
- if (lookup) {
128
- if (isFunction(lookup.entityTemplates)) {
129
- config.enableTemplateLookups = true;
130
- }
131
- if (isFunction(lookup.dataPacks)) {
132
- config.enableDataPackLookups = true;
133
- }
134
- }
135
-
136
- return config;
137
- }, [
138
- enableContextEditor,
139
- enableCratePreview,
140
- enableBrowseEntities,
141
- enableTemplateSave,
142
- enableReverseLinkBrowser,
143
- enableUrlMarkup,
144
- enableEntityTimestamps,
145
- purgeUnlinkedEntities,
146
- readonly,
147
- webComponent,
148
- tabLocation,
149
- showControls,
150
- language,
151
- lookup,
152
- ]);
153
-
154
- const init = useCallback(async () => {
155
-
156
- console.log("Initializing with crate:", crate);
157
- console.log("Profile loaded:", profile);
158
-
159
- i18next.changeLanguage(language);
160
-
161
- if (!crate || isEmpty(crate)) {
162
- setReady(false);
163
- setContextEntity(null);
164
- setError(false);
165
- return;
166
- }
167
-
168
- const newCm = new CrateManager({
169
- crate: crate as UnverifiedCrate,
170
- entityTimestamps: enableEntityTimestamps,
171
- });
172
-
173
- console.log("Entity:", newCm.getEntity({ id: entityId || "./" }));
174
-
175
- // Create a deep clone of the profile to avoid mutation issues
176
- const profileClone = profile ? JSON.parse(JSON.stringify(profile)) : {};
177
-
178
- const newPm = new ProfileManager({
179
- profile: profileClone,
180
- });
181
-
182
- // Add a key property to the ProfileManager for tracking changes
183
- newPm.$key = ++keys.current.pm;
184
-
185
- newCm.setProfileManager(newPm as ProfileManagerType);
186
-
187
- // Only set context if it exists
188
- if (newPm.context) newCm.setContext(newPm.context);
189
-
190
- if (lookup) {
191
- setLookups({ ...lookup, $key: ++keys.current.lookups });
192
- }
193
-
194
- const errors = newCm.getErrors();
195
- if (errors.hasError) {
196
- onError?.({ errors }); // Pass errors wrapped in an object to match Vue implementation
197
- setReady(false);
198
- //setError(true);
199
- console.error("❌ CrateManager reported errors:", errors);
200
- return;
201
- }
202
-
203
- const warnings = newCm.getWarnings();
204
- if (warnings.hasWarning) {
205
- onWarning?.({ warnings }); // Pass warnings wrapped in an object
206
- }
207
-
208
- setCm(newCm);
209
- setPm(newPm);
210
- setError(false);
211
-
212
- // Force state update to ensure UI refreshes
213
- state.configuration = configuration;
214
-
215
- try {
216
- // Add error handling for entity setting
217
- if (entityId) {
218
- handleSetCurrentEntity({ id: entityId });
219
- } else {
220
- // Make sure root entity exists and can be set
221
- const rootEntity = newCm.getEntity({ id: "./" });
222
- if (!isEmpty(rootEntity)) {
223
- setContextEntity(rootEntity);
224
- state.editorState.push({ id: rootEntity["@id"] });
225
- } else {
226
- console.warn("Root entity './' not found");
227
- setError(true);
228
- return;
229
- }
230
- }
231
-
232
- setReady(true);
233
- onReady?.();
234
- } catch (error) {
235
- console.error("Error setting current entity:", error);
236
- setError(true);
237
- onError?.({ error: "Failed to initialize entity" });
238
- }
239
- }, [crate, profile, entityId, lookup, configuration]);
240
-
241
- const handleSetCurrentEntity = useCallback((params: { id: string; updateState?: boolean }) => {
242
- const { id, updateState = true } = params;
243
- if (!id || !cm) return;
244
-
245
- try {
246
- const entity = cm.getEntity({ id });
247
- if (!isEmpty(entity)) {
248
- setContextEntity(entity);
249
- onNavigation?.({
250
- "@id": entity["@id"],
251
- "@type": entity["@type"],
252
- name: entity.name,
253
- });
254
-
255
- if (updateState) {
256
- state.editorState.push({ id: entity["@id"] });
257
- }
258
- } else {
259
- console.warn(`Entity with id ${id} not found`);
260
- // Try to fall back to root entity if not already trying to load it
261
- if (id !== "./") {
262
- handleSetCurrentEntity({ id: "./" });
263
- }
264
- }
265
- } catch (error) {
266
- console.error("Error in handleSetCurrentEntity:", error);
267
- onError?.({ error: "Failed to set entity" });
268
- }
269
- }, [cm, onNavigation]);
270
-
271
- const saveEntityAsTemplate = () => {
272
- if (!cm || !contextEntity) return;
273
- const template = cm.exportEntityTemplate({
274
- id: contextEntity["@id"],
275
- resolveDepth: 1, // Default resolveDepth or adjust as needed
276
- });
277
- onSaveEntityTemplate?.(template);
278
- };
279
-
280
- const handleWarning = () => {
281
- onWarning?.({});
282
- };
283
-
284
- const handleError = () => {
285
- onError?.({});
286
- };
287
-
288
- useEffect(() => {
289
- state.editorState.reset();
290
- init();
291
- }, [crate, profile, init]);
292
-
293
- useEffect(() => {
294
- if (entityId && entityId !== contextEntity?.["@id"]) {
295
- handleSetCurrentEntity({ id: entityId }); // Pass an object with the id property
296
- }
297
- }, [entityId, contextEntity, handleSetCurrentEntity]);
298
-
299
- const saveCrate = () => {
300
- if (!cm) return;
301
- if (purgeUnlinkedEntities) {
302
- cm.purgeUnlinkedEntities();
303
- }
304
- const exported = cm.exportCrate();
305
- onSaveCrate?.({ crate: exported });
306
- };
307
-
308
- return (
309
- <div className="recrate">
310
- <CacheProvider value={antdCache}>
311
- <ConfigProvider>
312
- <AntApp className="recrate-ant">
313
- <ProfileManagerContext.Provider value={pm}>
314
- <CrateManagerContext.Provider value={cm}>
315
- <LookupsContext.Provider value={lookups}>
316
- {ready && !error && contextEntity && (
317
- <RenderEntity
318
- ref={renderEntityRef}
319
- entity={contextEntity}
320
- onLoadEntity={handleSetCurrentEntity}
321
- onSaveCrate={saveCrate}
322
- onSaveEntityTemplate={saveEntityAsTemplate}
323
- onWarning={handleWarning}
324
- onError={handleError}
325
- />
326
- )}
327
- </LookupsContext.Provider>
328
- </CrateManagerContext.Provider>
329
- </ProfileManagerContext.Provider>
330
- </AntApp>
331
- </ConfigProvider>
332
- </CacheProvider>
333
- </div>
334
- );
335
- };
336
-
337
- export default DescriboCrateBuilder;
@@ -1,65 +0,0 @@
1
- .el-tabs__item {
2
- height: unset;
3
- }
4
-
5
- .el-select-dropdown__wrap {
6
- max-height: 500px !important;
7
- }
8
-
9
- .el-select-group__title {
10
- font-size: 14px !important;
11
- }
12
-
13
- /* ::-webkit-scrollbar {
14
- display: none;
15
- } */
16
-
17
- /* Customize website's scrollbar like Mac OS
18
- Not supports in Firefox and IE */
19
- .scrollbar {
20
- overflow: overlay
21
- }
22
-
23
- /* total width */
24
- .scrollbar::-webkit-scrollbar {
25
- background-color: rgba(0, 0, 0, 0);
26
- width: 16px;
27
- height: 16px;
28
- z-index: 999999;
29
- }
30
-
31
- /* background of the scrollbar except button or resizer */
32
- .scrollbar::-webkit-scrollbar-track {
33
- background-color: rgba(0, 0, 0, 0);
34
- }
35
-
36
- /* scrollbar itself */
37
- .scrollbar::-webkit-scrollbar-thumb {
38
- background-color: rgba(0, 0, 0, 0);
39
- border-radius: 16px;
40
- border: 0px solid #fff;
41
- }
42
-
43
- /* set button(top and bottom of the scrollbar) */
44
- .scrollbar::-webkit-scrollbar-button {
45
- display: none;
46
- }
47
-
48
-
49
- /* scrollbar when element is hovered */
50
- .scrollbar:hover::-webkit-scrollbar-thumb {
51
- background-color: #a0a0a5;
52
- border: 4px solid #fff;
53
- }
54
-
55
- /* scrollbar when scrollbar is hovered */
56
- .scrollbar::-webkit-scrollbar-thumb:hover {
57
- background-color: #a0a0a5;
58
- border: 4px solid #f4f4f4
59
- }
60
-
61
- .cm-editor {
62
- font-size: 12px;
63
- height: 350px;
64
- overflow: auto;
65
- }