@arpproject/recrate 0.1.18 → 0.1.20
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,8 +1,12 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
1
2
|
import { EditorState } from './editor-state';
|
|
2
3
|
interface Store {
|
|
3
4
|
configuration: Record<string, any>;
|
|
4
5
|
editorState: EditorState;
|
|
5
6
|
setConfiguration: (config: Record<string, any>) => void;
|
|
6
7
|
}
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const StateStoreProvider: ({ children }: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}) => React.FunctionComponentElement<React.ProviderProps<import('zustand').StoreApi<Store> | null>>;
|
|
11
|
+
export declare const useStateStore: () => Store;
|
|
8
12
|
export {};
|
package/dist/recrate.es.js
CHANGED
|
@@ -58701,7 +58701,7 @@ function requireLodash() {
|
|
|
58701
58701
|
copyObject(source, keys2(source), object4, customizer);
|
|
58702
58702
|
});
|
|
58703
58703
|
var at = flatRest(baseAt);
|
|
58704
|
-
function
|
|
58704
|
+
function create(prototype, properties) {
|
|
58705
58705
|
var result2 = baseCreate(prototype);
|
|
58706
58706
|
return properties == null ? result2 : baseAssign(result2, properties);
|
|
58707
58707
|
}
|
|
@@ -59448,7 +59448,7 @@ function requireLodash() {
|
|
|
59448
59448
|
lodash2.conforms = conforms;
|
|
59449
59449
|
lodash2.constant = constant;
|
|
59450
59450
|
lodash2.countBy = countBy;
|
|
59451
|
-
lodash2.create =
|
|
59451
|
+
lodash2.create = create;
|
|
59452
59452
|
lodash2.curry = curry;
|
|
59453
59453
|
lodash2.curryRight = curryRight;
|
|
59454
59454
|
lodash2.debounce = debounce2;
|
|
@@ -67349,13 +67349,6 @@ function useStore(api2, selector = identity) {
|
|
|
67349
67349
|
React__default.useDebugValue(slice2);
|
|
67350
67350
|
return slice2;
|
|
67351
67351
|
}
|
|
67352
|
-
const createImpl = (createState) => {
|
|
67353
|
-
const api2 = createStore(createState);
|
|
67354
|
-
const useBoundStore = (selector) => useStore(api2, selector);
|
|
67355
|
-
Object.assign(useBoundStore, api2);
|
|
67356
|
-
return useBoundStore;
|
|
67357
|
-
};
|
|
67358
|
-
const create = ((createState) => createState ? createImpl(createState) : createImpl);
|
|
67359
67352
|
let EditorState$1 = class EditorState {
|
|
67360
67353
|
constructor() {
|
|
67361
67354
|
this.history = [];
|
|
@@ -67378,6 +67371,8 @@ let EditorState$1 = class EditorState {
|
|
|
67378
67371
|
*/
|
|
67379
67372
|
push({ id: id2 }) {
|
|
67380
67373
|
if (!id2) return;
|
|
67374
|
+
const latest = this.latest();
|
|
67375
|
+
if ((latest == null ? void 0 : latest.id) === id2) return;
|
|
67381
67376
|
if (this.history.length - 1 > this.current) {
|
|
67382
67377
|
this.history = this.history.slice(0, this.current + 1);
|
|
67383
67378
|
}
|
|
@@ -67404,6 +67399,12 @@ let EditorState$1 = class EditorState {
|
|
|
67404
67399
|
latest() {
|
|
67405
67400
|
return this.history[this.current];
|
|
67406
67401
|
}
|
|
67402
|
+
canBack() {
|
|
67403
|
+
return this.current > 0;
|
|
67404
|
+
}
|
|
67405
|
+
canForward() {
|
|
67406
|
+
return this.current < this.history.length - 1;
|
|
67407
|
+
}
|
|
67407
67408
|
/**
|
|
67408
67409
|
* Update the current entry
|
|
67409
67410
|
*
|
|
@@ -67443,11 +67444,28 @@ let EditorState$1 = class EditorState {
|
|
|
67443
67444
|
});
|
|
67444
67445
|
}
|
|
67445
67446
|
};
|
|
67446
|
-
const
|
|
67447
|
+
const createStateStore = () => createStore((set2) => ({
|
|
67447
67448
|
configuration: {},
|
|
67448
67449
|
editorState: new EditorState$1(),
|
|
67449
67450
|
setConfiguration: (config2) => set2({ configuration: config2 })
|
|
67450
67451
|
}));
|
|
67452
|
+
const defaultStore = createStateStore();
|
|
67453
|
+
const StateStoreContext = createContext(null);
|
|
67454
|
+
const StateStoreProvider = ({ children }) => {
|
|
67455
|
+
const storeRef = useRef(null);
|
|
67456
|
+
if (!storeRef.current) {
|
|
67457
|
+
storeRef.current = createStateStore();
|
|
67458
|
+
}
|
|
67459
|
+
return React__default.createElement(
|
|
67460
|
+
StateStoreContext.Provider,
|
|
67461
|
+
{ value: storeRef.current },
|
|
67462
|
+
children
|
|
67463
|
+
);
|
|
67464
|
+
};
|
|
67465
|
+
const useStateStore = () => {
|
|
67466
|
+
const scopedStore = useContext(StateStoreContext);
|
|
67467
|
+
return useStore(scopedStore ?? defaultStore);
|
|
67468
|
+
};
|
|
67451
67469
|
const EntityId = ({ entity, onUpdate }) => {
|
|
67452
67470
|
var _a2;
|
|
67453
67471
|
const state = useStateStore();
|
|
@@ -77002,12 +77020,12 @@ function requireLeafletSrc() {
|
|
|
77002
77020
|
toBack(layer2._container);
|
|
77003
77021
|
}
|
|
77004
77022
|
};
|
|
77005
|
-
var
|
|
77023
|
+
var create = Browser.vml ? vmlCreate : svgCreate;
|
|
77006
77024
|
var SVG = Renderer.extend({
|
|
77007
77025
|
_initContainer: function() {
|
|
77008
|
-
this._container =
|
|
77026
|
+
this._container = create("svg");
|
|
77009
77027
|
this._container.setAttribute("pointer-events", "none");
|
|
77010
|
-
this._rootGroup =
|
|
77028
|
+
this._rootGroup = create("g");
|
|
77011
77029
|
this._container.appendChild(this._rootGroup);
|
|
77012
77030
|
},
|
|
77013
77031
|
_destroyContainer: function() {
|
|
@@ -77034,7 +77052,7 @@ function requireLeafletSrc() {
|
|
|
77034
77052
|
},
|
|
77035
77053
|
// methods below are called by vector layers implementations
|
|
77036
77054
|
_initPath: function(layer2) {
|
|
77037
|
-
var path2 = layer2._path =
|
|
77055
|
+
var path2 = layer2._path = create("path");
|
|
77038
77056
|
if (layer2.options.className) {
|
|
77039
77057
|
addClass(path2, layer2.options.className);
|
|
77040
77058
|
}
|
|
@@ -77169,7 +77187,7 @@ function requireLeafletSrc() {
|
|
|
77169
77187
|
function rectangle(latLngBounds, options) {
|
|
77170
77188
|
return new Rectangle(latLngBounds, options);
|
|
77171
77189
|
}
|
|
77172
|
-
SVG.create =
|
|
77190
|
+
SVG.create = create;
|
|
77173
77191
|
SVG.pointsToPath = pointsToPath;
|
|
77174
77192
|
GeoJSON.geometryToLayer = geometryToLayer;
|
|
77175
77193
|
GeoJSON.coordsToLatLng = coordsToLatLng;
|
|
@@ -83341,8 +83359,8 @@ class StateField {
|
|
|
83341
83359
|
way it is initialized. Can be useful when you need to provide a
|
|
83342
83360
|
non-default starting value for the field.
|
|
83343
83361
|
*/
|
|
83344
|
-
init(
|
|
83345
|
-
return [this, initField.of({ field: this, create
|
|
83362
|
+
init(create) {
|
|
83363
|
+
return [this, initField.of({ field: this, create })];
|
|
83346
83364
|
}
|
|
83347
83365
|
/**
|
|
83348
83366
|
State field instances can be used as
|
|
@@ -87542,9 +87560,9 @@ const viewPlugin = /* @__PURE__ */ Facet.define({
|
|
|
87542
87560
|
}
|
|
87543
87561
|
});
|
|
87544
87562
|
class ViewPlugin {
|
|
87545
|
-
constructor(id2,
|
|
87563
|
+
constructor(id2, create, domEventHandlers, domEventObservers, buildExtensions) {
|
|
87546
87564
|
this.id = id2;
|
|
87547
|
-
this.create =
|
|
87565
|
+
this.create = create;
|
|
87548
87566
|
this.domEventHandlers = domEventHandlers;
|
|
87549
87567
|
this.domEventObservers = domEventObservers;
|
|
87550
87568
|
this.baseExtensions = buildExtensions(this);
|
|
@@ -87560,9 +87578,9 @@ class ViewPlugin {
|
|
|
87560
87578
|
Define a plugin from a constructor function that creates the
|
|
87561
87579
|
plugin's value, given an editor view.
|
|
87562
87580
|
*/
|
|
87563
|
-
static define(
|
|
87581
|
+
static define(create, spec) {
|
|
87564
87582
|
const { eventHandlers, eventObservers, provide, decorations: deco } = spec || {};
|
|
87565
|
-
return new ViewPlugin(nextPluginID++,
|
|
87583
|
+
return new ViewPlugin(nextPluginID++, create, eventHandlers, eventObservers, (plugin) => {
|
|
87566
87584
|
let ext = [];
|
|
87567
87585
|
if (deco)
|
|
87568
87586
|
ext.push(decorations.of((view) => {
|
|
@@ -106644,15 +106662,19 @@ const RenderControls = ({
|
|
|
106644
106662
|
const loadRootDataset = () => {
|
|
106645
106663
|
onLoadEntity({ id: "./" });
|
|
106646
106664
|
};
|
|
106665
|
+
const canGoBack = state.editorState.canBack();
|
|
106666
|
+
const canGoForward = state.editorState.canForward();
|
|
106647
106667
|
const handleBack = () => {
|
|
106648
|
-
|
|
106668
|
+
if (!canGoBack) return;
|
|
106669
|
+
onBack();
|
|
106649
106670
|
const latest = state.editorState.latest();
|
|
106650
106671
|
if (latest == null ? void 0 : latest.id) {
|
|
106651
106672
|
onLoadEntity({ id: latest.id, updateState: false });
|
|
106652
106673
|
}
|
|
106653
106674
|
};
|
|
106654
106675
|
const handleForward = () => {
|
|
106655
|
-
|
|
106676
|
+
if (!canGoForward) return;
|
|
106677
|
+
onForward();
|
|
106656
106678
|
const latest = state.editorState.latest();
|
|
106657
106679
|
if (latest == null ? void 0 : latest.id) {
|
|
106658
106680
|
onLoadEntity({ id: latest.id, updateState: false });
|
|
@@ -106676,7 +106698,8 @@ const RenderControls = ({
|
|
|
106676
106698
|
{
|
|
106677
106699
|
onClick: handleBack,
|
|
106678
106700
|
type: "primary",
|
|
106679
|
-
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$8, {})
|
|
106701
|
+
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$8, {}),
|
|
106702
|
+
disabled: !canGoBack
|
|
106680
106703
|
}
|
|
106681
106704
|
),
|
|
106682
106705
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
@@ -106693,7 +106716,8 @@ const RenderControls = ({
|
|
|
106693
106716
|
{
|
|
106694
106717
|
onClick: handleForward,
|
|
106695
106718
|
type: "primary",
|
|
106696
|
-
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {})
|
|
106719
|
+
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {}),
|
|
106720
|
+
disabled: !canGoForward
|
|
106697
106721
|
}
|
|
106698
106722
|
)
|
|
106699
106723
|
] }),
|
|
@@ -115836,7 +115860,7 @@ var Logger = (function() {
|
|
|
115836
115860
|
}
|
|
115837
115861
|
}, {
|
|
115838
115862
|
key: "create",
|
|
115839
|
-
value: function
|
|
115863
|
+
value: function create(moduleName) {
|
|
115840
115864
|
return new Logger2(this.logger, _objectSpread$6(_objectSpread$6({}, {
|
|
115841
115865
|
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
115842
115866
|
}), this.options));
|
|
@@ -119521,7 +119545,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
|
|
|
119521
119545
|
}) : null
|
|
119522
119546
|
);
|
|
119523
119547
|
var CacheProvider = EmotionCacheContext.Provider;
|
|
119524
|
-
const version = "0.1.
|
|
119548
|
+
const version = "0.1.19";
|
|
119525
119549
|
const pkg = {
|
|
119526
119550
|
version
|
|
119527
119551
|
};
|
|
@@ -119530,6 +119554,9 @@ const ProfileManagerContext = React__default.createContext(null);
|
|
|
119530
119554
|
const CrateManagerContext = React__default.createContext(null);
|
|
119531
119555
|
const LookupsContext = React__default.createContext(null);
|
|
119532
119556
|
function DescriboCrateBuilder(props) {
|
|
119557
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(StateStoreProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(DescriboCrateBuilderInner, { ...props }) });
|
|
119558
|
+
}
|
|
119559
|
+
function DescriboCrateBuilderInner(props) {
|
|
119533
119560
|
const {
|
|
119534
119561
|
crate,
|
|
119535
119562
|
profile,
|
|
@@ -119568,6 +119595,7 @@ function DescriboCrateBuilder(props) {
|
|
|
119568
119595
|
const state = useStateStore();
|
|
119569
119596
|
const renderEntityRef = useRef(null);
|
|
119570
119597
|
const keys2 = useRef({ cm: 0, pm: 0, lookups: 0 });
|
|
119598
|
+
const lastHandledEntityIdRef = useRef(void 0);
|
|
119571
119599
|
const configuration = useMemo$1(() => {
|
|
119572
119600
|
const config2 = {
|
|
119573
119601
|
enableContextEditor,
|
|
@@ -119612,6 +119640,7 @@ function DescriboCrateBuilder(props) {
|
|
|
119612
119640
|
lookup
|
|
119613
119641
|
]);
|
|
119614
119642
|
const init2 = useCallback(async () => {
|
|
119643
|
+
var _a2, _b;
|
|
119615
119644
|
instance.changeLanguage(language2);
|
|
119616
119645
|
if (!crate || isEmpty(crate)) {
|
|
119617
119646
|
setReady(false);
|
|
@@ -119647,23 +119676,39 @@ function DescriboCrateBuilder(props) {
|
|
|
119647
119676
|
setCm(newCm);
|
|
119648
119677
|
setPm(newPm);
|
|
119649
119678
|
setError(false);
|
|
119650
|
-
state.configuration
|
|
119679
|
+
state.setConfiguration(configuration);
|
|
119651
119680
|
try {
|
|
119652
|
-
const
|
|
119653
|
-
|
|
119654
|
-
|
|
119655
|
-
|
|
119656
|
-
|
|
119681
|
+
const graph = Array.isArray(crate == null ? void 0 : crate["@graph"]) ? crate["@graph"] : [];
|
|
119682
|
+
const validIds = new Set(
|
|
119683
|
+
graph.filter((entry) => entry && typeof entry === "object" && typeof entry["@id"] === "string").map((entry) => String(entry["@id"]))
|
|
119684
|
+
);
|
|
119685
|
+
state.editorState.history = state.editorState.history.filter((entry) => validIds.has(entry.id));
|
|
119686
|
+
state.editorState.current = state.editorState.history.length === 0 ? 0 : Math.min(state.editorState.current, state.editorState.history.length - 1);
|
|
119687
|
+
const candidateIds = [(_a2 = state.editorState.latest()) == null ? void 0 : _a2.id, entityId, "./"];
|
|
119688
|
+
let nextEntity = null;
|
|
119689
|
+
for (const candidateId of candidateIds) {
|
|
119690
|
+
if (!candidateId) continue;
|
|
119691
|
+
const maybeEntity = newCm.getEntity({ id: candidateId, link: false, materialise: false });
|
|
119692
|
+
if (!isEmpty(maybeEntity)) {
|
|
119693
|
+
nextEntity = maybeEntity;
|
|
119694
|
+
break;
|
|
119695
|
+
}
|
|
119696
|
+
}
|
|
119697
|
+
if (!nextEntity) {
|
|
119657
119698
|
setError(true);
|
|
119658
119699
|
return;
|
|
119659
119700
|
}
|
|
119701
|
+
setContextEntity(nextEntity);
|
|
119702
|
+
if (((_b = state.editorState.latest()) == null ? void 0 : _b.id) !== nextEntity["@id"]) {
|
|
119703
|
+
state.editorState.push({ id: nextEntity["@id"] });
|
|
119704
|
+
}
|
|
119660
119705
|
setReady(true);
|
|
119661
119706
|
onReady == null ? void 0 : onReady();
|
|
119662
119707
|
} catch (error22) {
|
|
119663
119708
|
setError(true);
|
|
119664
119709
|
onError == null ? void 0 : onError({ error: "Failed to initialize entity" });
|
|
119665
119710
|
}
|
|
119666
|
-
}, [crate, profile, lookup, configuration, enableEntityTimestamps, language2, onError, onReady, state.editorState]);
|
|
119711
|
+
}, [crate, profile, entityId, lookup, configuration, enableEntityTimestamps, language2, onError, onReady, state.editorState]);
|
|
119667
119712
|
const handleSetCurrentEntity = useCallback((params) => {
|
|
119668
119713
|
const { id: id2, updateState = true } = params;
|
|
119669
119714
|
if (!id2 || !cm) return;
|
|
@@ -119714,14 +119759,23 @@ function DescriboCrateBuilder(props) {
|
|
|
119714
119759
|
onError == null ? void 0 : onError({});
|
|
119715
119760
|
};
|
|
119716
119761
|
useEffect(() => {
|
|
119717
|
-
state.editorState.reset();
|
|
119718
119762
|
init2();
|
|
119719
119763
|
}, [crate, profile, init2]);
|
|
119720
119764
|
useEffect(() => {
|
|
119721
|
-
|
|
119722
|
-
|
|
119765
|
+
var _a2;
|
|
119766
|
+
if (!entityId) {
|
|
119767
|
+
lastHandledEntityIdRef.current = void 0;
|
|
119768
|
+
return;
|
|
119769
|
+
}
|
|
119770
|
+
if (lastHandledEntityIdRef.current === entityId) {
|
|
119771
|
+
return;
|
|
119772
|
+
}
|
|
119773
|
+
lastHandledEntityIdRef.current = entityId;
|
|
119774
|
+
if (entityId !== (contextEntity == null ? void 0 : contextEntity["@id"])) {
|
|
119775
|
+
const shouldPushToHistory = ((_a2 = state.editorState.latest()) == null ? void 0 : _a2.id) !== entityId;
|
|
119776
|
+
handleSetCurrentEntity({ id: entityId, updateState: shouldPushToHistory });
|
|
119723
119777
|
}
|
|
119724
|
-
}, [entityId, contextEntity, handleSetCurrentEntity]);
|
|
119778
|
+
}, [entityId, contextEntity, handleSetCurrentEntity, state.editorState]);
|
|
119725
119779
|
const saveCrate = () => {
|
|
119726
119780
|
if (!cm) return;
|
|
119727
119781
|
if (purgeUnlinkedEntities) {
|